2012-05-21 04:12:37 -07: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-15 23:31:36 -07:00
|
|
|
|
|
|
|
#include "nsFontFaceList.h"
|
|
|
|
#include "nsFontFace.h"
|
2011-06-15 23:31:36 -07:00
|
|
|
#include "nsFontFaceLoader.h"
|
|
|
|
#include "nsIFrame.h"
|
2011-06-15 23:31:36 -07:00
|
|
|
#include "gfxFont.h"
|
2013-10-07 16:15:59 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2011-06-15 23:31:36 -07:00
|
|
|
|
|
|
|
nsFontFaceList::nsFontFaceList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFontFaceList::~nsFontFaceList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsFontFaceList, nsIDOMFontFaceList)
|
2011-06-15 23:31:36 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMFontFaceList
|
|
|
|
|
|
|
|
/* nsIDOMFontFace item (in unsigned long index); */
|
|
|
|
struct FindByIndexData {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mTarget;
|
|
|
|
uint32_t mCurrent;
|
2011-06-15 23:31:36 -07:00
|
|
|
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-08-22 08:56:38 -07:00
|
|
|
nsFontFaceList::Item(uint32_t index, nsIDOMFontFace **_retval)
|
2011-06-15 23:31:36 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(index < mFontFaces.Count(), NS_ERROR_INVALID_ARG);
|
|
|
|
FindByIndexData userData;
|
|
|
|
userData.mTarget = index;
|
|
|
|
userData.mCurrent = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
userData.mResult = nullptr;
|
2011-06-15 23:31:36 -07:00
|
|
|
mFontFaces.EnumerateRead(FindByIndex, &userData);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(userData.mResult != nullptr, "null entry in nsFontFaceList?");
|
2011-06-15 23:31:36 -07:00
|
|
|
NS_IF_ADDREF(*_retval = userData.mResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute unsigned long length; */
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsFontFaceList::GetLength(uint32_t *aLength)
|
2011-06-15 23:31:36 -07:00
|
|
|
{
|
|
|
|
*aLength = mFontFaces.Count();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFontFaceList
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun,
|
2013-12-18 05:25:54 -08:00
|
|
|
uint32_t aOffset, uint32_t aLength)
|
2011-06-15 23:31:36 -07:00
|
|
|
{
|
|
|
|
gfxTextRun::GlyphRunIterator iter(aTextRun, aOffset, aLength);
|
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry();
|
2011-06-15 23:31:37 -07: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 {
|
2012-12-19 01:42:25 -08:00
|
|
|
// A new font entry we haven't seen before
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<nsFontFace> ff =
|
2012-12-19 01:42:25 -08:00
|
|
|
new nsFontFace(fe, aTextRun->GetFontGroup(),
|
|
|
|
iter.GetGlyphRun()->mMatchType);
|
2012-05-18 10:30:49 -07:00
|
|
|
mFontFaces.Put(fe, ff);
|
2011-06-15 23:31:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|