Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsFontFaceList.h" |
michael@0 | 6 | #include "nsFontFace.h" |
michael@0 | 7 | #include "nsFontFaceLoader.h" |
michael@0 | 8 | #include "nsIFrame.h" |
michael@0 | 9 | #include "gfxFont.h" |
michael@0 | 10 | #include "mozilla/gfx/2D.h" |
michael@0 | 11 | |
michael@0 | 12 | nsFontFaceList::nsFontFaceList() |
michael@0 | 13 | { |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | nsFontFaceList::~nsFontFaceList() |
michael@0 | 17 | { |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 21 | // nsISupports |
michael@0 | 22 | |
michael@0 | 23 | NS_IMPL_ISUPPORTS(nsFontFaceList, nsIDOMFontFaceList) |
michael@0 | 24 | |
michael@0 | 25 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 26 | // nsIDOMFontFaceList |
michael@0 | 27 | |
michael@0 | 28 | /* nsIDOMFontFace item (in unsigned long index); */ |
michael@0 | 29 | struct FindByIndexData { |
michael@0 | 30 | uint32_t mTarget; |
michael@0 | 31 | uint32_t mCurrent; |
michael@0 | 32 | nsIDOMFontFace* mResult; |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | static PLDHashOperator |
michael@0 | 36 | FindByIndex(gfxFontEntry* aKey, nsIDOMFontFace* aData, void* aUserData) |
michael@0 | 37 | { |
michael@0 | 38 | FindByIndexData* data = static_cast<FindByIndexData*>(aUserData); |
michael@0 | 39 | if (data->mCurrent == data->mTarget) { |
michael@0 | 40 | data->mResult = aData; |
michael@0 | 41 | return PL_DHASH_STOP; |
michael@0 | 42 | } |
michael@0 | 43 | data->mCurrent++; |
michael@0 | 44 | return PL_DHASH_NEXT; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | NS_IMETHODIMP |
michael@0 | 48 | nsFontFaceList::Item(uint32_t index, nsIDOMFontFace **_retval) |
michael@0 | 49 | { |
michael@0 | 50 | NS_ENSURE_TRUE(index < mFontFaces.Count(), NS_ERROR_INVALID_ARG); |
michael@0 | 51 | FindByIndexData userData; |
michael@0 | 52 | userData.mTarget = index; |
michael@0 | 53 | userData.mCurrent = 0; |
michael@0 | 54 | userData.mResult = nullptr; |
michael@0 | 55 | mFontFaces.EnumerateRead(FindByIndex, &userData); |
michael@0 | 56 | NS_ASSERTION(userData.mResult != nullptr, "null entry in nsFontFaceList?"); |
michael@0 | 57 | NS_IF_ADDREF(*_retval = userData.mResult); |
michael@0 | 58 | return NS_OK; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | /* readonly attribute unsigned long length; */ |
michael@0 | 62 | NS_IMETHODIMP |
michael@0 | 63 | nsFontFaceList::GetLength(uint32_t *aLength) |
michael@0 | 64 | { |
michael@0 | 65 | *aLength = mFontFaces.Count(); |
michael@0 | 66 | return NS_OK; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 70 | // nsFontFaceList |
michael@0 | 71 | |
michael@0 | 72 | nsresult |
michael@0 | 73 | nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun, |
michael@0 | 74 | uint32_t aOffset, uint32_t aLength) |
michael@0 | 75 | { |
michael@0 | 76 | gfxTextRun::GlyphRunIterator iter(aTextRun, aOffset, aLength); |
michael@0 | 77 | while (iter.NextRun()) { |
michael@0 | 78 | gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry(); |
michael@0 | 79 | // if we have already listed this face, just make sure the match type is |
michael@0 | 80 | // recorded |
michael@0 | 81 | nsFontFace* existingFace = |
michael@0 | 82 | static_cast<nsFontFace*>(mFontFaces.GetWeak(fe)); |
michael@0 | 83 | if (existingFace) { |
michael@0 | 84 | existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType); |
michael@0 | 85 | } else { |
michael@0 | 86 | // A new font entry we haven't seen before |
michael@0 | 87 | nsRefPtr<nsFontFace> ff = |
michael@0 | 88 | new nsFontFace(fe, aTextRun->GetFontGroup(), |
michael@0 | 89 | iter.GetGlyphRun()->mMatchType); |
michael@0 | 90 | mFontFaces.Put(fe, ff); |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | return NS_OK; |
michael@0 | 95 | } |