Backed out 3 changesets (bug 1537594, bug 1537575) for causing build bustages on mathml/nsMathMLChar.cpp CLOSED TREE

Backed out changeset 7375a830b5ef (bug 1537594)
Backed out changeset 0cd1411e2fb3 (bug 1537575)
Backed out changeset c7565f50239a (bug 1537575)
This commit is contained in:
arthur.iakab 2019-04-01 23:41:04 +03:00
Родитель 8b801e06ee
Коммит cd473e09f4
37 изменённых файлов: 734 добавлений и 464 удалений

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

@ -15,7 +15,7 @@ const kFontNameListFmtSerif = "font.name-list.serif.%LANG%";
const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
const kFontNameListFmtMonospace = "font.name-list.monospace.%LANG%";
const kFontSizeFmtVariable = "font.size.variable.%LANG%";
const kFontSizeFmtFixed = "font.size.monospace.%LANG%";
const kFontSizeFmtFixed = "font.size.fixed.%LANG%";
const kFontMinSizeFmt = "font.minimum-size.%LANG%";
document.documentElement.addEventListener("dialoghelp", window.top.openPrefsHelp);

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

@ -3911,8 +3911,8 @@ gfxFontGroup* CanvasRenderingContext2D::GetCurrentFontStyle() {
GetAppUnitsValues(&perDevPixel, &perCSSPixel);
gfxFloat devToCssSize = gfxFloat(perDevPixel) / gfxFloat(perCSSPixel);
CurrentState().fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(
FontFamilyList(StyleGenericFontFamily::SansSerif), &style, tp,
nullptr, devToCssSize);
FontFamilyList(eFamily_sans_serif), &style, tp, nullptr,
devToCssSize);
if (CurrentState().fontGroup) {
CurrentState().font = kDefaultFontStyle;
} else {

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

@ -21,7 +21,7 @@ using namespace mozilla;
nsFont::nsFont(const FontFamilyList& aFontlist, nscoord aSize)
: fontlist(aFontlist), size(aSize) {}
nsFont::nsFont(StyleGenericFontFamily aGenericType, nscoord aSize)
nsFont::nsFont(FontFamilyType aGenericType, nscoord aSize)
: fontlist(aGenericType), size(aSize) {}
nsFont::nsFont(const nsFont& aOther) = default;

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

@ -21,6 +21,22 @@
struct gfxFontStyle;
// IDs for generic fonts
// NOTE: 0, 1 are reserved for the special IDs of the default variable
// and fixed fonts in the presentation context, see nsPresContext.h
const uint8_t kGenericFont_NONE = 0x00;
// Special
const uint8_t kGenericFont_moz_variable =
0x00; // for the default variable width font
const uint8_t kGenericFont_moz_fixed =
0x01; // our special "use the user's fixed font"
// CSS
const uint8_t kGenericFont_serif = 0x02;
const uint8_t kGenericFont_sans_serif = 0x04;
const uint8_t kGenericFont_monospace = 0x08;
const uint8_t kGenericFont_cursive = 0x10;
const uint8_t kGenericFont_fantasy = 0x20;
// Font structure.
struct nsFont {
typedef mozilla::FontStretch FontStretch;
@ -101,7 +117,7 @@ struct nsFont {
nsFont(const mozilla::FontFamilyList& aFontlist, nscoord aSize);
// initialize the font with a single generic
nsFont(mozilla::StyleGenericFontFamily, nscoord aSize);
nsFont(mozilla::FontFamilyType aGenericType, nscoord aSize);
// Make a copy of the given font
nsFont(const nsFont& aFont);

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

@ -1972,10 +1972,15 @@ bool gfxFcPlatformFontList::GetStandardFamilyName(const nsCString& aFontName,
}
void gfxFcPlatformFontList::AddGenericFonts(
mozilla::StyleGenericFontFamily aGenericType, nsAtom* aLanguage,
mozilla::FontFamilyType aGenericType, nsAtom* aLanguage,
nsTArray<FamilyAndGeneric>& aFamilyList) {
bool usePrefFontList = false;
// treat -moz-fixed as monospace
if (aGenericType == eFamily_moz_fixed) {
aGenericType = eFamily_monospace;
}
const char* generic = GetGenericName(aGenericType);
NS_ASSERTION(generic, "weird generic font type");
if (!generic) {

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

@ -301,7 +301,7 @@ class gfxFcPlatformFontList : public gfxPlatformFontList {
FcConfig* GetLastConfig() const { return mLastConfig; }
// override to use fontconfig lookup for generics
void AddGenericFonts(mozilla::StyleGenericFontFamily, nsAtom* aLanguage,
void AddGenericFonts(mozilla::FontFamilyType aGenericType, nsAtom* aLanguage,
nsTArray<FamilyAndGeneric>& aFamilyList) override;
void ClearLangGroupPrefFonts() override;

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

@ -9,7 +9,6 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/FontPropertyTypes.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/IntegerRange.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/SVGContextPaint.h"
@ -4001,11 +4000,10 @@ bool gfxFont::TryGetMathTable() {
void SharedFontList::Initialize() {
sEmpty = new SharedFontList();
for (auto i : IntegerRange(ArrayLength(sSingleGenerics))) {
auto type = static_cast<StyleGenericFontFamily>(i);
if (type != StyleGenericFontFamily::None) {
sSingleGenerics[i] = new SharedFontList(type);
}
for (uint8_t i = 0; i < uint8_t(eFamily_generic_count_including_special);
++i) {
auto type = static_cast<FontFamilyType>(i + uint8_t(eFamily_generic_first));
sSingleGenerics[i] = new SharedFontList(type);
}
}
@ -4021,4 +4019,4 @@ void SharedFontList::Shutdown() {
StaticRefPtr<SharedFontList> SharedFontList::sEmpty;
StaticRefPtr<SharedFontList>
SharedFontList::sSingleGenerics[size_t(StyleGenericFontFamily::MozEmoji)];
SharedFontList::sSingleGenerics[eFamily_generic_count_including_special];

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

@ -937,28 +937,28 @@ struct FontFamily {
// particular case (so it can be reported to the DevTools font inspector).
struct FamilyAndGeneric final {
FamilyAndGeneric()
: mFamily(), mGeneric(mozilla::StyleGenericFontFamily::None) {}
: mFamily(), mGeneric(mozilla::FontFamilyType::eFamily_none) {}
FamilyAndGeneric(const FamilyAndGeneric& aOther)
: mFamily(aOther.mFamily), mGeneric(aOther.mGeneric) {}
explicit FamilyAndGeneric(gfxFontFamily* aFamily,
mozilla::StyleGenericFontFamily aGeneric =
mozilla::StyleGenericFontFamily::None)
explicit FamilyAndGeneric(
gfxFontFamily* aFamily,
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily), mGeneric(aGeneric) {}
explicit FamilyAndGeneric(mozilla::fontlist::Family* aFamily,
mozilla::StyleGenericFontFamily aGeneric =
mozilla::StyleGenericFontFamily::None)
explicit FamilyAndGeneric(
mozilla::fontlist::Family* aFamily,
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily), mGeneric(aGeneric) {}
explicit FamilyAndGeneric(const FontFamily& aFamily,
mozilla::StyleGenericFontFamily aGeneric =
mozilla::StyleGenericFontFamily::None)
explicit FamilyAndGeneric(
const FontFamily& aFamily,
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily), mGeneric(aGeneric) {}
bool operator==(const FamilyAndGeneric& aOther) const {
return mFamily == aOther.mFamily && mGeneric == aOther.mGeneric;
return (mFamily == aOther.mFamily && mGeneric == aOther.mGeneric);
}
FontFamily mFamily;
mozilla::StyleGenericFontFamily mGeneric;
mozilla::FontFamilyType mGeneric;
};
#endif

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

@ -10,7 +10,6 @@
#include "nsDebug.h"
#include "nsISupportsImpl.h"
#include "nsString.h"
#include "nsStyleConsts.h"
#include "nsUnicharUtils.h"
#include "nsTArray.h"
#include "mozilla/MemoryReporting.h"
@ -20,70 +19,116 @@
namespace mozilla {
/**
* type of font family name, either a name (e.g. Helvetica) or a
* generic (e.g. serif, sans-serif), with the ability to distinguish
* between unquoted and quoted names for serializaiton
*/
enum FontFamilyType : uint8_t {
eFamily_none = 0, // used when finding generics
// explicitly named font family (e.g. Helvetica)
eFamily_named,
eFamily_named_quoted,
// generics
eFamily_serif, // pref font code relies on this ordering!!!
eFamily_sans_serif,
eFamily_monospace,
eFamily_cursive,
eFamily_fantasy,
// special
eFamily_moz_variable,
eFamily_moz_fixed,
eFamily_moz_emoji,
eFamily_generic_first = eFamily_serif,
eFamily_generic_last = eFamily_fantasy,
eFamily_generic_last_including_special = eFamily_moz_emoji,
eFamily_generic_count = eFamily_generic_last - eFamily_generic_first + 1,
eFamily_generic_count_including_special =
eFamily_generic_last_including_special - eFamily_generic_first + 1,
};
enum QuotedName { eQuotedName, eUnquotedName };
/**
* font family name, an Atom for the name if not a generic and
* a font type indicated named family or which generic family
*/
struct FontFamilyName final {
using Syntax = StyleFontFamilyNameSyntax;
FontFamilyName() = delete;
FontFamilyName() : mType(eFamily_none) {}
// named font family - e.g. Helvetica
explicit FontFamilyName(nsAtom* aFamilyName, Syntax aSyntax)
: mName(aFamilyName), mSyntax(aSyntax) {}
explicit FontFamilyName(const nsACString& aFamilyName, Syntax aSyntax)
: mName(NS_Atomize(aFamilyName)), mSyntax(aSyntax) {}
// generic font family - e.g. sans-serif
explicit FontFamilyName(StyleGenericFontFamily aGeneric)
: mGeneric(aGeneric) {
MOZ_ASSERT(mGeneric != StyleGenericFontFamily::None);
explicit FontFamilyName(nsAtom* aFamilyName,
QuotedName aQuoted = eUnquotedName) {
mType = (aQuoted == eQuotedName) ? eFamily_named_quoted : eFamily_named;
mName = aFamilyName;
}
FontFamilyName(const FontFamilyName&) = default;
explicit FontFamilyName(const nsACString& aFamilyName,
QuotedName aQuoted = eUnquotedName) {
mType = (aQuoted == eQuotedName) ? eFamily_named_quoted : eFamily_named;
mName = NS_Atomize(aFamilyName);
}
bool IsNamed() const { return !!mName; }
// generic font family - e.g. sans-serif
explicit FontFamilyName(FontFamilyType aType) {
NS_ASSERTION(aType != eFamily_named && aType != eFamily_named_quoted &&
aType != eFamily_none,
"expected a generic font type");
mName = nullptr;
mType = aType;
}
FontFamilyName(const FontFamilyName& aCopy) {
mType = aCopy.mType;
mName = aCopy.mName;
}
bool IsNamed() const {
return mType == eFamily_named || mType == eFamily_named_quoted;
}
bool IsGeneric() const { return !IsNamed(); }
void AppendToString(nsACString& aFamilyList, bool aQuotes = true) const {
if (IsNamed()) {
if (mSyntax == Syntax::Identifiers) {
return aFamilyList.Append(nsAtomCString(mName));
}
if (aQuotes) {
aFamilyList.Append('"');
}
aFamilyList.Append(nsAtomCString(mName));
if (aQuotes) {
aFamilyList.Append('"');
}
return;
}
switch (mGeneric) {
case StyleGenericFontFamily::None:
case StyleGenericFontFamily::MozEmoji:
MOZ_FALLTHROUGH_ASSERT("Should never appear in a font-family name!");
case StyleGenericFontFamily::Serif:
switch (mType) {
case eFamily_named:
aFamilyList.Append(nsAtomCString(mName));
break;
case eFamily_named_quoted:
if (aQuotes) {
aFamilyList.Append('"');
}
aFamilyList.Append(nsAtomCString(mName));
if (aQuotes) {
aFamilyList.Append('"');
}
break;
case eFamily_serif:
aFamilyList.AppendLiteral("serif");
break;
case StyleGenericFontFamily::SansSerif:
case eFamily_sans_serif:
aFamilyList.AppendLiteral("sans-serif");
break;
case StyleGenericFontFamily::Monospace:
case eFamily_monospace:
aFamilyList.AppendLiteral("monospace");
break;
case StyleGenericFontFamily::Cursive:
case eFamily_cursive:
aFamilyList.AppendLiteral("cursive");
break;
case StyleGenericFontFamily::Fantasy:
case eFamily_fantasy:
aFamilyList.AppendLiteral("fantasy");
break;
case eFamily_moz_fixed:
aFamilyList.AppendLiteral("-moz-fixed");
break;
default:
MOZ_ASSERT_UNREACHABLE("Unknown generic font-family!");
break;
}
}
@ -96,33 +141,32 @@ struct FontFamilyName final {
NS_ASSERTION(aFamilyOrGenericName.FindChar(',') == -1,
"Convert method should only be passed a single family name");
auto genericType = StyleGenericFontFamily::None;
FontFamilyType genericType = eFamily_none;
if (aFamilyOrGenericName.LowerCaseEqualsLiteral("serif")) {
genericType = StyleGenericFontFamily::Serif;
genericType = eFamily_serif;
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("sans-serif")) {
genericType = StyleGenericFontFamily::SansSerif;
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("monospace") ||
aFamilyOrGenericName.LowerCaseEqualsLiteral("-moz-fixed")) {
genericType = StyleGenericFontFamily::Monospace;
genericType = eFamily_sans_serif;
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("monospace")) {
genericType = eFamily_monospace;
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("cursive")) {
genericType = StyleGenericFontFamily::Cursive;
genericType = eFamily_cursive;
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("fantasy")) {
genericType = StyleGenericFontFamily::Fantasy;
genericType = eFamily_fantasy;
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("-moz-fixed")) {
genericType = eFamily_moz_fixed;
} else {
return FontFamilyName(aFamilyOrGenericName, Syntax::Identifiers);
return FontFamilyName(aFamilyOrGenericName, eUnquotedName);
}
return FontFamilyName(genericType);
}
RefPtr<nsAtom> mName; // null if mGeneric != Default
StyleFontFamilyNameSyntax mSyntax = StyleFontFamilyNameSyntax::Quoted;
StyleGenericFontFamily mGeneric = StyleGenericFontFamily::None;
FontFamilyType mType;
RefPtr<nsAtom> mName; // null if mType != eFamily_named
};
inline bool operator==(const FontFamilyName& a, const FontFamilyName& b) {
return a.mName == b.mName && a.mSyntax == b.mSyntax &&
a.mGeneric == b.mGeneric;
return a.mType == b.mType && a.mName == b.mName;
}
/**
@ -133,25 +177,36 @@ inline bool operator==(const FontFamilyName& a, const FontFamilyName& b) {
* FontFamilyName) in Rust.
*/
class SharedFontList {
using Syntax = StyleFontFamilyNameSyntax;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedFontList);
SharedFontList() = default;
SharedFontList() {}
explicit SharedFontList(StyleGenericFontFamily aGenericType)
explicit SharedFontList(FontFamilyType aGenericType)
: mNames{FontFamilyName(aGenericType)} {}
SharedFontList(nsAtom* aFamilyName, Syntax aSyntax)
: mNames{FontFamilyName(aFamilyName, aSyntax)} {}
SharedFontList(nsAtom* aFamilyName, QuotedName aQuoted)
: mNames{FontFamilyName(aFamilyName, aQuoted)} {}
SharedFontList(const nsACString& aFamilyName, Syntax aSyntax)
: mNames{FontFamilyName(aFamilyName, aSyntax)} {}
SharedFontList(const nsACString& aFamilyName, QuotedName aQuoted)
: mNames{FontFamilyName(aFamilyName, aQuoted)} {}
explicit SharedFontList(const FontFamilyName& aName) : mNames{aName} {}
explicit SharedFontList(nsTArray<FontFamilyName>&& aNames)
: mNames(std::move(aNames)) {}
FontFamilyType FirstGeneric() const {
for (const FontFamilyName& name : mNames) {
if (name.IsGeneric()) {
return name.mType;
}
}
return eFamily_none;
}
bool HasGeneric() const { return FirstGeneric() != eFamily_none; }
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
size_t n = 0;
n += aMallocSizeOf(this);
@ -173,7 +228,7 @@ class SharedFontList {
static void Shutdown();
static StaticRefPtr<SharedFontList> sEmpty;
static StaticRefPtr<SharedFontList>
sSingleGenerics[size_t(StyleGenericFontFamily::MozEmoji)];
sSingleGenerics[eFamily_generic_count_including_special];
private:
~SharedFontList() = default;
@ -185,29 +240,37 @@ class SharedFontList {
* font type is used to preserve the variable font fallback behavior
*/
class FontFamilyList {
using Syntax = StyleFontFamilyNameSyntax;
public:
FontFamilyList() : mFontlist(WrapNotNull(SharedFontList::sEmpty.get())) {}
FontFamilyList()
: mFontlist(WrapNotNull(SharedFontList::sEmpty.get())),
mDefaultFontType(eFamily_none) {}
explicit FontFamilyList(StyleGenericFontFamily aGenericType)
: mFontlist(MakeNotNull<SharedFontList*>(aGenericType)) {}
explicit FontFamilyList(FontFamilyType aGenericType)
: mFontlist(MakeNotNull<SharedFontList*>(aGenericType)),
mDefaultFontType(eFamily_none) {}
FontFamilyList(nsAtom* aFamilyName, Syntax aSyntax)
: mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aSyntax)) {}
FontFamilyList(nsAtom* aFamilyName, QuotedName aQuoted)
: mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aQuoted)),
mDefaultFontType(eFamily_none) {}
FontFamilyList(const nsACString& aFamilyName, Syntax aSyntax)
: mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aSyntax)) {}
FontFamilyList(const nsACString& aFamilyName, QuotedName aQuoted)
: mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aQuoted)),
mDefaultFontType(eFamily_none) {}
explicit FontFamilyList(const FontFamilyName& aName)
: mFontlist(MakeNotNull<SharedFontList*>(aName)),
mDefaultFontType(eFamily_none) {}
explicit FontFamilyList(nsTArray<FontFamilyName>&& aNames)
: mFontlist(MakeNotNull<SharedFontList*>(std::move(aNames))) {}
: mFontlist(MakeNotNull<SharedFontList*>(std::move(aNames))),
mDefaultFontType(eFamily_none) {}
FontFamilyList(const FontFamilyList& aOther)
: mFontlist(aOther.mFontlist),
mDefaultFontType(aOther.mDefaultFontType) {}
explicit FontFamilyList(NotNull<SharedFontList*> aFontList)
: mFontlist(aFontList) {}
: mFontlist(aFontList), mDefaultFontType(eFamily_none) {}
void SetFontlist(nsTArray<FontFamilyName>&& aNames) {
mFontlist = MakeNotNull<SharedFontList*>(std::move(aNames));
@ -229,12 +292,13 @@ class FontFamilyList {
mDefaultFontType == aFontlist.mDefaultFontType;
}
FontFamilyType FirstGeneric() const { return mFontlist->FirstGeneric(); }
bool HasGeneric() const { return mFontlist->HasGeneric(); }
bool HasDefaultGeneric() const {
if (mDefaultFontType == StyleGenericFontFamily::None) {
return false;
}
for (const FontFamilyName& name : mFontlist->mNames) {
if (name.mGeneric == mDefaultFontType) {
if (name.mType == mDefaultFontType) {
return true;
}
}
@ -249,8 +313,7 @@ class FontFamilyList {
for (uint32_t i = 0; i < len; i++) {
const FontFamilyName name = mFontlist->mNames[i];
if (name.IsGeneric()) {
if (name.mGeneric == StyleGenericFontFamily::Cursive ||
name.mGeneric == StyleGenericFontFamily::Fantasy) {
if (name.mType == eFamily_cursive || name.mType == eFamily_fantasy) {
continue;
}
if (i > 0) {
@ -266,10 +329,10 @@ class FontFamilyList {
return false;
}
void PrependGeneric(StyleGenericFontFamily aGeneric) {
void PrependGeneric(FontFamilyType aType) {
nsTArray<FontFamilyName> names;
names.AppendElements(mFontlist->mNames);
names.InsertElementAt(0, FontFamilyName(aGeneric));
names.InsertElementAt(0, FontFamilyName(aType));
SetFontlist(std::move(names));
}
@ -285,11 +348,11 @@ class FontFamilyList {
const FontFamilyName& name = names[i];
name.AppendToString(aFamilyList, aQuotes);
}
if (aIncludeDefault && mDefaultFontType != StyleGenericFontFamily::None) {
if (aIncludeDefault && mDefaultFontType != eFamily_none) {
if (!aFamilyList.IsEmpty()) {
aFamilyList.Append(',');
}
if (mDefaultFontType == StyleGenericFontFamily::Serif) {
if (mDefaultFontType == eFamily_serif) {
aFamilyList.AppendLiteral("serif");
} else {
aFamilyList.AppendLiteral("sans-serif");
@ -312,11 +375,10 @@ class FontFamilyList {
return false;
}
StyleGenericFontFamily GetDefaultFontType() const { return mDefaultFontType; }
void SetDefaultFontType(StyleGenericFontFamily aType) {
NS_ASSERTION(aType == StyleGenericFontFamily::None ||
aType == StyleGenericFontFamily::Serif ||
aType == StyleGenericFontFamily::SansSerif,
FontFamilyType GetDefaultFontType() const { return mDefaultFontType; }
void SetDefaultFontType(FontFamilyType aType) {
NS_ASSERTION(aType == eFamily_none || aType == eFamily_serif ||
aType == eFamily_sans_serif,
"default font type must be either serif or sans-serif");
mDefaultFontType = aType;
}
@ -334,8 +396,7 @@ class FontFamilyList {
protected:
NotNull<RefPtr<SharedFontList>> mFontlist;
StyleGenericFontFamily mDefaultFontType =
StyleGenericFontFamily::None; // or serif, or sans-serif
FontFamilyType mDefaultFontType; // none, serif or sans-serif
};
inline bool operator==(const FontFamilyList& a, const FontFamilyList& b) {

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

@ -891,7 +891,7 @@ void gfxPlatformFontList::RemoveCmap(const gfxCharacterMap* aCharMap) {
}
void gfxPlatformFontList::ResolveGenericFontNames(
StyleGenericFontFamily aGenericType, eFontPrefLang aPrefLang,
FontFamilyType aGenericType, eFontPrefLang aPrefLang,
PrefFontList* aGenericFamilies) {
const char* langGroupStr = GetPrefLangName(aPrefLang);
const char* generic = GetGenericName(aGenericType);
@ -957,8 +957,13 @@ void gfxPlatformFontList::GetFontFamiliesFromGenericFamilies(
}
gfxPlatformFontList::PrefFontList* gfxPlatformFontList::GetPrefFontsLangGroup(
StyleGenericFontFamily aGenericType, eFontPrefLang aPrefLang) {
if (aGenericType == StyleGenericFontFamily::MozEmoji) {
mozilla::FontFamilyType aGenericType, eFontPrefLang aPrefLang) {
// treat -moz-fixed as monospace
if (aGenericType == eFamily_moz_fixed) {
aGenericType = eFamily_monospace;
}
if (aGenericType == eFamily_moz_emoji) {
// Emoji font has no lang
PrefFontList* prefFonts = mEmojiPrefFont.get();
if (MOZ_UNLIKELY(!prefFonts)) {
@ -969,18 +974,17 @@ gfxPlatformFontList::PrefFontList* gfxPlatformFontList::GetPrefFontsLangGroup(
return prefFonts;
}
auto index = static_cast<size_t>(aGenericType);
PrefFontList* prefFonts = mLangGroupPrefFonts[aPrefLang][index].get();
PrefFontList* prefFonts = mLangGroupPrefFonts[aPrefLang][aGenericType].get();
if (MOZ_UNLIKELY(!prefFonts)) {
prefFonts = new PrefFontList;
ResolveGenericFontNames(aGenericType, aPrefLang, prefFonts);
mLangGroupPrefFonts[aPrefLang][index].reset(prefFonts);
mLangGroupPrefFonts[aPrefLang][aGenericType].reset(prefFonts);
}
return prefFonts;
}
void gfxPlatformFontList::AddGenericFonts(
mozilla::StyleGenericFontFamily aGenericType, nsAtom* aLanguage,
mozilla::FontFamilyType aGenericType, nsAtom* aLanguage,
nsTArray<FamilyAndGeneric>& aFamilyList) {
// map lang ==> langGroup
nsAtom* langGroup = GetLangGroup(aLanguage);
@ -1278,10 +1282,10 @@ void gfxPlatformFontList::AppendPrefLang(eFontPrefLang aPrefLangs[],
}
}
mozilla::StyleGenericFontFamily gfxPlatformFontList::GetDefaultGeneric(
mozilla::FontFamilyType gfxPlatformFontList::GetDefaultGeneric(
eFontPrefLang aLang) {
if (aLang == eFontPrefLang_Emoji) {
return StyleGenericFontFamily::MozEmoji;
return eFamily_moz_emoji;
}
// initialize lang group pref font defaults (i.e. serif/sans-serif)
@ -1293,9 +1297,9 @@ mozilla::StyleGenericFontFamily gfxPlatformFontList::GetDefaultGeneric(
nsAutoCString serifOrSans;
Preferences::GetCString(prefDefaultFontType.get(), serifOrSans);
if (serifOrSans.EqualsLiteral("sans-serif")) {
mDefaultGenericsLangGroup[i] = StyleGenericFontFamily::SansSerif;
mDefaultGenericsLangGroup[i] = eFamily_sans_serif;
} else {
mDefaultGenericsLangGroup[i] = StyleGenericFontFamily::Serif;
mDefaultGenericsLangGroup[i] = eFamily_serif;
}
}
}
@ -1303,7 +1307,7 @@ mozilla::StyleGenericFontFamily gfxPlatformFontList::GetDefaultGeneric(
if (uint32_t(aLang) < ArrayLength(gPrefLangNames)) {
return mDefaultGenericsLangGroup[uint32_t(aLang)];
}
return StyleGenericFontFamily::Serif;
return eFamily_serif;
}
FontFamily gfxPlatformFontList::GetDefaultFont(const gfxFontStyle* aStyle) {
@ -1339,7 +1343,7 @@ nsAtom* gfxPlatformFontList::GetLangGroup(nsAtom* aLanguage) {
}
/* static */ const char* gfxPlatformFontList::GetGenericName(
StyleGenericFontFamily aGenericType) {
FontFamilyType aGenericType) {
static const char kGeneric_serif[] = "serif";
static const char kGeneric_sans_serif[] = "sans-serif";
static const char kGeneric_monospace[] = "monospace";
@ -1347,22 +1351,32 @@ nsAtom* gfxPlatformFontList::GetLangGroup(nsAtom* aLanguage) {
static const char kGeneric_fantasy[] = "fantasy";
// type should be standard generic type at this point
NS_ASSERTION(aGenericType >= eFamily_serif && aGenericType <= eFamily_fantasy,
"standard generic font family type required");
// map generic type to string
const char* generic = nullptr;
switch (aGenericType) {
case StyleGenericFontFamily::Serif:
return kGeneric_serif;
case StyleGenericFontFamily::SansSerif:
return kGeneric_sans_serif;
case StyleGenericFontFamily::Monospace:
return kGeneric_monospace;
case StyleGenericFontFamily::Cursive:
return kGeneric_cursive;
case StyleGenericFontFamily::Fantasy:
return kGeneric_fantasy;
case eFamily_serif:
generic = kGeneric_serif;
break;
case eFamily_sans_serif:
generic = kGeneric_sans_serif;
break;
case eFamily_monospace:
generic = kGeneric_monospace;
break;
case eFamily_cursive:
generic = kGeneric_cursive;
break;
case eFamily_fantasy:
generic = kGeneric_fantasy;
break;
default:
MOZ_ASSERT_UNREACHABLE("Unknown generic");
return nullptr;
break;
}
return generic;
}
void gfxPlatformFontList::InitLoader() {
@ -1490,8 +1504,9 @@ void gfxPlatformFontList::ClearLangGroupPrefFonts() {
for (uint32_t i = eFontPrefLang_First;
i < eFontPrefLang_First + eFontPrefLang_Count; i++) {
auto& prefFontsLangGroup = mLangGroupPrefFonts[i];
for (auto& pref : prefFontsLangGroup) {
pref = nullptr;
for (uint32_t j = eFamily_generic_first;
j < eFamily_generic_first + eFamily_generic_count; j++) {
prefFontsLangGroup[j] = nullptr;
}
}
mCJKPrefLangs.Clear();
@ -1549,7 +1564,9 @@ void gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
for (uint32_t i = eFontPrefLang_First;
i < eFontPrefLang_First + eFontPrefLang_Count; i++) {
auto& prefFontsLangGroup = mLangGroupPrefFonts[i];
for (const UniquePtr<PrefFontList>& pf : prefFontsLangGroup) {
for (uint32_t j = eFamily_generic_first;
j < eFamily_generic_first + eFamily_generic_count; j++) {
PrefFontList* pf = prefFontsLangGroup[j].get();
if (pf) {
aSizes->mFontListSize += pf->ShallowSizeOfExcludingThis(aMallocSizeOf);
}

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

@ -258,12 +258,12 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
aLoaderState = (uint32_t)mState;
}
virtual void AddGenericFonts(mozilla::StyleGenericFontFamily aGenericType,
virtual void AddGenericFonts(mozilla::FontFamilyType aGenericType,
nsAtom* aLanguage,
nsTArray<FamilyAndGeneric>& aFamilyList);
PrefFontList* GetPrefFontsLangGroup(
mozilla::StyleGenericFontFamily aGenericType, eFontPrefLang aPrefLang);
PrefFontList* GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType,
eFontPrefLang aPrefLang);
// in some situations, need to make decisions about ambiguous characters, may
// need to look at multiple pref langs
@ -295,7 +295,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
eFontPrefLang aAddLang);
// default serif/sans-serif choice based on font.default.xxx prefs
mozilla::StyleGenericFontFamily GetDefaultGeneric(eFontPrefLang aLang);
mozilla::FontFamilyType GetDefaultGeneric(eFontPrefLang aLang);
// Returns true if the font family whitelist is not empty.
bool IsFontFamilyWhitelistActive();
@ -305,8 +305,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
bool AddWithLegacyFamilyName(const nsACString& aLegacyName,
gfxFontEntry* aFontEntry);
static const char* GetGenericName(
mozilla::StyleGenericFontFamily aGenericType);
static const char* GetGenericName(mozilla::FontFamilyType aGenericType);
protected:
class InitOtherFamilyNamesRunnable : public mozilla::CancelableRunnable {
@ -487,7 +486,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
void RebuildLocalFonts();
void ResolveGenericFontNames(mozilla::StyleGenericFontFamily aGenericType,
void ResolveGenericFontNames(mozilla::FontFamilyType aGenericType,
eFontPrefLang aPrefLang,
PrefFontList* aGenericFamilies);
@ -553,9 +552,8 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
mozilla::UniquePtr<nsTHashtable<nsCStringHashKey>> mOtherNamesMissed;
typedef mozilla::RangedArray<mozilla::UniquePtr<PrefFontList>,
size_t(mozilla::StyleGenericFontFamily::None),
size_t(
mozilla::StyleGenericFontFamily::MozEmoji)>
mozilla::eFamily_generic_first,
mozilla::eFamily_generic_count>
PrefFontsForLangGroup;
mozilla::RangedArray<PrefFontsForLangGroup, eFontPrefLang_First,
eFontPrefLang_Count>
@ -591,7 +589,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
nsLanguageAtomService* mLangService;
nsTArray<uint32_t> mCJKPrefLangs;
nsTArray<mozilla::StyleGenericFontFamily> mDefaultGenericsLangGroup;
nsTArray<mozilla::FontFamilyType> mDefaultGenericsLangGroup;
bool mFontFamilyWhitelistActive;
};

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

@ -1535,7 +1535,7 @@ void gfxTextRun::SetSpaceGlyph(gfxFont* aFont, DrawTarget* aDrawTarget,
aDrawTarget, &space, 1, gfxShapedWord::HashMix(0, ' '), Script::LATIN,
vertical, mAppUnitsPerDevUnit, flags, roundingFlags, nullptr);
if (sw) {
AddGlyphRun(aFont, FontMatchType::Kind::kFontGroup, aCharIndex, false,
AddGlyphRun(aFont, FontMatchType::kFontGroup, aCharIndex, false,
aOrientation);
CopyGlyphDataFrom(sw, aCharIndex);
GetCharacterGlyphs()[aCharIndex].SetIsSpace();
@ -1560,7 +1560,7 @@ bool gfxTextRun::SetSpaceGlyphIfSimple(gfxFont* aFont, uint32_t aCharIndex,
return false;
}
AddGlyphRun(aFont, FontMatchType::Kind::kFontGroup, aCharIndex, false,
AddGlyphRun(aFont, FontMatchType::kFontGroup, aCharIndex, false,
aOrientation);
CompressedGlyph g =
CompressedGlyph::MakeSimpleGlyph(spaceWidthAppUnits, spaceGlyph);
@ -1715,7 +1715,7 @@ void gfxFontGroup::BuildFontList() {
MOZ_ASSERT_UNREACHABLE("broken FontFamilyName, no atom!");
}
} else {
pfl->AddGenericFonts(name.mGeneric, mStyle.language, fonts);
pfl->AddGenericFonts(name.mType, mStyle.language, fonts);
if (mTextPerf) {
mTextPerf->current.genericLookups++;
}
@ -1723,7 +1723,7 @@ void gfxFontGroup::BuildFontList() {
}
// if necessary, append default generic onto the end
if (mFamilyList.GetDefaultFontType() != StyleGenericFontFamily::None &&
if (mFamilyList.GetDefaultFontType() != eFamily_none &&
!mFamilyList.HasDefaultGeneric()) {
pfl->AddGenericFonts(mFamilyList.GetDefaultFontType(), mStyle.language,
fonts);
@ -1761,7 +1761,7 @@ void gfxFontGroup::AddPlatformFont(const nsACString& aName,
}
void gfxFontGroup::AddFamilyToFontList(gfxFontFamily* aFamily,
StyleGenericFontFamily aGeneric) {
FontFamilyType aGeneric) {
if (!aFamily) {
MOZ_ASSERT_UNREACHABLE("don't try to add a null font family!");
return;
@ -1963,7 +1963,7 @@ gfxFont* gfxFontGroup::GetDefaultFont() {
}
gfxFont* gfxFontGroup::GetFirstValidFont(uint32_t aCh,
StyleGenericFontFamily* aGeneric) {
FontFamilyType* aGeneric) {
uint32_t count = mFonts.Length();
for (uint32_t i = 0; i < count; ++i) {
FamilyFace& ff = mFonts[i];
@ -2006,7 +2006,7 @@ gfxFont* gfxFontGroup::GetFirstValidFont(uint32_t aCh,
}
}
if (aGeneric) {
*aGeneric = StyleGenericFontFamily::None;
*aGeneric = eFamily_none;
}
return GetDefaultFont();
}
@ -2078,7 +2078,7 @@ already_AddRefed<gfxTextRun> gfxFontGroup::MakeSpaceTextRun(
// Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
// them, and always create at least size 1 fonts, i.e. they still
// render something for size 0 fonts.
textRun->AddGlyphRun(font, FontMatchType::Kind::kFontGroup, 0, false,
textRun->AddGlyphRun(font, FontMatchType::kFontGroup, 0, false,
orientation);
} else {
if (font->GetSpaceGlyph()) {
@ -2116,8 +2116,8 @@ already_AddRefed<gfxTextRun> gfxFontGroup::MakeBlankTextRun(
if (orientation == ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED) {
orientation = ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
}
textRun->AddGlyphRun(GetFirstValidFont(), FontMatchType::Kind::kFontGroup, 0,
false, orientation);
textRun->AddGlyphRun(GetFirstValidFont(), FontMatchType::kFontGroup, 0, false,
orientation);
return textRun.forget();
}
@ -2274,10 +2274,9 @@ void gfxFontGroup::InitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
"len %d weight: %g stretch: %g%% style: %s size: %6.2f %zu-byte "
"TEXTRUN [%s] ENDTEXTRUN\n",
(mStyle.systemFont ? "textrunui" : "textrun"), families.get(),
(mFamilyList.GetDefaultFontType() == StyleGenericFontFamily::Serif
(mFamilyList.GetDefaultFontType() == eFamily_serif
? "serif"
: (mFamilyList.GetDefaultFontType() ==
StyleGenericFontFamily::SansSerif
: (mFamilyList.GetDefaultFontType() == eFamily_sans_serif
? "sans-serif"
: "none")),
lang.get(), static_cast<int>(Script::LATIN), aLength,
@ -2321,11 +2320,9 @@ void gfxFontGroup::InitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
"len %d weight: %g stretch: %g%% style: %s size: %6.2f "
"%zu-byte TEXTRUN [%s] ENDTEXTRUN\n",
(mStyle.systemFont ? "textrunui" : "textrun"), families.get(),
(mFamilyList.GetDefaultFontType() ==
StyleGenericFontFamily::Serif
(mFamilyList.GetDefaultFontType() == eFamily_serif
? "serif"
: (mFamilyList.GetDefaultFontType() ==
StyleGenericFontFamily::SansSerif
: (mFamilyList.GetDefaultFontType() == eFamily_sans_serif
? "sans-serif"
: "none")),
lang.get(), static_cast<int>(runScript), runLen,
@ -2503,7 +2500,7 @@ void gfxFontGroup::InitScriptRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
}
}
} else {
aTextRun->AddGlyphRun(mainFont, FontMatchType::Kind::kFontGroup,
aTextRun->AddGlyphRun(mainFont, FontMatchType::kFontGroup,
aOffset + runStart, (matchedLength > 0),
range.orientation);
}
@ -2710,7 +2707,8 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
gfxFont* firstFont = GetFontAt(0, aCh);
if (firstFont) {
if (firstFont->HasCharacter(aCh)) {
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[0].Generic()};
*aMatchType =
FontMatchType::kFontGroup | FontMatchType(mFonts[0].Generic());
return firstFont;
}
@ -2725,7 +2723,8 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
font = FindFallbackFaceForChar(mFonts[0].Family(), aCh);
}
if (font) {
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[0].Generic()};
*aMatchType =
FontMatchType::kFontGroup | FontMatchType(mFonts[0].Generic());
return font;
}
}
@ -2775,7 +2774,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
gfxFont* font = ff.Font();
if (font) {
if (font->HasCharacter(aCh)) {
*aMatchType = {FontMatchType::Kind::kFontGroup, ff.Generic()};
*aMatchType = FontMatchType::kFontGroup | FontMatchType(ff.Generic());
return font;
}
continue;
@ -2804,7 +2803,8 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
if (pfe && pfe->HasCharacter(aCh)) {
font = GetFontAt(i, aCh);
if (font) {
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[i].Generic()};
*aMatchType =
FontMatchType::kFontGroup | FontMatchType(mFonts[i].Generic());
return font;
}
}
@ -2813,7 +2813,8 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
// build the font via GetFontAt
font = GetFontAt(i, aCh);
if (font) {
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[i].Generic()};
*aMatchType =
FontMatchType::kFontGroup | FontMatchType(mFonts[i].Generic());
return font;
}
}
@ -2827,7 +2828,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
"should only do fallback once per font family");
font = FindFallbackFaceForChar(ff.Family(), aCh);
if (font) {
*aMatchType = {FontMatchType::Kind::kFontGroup, ff.Generic()};
*aMatchType = FontMatchType::kFontGroup | FontMatchType(ff.Generic());
return font;
}
} else {
@ -2838,7 +2839,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
if (!fe->mIsUserFontContainer && !fe->IsUserFont()) {
font = FindFallbackFaceForChar(ff.Family(), aCh);
if (font) {
*aMatchType = {FontMatchType::Kind::kFontGroup, ff.Generic()};
*aMatchType = FontMatchType::kFontGroup | FontMatchType(ff.Generic());
return font;
}
}
@ -2848,7 +2849,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
if (fontListLength == 0) {
gfxFont* defaultFont = GetDefaultFont();
if (defaultFont->HasCharacter(aCh)) {
*aMatchType = FontMatchType::Kind::kFontGroup;
*aMatchType = FontMatchType::kFontGroup;
return defaultFont;
}
}
@ -2861,7 +2862,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
// 2. search pref fonts
gfxFont* font = WhichPrefFontSupportsChar(aCh, aNextCh);
if (font) {
*aMatchType = FontMatchType::Kind::kPrefsFallback;
*aMatchType = FontMatchType::kPrefsFallback;
return font;
}
@ -2869,7 +2870,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
// -- before searching for something else check the font used for the
// previous character
if (aPrevMatchedFont && aPrevMatchedFont->HasCharacter(aCh)) {
*aMatchType = FontMatchType::Kind::kSystemFallback;
*aMatchType = FontMatchType::kSystemFallback;
return aPrevMatchedFont;
}
@ -2881,7 +2882,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
}
// -- otherwise look for other stuff
*aMatchType = FontMatchType::Kind::kSystemFallback;
*aMatchType = FontMatchType::kSystemFallback;
return WhichSystemFontSupportsChar(aCh, aNextCh, aRunScript);
}
@ -2905,12 +2906,12 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
// 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)
StyleGenericFontFamily generic = StyleGenericFontFamily::None;
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
FontMatchType matchType = {FontMatchType::Kind::kFontGroup, generic};
FontMatchType matchType = FontMatchType::kFontGroup | FontMatchType(generic);
for (uint32_t i = 0; i < aLength; i++) {
const uint32_t origI = i; // save off in case we increase for surrogate
@ -2957,7 +2958,8 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
!gfxFontUtils::IsJoinControl(ch) &&
!gfxFontUtils::IsJoinCauser(prevCh) &&
!gfxFontUtils::IsVarSelector(ch)))) {
matchType = {FontMatchType::Kind::kFontGroup, mFonts[0].Generic()};
matchType =
FontMatchType::kFontGroup | FontMatchType(mFonts[0].Generic());
} else {
font =
FindFontForChar(ch, prevCh, nextCh, aRunScript, prevFont, &matchType);
@ -2965,9 +2967,9 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
#ifndef RELEASE_OR_BETA
if (MOZ_UNLIKELY(mTextPerf)) {
if (matchType.kind == FontMatchType::Kind::kPrefsFallback) {
if (matchType & FontMatchType::kPrefsFallback) {
mTextPerf->current.fallbackPrefs++;
} else if (matchType.kind == FontMatchType::Kind::kSystemFallback) {
} else if (matchType & FontMatchType::kSystemFallback) {
mTextPerf->current.fallbackSystem++;
}
}
@ -3049,16 +3051,16 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
for (size_t i = 0, i_end = aRanges.Length(); i < i_end; i++) {
const TextRange& r = aRanges[i];
nsAutoCString matchTypes;
if (r.matchType.kind & FontMatchType::Kind::kFontGroup) {
if (r.matchType & FontMatchType::kFontGroup) {
matchTypes.AppendLiteral("list");
}
if (r.matchType.kind & FontMatchType::Kind::kPrefsFallback) {
if (r.matchType & FontMatchType::kPrefsFallback) {
if (!matchTypes.IsEmpty()) {
matchTypes.AppendLiteral(",");
}
matchTypes.AppendLiteral("prefs");
}
if (r.matchType.kind & FontMatchType::Kind::kPrefsFallback) {
if (r.matchType & FontMatchType::kPrefsFallback) {
if (!matchTypes.IsEmpty()) {
matchTypes.AppendLiteral(",");
}
@ -3073,10 +3075,9 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
("(%s-fontmatching) fontgroup: [%s] default: %s lang: %s script: %d"
"%s\n",
(mStyle.systemFont ? "textrunui" : "textrun"), families.get(),
(mFamilyList.GetDefaultFontType() == StyleGenericFontFamily::Serif
(mFamilyList.GetDefaultFontType() == eFamily_serif
? "serif"
: (mFamilyList.GetDefaultFontType() ==
StyleGenericFontFamily::SansSerif
: (mFamilyList.GetDefaultFontType() == eFamily_sans_serif
? "sans-serif"
: "none")),
lang.get(), static_cast<int>(aRunScript), fontMatches.get()));
@ -3174,7 +3175,8 @@ gfxFont* gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh,
for (i = 0; i < numLangs; i++) {
eFontPrefLang currentLang = prefLangs[i];
StyleGenericFontFamily defaultGeneric = pfl->GetDefaultGeneric(currentLang);
mozilla::FontFamilyType defaultGeneric =
pfl->GetDefaultGeneric(currentLang);
gfxPlatformFontList::PrefFontList* families =
pfl->GetPrefFontsLangGroup(defaultGeneric, currentLang);
NS_ASSERTION(families, "no pref font families found");

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

@ -851,8 +851,8 @@ class gfxFontGroup final : public gfxTextRunFactory {
// 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::StyleGenericFontFamily* aGeneric = nullptr);
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
@ -1024,14 +1024,14 @@ class gfxFontGroup final : public gfxTextRunFactory {
FamilyFace()
: mFamily(nullptr),
mFontEntry(nullptr),
mGeneric(mozilla::StyleGenericFontFamily::None),
mGeneric(mozilla::eFamily_none),
mFontCreated(false),
mLoading(false),
mInvalid(false),
mCheckForFallbackFaces(false) {}
FamilyFace(gfxFontFamily* aFamily, gfxFont* aFont,
mozilla::StyleGenericFontFamily aGeneric)
mozilla::FontFamilyType aGeneric)
: mFamily(aFamily),
mGeneric(aGeneric),
mFontCreated(true),
@ -1046,7 +1046,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
}
FamilyFace(gfxFontFamily* aFamily, gfxFontEntry* aFontEntry,
mozilla::StyleGenericFontFamily aGeneric)
mozilla::FontFamilyType aGeneric)
: mFamily(aFamily),
mGeneric(aGeneric),
mFontCreated(false),
@ -1115,7 +1115,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
return mFontCreated ? mFont->GetFontEntry() : mFontEntry;
}
mozilla::StyleGenericFontFamily Generic() const { return mGeneric; }
mozilla::FontFamilyType Generic() const { return mGeneric; }
bool IsUserFontContainer() const {
return FontEntry()->mIsUserFontContainer;
@ -1152,7 +1152,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
gfxFont* MOZ_OWNING_REF mFont;
gfxFontEntry* MOZ_OWNING_REF mFontEntry;
};
mozilla::StyleGenericFontFamily mGeneric;
mozilla::FontFamilyType mGeneric;
bool mFontCreated : 1;
bool mLoading : 1;
bool mInvalid : 1;
@ -1261,7 +1261,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
// do style selection and add entries to list
void AddFamilyToFontList(gfxFontFamily* aFamily,
mozilla::StyleGenericFontFamily aGeneric);
mozilla::FontFamilyType aGeneric);
};
// A "missing font recorder" is to be used during text-run creation to keep

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

@ -8,7 +8,6 @@
#include <stdint.h>
#include "mozilla/TypedEnumBits.h"
#include "nsStyleConsts.h"
typedef struct _cairo_surface cairo_surface_t;
typedef struct _cairo_user_data_key cairo_user_data_key_t;
@ -88,42 +87,19 @@ enum class gfxAlphaType {
* Type used to record how a particular font is selected during the font-
* matching process, so that this can be exposed to the Inspector.
*/
struct FontMatchType {
enum class Kind : uint8_t {
kFontGroup = 1,
kPrefsFallback = 1 << 1,
kSystemFallback = 1 << 2,
};
enum class FontMatchType : 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,
inline FontMatchType& operator|=(const FontMatchType& aOther);
bool operator==(const FontMatchType& aOther) const {
return kind == aOther.kind && generic == aOther.generic;
}
bool operator!=(const FontMatchType& aOther) const {
return !(*this == aOther);
}
MOZ_IMPLICIT FontMatchType() = default;
MOZ_IMPLICIT FontMatchType(Kind aKind) : kind(aKind) {}
FontMatchType(Kind aKind, mozilla::StyleGenericFontFamily aGeneric)
: kind(aKind), generic(aGeneric) {}
Kind kind = static_cast<Kind>(0);
mozilla::StyleGenericFontFamily generic =
mozilla::StyleGenericFontFamily::None;
// Flags for recording the kind of font-matching that was used.
// Note that multiple flags may be set on a single range.
kFontGroup = 0x0100,
kPrefsFallback = 0x0200,
kSystemFallback = 0x0400
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(FontMatchType::Kind)
FontMatchType& FontMatchType::operator|=(const FontMatchType& aOther) {
kind |= aOther.kind;
// We only keep track of one generic.
if (generic != aOther.generic) {
generic = mozilla::StyleGenericFontFamily::None;
}
return *this;
}
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(FontMatchType)
#endif /* GFX_TYPES_H */

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

@ -10207,8 +10207,7 @@ void ReflowCountMgr::PaintCount(const char* aName,
// We don't care about the document language or user fonts here;
// just get a default Latin font.
nsFont font(StyleGenericFontFamily::Serif,
nsPresContext::CSSPixelsToAppUnits(11));
nsFont font(eFamily_serif, nsPresContext::CSSPixelsToAppUnits(11));
nsFontMetrics::Params params;
params.language = nsGkAtoms::x_western;
params.textPerf = aPresContext->GetTextPerfMetrics();

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

@ -40,6 +40,7 @@ StaticPresData::StaticPresData() {
// clang-format off
static const char* const kGenericFont[] = {
".variable.",
".fixed.",
".serif.",
".sans-serif.",
".monospace.",
@ -51,6 +52,7 @@ static const char* const kGenericFont[] = {
// These are private, use the list in nsFont.h if you want a public list.
enum {
eDefaultFont_Variable,
eDefaultFont_Fixed,
eDefaultFont_Serif,
eDefaultFont_SansSerif,
eDefaultFont_Monospace,
@ -91,7 +93,7 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
aLangGroupAtom->ToUTF8String(langGroup);
mDefaultVariableFont.size = nsPresContext::CSSPixelsToAppUnits(16);
mDefaultMonospaceFont.size = nsPresContext::CSSPixelsToAppUnits(13);
mDefaultFixedFont.size = nsPresContext::CSSPixelsToAppUnits(13);
nsAutoCString pref;
@ -105,6 +107,7 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
// clang-format off
nsFont* fontTypes[] = {
&mDefaultVariableFont,
&mDefaultFixedFont,
&mDefaultSerifFont,
&mDefaultSansSerifFont,
&mDefaultMonospaceFont,
@ -138,10 +141,10 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
Preferences::GetCString(pref.get(), value);
if (!value.IsEmpty()) {
FontFamilyName defaultVariableName = FontFamilyName::Convert(value);
StyleGenericFontFamily defaultType = defaultVariableName.mGeneric;
NS_ASSERTION(defaultType == StyleGenericFontFamily::Serif ||
defaultType == StyleGenericFontFamily::SansSerif,
"default type must be serif or sans-serif");
FontFamilyType defaultType = defaultVariableName.mType;
NS_ASSERTION(
defaultType == eFamily_serif || defaultType == eFamily_sans_serif,
"default type must be serif or sans-serif");
mDefaultVariableFont.fontlist = FontFamilyList();
mDefaultVariableFont.fontlist.SetDefaultFontType(defaultType);
// We create mDefaultVariableFont.fontlist with defaultType as the
@ -152,10 +155,10 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
Preferences::GetCString(pref.get(), value);
if (!value.IsEmpty()) {
FontFamilyName defaultVariableName = FontFamilyName::Convert(value);
StyleGenericFontFamily defaultType = defaultVariableName.mGeneric;
NS_ASSERTION(defaultType == StyleGenericFontFamily::Serif ||
defaultType == StyleGenericFontFamily::SansSerif,
"default type must be serif or sans-serif");
FontFamilyType defaultType = defaultVariableName.mType;
NS_ASSERTION(
defaultType == eFamily_serif || defaultType == eFamily_sans_serif,
"default type must be serif or sans-serif");
mDefaultVariableFont.fontlist = FontFamilyList();
mDefaultVariableFont.fontlist.SetDefaultFontType(defaultType);
// We create mDefaultVariableFont.fontlist with defaultType as the
@ -164,7 +167,14 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
}
}
} else {
if (eType != eDefaultFont_Monospace) {
if (eType == eDefaultFont_Monospace) {
// This takes care of the confusion whereby people often expect
// "monospace" to have the same default font-size as "-moz-fixed" (this
// tentative size may be overwritten with the specific value for
// "monospace" when "font.size.monospace.[langGroup]" is read -- see
// below)
mDefaultMonospaceFont.size = mDefaultFixedFont.size;
} else if (eType != eDefaultFont_Fixed) {
// all the other generic fonts are initialized with the size of the
// variable font, but their specific size can supersede later -- see
// below

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

@ -22,13 +22,13 @@ struct LangGroupFontPrefs {
: mLangGroup(nullptr),
mMinimumFontSize(0),
mDefaultVariableFont(),
mDefaultSerifFont(StyleGenericFontFamily::Serif, 0),
mDefaultSansSerifFont(StyleGenericFontFamily::SansSerif, 0),
mDefaultMonospaceFont(StyleGenericFontFamily::Monospace, 0),
mDefaultCursiveFont(StyleGenericFontFamily::Cursive, 0),
mDefaultFantasyFont(StyleGenericFontFamily::Fantasy, 0) {
mDefaultVariableFont.fontlist.SetDefaultFontType(
StyleGenericFontFamily::Serif);
mDefaultFixedFont(mozilla::eFamily_monospace, 0),
mDefaultSerifFont(mozilla::eFamily_serif, 0),
mDefaultSansSerifFont(mozilla::eFamily_sans_serif, 0),
mDefaultMonospaceFont(mozilla::eFamily_monospace, 0),
mDefaultCursiveFont(mozilla::eFamily_cursive, 0),
mDefaultFantasyFont(mozilla::eFamily_fantasy, 0) {
mDefaultVariableFont.fontlist.SetDefaultFontType(mozilla::eFamily_serif);
// We create mDefaultVariableFont.fontlist with defaultType as the
// fallback font, and not as part of the font list proper. This way,
// it can be overwritten should there be a language change.
@ -67,26 +67,36 @@ struct LangGroupFontPrefs {
*
* This object is read-only, you must copy the font to modify it.
*
* When aFontID is kPresContext_DefaultVariableFontID or
* kPresContext_DefaultFixedFontID (which equals
* kGenericFont_moz_fixed, which is used for the -moz-fixed generic),
* the nsFont returned has its name as a CSS generic family (serif or
* sans-serif for the former, monospace for the latter), and its size
* as the default font size for variable or fixed fonts for the
* language group.
*
* For aFontID corresponding to a CSS Generic, the nsFont returned has
* its name set to that generic font's name, and its size set to
* the user's preference for font size for that generic and the
* given language.
*/
const nsFont* GetDefaultFont(StyleGenericFontFamily aFamily) const {
switch (aFamily) {
const nsFont* GetDefaultFont(uint8_t aFontID) const {
switch (aFontID) {
// Special (our default variable width font and fixed width font)
case StyleGenericFontFamily::None:
case kGenericFont_moz_variable:
return &mDefaultVariableFont;
case kGenericFont_moz_fixed:
return &mDefaultFixedFont;
// CSS
case StyleGenericFontFamily::Serif:
case kGenericFont_serif:
return &mDefaultSerifFont;
case StyleGenericFontFamily::SansSerif:
case kGenericFont_sans_serif:
return &mDefaultSansSerifFont;
case StyleGenericFontFamily::Monospace:
case kGenericFont_monospace:
return &mDefaultMonospaceFont;
case StyleGenericFontFamily::Cursive:
case kGenericFont_cursive:
return &mDefaultCursiveFont;
case StyleGenericFontFamily::Fantasy:
case kGenericFont_fantasy:
return &mDefaultFantasyFont;
break;
default:
@ -98,6 +108,7 @@ struct LangGroupFontPrefs {
nsStaticAtom* mLangGroup;
nscoord mMinimumFontSize;
nsFont mDefaultVariableFont;
nsFont mDefaultFixedFont;
nsFont mDefaultSerifFont;
nsFont mDefaultSansSerifFont;
nsFont mDefaultMonospaceFont;

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

@ -9749,9 +9749,8 @@ void nsLayoutUtils::ComputeSystemFont(nsFont* aSystemFont,
if (LookAndFeel::GetFont(aFontID, systemFontName, fontStyle)) {
systemFontName.Trim("\"'");
aSystemFont->fontlist =
FontFamilyList(NS_ConvertUTF16toUTF8(systemFontName),
StyleFontFamilyNameSyntax::Identifiers);
aSystemFont->fontlist.SetDefaultFontType(StyleGenericFontFamily::None);
FontFamilyList(NS_ConvertUTF16toUTF8(systemFontName), eUnquotedName);
aSystemFont->fontlist.SetDefaultFontType(eFamily_none);
aSystemFont->style = fontStyle.style;
aSystemFont->systemFont = fontStyle.systemFont;
aSystemFont->weight = fontStyle.weight;

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

@ -53,12 +53,13 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(
nscoord halfInch = PresContext()->CSSTwipsToAppUnits(NS_INCHES_TO_TWIPS(0.5));
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
// XXX Unsafe to assume successful allocation
mPageData = new nsSharedPageData();
mPageData->mHeadFootFont =
*PresContext()
->Document()
->GetFontPrefsForLang(aStyle->StyleFont()->mLanguage)
->GetDefaultFont(StyleGenericFontFamily::Serif);
->GetDefaultFont(kGenericFont_serif);
mPageData->mHeadFootFont.size = nsPresContext::CSSPointsToAppUnits(10);
// Doing this here so we only have to go get these formats once

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

@ -5731,7 +5731,7 @@ gfxFloat nsTextFrame::ComputeSelectionUnderlineHeight(
nscoord defaultFontSize =
aPresContext->Document()
->GetFontPrefsForLang(nullptr)
->GetDefaultFont(StyleGenericFontFamily::None)
->GetDefaultFont(kPresContext_DefaultVariableFont_ID)
->size;
int32_t zoomedFontSize = aPresContext->AppUnitsToDevPixels(
nsStyleFont::ZoomText(*aPresContext->Document(), defaultFontSize));

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

@ -31,15 +31,15 @@ InspectorFontFace::InspectorFontFace(gfxFontEntry* aFontEntry,
InspectorFontFace::~InspectorFontFace() { MOZ_COUNT_DTOR(InspectorFontFace); }
bool InspectorFontFace::FromFontGroup() {
return bool(mMatchType.kind & FontMatchType::Kind::kFontGroup);
return bool(mMatchType & FontMatchType::kFontGroup);
}
bool InspectorFontFace::FromLanguagePrefs() {
return bool(mMatchType.kind & FontMatchType::Kind::kPrefsFallback);
return bool(mMatchType & FontMatchType::kPrefsFallback);
}
bool InspectorFontFace::FromSystemFallback() {
return bool(mMatchType.kind & FontMatchType::Kind::kSystemFallback);
return bool(mMatchType & FontMatchType::kSystemFallback);
}
void InspectorFontFace::GetName(nsAString& aName) {
@ -56,8 +56,10 @@ void InspectorFontFace::GetCSSFamilyName(nsAString& aCSSFamilyName) {
}
void InspectorFontFace::GetCSSGeneric(nsAString& aName) {
if (mMatchType.generic != StyleGenericFontFamily::None) {
aName.AssignASCII(gfxPlatformFontList::GetGenericName(mMatchType.generic));
auto genericType = FontFamilyType(mMatchType & FontMatchType::kGenericMask);
if (genericType >= FontFamilyType::eFamily_generic_first &&
genericType <= FontFamilyType::eFamily_generic_last) {
aName.AssignASCII(gfxPlatformFontList::GetGenericName(genericType));
} else {
aName.Truncate(0);
}

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

@ -56,13 +56,13 @@ static const float kLargeOpFactor = float(M_SQRT2);
static const float kIntegralFactor = 2.0;
static void NormalizeDefaultFont(nsFont& aFont, float aFontSizeInflation) {
if (aFont.fontlist.GetDefaultFontType() != StyleGenericFontFamily::None) {
if (aFont.fontlist.GetDefaultFontType() != eFamily_none) {
nsTArray<FontFamilyName> names;
names.AppendElements(aFont.fontlist.GetFontlist()->mNames);
names.AppendElement(FontFamilyName(aFont.fontlist.GetDefaultFontType()));
aFont.fontlist.SetFontlist(std::move(names));
aFont.fontlist.SetDefaultFontType(StyleGenericFontFamily::None);
aFont.fontlist.SetDefaultFontType(eFamily_none);
}
aFont.size = NSToCoordRound(aFont.size * aFontSizeInflation);
}
@ -166,8 +166,8 @@ class nsPropertiesTable final : public nsGlyphTable {
explicit nsPropertiesTable(const nsACString& aPrimaryFontName)
: mState(NS_TABLE_STATE_EMPTY) {
MOZ_COUNT_CTOR(nsPropertiesTable);
mGlyphCodeFonts.AppendElement(FontFamilyName(
aPrimaryFontName, StyleFontFamilyNameSyntax::Identifiers));
mGlyphCodeFonts.AppendElement(
FontFamilyName(aPrimaryFontName, eUnquotedName));
}
~nsPropertiesTable() { MOZ_COUNT_DTOR(nsPropertiesTable); }
@ -286,8 +286,7 @@ nsGlyphCode nsPropertiesTable::ElementAt(DrawTarget* /* aDrawTarget */,
Clean(value);
mGlyphCodeFonts.AppendElement(FontFamilyName(
NS_ConvertUTF16toUTF8(value),
StyleFontFamilyNameSyntax::Identifiers)); // i.e., mGlyphCodeFonts[i]
// holds this font name
eUnquotedName)); // i.e., mGlyphCodeFonts[i] holds this font name
}
}
@ -420,8 +419,7 @@ class nsOpenTypeTable final : public nsGlyphTable {
explicit nsOpenTypeTable(gfxFont* aFont)
: mFont(aFont),
mFontFamilyName(aFont->GetFontEntry()->FamilyName(),
StyleFontFamilyNameSyntax::Identifiers),
mFontFamilyName(aFont->GetFontEntry()->FamilyName(), eUnquotedName),
mGlyphID(0) {
MOZ_COUNT_CTOR(nsOpenTypeTable);
}
@ -518,7 +516,7 @@ already_AddRefed<gfxTextRun> nsOpenTypeTable::MakeTextRun(
gfxTextRun::Create(&params, 1, aFontGroup, gfx::ShapedTextFlags(),
nsTextFrameUtils::Flags());
textRun->AddGlyphRun(aFontGroup->GetFirstValidFont(),
FontMatchType::Kind::kFontGroup, 0, false,
FontMatchType::kFontGroup, 0, false,
gfx::ShapedTextFlags::TEXT_ORIENT_HORIZONTAL);
// We don't care about CSS writing mode here;
// math runs are assumed to be horizontal.
@ -892,7 +890,7 @@ bool nsMathMLChar::SetFontFamily(nsPresContext* aPresContext,
// or if the same family name has been found
gfxFont* firstFont = fm->GetThebesFontGroup()->GetFirstValidFont();
FontFamilyList firstFontList(firstFont->GetFontEntry()->FamilyName(),
StyleFontFamilyNameSyntax::Identifiers);
eUnquotedName);
if (aGlyphTable == &gGlyphTableList->mUnicodeTable ||
firstFontList == familyList) {
aFont.fontlist = familyList;
@ -1282,8 +1280,8 @@ bool nsMathMLChar::StretchEnumContext::EnumCallback(
// for comparisons, force use of unquoted names
FontFamilyName unquotedFamilyName(aFamily);
if (unquotedFamilyName.mSyntax == StyleFontFamilyNameSyntax::Quoted) {
unquotedFamilyName.mSyntax = StyleFontFamilyNameSyntax::Identifiers;
if (unquotedFamilyName.mType == eFamily_named_quoted) {
unquotedFamilyName.mType = eFamily_named;
}
// Check font family if it is not a generic one
@ -1292,7 +1290,7 @@ bool nsMathMLChar::StretchEnumContext::EnumCallback(
nsFont font = sc->StyleFont()->mFont;
NormalizeDefaultFont(font, context->mFontSizeInflation);
RefPtr<gfxFontGroup> fontGroup;
FontFamilyList family({unquotedFamilyName});
FontFamilyList family(unquotedFamilyName);
if (!aGeneric &&
!context->mChar->SetFontFamily(context->mPresContext, nullptr, kNullGlyph,
family, font, &fontGroup))
@ -1345,8 +1343,7 @@ bool nsMathMLChar::StretchEnumContext::EnumCallback(
static void AppendFallbacks(nsTArray<FontFamilyName>& aNames,
const nsTArray<nsCString>& aFallbacks) {
for (const nsCString& fallback : aFallbacks) {
aNames.AppendElement(
FontFamilyName(fallback, StyleFontFamilyNameSyntax::Identifiers));
aNames.AppendElement(FontFamilyName(fallback, eUnquotedName));
}
}

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

@ -91,9 +91,9 @@ ServoTraversalStatistics ServoTraversalStatistics::sSingleton;
static RWLock* sServoFFILock = nullptr;
static const nsFont* ThreadSafeGetDefaultFontHelper(
const Document& aDocument, nsAtom* aLanguage,
StyleGenericFontFamily aGenericId) {
static const nsFont* ThreadSafeGetDefaultFontHelper(const Document& aDocument,
nsAtom* aLanguage,
uint8_t aGenericId) {
bool needsCache = false;
const nsFont* retval;
@ -962,14 +962,14 @@ void Gecko_AddRefAtom(nsAtom* aAtom) { NS_ADDREF(aAtom); }
void Gecko_ReleaseAtom(nsAtom* aAtom) { NS_RELEASE(aAtom); }
void Gecko_nsTArray_FontFamilyName_AppendNamed(
nsTArray<FontFamilyName>* aNames, nsAtom* aName,
StyleFontFamilyNameSyntax aSyntax) {
aNames->AppendElement(FontFamilyName(aName, aSyntax));
void Gecko_nsTArray_FontFamilyName_AppendNamed(nsTArray<FontFamilyName>* aNames,
nsAtom* aName, bool aQuoted) {
aNames->AppendElement(
FontFamilyName(aName, aQuoted ? eQuotedName : eUnquotedName));
}
void Gecko_nsTArray_FontFamilyName_AppendGeneric(
nsTArray<FontFamilyName>* aNames, StyleGenericFontFamily aType) {
nsTArray<FontFamilyName>* aNames, FontFamilyType aType) {
aNames->AppendElement(FontFamilyName(aType));
}
@ -1002,7 +1002,7 @@ void Gecko_nsFont_InitSystem(nsFont* aDest, int32_t aFontId,
const nsStyleFont* aFont,
const Document* aDocument) {
const nsFont* defaultVariableFont = ThreadSafeGetDefaultFontHelper(
*aDocument, aFont->mLanguage, StyleGenericFontFamily::None);
*aDocument, aFont->mLanguage, kPresContext_DefaultVariableFont_ID);
// We have passed uninitialized memory to this function,
// initialize it. We can't simply return an nsFont because then
@ -1018,9 +1018,9 @@ void Gecko_nsFont_InitSystem(nsFont* aDest, int32_t aFontId,
void Gecko_nsFont_Destroy(nsFont* aDest) { aDest->~nsFont(); }
StyleGenericFontFamily Gecko_nsStyleFont_ComputeDefaultFontType(
const Document* aDoc, StyleGenericFontFamily aGenericId,
nsAtom* aLanguage) {
FontFamilyType Gecko_nsStyleFont_ComputeDefaultFontType(const Document* aDoc,
uint8_t aGenericId,
nsAtom* aLanguage) {
const nsFont* defaultFont =
ThreadSafeGetDefaultFontHelper(*aDoc, aLanguage, aGenericId);
return defaultFont->fontlist.GetDefaultFontType();
@ -1892,15 +1892,32 @@ void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont,
aFont->mLanguage = aSource->mLanguage;
}
void Gecko_nsStyleFont_PrioritizeUserFonts(
nsStyleFont* aFont, StyleGenericFontFamily aDefaultGeneric) {
void Gecko_nsStyleFont_PrioritizeUserFonts(nsStyleFont* aFont,
FontFamilyType aDefaultGeneric) {
MOZ_ASSERT(!StaticPrefs::browser_display_use_document_fonts());
MOZ_ASSERT(aDefaultGeneric != StyleGenericFontFamily::None);
MOZ_ASSERT(aDefaultGeneric != eFamily_none);
if (!aFont->mFont.fontlist.PrioritizeFirstGeneric()) {
aFont->mFont.fontlist.PrependGeneric(aDefaultGeneric);
}
}
void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* aFont,
const Document* aDocument,
uint8_t aGenericId) {
const nsFont* defaultFont =
ThreadSafeGetDefaultFontHelper(*aDocument, aFont->mLanguage, aGenericId);
// In case of just the language changing, the parent could have had no
// generic, which Gecko just does regular cascading with. Do the same. This
// can only happen in the case where the language changed but the family did
// not
if (aGenericId != kGenericFont_NONE) {
aFont->mFont.fontlist = defaultFont->fontlist;
} else {
aFont->mFont.fontlist.SetDefaultFontType(
defaultFont->fontlist.GetDefaultFontType());
}
}
nscoord Gecko_nsStyleFont_ComputeMinSize(const nsStyleFont* aFont,
const Document* aDocument) {
// Don't change font-size:0, since that would un-hide hidden text, nor chrome
@ -1937,6 +1954,7 @@ nscoord Gecko_nsStyleFont_ComputeMinSize(const nsStyleFont* aFont,
void FontSizePrefs::CopyFrom(const LangGroupFontPrefs& prefs) {
mDefaultVariableSize = prefs.mDefaultVariableFont.size;
mDefaultFixedSize = prefs.mDefaultFixedFont.size;
mDefaultSerifSize = prefs.mDefaultSerifFont.size;
mDefaultSansSerifSize = prefs.mDefaultSansSerifFont.size;
mDefaultMonospaceSize = prefs.mDefaultMonospaceFont.size;

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

@ -266,11 +266,10 @@ void Gecko_ReleaseAtom(nsAtom* aAtom);
void Gecko_CopyFontFamilyFrom(nsFont* dst, const nsFont* src);
void Gecko_nsTArray_FontFamilyName_AppendNamed(
nsTArray<mozilla::FontFamilyName>* aNames, nsAtom* aName,
mozilla::StyleFontFamilyNameSyntax);
nsTArray<mozilla::FontFamilyName>* aNames, nsAtom* aName, bool aQuoted);
void Gecko_nsTArray_FontFamilyName_AppendGeneric(
nsTArray<mozilla::FontFamilyName>* aNames, mozilla::StyleGenericFontFamily);
nsTArray<mozilla::FontFamilyName>* aNames, mozilla::FontFamilyType aType);
// Returns an already-AddRefed SharedFontList with an empty mNames array.
mozilla::SharedFontList* Gecko_SharedFontList_Create();
@ -679,15 +678,18 @@ void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont,
//
// Document fonts may still be used as fallback for unsupported glyphs though.
void Gecko_nsStyleFont_PrioritizeUserFonts(
nsStyleFont* font, mozilla::StyleGenericFontFamily aDefaultGeneric);
nsStyleFont* font, mozilla::FontFamilyType aDefaultGeneric);
void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* font,
const mozilla::dom::Document*,
uint8_t generic_id);
nscoord Gecko_nsStyleFont_ComputeMinSize(const nsStyleFont*,
const mozilla::dom::Document*);
// Computes the default generic font for a generic family and language.
mozilla::StyleGenericFontFamily Gecko_nsStyleFont_ComputeDefaultFontType(
const mozilla::dom::Document*,
mozilla::StyleGenericFontFamily generic_family, nsAtom* language);
mozilla::FontFamilyType Gecko_nsStyleFont_ComputeDefaultFontType(
const mozilla::dom::Document*, uint8_t generic_family, nsAtom* language);
mozilla::FontSizePrefs Gecko_GetBaseSize(nsAtom* lang);

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

@ -64,6 +64,7 @@ rusty-enums = [
"mozilla::dom::IterationCompositeOperation",
"mozilla::dom::CompositeOperation",
"mozilla::InheritTarget",
"mozilla::FontFamilyType",
"mozilla::css::DocumentMatchingFunction",
"mozilla::css::SheetParsingMode",
"mozilla::StyleContentType",
@ -457,8 +458,6 @@ cbindgen-types = [
{ gecko = "StyleOwned", servo = "gecko_bindings::sugar::ownership::Owned" },
{ gecko = "StyleOwnedOrNull", servo = "gecko_bindings::sugar::ownership::OwnedOrNull" },
{ gecko = "StyleStrong", servo = "gecko_bindings::sugar::ownership::Strong" },
{ gecko = "StyleGenericFontFamily", servo = "values::computed::font::GenericFontFamily" },
{ gecko = "StyleFontFamilyNameSyntax", servo = "values::computed::font::FontFamilyNameSyntax" },
]
mapped-generic-types = [

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

@ -161,6 +161,7 @@ struct MediumFeaturesChangedResult {
struct FontSizePrefs {
void CopyFrom(const mozilla::LangGroupFontPrefs&);
nscoord mDefaultVariableSize;
nscoord mDefaultFixedSize;
nscoord mDefaultSerifSize;
nscoord mDefaultSansSerifSize;
nscoord mDefaultMonospaceSize;

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

@ -112,12 +112,12 @@ nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
nsStyleFont::nsStyleFont(const Document& aDocument)
: mFont(*aDocument.GetFontPrefsForLang(nullptr)->GetDefaultFont(
StyleGenericFontFamily::None)),
kPresContext_DefaultVariableFont_ID)),
mSize(ZoomText(aDocument, mFont.size)),
mFontSizeFactor(1.0),
mFontSizeOffset(0),
mFontSizeKeyword(NS_STYLE_FONT_SIZE_MEDIUM),
mGenericID(StyleGenericFontFamily::None),
mGenericID(kGenericFont_NONE),
mScriptLevel(0),
mMathVariant(NS_MATHML_MATHVARIANT_NONE),
mMathDisplay(NS_MATHML_DISPLAYSTYLE_INLINE),

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

@ -105,7 +105,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
// NS_STYLE_FONT_SIZE_NO_KEYWORD when not
// keyword-derived
mozilla::StyleGenericFontFamily mGenericID;
uint8_t mGenericID; // generic CSS font family, if any;
// value is a kGenericFont_* constant, see nsFont.h.
// MathML scriptlevel support
int8_t mScriptLevel;

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

@ -3442,149 +3442,149 @@ pref("svg.context-properties.content.enabled", false);
pref("font.default.ar", "sans-serif");
pref("font.minimum-size.ar", 0);
pref("font.size.variable.ar", 16);
pref("font.size.monospace.ar", 13);
pref("font.size.fixed.ar", 13);
pref("font.default.el", "serif");
pref("font.minimum-size.el", 0);
pref("font.size.variable.el", 16);
pref("font.size.monospace.el", 13);
pref("font.size.fixed.el", 13);
pref("font.default.he", "sans-serif");
pref("font.minimum-size.he", 0);
pref("font.size.variable.he", 16);
pref("font.size.monospace.he", 13);
pref("font.size.fixed.he", 13);
pref("font.default.ja", "sans-serif");
pref("font.minimum-size.ja", 0);
pref("font.size.variable.ja", 16);
pref("font.size.monospace.ja", 16);
pref("font.size.fixed.ja", 16);
pref("font.default.ko", "sans-serif");
pref("font.minimum-size.ko", 0);
pref("font.size.variable.ko", 16);
pref("font.size.monospace.ko", 16);
pref("font.size.fixed.ko", 16);
pref("font.default.th", "sans-serif");
pref("font.minimum-size.th", 0);
pref("font.size.variable.th", 16);
pref("font.size.monospace.th", 13);
pref("font.size.fixed.th", 13);
pref("font.default.x-cyrillic", "serif");
pref("font.minimum-size.x-cyrillic", 0);
pref("font.size.variable.x-cyrillic", 16);
pref("font.size.monospace.x-cyrillic", 13);
pref("font.size.fixed.x-cyrillic", 13);
pref("font.default.x-devanagari", "serif");
pref("font.minimum-size.x-devanagari", 0);
pref("font.size.variable.x-devanagari", 16);
pref("font.size.monospace.x-devanagari", 13);
pref("font.size.fixed.x-devanagari", 13);
pref("font.default.x-tamil", "serif");
pref("font.minimum-size.x-tamil", 0);
pref("font.size.variable.x-tamil", 16);
pref("font.size.monospace.x-tamil", 13);
pref("font.size.fixed.x-tamil", 13);
pref("font.default.x-armn", "serif");
pref("font.minimum-size.x-armn", 0);
pref("font.size.variable.x-armn", 16);
pref("font.size.monospace.x-armn", 13);
pref("font.size.fixed.x-armn", 13);
pref("font.default.x-beng", "serif");
pref("font.minimum-size.x-beng", 0);
pref("font.size.variable.x-beng", 16);
pref("font.size.monospace.x-beng", 13);
pref("font.size.fixed.x-beng", 13);
pref("font.default.x-cans", "serif");
pref("font.minimum-size.x-cans", 0);
pref("font.size.variable.x-cans", 16);
pref("font.size.monospace.x-cans", 13);
pref("font.size.fixed.x-cans", 13);
pref("font.default.x-ethi", "serif");
pref("font.minimum-size.x-ethi", 0);
pref("font.size.variable.x-ethi", 16);
pref("font.size.monospace.x-ethi", 13);
pref("font.size.fixed.x-ethi", 13);
pref("font.default.x-geor", "serif");
pref("font.minimum-size.x-geor", 0);
pref("font.size.variable.x-geor", 16);
pref("font.size.monospace.x-geor", 13);
pref("font.size.fixed.x-geor", 13);
pref("font.default.x-gujr", "serif");
pref("font.minimum-size.x-gujr", 0);
pref("font.size.variable.x-gujr", 16);
pref("font.size.monospace.x-gujr", 13);
pref("font.size.fixed.x-gujr", 13);
pref("font.default.x-guru", "serif");
pref("font.minimum-size.x-guru", 0);
pref("font.size.variable.x-guru", 16);
pref("font.size.monospace.x-guru", 13);
pref("font.size.fixed.x-guru", 13);
pref("font.default.x-khmr", "serif");
pref("font.minimum-size.x-khmr", 0);
pref("font.size.variable.x-khmr", 16);
pref("font.size.monospace.x-khmr", 13);
pref("font.size.fixed.x-khmr", 13);
pref("font.default.x-mlym", "serif");
pref("font.minimum-size.x-mlym", 0);
pref("font.size.variable.x-mlym", 16);
pref("font.size.monospace.x-mlym", 13);
pref("font.size.fixed.x-mlym", 13);
pref("font.default.x-orya", "serif");
pref("font.minimum-size.x-orya", 0);
pref("font.size.variable.x-orya", 16);
pref("font.size.monospace.x-orya", 13);
pref("font.size.fixed.x-orya", 13);
pref("font.default.x-telu", "serif");
pref("font.minimum-size.x-telu", 0);
pref("font.size.variable.x-telu", 16);
pref("font.size.monospace.x-telu", 13);
pref("font.size.fixed.x-telu", 13);
pref("font.default.x-knda", "serif");
pref("font.minimum-size.x-knda", 0);
pref("font.size.variable.x-knda", 16);
pref("font.size.monospace.x-knda", 13);
pref("font.size.fixed.x-knda", 13);
pref("font.default.x-sinh", "serif");
pref("font.minimum-size.x-sinh", 0);
pref("font.size.variable.x-sinh", 16);
pref("font.size.monospace.x-sinh", 13);
pref("font.size.fixed.x-sinh", 13);
pref("font.default.x-tibt", "serif");
pref("font.minimum-size.x-tibt", 0);
pref("font.size.variable.x-tibt", 16);
pref("font.size.monospace.x-tibt", 13);
pref("font.size.fixed.x-tibt", 13);
pref("font.default.x-unicode", "serif");
pref("font.minimum-size.x-unicode", 0);
pref("font.size.variable.x-unicode", 16);
pref("font.size.monospace.x-unicode", 13);
pref("font.size.fixed.x-unicode", 13);
pref("font.default.x-western", "serif");
pref("font.minimum-size.x-western", 0);
pref("font.size.variable.x-western", 16);
pref("font.size.monospace.x-western", 13);
pref("font.size.fixed.x-western", 13);
pref("font.default.zh-CN", "sans-serif");
pref("font.minimum-size.zh-CN", 0);
pref("font.size.variable.zh-CN", 16);
pref("font.size.monospace.zh-CN", 16);
pref("font.size.fixed.zh-CN", 16);
pref("font.default.zh-HK", "sans-serif");
pref("font.minimum-size.zh-HK", 0);
pref("font.size.variable.zh-HK", 16);
pref("font.size.monospace.zh-HK", 16);
pref("font.size.fixed.zh-HK", 16);
pref("font.default.zh-TW", "sans-serif");
pref("font.minimum-size.zh-TW", 0);
pref("font.size.variable.zh-TW", 16);
pref("font.size.monospace.zh-TW", 16);
pref("font.size.fixed.zh-TW", 16);
// mathml.css sets font-size to "inherit" and font-family to "serif" so only
// font.name.*.x-math and font.minimum-size.x-math are really relevant.
pref("font.default.x-math", "serif");
pref("font.minimum-size.x-math", 0);
pref("font.size.variable.x-math", 16);
pref("font.size.monospace.x-math", 13);
pref("font.size.fixed.x-math", 13);
/*
* A value greater than zero enables font size inflation for
@ -4422,19 +4422,19 @@ pref("font.name-list.serif.ar", "serif");
pref("font.name-list.sans-serif.ar", "sans-serif");
pref("font.name-list.monospace.ar", "monospace");
pref("font.name-list.cursive.ar", "cursive");
pref("font.size.monospace.ar", 12);
pref("font.size.fixed.ar", 12);
pref("font.name-list.serif.el", "serif");
pref("font.name-list.sans-serif.el", "sans-serif");
pref("font.name-list.monospace.el", "monospace");
pref("font.name-list.cursive.el", "cursive");
pref("font.size.monospace.el", 12);
pref("font.size.fixed.el", 12);
pref("font.name-list.serif.he", "serif");
pref("font.name-list.sans-serif.he", "sans-serif");
pref("font.name-list.monospace.he", "monospace");
pref("font.name-list.cursive.he", "cursive");
pref("font.size.monospace.he", 12);
pref("font.size.fixed.he", 12);
pref("font.name-list.serif.ja", "serif");
pref("font.name-list.sans-serif.ja", "sans-serif");
@ -4471,7 +4471,7 @@ pref("font.name-list.serif.x-cyrillic", "serif");
pref("font.name-list.sans-serif.x-cyrillic", "sans-serif");
pref("font.name-list.monospace.x-cyrillic", "monospace");
pref("font.name-list.cursive.x-cyrillic", "cursive");
pref("font.size.monospace.x-cyrillic", 12);
pref("font.size.fixed.x-cyrillic", 12);
pref("font.name-list.serif.x-devanagari", "serif");
pref("font.name-list.sans-serif.x-devanagari", "sans-serif");
@ -4542,13 +4542,13 @@ pref("font.name-list.serif.x-unicode", "serif");
pref("font.name-list.sans-serif.x-unicode", "sans-serif");
pref("font.name-list.monospace.x-unicode", "monospace");
pref("font.name-list.cursive.x-unicode", "cursive");
pref("font.size.monospace.x-unicode", 12);
pref("font.size.fixed.x-unicode", 12);
pref("font.name-list.serif.x-western", "serif");
pref("font.name-list.sans-serif.x-western", "sans-serif");
pref("font.name-list.monospace.x-western", "monospace");
pref("font.name-list.cursive.x-western", "cursive");
pref("font.size.monospace.x-western", 12);
pref("font.size.fixed.x-western", 12);
pref("font.name-list.serif.zh-CN", "serif");
pref("font.name-list.sans-serif.zh-CN", "sans-serif");
@ -4602,21 +4602,21 @@ pref("gfx.font_rendering.fontconfig.max_generic_substitutions", 3);
#if defined(ANDROID)
pref("font.size.monospace.ar", 12);
pref("font.size.fixed.ar", 12);
pref("font.default.el", "sans-serif");
pref("font.size.monospace.el", 12);
pref("font.size.fixed.el", 12);
pref("font.size.monospace.he", 12);
pref("font.size.fixed.he", 12);
pref("font.default.x-cyrillic", "sans-serif");
pref("font.size.monospace.x-cyrillic", 12);
pref("font.size.fixed.x-cyrillic", 12);
pref("font.default.x-unicode", "sans-serif");
pref("font.size.monospace.x-unicode", 12);
pref("font.size.fixed.x-unicode", 12);
pref("font.default.x-western", "sans-serif");
pref("font.size.monospace.x-western", 12);
pref("font.size.fixed.x-western", 12);
# ANDROID
#endif

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

@ -43,7 +43,7 @@ pub trait FontMetricsProvider {
}
/// Get default size of a given language and generic family.
fn get_size(&self, font_name: &Atom, font_family: crate::values::computed::font::GenericFontFamily) -> Au;
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au;
/// Construct from a shared style context
fn create_from(context: &SharedStyleContext) -> Self

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

@ -69,7 +69,6 @@ use crate::selector_parser::{AttrValue, HorizontalDirection, Lang};
use crate::shared_lock::Locked;
use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use crate::stylist::CascadeData;
use crate::values::computed::font::GenericFontFamily;
use crate::values::specified::length::FontBaseSize;
use crate::CaseSensitivityExt;
use app_units::Au;
@ -1042,7 +1041,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
GeckoFontMetricsProvider::new()
}
fn get_size(&self, font_name: &Atom, font_family: GenericFontFamily) -> Au {
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au {
let mut cache = self.font_size_cache.borrow_mut();
if let Some(sizes) = cache.iter().find(|el| el.0 == *font_name) {
return sizes.1.size_for_generic(font_family);
@ -1101,17 +1100,16 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
}
impl structs::FontSizePrefs {
fn size_for_generic(&self, font_family: GenericFontFamily) -> Au {
fn size_for_generic(&self, font_family: u8) -> Au {
Au(match font_family {
GenericFontFamily::None => self.mDefaultVariableSize,
GenericFontFamily::Serif => self.mDefaultSerifSize,
GenericFontFamily::SansSerif => self.mDefaultSansSerifSize,
GenericFontFamily::Monospace => self.mDefaultMonospaceSize,
GenericFontFamily::Cursive => self.mDefaultCursiveSize,
GenericFontFamily::Fantasy => self.mDefaultFantasySize,
GenericFontFamily::MozEmoji => {
unreachable!("Should never get here, since this doesn't (yet) appear on font family")
},
structs::kPresContext_DefaultVariableFont_ID => self.mDefaultVariableSize,
structs::kPresContext_DefaultFixedFont_ID => self.mDefaultFixedSize,
structs::kGenericFont_serif => self.mDefaultSerifSize,
structs::kGenericFont_sans_serif => self.mDefaultSansSerifSize,
structs::kGenericFont_monospace => self.mDefaultMonospaceSize,
structs::kGenericFont_cursive => self.mDefaultCursiveSize,
structs::kGenericFont_fantasy => self.mDefaultFantasySize,
_ => unreachable!("Unknown generic ID"),
})
}
}

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

@ -683,7 +683,6 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
#[cfg(feature = "gecko")]
fn recompute_default_font_family_type_if_needed(&mut self) {
use crate::gecko_bindings::{bindings, structs};
use crate::values::computed::font::GenericFontFamily;
if !self.seen.contains(LonghandId::XLang) &&
!self.seen.contains(LonghandId::FontFamily) {
@ -698,7 +697,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
// System fonts are all right, and should have the default font type
// set to none already, so bail out early.
if font.mFont.systemFont {
debug_assert_eq!(font.mFont.fontlist.mDefaultFontType, GenericFontFamily::None);
debug_assert_eq!(font.mFont.fontlist.mDefaultFontType, structs::FontFamilyType::eFamily_none);
return;
}
@ -718,11 +717,11 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
!use_document_fonts &&
matches!(
font.mGenericID,
GenericFontFamily::None |
GenericFontFamily::Fantasy |
GenericFontFamily::Cursive
structs::kGenericFont_NONE |
structs::kGenericFont_fantasy |
structs::kGenericFont_cursive
) &&
default_font_type != GenericFontFamily::None;
default_font_type != structs::FontFamilyType::eFamily_none;
if !prioritize_user_fonts && default_font_type == font.mFont.fontlist.mDefaultFontType {
// Nothing to do.

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

@ -1984,20 +1984,20 @@ fn static_assert() {
<% impl_font_settings("font_variation_settings", "gfxFontVariation", "VariationValue", "f32", "f32") %>
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
use crate::values::computed::font::GenericFontFamily;
use crate::gecko_bindings::structs::FontFamilyType;
let is_system_font = v.is_system_font;
self.gecko.mFont.systemFont = is_system_font;
self.gecko.mGenericID = if is_system_font {
GenericFontFamily::None
structs::kGenericFont_NONE
} else {
v.families.single_generic().unwrap_or(GenericFontFamily::None)
v.families.single_generic().unwrap_or(structs::kGenericFont_NONE)
};
self.gecko.mFont.fontlist.mFontlist.mBasePtr.set_move(
v.families.shared_font_list().clone()
);
// Fixed-up if needed in Cascade::fixup_font_stuff.
self.gecko.mFont.fontlist.mDefaultFontType = GenericFontFamily::None;
self.gecko.mFont.fontlist.mDefaultFontType = FontFamilyType::eFamily_none;
}
pub fn copy_font_family_from(&mut self, other: &Self) {
@ -2011,13 +2011,33 @@ fn static_assert() {
}
pub fn clone_font_family(&self) -> longhands::font_family::computed_value::T {
use crate::gecko_bindings::structs::FontFamilyType;
use crate::values::computed::font::{FontFamily, SingleFontFamily, FontFamilyList};
let fontlist = &self.gecko.mFont.fontlist;
let shared_fontlist = unsafe { fontlist.mFontlist.mBasePtr.to_safe() };
let families = if shared_fontlist.mNames.is_empty() {
let default = SingleFontFamily::Generic(fontlist.mDefaultFontType);
let default = fontlist.mDefaultFontType;
let default = match default {
FontFamilyType::eFamily_serif => {
SingleFontFamily::Generic(atom!("serif"))
}
_ => {
// This can break with some combinations of user prefs, see
// bug 1442195 for example. It doesn't really matter in this
// case...
//
// FIXME(emilio): Probably should be storing the whole
// default font name instead though.
debug_assert_eq!(
default,
FontFamilyType::eFamily_sans_serif,
"Default generic should be serif or sans-serif"
);
SingleFontFamily::Generic(atom!("sans-serif"))
}
};
FontFamilyList::new(Box::new([default]))
} else {
FontFamilyList::SharedFontList(shared_fontlist)

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

@ -326,7 +326,7 @@ ${helpers.predefined_type(
use app_units::Au;
use cssparser::{Parser, ToCss};
use crate::values::computed::font::GenericFontFamily;
use crate::gecko_bindings::structs::FontFamilyType;
use crate::properties::longhands;
use std::fmt;
use std::hash::{Hash, Hasher};
@ -466,7 +466,7 @@ ${helpers.predefined_type(
pub ${name}: longhands::${name}::computed_value::T,
% endfor
pub system_font: SystemFont,
pub default_font_type: GenericFontFamily,
pub default_font_type: FontFamilyType,
}
impl SystemFont {

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

@ -157,6 +157,10 @@ impl FontSize {
}
}
/// XXXManishearth it might be better to
/// animate this as computed, however this complicates
/// clamping and might not be the right thing to do.
/// We should figure it out.
impl ToAnimatedValue for FontSize {
type AnimatedValue = NonNegativeLength;
@ -174,8 +178,8 @@ impl ToAnimatedValue for FontSize {
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(Hash, MallocSizeOf))]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
/// Specifies a prioritized list of font family names or generic family names.
pub struct FontFamily {
/// The actual list of family names.
@ -189,7 +193,7 @@ impl FontFamily {
/// Get default font family as `serif` which is a generic font-family
pub fn serif() -> Self {
FontFamily {
families: FontFamilyList::new(Box::new([SingleFontFamily::Generic(GenericFontFamily::Serif)])),
families: FontFamilyList::new(Box::new([SingleFontFamily::Generic(atom!("serif"))])),
is_system_font: false,
}
}
@ -228,7 +232,7 @@ pub struct FamilyName {
/// Name of the font family
pub name: Atom,
/// Syntax of the font family
pub syntax: FontFamilyNameSyntax,
pub syntax: FamilyNameSyntax,
}
impl ToCss for FamilyName {
@ -237,12 +241,12 @@ impl ToCss for FamilyName {
W: fmt::Write,
{
match self.syntax {
FontFamilyNameSyntax::Quoted => {
FamilyNameSyntax::Quoted => {
dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.name)?;
dest.write_char('"')
},
FontFamilyNameSyntax::Identifiers => {
FamilyNameSyntax::Identifiers => {
let mut first = true;
for ident in self.name.to_string().split(' ') {
if first {
@ -264,12 +268,11 @@ impl ToCss for FamilyName {
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
/// Font family names must either be given quoted as strings,
/// or unquoted as a sequence of one or more identifiers.
#[repr(u8)]
pub enum FontFamilyNameSyntax {
pub enum FamilyNameSyntax {
/// The family name was specified in a quoted form, e.g. "Font Name"
/// or 'Font Name'.
Quoted,
@ -279,56 +282,85 @@ pub enum FontFamilyNameSyntax {
Identifiers,
}
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
/// A set of faces that vary in weight, width or slope.
pub enum SingleFontFamily {
/// The name of a font family of choice.
FamilyName(FamilyName),
/// Generic family name.
Generic(GenericFontFamily),
}
/// A generic font-family name.
///
/// The order here is important, if you change it make sure that
/// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s
/// sSingleGenerics are updated as well.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum GenericFontFamily {
/// No generic family specified, only for internal usage.
#[css(skip)]
None,
Serif,
SansSerif,
#[parse(aliases = "-moz-fixed")]
Monospace,
Cursive,
Fantasy,
/// An internal value for emoji font selection.
#[css(skip)]
#[cfg(feature = "gecko")]
MozEmoji,
Generic(Atom),
}
impl SingleFontFamily {
/// Parse a font-family value.
#[inline]
/// Get font family name as Atom
pub fn atom(&self) -> &Atom {
match *self {
SingleFontFamily::FamilyName(ref family_name) => &family_name.name,
SingleFontFamily::Generic(ref name) => name,
}
}
#[inline]
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
/// Get font family name
pub fn name(&self) -> &str {
self.atom()
}
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
/// Get the corresponding font-family with Atom
pub fn from_atom(input: Atom) -> SingleFontFamily {
match input {
atom!("serif") |
atom!("sans-serif") |
atom!("cursive") |
atom!("fantasy") |
atom!("monospace") => return SingleFontFamily::Generic(input),
_ => {},
}
match_ignore_ascii_case! { &input,
"serif" => return SingleFontFamily::Generic(atom!("serif")),
"sans-serif" => return SingleFontFamily::Generic(atom!("sans-serif")),
"cursive" => return SingleFontFamily::Generic(atom!("cursive")),
"fantasy" => return SingleFontFamily::Generic(atom!("fantasy")),
"monospace" => return SingleFontFamily::Generic(atom!("monospace")),
_ => {}
}
// We don't know if it's quoted or not. So we set it to
// quoted by default.
SingleFontFamily::FamilyName(FamilyName {
name: input,
syntax: FamilyNameSyntax::Quoted,
})
}
/// Parse a font-family value
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if let Ok(value) = input.try(|i| i.expect_string_cloned()) {
return Ok(SingleFontFamily::FamilyName(FamilyName {
name: Atom::from(&*value),
syntax: FontFamilyNameSyntax::Quoted,
syntax: FamilyNameSyntax::Quoted,
}));
}
let first_ident = input.expect_ident()?.clone();
let first_ident = input.expect_ident_cloned()?;
if let Ok(generic) = GenericFontFamily::from_ident(&first_ident) {
return Ok(SingleFontFamily::Generic(generic));
}
// FIXME(bholley): The fast thing to do here would be to look up the
// string (as lowercase) in the static atoms table. We don't have an
// API to do that yet though, so we do the simple thing for now.
let mut css_wide_keyword = false;
match_ignore_ascii_case! { &first_ident,
"serif" => return Ok(SingleFontFamily::Generic(atom!("serif"))),
"sans-serif" => return Ok(SingleFontFamily::Generic(atom!("sans-serif"))),
"cursive" => return Ok(SingleFontFamily::Generic(atom!("cursive"))),
"fantasy" => return Ok(SingleFontFamily::Generic(atom!("fantasy"))),
"monospace" => return Ok(SingleFontFamily::Generic(atom!("monospace"))),
#[cfg(feature = "gecko")]
"-moz-fixed" => return Ok(SingleFontFamily::Generic(atom!("-moz-fixed"))),
let reserved = match_ignore_ascii_case! { &first_ident,
// https://drafts.csswg.org/css-fonts/#propdef-font-family
// "Font family names that happen to be the same as a keyword value
// (`inherit`, `serif`, `sans-serif`, `monospace`, `fantasy`, and `cursive`)
@ -336,15 +368,18 @@ impl SingleFontFamily {
// The keywords initial and default are reserved for future use
// and must also be quoted when used as font names.
// UAs must not consider these keywords as matching the <family-name> type."
"inherit" | "initial" | "unset" | "revert" | "default" => true,
_ => false,
};
"inherit" => css_wide_keyword = true,
"initial" => css_wide_keyword = true,
"unset" => css_wide_keyword = true,
"default" => css_wide_keyword = true,
_ => {}
}
let mut value = first_ident.as_ref().to_owned();
// These keywords are not allowed by themselves.
// The only way this value can be valid with with another keyword.
if reserved {
if css_wide_keyword {
let ident = input.expect_ident()?;
value.push(' ');
value.push_str(&ident);
@ -358,9 +393,9 @@ impl SingleFontFamily {
// `font-family: \ a\ \ b\ \ c\ ;`, it is tricky to serialize them
// as identifiers correctly. Just mark them quoted so we don't need
// to worry about them in serialization code.
FontFamilyNameSyntax::Quoted
FamilyNameSyntax::Quoted
} else {
FontFamilyNameSyntax::Identifiers
FamilyNameSyntax::Identifiers
};
Ok(SingleFontFamily::FamilyName(FamilyName {
name: Atom::from(value),
@ -368,18 +403,94 @@ impl SingleFontFamily {
}))
}
#[cfg(feature = "gecko")]
/// Return the generic ID for a given generic font name
pub fn generic(name: &Atom) -> (structs::FontFamilyType, u8) {
use crate::gecko_bindings::structs::FontFamilyType;
if *name == atom!("serif") {
(FontFamilyType::eFamily_serif, structs::kGenericFont_serif)
} else if *name == atom!("sans-serif") {
(
FontFamilyType::eFamily_sans_serif,
structs::kGenericFont_sans_serif,
)
} else if *name == atom!("cursive") {
(
FontFamilyType::eFamily_cursive,
structs::kGenericFont_cursive,
)
} else if *name == atom!("fantasy") {
(
FontFamilyType::eFamily_fantasy,
structs::kGenericFont_fantasy,
)
} else if *name == atom!("monospace") {
(
FontFamilyType::eFamily_monospace,
structs::kGenericFont_monospace,
)
} else if *name == atom!("-moz-fixed") {
(
FontFamilyType::eFamily_moz_fixed,
structs::kGenericFont_moz_fixed,
)
} else {
panic!("Unknown generic {}", name);
}
}
#[cfg(feature = "gecko")]
/// Get the corresponding font-family with family name
fn from_font_family_name(family: &structs::FontFamilyName) -> SingleFontFamily {
if family.mName.mRawPtr.is_null() {
debug_assert_ne!(family.mGeneric, GenericFontFamily::None);
return SingleFontFamily::Generic(family.mGeneric);
use crate::gecko_bindings::structs::FontFamilyType;
match family.mType {
FontFamilyType::eFamily_sans_serif => SingleFontFamily::Generic(atom!("sans-serif")),
FontFamilyType::eFamily_serif => SingleFontFamily::Generic(atom!("serif")),
FontFamilyType::eFamily_monospace => SingleFontFamily::Generic(atom!("monospace")),
FontFamilyType::eFamily_cursive => SingleFontFamily::Generic(atom!("cursive")),
FontFamilyType::eFamily_fantasy => SingleFontFamily::Generic(atom!("fantasy")),
FontFamilyType::eFamily_moz_fixed => SingleFontFamily::Generic(atom!("-moz-fixed")),
FontFamilyType::eFamily_named => {
let name = unsafe { Atom::from_raw(family.mName.mRawPtr) };
SingleFontFamily::FamilyName(FamilyName {
name,
syntax: FamilyNameSyntax::Identifiers,
})
},
FontFamilyType::eFamily_named_quoted => {
let name = unsafe { Atom::from_raw(family.mName.mRawPtr) };
SingleFontFamily::FamilyName(FamilyName {
name,
syntax: FamilyNameSyntax::Quoted,
})
},
_ => panic!("Found unexpected font FontFamilyType"),
}
}
}
impl ToCss for SingleFontFamily {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
match *self {
SingleFontFamily::FamilyName(ref name) => name.to_css(dest),
// All generic values accepted by the parser are known to not require escaping.
SingleFontFamily::Generic(ref name) => {
#[cfg(feature = "gecko")]
{
// We should treat -moz-fixed as monospace
if name == &atom!("-moz-fixed") {
return dest.write_str("monospace");
}
}
write!(dest, "{}", name)
},
}
let name = unsafe { Atom::from_raw(family.mName.mRawPtr) };
SingleFontFamily::FamilyName(FamilyName {
name,
syntax: family.mSyntax,
})
}
}
@ -395,7 +506,7 @@ pub enum FontFamilyList {
/// A strong reference to a Gecko SharedFontList object.
SharedFontList(RefPtr<structs::SharedFontList>),
/// A font-family generic ID.
Generic(GenericFontFamily),
Generic(structs::FontFamilyType),
}
#[cfg(feature = "gecko")]
@ -403,19 +514,38 @@ impl ToShmem for FontFamilyList {
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
// In practice, the only SharedFontList objects we create from shared
// style sheets are ones with a single generic entry.
ManuallyDrop::new(match *self {
FontFamilyList::SharedFontList(ref r) => {
ManuallyDrop::new(match self {
FontFamilyList::SharedFontList(r) => {
assert!(
r.mNames.len() == 1 && r.mNames[0].mName.mRawPtr.is_null(),
"ToShmem failed for FontFamilyList: cannot handle non-generic families",
);
FontFamilyList::Generic(r.mNames[0].mGeneric)
FontFamilyList::Generic(r.mNames[0].mType)
},
FontFamilyList::Generic(t) => FontFamilyList::Generic(t),
FontFamilyList::Generic(t) => FontFamilyList::Generic(*t),
})
}
}
#[cfg(feature = "gecko")]
impl Hash for FontFamilyList {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
use crate::string_cache::WeakAtom;
for name in self.shared_font_list().mNames.iter() {
name.mType.hash(state);
if !name.mName.mRawPtr.is_null() {
unsafe {
WeakAtom::new(name.mName.mRawPtr).hash(state);
}
}
}
}
}
#[cfg(feature = "gecko")]
impl PartialEq for FontFamilyList {
fn eq(&self, other: &FontFamilyList) -> bool {
@ -426,8 +556,7 @@ impl PartialEq for FontFamilyList {
return false;
}
for (a, b) in self_list.mNames.iter().zip(other_list.mNames.iter()) {
if a.mSyntax != b.mSyntax || a.mName.mRawPtr != b.mName.mRawPtr ||
a.mGeneric != b.mGeneric {
if a.mType != b.mType || a.mName.mRawPtr != b.mName.mRawPtr {
return false;
}
}
@ -459,17 +588,19 @@ impl FontFamilyList {
for family in families.iter() {
match *family {
SingleFontFamily::FamilyName(ref f) => {
let quoted = matches!(f.syntax, FamilyNameSyntax::Quoted);
unsafe {
bindings::Gecko_nsTArray_FontFamilyName_AppendNamed(
names,
f.name.as_ptr(),
f.syntax,
quoted,
);
}
},
SingleFontFamily::Generic(family) => {
SingleFontFamily::Generic(ref name) => {
let (family_type, _generic) = SingleFontFamily::generic(name);
unsafe {
bindings::Gecko_nsTArray_FontFamilyName_AppendGeneric(names, family);
bindings::Gecko_nsTArray_FontFamilyName_AppendGeneric(names, family_type);
}
},
}
@ -494,11 +625,12 @@ impl FontFamilyList {
}
/// Return the generic ID if it is a single generic font
pub fn single_generic(&self) -> Option<GenericFontFamily> {
#[cfg(feature = "gecko")]
pub fn single_generic(&self) -> Option<u8> {
let mut iter = self.iter();
if let Some(SingleFontFamily::Generic(f)) = iter.next() {
if let Some(SingleFontFamily::Generic(ref name)) = iter.next() {
if iter.next().is_none() {
return Some(f);
return Some(SingleFontFamily::generic(name).1);
}
}
None
@ -507,12 +639,13 @@ impl FontFamilyList {
/// Return a reference to the Gecko SharedFontList.
#[cfg(feature = "gecko")]
pub fn shared_font_list(&self) -> &RefPtr<structs::SharedFontList> {
match *self {
FontFamilyList::SharedFontList(ref r) => r,
match self {
FontFamilyList::SharedFontList(r) => r,
FontFamilyList::Generic(t) => {
unsafe {
// TODO(heycam): Should really add StaticRefPtr sugar.
let index = t as usize;
let index =
(*t as usize) - (structs::FontFamilyType::eFamily_generic_first as usize);
mem::transmute::<
&structs::StaticRefPtr<structs::SharedFontList>,
&RefPtr<structs::SharedFontList>,

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

@ -515,8 +515,7 @@ impl From<LengthPercentage> for FontSize {
}
/// Specifies a prioritized list of font family names or generic family names.
#[derive(Clone, Debug, Eq, PartialEq, ToCss, ToShmem)]
#[cfg_attr(feature = "servo", derive(Hash))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss, ToShmem)]
pub enum FontFamily {
/// List of `font-family`
#[css(comma)]
@ -531,8 +530,18 @@ impl FontFamily {
/// Parse a specified font-family value
pub fn parse_specified<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let values = input.parse_comma_separated(SingleFontFamily::parse)?;
Ok(FontFamily::Values(FontFamilyList::new(values.into_boxed_slice())))
input
.parse_comma_separated(|input| SingleFontFamily::parse(input))
.map(|v| FontFamily::Values(FontFamilyList::new(v.into_boxed_slice())))
}
#[cfg(feature = "gecko")]
/// Return the generic ID if it is a single generic font
pub fn single_generic(&self) -> Option<u8> {
match *self {
FontFamily::Values(ref values) => values.single_generic(),
_ => None,
}
}
}

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

@ -61,8 +61,6 @@ include = [
"FontDisplay",
"FontFaceSourceListComponent",
"FontLanguageOverride",
"GenericFontFamily",
"FontFamilyNameSyntax",
"OverflowWrap",
"TimingFunction",
"PathCommand",