зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1537575 - Cleanup generic font-family handling. r=jfkthame
To be more similar between Rust and C++. This introduces GenericFontFamily and exposes that plus FontFamilyNameSyntax to C++, using that where appropriate instead of plain uint8_t as we were doing. As a follow-up, as discussed on IRC with Jonathan, we can remove the -moz-fixed family, and turn it just into an alias of Monospace. The only non-trivial change is the MatchType changes, but they're ok I think. The code already assumed at most one CSS generic, and the struct still takes 8 bits. I've verified that the relevant tests are passing (though try is closed). Differential Revision: https://phabricator.services.mozilla.com/D24272 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
b0f2640ec4
Коммит
2188b25101
|
@ -3911,8 +3911,8 @@ gfxFontGroup* CanvasRenderingContext2D::GetCurrentFontStyle() {
|
|||
GetAppUnitsValues(&perDevPixel, &perCSSPixel);
|
||||
gfxFloat devToCssSize = gfxFloat(perDevPixel) / gfxFloat(perCSSPixel);
|
||||
CurrentState().fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(
|
||||
FontFamilyList(eFamily_sans_serif), &style, tp, nullptr,
|
||||
devToCssSize);
|
||||
FontFamilyList(StyleGenericFontFamily::SansSerif), &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(FontFamilyType aGenericType, nscoord aSize)
|
||||
nsFont::nsFont(StyleGenericFontFamily aGenericType, nscoord aSize)
|
||||
: fontlist(aGenericType), size(aSize) {}
|
||||
|
||||
nsFont::nsFont(const nsFont& aOther) = default;
|
||||
|
|
|
@ -21,22 +21,6 @@
|
|||
|
||||
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;
|
||||
|
@ -117,7 +101,7 @@ struct nsFont {
|
|||
nsFont(const mozilla::FontFamilyList& aFontlist, nscoord aSize);
|
||||
|
||||
// initialize the font with a single generic
|
||||
nsFont(mozilla::FontFamilyType aGenericType, nscoord aSize);
|
||||
nsFont(mozilla::StyleGenericFontFamily, nscoord aSize);
|
||||
|
||||
// Make a copy of the given font
|
||||
nsFont(const nsFont& aFont);
|
||||
|
|
|
@ -1972,13 +1972,13 @@ bool gfxFcPlatformFontList::GetStandardFamilyName(const nsCString& aFontName,
|
|||
}
|
||||
|
||||
void gfxFcPlatformFontList::AddGenericFonts(
|
||||
mozilla::FontFamilyType aGenericType, nsAtom* aLanguage,
|
||||
mozilla::StyleGenericFontFamily aGenericType, nsAtom* aLanguage,
|
||||
nsTArray<FamilyAndGeneric>& aFamilyList) {
|
||||
bool usePrefFontList = false;
|
||||
|
||||
// treat -moz-fixed as monospace
|
||||
if (aGenericType == eFamily_moz_fixed) {
|
||||
aGenericType = eFamily_monospace;
|
||||
if (aGenericType == StyleGenericFontFamily::MozFixed) {
|
||||
aGenericType = StyleGenericFontFamily::Monospace;
|
||||
}
|
||||
|
||||
const char* generic = GetGenericName(aGenericType);
|
||||
|
|
|
@ -301,7 +301,7 @@ class gfxFcPlatformFontList : public gfxPlatformFontList {
|
|||
FcConfig* GetLastConfig() const { return mLastConfig; }
|
||||
|
||||
// override to use fontconfig lookup for generics
|
||||
void AddGenericFonts(mozilla::FontFamilyType aGenericType, nsAtom* aLanguage,
|
||||
void AddGenericFonts(mozilla::StyleGenericFontFamily, nsAtom* aLanguage,
|
||||
nsTArray<FamilyAndGeneric>& aFamilyList) override;
|
||||
|
||||
void ClearLangGroupPrefFonts() override;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#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"
|
||||
|
@ -4000,10 +4001,11 @@ bool gfxFont::TryGetMathTable() {
|
|||
void SharedFontList::Initialize() {
|
||||
sEmpty = new SharedFontList();
|
||||
|
||||
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);
|
||||
for (auto i : IntegerRange(ArrayLength(sSingleGenerics))) {
|
||||
auto type = static_cast<StyleGenericFontFamily>(i);
|
||||
if (type != StyleGenericFontFamily::None) {
|
||||
sSingleGenerics[i] = new SharedFontList(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4019,4 +4021,4 @@ void SharedFontList::Shutdown() {
|
|||
StaticRefPtr<SharedFontList> SharedFontList::sEmpty;
|
||||
|
||||
StaticRefPtr<SharedFontList>
|
||||
SharedFontList::sSingleGenerics[eFamily_generic_count_including_special];
|
||||
SharedFontList::sSingleGenerics[size_t(StyleGenericFontFamily::MozEmoji)];
|
||||
|
|
|
@ -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::FontFamilyType::eFamily_none) {}
|
||||
: mFamily(), mGeneric(mozilla::StyleGenericFontFamily::None) {}
|
||||
FamilyAndGeneric(const FamilyAndGeneric& aOther)
|
||||
: mFamily(aOther.mFamily), mGeneric(aOther.mGeneric) {}
|
||||
explicit FamilyAndGeneric(
|
||||
gfxFontFamily* aFamily,
|
||||
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
|
||||
explicit FamilyAndGeneric(gfxFontFamily* aFamily,
|
||||
mozilla::StyleGenericFontFamily aGeneric =
|
||||
mozilla::StyleGenericFontFamily::None)
|
||||
: mFamily(aFamily), mGeneric(aGeneric) {}
|
||||
explicit FamilyAndGeneric(
|
||||
mozilla::fontlist::Family* aFamily,
|
||||
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
|
||||
explicit FamilyAndGeneric(mozilla::fontlist::Family* aFamily,
|
||||
mozilla::StyleGenericFontFamily aGeneric =
|
||||
mozilla::StyleGenericFontFamily::None)
|
||||
: mFamily(aFamily), mGeneric(aGeneric) {}
|
||||
explicit FamilyAndGeneric(
|
||||
const FontFamily& aFamily,
|
||||
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
|
||||
explicit FamilyAndGeneric(const FontFamily& aFamily,
|
||||
mozilla::StyleGenericFontFamily aGeneric =
|
||||
mozilla::StyleGenericFontFamily::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::FontFamilyType mGeneric;
|
||||
mozilla::StyleGenericFontFamily mGeneric;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "nsDebug.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
@ -19,116 +20,73 @@
|
|||
|
||||
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 {
|
||||
FontFamilyName() : mType(eFamily_none) {}
|
||||
using Syntax = StyleFontFamilyNameSyntax;
|
||||
|
||||
FontFamilyName() = delete;
|
||||
|
||||
// named font family - e.g. Helvetica
|
||||
explicit FontFamilyName(nsAtom* aFamilyName,
|
||||
QuotedName aQuoted = eUnquotedName) {
|
||||
mType = (aQuoted == eQuotedName) ? eFamily_named_quoted : eFamily_named;
|
||||
mName = aFamilyName;
|
||||
}
|
||||
explicit FontFamilyName(nsAtom* aFamilyName, Syntax aSyntax)
|
||||
: mName(aFamilyName), mSyntax(aSyntax) {}
|
||||
|
||||
explicit FontFamilyName(const nsACString& aFamilyName,
|
||||
QuotedName aQuoted = eUnquotedName) {
|
||||
mType = (aQuoted == eQuotedName) ? eFamily_named_quoted : eFamily_named;
|
||||
mName = NS_Atomize(aFamilyName);
|
||||
}
|
||||
explicit FontFamilyName(const nsACString& aFamilyName, Syntax aSyntax)
|
||||
: mName(NS_Atomize(aFamilyName)), mSyntax(aSyntax) {}
|
||||
|
||||
// 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;
|
||||
explicit FontFamilyName(StyleGenericFontFamily aGeneric)
|
||||
: mGeneric(aGeneric) {
|
||||
MOZ_ASSERT(mGeneric != StyleGenericFontFamily::None);
|
||||
}
|
||||
|
||||
FontFamilyName(const FontFamilyName& aCopy) {
|
||||
mType = aCopy.mType;
|
||||
mName = aCopy.mName;
|
||||
}
|
||||
FontFamilyName(const FontFamilyName&) = default;
|
||||
|
||||
bool IsNamed() const {
|
||||
return mType == eFamily_named || mType == eFamily_named_quoted;
|
||||
}
|
||||
bool IsNamed() const { return !!mName; }
|
||||
|
||||
bool IsGeneric() const { return !IsNamed(); }
|
||||
|
||||
void AppendToString(nsACString& aFamilyList, bool aQuotes = true) const {
|
||||
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:
|
||||
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:
|
||||
aFamilyList.AppendLiteral("serif");
|
||||
break;
|
||||
case eFamily_sans_serif:
|
||||
case StyleGenericFontFamily::SansSerif:
|
||||
aFamilyList.AppendLiteral("sans-serif");
|
||||
break;
|
||||
case eFamily_monospace:
|
||||
case StyleGenericFontFamily::Monospace:
|
||||
aFamilyList.AppendLiteral("monospace");
|
||||
break;
|
||||
case eFamily_cursive:
|
||||
aFamilyList.AppendLiteral("cursive");
|
||||
break;
|
||||
case eFamily_fantasy:
|
||||
aFamilyList.AppendLiteral("fantasy");
|
||||
break;
|
||||
case eFamily_moz_fixed:
|
||||
case StyleGenericFontFamily::MozFixed:
|
||||
aFamilyList.AppendLiteral("-moz-fixed");
|
||||
break;
|
||||
case StyleGenericFontFamily::Cursive:
|
||||
aFamilyList.AppendLiteral("cursive");
|
||||
break;
|
||||
case StyleGenericFontFamily::Fantasy:
|
||||
aFamilyList.AppendLiteral("fantasy");
|
||||
break;
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Unknown generic font-family!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -141,32 +99,34 @@ struct FontFamilyName final {
|
|||
NS_ASSERTION(aFamilyOrGenericName.FindChar(',') == -1,
|
||||
"Convert method should only be passed a single family name");
|
||||
|
||||
FontFamilyType genericType = eFamily_none;
|
||||
auto genericType = StyleGenericFontFamily::None;
|
||||
if (aFamilyOrGenericName.LowerCaseEqualsLiteral("serif")) {
|
||||
genericType = eFamily_serif;
|
||||
genericType = StyleGenericFontFamily::Serif;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("sans-serif")) {
|
||||
genericType = eFamily_sans_serif;
|
||||
genericType = StyleGenericFontFamily::SansSerif;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("monospace")) {
|
||||
genericType = eFamily_monospace;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("cursive")) {
|
||||
genericType = eFamily_cursive;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("fantasy")) {
|
||||
genericType = eFamily_fantasy;
|
||||
genericType = StyleGenericFontFamily::Monospace;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("-moz-fixed")) {
|
||||
genericType = eFamily_moz_fixed;
|
||||
genericType = StyleGenericFontFamily::MozFixed;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("cursive")) {
|
||||
genericType = StyleGenericFontFamily::Cursive;
|
||||
} else if (aFamilyOrGenericName.LowerCaseEqualsLiteral("fantasy")) {
|
||||
genericType = StyleGenericFontFamily::Fantasy;
|
||||
} else {
|
||||
return FontFamilyName(aFamilyOrGenericName, eUnquotedName);
|
||||
return FontFamilyName(aFamilyOrGenericName, Syntax::Identifiers);
|
||||
}
|
||||
|
||||
return FontFamilyName(genericType);
|
||||
}
|
||||
|
||||
FontFamilyType mType;
|
||||
RefPtr<nsAtom> mName; // null if mType != eFamily_named
|
||||
RefPtr<nsAtom> mName; // null if mGeneric != Default
|
||||
StyleFontFamilyNameSyntax mSyntax = StyleFontFamilyNameSyntax::Quoted;
|
||||
StyleGenericFontFamily mGeneric = StyleGenericFontFamily::None;
|
||||
};
|
||||
|
||||
inline bool operator==(const FontFamilyName& a, const FontFamilyName& b) {
|
||||
return a.mType == b.mType && a.mName == b.mName;
|
||||
return a.mName == b.mName && a.mSyntax == b.mSyntax &&
|
||||
a.mGeneric == b.mGeneric;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,36 +137,25 @@ 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() {}
|
||||
SharedFontList() = default;
|
||||
|
||||
explicit SharedFontList(FontFamilyType aGenericType)
|
||||
explicit SharedFontList(StyleGenericFontFamily aGenericType)
|
||||
: mNames{FontFamilyName(aGenericType)} {}
|
||||
|
||||
SharedFontList(nsAtom* aFamilyName, QuotedName aQuoted)
|
||||
: mNames{FontFamilyName(aFamilyName, aQuoted)} {}
|
||||
SharedFontList(nsAtom* aFamilyName, Syntax aSyntax)
|
||||
: mNames{FontFamilyName(aFamilyName, aSyntax)} {}
|
||||
|
||||
SharedFontList(const nsACString& aFamilyName, QuotedName aQuoted)
|
||||
: mNames{FontFamilyName(aFamilyName, aQuoted)} {}
|
||||
|
||||
explicit SharedFontList(const FontFamilyName& aName) : mNames{aName} {}
|
||||
SharedFontList(const nsACString& aFamilyName, Syntax aSyntax)
|
||||
: mNames{FontFamilyName(aFamilyName, aSyntax)} {}
|
||||
|
||||
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);
|
||||
|
@ -228,7 +177,7 @@ class SharedFontList {
|
|||
static void Shutdown();
|
||||
static StaticRefPtr<SharedFontList> sEmpty;
|
||||
static StaticRefPtr<SharedFontList>
|
||||
sSingleGenerics[eFamily_generic_count_including_special];
|
||||
sSingleGenerics[size_t(StyleGenericFontFamily::MozEmoji)];
|
||||
|
||||
private:
|
||||
~SharedFontList() = default;
|
||||
|
@ -240,37 +189,29 @@ 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())),
|
||||
mDefaultFontType(eFamily_none) {}
|
||||
FontFamilyList() : mFontlist(WrapNotNull(SharedFontList::sEmpty.get())) {}
|
||||
|
||||
explicit FontFamilyList(FontFamilyType aGenericType)
|
||||
: mFontlist(MakeNotNull<SharedFontList*>(aGenericType)),
|
||||
mDefaultFontType(eFamily_none) {}
|
||||
explicit FontFamilyList(StyleGenericFontFamily aGenericType)
|
||||
: mFontlist(MakeNotNull<SharedFontList*>(aGenericType)) {}
|
||||
|
||||
FontFamilyList(nsAtom* aFamilyName, QuotedName aQuoted)
|
||||
: mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aQuoted)),
|
||||
mDefaultFontType(eFamily_none) {}
|
||||
FontFamilyList(nsAtom* 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) {}
|
||||
FontFamilyList(const nsACString& aFamilyName, Syntax aSyntax)
|
||||
: mFontlist(MakeNotNull<SharedFontList*>(aFamilyName, aSyntax)) {}
|
||||
|
||||
explicit FontFamilyList(nsTArray<FontFamilyName>&& aNames)
|
||||
: mFontlist(MakeNotNull<SharedFontList*>(std::move(aNames))),
|
||||
mDefaultFontType(eFamily_none) {}
|
||||
: mFontlist(MakeNotNull<SharedFontList*>(std::move(aNames))) {}
|
||||
|
||||
FontFamilyList(const FontFamilyList& aOther)
|
||||
: mFontlist(aOther.mFontlist),
|
||||
mDefaultFontType(aOther.mDefaultFontType) {}
|
||||
|
||||
explicit FontFamilyList(NotNull<SharedFontList*> aFontList)
|
||||
: mFontlist(aFontList), mDefaultFontType(eFamily_none) {}
|
||||
: mFontlist(aFontList) {}
|
||||
|
||||
void SetFontlist(nsTArray<FontFamilyName>&& aNames) {
|
||||
mFontlist = MakeNotNull<SharedFontList*>(std::move(aNames));
|
||||
|
@ -292,13 +233,12 @@ 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.mType == mDefaultFontType) {
|
||||
if (name.mGeneric == mDefaultFontType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +253,8 @@ class FontFamilyList {
|
|||
for (uint32_t i = 0; i < len; i++) {
|
||||
const FontFamilyName name = mFontlist->mNames[i];
|
||||
if (name.IsGeneric()) {
|
||||
if (name.mType == eFamily_cursive || name.mType == eFamily_fantasy) {
|
||||
if (name.mGeneric == StyleGenericFontFamily::Cursive ||
|
||||
name.mGeneric == StyleGenericFontFamily::Fantasy) {
|
||||
continue;
|
||||
}
|
||||
if (i > 0) {
|
||||
|
@ -329,10 +270,10 @@ class FontFamilyList {
|
|||
return false;
|
||||
}
|
||||
|
||||
void PrependGeneric(FontFamilyType aType) {
|
||||
void PrependGeneric(StyleGenericFontFamily aGeneric) {
|
||||
nsTArray<FontFamilyName> names;
|
||||
names.AppendElements(mFontlist->mNames);
|
||||
names.InsertElementAt(0, FontFamilyName(aType));
|
||||
names.InsertElementAt(0, FontFamilyName(aGeneric));
|
||||
SetFontlist(std::move(names));
|
||||
}
|
||||
|
||||
|
@ -348,11 +289,11 @@ class FontFamilyList {
|
|||
const FontFamilyName& name = names[i];
|
||||
name.AppendToString(aFamilyList, aQuotes);
|
||||
}
|
||||
if (aIncludeDefault && mDefaultFontType != eFamily_none) {
|
||||
if (aIncludeDefault && mDefaultFontType != StyleGenericFontFamily::None) {
|
||||
if (!aFamilyList.IsEmpty()) {
|
||||
aFamilyList.Append(',');
|
||||
}
|
||||
if (mDefaultFontType == eFamily_serif) {
|
||||
if (mDefaultFontType == StyleGenericFontFamily::Serif) {
|
||||
aFamilyList.AppendLiteral("serif");
|
||||
} else {
|
||||
aFamilyList.AppendLiteral("sans-serif");
|
||||
|
@ -375,10 +316,11 @@ class FontFamilyList {
|
|||
return false;
|
||||
}
|
||||
|
||||
FontFamilyType GetDefaultFontType() const { return mDefaultFontType; }
|
||||
void SetDefaultFontType(FontFamilyType aType) {
|
||||
NS_ASSERTION(aType == eFamily_none || aType == eFamily_serif ||
|
||||
aType == eFamily_sans_serif,
|
||||
StyleGenericFontFamily GetDefaultFontType() const { return mDefaultFontType; }
|
||||
void SetDefaultFontType(StyleGenericFontFamily aType) {
|
||||
NS_ASSERTION(aType == StyleGenericFontFamily::None ||
|
||||
aType == StyleGenericFontFamily::Serif ||
|
||||
aType == StyleGenericFontFamily::SansSerif,
|
||||
"default font type must be either serif or sans-serif");
|
||||
mDefaultFontType = aType;
|
||||
}
|
||||
|
@ -396,7 +338,8 @@ class FontFamilyList {
|
|||
|
||||
protected:
|
||||
NotNull<RefPtr<SharedFontList>> mFontlist;
|
||||
FontFamilyType mDefaultFontType; // none, serif or sans-serif
|
||||
StyleGenericFontFamily mDefaultFontType =
|
||||
StyleGenericFontFamily::None; // or 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(
|
||||
FontFamilyType aGenericType, eFontPrefLang aPrefLang,
|
||||
StyleGenericFontFamily aGenericType, eFontPrefLang aPrefLang,
|
||||
PrefFontList* aGenericFamilies) {
|
||||
const char* langGroupStr = GetPrefLangName(aPrefLang);
|
||||
const char* generic = GetGenericName(aGenericType);
|
||||
|
@ -957,13 +957,13 @@ void gfxPlatformFontList::GetFontFamiliesFromGenericFamilies(
|
|||
}
|
||||
|
||||
gfxPlatformFontList::PrefFontList* gfxPlatformFontList::GetPrefFontsLangGroup(
|
||||
mozilla::FontFamilyType aGenericType, eFontPrefLang aPrefLang) {
|
||||
StyleGenericFontFamily aGenericType, eFontPrefLang aPrefLang) {
|
||||
// treat -moz-fixed as monospace
|
||||
if (aGenericType == eFamily_moz_fixed) {
|
||||
aGenericType = eFamily_monospace;
|
||||
if (aGenericType == StyleGenericFontFamily::MozFixed) {
|
||||
aGenericType = StyleGenericFontFamily::Monospace;
|
||||
}
|
||||
|
||||
if (aGenericType == eFamily_moz_emoji) {
|
||||
if (aGenericType == StyleGenericFontFamily::MozEmoji) {
|
||||
// Emoji font has no lang
|
||||
PrefFontList* prefFonts = mEmojiPrefFont.get();
|
||||
if (MOZ_UNLIKELY(!prefFonts)) {
|
||||
|
@ -974,17 +974,18 @@ gfxPlatformFontList::PrefFontList* gfxPlatformFontList::GetPrefFontsLangGroup(
|
|||
return prefFonts;
|
||||
}
|
||||
|
||||
PrefFontList* prefFonts = mLangGroupPrefFonts[aPrefLang][aGenericType].get();
|
||||
auto index = static_cast<size_t>(aGenericType);
|
||||
PrefFontList* prefFonts = mLangGroupPrefFonts[aPrefLang][index].get();
|
||||
if (MOZ_UNLIKELY(!prefFonts)) {
|
||||
prefFonts = new PrefFontList;
|
||||
ResolveGenericFontNames(aGenericType, aPrefLang, prefFonts);
|
||||
mLangGroupPrefFonts[aPrefLang][aGenericType].reset(prefFonts);
|
||||
mLangGroupPrefFonts[aPrefLang][index].reset(prefFonts);
|
||||
}
|
||||
return prefFonts;
|
||||
}
|
||||
|
||||
void gfxPlatformFontList::AddGenericFonts(
|
||||
mozilla::FontFamilyType aGenericType, nsAtom* aLanguage,
|
||||
mozilla::StyleGenericFontFamily aGenericType, nsAtom* aLanguage,
|
||||
nsTArray<FamilyAndGeneric>& aFamilyList) {
|
||||
// map lang ==> langGroup
|
||||
nsAtom* langGroup = GetLangGroup(aLanguage);
|
||||
|
@ -1282,10 +1283,10 @@ void gfxPlatformFontList::AppendPrefLang(eFontPrefLang aPrefLangs[],
|
|||
}
|
||||
}
|
||||
|
||||
mozilla::FontFamilyType gfxPlatformFontList::GetDefaultGeneric(
|
||||
mozilla::StyleGenericFontFamily gfxPlatformFontList::GetDefaultGeneric(
|
||||
eFontPrefLang aLang) {
|
||||
if (aLang == eFontPrefLang_Emoji) {
|
||||
return eFamily_moz_emoji;
|
||||
return StyleGenericFontFamily::MozEmoji;
|
||||
}
|
||||
|
||||
// initialize lang group pref font defaults (i.e. serif/sans-serif)
|
||||
|
@ -1297,9 +1298,9 @@ mozilla::FontFamilyType gfxPlatformFontList::GetDefaultGeneric(
|
|||
nsAutoCString serifOrSans;
|
||||
Preferences::GetCString(prefDefaultFontType.get(), serifOrSans);
|
||||
if (serifOrSans.EqualsLiteral("sans-serif")) {
|
||||
mDefaultGenericsLangGroup[i] = eFamily_sans_serif;
|
||||
mDefaultGenericsLangGroup[i] = StyleGenericFontFamily::SansSerif;
|
||||
} else {
|
||||
mDefaultGenericsLangGroup[i] = eFamily_serif;
|
||||
mDefaultGenericsLangGroup[i] = StyleGenericFontFamily::Serif;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1307,7 +1308,7 @@ mozilla::FontFamilyType gfxPlatformFontList::GetDefaultGeneric(
|
|||
if (uint32_t(aLang) < ArrayLength(gPrefLangNames)) {
|
||||
return mDefaultGenericsLangGroup[uint32_t(aLang)];
|
||||
}
|
||||
return eFamily_serif;
|
||||
return StyleGenericFontFamily::Serif;
|
||||
}
|
||||
|
||||
FontFamily gfxPlatformFontList::GetDefaultFont(const gfxFontStyle* aStyle) {
|
||||
|
@ -1343,7 +1344,7 @@ nsAtom* gfxPlatformFontList::GetLangGroup(nsAtom* aLanguage) {
|
|||
}
|
||||
|
||||
/* static */ const char* gfxPlatformFontList::GetGenericName(
|
||||
FontFamilyType aGenericType) {
|
||||
StyleGenericFontFamily aGenericType) {
|
||||
static const char kGeneric_serif[] = "serif";
|
||||
static const char kGeneric_sans_serif[] = "sans-serif";
|
||||
static const char kGeneric_monospace[] = "monospace";
|
||||
|
@ -1351,32 +1352,23 @@ 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 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;
|
||||
case StyleGenericFontFamily::Serif:
|
||||
return kGeneric_serif;
|
||||
case StyleGenericFontFamily::SansSerif:
|
||||
return kGeneric_sans_serif;
|
||||
case StyleGenericFontFamily::Monospace:
|
||||
case StyleGenericFontFamily::MozFixed:
|
||||
return kGeneric_monospace;
|
||||
case StyleGenericFontFamily::Cursive:
|
||||
return kGeneric_cursive;
|
||||
case StyleGenericFontFamily::Fantasy:
|
||||
return kGeneric_fantasy;
|
||||
default:
|
||||
break;
|
||||
MOZ_ASSERT_UNREACHABLE("Unknown generic");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return generic;
|
||||
}
|
||||
|
||||
void gfxPlatformFontList::InitLoader() {
|
||||
|
@ -1504,9 +1496,8 @@ void gfxPlatformFontList::ClearLangGroupPrefFonts() {
|
|||
for (uint32_t i = eFontPrefLang_First;
|
||||
i < eFontPrefLang_First + eFontPrefLang_Count; i++) {
|
||||
auto& prefFontsLangGroup = mLangGroupPrefFonts[i];
|
||||
for (uint32_t j = eFamily_generic_first;
|
||||
j < eFamily_generic_first + eFamily_generic_count; j++) {
|
||||
prefFontsLangGroup[j] = nullptr;
|
||||
for (auto& pref : prefFontsLangGroup) {
|
||||
pref = nullptr;
|
||||
}
|
||||
}
|
||||
mCJKPrefLangs.Clear();
|
||||
|
@ -1564,9 +1555,7 @@ void gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
|||
for (uint32_t i = eFontPrefLang_First;
|
||||
i < eFontPrefLang_First + eFontPrefLang_Count; i++) {
|
||||
auto& prefFontsLangGroup = mLangGroupPrefFonts[i];
|
||||
for (uint32_t j = eFamily_generic_first;
|
||||
j < eFamily_generic_first + eFamily_generic_count; j++) {
|
||||
PrefFontList* pf = prefFontsLangGroup[j].get();
|
||||
for (const UniquePtr<PrefFontList>& pf : prefFontsLangGroup) {
|
||||
if (pf) {
|
||||
aSizes->mFontListSize += pf->ShallowSizeOfExcludingThis(aMallocSizeOf);
|
||||
}
|
||||
|
|
|
@ -258,12 +258,12 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
|
|||
aLoaderState = (uint32_t)mState;
|
||||
}
|
||||
|
||||
virtual void AddGenericFonts(mozilla::FontFamilyType aGenericType,
|
||||
virtual void AddGenericFonts(mozilla::StyleGenericFontFamily aGenericType,
|
||||
nsAtom* aLanguage,
|
||||
nsTArray<FamilyAndGeneric>& aFamilyList);
|
||||
|
||||
PrefFontList* GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType,
|
||||
eFontPrefLang aPrefLang);
|
||||
PrefFontList* GetPrefFontsLangGroup(
|
||||
mozilla::StyleGenericFontFamily 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::FontFamilyType GetDefaultGeneric(eFontPrefLang aLang);
|
||||
mozilla::StyleGenericFontFamily GetDefaultGeneric(eFontPrefLang aLang);
|
||||
|
||||
// Returns true if the font family whitelist is not empty.
|
||||
bool IsFontFamilyWhitelistActive();
|
||||
|
@ -305,7 +305,8 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
|
|||
bool AddWithLegacyFamilyName(const nsACString& aLegacyName,
|
||||
gfxFontEntry* aFontEntry);
|
||||
|
||||
static const char* GetGenericName(mozilla::FontFamilyType aGenericType);
|
||||
static const char* GetGenericName(
|
||||
mozilla::StyleGenericFontFamily aGenericType);
|
||||
|
||||
protected:
|
||||
class InitOtherFamilyNamesRunnable : public mozilla::CancelableRunnable {
|
||||
|
@ -486,7 +487,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
|
|||
|
||||
void RebuildLocalFonts();
|
||||
|
||||
void ResolveGenericFontNames(mozilla::FontFamilyType aGenericType,
|
||||
void ResolveGenericFontNames(mozilla::StyleGenericFontFamily aGenericType,
|
||||
eFontPrefLang aPrefLang,
|
||||
PrefFontList* aGenericFamilies);
|
||||
|
||||
|
@ -552,8 +553,9 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
|
|||
mozilla::UniquePtr<nsTHashtable<nsCStringHashKey>> mOtherNamesMissed;
|
||||
|
||||
typedef mozilla::RangedArray<mozilla::UniquePtr<PrefFontList>,
|
||||
mozilla::eFamily_generic_first,
|
||||
mozilla::eFamily_generic_count>
|
||||
size_t(mozilla::StyleGenericFontFamily::None),
|
||||
size_t(
|
||||
mozilla::StyleGenericFontFamily::MozEmoji)>
|
||||
PrefFontsForLangGroup;
|
||||
mozilla::RangedArray<PrefFontsForLangGroup, eFontPrefLang_First,
|
||||
eFontPrefLang_Count>
|
||||
|
@ -589,7 +591,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
|
|||
nsLanguageAtomService* mLangService;
|
||||
|
||||
nsTArray<uint32_t> mCJKPrefLangs;
|
||||
nsTArray<mozilla::FontFamilyType> mDefaultGenericsLangGroup;
|
||||
nsTArray<mozilla::StyleGenericFontFamily> 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::kFontGroup, aCharIndex, false,
|
||||
AddGlyphRun(aFont, FontMatchType::Kind::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::kFontGroup, aCharIndex, false,
|
||||
AddGlyphRun(aFont, FontMatchType::Kind::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.mType, mStyle.language, fonts);
|
||||
pfl->AddGenericFonts(name.mGeneric, 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() != eFamily_none &&
|
||||
if (mFamilyList.GetDefaultFontType() != StyleGenericFontFamily::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,
|
||||
FontFamilyType aGeneric) {
|
||||
StyleGenericFontFamily 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,
|
||||
FontFamilyType* aGeneric) {
|
||||
StyleGenericFontFamily* 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 = eFamily_none;
|
||||
*aGeneric = StyleGenericFontFamily::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::kFontGroup, 0, false,
|
||||
textRun->AddGlyphRun(font, FontMatchType::Kind::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::kFontGroup, 0, false,
|
||||
orientation);
|
||||
textRun->AddGlyphRun(GetFirstValidFont(), FontMatchType::Kind::kFontGroup, 0,
|
||||
false, orientation);
|
||||
return textRun.forget();
|
||||
}
|
||||
|
||||
|
@ -2274,9 +2274,10 @@ 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() == eFamily_serif
|
||||
(mFamilyList.GetDefaultFontType() == StyleGenericFontFamily::Serif
|
||||
? "serif"
|
||||
: (mFamilyList.GetDefaultFontType() == eFamily_sans_serif
|
||||
: (mFamilyList.GetDefaultFontType() ==
|
||||
StyleGenericFontFamily::SansSerif
|
||||
? "sans-serif"
|
||||
: "none")),
|
||||
lang.get(), static_cast<int>(Script::LATIN), aLength,
|
||||
|
@ -2320,9 +2321,11 @@ 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() == eFamily_serif
|
||||
(mFamilyList.GetDefaultFontType() ==
|
||||
StyleGenericFontFamily::Serif
|
||||
? "serif"
|
||||
: (mFamilyList.GetDefaultFontType() == eFamily_sans_serif
|
||||
: (mFamilyList.GetDefaultFontType() ==
|
||||
StyleGenericFontFamily::SansSerif
|
||||
? "sans-serif"
|
||||
: "none")),
|
||||
lang.get(), static_cast<int>(runScript), runLen,
|
||||
|
@ -2500,7 +2503,7 @@ void gfxFontGroup::InitScriptRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
aTextRun->AddGlyphRun(mainFont, FontMatchType::kFontGroup,
|
||||
aTextRun->AddGlyphRun(mainFont, FontMatchType::Kind::kFontGroup,
|
||||
aOffset + runStart, (matchedLength > 0),
|
||||
range.orientation);
|
||||
}
|
||||
|
@ -2707,8 +2710,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
gfxFont* firstFont = GetFontAt(0, aCh);
|
||||
if (firstFont) {
|
||||
if (firstFont->HasCharacter(aCh)) {
|
||||
*aMatchType =
|
||||
FontMatchType::kFontGroup | FontMatchType(mFonts[0].Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[0].Generic()};
|
||||
return firstFont;
|
||||
}
|
||||
|
||||
|
@ -2723,8 +2725,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
font = FindFallbackFaceForChar(mFonts[0].Family(), aCh);
|
||||
}
|
||||
if (font) {
|
||||
*aMatchType =
|
||||
FontMatchType::kFontGroup | FontMatchType(mFonts[0].Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[0].Generic()};
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
@ -2774,7 +2775,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
gfxFont* font = ff.Font();
|
||||
if (font) {
|
||||
if (font->HasCharacter(aCh)) {
|
||||
*aMatchType = FontMatchType::kFontGroup | FontMatchType(ff.Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, ff.Generic()};
|
||||
return font;
|
||||
}
|
||||
continue;
|
||||
|
@ -2803,8 +2804,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
if (pfe && pfe->HasCharacter(aCh)) {
|
||||
font = GetFontAt(i, aCh);
|
||||
if (font) {
|
||||
*aMatchType =
|
||||
FontMatchType::kFontGroup | FontMatchType(mFonts[i].Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[i].Generic()};
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
@ -2813,8 +2813,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
// build the font via GetFontAt
|
||||
font = GetFontAt(i, aCh);
|
||||
if (font) {
|
||||
*aMatchType =
|
||||
FontMatchType::kFontGroup | FontMatchType(mFonts[i].Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, mFonts[i].Generic()};
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
@ -2828,7 +2827,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::kFontGroup | FontMatchType(ff.Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, ff.Generic()};
|
||||
return font;
|
||||
}
|
||||
} else {
|
||||
|
@ -2839,7 +2838,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
if (!fe->mIsUserFontContainer && !fe->IsUserFont()) {
|
||||
font = FindFallbackFaceForChar(ff.Family(), aCh);
|
||||
if (font) {
|
||||
*aMatchType = FontMatchType::kFontGroup | FontMatchType(ff.Generic());
|
||||
*aMatchType = {FontMatchType::Kind::kFontGroup, ff.Generic()};
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
@ -2849,7 +2848,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
if (fontListLength == 0) {
|
||||
gfxFont* defaultFont = GetDefaultFont();
|
||||
if (defaultFont->HasCharacter(aCh)) {
|
||||
*aMatchType = FontMatchType::kFontGroup;
|
||||
*aMatchType = FontMatchType::Kind::kFontGroup;
|
||||
return defaultFont;
|
||||
}
|
||||
}
|
||||
|
@ -2862,7 +2861,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
// 2. search pref fonts
|
||||
gfxFont* font = WhichPrefFontSupportsChar(aCh, aNextCh);
|
||||
if (font) {
|
||||
*aMatchType = FontMatchType::kPrefsFallback;
|
||||
*aMatchType = FontMatchType::Kind::kPrefsFallback;
|
||||
return font;
|
||||
}
|
||||
|
||||
|
@ -2870,7 +2869,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::kSystemFallback;
|
||||
*aMatchType = FontMatchType::Kind::kSystemFallback;
|
||||
return aPrevMatchedFont;
|
||||
}
|
||||
|
||||
|
@ -2882,7 +2881,7 @@ gfxFont* gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
|
|||
}
|
||||
|
||||
// -- otherwise look for other stuff
|
||||
*aMatchType = FontMatchType::kSystemFallback;
|
||||
*aMatchType = FontMatchType::Kind::kSystemFallback;
|
||||
return WhichSystemFontSupportsChar(aCh, aNextCh, aRunScript);
|
||||
}
|
||||
|
||||
|
@ -2906,12 +2905,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)
|
||||
FontFamilyType generic = eFamily_none;
|
||||
StyleGenericFontFamily generic = StyleGenericFontFamily::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::kFontGroup | FontMatchType(generic);
|
||||
FontMatchType matchType = {FontMatchType::Kind::kFontGroup, generic};
|
||||
|
||||
for (uint32_t i = 0; i < aLength; i++) {
|
||||
const uint32_t origI = i; // save off in case we increase for surrogate
|
||||
|
@ -2958,8 +2957,7 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
|
|||
!gfxFontUtils::IsJoinControl(ch) &&
|
||||
!gfxFontUtils::IsJoinCauser(prevCh) &&
|
||||
!gfxFontUtils::IsVarSelector(ch)))) {
|
||||
matchType =
|
||||
FontMatchType::kFontGroup | FontMatchType(mFonts[0].Generic());
|
||||
matchType = {FontMatchType::Kind::kFontGroup, mFonts[0].Generic()};
|
||||
} else {
|
||||
font =
|
||||
FindFontForChar(ch, prevCh, nextCh, aRunScript, prevFont, &matchType);
|
||||
|
@ -2967,9 +2965,9 @@ void gfxFontGroup::ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
|
|||
|
||||
#ifndef RELEASE_OR_BETA
|
||||
if (MOZ_UNLIKELY(mTextPerf)) {
|
||||
if (matchType & FontMatchType::kPrefsFallback) {
|
||||
if (matchType.kind == FontMatchType::Kind::kPrefsFallback) {
|
||||
mTextPerf->current.fallbackPrefs++;
|
||||
} else if (matchType & FontMatchType::kSystemFallback) {
|
||||
} else if (matchType.kind == FontMatchType::Kind::kSystemFallback) {
|
||||
mTextPerf->current.fallbackSystem++;
|
||||
}
|
||||
}
|
||||
|
@ -3051,16 +3049,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 & FontMatchType::kFontGroup) {
|
||||
if (r.matchType.kind & FontMatchType::Kind::kFontGroup) {
|
||||
matchTypes.AppendLiteral("list");
|
||||
}
|
||||
if (r.matchType & FontMatchType::kPrefsFallback) {
|
||||
if (r.matchType.kind & FontMatchType::Kind::kPrefsFallback) {
|
||||
if (!matchTypes.IsEmpty()) {
|
||||
matchTypes.AppendLiteral(",");
|
||||
}
|
||||
matchTypes.AppendLiteral("prefs");
|
||||
}
|
||||
if (r.matchType & FontMatchType::kPrefsFallback) {
|
||||
if (r.matchType.kind & FontMatchType::Kind::kPrefsFallback) {
|
||||
if (!matchTypes.IsEmpty()) {
|
||||
matchTypes.AppendLiteral(",");
|
||||
}
|
||||
|
@ -3075,9 +3073,10 @@ 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() == eFamily_serif
|
||||
(mFamilyList.GetDefaultFontType() == StyleGenericFontFamily::Serif
|
||||
? "serif"
|
||||
: (mFamilyList.GetDefaultFontType() == eFamily_sans_serif
|
||||
: (mFamilyList.GetDefaultFontType() ==
|
||||
StyleGenericFontFamily::SansSerif
|
||||
? "sans-serif"
|
||||
: "none")),
|
||||
lang.get(), static_cast<int>(aRunScript), fontMatches.get()));
|
||||
|
@ -3175,8 +3174,7 @@ gfxFont* gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh,
|
|||
|
||||
for (i = 0; i < numLangs; i++) {
|
||||
eFontPrefLang currentLang = prefLangs[i];
|
||||
mozilla::FontFamilyType defaultGeneric =
|
||||
pfl->GetDefaultGeneric(currentLang);
|
||||
StyleGenericFontFamily 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::FontFamilyType* aGeneric = nullptr);
|
||||
gfxFont* GetFirstValidFont(
|
||||
uint32_t aCh = 0x20, mozilla::StyleGenericFontFamily* 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::eFamily_none),
|
||||
mGeneric(mozilla::StyleGenericFontFamily::None),
|
||||
mFontCreated(false),
|
||||
mLoading(false),
|
||||
mInvalid(false),
|
||||
mCheckForFallbackFaces(false) {}
|
||||
|
||||
FamilyFace(gfxFontFamily* aFamily, gfxFont* aFont,
|
||||
mozilla::FontFamilyType aGeneric)
|
||||
mozilla::StyleGenericFontFamily aGeneric)
|
||||
: mFamily(aFamily),
|
||||
mGeneric(aGeneric),
|
||||
mFontCreated(true),
|
||||
|
@ -1046,7 +1046,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
|
|||
}
|
||||
|
||||
FamilyFace(gfxFontFamily* aFamily, gfxFontEntry* aFontEntry,
|
||||
mozilla::FontFamilyType aGeneric)
|
||||
mozilla::StyleGenericFontFamily aGeneric)
|
||||
: mFamily(aFamily),
|
||||
mGeneric(aGeneric),
|
||||
mFontCreated(false),
|
||||
|
@ -1115,7 +1115,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
|
|||
return mFontCreated ? mFont->GetFontEntry() : mFontEntry;
|
||||
}
|
||||
|
||||
mozilla::FontFamilyType Generic() const { return mGeneric; }
|
||||
mozilla::StyleGenericFontFamily 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::FontFamilyType mGeneric;
|
||||
mozilla::StyleGenericFontFamily 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::FontFamilyType aGeneric);
|
||||
mozilla::StyleGenericFontFamily aGeneric);
|
||||
};
|
||||
|
||||
// A "missing font recorder" is to be used during text-run creation to keep
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#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;
|
||||
|
@ -87,19 +88,42 @@ 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.
|
||||
*/
|
||||
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,
|
||||
struct FontMatchType {
|
||||
enum class Kind : uint8_t {
|
||||
kFontGroup = 1,
|
||||
kPrefsFallback = 1 << 1,
|
||||
kSystemFallback = 1 << 2,
|
||||
};
|
||||
|
||||
// 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
|
||||
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;
|
||||
};
|
||||
|
||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(FontMatchType)
|
||||
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;
|
||||
}
|
||||
|
||||
#endif /* GFX_TYPES_H */
|
||||
|
|
|
@ -10207,7 +10207,8 @@ 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(eFamily_serif, nsPresContext::CSSPixelsToAppUnits(11));
|
||||
nsFont font(StyleGenericFontFamily::Serif,
|
||||
nsPresContext::CSSPixelsToAppUnits(11));
|
||||
nsFontMetrics::Params params;
|
||||
params.language = nsGkAtoms::x_western;
|
||||
params.textPerf = aPresContext->GetTextPerfMetrics();
|
||||
|
|
|
@ -141,10 +141,10 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
|
|||
Preferences::GetCString(pref.get(), value);
|
||||
if (!value.IsEmpty()) {
|
||||
FontFamilyName defaultVariableName = FontFamilyName::Convert(value);
|
||||
FontFamilyType defaultType = defaultVariableName.mType;
|
||||
NS_ASSERTION(
|
||||
defaultType == eFamily_serif || defaultType == eFamily_sans_serif,
|
||||
"default type must be serif or sans-serif");
|
||||
StyleGenericFontFamily defaultType = defaultVariableName.mGeneric;
|
||||
NS_ASSERTION(defaultType == StyleGenericFontFamily::Serif ||
|
||||
defaultType == StyleGenericFontFamily::SansSerif,
|
||||
"default type must be serif or sans-serif");
|
||||
mDefaultVariableFont.fontlist = FontFamilyList();
|
||||
mDefaultVariableFont.fontlist.SetDefaultFontType(defaultType);
|
||||
// We create mDefaultVariableFont.fontlist with defaultType as the
|
||||
|
@ -155,10 +155,10 @@ void LangGroupFontPrefs::Initialize(nsStaticAtom* aLangGroupAtom) {
|
|||
Preferences::GetCString(pref.get(), value);
|
||||
if (!value.IsEmpty()) {
|
||||
FontFamilyName defaultVariableName = FontFamilyName::Convert(value);
|
||||
FontFamilyType defaultType = defaultVariableName.mType;
|
||||
NS_ASSERTION(
|
||||
defaultType == eFamily_serif || defaultType == eFamily_sans_serif,
|
||||
"default type must be serif or sans-serif");
|
||||
StyleGenericFontFamily defaultType = defaultVariableName.mGeneric;
|
||||
NS_ASSERTION(defaultType == StyleGenericFontFamily::Serif ||
|
||||
defaultType == StyleGenericFontFamily::SansSerif,
|
||||
"default type must be serif or sans-serif");
|
||||
mDefaultVariableFont.fontlist = FontFamilyList();
|
||||
mDefaultVariableFont.fontlist.SetDefaultFontType(defaultType);
|
||||
// We create mDefaultVariableFont.fontlist with defaultType as the
|
||||
|
|
|
@ -22,13 +22,14 @@ struct LangGroupFontPrefs {
|
|||
: mLangGroup(nullptr),
|
||||
mMinimumFontSize(0),
|
||||
mDefaultVariableFont(),
|
||||
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);
|
||||
mDefaultFixedFont(StyleGenericFontFamily::MozFixed, 0),
|
||||
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);
|
||||
// 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.
|
||||
|
@ -68,8 +69,8 @@ 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),
|
||||
* kPresContext_DefaultFixedFontID (which equals MozFixed, 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
|
||||
|
@ -80,23 +81,23 @@ struct LangGroupFontPrefs {
|
|||
* the user's preference for font size for that generic and the
|
||||
* given language.
|
||||
*/
|
||||
const nsFont* GetDefaultFont(uint8_t aFontID) const {
|
||||
switch (aFontID) {
|
||||
const nsFont* GetDefaultFont(StyleGenericFontFamily aFamily) const {
|
||||
switch (aFamily) {
|
||||
// Special (our default variable width font and fixed width font)
|
||||
case kGenericFont_moz_variable:
|
||||
case StyleGenericFontFamily::None:
|
||||
return &mDefaultVariableFont;
|
||||
case kGenericFont_moz_fixed:
|
||||
case StyleGenericFontFamily::MozFixed:
|
||||
return &mDefaultFixedFont;
|
||||
// CSS
|
||||
case kGenericFont_serif:
|
||||
case StyleGenericFontFamily::Serif:
|
||||
return &mDefaultSerifFont;
|
||||
case kGenericFont_sans_serif:
|
||||
case StyleGenericFontFamily::SansSerif:
|
||||
return &mDefaultSansSerifFont;
|
||||
case kGenericFont_monospace:
|
||||
case StyleGenericFontFamily::Monospace:
|
||||
return &mDefaultMonospaceFont;
|
||||
case kGenericFont_cursive:
|
||||
case StyleGenericFontFamily::Cursive:
|
||||
return &mDefaultCursiveFont;
|
||||
case kGenericFont_fantasy:
|
||||
case StyleGenericFontFamily::Fantasy:
|
||||
return &mDefaultFantasyFont;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -9749,8 +9749,9 @@ void nsLayoutUtils::ComputeSystemFont(nsFont* aSystemFont,
|
|||
if (LookAndFeel::GetFont(aFontID, systemFontName, fontStyle)) {
|
||||
systemFontName.Trim("\"'");
|
||||
aSystemFont->fontlist =
|
||||
FontFamilyList(NS_ConvertUTF16toUTF8(systemFontName), eUnquotedName);
|
||||
aSystemFont->fontlist.SetDefaultFontType(eFamily_none);
|
||||
FontFamilyList(NS_ConvertUTF16toUTF8(systemFontName),
|
||||
StyleFontFamilyNameSyntax::Identifiers);
|
||||
aSystemFont->fontlist.SetDefaultFontType(StyleGenericFontFamily::None);
|
||||
aSystemFont->style = fontStyle.style;
|
||||
aSystemFont->systemFont = fontStyle.systemFont;
|
||||
aSystemFont->weight = fontStyle.weight;
|
||||
|
|
|
@ -53,13 +53,12 @@ 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(kGenericFont_serif);
|
||||
->GetDefaultFont(StyleGenericFontFamily::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(kPresContext_DefaultVariableFont_ID)
|
||||
->GetDefaultFont(StyleGenericFontFamily::None)
|
||||
->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 & FontMatchType::kFontGroup);
|
||||
return bool(mMatchType.kind & FontMatchType::Kind::kFontGroup);
|
||||
}
|
||||
|
||||
bool InspectorFontFace::FromLanguagePrefs() {
|
||||
return bool(mMatchType & FontMatchType::kPrefsFallback);
|
||||
return bool(mMatchType.kind & FontMatchType::Kind::kPrefsFallback);
|
||||
}
|
||||
|
||||
bool InspectorFontFace::FromSystemFallback() {
|
||||
return bool(mMatchType & FontMatchType::kSystemFallback);
|
||||
return bool(mMatchType.kind & FontMatchType::Kind::kSystemFallback);
|
||||
}
|
||||
|
||||
void InspectorFontFace::GetName(nsAString& aName) {
|
||||
|
@ -56,10 +56,8 @@ void InspectorFontFace::GetCSSFamilyName(nsAString& aCSSFamilyName) {
|
|||
}
|
||||
|
||||
void InspectorFontFace::GetCSSGeneric(nsAString& aName) {
|
||||
auto genericType = FontFamilyType(mMatchType & FontMatchType::kGenericMask);
|
||||
if (genericType >= FontFamilyType::eFamily_generic_first &&
|
||||
genericType <= FontFamilyType::eFamily_generic_last) {
|
||||
aName.AssignASCII(gfxPlatformFontList::GetGenericName(genericType));
|
||||
if (mMatchType.generic != StyleGenericFontFamily::None) {
|
||||
aName.AssignASCII(gfxPlatformFontList::GetGenericName(mMatchType.generic));
|
||||
} 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() != eFamily_none) {
|
||||
if (aFont.fontlist.GetDefaultFontType() != StyleGenericFontFamily::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(eFamily_none);
|
||||
aFont.fontlist.SetDefaultFontType(StyleGenericFontFamily::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, eUnquotedName));
|
||||
mGlyphCodeFonts.AppendElement(FontFamilyName(
|
||||
aPrimaryFontName, StyleFontFamilyNameSyntax::Identifiers));
|
||||
}
|
||||
|
||||
~nsPropertiesTable() { MOZ_COUNT_DTOR(nsPropertiesTable); }
|
||||
|
@ -286,7 +286,8 @@ nsGlyphCode nsPropertiesTable::ElementAt(DrawTarget* /* aDrawTarget */,
|
|||
Clean(value);
|
||||
mGlyphCodeFonts.AppendElement(FontFamilyName(
|
||||
NS_ConvertUTF16toUTF8(value),
|
||||
eUnquotedName)); // i.e., mGlyphCodeFonts[i] holds this font name
|
||||
StyleFontFamilyNameSyntax::Identifiers)); // i.e., mGlyphCodeFonts[i]
|
||||
// holds this font name
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,7 +420,8 @@ class nsOpenTypeTable final : public nsGlyphTable {
|
|||
|
||||
explicit nsOpenTypeTable(gfxFont* aFont)
|
||||
: mFont(aFont),
|
||||
mFontFamilyName(aFont->GetFontEntry()->FamilyName(), eUnquotedName),
|
||||
mFontFamilyName(aFont->GetFontEntry()->FamilyName(),
|
||||
StyleFontFamilyNameSyntax::Identifiers),
|
||||
mGlyphID(0) {
|
||||
MOZ_COUNT_CTOR(nsOpenTypeTable);
|
||||
}
|
||||
|
@ -516,7 +518,7 @@ already_AddRefed<gfxTextRun> nsOpenTypeTable::MakeTextRun(
|
|||
gfxTextRun::Create(¶ms, 1, aFontGroup, gfx::ShapedTextFlags(),
|
||||
nsTextFrameUtils::Flags());
|
||||
textRun->AddGlyphRun(aFontGroup->GetFirstValidFont(),
|
||||
FontMatchType::kFontGroup, 0, false,
|
||||
FontMatchType::Kind::kFontGroup, 0, false,
|
||||
gfx::ShapedTextFlags::TEXT_ORIENT_HORIZONTAL);
|
||||
// We don't care about CSS writing mode here;
|
||||
// math runs are assumed to be horizontal.
|
||||
|
@ -890,7 +892,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(),
|
||||
eUnquotedName);
|
||||
StyleFontFamilyNameSyntax::Identifiers);
|
||||
if (aGlyphTable == &gGlyphTableList->mUnicodeTable ||
|
||||
firstFontList == familyList) {
|
||||
aFont.fontlist = familyList;
|
||||
|
@ -1280,8 +1282,8 @@ bool nsMathMLChar::StretchEnumContext::EnumCallback(
|
|||
|
||||
// for comparisons, force use of unquoted names
|
||||
FontFamilyName unquotedFamilyName(aFamily);
|
||||
if (unquotedFamilyName.mType == eFamily_named_quoted) {
|
||||
unquotedFamilyName.mType = eFamily_named;
|
||||
if (unquotedFamilyName.mSyntax == StyleFontFamilyNameSyntax::Quoted) {
|
||||
unquotedFamilyName.mSyntax = StyleFontFamilyNameSyntax::Identifiers;
|
||||
}
|
||||
|
||||
// Check font family if it is not a generic one
|
||||
|
@ -1290,7 +1292,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))
|
||||
|
@ -1343,7 +1345,8 @@ bool nsMathMLChar::StretchEnumContext::EnumCallback(
|
|||
static void AppendFallbacks(nsTArray<FontFamilyName>& aNames,
|
||||
const nsTArray<nsCString>& aFallbacks) {
|
||||
for (const nsCString& fallback : aFallbacks) {
|
||||
aNames.AppendElement(FontFamilyName(fallback, eUnquotedName));
|
||||
aNames.AppendElement(
|
||||
FontFamilyName(fallback, StyleFontFamilyNameSyntax::Identifiers));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,9 +91,9 @@ ServoTraversalStatistics ServoTraversalStatistics::sSingleton;
|
|||
|
||||
static RWLock* sServoFFILock = nullptr;
|
||||
|
||||
static const nsFont* ThreadSafeGetDefaultFontHelper(const Document& aDocument,
|
||||
nsAtom* aLanguage,
|
||||
uint8_t aGenericId) {
|
||||
static const nsFont* ThreadSafeGetDefaultFontHelper(
|
||||
const Document& aDocument, nsAtom* aLanguage,
|
||||
StyleGenericFontFamily 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, bool aQuoted) {
|
||||
aNames->AppendElement(
|
||||
FontFamilyName(aName, aQuoted ? eQuotedName : eUnquotedName));
|
||||
void Gecko_nsTArray_FontFamilyName_AppendNamed(
|
||||
nsTArray<FontFamilyName>* aNames, nsAtom* aName,
|
||||
StyleFontFamilyNameSyntax aSyntax) {
|
||||
aNames->AppendElement(FontFamilyName(aName, aSyntax));
|
||||
}
|
||||
|
||||
void Gecko_nsTArray_FontFamilyName_AppendGeneric(
|
||||
nsTArray<FontFamilyName>* aNames, FontFamilyType aType) {
|
||||
nsTArray<FontFamilyName>* aNames, StyleGenericFontFamily 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, kPresContext_DefaultVariableFont_ID);
|
||||
*aDocument, aFont->mLanguage, StyleGenericFontFamily::None);
|
||||
|
||||
// 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(); }
|
||||
|
||||
FontFamilyType Gecko_nsStyleFont_ComputeDefaultFontType(const Document* aDoc,
|
||||
uint8_t aGenericId,
|
||||
nsAtom* aLanguage) {
|
||||
StyleGenericFontFamily Gecko_nsStyleFont_ComputeDefaultFontType(
|
||||
const Document* aDoc, StyleGenericFontFamily aGenericId,
|
||||
nsAtom* aLanguage) {
|
||||
const nsFont* defaultFont =
|
||||
ThreadSafeGetDefaultFontHelper(*aDoc, aLanguage, aGenericId);
|
||||
return defaultFont->fontlist.GetDefaultFontType();
|
||||
|
@ -1892,32 +1892,15 @@ void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont,
|
|||
aFont->mLanguage = aSource->mLanguage;
|
||||
}
|
||||
|
||||
void Gecko_nsStyleFont_PrioritizeUserFonts(nsStyleFont* aFont,
|
||||
FontFamilyType aDefaultGeneric) {
|
||||
void Gecko_nsStyleFont_PrioritizeUserFonts(
|
||||
nsStyleFont* aFont, StyleGenericFontFamily aDefaultGeneric) {
|
||||
MOZ_ASSERT(!StaticPrefs::browser_display_use_document_fonts());
|
||||
MOZ_ASSERT(aDefaultGeneric != eFamily_none);
|
||||
MOZ_ASSERT(aDefaultGeneric != StyleGenericFontFamily::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
|
||||
|
|
|
@ -266,10 +266,11 @@ void Gecko_ReleaseAtom(nsAtom* aAtom);
|
|||
void Gecko_CopyFontFamilyFrom(nsFont* dst, const nsFont* src);
|
||||
|
||||
void Gecko_nsTArray_FontFamilyName_AppendNamed(
|
||||
nsTArray<mozilla::FontFamilyName>* aNames, nsAtom* aName, bool aQuoted);
|
||||
nsTArray<mozilla::FontFamilyName>* aNames, nsAtom* aName,
|
||||
mozilla::StyleFontFamilyNameSyntax);
|
||||
|
||||
void Gecko_nsTArray_FontFamilyName_AppendGeneric(
|
||||
nsTArray<mozilla::FontFamilyName>* aNames, mozilla::FontFamilyType aType);
|
||||
nsTArray<mozilla::FontFamilyName>* aNames, mozilla::StyleGenericFontFamily);
|
||||
|
||||
// Returns an already-AddRefed SharedFontList with an empty mNames array.
|
||||
mozilla::SharedFontList* Gecko_SharedFontList_Create();
|
||||
|
@ -678,18 +679,15 @@ 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::FontFamilyType aDefaultGeneric);
|
||||
|
||||
void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* font,
|
||||
const mozilla::dom::Document*,
|
||||
uint8_t generic_id);
|
||||
nsStyleFont* font, mozilla::StyleGenericFontFamily aDefaultGeneric);
|
||||
|
||||
nscoord Gecko_nsStyleFont_ComputeMinSize(const nsStyleFont*,
|
||||
const mozilla::dom::Document*);
|
||||
|
||||
// Computes the default generic font for a generic family and language.
|
||||
mozilla::FontFamilyType Gecko_nsStyleFont_ComputeDefaultFontType(
|
||||
const mozilla::dom::Document*, uint8_t generic_family, nsAtom* language);
|
||||
mozilla::StyleGenericFontFamily Gecko_nsStyleFont_ComputeDefaultFontType(
|
||||
const mozilla::dom::Document*,
|
||||
mozilla::StyleGenericFontFamily generic_family, nsAtom* language);
|
||||
|
||||
mozilla::FontSizePrefs Gecko_GetBaseSize(nsAtom* lang);
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ rusty-enums = [
|
|||
"mozilla::dom::IterationCompositeOperation",
|
||||
"mozilla::dom::CompositeOperation",
|
||||
"mozilla::InheritTarget",
|
||||
"mozilla::FontFamilyType",
|
||||
"mozilla::css::DocumentMatchingFunction",
|
||||
"mozilla::css::SheetParsingMode",
|
||||
"mozilla::StyleContentType",
|
||||
|
@ -458,6 +457,8 @@ 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 = [
|
||||
|
|
|
@ -112,12 +112,12 @@ nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
|
|||
|
||||
nsStyleFont::nsStyleFont(const Document& aDocument)
|
||||
: mFont(*aDocument.GetFontPrefsForLang(nullptr)->GetDefaultFont(
|
||||
kPresContext_DefaultVariableFont_ID)),
|
||||
StyleGenericFontFamily::None)),
|
||||
mSize(ZoomText(aDocument, mFont.size)),
|
||||
mFontSizeFactor(1.0),
|
||||
mFontSizeOffset(0),
|
||||
mFontSizeKeyword(NS_STYLE_FONT_SIZE_MEDIUM),
|
||||
mGenericID(kGenericFont_NONE),
|
||||
mGenericID(StyleGenericFontFamily::None),
|
||||
mScriptLevel(0),
|
||||
mMathVariant(NS_MATHML_MATHVARIANT_NONE),
|
||||
mMathDisplay(NS_MATHML_DISPLAYSTYLE_INLINE),
|
||||
|
|
|
@ -105,8 +105,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
|
|||
// NS_STYLE_FONT_SIZE_NO_KEYWORD when not
|
||||
// keyword-derived
|
||||
|
||||
uint8_t mGenericID; // generic CSS font family, if any;
|
||||
// value is a kGenericFont_* constant, see nsFont.h.
|
||||
mozilla::StyleGenericFontFamily mGenericID;
|
||||
|
||||
// MathML scriptlevel support
|
||||
int8_t mScriptLevel;
|
||||
|
|
|
@ -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: u8) -> Au;
|
||||
fn get_size(&self, font_name: &Atom, font_family: crate::values::computed::font::GenericFontFamily) -> Au;
|
||||
|
||||
/// Construct from a shared style context
|
||||
fn create_from(context: &SharedStyleContext) -> Self
|
||||
|
|
|
@ -69,6 +69,7 @@ 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;
|
||||
|
@ -1041,7 +1042,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
GeckoFontMetricsProvider::new()
|
||||
}
|
||||
|
||||
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au {
|
||||
fn get_size(&self, font_name: &Atom, font_family: GenericFontFamily) -> 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);
|
||||
|
@ -1100,16 +1101,17 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
}
|
||||
|
||||
impl structs::FontSizePrefs {
|
||||
fn size_for_generic(&self, font_family: u8) -> Au {
|
||||
fn size_for_generic(&self, font_family: GenericFontFamily) -> Au {
|
||||
Au(match 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"),
|
||||
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")
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -683,6 +683,7 @@ 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) {
|
||||
|
@ -697,7 +698,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, structs::FontFamilyType::eFamily_none);
|
||||
debug_assert_eq!(font.mFont.fontlist.mDefaultFontType, GenericFontFamily::None);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -717,11 +718,11 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
!use_document_fonts &&
|
||||
matches!(
|
||||
font.mGenericID,
|
||||
structs::kGenericFont_NONE |
|
||||
structs::kGenericFont_fantasy |
|
||||
structs::kGenericFont_cursive
|
||||
GenericFontFamily::None |
|
||||
GenericFontFamily::Fantasy |
|
||||
GenericFontFamily::Cursive
|
||||
) &&
|
||||
default_font_type != structs::FontFamilyType::eFamily_none;
|
||||
default_font_type != GenericFontFamily::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::gecko_bindings::structs::FontFamilyType;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
|
||||
let is_system_font = v.is_system_font;
|
||||
self.gecko.mFont.systemFont = is_system_font;
|
||||
self.gecko.mGenericID = if is_system_font {
|
||||
structs::kGenericFont_NONE
|
||||
GenericFontFamily::None
|
||||
} else {
|
||||
v.families.single_generic().unwrap_or(structs::kGenericFont_NONE)
|
||||
v.families.single_generic().unwrap_or(GenericFontFamily::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 = FontFamilyType::eFamily_none;
|
||||
self.gecko.mFont.fontlist.mDefaultFontType = GenericFontFamily::None;
|
||||
}
|
||||
|
||||
pub fn copy_font_family_from(&mut self, other: &Self) {
|
||||
|
@ -2011,33 +2011,13 @@ 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 = 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"))
|
||||
}
|
||||
};
|
||||
let default = SingleFontFamily::Generic(fontlist.mDefaultFontType);
|
||||
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::gecko_bindings::structs::FontFamilyType;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
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: FontFamilyType,
|
||||
pub default_font_type: GenericFontFamily,
|
||||
}
|
||||
|
||||
impl SystemFont {
|
||||
|
|
|
@ -157,10 +157,6 @@ 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;
|
||||
|
||||
|
@ -178,8 +174,8 @@ impl ToAnimatedValue for FontSize {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Hash, MallocSizeOf))]
|
||||
/// Specifies a prioritized list of font family names or generic family names.
|
||||
pub struct FontFamily {
|
||||
/// The actual list of family names.
|
||||
|
@ -193,7 +189,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(atom!("serif"))])),
|
||||
families: FontFamilyList::new(Box::new([SingleFontFamily::Generic(GenericFontFamily::Serif)])),
|
||||
is_system_font: false,
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +228,7 @@ pub struct FamilyName {
|
|||
/// Name of the font family
|
||||
pub name: Atom,
|
||||
/// Syntax of the font family
|
||||
pub syntax: FamilyNameSyntax,
|
||||
pub syntax: FontFamilyNameSyntax,
|
||||
}
|
||||
|
||||
impl ToCss for FamilyName {
|
||||
|
@ -241,12 +237,12 @@ impl ToCss for FamilyName {
|
|||
W: fmt::Write,
|
||||
{
|
||||
match self.syntax {
|
||||
FamilyNameSyntax::Quoted => {
|
||||
FontFamilyNameSyntax::Quoted => {
|
||||
dest.write_char('"')?;
|
||||
write!(CssStringWriter::new(dest), "{}", self.name)?;
|
||||
dest.write_char('"')
|
||||
},
|
||||
FamilyNameSyntax::Identifiers => {
|
||||
FontFamilyNameSyntax::Identifiers => {
|
||||
let mut first = true;
|
||||
for ident in self.name.to_string().split(' ') {
|
||||
if first {
|
||||
|
@ -268,11 +264,12 @@ impl ToCss for FamilyName {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
|
||||
#[derive(Clone, Copy, 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.
|
||||
pub enum FamilyNameSyntax {
|
||||
#[repr(u8)]
|
||||
pub enum FontFamilyNameSyntax {
|
||||
/// The family name was specified in a quoted form, e.g. "Font Name"
|
||||
/// or 'Font Name'.
|
||||
Quoted,
|
||||
|
@ -282,85 +279,79 @@ pub enum FamilyNameSyntax {
|
|||
Identifiers,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))]
|
||||
/// 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(Atom),
|
||||
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,
|
||||
Monospace,
|
||||
Cursive,
|
||||
Fantasy,
|
||||
/// This is basically monospace, but with different font prefs. We should
|
||||
/// consider removing it in favor of just using the monospace.* prefs, since
|
||||
/// in practice we don't override the monospace prefs at all.
|
||||
#[cfg(feature = "gecko")]
|
||||
MozFixed,
|
||||
/// An internal value for emoji font selection.
|
||||
#[css(skip)]
|
||||
#[cfg(feature = "gecko")]
|
||||
MozEmoji,
|
||||
}
|
||||
|
||||
// TODO(emilio): Derive this when we make -moz-fixed a parse alias of Monospace.
|
||||
impl ToCss for GenericFontFamily {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
dest.write_str(match *self {
|
||||
GenericFontFamily::MozEmoji |
|
||||
GenericFontFamily::Default => return Ok(()),
|
||||
GenericFontFamily::MozFixed |
|
||||
GenericFontFamily::Monospace => "monospace",
|
||||
GenericFontFamily::Serif => "serif",
|
||||
GenericFontFamily::SansSerif => "sans-serif",
|
||||
GenericFontFamily::Cursive => "cursive",
|
||||
GenericFontFamily::Fantasy => "fantasy",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl SingleFontFamily {
|
||||
#[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
|
||||
/// 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: FamilyNameSyntax::Quoted,
|
||||
syntax: FontFamilyNameSyntax::Quoted,
|
||||
}));
|
||||
}
|
||||
let first_ident = input.expect_ident()?.clone();
|
||||
|
||||
// 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 first_ident = input.expect_ident_cloned()?;
|
||||
if let Ok(generic) = GenericFontFamily::from_ident(&first_ident) {
|
||||
return Ok(SingleFontFamily::Generic(generic));
|
||||
}
|
||||
|
||||
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`)
|
||||
|
@ -368,18 +359,15 @@ 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" => css_wide_keyword = true,
|
||||
"initial" => css_wide_keyword = true,
|
||||
"unset" => css_wide_keyword = true,
|
||||
"default" => css_wide_keyword = true,
|
||||
_ => {}
|
||||
}
|
||||
"inherit" | "initial" | "unset" | "revert" | "default" => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
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 css_wide_keyword {
|
||||
if reserved {
|
||||
let ident = input.expect_ident()?;
|
||||
value.push(' ');
|
||||
value.push_str(&ident);
|
||||
|
@ -393,9 +381,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.
|
||||
FamilyNameSyntax::Quoted
|
||||
FontFamilyNameSyntax::Quoted
|
||||
} else {
|
||||
FamilyNameSyntax::Identifiers
|
||||
FontFamilyNameSyntax::Identifiers
|
||||
};
|
||||
Ok(SingleFontFamily::FamilyName(FamilyName {
|
||||
name: Atom::from(value),
|
||||
|
@ -403,94 +391,18 @@ 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 {
|
||||
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)
|
||||
},
|
||||
if family.mName.mRawPtr.is_null() {
|
||||
debug_assert_ne!(family.mGeneric, GenericFontFamily::None);
|
||||
return SingleFontFamily::Generic(family.mGeneric);
|
||||
}
|
||||
let name = unsafe { Atom::from_raw(family.mName.mRawPtr) };
|
||||
SingleFontFamily::FamilyName(FamilyName {
|
||||
name,
|
||||
syntax: family.mSyntax,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -506,7 +418,7 @@ pub enum FontFamilyList {
|
|||
/// A strong reference to a Gecko SharedFontList object.
|
||||
SharedFontList(RefPtr<structs::SharedFontList>),
|
||||
/// A font-family generic ID.
|
||||
Generic(structs::FontFamilyType),
|
||||
Generic(GenericFontFamily),
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -514,38 +426,19 @@ 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(r) => {
|
||||
ManuallyDrop::new(match *self {
|
||||
FontFamilyList::SharedFontList(ref 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].mType)
|
||||
FontFamilyList::Generic(r.mNames[0].mGeneric)
|
||||
},
|
||||
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 {
|
||||
|
@ -556,7 +449,8 @@ impl PartialEq for FontFamilyList {
|
|||
return false;
|
||||
}
|
||||
for (a, b) in self_list.mNames.iter().zip(other_list.mNames.iter()) {
|
||||
if a.mType != b.mType || a.mName.mRawPtr != b.mName.mRawPtr {
|
||||
if a.mSyntax != b.mSyntax || a.mName.mRawPtr != b.mName.mRawPtr ||
|
||||
a.mGeneric != b.mGeneric {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -588,19 +482,17 @@ 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(),
|
||||
quoted,
|
||||
f.syntax,
|
||||
);
|
||||
}
|
||||
},
|
||||
SingleFontFamily::Generic(ref name) => {
|
||||
let (family_type, _generic) = SingleFontFamily::generic(name);
|
||||
SingleFontFamily::Generic(family) => {
|
||||
unsafe {
|
||||
bindings::Gecko_nsTArray_FontFamilyName_AppendGeneric(names, family_type);
|
||||
bindings::Gecko_nsTArray_FontFamilyName_AppendGeneric(names, family);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -625,12 +517,11 @@ impl FontFamilyList {
|
|||
}
|
||||
|
||||
/// Return the generic ID if it is a single generic font
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn single_generic(&self) -> Option<u8> {
|
||||
pub fn single_generic(&self) -> Option<GenericFontFamily> {
|
||||
let mut iter = self.iter();
|
||||
if let Some(SingleFontFamily::Generic(ref name)) = iter.next() {
|
||||
if let Some(SingleFontFamily::Generic(f)) = iter.next() {
|
||||
if iter.next().is_none() {
|
||||
return Some(SingleFontFamily::generic(name).1);
|
||||
return Some(f);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -639,13 +530,12 @@ 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(r) => r,
|
||||
match *self {
|
||||
FontFamilyList::SharedFontList(ref r) => r,
|
||||
FontFamilyList::Generic(t) => {
|
||||
unsafe {
|
||||
// TODO(heycam): Should really add StaticRefPtr sugar.
|
||||
let index =
|
||||
(*t as usize) - (structs::FontFamilyType::eFamily_generic_first as usize);
|
||||
let index = t as usize;
|
||||
mem::transmute::<
|
||||
&structs::StaticRefPtr<structs::SharedFontList>,
|
||||
&RefPtr<structs::SharedFontList>,
|
||||
|
|
|
@ -515,7 +515,8 @@ impl From<LengthPercentage> for FontSize {
|
|||
}
|
||||
|
||||
/// Specifies a prioritized list of font family names or generic family names.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss, ToShmem)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss, ToShmem)]
|
||||
#[cfg_attr(feature = "servo", derive(Hash))]
|
||||
pub enum FontFamily {
|
||||
/// List of `font-family`
|
||||
#[css(comma)]
|
||||
|
|
|
@ -61,6 +61,8 @@ include = [
|
|||
"FontDisplay",
|
||||
"FontFaceSourceListComponent",
|
||||
"FontLanguageOverride",
|
||||
"GenericFontFamily",
|
||||
"FontFamilyNameSyntax",
|
||||
"OverflowWrap",
|
||||
"TimingFunction",
|
||||
"PathCommand",
|
||||
|
|
Загрузка…
Ссылка в новой задаче