summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-07-09 15:12:10 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-09 22:16:13 +0200
commit80ed7d220c3df9ccc9678dda5266f8a4a776a4f1 (patch)
treea00648ba98ebfe932e8b66c46182f7f1bbd55000 /Userland/Libraries
parent2217d91b8d7c5086fad76396d5b50e13d67aae65 (diff)
downloadserenity-80ed7d220c3df9ccc9678dda5266f8a4a776a4f1.zip
LibGfx: Paint whitespace characters (including &nbsp;) as empty space
This fixes an issue where &nbsp; would sometimes render as "A" in web content.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp11
1 files changed, 8 insertions, 3 deletions
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 <kling@serenityos.org>
+ * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
@@ -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<BitmapFormat format = BitmapFormat::Invalid>
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;