mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1031206 - Part 1: Split out creation and addition of font faces in gfxUserFontSet. r=jdaggett
This commit is contained in:
parent
7ca2de4659
commit
3ecb723a73
@ -582,8 +582,75 @@ gfxUserFontSet::~gfxUserFontSet()
|
||||
}
|
||||
}
|
||||
|
||||
gfxFontEntry*
|
||||
gfxUserFontSet::AddFontFace(const nsAString& aFamilyName,
|
||||
already_AddRefed<gfxProxyFontEntry>
|
||||
gfxUserFontSet::FindOrCreateFontFace(
|
||||
const nsAString& aFamilyName,
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
||||
uint32_t aWeight,
|
||||
int32_t aStretch,
|
||||
uint32_t aItalicStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
uint32_t aLanguageOverride,
|
||||
gfxSparseBitSet* aUnicodeRanges)
|
||||
{
|
||||
nsRefPtr<gfxProxyFontEntry> entry;
|
||||
|
||||
// If there's already a proxy in the family whose descriptors all match,
|
||||
// we can just move it to the end of the list instead of adding a new
|
||||
// face that will always "shadow" the old one.
|
||||
// Note that we can't do this for "real" (non-proxy) entries, even if the
|
||||
// style descriptors match, as they might have had a different source list,
|
||||
// but we no longer have the old source list available to check.
|
||||
gfxMixedFontFamily* family = LookupFamily(aFamilyName);
|
||||
if (family) {
|
||||
entry = FindExistingProxyEntry(family, aFontFaceSrcList, aWeight,
|
||||
aStretch, aItalicStyle, aFeatureSettings,
|
||||
aLanguageOverride, aUnicodeRanges);
|
||||
}
|
||||
|
||||
if (!entry) {
|
||||
entry = CreateFontFace(aFontFaceSrcList, aWeight, aStretch,
|
||||
aItalicStyle, aFeatureSettings, aLanguageOverride,
|
||||
aUnicodeRanges);
|
||||
entry->mFamilyName = aFamilyName;
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
if (LOG_ENABLED()) {
|
||||
LOG(("userfonts (%p) created \"%s\" (%p) with style: %s weight: %d "
|
||||
"stretch: %d",
|
||||
this, NS_ConvertUTF16toUTF8(aFamilyName).get(), entry.get(),
|
||||
(aItalicStyle & NS_FONT_STYLE_ITALIC ? "italic" :
|
||||
(aItalicStyle & NS_FONT_STYLE_OBLIQUE ? "oblique" : "normal")),
|
||||
aWeight, aStretch));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return entry.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<gfxProxyFontEntry>
|
||||
gfxUserFontSet::CreateFontFace(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
||||
uint32_t aWeight,
|
||||
int32_t aStretch,
|
||||
uint32_t aItalicStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
uint32_t aLanguageOverride,
|
||||
gfxSparseBitSet* aUnicodeRanges)
|
||||
{
|
||||
MOZ_ASSERT(aWeight != 0,
|
||||
"aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
|
||||
|
||||
nsRefPtr<gfxProxyFontEntry> proxyEntry =
|
||||
new gfxProxyFontEntry(this, aFontFaceSrcList, aWeight,
|
||||
aStretch, aItalicStyle, aFeatureSettings,
|
||||
aLanguageOverride, aUnicodeRanges);
|
||||
return proxyEntry.forget();
|
||||
}
|
||||
|
||||
gfxProxyFontEntry*
|
||||
gfxUserFontSet::FindExistingProxyEntry(
|
||||
gfxMixedFontFamily* aFamily,
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
||||
uint32_t aWeight,
|
||||
int32_t aStretch,
|
||||
@ -595,18 +662,9 @@ gfxUserFontSet::AddFontFace(const nsAString& aFamilyName,
|
||||
MOZ_ASSERT(aWeight != 0,
|
||||
"aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
|
||||
|
||||
// stretch, italic/oblique ==> zero implies normal
|
||||
nsTArray<nsRefPtr<gfxFontEntry>>& fontList = aFamily->GetFontList();
|
||||
|
||||
gfxMixedFontFamily* family = GetFamily(aFamilyName);
|
||||
|
||||
// If there's already a proxy in the family whose descriptors all match,
|
||||
// we can just move it to the end of the list instead of adding a new
|
||||
// face that will always "shadow" the old one.
|
||||
// Note that we can't do this for "real" (non-proxy) entries, even if the
|
||||
// style descriptors match, as they might have had a different source list,
|
||||
// but we no longer have the old source list available to check.
|
||||
nsTArray<nsRefPtr<gfxFontEntry> >& fontList = family->GetFontList();
|
||||
for (uint32_t i = 0, count = fontList.Length(); i < count; i++) {
|
||||
for (size_t i = 0, count = fontList.Length(); i < count; i++) {
|
||||
if (!fontList[i]->mIsProxy) {
|
||||
continue;
|
||||
}
|
||||
@ -620,34 +678,10 @@ gfxUserFontSet::AddFontFace(const nsAString& aFamilyName,
|
||||
continue;
|
||||
}
|
||||
|
||||
// We've found an entry that matches the new face exactly, so just add
|
||||
// it to the end of the list. gfxMixedFontFamily::AddFontEntry() will
|
||||
// automatically remove any earlier occurrence of the same proxy.
|
||||
family->AddFontEntry(existingProxyEntry);
|
||||
return existingProxyEntry;
|
||||
}
|
||||
|
||||
// construct a new face and add it into the family
|
||||
gfxProxyFontEntry *proxyEntry =
|
||||
new gfxProxyFontEntry(this, aFontFaceSrcList,
|
||||
aWeight, aStretch,
|
||||
aItalicStyle,
|
||||
aFeatureSettings,
|
||||
aLanguageOverride,
|
||||
aUnicodeRanges);
|
||||
proxyEntry->mFamilyName = aFamilyName;
|
||||
family->AddFontEntry(proxyEntry);
|
||||
#ifdef PR_LOGGING
|
||||
if (LOG_ENABLED()) {
|
||||
LOG(("userfonts (%p) added (%s) with style: %s weight: %d stretch: %d",
|
||||
this, NS_ConvertUTF16toUTF8(aFamilyName).get(),
|
||||
(aItalicStyle & NS_FONT_STYLE_ITALIC ? "italic" :
|
||||
(aItalicStyle & NS_FONT_STYLE_OBLIQUE ? "oblique" : "normal")),
|
||||
aWeight, aStretch));
|
||||
}
|
||||
#endif
|
||||
|
||||
return proxyEntry;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
@ -656,6 +690,13 @@ gfxUserFontSet::AddFontFace(const nsAString& aFamilyName,
|
||||
{
|
||||
gfxMixedFontFamily* family = GetFamily(aFamilyName);
|
||||
family->AddFontEntry(aFontEntry);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
if (LOG_ENABLED()) {
|
||||
LOG(("userfonts (%p) added \"%s\" (%p)",
|
||||
this, NS_ConvertUTF16toUTF8(aFamilyName).get(), aFontEntry));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
gfxFontEntry*
|
||||
|
@ -167,20 +167,32 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// add in a font face
|
||||
// creates a font face without adding it to a particular family
|
||||
// weight - [100, 900] (multiples of 100)
|
||||
// stretch = [NS_FONT_STRETCH_ULTRA_CONDENSED, NS_FONT_STRETCH_ULTRA_EXPANDED]
|
||||
// italic style = constants in gfxFontConstants.h, e.g. NS_FONT_STYLE_NORMAL
|
||||
// language override = result of calling gfxFontStyle::ParseFontLanguageOverride
|
||||
// TODO: support for unicode ranges not yet implemented
|
||||
gfxFontEntry *AddFontFace(const nsAString& aFamilyName,
|
||||
already_AddRefed<gfxProxyFontEntry> CreateFontFace(
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
||||
uint32_t aWeight,
|
||||
int32_t aStretch,
|
||||
uint32_t aItalicStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
uint32_t aLanguageOverride,
|
||||
gfxSparseBitSet *aUnicodeRanges = nullptr);
|
||||
gfxSparseBitSet* aUnicodeRanges);
|
||||
|
||||
// creates a font face for the specified family, or returns an existing
|
||||
// matching entry on the family if there is one
|
||||
already_AddRefed<gfxProxyFontEntry> FindOrCreateFontFace(
|
||||
const nsAString& aFamilyName,
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
||||
uint32_t aWeight,
|
||||
int32_t aStretch,
|
||||
uint32_t aItalicStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
uint32_t aLanguageOverride,
|
||||
gfxSparseBitSet* aUnicodeRanges);
|
||||
|
||||
// add in a font face for which we have the gfxFontEntry already
|
||||
void AddFontFace(const nsAString& aFamilyName, gfxFontEntry* aFontEntry);
|
||||
@ -432,6 +444,17 @@ protected:
|
||||
// helper method for performing the actual userfont set rebuild
|
||||
virtual void DoRebuildUserFontSet() = 0;
|
||||
|
||||
// helper method for FindOrCreateFontFace
|
||||
gfxProxyFontEntry* FindExistingProxyEntry(
|
||||
gfxMixedFontFamily* aFamily,
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
||||
uint32_t aWeight,
|
||||
int32_t aStretch,
|
||||
uint32_t aItalicStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
uint32_t aLanguageOverride,
|
||||
gfxSparseBitSet* aUnicodeRanges);
|
||||
|
||||
// creates a new gfxMixedFontFamily in mFontFamilies, or returns an existing
|
||||
// family if there is one
|
||||
gfxMixedFontFamily* GetFamily(const nsAString& aFamilyName);
|
||||
|
@ -722,10 +722,17 @@ nsUserFontSet::InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType,
|
||||
FontFaceRuleRecord ruleRec;
|
||||
ruleRec.mContainer.mRule = aRule;
|
||||
ruleRec.mContainer.mSheetType = aSheetType;
|
||||
ruleRec.mFontEntry = AddFontFace(fontfamily, srcArray,
|
||||
ruleRec.mFontEntry = FindOrCreateFontFace(fontfamily, srcArray,
|
||||
weight, stretch, italicStyle,
|
||||
featureSettings, languageOverride);
|
||||
featureSettings, languageOverride,
|
||||
nullptr /* aUnicodeRanges */);
|
||||
if (ruleRec.mFontEntry) {
|
||||
// Add the entry to the end of the list. If an existing proxy entry was
|
||||
// returned by FindOrCreateFontFace that was already stored on the
|
||||
// family, gfxMixedFontFamily::AddFontEntry(), which AddFontFace calls,
|
||||
// will automatically remove the earlier occurrence of the same proxy.
|
||||
AddFontFace(fontfamily, ruleRec.mFontEntry);
|
||||
|
||||
mRules.AppendElement(ruleRec);
|
||||
}
|
||||
// this was a new rule and fontEntry, so note that the set was modified
|
||||
|
Loading…
Reference in New Issue
Block a user