1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:07:46 +00:00

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.
This commit is contained in:
Max Wipfli 2021-05-20 13:00:04 +02:00 committed by Andreas Kling
parent 3c2565da94
commit 4cd8ca07e3

View file

@ -9,6 +9,7 @@
#include "GlyphMapWidget.h" #include "GlyphMapWidget.h"
#include "NewFontDialog.h" #include "NewFontDialog.h"
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/UnicodeUtils.h>
#include <Applications/FontEditor/FontEditorWindowGML.h> #include <Applications/FontEditor/FontEditorWindowGML.h>
#include <LibDesktop/Launcher.h> #include <LibDesktop/Launcher.h>
#include <LibGUI/Action.h> #include <LibGUI/Action.h>
@ -33,6 +34,7 @@
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibGfx/BitmapFont.h> #include <LibGfx/BitmapFont.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
#include <LibGfx/TextDirection.h>
#include <stdlib.h> #include <stdlib.h>
static constexpr int s_pangram_count = 7; static constexpr int s_pangram_count = 7;
@ -130,18 +132,21 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
auto update_statusbar = [&] { auto update_statusbar = [&] {
auto glyph = m_glyph_map_widget->selected_glyph(); auto glyph = m_glyph_map_widget->selected_glyph();
StringBuilder builder; StringBuilder builder;
builder.appendff("{:#02x} (", glyph); builder.appendff("U+{:04X} (", glyph);
if (glyph < 128) {
if (glyph == 10) if (AK::UnicodeUtils::is_unicode_control_code_point(glyph)) {
builder.append("LF"); builder.append(AK::UnicodeUtils::get_unicode_control_code_point_alias(glyph).value());
else } else if (Gfx::get_char_bidi_class(glyph) == Gfx::BidirectionalClass::STRONG_RTL) {
builder.append(glyph); // 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 { } else {
builder.append(128 | 64 | (glyph / 64)); builder.append_code_point(glyph);
builder.append(128 | (glyph % 64));
} }
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()); statusbar.set_text(builder.to_string());
}; };