From b1870e70298b9d5933fd4cee4fc6d947b8198d98 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 27 Sep 2024 14:27:55 +0100 Subject: [PATCH] LibWeb/CSS: Parse font-width descriptor and its font-stretch alias --- Userland/Libraries/LibWeb/CSS/FontFace.cpp | 3 ++- Userland/Libraries/LibWeb/CSS/ParsedFontFace.cpp | 3 ++- Userland/Libraries/LibWeb/CSS/ParsedFontFace.h | 8 +++++--- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 11 ++++++++++- Userland/Libraries/LibWeb/Dump.cpp | 5 +++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.cpp b/Userland/Libraries/LibWeb/CSS/FontFace.cpp index ced54f62ace..0afe492dd46 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFace.cpp +++ b/Userland/Libraries/LibWeb/CSS/FontFace.cpp @@ -392,7 +392,8 @@ void FontFace::load_font_source() ParsedFontFace parsed_font_face { font->m_family, font->m_weight.to_number(), - 0, // FIXME: slope + 0, // FIXME: slope + Gfx::FontWidth::Normal, // FIXME: width font->m_urls, font->m_unicode_ranges, {}, // FIXME: ascent_override diff --git a/Userland/Libraries/LibWeb/CSS/ParsedFontFace.cpp b/Userland/Libraries/LibWeb/CSS/ParsedFontFace.cpp index adf1a214d23..17e1f1e7df9 100644 --- a/Userland/Libraries/LibWeb/CSS/ParsedFontFace.cpp +++ b/Userland/Libraries/LibWeb/CSS/ParsedFontFace.cpp @@ -9,11 +9,12 @@ namespace Web::CSS { -ParsedFontFace::ParsedFontFace(FlyString font_family, Optional weight, Optional slope, Vector sources, Vector unicode_ranges, Optional ascent_override, Optional descent_override, Optional line_gap_override, FontDisplay font_display, Optional font_named_instance) +ParsedFontFace::ParsedFontFace(FlyString font_family, Optional weight, Optional slope, Optional width, Vector sources, Vector unicode_ranges, Optional ascent_override, Optional descent_override, Optional line_gap_override, FontDisplay font_display, Optional font_named_instance) : m_font_family(move(font_family)) , m_font_named_instance(move(font_named_instance)) , m_weight(weight) , m_slope(slope) + , m_width(width) , m_sources(move(sources)) , m_unicode_ranges(move(unicode_ranges)) , m_ascent_override(move(ascent_override)) diff --git a/Userland/Libraries/LibWeb/CSS/ParsedFontFace.h b/Userland/Libraries/LibWeb/CSS/ParsedFontFace.h index cae522839cb..11c7140f26e 100644 --- a/Userland/Libraries/LibWeb/CSS/ParsedFontFace.h +++ b/Userland/Libraries/LibWeb/CSS/ParsedFontFace.h @@ -23,7 +23,7 @@ public: Optional format; }; - ParsedFontFace(FlyString font_family, Optional weight, Optional slope, Vector sources, Vector unicode_ranges, Optional ascent_override, Optional descent_override, Optional line_gap_override, FontDisplay font_display, Optional font_named_instance); + ParsedFontFace(FlyString font_family, Optional weight, Optional slope, Optional width, Vector sources, Vector unicode_ranges, Optional ascent_override, Optional descent_override, Optional line_gap_override, FontDisplay font_display, Optional font_named_instance); ~ParsedFontFace() = default; Optional ascent_override() const { return m_ascent_override; } @@ -33,6 +33,7 @@ public: Optional font_named_instance() const { return m_font_named_instance; } Optional slope() const { return m_slope; } Optional weight() const { return m_weight; } + Optional width() const { return m_width; } Optional line_gap_override() const { return m_line_gap_override; } Vector const& sources() const { return m_sources; } Vector const& unicode_ranges() const { return m_unicode_ranges; } @@ -40,8 +41,9 @@ public: private: FlyString m_font_family; Optional m_font_named_instance; - Optional m_weight { 0 }; - Optional m_slope { 0 }; + Optional m_weight; + Optional m_slope; + Optional m_width; Vector m_sources; Vector m_unicode_ranges; Optional m_ascent_override; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index d9502f0342f..cfb1aba1761 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -5457,6 +5457,7 @@ JS::GCPtr Parser::parse_font_face_rule(TokenStream unicode_range; Optional weight; Optional slope; + Optional width; Optional ascent_override; Optional descent_override; Optional line_gap_override; @@ -5615,6 +5616,14 @@ JS::GCPtr Parser::parse_font_face_rule(TokenStreamto_font_width(); + } + continue; + } if (declaration.name().equals_ignoring_ascii_case("line-gap-override"sv)) { auto value = parse_as_percentage_or_normal(declaration.values()); if (value.is_error()) { @@ -5653,7 +5662,7 @@ JS::GCPtr Parser::parse_font_face_rule(TokenStream Parser::parse_as_font_face_src() diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 07bd8e9073b..b1d9c8f6c14 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -662,6 +662,11 @@ void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rul builder.appendff("slope: {}\n", font_face.slope().value()); } + if (font_face.width().has_value()) { + indent(builder, indent_levels + 1); + builder.appendff("width: {}\n", font_face.width().value()); + } + indent(builder, indent_levels + 1); builder.append("sources:\n"sv); for (auto const& source : font_face.sources()) {