diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-06 12:52:41 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-06 12:52:41 +0100 |
commit | 7f6c81d90f0b1ccb217bd283dfb59727fbb0045d (patch) | |
tree | 75ab6a542e01c5abd230b6c71924f2af23aec06d /Applications/FontEditor | |
parent | 0a86366c71e852b93dda40942ef468f9e5f9b48d (diff) | |
download | serenity-7f6c81d90f0b1ccb217bd283dfb59727fbb0045d.zip |
Implement basic support for variable-width fonts.
Also add a nice new font called Katica. It's not used anywhere yet but
I'm definitely itching to start using it. :^)
Diffstat (limited to 'Applications/FontEditor')
-rw-r--r-- | Applications/FontEditor/FontEditor.cpp | 60 | ||||
-rw-r--r-- | Applications/FontEditor/FontEditor.h | 1 | ||||
-rw-r--r-- | Applications/FontEditor/main.cpp | 3 |
3 files changed, 53 insertions, 11 deletions
diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp index e1793ce60a..243cb7bde5 100644 --- a/Applications/FontEditor/FontEditor.cpp +++ b/Applications/FontEditor/FontEditor.cpp @@ -3,13 +3,14 @@ #include <LibGUI/GButton.h> #include <LibGUI/GLabel.h> #include <LibGUI/GTextBox.h> +#include <LibGUI/GCheckBox.h> FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_font, GWidget* parent) : GWidget(parent) , m_edited_font(move(edited_font)) { if (path.is_empty()) - m_path = "/saved.font"; + m_path = "/tmp/saved.font"; else m_path = path; @@ -19,16 +20,28 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_ m_glyph_editor_widget = new GlyphEditorWidget(*m_edited_font, this); m_glyph_editor_widget->move_to({ 5, 5 }); + auto* fixed_width_checkbox = new GCheckBox(this); + fixed_width_checkbox->set_caption("Fixed width"); + fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width()); + fixed_width_checkbox->set_relative_rect({ 5, 195, 100, 20 }); + m_name_textbox = new GTextBox(this); - m_name_textbox->set_relative_rect({ 5, 135, 100, 20 }); + m_name_textbox->set_relative_rect({ 5, 220, 300, 20 }); m_name_textbox->set_text(m_edited_font->name()); m_name_textbox->on_change = [this] (GTextBox&) { m_edited_font->set_name(m_name_textbox->text()); }; + m_path_textbox = new GTextBox(this); + m_path_textbox->set_relative_rect({ 5, 245, 300, 20 }); + m_path_textbox->set_text(m_path); + m_path_textbox->on_change = [this] (GTextBox&) { + m_path = m_path_textbox->text(); + }; + auto* save_button = new GButton(this); save_button->set_caption("Save"); - save_button->set_relative_rect({ 5, 170, 100, 20 }); + save_button->set_relative_rect({ 5, 270, 100, 20 }); save_button->on_click = [this] (GButton&) { dbgprintf("write to file: '%s'\n", m_path.characters()); m_edited_font->write_to_file(m_path); @@ -36,7 +49,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_ auto* quit_button = new GButton(this); quit_button->set_caption("Quit"); - quit_button->set_relative_rect({ 110, 170, 100, 20 }); + quit_button->set_relative_rect({ 110, 270, 100, 20 }); quit_button->on_click = [] (GButton&) { exit(0); }; @@ -45,6 +58,9 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_ info_label->set_text_alignment(TextAlignment::CenterLeft); info_label->set_relative_rect({ 5, 110, 100, 20 }); + auto* width_textbox = new GTextBox(this); + width_textbox->set_relative_rect({ 5, 135, 100, 20 }); + auto* demo_label_1 = new GLabel(this); demo_label_1->set_font(m_edited_font.copy_ref()); demo_label_1->set_text("quick fox jumps nightly above wizard."); @@ -55,17 +71,39 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_ demo_label_2->set_text("QUICK FOX JUMPS NIGHTLY ABOVE WIZARD!"); demo_label_2->set_relative_rect({ 110, 140, 300, 20 }); - m_glyph_editor_widget->on_glyph_altered = [this, demo_label_1, demo_label_2] { - m_glyph_map_widget->update(); + auto update_demo = [demo_label_1, demo_label_2] { demo_label_1->update(); demo_label_2->update(); }; - m_glyph_map_widget->on_glyph_selected = [this, info_label] (byte glyph) { + m_glyph_editor_widget->on_glyph_altered = [this, update_demo] { + m_glyph_map_widget->update(); + update_demo(); + }; + + m_glyph_map_widget->on_glyph_selected = [this, info_label, width_textbox] (byte glyph) { m_glyph_editor_widget->set_glyph(glyph); + width_textbox->set_text(String::format("%u", m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()))); info_label->set_text(String::format("0x%b (%c)", glyph, glyph)); }; + fixed_width_checkbox->on_change = [this, width_textbox, update_demo] (GCheckBox&, bool is_checked) { + m_edited_font->set_fixed_width(is_checked); + width_textbox->set_text(String::format("%u", m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()))); + m_glyph_editor_widget->update(); + update_demo(); + }; + + width_textbox->on_change = [this, update_demo] (GTextBox& textbox) { + bool ok; + unsigned width = textbox.text().to_uint(ok); + if (ok) { + m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), width); + m_glyph_editor_widget->update(); + update_demo(); + } + }; + m_glyph_map_widget->set_selected_glyph('A'); } @@ -196,8 +234,12 @@ void GlyphEditorWidget::paint_event(GPaintEvent&) for (int y = 0; y < font().glyph_height(); ++y) { for (int x = 0; x < font().max_glyph_width(); ++x) { Rect rect { x * m_scale, y * m_scale, m_scale, m_scale }; - if (bitmap.bit_at(x, y)) - painter.fill_rect(rect, Color::Black); + if (x >= font().glyph_width(m_glyph)) { + painter.fill_rect(rect, Color::MidGray); + } else { + if (bitmap.bit_at(x, y)) + painter.fill_rect(rect, Color::Black); + } } } diff --git a/Applications/FontEditor/FontEditor.h b/Applications/FontEditor/FontEditor.h index d44c7e698c..c53d8bb087 100644 --- a/Applications/FontEditor/FontEditor.h +++ b/Applications/FontEditor/FontEditor.h @@ -18,6 +18,7 @@ private: GlyphMapWidget* m_glyph_map_widget { nullptr }; GlyphEditorWidget* m_glyph_editor_widget { nullptr }; GTextBox* m_name_textbox { nullptr }; + GTextBox* m_path_textbox { nullptr }; String m_path; }; diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index d9bb835cca..bf0511e6da 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -26,9 +26,8 @@ int main(int argc, char** argv) auto* window = new GWindow; window->set_title("FontEditor"); - window->set_rect({ 50, 50, 420, 200 }); + window->set_rect({ 50, 50, 420, 300 }); auto* font_editor = new FontEditorWidget(path, move(edited_font)); - font_editor->set_relative_rect({ 0, 0, 420, 200 }); window->set_main_widget(font_editor); window->set_should_exit_app_on_close(true); window->show(); |