Skip to content

Commit

Permalink
LibGfx: Take into account unicode ranges to find font for space glyph
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kalenikaliaksandr committed Jan 7, 2024
1 parent 335097e commit f50c462
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tests/LibWeb/Ref/reference/space-glyph-width-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<style>
.text {
font-size: 100px;
}
</style>
</head>
<body>
<div class="text">A B</div>
</body>
</html>
21 changes: 21 additions & 0 deletions Tests/LibWeb/Ref/space-glyph-width.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<link rel="match" href="reference/space-glyph-width-ref.html" />
<style>
@font-face {
font-family: 'HashFont';
src: url('assets/HashSans.woff');
unicode-range: U+0;
}

.text {
font-family: 'HashFont', 'SerenitySans';
font-size: 100px;
}
</style>
</head>
<body>
<div class="text">A B</div>
</body>
</html>
3 changes: 2 additions & 1 deletion Userland/Libraries/LibGfx/TextLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ Variant<DrawGlyph, DrawEmoji> prepare_draw_glyph_or_emoji(FloatPoint point, Utf8
template<typename Callback>
void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, FontCascadeList const& font_list, Callback callback, IncludeLeftBearing include_left_bearing = IncludeLeftBearing::No, Optional<float&> 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;

Expand Down

0 comments on commit f50c462

Please sign in to comment.