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

FontEditor: Update editor to handle new font format

The editor now unmasks fonts on load, mapping their glyphs to the
complete unicode character set, and masks them upon saving to
reduce disk space. This is a naive approach in terms of memory
usage and can be improved but whose immediate goal is to allow
editing any glyph without concern for range allocation.
This commit is contained in:
thankyouverycool 2021-09-09 07:41:08 -04:00 committed by Andreas Kling
parent 9bcfdfc03b
commit a486415f03
10 changed files with 26 additions and 91 deletions

View file

@ -119,7 +119,6 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
m_family_textbox = *find_descendant_of_type_named<GUI::TextBox>("family_textbox");
m_presentation_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("presentation_spinbox");
m_weight_combobox = *find_descendant_of_type_named<GUI::ComboBox>("weight_combobox");
m_type_combobox = *find_descendant_of_type_named<GUI::ComboBox>("type_combobox");
m_spacing_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("spacing_spinbox");
m_mean_line_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("mean_line_spinbox");
m_baseline_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("baseline_spinbox");
@ -170,7 +169,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
if (new_font_wizard->exec() == GUI::Dialog::ExecOK) {
auto metadata = new_font_wizard->new_font_metadata();
RefPtr<Gfx::BitmapFont> new_font = Gfx::BitmapFont::create(metadata.glyph_height, metadata.glyph_width, metadata.is_fixed_width, metadata.type);
RefPtr<Gfx::BitmapFont> new_font = Gfx::BitmapFont::create(metadata.glyph_height, metadata.glyph_width, metadata.is_fixed_width, 0x110000);
if (!new_font) {
GUI::MessageBox::show(window(), "Failed to create new font.", "Font Editor", GUI::MessageBox::Type::Error);
return;
@ -208,7 +207,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error);
return;
}
RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->clone());
RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set());
if (!new_font) {
String message = String::formatted("Couldn't load font: {}\n", open_path.value());
GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error);
@ -396,12 +395,6 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
did_modify_font();
};
m_type_combobox->on_change = [this](auto&, const auto& index) {
m_edited_font->set_type(static_cast<Gfx::FontTypes>(index.row()));
m_glyph_map_widget->reprobe_font();
did_modify_font();
};
m_presentation_spinbox->on_change = [this, update_demo](int value) {
m_edited_font->set_presentation_size(value);
update_demo();
@ -487,16 +480,6 @@ void FontEditorWidget::initialize(const String& path, RefPtr<Gfx::BitmapFont>&&
i++;
}
m_font_type_list.clear();
StringBuilder type_count;
for (int i = 0; i < Gfx::FontTypes::__Count; i++) {
type_count.appendff("{}", Gfx::BitmapFont::type_name_by_type(static_cast<Gfx::FontTypes>(i)));
m_font_type_list.append(type_count.to_string());
type_count.clear();
}
m_type_combobox->set_model(*GUI::ItemListModel<String>::create(m_font_type_list));
m_type_combobox->set_selected_index(m_edited_font->type());
m_fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width());
m_glyph_map_widget->set_selected_glyph('A');
@ -562,7 +545,8 @@ void FontEditorWidget::initialize_menubar(GUI::Window& window)
bool FontEditorWidget::save_as(const String& path)
{
auto ret_val = m_edited_font->write_to_file(path);
auto saved_font = m_edited_font->masked_character_set();
auto ret_val = saved_font->write_to_file(path);
if (!ret_val) {
GUI::MessageBox::show(window(), "The font file could not be saved.", "Save failed", GUI::MessageBox::Type::Error);
return false;