From 4cd8ca07e327f8deefa5352048b43f9b0f02b9db Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Thu, 20 May 2021 13:00:04 +0200 Subject: [PATCH] FontEditor: Make statusbar text generation more robust This makes a few modifications to the statusbar text generation: * Use the canonical U+XXXX representation of unicode characters. * For control characters, display their alias instead of whitespace. * Substitute RTL codepoints with U+FFFD so the text paints correctly. * Only show the glyph's dimensions if it actually exists in the font. This fixes #7286. --- .../Applications/FontEditor/FontEditor.cpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index af2ccfdd47..7aae6efb87 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -9,6 +9,7 @@ #include "GlyphMapWidget.h" #include "NewFontDialog.h" #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #include static constexpr int s_pangram_count = 7; @@ -130,18 +132,21 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& auto update_statusbar = [&] { auto glyph = m_glyph_map_widget->selected_glyph(); StringBuilder builder; - builder.appendff("{:#02x} (", glyph); - if (glyph < 128) { - if (glyph == 10) - builder.append("LF"); - else - builder.append(glyph); + builder.appendff("U+{:04X} (", glyph); + + if (AK::UnicodeUtils::is_unicode_control_code_point(glyph)) { + builder.append(AK::UnicodeUtils::get_unicode_control_code_point_alias(glyph).value()); + } else if (Gfx::get_char_bidi_class(glyph) == Gfx::BidirectionalClass::STRONG_RTL) { + // FIXME: This is a necessary hack, as RTL text will mess up the painting of the statusbar text. + // For now, replace RTL glyphs with U+FFFD, the replacement character. + builder.append_code_point(0xFFFD); } else { - builder.append(128 | 64 | (glyph / 64)); - builder.append(128 | (glyph % 64)); + builder.append_code_point(glyph); } - builder.append(") "); - builder.appendff("[{}x{}]", m_edited_font->raw_glyph_width(glyph), m_edited_font->glyph_height()); + + builder.append(")"); + if (m_edited_font->raw_glyph_width(glyph) > 0) + builder.appendff(" [{}x{}]", m_edited_font->raw_glyph_width(glyph), m_edited_font->glyph_height()); statusbar.set_text(builder.to_string()); };