LibWeb/CSS: Add parsing for <opentype-tag>

This is a special form of `<string>` so doesn't need its own style value
type. It's used in a couple of font-related properties. For completeness
it's included in ValueType.
This commit is contained in:
Sam Atkins 2024-09-30 14:38:17 +01:00 committed by Sam Atkins
commit cd13b30fb8
Notes: github-actions[bot] 2024-10-02 15:37:57 +00:00
4 changed files with 37 additions and 1 deletions

View file

@ -7899,6 +7899,11 @@ Optional<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readon
}
}
if (auto property = any_property_accepts_type(property_ids, ValueType::OpenTypeTag); property.has_value()) {
if (auto maybe_rect = parse_opentype_tag_value(tokens))
return PropertyAndValue { *property, maybe_rect };
}
if (peek_token.is(Token::Type::Percentage)) {
auto percentage = Percentage(peek_token.token().percentage());
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value() && property_accepts_percentage(*property, percentage)) {
@ -8864,4 +8869,29 @@ bool Parser::substitute_attr_function(DOM::Element& element, FlyString const& pr
return false;
}
// https://drafts.csswg.org/css-fonts/#typedef-opentype-tag
RefPtr<StringStyleValue> Parser::parse_opentype_tag_value(TokenStream<ComponentValue>& tokens)
{
// <opentype-tag> = <string>
// The <opentype-tag> is a case-sensitive OpenType feature tag.
// As specified in the OpenType specification [OPENTYPE], feature tags contain four ASCII characters.
// Tag strings longer or shorter than four characters, or containing characters outside the U+207E codepoint range are invalid.
auto transaction = tokens.begin_transaction();
auto string_value = parse_string_value(tokens);
if (string_value == nullptr)
return nullptr;
auto string = string_value->string_value().bytes_as_string_view();
if (string.length() != 4)
return nullptr;
for (char c : string) {
if (c < 0x20 || c > 0x7E)
return nullptr;
}
transaction.commit();
return string_value;
}
}