From 04d32deb520b3c89e3b72a996741857281acb304 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 5 Aug 2025 07:11:58 -0400 Subject: [PATCH] LibWeb: Port SVGFormattingContext to UTF-16 --- Libraries/LibWeb/Layout/SVGFormattingContext.cpp | 8 +++----- Libraries/LibWeb/SVG/SVGTextContentElement.cpp | 7 +++---- Libraries/LibWeb/SVG/SVGTextContentElement.h | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index 4d81a6b14fe..5e743aec99a 100644 --- a/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -339,8 +339,7 @@ Gfx::Path SVGFormattingContext::compute_path_for_text(SVGTextBox const& text_box // FIXME: Use per-code-point fonts. auto& font = text_box.first_available_font(); auto text_contents = text_element.text_contents(); - Utf8View text_utf8 { text_contents }; - auto text_width = font.width(text_utf8); + auto text_width = font.width(text_contents); auto text_offset = text_element.get_offset(m_viewport_size); // https://svgwg.org/svg2-draft/text.html#TextAnchoringProperties @@ -368,7 +367,7 @@ Gfx::Path SVGFormattingContext::compute_path_for_text(SVGTextBox const& text_box Gfx::Path path; path.move_to(text_offset); - path.text(text_utf8, font); + path.text(text_contents, font); return path; } @@ -382,10 +381,9 @@ Gfx::Path SVGFormattingContext::compute_path_for_text_path(SVGTextPathBox const& // FIXME: Use per-code-point fonts. auto& font = text_path_box.first_available_font(); auto text_contents = text_path_element.text_contents(); - Utf8View text_utf8 { text_contents }; auto shape_path = const_cast(*path_or_shape).get_path(m_viewport_size); - return shape_path.place_text_along(text_utf8, font); + return shape_path.place_text_along(text_contents, font); } void SVGFormattingContext::layout_path_like_element(SVGGraphicsBox const& graphics_box) diff --git a/Libraries/LibWeb/SVG/SVGTextContentElement.cpp b/Libraries/LibWeb/SVG/SVGTextContentElement.cpp index 5ae4e36448f..63f2bbcb2d5 100644 --- a/Libraries/LibWeb/SVG/SVGTextContentElement.cpp +++ b/Libraries/LibWeb/SVG/SVGTextContentElement.cpp @@ -40,16 +40,15 @@ Optional SVGTextContentElement::text_anchor() const } } -ByteString SVGTextContentElement::text_contents() const +Utf16String SVGTextContentElement::text_contents() const { - return child_text_content().to_byte_string().trim_whitespace(); + return child_text_content().trim_ascii_whitespace(); } // https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars WebIDL::ExceptionOr SVGTextContentElement::get_number_of_chars() const { - auto length_in_code_units = AK::utf16_code_unit_length_from_utf8(text_contents()); - return static_cast(length_in_code_units); + return static_cast(text_contents().length_in_code_units()); } GC::Ref SVGTextContentElement::get_start_position_of_char(WebIDL::UnsignedLong charnum) diff --git a/Libraries/LibWeb/SVG/SVGTextContentElement.h b/Libraries/LibWeb/SVG/SVGTextContentElement.h index aa88e428869..d15a9fe444a 100644 --- a/Libraries/LibWeb/SVG/SVGTextContentElement.h +++ b/Libraries/LibWeb/SVG/SVGTextContentElement.h @@ -23,7 +23,7 @@ public: Optional text_anchor() const; - ByteString text_contents() const; + Utf16String text_contents() const; GC::Ref get_start_position_of_char(WebIDL::UnsignedLong charnum);