From edf86af4f48c66fc046933e0b92fbb0ba34f84e9 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Mon, 29 Nov 2021 08:43:32 -0500 Subject: [PATCH] LibGfx+FontEditor: Add helper to determine raw glyph presence GlyphBitmaps are considered present if they have a width greater than zero. This adds a counterpart method for raw (unmasked) glyphs and makes intent more explicit throughout FontEditor. --- Userland/Applications/FontEditor/FontEditor.cpp | 10 +++++----- Userland/Applications/FontEditor/GlyphMapWidget.cpp | 4 ++-- Userland/Libraries/LibGfx/BitmapFont.h | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index c3aa56b475..b5d1346ddf 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -204,7 +204,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& }); m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "glyph/x-fonteditor"); m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { - if (m_glyph_editor_widget->is_glyph_empty() && m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) == 0) + if (m_glyph_editor_widget->is_glyph_empty() && !m_edited_font->contains_raw_glyph(m_glyph_map_widget->selected_glyph())) return; m_glyph_editor_widget->delete_glyph(); if (m_edited_font->is_fixed_width()) @@ -252,7 +252,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& } else if (i < 0 && search_wrapped) { break; } - if (m_edited_font->raw_glyph_width(i) > 0) { + if (m_edited_font->contains_raw_glyph(i)) { m_glyph_map_widget->set_focus(true); m_glyph_map_widget->set_selected_glyph(i); m_glyph_map_widget->scroll_to_glyph(i); @@ -270,7 +270,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& } else if (i > 0x10FFFF && search_wrapped) { break; } - if (m_edited_font->raw_glyph_width(i) > 0) { + if (m_edited_font->contains_raw_glyph(i)) { m_glyph_map_widget->set_focus(true); m_glyph_map_widget->set_selected_glyph(i); m_glyph_map_widget->scroll_to_glyph(i); @@ -501,7 +501,7 @@ void FontEditorWidget::initialize(const String& path, RefPtr&& m_glyph_editor_width_spinbox->set_value(m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()), GUI::AllowCallback::No); m_glyph_editor_present_checkbox->set_visible(m_edited_font->is_fixed_width()); - m_glyph_editor_present_checkbox->set_checked(m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) > 0, GUI::AllowCallback::No); + m_glyph_editor_present_checkbox->set_checked(m_edited_font->contains_raw_glyph(m_glyph_map_widget->selected_glyph()), GUI::AllowCallback::No); m_fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width(), GUI::AllowCallback::No); m_name_textbox->set_text(m_edited_font->name(), GUI::AllowCallback::No); @@ -736,7 +736,7 @@ void FontEditorWidget::update_statusbar() builder.appendff(" {}", glyph_name.value()); } - if (m_edited_font->raw_glyph_width(glyph) > 0) + if (m_edited_font->contains_raw_glyph(glyph)) builder.appendff(" [{}x{}]", m_edited_font->raw_glyph_width(glyph), m_edited_font->glyph_height()); m_statusbar->set_text(builder.to_string()); } diff --git a/Userland/Applications/FontEditor/GlyphMapWidget.cpp b/Userland/Applications/FontEditor/GlyphMapWidget.cpp index 037e2b147f..73d0f3a1b8 100644 --- a/Userland/Applications/FontEditor/GlyphMapWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphMapWidget.cpp @@ -97,9 +97,9 @@ 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()); - if (m_font->raw_glyph_width(glyph)) + if (m_font->contains_raw_glyph(glyph)) painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text()); - } else if (m_font->raw_glyph_width(glyph)) { + } else if (m_font->contains_raw_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.h b/Userland/Libraries/LibGfx/BitmapFont.h index 6adb4858c1..632ddd2f32 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.h +++ b/Userland/Libraries/LibGfx/BitmapFont.h @@ -43,6 +43,7 @@ public: Glyph glyph(u32 code_point) const override; Glyph raw_glyph(u32 code_point) const; bool contains_glyph(u32 code_point) const override; + bool contains_raw_glyph(u32 code_point) const { return m_glyph_widths[code_point] > 0; } ALWAYS_INLINE int glyph_or_emoji_width(u32 code_point) const override {