2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-16 06:31:36 +00:00
|
|
|
|
2011-06-16 06:31:36 +00:00
|
|
|
#define _IMPL_NS_LAYOUT
|
|
|
|
|
2011-06-16 06:31:36 +00:00
|
|
|
#include "nsFontFaceList.h"
|
|
|
|
#include "nsFontFace.h"
|
2011-06-16 06:31:36 +00:00
|
|
|
#include "nsFontFaceLoader.h"
|
|
|
|
#include "nsIFrame.h"
|
2011-06-16 06:31:36 +00:00
|
|
|
#include "gfxFont.h"
|
|
|
|
|
|
|
|
nsFontFaceList::nsFontFaceList()
|
|
|
|
{
|
|
|
|
mFontFaces.Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFontFaceList::~nsFontFaceList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsFontFaceList, nsIDOMFontFaceList)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMFontFaceList
|
|
|
|
|
|
|
|
/* nsIDOMFontFace item (in unsigned long index); */
|
|
|
|
struct FindByIndexData {
|
|
|
|
PRUint32 mTarget;
|
|
|
|
PRUint32 mCurrent;
|
|
|
|
nsIDOMFontFace* mResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
FindByIndex(gfxFontEntry* aKey, nsIDOMFontFace* aData, void* aUserData)
|
|
|
|
{
|
|
|
|
FindByIndexData* data = static_cast<FindByIndexData*>(aUserData);
|
|
|
|
if (data->mCurrent == data->mTarget) {
|
|
|
|
data->mResult = aData;
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
data->mCurrent++;
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-06 20:14:07 +00:00
|
|
|
nsFontFaceList::Item(PRUint32 index, nsIDOMFontFace **_retval)
|
2011-06-16 06:31:36 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(index < mFontFaces.Count(), NS_ERROR_INVALID_ARG);
|
|
|
|
FindByIndexData userData;
|
|
|
|
userData.mTarget = index;
|
|
|
|
userData.mCurrent = 0;
|
|
|
|
userData.mResult = nsnull;
|
|
|
|
mFontFaces.EnumerateRead(FindByIndex, &userData);
|
|
|
|
NS_ASSERTION(userData.mResult != nsnull, "null entry in nsFontFaceList?");
|
|
|
|
NS_IF_ADDREF(*_retval = userData.mResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute unsigned long length; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFontFaceList::GetLength(PRUint32 *aLength)
|
|
|
|
{
|
|
|
|
*aLength = mFontFaces.Count();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFontFaceList
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun,
|
2011-06-16 06:31:36 +00:00
|
|
|
PRUint32 aOffset, PRUint32 aLength,
|
|
|
|
nsIFrame* aFrame)
|
2011-06-16 06:31:36 +00:00
|
|
|
{
|
|
|
|
gfxTextRun::GlyphRunIterator iter(aTextRun, aOffset, aLength);
|
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry();
|
2011-06-16 06:31:37 +00:00
|
|
|
// if we have already listed this face, just make sure the match type is
|
|
|
|
// recorded
|
|
|
|
nsFontFace* existingFace =
|
|
|
|
static_cast<nsFontFace*>(mFontFaces.GetWeak(fe));
|
|
|
|
if (existingFace) {
|
|
|
|
existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType);
|
|
|
|
} else {
|
|
|
|
// A new font entry we haven't seen before;
|
2011-06-16 06:31:36 +00:00
|
|
|
// check whether this font entry is associated with an @font-face rule
|
|
|
|
nsRefPtr<nsCSSFontFaceRule> rule;
|
|
|
|
nsUserFontSet* fontSet =
|
|
|
|
static_cast<nsUserFontSet*>(aFrame->PresContext()->GetUserFontSet());
|
|
|
|
if (fontSet) {
|
|
|
|
rule = fontSet->FindRuleForEntry(fe);
|
|
|
|
}
|
2011-06-16 06:31:37 +00:00
|
|
|
nsCOMPtr<nsFontFace> ff =
|
|
|
|
new nsFontFace(fe, iter.GetGlyphRun()->mMatchType, rule);
|
2012-05-18 17:30:49 +00:00
|
|
|
mFontFaces.Put(fe, ff);
|
2011-06-16 06:31:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|