LibWeb: Port SVGFormattingContext to UTF-16

This commit is contained in:
Timothy Flynn 2025-08-05 07:11:58 -04:00 committed by Jelle Raaijmakers
commit 04d32deb52
Notes: github-actions[bot] 2025-08-05 13:14:54 +00:00
3 changed files with 7 additions and 10 deletions

View file

@ -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<SVG::SVGGeometryElement&>(*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)

View file

@ -40,16 +40,15 @@ Optional<TextAnchor> 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<WebIDL::Long> SVGTextContentElement::get_number_of_chars() const
{
auto length_in_code_units = AK::utf16_code_unit_length_from_utf8(text_contents());
return static_cast<WebIDL::Long>(length_in_code_units);
return static_cast<WebIDL::Long>(text_contents().length_in_code_units());
}
GC::Ref<Geometry::DOMPoint> SVGTextContentElement::get_start_position_of_char(WebIDL::UnsignedLong charnum)

View file

@ -23,7 +23,7 @@ public:
Optional<TextAnchor> text_anchor() const;
ByteString text_contents() const;
Utf16String text_contents() const;
GC::Ref<Geometry::DOMPoint> get_start_position_of_char(WebIDL::UnsignedLong charnum);