浏览代码

LibWeb/CSS: Parse the font-language-override descriptor

Sam Atkins 10 月之前
父节点
当前提交
20af2eb2b0

+ 1 - 0
Userland/Libraries/LibWeb/CSS/FontFace.cpp

@@ -401,6 +401,7 @@ void FontFace::load_font_source()
                 {},                // FIXME: line_gap_override
                 FontDisplay::Auto, // FIXME: font_display
                 {},                // 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())
                 loader->start_loading_next_url();

+ 2 - 1
Userland/Libraries/LibWeb/CSS/ParsedFontFace.cpp

@@ -9,7 +9,7 @@
 
 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_named_instance(move(font_named_instance))
     , m_weight(weight)
@@ -21,6 +21,7 @@ ParsedFontFace::ParsedFontFace(FlyString font_family, Optional<int> weight, Opti
     , m_descent_override(move(descent_override))
     , m_line_gap_override(move(line_gap_override))
     , m_font_display(font_display)
+    , m_font_language_override(font_language_override)
 {
 }
 

+ 3 - 1
Userland/Libraries/LibWeb/CSS/ParsedFontFace.h

@@ -23,13 +23,14 @@ public:
         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;
 
     Optional<Percentage> ascent_override() const { return m_ascent_override; }
     Optional<Percentage> descent_override() const { return m_descent_override; }
     FontDisplay font_display() const { return m_font_display; }
     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<int> slope() const { return m_slope; }
     Optional<int> weight() const { return m_weight; }
@@ -50,6 +51,7 @@ private:
     Optional<Percentage> m_descent_override;
     Optional<Percentage> m_line_gap_override;
     FontDisplay m_font_display;
+    Optional<FlyString> m_font_language_override;
 };
 
 }

+ 14 - 1
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -5507,6 +5507,7 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
     Optional<Percentage> descent_override;
     Optional<Percentage> line_gap_override;
     FontDisplay font_display = FontDisplay::Auto;
+    Optional<FlyString> language_override;
 
     // "normal" is returned as nullptr
     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();
             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)) {
             // auto | <string>
             TokenStream token_stream { declaration.values() };
@@ -5707,7 +5720,7 @@ JS::GCPtr<CSSFontFaceRule> Parser::parse_font_face_rule(TokenStream<ComponentVal
         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()

+ 5 - 0
Userland/Libraries/LibWeb/Dump.cpp

@@ -704,6 +704,11 @@ void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rul
         indent(builder, indent_levels + 1);
         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)