From cc7744f6cabec3d76008d71677c62ff7c4acf7c1 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Thu, 22 Apr 2021 14:25:28 -0400 Subject: [PATCH] LibGfx+FontEditor: Account for raw width when painting glyphs Fixes hidden glyphs being painted in editor and map, and '?' subsitute glyphs being overdrawn in the system. --- Userland/Applications/FontEditor/GlyphEditorWidget.cpp | 2 +- Userland/Applications/FontEditor/GlyphMapWidget.cpp | 3 ++- Userland/Libraries/LibGfx/BitmapFont.cpp | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index 753e25a69f2..44f61dd5c86 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -147,7 +147,7 @@ void GlyphEditorWidget::paint_event(GUI::PaintEvent& event) for (int y = 0; y < font().glyph_height(); ++y) { for (int x = 0; x < font().max_glyph_width(); ++x) { Gfx::IntRect rect { x * m_scale, y * m_scale, m_scale, m_scale }; - if (x >= font().glyph_width(m_glyph)) { + if (x >= font().raw_glyph_width(m_glyph)) { painter.fill_rect(rect, palette().threed_shadow1()); } else { if (bitmap.bit_at(x, y)) diff --git a/Userland/Applications/FontEditor/GlyphMapWidget.cpp b/Userland/Applications/FontEditor/GlyphMapWidget.cpp index f5a2a0be581..51a1161415c 100644 --- a/Userland/Applications/FontEditor/GlyphMapWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphMapWidget.cpp @@ -98,7 +98,8 @@ void GlyphMapWidget::paint_event(GUI::PaintEvent& event) font().glyph_height()); if (glyph == m_selected_glyph) { painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection()); - painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text()); + if (m_font->contains_glyph(glyph)) + painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text()); } else if (m_font->contains_glyph(glyph)) { painter.fill_rect(outer_rect, palette().base()); painter.draw_glyph(inner_rect.location(), glyph, palette().base_text()); diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index 3c50a0c17f4..eeac6e90554 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -241,8 +241,12 @@ Glyph BitmapFont::glyph(u32 code_point) const int BitmapFont::glyph_or_emoji_width(u32 code_point) const { - if (code_point < m_glyph_count) - return glyph_width(code_point); + if (code_point < m_glyph_count) { + if (m_glyph_widths[code_point] > 0) + return glyph_width(code_point); + else + return glyph_width('?'); + } if (m_fixed_width) return m_glyph_width;