Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 833169 - add font family name to font entries and use in user fon…
Browse files Browse the repository at this point in the history
…t cache key. r=jkew
  • Loading branch information
John Daggett committed Feb 18, 2013
1 parent b21eb7e commit f494b83
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 120 deletions.
4 changes: 3 additions & 1 deletion accessible/src/base/TextAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ TextAttrsMgr::FontFamilyTextAttr::
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm));

gfxFontGroup* fontGroup = fm->GetThebesFontGroup();
aFamily = fontGroup->GetFamilyNameAt(0);
gfxFont* font = fontGroup->GetFontAt(0);
gfxFontEntry* fontEntry = font->GetFontEntry();
aFamily = fontEntry->FamilyName();
return true;
}

Expand Down
15 changes: 0 additions & 15 deletions gfx/thebes/gfxFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,6 @@ nsresult gfxFontEntry::ReadCMAP()
return NS_OK;
}

nsString
gfxFontEntry::FamilyName()
{
FallibleTArray<uint8_t> nameTable;
nsresult rv = GetFontTable(TRUETYPE_TAG('n','a','m','e'), nameTable);
if (NS_SUCCEEDED(rv)) {
nsAutoString name;
rv = gfxFontUtils::GetFamilyNameFromTable(nameTable, name);
if (NS_SUCCEEDED(rv)) {
return name;
}
}
return Name();
}

nsString
gfxFontEntry::RealFaceName()
{
Expand Down
22 changes: 5 additions & 17 deletions gfx/thebes/gfxFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ class gfxFontEntry {
// "real" or user-friendly name, may be an internal identifier
const nsString& Name() const { return mName; }

// family name
const nsString& FamilyName() const { return mFamilyName; }

// The following two methods may be relatively expensive, as they
// will (usually, except on Linux) load and parse the 'name' table;
// they are intended only for the font-inspection API, not for
Expand All @@ -241,10 +244,6 @@ class gfxFontEntry {
// returns Name() if nothing better is available.
virtual nsString RealFaceName();

// The family name (if available) that would be used in css font-family
// properties; returns Name() if nothing better available.
virtual nsString FamilyName();

uint16_t Weight() const { return mWeight; }
int16_t Stretch() const { return mStretch; }

Expand Down Expand Up @@ -335,6 +334,7 @@ class gfxFontEntry {
FontListSizes* aSizes) const;

nsString mName;
nsString mFamilyName;

bool mItalic : 1;
bool mFixedPitch : 1;
Expand Down Expand Up @@ -561,6 +561,7 @@ class gfxFontFamily {
{
aFontEntry->mIgnoreGDEF = true;
}
aFontEntry->mFamilyName = Name();
mAvailableFonts.AppendElement(aFontEntry);
}

Expand Down Expand Up @@ -3106,19 +3107,6 @@ class THEBES_API gfxFontGroup : public gfxTextRunFactory {
return mFonts[i].Font();
}
// Return the family name of the primary font in the group.
// Note that gfxPangoFontGroup (for the Linux/Fontconfig backend),
// which does not have gfxFontFamily objects, must override this.
virtual nsString GetFamilyNameAt(int32_t i) {
NS_ASSERTION(!mUserFontSet || mCurrGeneration == GetGeneration(),
"Whoever was caching this font group should have "
"called UpdateFontList on it");
NS_ASSERTION(mFonts.Length() > uint32_t(i) && mFonts[i].Family(),
"No fonts in the group!");
return mFonts[i].Family()->Name();
}
uint32_t FontListLength() const {
return mFonts.Length();
}
Expand Down
42 changes: 0 additions & 42 deletions gfx/thebes/gfxPangoFonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ class gfxFcFontEntry : public gfxFontEntry {
// GetFontTable() here
virtual nsString RealFaceName();

virtual nsString FamilyName();

// This is needed to make gfxFontEntry::HasCharacter(aCh) work.
virtual bool TestCharacterMap(uint32_t aCh)
{
Expand Down Expand Up @@ -234,20 +232,6 @@ gfxFcFontEntry::RealFaceName()
return gfxFontEntry::RealFaceName();
}

nsString
gfxFcFontEntry::FamilyName()
{
FcChar8 *name;
if (!mPatterns.IsEmpty()) {
if (FcPatternGetString(mPatterns[0],
FC_FAMILY, 0, &name) == FcResultMatch) {
return NS_ConvertUTF8toUTF16((const char*)name);
}
}
// fall back to gfxFontEntry implementation (only works for sfnt fonts)
return gfxFontEntry::FamilyName();
}

#ifdef MOZ_GRAPHITE
void
gfxFcFontEntry::CheckForGraphiteTables()
Expand Down Expand Up @@ -793,16 +777,6 @@ class gfxFcFont : public gfxFT2FontBase {
return mPangoFont;
}

nsString GetFamilyName() {
PangoFontDescription *desc = pango_font_describe(GetPangoFont());
const char *name = pango_font_description_get_family(desc);
if (name) {
return NS_ConvertUTF8toUTF16(name);
} else {
return GetFontEntry()->FamilyName();
}
}

protected:
virtual bool ShapeText(gfxContext *aContext,
const PRUnichar *aText,
Expand Down Expand Up @@ -1985,22 +1959,6 @@ gfxPangoFontGroup::GetFontAt(int32_t i)
return GetBaseFont();
}

nsString
gfxPangoFontGroup::GetFamilyNameAt(int32_t i)
{
gfxFcFont* font = static_cast<gfxFcFont*>(GetFontAt(i));

if (font->GetFontEntry()->IsUserFont()) {
gfxFontFamily* family =
GetUserFontSet()->FindFamilyFor(font->GetFontEntry());
if (family) { // should never fail, but just in case...
return family->Name();
}
}

return font->GetFamilyName();
}

void
gfxPangoFontGroup::UpdateFontList()
{
Expand Down
2 changes: 0 additions & 2 deletions gfx/thebes/gfxPangoFonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class THEBES_API gfxPangoFontGroup : public gfxFontGroup {

virtual gfxFont *GetFontAt(int32_t i);

virtual nsString GetFamilyNameAt(int32_t i);

virtual void UpdateFontList();

virtual already_AddRefed<gfxFont>
Expand Down
8 changes: 5 additions & 3 deletions gfx/thebes/gfxUserFontSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ gfxUserFontSet::LoadNext(gfxMixedFontFamily *aFamily,
if (NS_SUCCEEDED(rv) &&
(fe = LoadFont(aFamily, aProxyEntry,
buffer, bufferLength))) {
UserFontCache::CacheFont(fe);
return STATUS_LOADED;
} else {
LogMessage(aFamily, aProxyEntry,
Expand Down Expand Up @@ -672,8 +671,8 @@ gfxUserFontSet::LoadFont(gfxMixedFontFamily *aFamily,
uint32_t(mGeneration)));
}
#endif
UserFontCache::CacheFont(fe);
ReplaceFontEntry(aFamily, aProxy, fe);
UserFontCache::CacheFont(fe);
} else {
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
Expand Down Expand Up @@ -764,7 +763,8 @@ gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
mFontEntry->mWeight != fe->mWeight ||
mFontEntry->mStretch != fe->mStretch ||
mFontEntry->mFeatureSettings != fe->mFeatureSettings ||
mFontEntry->mLanguageOverride != fe->mLanguageOverride) {
mFontEntry->mLanguageOverride != fe->mLanguageOverride ||
mFontEntry->mFamilyName != fe->mFamilyName) {
return false;
}

Expand All @@ -774,6 +774,8 @@ gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
void
gfxUserFontSet::UserFontCache::CacheFont(gfxFontEntry *aFontEntry)
{
NS_ASSERTION(aFontEntry->mFamilyName.Length() != 0,
"caching a font associated with no family yet");
if (!sUserFonts) {
sUserFonts = new nsTHashtable<Entry>;
sUserFonts->Init();
Expand Down
3 changes: 3 additions & 0 deletions gfx/thebes/gfxUserFontSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class gfxMixedFontFamily : public gfxFontFamily {
void AddFontEntry(gfxFontEntry *aFontEntry) {
nsRefPtr<gfxFontEntry> fe = aFontEntry;
mAvailableFonts.AppendElement(fe);
aFontEntry->mFamilyName = Name();
ResetCharacterMap();
}

Expand All @@ -90,6 +91,7 @@ class gfxMixedFontFamily : public gfxFontFamily {
if (fe == aOldFontEntry) {
// note that this may delete aOldFontEntry, if there's no
// other reference to it except from its family
aNewFontEntry->mFamilyName = Name();
mAvailableFonts[i] = aNewFontEntry;
break;
}
Expand Down Expand Up @@ -303,6 +305,7 @@ class THEBES_API gfxUserFontSet {
return mozilla::HashGeneric(principalHash,
nsURIHashKey::HashKey(aKey->mURI),
HashFeatures(aKey->mFontEntry->mFeatureSettings),
mozilla::HashString(aKey->mFontEntry->mFamilyName),
((uint32_t)aKey->mFontEntry->mItalic |
(aKey->mFontEntry->mWeight << 1) |
(aKey->mFontEntry->mStretch << 10) ) ^
Expand Down
39 changes: 0 additions & 39 deletions layout/inspector/src/nsFontFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,6 @@ nsFontFace::GetName(nsAString & aName)
NS_IMETHODIMP
nsFontFace::GetCSSFamilyName(nsAString & aCSSFamilyName)
{
if (mFontEntry->IsUserFont()) {
// for a user font, find CSS family name from the @font-face rule
nsUserFontSet* fontSet =
static_cast<nsUserFontSet*>(mFontGroup->GetUserFontSet());
if (fontSet) {
nsCSSFontFaceRule* rule = fontSet->FindRuleForEntry(mFontEntry);
if (rule) {
nsCOMPtr<nsIDOMCSSStyleDeclaration> style;
nsresult rv = rule->GetStyle(getter_AddRefs(style));
if (NS_SUCCEEDED(rv)) {
nsString familyName;
rv = style->GetPropertyValue(NS_LITERAL_STRING("font-family"),
aCSSFamilyName);
if (NS_SUCCEEDED(rv)) {
// GetPropertyValue gives us the name in "quotes"; strip them off.
// XXX What about possible CSS escapes - should we unescape here?
// Or don't we care, as this is just for display/debugging use?
if (aCSSFamilyName[0] == '"' &&
aCSSFamilyName[aCSSFamilyName.Length() - 1] == '"') {
aCSSFamilyName.Truncate(aCSSFamilyName.Length() - 1);
aCSSFamilyName.Cut(0, 1);
}
return NS_OK;
}
}
}
}
}

// look through the font-group's list for this entry
uint32_t count = mFontGroup->FontListLength();
for (uint32_t i = 0; i < count; ++i) {
if (mFontGroup->GetFontAt(i)->GetFontEntry() == mFontEntry) {
aCSSFamilyName = mFontGroup->GetFamilyNameAt(i);
return NS_OK;
}
}

// if it wasn't found there, query the font entry itself
aCSSFamilyName = mFontEntry->FamilyName();
return NS_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion layout/mathml/nsMathMLChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ SetFontFamily(nsStyleContext* aStyleContext,
// Set the font if it is an unicode table
// or if the same family name has been found
if (aGlyphTable == &gGlyphTableList->mUnicodeTable ||
fm->GetThebesFontGroup()->GetFamilyNameAt(0) == family) {
fm->GetThebesFontGroup()->GetFontAt(0)->GetFontEntry()->
FamilyName() == family) {
aFont.name = family;
aRenderingContext.SetFont(fm);
} else {
Expand Down

0 comments on commit f494b83

Please sign in to comment.