mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 15:43:20 +00:00
LibWeb: Make DisplayListRecorder::draw_text() take text as UTF-16
This is prep work for getting rid of UTF-8 text shaping.
This commit is contained in:
parent
b634918ff6
commit
6042b5631a
Notes:
github-actions[bot]
2025-09-21 11:23:52 +00:00
Author: https://github.com/awesomekling
Commit: 6042b5631a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6254
Reviewed-by: https://github.com/tcl3
6 changed files with 7 additions and 7 deletions
|
@ -222,12 +222,12 @@ void DisplayListRecorder::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color
|
|||
});
|
||||
}
|
||||
|
||||
void DisplayListRecorder::draw_text(Gfx::IntRect const& rect, String raw_text, Gfx::Font const& font, Gfx::TextAlignment alignment, Color color)
|
||||
void DisplayListRecorder::draw_text(Gfx::IntRect const& rect, Utf16String const& raw_text, Gfx::Font const& font, Gfx::TextAlignment alignment, Color color)
|
||||
{
|
||||
if (rect.is_empty() || color.alpha() == 0)
|
||||
return;
|
||||
|
||||
auto glyph_run = Gfx::shape_text({}, 0, raw_text.code_points(), font, Gfx::GlyphRun::TextType::Ltr, {});
|
||||
auto glyph_run = Gfx::shape_text({}, 0, raw_text.utf16_view(), font, Gfx::GlyphRun::TextType::Ltr, {});
|
||||
float baseline_x = 0;
|
||||
if (alignment == Gfx::TextAlignment::CenterLeft) {
|
||||
baseline_x = rect.x();
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
|
||||
void draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness = 1, Gfx::LineStyle style = Gfx::LineStyle::Solid, Color alternate_color = Color::Transparent);
|
||||
|
||||
void draw_text(Gfx::IntRect const&, String, Gfx::Font const&, Gfx::TextAlignment, Color);
|
||||
void draw_text(Gfx::IntRect const&, Utf16String const&, Gfx::Font const&, Gfx::TextAlignment, Color);
|
||||
|
||||
// Streamlined text drawing routine that does no wrapping/elision/alignment.
|
||||
void draw_glyph_run(Gfx::FloatPoint baseline_start, Gfx::GlyphRun const& glyph_run, Color color, Gfx::IntRect const& rect, double scale, Gfx::Orientation);
|
||||
|
|
|
@ -71,7 +71,7 @@ void ImagePaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
|
|||
if (!m_alt_text.is_empty()) {
|
||||
auto enclosing_rect = context.enclosing_device_rect(image_rect).to_type<int>();
|
||||
context.display_list_recorder().draw_rect(enclosing_rect, Gfx::Color::Black);
|
||||
context.display_list_recorder().draw_text(enclosing_rect, m_alt_text, *Platform::FontPlugin::the().default_font(12), Gfx::TextAlignment::Center, computed_values().color());
|
||||
context.display_list_recorder().draw_text(enclosing_rect, Utf16String::from_utf8(m_alt_text), *Platform::FontPlugin::the().default_font(12), Gfx::TextAlignment::Center, computed_values().color());
|
||||
}
|
||||
} else if (auto bitmap = m_image_provider.current_image_bitmap_sized(image_rect_device_pixels.size().to_type<int>())) {
|
||||
ScopedCornerRadiusClip corner_clip { context, image_rect_device_pixels, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
||||
|
|
|
@ -59,7 +59,7 @@ void MarkerPaintable::paint(DisplayListRecordingContext& context, PaintPhase pha
|
|||
if (auto text = layout_box().text(); text.has_value()) {
|
||||
// FIXME: This should use proper text layout logic!
|
||||
// This does not line up with the text in the <li> element which looks very sad :(
|
||||
context.display_list_recorder().draw_text(device_rect.to_type<int>(), *text, layout_box().font(context), Gfx::TextAlignment::Center, color);
|
||||
context.display_list_recorder().draw_text(device_rect.to_type<int>(), Utf16String::from_utf8(*text), layout_box().font(context), Gfx::TextAlignment::Center, color);
|
||||
} else if (auto const* counter_style = layout_box().list_style_type().get_pointer<CSS::CounterStyleNameKeyword>()) {
|
||||
switch (*counter_style) {
|
||||
case CSS::CounterStyleNameKeyword::Square:
|
||||
|
|
|
@ -196,7 +196,7 @@ void MediaPaintable::paint_control_bar_timestamp(DisplayListRecordingContext& co
|
|||
if (components.timestamp_rect.is_empty())
|
||||
return;
|
||||
|
||||
context.display_list_recorder().draw_text(components.timestamp_rect.to_type<int>(), components.timestamp.to_well_formed_utf8(), *components.timestamp_font, Gfx::TextAlignment::CenterLeft, Color::White);
|
||||
context.display_list_recorder().draw_text(components.timestamp_rect.to_type<int>(), components.timestamp, *components.timestamp_font, Gfx::TextAlignment::CenterLeft, Color::White);
|
||||
}
|
||||
|
||||
void MediaPaintable::paint_control_bar_speaker(DisplayListRecordingContext& context, HTML::HTMLMediaElement const& media_element, Components const& components, Optional<DevicePixelPoint> const& mouse_position)
|
||||
|
|
|
@ -547,7 +547,7 @@ void PaintableBox::paint_inspector_overlay_internal(DisplayListRecordingContext&
|
|||
auto size_text_device_rect = context.enclosing_device_rect(size_text_rect).to_type<int>();
|
||||
context.display_list_recorder().fill_rect(size_text_device_rect, context.palette().color(Gfx::ColorRole::Tooltip));
|
||||
context.display_list_recorder().draw_rect(size_text_device_rect, context.palette().threed_shadow1());
|
||||
context.display_list_recorder().draw_text(size_text_device_rect, size_text.to_well_formed_utf8(), font->with_size(font->point_size() * context.device_pixels_per_css_pixel()), Gfx::TextAlignment::Center, context.palette().color(Gfx::ColorRole::TooltipText));
|
||||
context.display_list_recorder().draw_text(size_text_device_rect, size_text, font->with_size(font->point_size() * context.device_pixels_per_css_pixel()), Gfx::TextAlignment::Center, context.palette().color(Gfx::ColorRole::TooltipText));
|
||||
}
|
||||
|
||||
void PaintableBox::set_stacking_context(NonnullOwnPtr<StackingContext> stacking_context)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue