layout/inspector/nsFontFaceList.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial