Bug 1464400 - Keep track of CSS generics when resolving to actual font families and faces, and expose as a new CSSGeneric attribute on InspectorFontFace. r=jwatt

This commit is contained in:
Jonathan Kew 2018-05-25 14:07:57 +01:00
Родитель ca7c5f1e17
Коммит 0cc7412d4f
21 изменённых файлов: 214 добавлений и 64 удалений

Просмотреть файл

@ -135,6 +135,8 @@ interface InspectorFontFace {
readonly attribute DOMString CSSFamilyName; // a family name that could be used in CSS font-family
// (not necessarily the actual name that was used,
// due to aliases, generics, localized names, etc)
readonly attribute DOMString CSSGeneric; // CSS generic (serif, sans-serif, etc) that was mapped
// to this font, if any (frequently empty!)
[NewObject,Throws] sequence<InspectorVariationAxis> getVariationAxes();
[NewObject,Throws] sequence<InspectorVariationInstance> getVariationInstances();

Просмотреть файл

@ -1426,7 +1426,7 @@ gfxDWriteFontList::GetStandardFamilyName(const nsAString& aFontName,
bool
gfxDWriteFontList::FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
@ -1436,7 +1436,7 @@ gfxDWriteFontList::FindAndAddFamilies(const nsAString& aFamily,
gfxFontFamily *ff = mFontSubstitutes.GetWeak(keyName);
if (ff) {
aOutput->AppendElement(ff);
aOutput->AppendElement(FamilyAndGeneric(ff));
return true;
}

Просмотреть файл

@ -427,7 +427,7 @@ public:
bool UseGDIFontTableAccess() { return mGDIFontTableAccess; }
bool FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;

Просмотреть файл

@ -1893,7 +1893,7 @@ gfxFcPlatformFontList::MakePlatformFont(const nsAString& aFontName,
bool
gfxFcPlatformFontList::FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
@ -1941,7 +1941,7 @@ gfxFcPlatformFontList::FindAndAddFamilies(const nsAString& aFamily,
// Because the FcConfigSubstitute call is quite expensive, we cache the
// actual font families found via this process. So check the cache first:
NS_ConvertUTF16toUTF8 familyToFind(familyName);
AutoTArray<gfxFontFamily*,10> cachedFamilies;
AutoTArray<FamilyAndGeneric,10> cachedFamilies;
if (mFcSubstituteCache.Get(familyToFind, &cachedFamilies)) {
if (cachedFamilies.IsEmpty()) {
return false;
@ -2090,7 +2090,7 @@ gfxFcPlatformFontList::GetStandardFamilyName(const nsAString& aFontName,
void
gfxFcPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
nsAtom* aLanguage,
nsTArray<gfxFontFamily*>& aFamilyList)
nsTArray<FamilyAndGeneric>& aFamilyList)
{
bool usePrefFontList = false;
@ -2147,7 +2147,10 @@ gfxFcPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
PrefFontList* prefFonts = FindGenericFamilies(genericToLookup, aLanguage);
NS_ASSERTION(prefFonts, "null generic font list");
aFamilyList.AppendElements(*prefFonts);
aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length());
for (auto& f : *prefFonts) {
aFamilyList.AppendElement(FamilyAndGeneric(f.get(), aGenericType));
}
}
void
@ -2258,14 +2261,14 @@ gfxFcPlatformFontList::FindGenericFamilies(const nsAString& aGeneric,
FcPatternGetString(font, FC_FAMILY, 0, &mappedGeneric);
if (mappedGeneric) {
NS_ConvertUTF8toUTF16 mappedGenericName(ToCharPtr(mappedGeneric));
AutoTArray<gfxFontFamily*,1> genericFamilies;
AutoTArray<FamilyAndGeneric,1> genericFamilies;
if (gfxPlatformFontList::FindAndAddFamilies(mappedGenericName,
&genericFamilies,
FindFamiliesFlags(0))) {
MOZ_ASSERT(genericFamilies.Length() == 1,
"expected a single family");
if (!prefFonts->Contains(genericFamilies[0])) {
prefFonts->AppendElement(genericFamilies[0]);
if (!prefFonts->Contains(genericFamilies[0].mFamily)) {
prefFonts->AppendElement(genericFamilies[0].mFamily);
bool foundLang =
!fcLang.IsEmpty() &&
PatternHasLang(font, ToFcChar8Ptr(fcLang.get()));

Просмотреть файл

@ -305,7 +305,7 @@ public:
uint32_t aLength) override;
bool FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;
@ -318,7 +318,7 @@ public:
// override to use fontconfig lookup for generics
void AddGenericFonts(mozilla::FontFamilyType aGenericType,
nsAtom* aLanguage,
nsTArray<gfxFontFamily*>& aFamilyList) override;
nsTArray<FamilyAndGeneric>& aFamilyList) override;
void ClearLangGroupPrefFonts() override;
@ -399,7 +399,7 @@ protected:
// these pointers will be invalidated. InitFontList() flushes the cache
// in this case.
nsDataHashtable<nsCStringHashKey,
nsTArray<gfxFontFamily*>> mFcSubstituteCache;
nsTArray<FamilyAndGeneric>> mFcSubstituteCache;
nsCOMPtr<nsITimer> mCheckFontUpdatesTimer;
nsCountedRef<FcConfig> mLastConfig;

Просмотреть файл

@ -631,12 +631,17 @@ protected:
};
struct gfxTextRange {
enum class MatchType : uint8_t {
enum class MatchType : uint16_t {
// The CSS generic that mapped to this font, if any. This field of
// the MatchType stores a FontFamilyType value as defined in the enum
// in gfxFontFamilyList.h.
kGenericMask = 0x00ff,
// Flags for recording the kind of font-matching that was used.
// Note that multiple flags may be set on a single range.
kFontGroup = 0x01,
kPrefsFallback = 0x02,
kSystemFallback = 0x04
kFontGroup = 0x0100,
kPrefsFallback = 0x0200,
kSystemFallback = 0x0400
};
gfxTextRange(uint32_t aStart, uint32_t aEnd,
gfxFont* aFont, MatchType aMatchType,

Просмотреть файл

@ -925,4 +925,29 @@ protected:
};
};
// Struct used in the gfxFontGroup font list to keep track of a font family
// together with the CSS generic (if any) that was mapped to it in this
// particular case (so it can be reported to the DevTools font inspector).
struct FamilyAndGeneric final {
FamilyAndGeneric()
: mFamily(nullptr)
, mGeneric(mozilla::FontFamilyType::eFamily_none)
{
}
FamilyAndGeneric(const FamilyAndGeneric& aOther)
: mFamily(aOther.mFamily)
, mGeneric(aOther.mGeneric)
{
}
explicit FamilyAndGeneric(gfxFontFamily* aFamily,
mozilla::FontFamilyType aGeneric =
mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily)
, mGeneric(aGeneric)
{
}
gfxFontFamily* mFamily;
mozilla::FontFamilyType mGeneric;
};
#endif

Просмотреть файл

@ -23,7 +23,7 @@ namespace mozilla {
* between unquoted and quoted names for serializaiton
*/
enum FontFamilyType : uint32_t {
enum FontFamilyType : uint8_t {
eFamily_none = 0, // used when finding generics
// explicitly named font family (e.g. Helvetica)

Просмотреть файл

@ -882,7 +882,7 @@ gfxGDIFontList::MakePlatformFont(const nsAString& aFontName,
bool
gfxGDIFontList::FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
@ -892,7 +892,7 @@ gfxGDIFontList::FindAndAddFamilies(const nsAString& aFamily,
gfxFontFamily *ff = mFontSubstitutes.GetWeak(keyName);
if (ff) {
aOutput->AppendElement(ff);
aOutput->AppendElement(FamilyAndGeneric(ff));
return true;
}

Просмотреть файл

@ -326,7 +326,7 @@ public:
gfxFontFamily* CreateFontFamily(const nsAString& aName) const override;
bool FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;

Просмотреть файл

@ -156,7 +156,7 @@ public:
uint32_t aLength) override;
bool FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;

Просмотреть файл

@ -1628,7 +1628,7 @@ static const char kSystemFont_system[] = "-apple-system";
bool
gfxMacPlatformFontList::FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)

Просмотреть файл

@ -751,7 +751,7 @@ gfxPlatformFontList::CheckFamily(gfxFontFamily *aFamily)
bool
gfxPlatformFontList::FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
@ -818,7 +818,7 @@ gfxPlatformFontList::FindAndAddFamilies(const nsAString& aFamily,
}
if (familyEntry) {
aOutput->AppendElement(familyEntry);
aOutput->AppendElement(FamilyAndGeneric(familyEntry));
return true;
}
@ -1011,12 +1011,12 @@ gfxPlatformFontList::GetFontFamiliesFromGenericFamilies(
gfxFontStyle style;
style.language = aLangGroup;
style.systemFont = false;
AutoTArray<gfxFontFamily*,10> families;
AutoTArray<FamilyAndGeneric,10> families;
FindAndAddFamilies(genericFamily, &families, FindFamiliesFlags(0),
&style);
for (gfxFontFamily* f : families) {
if (!aGenericFamilies->Contains(f)) {
aGenericFamilies->AppendElement(f);
for (const FamilyAndGeneric& f : families) {
if (!aGenericFamilies->Contains(f.mFamily)) {
aGenericFamilies->AppendElement(f.mFamily);
}
}
}
@ -1055,7 +1055,7 @@ gfxPlatformFontList::GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType,
void
gfxPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
nsAtom* aLanguage,
nsTArray<gfxFontFamily*>& aFamilyList)
nsTArray<FamilyAndGeneric>& aFamilyList)
{
// map lang ==> langGroup
nsAtom* langGroup = GetLangGroup(aLanguage);
@ -1068,7 +1068,10 @@ gfxPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
GetPrefFontsLangGroup(aGenericType, prefLang);
if (!prefFonts->IsEmpty()) {
aFamilyList.AppendElements(*prefFonts);
aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length());
for (auto& f : *prefFonts) {
aFamilyList.AppendElement(FamilyAndGeneric(f.get(), aGenericType));
}
}
}

Просмотреть файл

@ -166,7 +166,7 @@ public:
// Return true if any match was found and appended, false if none.
virtual bool
FindAndAddFamilies(const nsAString& aFamily,
nsTArray<gfxFontFamily*>* aOutput,
nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags,
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0);
@ -263,7 +263,7 @@ public:
virtual void
AddGenericFonts(mozilla::FontFamilyType aGenericType,
nsAtom* aLanguage,
nsTArray<gfxFontFamily*>& aFamilyList);
nsTArray<FamilyAndGeneric>& aFamilyList);
nsTArray<RefPtr<gfxFontFamily>>*
GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType,
@ -305,6 +305,8 @@ public:
bool AddWithLegacyFamilyName(const nsAString& aLegacyName,
gfxFontEntry* aFontEntry);
static const char* GetGenericName(mozilla::FontFamilyType aGenericType);
protected:
class InitOtherFamilyNamesRunnable : public mozilla::CancelableRunnable
{
@ -403,12 +405,13 @@ protected:
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0)
{
AutoTArray<gfxFontFamily*,1> families;
AutoTArray<FamilyAndGeneric,1> families;
return FindAndAddFamilies(aFamily,
&families,
aFlags,
aStyle,
aDevToCssSize) ? families[0] : nullptr;
aDevToCssSize)
? families[0].mFamily : nullptr;
}
// Lookup family name in global family list without substitutions or
@ -488,8 +491,6 @@ protected:
// helper function to map lang to lang group
nsAtom* GetLangGroup(nsAtom* aLanguage);
static const char* GetGenericName(mozilla::FontFamilyType aGenericType);
// gfxFontInfoLoader overrides, used to load in font cmaps
virtual void InitLoader() override;
virtual bool LoadFontInfo() override;

Просмотреть файл

@ -1796,7 +1796,7 @@ void
gfxFontGroup::BuildFontList()
{
// initialize fonts in the font family list
AutoTArray<gfxFontFamily*,10> fonts;
AutoTArray<FamilyAndGeneric,10> fonts;
gfxPlatformFontList *pfl = gfxPlatformFontList::PlatformFontList();
// lookup fonts in the fontlist
@ -1822,14 +1822,14 @@ gfxFontGroup::BuildFontList()
}
// build the fontlist from the specified families
for (gfxFontFamily* fontFamily : fonts) {
AddFamilyToFontList(fontFamily);
for (const auto& f : fonts) {
AddFamilyToFontList(f.mFamily, f.mGeneric);
}
}
void
gfxFontGroup::AddPlatformFont(const nsAString& aName,
nsTArray<gfxFontFamily*>& aFamilyList)
nsTArray<FamilyAndGeneric>& aFamilyList)
{
// First, look up in the user font set...
// If the fontSet matches the family, we must not look for a platform
@ -1853,7 +1853,8 @@ gfxFontGroup::AddPlatformFont(const nsAString& aName,
}
void
gfxFontGroup::AddFamilyToFontList(gfxFontFamily* aFamily)
gfxFontGroup::AddFamilyToFontList(gfxFontFamily* aFamily,
FontFamilyType aGeneric)
{
NS_ASSERTION(aFamily, "trying to add a null font family to fontlist");
AutoTArray<gfxFontEntry*,4> fontEntryList;
@ -1861,7 +1862,7 @@ gfxFontGroup::AddFamilyToFontList(gfxFontFamily* aFamily)
// add these to the fontlist
for (gfxFontEntry* fe : fontEntryList) {
if (!HasFont(fe)) {
FamilyFace ff(aFamily, fe);
FamilyFace ff(aFamily, fe, aGeneric);
if (fe->mIsUserFontContainer) {
ff.CheckState(mSkipDrawing);
}
@ -2064,7 +2065,7 @@ gfxFontGroup::GetDefaultFont()
}
gfxFont*
gfxFontGroup::GetFirstValidFont(uint32_t aCh)
gfxFontGroup::GetFirstValidFont(uint32_t aCh, FontFamilyType* aGeneric)
{
uint32_t count = mFonts.Length();
for (uint32_t i = 0; i < count; ++i) {
@ -2076,6 +2077,9 @@ gfxFontGroup::GetFirstValidFont(uint32_t aCh)
// already have a font?
gfxFont* font = ff.Font();
if (font) {
if (aGeneric) {
*aGeneric = ff.Generic();
}
return font;
}
@ -2099,9 +2103,15 @@ gfxFontGroup::GetFirstValidFont(uint32_t aCh)
font = GetFontAt(i, aCh);
if (font) {
if (aGeneric) {
*aGeneric = mFonts[i].Generic();
}
return font;
}
}
if (aGeneric) {
*aGeneric = eFamily_none;
}
return GetDefaultFont();
}
@ -2889,7 +2899,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
gfxFont* firstFont = GetFontAt(0, aCh);
if (firstFont) {
if (firstFont->HasCharacter(aCh)) {
*aMatchType = gfxTextRange::MatchType::kFontGroup;
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(mFonts[0].Generic());
return firstFont;
}
@ -2904,7 +2915,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
font = FindFallbackFaceForChar(mFonts[0].Family(), aCh);
}
if (font) {
*aMatchType = gfxTextRange::MatchType::kFontGroup;
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(mFonts[0].Generic());
return font;
}
}
@ -2954,6 +2966,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
gfxFont* font = ff.Font();
if (font) {
if (font->HasCharacter(aCh)) {
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(ff.Generic());
return font;
}
continue;
@ -2982,7 +2996,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
if (pfe && pfe->HasCharacter(aCh)) {
font = GetFontAt(i, aCh);
if (font) {
*aMatchType = gfxTextRange::MatchType::kFontGroup;
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(mFonts[i].Generic());
return font;
}
}
@ -2991,7 +3006,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
// build the font via GetFontAt
font = GetFontAt(i, aCh);
if (font) {
*aMatchType = gfxTextRange::MatchType::kFontGroup;
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(mFonts[i].Generic());
return font;
}
}
@ -3004,7 +3020,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
"should only do fallback once per font family");
font = FindFallbackFaceForChar(ff.Family(), aCh);
if (font) {
*aMatchType = gfxTextRange::MatchType::kFontGroup;
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(ff.Generic());
return font;
}
} else {
@ -3015,7 +3032,8 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
if (!fe->mIsUserFontContainer && !fe->IsUserFont()) {
font = FindFallbackFaceForChar(ff.Family(), aCh);
if (font) {
*aMatchType = gfxTextRange::MatchType::kFontGroup;
*aMatchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(ff.Generic());
return font;
}
}
@ -3084,11 +3102,13 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
// initialize prevFont to the group's primary font, so that this will be
// used for string-initial control chars, etc rather than risk hitting font
// fallback for these (bug 716229)
gfxFont *prevFont = GetFirstValidFont();
FontFamilyType generic = eFamily_none;
gfxFont *prevFont = GetFirstValidFont(' ', &generic);
// if we use the initial value of prevFont, we treat this as a match from
// the font group; fixes bug 978313
gfxTextRange::MatchType matchType = gfxTextRange::MatchType::kFontGroup;
gfxTextRange::MatchType matchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(generic);
for (uint32_t i = 0; i < aLength; i++) {
@ -3138,7 +3158,8 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
&& !gfxFontUtils::IsJoinControl(ch)
&& !gfxFontUtils::IsJoinCauser(prevCh)
&& !gfxFontUtils::IsVarSelector(ch)))) {
matchType = gfxTextRange::MatchType::kFontGroup;
matchType = gfxTextRange::MatchType::kFontGroup |
gfxTextRange::MatchType(mFonts[0].Generic());
} else {
font = FindFontForChar(ch, prevCh, nextCh, aRunScript, prevFont,
&matchType);
@ -3146,9 +3167,9 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
#ifndef RELEASE_OR_BETA
if (MOZ_UNLIKELY(mTextPerf)) {
if (matchType == gfxTextRange::MatchType::kPrefsFallback) {
if (matchType & gfxTextRange::MatchType::kPrefsFallback) {
mTextPerf->current.fallbackPrefs++;
} else if (matchType == gfxTextRange::MatchType::kSystemFallback) {
} else if (matchType & gfxTextRange::MatchType::kSystemFallback) {
mTextPerf->current.fallbackSystem++;
}
}

Просмотреть файл

@ -864,8 +864,11 @@ public:
virtual ~gfxFontGroup();
// Returns first valid font in the fontlist or default font.
// Initiates userfont loads if userfont not loaded
gfxFont* GetFirstValidFont(uint32_t aCh = 0x20);
// Initiates userfont loads if userfont not loaded.
// aGeneric: if non-null, returns the CSS generic type that was mapped to
// this font
gfxFont* GetFirstValidFont(uint32_t aCh = 0x20,
mozilla::FontFamilyType* aGeneric = nullptr);
// Returns the first font in the font-group that has an OpenType MATH table,
// or null if no such font is available. The GetMathConstant methods may be
@ -1025,13 +1028,15 @@ protected:
class FamilyFace {
public:
FamilyFace() : mFamily(nullptr), mFontEntry(nullptr),
mGeneric(mozilla::eFamily_none),
mFontCreated(false),
mLoading(false), mInvalid(false),
mCheckForFallbackFaces(false)
{ }
FamilyFace(gfxFontFamily* aFamily, gfxFont* aFont)
: mFamily(aFamily), mFontCreated(true),
FamilyFace(gfxFontFamily* aFamily, gfxFont* aFont,
mozilla::FontFamilyType aGeneric)
: mFamily(aFamily), mGeneric(aGeneric), mFontCreated(true),
mLoading(false), mInvalid(false), mCheckForFallbackFaces(false)
{
NS_ASSERTION(aFont, "font pointer must not be null");
@ -1042,8 +1047,9 @@ protected:
NS_ADDREF(aFont);
}
FamilyFace(gfxFontFamily* aFamily, gfxFontEntry* aFontEntry)
: mFamily(aFamily), mFontCreated(false),
FamilyFace(gfxFontFamily* aFamily, gfxFontEntry* aFontEntry,
mozilla::FontFamilyType aGeneric)
: mFamily(aFamily), mGeneric(aGeneric), mFontCreated(false),
mLoading(false), mInvalid(false), mCheckForFallbackFaces(false)
{
NS_ASSERTION(aFontEntry, "font entry pointer must not be null");
@ -1056,6 +1062,7 @@ protected:
FamilyFace(const FamilyFace& aOtherFamilyFace)
: mFamily(aOtherFamilyFace.mFamily),
mGeneric(aOtherFamilyFace.mGeneric),
mFontCreated(aOtherFamilyFace.mFontCreated),
mLoading(aOtherFamilyFace.mLoading),
mInvalid(aOtherFamilyFace.mInvalid),
@ -1088,6 +1095,7 @@ protected:
}
mFamily = aOther.mFamily;
mGeneric = aOther.mGeneric;
mFontCreated = aOther.mFontCreated;
mLoading = aOther.mLoading;
mInvalid = aOther.mInvalid;
@ -1112,6 +1120,8 @@ protected:
return mFontCreated ? mFont->GetFontEntry() : mFontEntry;
}
mozilla::FontFamilyType Generic() const { return mGeneric; }
bool IsUserFontContainer() const {
return FontEntry()->mIsUserFontContainer;
}
@ -1148,6 +1158,7 @@ protected:
gfxFont* MOZ_OWNING_REF mFont;
gfxFontEntry* MOZ_OWNING_REF mFontEntry;
};
mozilla::FontFamilyType mGeneric;
bool mFontCreated : 1;
bool mLoading : 1;
bool mInvalid : 1;
@ -1259,10 +1270,11 @@ protected:
// lookup and add a font with a given name (i.e. *not* a generic!)
void AddPlatformFont(const nsAString& aName,
nsTArray<gfxFontFamily*>& aFamilyList);
nsTArray<FamilyAndGeneric>& aFamilyList);
// do style selection and add entries to list
void AddFamilyToFontList(gfxFontFamily* aFamily);
void AddFamilyToFontList(gfxFontFamily* aFamily,
mozilla::FontFamilyType aGeneric);
};
// A "missing font recorder" is to be used during text-run creation to keep

Просмотреть файл

@ -6,6 +6,7 @@
#include "InspectorFontFace.h"
#include "gfxPlatformFontList.h"
#include "gfxTextRun.h"
#include "gfxUserFontSet.h"
#include "nsFontFaceLoader.h"
@ -55,6 +56,19 @@ InspectorFontFace::GetCSSFamilyName(nsAString& aCSSFamilyName)
aCSSFamilyName = mFontEntry->FamilyName();
}
void
InspectorFontFace::GetCSSGeneric(nsAString& aName)
{
auto genericType =
FontFamilyType(mMatchType & gfxTextRange::MatchType::kGenericMask);
if (genericType >= FontFamilyType::eFamily_generic_first &&
genericType <= FontFamilyType::eFamily_generic_last) {
aName.AssignASCII(gfxPlatformFontList::GetGenericName(genericType));
} else {
aName.Truncate(0);
}
}
ServoFontFaceRule*
InspectorFontFace::GetRule()
{

Просмотреть файл

@ -56,6 +56,7 @@ public:
bool FromSystemFallback();
void GetName(nsAString& aName);
void GetCSSFamilyName(nsAString& aCSSFamilyName);
void GetCSSGeneric(nsAString& aGeneric);
ServoFontFaceRule* GetRule();
int32_t SrcIndex();
void GetURI(nsAString& aURI);

Просмотреть файл

@ -28,3 +28,4 @@ support-files =
skip-if = (os == 'win' || os == 'linux' || os == 'mac') # bug 1433438, bug 1456855, bug 1456856
support-files =
test_fontVariationsAPI.css
[test_fontFaceGeneric.xul]

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window title="CSSGeneric attribute of InspectorFontFace"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="RunTest();">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
function RunTest() {
var rng = document.createRange();
var elem, fonts;
elem = document.getElementById("test1");
rng.selectNode(elem);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "one font found");
is(fonts[0].CSSGeneric, "serif", "font " + fonts[0].name + " was specified as CSS generic");
var serifFamily = fonts[0].CSSFamilyName;
elem = document.getElementById("test2");
elem.style.fontFamily = serifFamily + ", serif";
rng.selectNode(elem);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "one font found");
is(fonts[0].CSSFamilyName, serifFamily, "used the expected family (" + serifFamily + ")");
is(fonts[0].CSSGeneric, "", "font " + fonts[0].name + " was specified by name");
elem = document.getElementById("test3");
elem.getElementsByTagName("span")[0].style.fontFamily = serifFamily + ", serif";
rng.selectNode(elem);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 2, "two fonts found");
var checked = 0;
fonts.forEach(function(f) {
if (f.CSSFamilyName == serifFamily) {
is(f.CSSGeneric, "", "serif font " + f.name + " was specified by name");
checked++;
} else {
is(f.CSSGeneric, "monospace", "monospace font " + f.name + " was specified as generic");
checked++;
}
});
is(checked, 2, "two fonts checked");
SimpleTest.finish();
}
]]>
</script>
<!-- html:body contains elements the test will inspect -->
<body xmlns="http://www.w3.org/1999/xhtml">
<div id="test1" style="font-family: serif">test one</div>
<div id="test2" style="font-family: monospace">test two</div>
<div id="test3" style="font-family: monospace">test <span>three</span></div>
</body>
</window>

Просмотреть файл

@ -36,7 +36,7 @@ struct nsFont;
namespace mozilla {
class FontFamilyList;
struct FontFamilyName;
enum FontFamilyType : uint32_t;
enum FontFamilyType : uint8_t;
class SharedFontList;
enum class CSSPseudoElementType : uint8_t;
struct Keyframe;