diff options
-rw-r--r-- | Userland/Applications/FontEditor/FontEditor.cpp | 16 | ||||
-rw-r--r-- | Userland/Applications/FontEditor/FontEditor.h | 4 | ||||
-rw-r--r-- | Userland/Applications/FontEditor/GlyphMapWidget.cpp | 3 | ||||
-rw-r--r-- | Userland/Applications/FontEditor/main.cpp | 31 |
4 files changed, 20 insertions, 34 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index 534c1b68d4..60652d2524 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -106,7 +106,7 @@ static RefPtr<GUI::Window> create_font_preview_window(FontEditorWidget& editor) return window; } -FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&& edited_font) +FontEditorWidget::FontEditorWidget() { load_from_gml(font_editor_window_gml); @@ -475,8 +475,6 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&& GUI::Application::the()->on_action_leave = [this](GUI::Action&) { m_statusbar->set_override_text({}); }; - - initialize(path, move(edited_font)); } FontEditorWidget::~FontEditorWidget() @@ -619,22 +617,18 @@ void FontEditorWidget::set_show_font_metadata(bool show) m_font_metadata_groupbox->set_visible(m_font_metadata); } -void FontEditorWidget::open_file(String const& path) +bool FontEditorWidget::open_file(String const& path) { auto bitmap_font = Gfx::BitmapFont::load_from_file(path); if (!bitmap_font) { String message = String::formatted("Couldn't load font: {}\n", path); GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error); - return; - } - 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", path); - GUI::MessageBox::show(window(), message, "Font Editor", GUI::MessageBox::Type::Error); - return; + return false; } + auto new_font = bitmap_font->unmasked_character_set(); window()->set_modified(false); initialize(path, move(new_font)); + return true; } void FontEditorWidget::undo() diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h index 9a38b2154e..a4af6ac5b8 100644 --- a/Userland/Applications/FontEditor/FontEditor.h +++ b/Userland/Applications/FontEditor/FontEditor.h @@ -20,6 +20,7 @@ class FontEditorWidget final : public GUI::Widget { public: virtual ~FontEditorWidget() override; + bool open_file(String const&); bool save_as(const String&); bool request_close(); void update_title(); @@ -35,11 +36,10 @@ public: Function<void()> on_initialize; private: - FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&); + FontEditorWidget(); virtual void drop_event(GUI::DropEvent&) override; - void open_file(String const&); void undo(); void redo(); void did_modify_font(); diff --git a/Userland/Applications/FontEditor/GlyphMapWidget.cpp b/Userland/Applications/FontEditor/GlyphMapWidget.cpp index 73d0f3a1b8..a66b8c5a08 100644 --- a/Userland/Applications/FontEditor/GlyphMapWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphMapWidget.cpp @@ -31,6 +31,9 @@ void GlyphMapWidget::initialize(Gfx::BitmapFont& mutable_font) void GlyphMapWidget::resize_event(GUI::ResizeEvent& event) { + if (!m_font) + return; + int event_width = event.size().width() - this->vertical_scrollbar().width() - (frame_thickness() * 2) - m_horizontal_spacing; int event_height = event.size().height() - (frame_thickness() * 2); m_visible_glyphs = (event_width * event_height) / (font().max_glyph_width() * font().glyph_height()); diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp index 41dfae7798..8b197ead91 100644 --- a/Userland/Applications/FontEditor/main.cpp +++ b/Userland/Applications/FontEditor/main.cpp @@ -34,35 +34,24 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) args_parser.add_positional_argument(path, "The font file for editing.", "file", Core::ArgsParser::Required::No); args_parser.parse(arguments); - RefPtr<Gfx::BitmapFont> edited_font; - if (path == nullptr) { - auto bitmap_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone()); - edited_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set()); - } else { - auto bitmap_font = Gfx::BitmapFont::load_from_file(path); - if (!bitmap_font) { - String message = String::formatted("Couldn't load font: {}\n", path); - GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error); - return 1; - } - edited_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->unmasked_character_set()); - if (!edited_font) { - String message = String::formatted("Couldn't load font: {}\n", path); - GUI::MessageBox::show(nullptr, message, "Font Editor", GUI::MessageBox::Type::Error); - return 1; - } - } - auto app_icon = GUI::Icon::default_icon("app-font-editor"); auto window = TRY(GUI::Window::try_create()); window->set_icon(app_icon.bitmap_for_size(16)); window->resize(440, 470); - auto& font_editor = window->set_main_widget<FontEditorWidget>(path, move(edited_font)); - + auto& font_editor = window->set_main_widget<FontEditorWidget>(); font_editor.initialize_menubar(*window); + if (path) { + auto success = font_editor.open_file(path); + if (!success) + return 1; + } else { + auto mutable_font = static_ptr_cast<Gfx::BitmapFont>(Gfx::FontDatabase::default_font().clone())->unmasked_character_set(); + font_editor.initialize({}, move(mutable_font)); + } + window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { if (font_editor.request_close()) return GUI::Window::CloseRequestDecision::Close; |