Преглед на файлове

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.
Aliaksandr Kalenik преди 1 година
родител
ревизия
5c02b960ab
променени са 3 файла, в които са добавени 36 реда и са изтрити 1 реда
  1. 13 0
      Tests/LibWeb/Ref/reference/space-glyph-width-ref.html
  2. 21 0
      Tests/LibWeb/Ref/space-glyph-width.html
  3. 2 1
      Userland/Libraries/LibGfx/TextLayout.h

+ 13 - 0
Tests/LibWeb/Ref/reference/space-glyph-width-ref.html

@@ -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 - 0
Tests/LibWeb/Ref/space-glyph-width.html

@@ -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>

+ 2 - 1
Userland/Libraries/LibGfx/TextLayout.h

@@ -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;