LibWeb/CSS: Parse the font-language-override descriptor
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run

This commit is contained in:
Sam Atkins 2024-09-27 17:11:31 +01:00 committed by Andreas Kling
parent 1d8867d9ae
commit 20af2eb2b0
Notes: github-actions[bot] 2024-09-28 12:43:20 +00:00
5 changed files with 25 additions and 3 deletions

View file

@ -401,6 +401,7 @@ void FontFace::load_font_source()
{}, // FIXME: line_gap_override {}, // FIXME: line_gap_override
FontDisplay::Auto, // FIXME: font_display FontDisplay::Auto, // FIXME: font_display
{}, // font-named-instance doesn't exist in FontFace {}, // font-named-instance doesn't exist in FontFace
{}, // font-language-override doesn't exist in FontFace
}; };
if (auto loader = style_computer.load_font_face(parsed_font_face, move(on_load), move(on_error)); loader.has_value()) if (auto loader = style_computer.load_font_face(parsed_font_face, move(on_load), move(on_error)); loader.has_value())
loader->start_loading_next_url(); loader->start_loading_next_url();

View file

@ -9,7 +9,7 @@
namespace Web::CSS { namespace Web::CSS {
ParsedFontFace::ParsedFontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Optional<int> width, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges, Optional<Percentage> ascent_override, Optional<Percentage> descent_override, Optional<Percentage> line_gap_override, FontDisplay font_display, Optional<FlyString> font_named_instance) ParsedFontFace::ParsedFontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Optional<int> width, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges, Optional<Percentage> ascent_override, Optional<Percentage> descent_override, Optional<Percentage> line_gap_override, FontDisplay font_display, Optional<FlyString> font_named_instance, Optional<FlyString> font_language_override)
: m_font_family(move(font_family)) : m_font_family(move(font_family))
, m_font_named_instance(move(font_named_instance)) , m_font_named_instance(move(font_named_instance))
, m_weight(weight) , m_weight(weight)
@ -21,6 +21,7 @@ ParsedFontFace::ParsedFontFace(FlyString font_family, Optional<int> weight, Opti
, m_descent_override(move(descent_override)) , m_descent_override(move(descent_override))
, m_line_gap_override(move(line_gap_override)) , m_line_gap_override(move(line_gap_override))
, m_font_display(font_display) , m_font_display(font_display)
, m_font_language_override(font_language_override)
{ {
} }

View file

@ -23,13 +23,14 @@ public:
Optional<FlyString> format; Optional<FlyString> format;
}; };
ParsedFontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Optional<int> width, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges, Optional<Percentage> ascent_override, Optional<Percentage> descent_override, Optional<Percentage> line_gap_override, FontDisplay font_display, Optional<FlyString> font_named_instance); ParsedFontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Optional<int> width, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges, Optional<Percentage> ascent_override, Optional<Percentage> descent_override, Optional<Percentage> line_gap_override, FontDisplay font_display, Optional<FlyString> font_named_instance, Optional<FlyString> font_language_override);
~ParsedFontFace() = default; ~ParsedFontFace() = default;
Optional<Percentage> ascent_override() const { return m_ascent_override; } Optional<Percentage> ascent_override() const { return m_ascent_override; }
Optional<Percentage> descent_override() const { return m_descent_override; } Optional<Percentage> descent_override() const { return m_descent_override; }
FontDisplay font_display() const { return m_font_display; } FontDisplay font_display() const { return m_font_display; }
FlyString font_family() const { return m_font_family; } FlyString font_family() const { return m_font_family; }
Optional<FlyString> font_language_override() const { return m_font_language_override; }
Optional<FlyString> font_named_instance() const { return m_font_named_instance; } Optional<FlyString> font_named_instance() const { return m_font_named_instance; }
Optional<int> slope() const { return m_slope; } Optional<int> slope() const { return m_slope; }
Optional<int> weight() const { return m_weight; } Optional<int> weight() const { return m_weight; }
@ -50,6 +51,7 @@ private:
Optional<Percentage> m_descent_override; Optional<Percentage> m_descent_override;
Optional<Percentage> m_line_gap_override; Optional<Percentage> m_line_gap_override;
FontDisplay m_font_display; FontDisplay m_font_display;
Optional<FlyString> m_font_language_override;
}; };
} }

View file

@ -5507,6 +5507,7 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
Optional<Percentage> descent_override; Optional<Percentage> descent_override;
Optional<Percentage> line_gap_override; Optional<Percentage> line_gap_override;
FontDisplay font_display = FontDisplay::Auto; FontDisplay font_display = FontDisplay::Auto;
Optional<FlyString> language_override;
// "normal" is returned as nullptr // "normal" is returned as nullptr
auto parse_as_percentage_or_normal = [&](Vector<ComponentValue> const& values) -> ErrorOr<Optional<Percentage>> { auto parse_as_percentage_or_normal = [&](Vector<ComponentValue> const& values) -> ErrorOr<Optional<Percentage>> {
@ -5626,6 +5627,18 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
font_family = String::join(' ', font_family_parts).release_value_but_fixme_should_propagate_errors(); font_family = String::join(' ', font_family_parts).release_value_but_fixme_should_propagate_errors();
continue; continue;
} }
if (declaration.name().equals_ignoring_ascii_case("font-language-override"sv)) {
TokenStream token_stream { declaration.values() };
if (auto maybe_value = parse_css_value(CSS::PropertyID::FontLanguageOverride, token_stream); !maybe_value.is_error()) {
auto& value = maybe_value.value();
if (value->is_string()) {
language_override = value->as_string().string_value();
} else {
language_override.clear();
}
}
continue;
}
if (declaration.name().equals_ignoring_ascii_case("font-named-instance"sv)) { if (declaration.name().equals_ignoring_ascii_case("font-named-instance"sv)) {
// auto | <string> // auto | <string>
TokenStream token_stream { declaration.values() }; TokenStream token_stream { declaration.values() };
@ -5707,7 +5720,7 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
unicode_range.empend(0x0u, 0x10FFFFu); unicode_range.empend(0x0u, 0x10FFFFu);
} }
return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), move(weight), move(slope), move(width), move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display, move(font_named_instance) }); return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), move(weight), move(slope), move(width), move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display, move(font_named_instance), move(language_override) });
} }
Vector<ParsedFontFace::Source> Parser::parse_as_font_face_src() Vector<ParsedFontFace::Source> Parser::parse_as_font_face_src()

View file

@ -704,6 +704,11 @@ void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rul
indent(builder, indent_levels + 1); indent(builder, indent_levels + 1);
builder.appendff("named-instance: {}\n", font_face.font_named_instance().value()); builder.appendff("named-instance: {}\n", font_face.font_named_instance().value());
} }
if (font_face.font_language_override().has_value()) {
indent(builder, indent_levels + 1);
builder.appendff("language-override: {}\n", font_face.font_language_override().value());
}
} }
void dump_import_rule(StringBuilder& builder, CSS::CSSImportRule const& rule, int indent_levels) void dump_import_rule(StringBuilder& builder, CSS::CSSImportRule const& rule, int indent_levels)