From 5c02b960aba9b16a8d0fb251ad0477995efefbe9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 8 Jan 2024 00:10:10 +0100 Subject: [PATCH] LibGfx: Take into account unicode ranges to find font for space glyph Instead of assuming that the first font in the cascade font list will have a glyph for space, we need to find it in the list taking into account unicode ranges. --- .../Ref/reference/space-glyph-width-ref.html | 13 ++++++++++++ Tests/LibWeb/Ref/space-glyph-width.html | 21 +++++++++++++++++++ Userland/Libraries/LibGfx/TextLayout.h | 3 ++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Ref/reference/space-glyph-width-ref.html create mode 100644 Tests/LibWeb/Ref/space-glyph-width.html diff --git a/Tests/LibWeb/Ref/reference/space-glyph-width-ref.html b/Tests/LibWeb/Ref/reference/space-glyph-width-ref.html new file mode 100644 index 0000000000..f7e51aeb99 --- /dev/null +++ b/Tests/LibWeb/Ref/reference/space-glyph-width-ref.html @@ -0,0 +1,13 @@ + + + + + + +
A B
+ + diff --git a/Tests/LibWeb/Ref/space-glyph-width.html b/Tests/LibWeb/Ref/space-glyph-width.html new file mode 100644 index 0000000000..8584235727 --- /dev/null +++ b/Tests/LibWeb/Ref/space-glyph-width.html @@ -0,0 +1,21 @@ + + + + + + + +
A B
+ + diff --git a/Userland/Libraries/LibGfx/TextLayout.h b/Userland/Libraries/LibGfx/TextLayout.h index b002ddcd35..5a4243840a 100644 --- a/Userland/Libraries/LibGfx/TextLayout.h +++ b/Userland/Libraries/LibGfx/TextLayout.h @@ -105,7 +105,8 @@ Variant prepare_draw_glyph_or_emoji(FloatPoint point, Utf8 template void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, FontCascadeList const& font_list, Callback callback, IncludeLeftBearing include_left_bearing = IncludeLeftBearing::No, Optional width = {}) { - float space_width = font_list.first().glyph_width(' ') + font_list.first().glyph_spacing(); + auto const& space_glyph_font = font_list.font_for_code_point(' '); + float space_width = space_glyph_font.glyph_width(' ') + space_glyph_font.glyph_spacing(); u32 last_code_point = 0;