зеркало из https://github.com/mozilla/pjs.git
bug 467669 - pt 2 - find the @font-face rule (if any) responsible for the font entry. r=roc
This commit is contained in:
Родитель
6ca803b1ee
Коммит
f569f56be6
|
@ -4120,7 +4120,8 @@ nsLayoutUtils::GetFontFacesForText(nsIFrame* aFrame,
|
|||
PRUint32 skipStart = iter.ConvertOriginalToSkipped(fstart - offset);
|
||||
PRUint32 skipEnd = iter.ConvertOriginalToSkipped(fend - offset);
|
||||
aFontFaceList->AddFontsFromTextRun(textRun,
|
||||
skipStart, skipEnd - skipStart);
|
||||
skipStart, skipEnd - skipStart,
|
||||
curr);
|
||||
} while (aFollowContinuations &&
|
||||
(curr = static_cast<nsTextFrame*>(curr->GetNextContinuation())));
|
||||
|
||||
|
|
|
@ -34,10 +34,16 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsFontFace.h"
|
||||
#define _IMPL_NS_LAYOUT
|
||||
|
||||
nsFontFace::nsFontFace(gfxFontEntry* aFontEntry)
|
||||
: mFontEntry(aFontEntry)
|
||||
#include "nsFontFace.h"
|
||||
#include "nsIDOMCSSFontFaceRule.h"
|
||||
#include "nsCSSRules.h"
|
||||
|
||||
nsFontFace::nsFontFace(gfxFontEntry* aFontEntry,
|
||||
nsCSSFontFaceRule* aRule)
|
||||
: mFontEntry(aFontEntry),
|
||||
mRule(aRule)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -94,7 +100,8 @@ nsFontFace::GetCSSFamilyName(nsAString & aCSSFamilyName)
|
|||
NS_IMETHODIMP
|
||||
nsFontFace::GetRule(nsIDOMCSSFontFaceRule **aRule)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_IF_ADDREF(*aRule = mRule.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute long srcIndex; */
|
||||
|
|
|
@ -41,19 +41,23 @@
|
|||
|
||||
#include "gfxFont.h"
|
||||
|
||||
class nsCSSFontFaceRule;
|
||||
|
||||
class nsFontFace : public nsIDOMFontFace
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMFONTFACE
|
||||
|
||||
nsFontFace(gfxFontEntry* aFontEntry);
|
||||
nsFontFace(gfxFontEntry* aFontEntry,
|
||||
nsCSSFontFaceRule* aRule);
|
||||
virtual ~nsFontFace();
|
||||
|
||||
gfxFontEntry* GetFontEntry() const { return mFontEntry.get(); }
|
||||
|
||||
protected:
|
||||
nsRefPtr<gfxFontEntry> mFontEntry;
|
||||
nsRefPtr<nsCSSFontFaceRule> mRule;
|
||||
};
|
||||
|
||||
#endif // __nsFontFace_h__
|
||||
|
|
|
@ -34,8 +34,12 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#define _IMPL_NS_LAYOUT
|
||||
|
||||
#include "nsFontFaceList.h"
|
||||
#include "nsFontFace.h"
|
||||
#include "nsFontFaceLoader.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "gfxFont.h"
|
||||
|
||||
nsFontFaceList::nsFontFaceList()
|
||||
|
@ -101,13 +105,21 @@ nsFontFaceList::GetLength(PRUint32 *aLength)
|
|||
|
||||
nsresult
|
||||
nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun,
|
||||
PRUint32 aOffset, PRUint32 aLength)
|
||||
PRUint32 aOffset, PRUint32 aLength,
|
||||
nsIFrame* aFrame)
|
||||
{
|
||||
gfxTextRun::GlyphRunIterator iter(aTextRun, aOffset, aLength);
|
||||
while (iter.NextRun()) {
|
||||
gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry();
|
||||
if (!mFontFaces.GetWeak(fe)) {
|
||||
nsCOMPtr<nsFontFace> ff = new nsFontFace(fe);
|
||||
// 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);
|
||||
}
|
||||
nsCOMPtr<nsFontFace> ff = new nsFontFace(fe, rule);
|
||||
if (!mFontFaces.Put(fe, ff)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "gfxFont.h"
|
||||
|
||||
class gfxTextRun;
|
||||
class nsIFrame;
|
||||
|
||||
class nsFontFaceList : public nsIDOMFontFaceList
|
||||
{
|
||||
|
@ -56,7 +57,8 @@ public:
|
|||
virtual ~nsFontFaceList();
|
||||
|
||||
nsresult AddFontsFromTextRun(gfxTextRun* aTextRun,
|
||||
PRUint32 aOffset, PRUint32 aLength);
|
||||
PRUint32 aOffset, PRUint32 aLength,
|
||||
nsIFrame* aFrame);
|
||||
|
||||
protected:
|
||||
nsInterfaceHashtable<nsPtrHashKey<gfxFontEntry>,nsIDOMFontFace> mFontFaces;
|
||||
|
|
|
@ -686,3 +686,14 @@ nsUserFontSet::ReplaceFontEntry(gfxProxyFontEntry *aProxy,
|
|||
static_cast<gfxMixedFontFamily*>(aProxy->Family())->
|
||||
ReplaceFontEntry(aProxy, aFontEntry);
|
||||
}
|
||||
|
||||
nsCSSFontFaceRule*
|
||||
nsUserFontSet::FindRuleForEntry(gfxFontEntry *aFontEntry)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mRules.Length(); ++i) {
|
||||
if (mRules[i].mFontEntry == aFontEntry) {
|
||||
return mRules[i].mContainer.mRule;
|
||||
}
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ public:
|
|||
virtual void ReplaceFontEntry(gfxProxyFontEntry *aProxy,
|
||||
gfxFontEntry *aFontEntry);
|
||||
|
||||
nsCSSFontFaceRule *FindRuleForEntry(gfxFontEntry *aFontEntry);
|
||||
|
||||
protected:
|
||||
// The font-set keeps track of the collection of rules, and their
|
||||
// corresponding font entries (whether proxies or real entries),
|
||||
|
|
Загрузка…
Ссылка в новой задаче