diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt index 0296d5ffff80..697766486e1b 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt @@ -11,7 +11,7 @@ PASS Check that src: url("foo.ttf") format("truetype") is valid PASS Check that src: url("foo.ttf") format("woff") is valid PASS Check that src: url("foo.ttf") format("woff2") is valid PASS Check that src: url("foo.ttf") format("opentype", "truetype") is invalid -PASS Check that src: url("foo.ttf") format(collection) is valid +FAIL Check that src: url("foo.ttf") format(collection) is valid assert_equals: expected true but got false PASS Check that src: url("foo.ttf") format(opentype) is valid PASS Check that src: url("foo.ttf") format(truetype) is valid PASS Check that src: url("foo.ttf") format(woff) is valid diff --git a/Source/WebCore/css/CSSFontFaceSrcValue.cpp b/Source/WebCore/css/CSSFontFaceSrcValue.cpp index e92bc42bfb7a..2507332b6f24 100644 --- a/Source/WebCore/css/CSSFontFaceSrcValue.cpp +++ b/Source/WebCore/css/CSSFontFaceSrcValue.cpp @@ -100,7 +100,7 @@ std::unique_ptr CSSFontFaceSrcResourceValue::fontLoadRequest(Sc isFormatSVG = false; } else { isFormatSVG = equalLettersIgnoringASCIICase(m_format, "svg"_s); - if (!isFormatSVG && !FontCustomPlatformData::supportsFormat(m_format)) + if (!FontCustomPlatformData::supportsFormat(m_format)) return nullptr; } diff --git a/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp b/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp index 2429e5628931..20c3c2b25ecb 100644 --- a/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp +++ b/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp @@ -8202,19 +8202,6 @@ RefPtr consumeFontFaceFontFamily(CSSParserTokenRange& range) return CSSValueList::createCommaSeparated(name.releaseNonNull()); } -bool identMatchesSupportedFontFormat(CSSValueID id) -{ - return identMatches< - CSSValueCollection, - CSSValueEmbeddedOpentype, - CSSValueOpentype, - CSSValueSvg, - CSSValueTruetype, - CSSValueWoff, - CSSValueWoff2 - >(id); -} - Vector consumeFontTech(CSSParserTokenRange& range, bool singleValue) { @@ -8233,6 +8220,22 @@ Vector consumeFontTech(CSSParserTokenRange& range, bool singleVa return technologies; } +String consumeFontFormat(CSSParserTokenRange& range, bool rejectStringValues) +{ + // https://drafts.csswg.org/css-fonts/#descdef-font-face-src + // FIXME: We allow any identifier here and convert to strings; specification calls for certain keywords and legacy compatibility strings. + auto args = CSSPropertyParserHelpers::consumeFunction(range); + auto& arg = args.consumeIncludingWhitespace(); + if (!args.atEnd()) + return nullString(); + if (arg.type() != IdentToken && (rejectStringValues || arg.type() != StringToken)) + return nullString(); + auto format = arg.value().toString(); + if (arg.type() == IdentToken && !FontCustomPlatformData::supportsFormat(format)) + return nullString(); + return format; +} + // MARK: @font-palette-values RefPtr consumeFontPaletteValuesOverrideColors(CSSParserTokenRange& range, const CSSParserContext& context) diff --git a/Source/WebCore/css/parser/CSSPropertyParserHelpers.h b/Source/WebCore/css/parser/CSSPropertyParserHelpers.h index 4812c76971cf..2cf29288f310 100644 --- a/Source/WebCore/css/parser/CSSPropertyParserHelpers.h +++ b/Source/WebCore/css/parser/CSSPropertyParserHelpers.h @@ -321,7 +321,7 @@ RefPtr consumeDeclarationValue(CSSParserTokenRange&, const CSSParserCo RefPtr consumeFontFaceFontFamily(CSSParserTokenRange&); Vector consumeFontTech(CSSParserTokenRange&, bool singleValue = false); -bool identMatchesSupportedFontFormat(CSSValueID); +String consumeFontFormat(CSSParserTokenRange&, bool rejectStringValues = false); // @font-palette-values descriptor consumers: diff --git a/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp b/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp index 06be81f2c458..83a99ff38870 100644 --- a/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp +++ b/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp @@ -44,6 +44,7 @@ #include "CSSTokenizer.h" #include "CSSUnicodeRangeValue.h" #include "Document.h" +#include "FontCustomPlatformData.h" #include "ParsingUtilities.h" #include "ScriptExecutionContext.h" #include "StyleSheetContents.h" @@ -235,18 +236,9 @@ static RefPtr consumeFontFaceSrcURI(CSSParserTokenR String format; Vector supportedTechnologies; if (range.peek().functionId() == CSSValueFormat) { - // https://drafts.csswg.org/css-fonts/#descdef-font-face-src - // FIXME: We allow any identifier here and convert to strings; specification calls for certain keywords and legacy compatibility strings. - auto args = CSSPropertyParserHelpers::consumeFunction(range); - auto& arg = args.consumeIncludingWhitespace(); - if (!args.atEnd()) - return nullptr; - if (arg.type() == IdentToken) { - if (!CSSPropertyParserHelpers::identMatchesSupportedFontFormat(arg.id())) - return nullptr; - } else if (arg.type() != StringToken) + format = CSSPropertyParserHelpers::consumeFontFormat(range); + if (format.isNull()) return nullptr; - format = arg.value().toString(); } if (range.peek().functionId() == CSSValueTech) { supportedTechnologies = CSSPropertyParserHelpers::consumeFontTech(range); diff --git a/Source/WebCore/css/parser/CSSSupportsParser.cpp b/Source/WebCore/css/parser/CSSSupportsParser.cpp index 6840e49b8bb3..d4148b7adab6 100644 --- a/Source/WebCore/css/parser/CSSSupportsParser.cpp +++ b/Source/WebCore/css/parser/CSSSupportsParser.cpp @@ -169,15 +169,8 @@ CSSSupportsParser::SupportsResult CSSSupportsParser::consumeSupportsSelectorFunc CSSSupportsParser::SupportsResult CSSSupportsParser::consumeSupportsFontFormatFunction(CSSParserTokenRange& range) { ASSERT(range.peek().type() == FunctionToken && range.peek().functionId() == CSSValueFontFormat); - - auto block = range.consumeBlock(); - block.consumeWhitespace(); - - auto isSupported = CSSPropertyParserHelpers::consumeIdent(block, CSSPropertyParserHelpers::identMatchesSupportedFontFormat) ? Supported : Unsupported; - if (!block.atEnd()) - return Unsupported; - - return isSupported; + auto format = CSSPropertyParserHelpers::consumeFontFormat(range, true); + return format.isNull() ? Unsupported : Supported; } // diff --git a/Source/WebCore/platform/graphics/coretext/FontCustomPlatformDataCoreText.cpp b/Source/WebCore/platform/graphics/coretext/FontCustomPlatformDataCoreText.cpp index 0362bd3efb01..11384ae09ea5 100644 --- a/Source/WebCore/platform/graphics/coretext/FontCustomPlatformDataCoreText.cpp +++ b/Source/WebCore/platform/graphics/coretext/FontCustomPlatformDataCoreText.cpp @@ -99,7 +99,8 @@ bool FontCustomPlatformData::supportsFormat(const String& format) || equalLettersIgnoringASCIICase(format, "woff-variations"_s) || equalLettersIgnoringASCIICase(format, "truetype-variations"_s) || equalLettersIgnoringASCIICase(format, "opentype-variations"_s) - || equalLettersIgnoringASCIICase(format, "woff"_s); + || equalLettersIgnoringASCIICase(format, "woff"_s) + || equalLettersIgnoringASCIICase(format, "svg"_s); } bool FontCustomPlatformData::supportsTechnology(const FontTechnology& tech) diff --git a/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp b/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp index 928454fef7af..dcf612809918 100644 --- a/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp +++ b/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp @@ -161,7 +161,8 @@ bool FontCustomPlatformData::supportsFormat(const String& format) || equalLettersIgnoringASCIICase(format, "truetype-variations"_s) || equalLettersIgnoringASCIICase(format, "opentype-variations"_s) #endif - || equalLettersIgnoringASCIICase(format, "woff"_s); + || equalLettersIgnoringASCIICase(format, "woff"_s) + || equalLettersIgnoringASCIICase(format, "svg"_s); } bool FontCustomPlatformData::supportsTechnology(const FontTechnology&) diff --git a/Source/WebCore/platform/graphics/win/FontCustomPlatformDataWin.cpp b/Source/WebCore/platform/graphics/win/FontCustomPlatformDataWin.cpp index b1d8a1881752..a42f11361bc8 100644 --- a/Source/WebCore/platform/graphics/win/FontCustomPlatformDataWin.cpp +++ b/Source/WebCore/platform/graphics/win/FontCustomPlatformDataWin.cpp @@ -105,7 +105,8 @@ bool FontCustomPlatformData::supportsFormat(const String& format) #if USE(WOFF2) || equalLettersIgnoringASCIICase(format, "woff2"_s) #endif - || equalLettersIgnoringASCIICase(format, "woff"_s); + || equalLettersIgnoringASCIICase(format, "woff"_s) + || equalLettersIgnoringASCIICase(format, "svg"_s); } bool FontCustomPlatformData::supportsTechnology(const FontTechnology&)