Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
@font-face src format() should parse valid unsupported keywords
https://bugs.webkit.org/show_bug.cgi?id=259144
rdar://112135869

Reviewed by Tim Nguyen.

A valid format() keyword (ident) argument should be parsed even if the represented
format is not supported by the engine. The engine should reject loading
the font for unsupported formats but this should happen only at
loading time and not at parsing time.

The reason why we were rejecting it before, at parsing time, is for some
inconsistency in different parts of the spec. That
will be fixed soon by the CSSWG, see: w3c/csswg-drafts#8793

* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-format-expected.txt:
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::isFontFormatKeywordValid):
(WebCore::CSSPropertyParserHelpers::consumeFontFormat):
* Source/WebCore/css/parser/CSSSupportsParser.cpp:
(WebCore::CSSSupportsParser::consumeSupportsFontFormatFunction):

Canonical link: https://commits.webkit.org/266043@main
  • Loading branch information
vitorroriz committed Jul 13, 2023
1 parent 10dac7d commit b2a00a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Expand Up @@ -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
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(collection) is valid
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
Expand Down
27 changes: 21 additions & 6 deletions Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Expand Up @@ -8248,6 +8248,22 @@ Vector<FontTechnology> consumeFontTech(CSSParserTokenRange& range, bool singleVa
return technologies;
}

static bool isFontFormatKeywordValid(CSSValueID id)
{
switch (id) {
case CSSValueCollection:
case CSSValueEmbeddedOpentype:
case CSSValueOpentype:
case CSSValueSvg:
case CSSValueTruetype:
case CSSValueWoff:
case CSSValueWoff2:
return true;
default:
return false;
}
}

String consumeFontFormat(CSSParserTokenRange& range, bool rejectStringValues)
{
// https://drafts.csswg.org/css-fonts/#descdef-font-face-src
Expand All @@ -8256,12 +8272,11 @@ String consumeFontFormat(CSSParserTokenRange& range, bool rejectStringValues)
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;
if (arg.type() == IdentToken && isFontFormatKeywordValid(arg.id()))
return arg.value().toString();
if (arg.type() == StringToken && !rejectStringValues)
return arg.value().toString();
return nullString();
}

// MARK: @font-palette-values
Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/css/parser/CSSSupportsParser.cpp
Expand Up @@ -171,7 +171,9 @@ CSSSupportsParser::SupportsResult CSSSupportsParser::consumeSupportsFontFormatFu
{
ASSERT(range.peek().type() == FunctionToken && range.peek().functionId() == CSSValueFontFormat);
auto format = CSSPropertyParserHelpers::consumeFontFormat(range, true);
return format.isNull() ? Unsupported : Supported;
if (format.isNull())
return Unsupported;
return FontCustomPlatformData::supportsFormat(format) ? Supported : Unsupported;
}

// <supports-font-tech-fn>
Expand Down

0 comments on commit b2a00a2

Please sign in to comment.