Bug 1784058 - Simplify @font-face format hint handling in gfx/thebes, now that it is explicitly only a single hint, not a set. r=gfx-reviewers,aosmond,lsalzman

No functional change, just simplifying the code a bit.

Differential Revision: https://phabricator.services.mozilla.com/D154236
This commit is contained in:
Jonathan Kew 2022-08-11 13:10:02 +00:00
Родитель 91d8e38d70
Коммит e42a3850ec
9 изменённых файлов: 121 добавлений и 161 удалений

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

@ -1799,23 +1799,29 @@ bool gfxPlatform::UseGraphiteShaping() {
return StaticPrefs::gfx_font_rendering_graphite_enabled();
}
bool gfxPlatform::IsFontFormatSupported(uint32_t aFormatFlags) {
// check for strange format flags
MOZ_ASSERT(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
"strange font format hint set");
// accept "common" formats that we support on all platforms
if (aFormatFlags & gfxUserFontSet::FLAG_FORMATS_COMMON) {
return true;
bool gfxPlatform::IsFontFormatSupported(uint8_t aHint) {
switch (aHint) {
case gfxUserFontSet::FormatHint::NONE:
return true;
case gfxUserFontSet::FormatHint::COLLECTION:
return false;
case gfxUserFontSet::FormatHint::OPENTYPE:
case gfxUserFontSet::FormatHint::TRUETYPE:
return true;
case gfxUserFontSet::FormatHint::EOT:
return false;
case gfxUserFontSet::FormatHint::SVG:
return false;
case gfxUserFontSet::FormatHint::WOFF:
return true;
case gfxUserFontSet::FormatHint::WOFF2:
return true;
case gfxUserFontSet::FormatHint::UNKNOWN:
return false;
default:
MOZ_ASSERT_UNREACHABLE("bad format hint!");
return false;
}
// reject all other formats, known and unknown
if (aFormatFlags != 0) {
return false;
}
// no format hint set, need to look at data
return true;
}
gfxFontGroup* gfxPlatform::CreateFontGroup(

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

@ -497,7 +497,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
// Check whether format is supported on a platform (if unclear, returns true).
// Default implementation checks for "common" formats that we support across
// all platforms, but individual platform implementations may override.
virtual bool IsFontFormatSupported(uint32_t aFormatFlags);
virtual bool IsFontFormatSupported(uint8_t aFormatHint);
virtual bool DidRenderingDeviceReset(
DeviceResetReason* aResetReason = nullptr) {

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

@ -179,20 +179,6 @@ already_AddRefed<gfxASurface> gfxPlatformMac::CreateOffscreenSurface(
return newSurface.forget();
}
bool gfxPlatformMac::IsFontFormatSupported(uint32_t aFormatFlags) {
if (gfxPlatform::IsFontFormatSupported(aFormatFlags)) {
return true;
}
// If the generic method rejected the format hint, then check for any
// platform-specific format we know about.
if (aFormatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT) {
return true;
}
return false;
}
void gfxPlatformMac::GetCommonFallbackFonts(uint32_t aCh, Script aRunScript,
eFontPresentation aPresentation,
nsTArray<const char*>& aFontList) {

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

@ -44,8 +44,6 @@ class gfxPlatformMac : public gfxPlatform {
void ReadSystemFontList(mozilla::dom::SystemFontList* aFontList) override;
bool IsFontFormatSupported(uint32_t aFormatFlags) override;
void GetCommonFallbackFonts(uint32_t aCh, Script aRunScript,
eFontPresentation aPresentation,
nsTArray<const char*>& aFontList) override;

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

@ -231,7 +231,7 @@ void gfxUserFontEntry::StoreUserFontData(gfxFontEntry* aFontEntry,
break;
}
userFontData->mPrivate = aPrivate;
userFontData->mFormat = src.mFormatFlags;
userFontData->mFormatHint = src.mFormatHint;
userFontData->mRealName = aOriginalName;
if (aMetadata) {
userFontData->mMetadata = std::move(*aMetadata);
@ -469,7 +469,7 @@ void gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync) {
// src url ==> start the load process
else if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL) {
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(
currSrc.mFormatFlags)) {
currSrc.mFormatHint)) {
if (ServoStyleSet* set = gfxFontUtils::CurrentServoStyleSet()) {
// Only support style worker threads synchronously getting
// entries from the font cache when it's not a data: URI

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

@ -77,10 +77,20 @@ struct gfxFontFaceSrc {
// if url, whether to use the origin principal or not
bool mUseOriginPrincipal = false;
// format hint flags, union of all possible formats
// (e.g. TrueType, EOT, SVG, etc.)
// see FLAG_FORMAT_* enum values below
uint32_t mFormatFlags;
// Format hint, if any was specified.
enum FormatHint : uint8_t {
NONE = 0, // no hint set
COLLECTION = 1,
OPENTYPE = 2,
TRUETYPE = 3,
EOT = 4,
SVG = 5,
WOFF = 6,
WOFF2 = 7,
UNKNOWN = 255 // unknown format hint set
};
FormatHint mFormatHint;
nsCString mLocalName; // full font name if local
RefPtr<gfxFontSrcURI> mURI; // uri if url
@ -115,7 +125,7 @@ inline bool operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b) {
return false;
}
bool equals;
return a.mFormatFlags == b.mFormatFlags &&
return a.mFormatHint == b.mFormatHint &&
(a.mURI == b.mURI || a.mURI->Equals(b.mURI)) &&
NS_SUCCEEDED(a.mReferrerInfo->Equals(b.mReferrerInfo, &equals)) &&
equals;
@ -137,8 +147,8 @@ class gfxUserFontData {
public:
gfxUserFontData()
: mSrcIndex(0),
mFormat(0),
mMetaOrigLen(0),
mFormatHint(gfxFontFaceSrc::FormatHint::NONE),
mCompression(kUnknownCompression),
mPrivate(false),
mIsBuffer(false) {}
@ -153,11 +163,12 @@ class gfxUserFontData {
nsCString mLocalName; // font name used for the source, if local()
nsCString mRealName; // original fullname from the font resource
uint32_t mSrcIndex; // index in the rule's source list
uint32_t mFormat; // format hint for the source used, if any
uint32_t mMetaOrigLen; // length needed to decompress metadata
uint8_t mCompression; // compression type
bool mPrivate; // whether font belongs to a private window
bool mIsBuffer; // whether the font source was a buffer
gfxFontFaceSrc::FormatHint
mFormatHint; // format hint for the source used, if any
uint8_t mCompression; // compression type
bool mPrivate; // whether font belongs to a private window
bool mIsBuffer; // whether the font source was a buffer
enum {
kUnknownCompression = 0,
@ -239,33 +250,7 @@ class gfxUserFontSet {
void Destroy();
enum {
// no flags ==> no hint set
// unknown ==> unknown format hint set
FLAG_FORMAT_UNKNOWN = 1,
FLAG_FORMAT_OPENTYPE = 1 << 1,
FLAG_FORMAT_TRUETYPE = 1 << 2,
FLAG_FORMAT_TRUETYPE_AAT = 1 << 3,
FLAG_FORMAT_EOT = 1 << 4,
FLAG_FORMAT_SVG = 1 << 5,
FLAG_FORMAT_WOFF = 1 << 6,
FLAG_FORMAT_WOFF2 = 1 << 7,
FLAG_FORMAT_OPENTYPE_VARIATIONS = 1 << 8,
FLAG_FORMAT_TRUETYPE_VARIATIONS = 1 << 9,
FLAG_FORMAT_WOFF_VARIATIONS = 1 << 10,
FLAG_FORMAT_WOFF2_VARIATIONS = 1 << 11,
// the common formats that we support everywhere
FLAG_FORMATS_COMMON =
FLAG_FORMAT_OPENTYPE | FLAG_FORMAT_TRUETYPE | FLAG_FORMAT_WOFF |
FLAG_FORMAT_WOFF2 | FLAG_FORMAT_OPENTYPE_VARIATIONS |
FLAG_FORMAT_TRUETYPE_VARIATIONS | FLAG_FORMAT_WOFF_VARIATIONS |
FLAG_FORMAT_WOFF2_VARIATIONS,
// mask of all unused bits, update when adding new formats
FLAG_FORMAT_NOT_USED = ~((1 << 12) - 1)
};
using FormatHint = gfxFontFaceSrc::FormatHint;
// creates a font face without adding it to a particular family
// weight - [100, 900] (multiples of 100)

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

@ -120,50 +120,39 @@ void InspectorFontFace::GetLocalName(nsAString& aLocalName) {
}
}
static void AppendToFormat(nsAString& aResult, const char* aFormat) {
if (!aResult.IsEmpty()) {
aResult.Append(',');
}
aResult.AppendASCII(aFormat);
}
void InspectorFontFace::GetFormat(nsAString& aFormat) {
aFormat.Truncate();
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
uint32_t formatFlags = mFontEntry->mUserFontData->mFormat;
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_OPENTYPE) {
AppendToFormat(aFormat, "opentype");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE) {
AppendToFormat(aFormat, "truetype");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT) {
AppendToFormat(aFormat, "truetype-aat");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_EOT) {
AppendToFormat(aFormat, "embedded-opentype");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_SVG) {
AppendToFormat(aFormat, "svg");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF) {
AppendToFormat(aFormat, "woff");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF2) {
AppendToFormat(aFormat, "woff2");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_OPENTYPE_VARIATIONS) {
AppendToFormat(aFormat, "opentype-variations");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE_VARIATIONS) {
AppendToFormat(aFormat, "truetype-variations");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF_VARIATIONS) {
AppendToFormat(aFormat, "woff-variations");
}
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF2_VARIATIONS) {
AppendToFormat(aFormat, "woff2-variations");
auto hint =
gfxUserFontSet::FormatHint(mFontEntry->mUserFontData->mFormatHint);
switch (hint) {
case gfxUserFontSet::FormatHint::NONE:
break;
case gfxUserFontSet::FormatHint::COLLECTION:
aFormat.AssignLiteral("collection");
break;
case gfxUserFontSet::FormatHint::OPENTYPE:
aFormat.AssignLiteral("opentype");
break;
case gfxUserFontSet::FormatHint::TRUETYPE:
aFormat.AssignLiteral("truetype");
break;
case gfxUserFontSet::FormatHint::EOT:
aFormat.AssignLiteral("embedded-opentype");
break;
case gfxUserFontSet::FormatHint::SVG:
aFormat.AssignLiteral("svg");
break;
case gfxUserFontSet::FormatHint::WOFF:
aFormat.AssignLiteral("woff");
break;
case gfxUserFontSet::FormatHint::WOFF2:
aFormat.AssignLiteral("woff2");
break;
case gfxUserFontSet::FormatHint::UNKNOWN:
aFormat.AssignLiteral("unknown!");
break;
}
}
}

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

@ -503,9 +503,10 @@ FontFaceSetImpl::FindOrCreateUserFontEntryFromFontFace(
face->mLocalName.Append(nsAtomCString(atom));
face->mSourceType = gfxFontFaceSrc::eSourceType_Local;
face->mURI = nullptr;
face->mFormatFlags = 0;
face->mFormatHint = FormatHint::NONE;
break;
}
case StyleFontFaceSourceListComponent::Tag::Url: {
face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
const StyleCssUrl* url = component.AsUrl();
@ -526,58 +527,52 @@ FontFaceSetImpl::FindOrCreateUserFontEntryFromFontFace(
}
face->mLocalName.Truncate();
face->mFormatFlags = 0;
face->mFormatHint = FormatHint::NONE;
while (i + 1 < len) {
if (i + 1 < len) {
const auto& maybeFontFormat = sourceListComponents[i + 1];
if (maybeFontFormat.tag !=
if (maybeFontFormat.tag ==
StyleFontFaceSourceListComponent::Tag::FormatHint) {
break;
}
nsDependentCSubstring valueString(
reinterpret_cast<const char*>(
maybeFontFormat.format_hint.utf8_bytes),
maybeFontFormat.format_hint.length);
nsDependentCSubstring valueString(
reinterpret_cast<const char*>(
maybeFontFormat.format_hint.utf8_bytes),
maybeFontFormat.format_hint.length);
if (valueString.LowerCaseEqualsASCII("woff")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_WOFF;
} else if (valueString.LowerCaseEqualsASCII("woff2")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_WOFF2;
} else if (valueString.LowerCaseEqualsASCII("opentype")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_OPENTYPE;
} else if (valueString.LowerCaseEqualsASCII("truetype")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_TRUETYPE;
} else if (valueString.LowerCaseEqualsASCII("truetype-aat")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT;
} else if (valueString.LowerCaseEqualsASCII("embedded-opentype")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_EOT;
} else if (valueString.LowerCaseEqualsASCII("svg")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_SVG;
} else if (StaticPrefs::layout_css_font_variations_enabled() &&
valueString.LowerCaseEqualsASCII("woff-variations")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_WOFF_VARIATIONS;
} else if (StaticPrefs::layout_css_font_variations_enabled() &&
valueString.LowerCaseEqualsASCII("woff2-variations")) {
face->mFormatFlags |=
gfxUserFontSet::FLAG_FORMAT_WOFF2_VARIATIONS;
} else if (StaticPrefs::layout_css_font_variations_enabled() &&
valueString.LowerCaseEqualsASCII(
"opentype-variations")) {
face->mFormatFlags |=
gfxUserFontSet::FLAG_FORMAT_OPENTYPE_VARIATIONS;
} else if (StaticPrefs::layout_css_font_variations_enabled() &&
valueString.LowerCaseEqualsASCII(
"truetype-variations")) {
face->mFormatFlags |=
gfxUserFontSet::FLAG_FORMAT_TRUETYPE_VARIATIONS;
} else {
// unknown format specified, mark to distinguish from the
// case where no format hints are specified
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_UNKNOWN;
if (valueString.LowerCaseEqualsASCII("woff")) {
face->mFormatHint = gfxUserFontSet::FormatHint::WOFF;
} else if (valueString.LowerCaseEqualsASCII("woff2")) {
face->mFormatHint = gfxUserFontSet::FormatHint::WOFF2;
} else if (valueString.LowerCaseEqualsASCII("opentype")) {
face->mFormatHint = gfxUserFontSet::FormatHint::OPENTYPE;
} else if (valueString.LowerCaseEqualsASCII("truetype")) {
face->mFormatHint = gfxUserFontSet::FormatHint::TRUETYPE;
} else if (valueString.LowerCaseEqualsASCII("truetype-aat")) {
face->mFormatHint = gfxUserFontSet::FormatHint::TRUETYPE;
} else if (valueString.LowerCaseEqualsASCII(
"embedded-opentype")) {
face->mFormatHint = gfxUserFontSet::FormatHint::EOT;
} else if (valueString.LowerCaseEqualsASCII("svg")) {
face->mFormatHint = gfxUserFontSet::FormatHint::SVG;
} // Non-standard values that Firefox accepted, for back-compat:
else if (valueString.LowerCaseEqualsASCII("woff-variations")) {
face->mFormatHint = gfxUserFontSet::FormatHint::WOFF;
} else if (valueString.LowerCaseEqualsASCII("woff2-variations")) {
face->mFormatHint = gfxUserFontSet::FormatHint::WOFF2;
} else if (valueString.LowerCaseEqualsASCII(
"opentype-variations")) {
face->mFormatHint = gfxUserFontSet::FormatHint::OPENTYPE;
} else if (valueString.LowerCaseEqualsASCII(
"truetype-variations")) {
face->mFormatHint = gfxUserFontSet::FormatHint::TRUETYPE;
} else {
// unknown format specified, mark to distinguish from the
// case where no format hints are specified
face->mFormatHint = gfxUserFontSet::FormatHint::UNKNOWN;
}
i++;
}
i++;
}
if (!face->mURI) {
// if URI not valid, omit from src array
srcArray.RemoveLastElement();
@ -586,6 +581,7 @@ FontFaceSetImpl::FindOrCreateUserFontEntryFromFontFace(
}
break;
}
case StyleFontFaceSourceListComponent::Tag::FormatHint:
MOZ_ASSERT_UNREACHABLE(
"Should always come after a URL source, and be consumed already");

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

@ -78,8 +78,8 @@ void FontPreloader::PrioritizeAsPreload(nsIChannel* aChannel) {
// For WOFF and WOFF2, we should tell servers/proxies/etc NOT to try
// and apply additional compression at the content-encoding layer
if (aFontFaceSrc->mFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF |
gfxUserFontSet::FLAG_FORMAT_WOFF2)) {
if (aFontFaceSrc->mFormatHint == gfxUserFontSet::FormatHint::WOFF ||
aFontFaceSrc->mFormatHint == gfxUserFontSet::FormatHint::WOFF2) {
rv = aHttpChannel->SetRequestHeader("Accept-Encoding"_ns, "identity"_ns,
false);
NS_ENSURE_SUCCESS(rv, rv);