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.
This commit is contained in:
thankyouverycool 2021-11-29 08:43:32 -05:00 committed by Andreas Kling
parent cdaa179eeb
commit edf86af4f4
Notes: sideshowbarker 2024-07-17 23:21:25 +09:00
3 changed files with 8 additions and 7 deletions

View File

@ -204,7 +204,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
}); });
m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "glyph/x-fonteditor"); m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "glyph/x-fonteditor");
m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { 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; return;
m_glyph_editor_widget->delete_glyph(); m_glyph_editor_widget->delete_glyph();
if (m_edited_font->is_fixed_width()) if (m_edited_font->is_fixed_width())
@ -252,7 +252,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
} else if (i < 0 && search_wrapped) { } else if (i < 0 && search_wrapped) {
break; 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_focus(true);
m_glyph_map_widget->set_selected_glyph(i); m_glyph_map_widget->set_selected_glyph(i);
m_glyph_map_widget->scroll_to_glyph(i); m_glyph_map_widget->scroll_to_glyph(i);
@ -270,7 +270,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
} else if (i > 0x10FFFF && search_wrapped) { } else if (i > 0x10FFFF && search_wrapped) {
break; 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_focus(true);
m_glyph_map_widget->set_selected_glyph(i); m_glyph_map_widget->set_selected_glyph(i);
m_glyph_map_widget->scroll_to_glyph(i); m_glyph_map_widget->scroll_to_glyph(i);
@ -501,7 +501,7 @@ void FontEditorWidget::initialize(const String& path, RefPtr<Gfx::BitmapFont>&&
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_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_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_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); 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()); 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()); builder.appendff(" [{}x{}]", m_edited_font->raw_glyph_width(glyph), m_edited_font->glyph_height());
m_statusbar->set_text(builder.to_string()); m_statusbar->set_text(builder.to_string());
} }

View File

@ -97,9 +97,9 @@ void GlyphMapWidget::paint_event(GUI::PaintEvent& event)
font().glyph_height()); font().glyph_height());
if (glyph == m_selected_glyph) { if (glyph == m_selected_glyph) {
painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection()); 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()); 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.fill_rect(outer_rect, palette().base());
painter.draw_glyph(inner_rect.location(), glyph, palette().base_text()); painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
} }

View File

@ -43,6 +43,7 @@ public:
Glyph glyph(u32 code_point) const override; Glyph glyph(u32 code_point) const override;
Glyph raw_glyph(u32 code_point) const; Glyph raw_glyph(u32 code_point) const;
bool contains_glyph(u32 code_point) const override; 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 ALWAYS_INLINE int glyph_or_emoji_width(u32 code_point) const override
{ {