From 80ed7d220c3df9ccc9678dda5266f8a4a776a4f1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 9 Jul 2022 15:12:10 +0200 Subject: LibGfx: Paint whitespace characters (including  ) as empty space This fixes an issue where   would sometimes render as "A" in web content. --- Userland/Libraries/LibGfx/Painter.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Userland/Libraries/LibGfx') diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index c6ce49562f..b5b67e50d6 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2022, Andreas Kling * Copyright (c) 2021, Idan Horowitz * Copyright (c) 2021, Mustafa Quraish * Copyright (c) 2021, Sam Atkins @@ -41,6 +41,11 @@ namespace Gfx { +static bool should_paint_as_space(u32 code_point) +{ + return is_ascii_space(code_point) || code_point == 0xa0; +} + template ALWAYS_INLINE Color get_pixel(Gfx::Bitmap const& bitmap, int x, int y) { @@ -1435,7 +1440,7 @@ void draw_text_line(IntRect const& a_rect, Utf8View const& text, Font const& fon u32 last_code_point { 0 }; for (auto it = text.begin(); it != text.end(); ++it) { auto code_point = *it; - if (code_point == ' ') { + if (should_paint_as_space(code_point)) { point.translate_by(space_width, 0); last_code_point = code_point; continue; @@ -2391,7 +2396,7 @@ void Painter::draw_text_run(FloatPoint const& baseline_start, Utf8View const& st for (auto code_point_iterator = string.begin(); code_point_iterator != string.end(); ++code_point_iterator) { auto code_point = *code_point_iterator; - if (code_point == ' ') { + if (should_paint_as_space(code_point)) { x += space_width + font.glyph_spacing(); last_code_point = code_point; continue; -- cgit v1.2.3