Skip to content

Commit

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

Reviewed by Myles C. Maxfield.

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

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

* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-face-src-tech-expected.txt:
* Source/WebCore/css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcResourceValue::fontLoadRequest):
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeFontTech):
* Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrcURI):
* Source/WebCore/css/parser/CSSSupportsParser.cpp:
(WebCore::CSSSupportsParser::consumeSupportsFontTechFunction):

Canonical link: https://commits.webkit.org/265999@main
  • Loading branch information
vitorroriz committed Jul 12, 2023
1 parent a64778e commit 8a43470
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Expand Up @@ -4,9 +4,9 @@ PASS Check that src: url("foo.ttf") tech() is invalid
PASS Check that src: url("foo.ttf") tech(features-opentype) is valid
PASS Check that src: url("foo.ttf") tech(features-aat) is valid
PASS Check that src: url("foo.ttf") tech(color-COLRv0) is valid
FAIL Check that src: url("foo.ttf") tech(color-COLRv1) is valid assert_equals: expected true but got false
PASS Check that src: url("foo.ttf") tech(color-COLRv1) is valid
PASS Check that src: url("foo.ttf") tech(color-sbix) is valid
FAIL Check that src: url("foo.ttf") tech(color-CBDT) is valid assert_equals: expected true but got false
PASS Check that src: url("foo.ttf") tech(color-CBDT) is valid
PASS Check that src: url("foo.ttf") tech(variations) is valid
PASS Check that src: url("foo.ttf") tech(palettes) is valid
PASS Check that src: url("foo.ttf") tech("features-opentype") is invalid
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/css/CSSFontFaceSrcValue.cpp
Expand Up @@ -104,6 +104,13 @@ std::unique_ptr<FontLoadRequest> CSSFontFaceSrcResourceValue::fontLoadRequest(Sc
return nullptr;
}

if (!m_technologies.isEmpty()) {
for (auto technology : m_technologies) {
if (!FontCustomPlatformData::supportsTechnology(technology))
return nullptr;
}
}

auto request = context.fontLoadRequest(m_location.resolvedURL.string(), isFormatSVG, isInitiatingElementInUserAgentShadowTree, m_loadedFromOpaqueSource);
if (auto* cachedRequest = dynamicDowncast<CachedFontLoadRequest>(request.get()))
m_cachedFont = &cachedRequest->cachedFont();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Expand Up @@ -8239,7 +8239,7 @@ Vector<FontTechnology> consumeFontTech(CSSParserTokenRange& range, bool singleVa
if (arg.type() != IdentToken)
return { };
auto technology = fromCSSValueID<FontTechnology>(arg.id());
if (technology != FontTechnology::Invalid && FontCustomPlatformData::supportsTechnology(technology))
if (technology != FontTechnology::Invalid)
technologies.append(technology);
} while (consumeCommaIncludingWhitespace(args) && !singleValue);
if (!args.atEnd())
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp
Expand Up @@ -234,21 +234,21 @@ static RefPtr<CSSFontFaceSrcResourceValue> consumeFontFaceSrcURI(CSSParserTokenR
return nullptr;

String format;
Vector<FontTechnology> supportedTechnologies;
Vector<FontTechnology> technologies;
if (range.peek().functionId() == CSSValueFormat) {
format = CSSPropertyParserHelpers::consumeFontFormat(range);
if (format.isNull())
return nullptr;
}
if (range.peek().functionId() == CSSValueTech) {
supportedTechnologies = CSSPropertyParserHelpers::consumeFontTech(range);
if (supportedTechnologies.isEmpty())
technologies = CSSPropertyParserHelpers::consumeFontTech(range);
if (technologies.isEmpty())
return nullptr;
}
if (!range.atEnd())
return nullptr;

return CSSFontFaceSrcResourceValue::create(WTFMove(location), WTFMove(format), WTFMove(supportedTechnologies), context.isContentOpaque ? LoadedFromOpaqueSource::Yes : LoadedFromOpaqueSource::No);
return CSSFontFaceSrcResourceValue::create(WTFMove(location), WTFMove(format), WTFMove(technologies), context.isContentOpaque ? LoadedFromOpaqueSource::Yes : LoadedFromOpaqueSource::No);
}

static RefPtr<CSSValue> consumeFontFaceSrcLocal(CSSParserTokenRange& range)
Expand Down
8 changes: 6 additions & 2 deletions Source/WebCore/css/parser/CSSSupportsParser.cpp
Expand Up @@ -33,6 +33,7 @@
#include "CSSParserImpl.h"
#include "CSSPropertyParserHelpers.h"
#include "CSSSelectorParser.h"
#include "FontCustomPlatformData.h"
#include "StyleRule.h"

namespace WebCore {
Expand Down Expand Up @@ -177,8 +178,11 @@ CSSSupportsParser::SupportsResult CSSSupportsParser::consumeSupportsFontFormatFu
CSSSupportsParser::SupportsResult CSSSupportsParser::consumeSupportsFontTechFunction(CSSParserTokenRange& range)
{
ASSERT(range.peek().type() == FunctionToken && range.peek().functionId() == CSSValueFontTech);
auto supportedTechnologies = CSSPropertyParserHelpers::consumeFontTech(range, true);
return supportedTechnologies.isEmpty() ? Unsupported : Supported;
auto technologies = CSSPropertyParserHelpers::consumeFontTech(range, true);
if (technologies.isEmpty())
return Unsupported;
ASSERT(technologies.size() == 1);
return FontCustomPlatformData::supportsTechnology(technologies[0]) ? Supported : Unsupported;
}

// <supports-in-parens> = ( <supports-condition> ) | <supports-feature> | <general-enclosed>
Expand Down

0 comments on commit 8a43470

Please sign in to comment.