From fde48f1a7a210abf5288ef2f8234da6a3441e199 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Thu, 23 Sep 2021 20:07:34 -0400 Subject: [PATCH] FontEditor: Allow editing new font header And make use of mapping functions moved from LibGUI/FontPickerWeightModel.h => LibGfx/FontStyleMapping.h --- .../Applications/FontEditor/FontEditor.cpp | 35 ++++++++++++++----- Userland/Applications/FontEditor/FontEditor.h | 2 ++ .../FontEditor/FontEditorWindow.gml | 30 +++++++++++----- .../Applications/FontEditor/NewFontDialog.cpp | 14 ++++++-- .../Applications/FontEditor/NewFontDialog.h | 3 ++ .../FontEditor/NewFontDialogPage1.gml | 19 +++++++++- 6 files changed, 81 insertions(+), 22 deletions(-) diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index f4c25e2da26..c730fd7925e 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -20,9 +20,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -120,6 +121,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& m_family_textbox = *find_descendant_of_type_named("family_textbox"); m_presentation_spinbox = *find_descendant_of_type_named("presentation_spinbox"); m_weight_combobox = *find_descendant_of_type_named("weight_combobox"); + m_slope_combobox = *find_descendant_of_type_named("slope_combobox"); m_spacing_spinbox = *find_descendant_of_type_named("spacing_spinbox"); m_mean_line_spinbox = *find_descendant_of_type_named("mean_line_spinbox"); m_baseline_spinbox = *find_descendant_of_type_named("baseline_spinbox"); @@ -154,6 +156,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& new_font->set_family(metadata.family); new_font->set_presentation_size(metadata.presentation_size); new_font->set_weight(metadata.weight); + new_font->set_slope(metadata.slope); new_font->set_baseline(metadata.baseline); new_font->set_mean_line(metadata.mean_line); window()->set_modified(true); @@ -415,9 +418,20 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& }; m_weight_combobox->on_change = [this](auto&, auto&) { - m_edited_font->set_weight(GUI::name_to_weight(m_weight_combobox->text())); + m_edited_font->set_weight(Gfx::name_to_weight(m_weight_combobox->text())); did_modify_font(); }; + for (auto& it : Gfx::font_weight_names) + m_font_weight_list.append(it.name); + m_weight_combobox->set_model(*GUI::ItemListModel::create(m_font_weight_list)); + + m_slope_combobox->on_change = [this](auto&, auto&) { + m_edited_font->set_slope(Gfx::name_to_slope(m_slope_combobox->text())); + did_modify_font(); + }; + for (auto& it : Gfx::font_slope_names) + m_font_slope_list.append(it.name); + m_slope_combobox->set_model(*GUI::ItemListModel::create(m_font_slope_list)); m_presentation_spinbox->on_change = [this](int value) { m_edited_font->set_presentation_size(value); @@ -495,19 +509,22 @@ void FontEditorWidget::initialize(const String& path, RefPtr&& m_mean_line_spinbox->set_value(m_edited_font->mean_line(), GUI::AllowCallback::No); m_baseline_spinbox->set_value(m_edited_font->baseline(), GUI::AllowCallback::No); - m_font_weight_list.clear(); - for (auto& it : GUI::font_weight_names) - m_font_weight_list.append(it.name); - m_weight_combobox->set_model(*GUI::ItemListModel::create(m_font_weight_list)); - int i = 0; - for (auto it : GUI::font_weight_names) { - if (it.weight == m_edited_font->weight()) { + for (auto& it : Gfx::font_weight_names) { + if (it.style == m_edited_font->weight()) { m_weight_combobox->set_selected_index(i); break; } i++; } + i = 0; + for (auto& it : Gfx::font_slope_names) { + if (it.style == m_edited_font->slope()) { + m_slope_combobox->set_selected_index(i); + break; + } + i++; + } deferred_invoke([this] { m_glyph_map_widget->set_focus(true); diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h index 4915dce3d9d..a79152adc5f 100644 --- a/Userland/Applications/FontEditor/FontEditor.h +++ b/Userland/Applications/FontEditor/FontEditor.h @@ -80,6 +80,7 @@ private: RefPtr m_left_column_container; RefPtr m_glyph_editor_container; RefPtr m_weight_combobox; + RefPtr m_slope_combobox; RefPtr m_spacing_spinbox; RefPtr m_baseline_spinbox; RefPtr m_mean_line_spinbox; @@ -93,5 +94,6 @@ private: String m_path; Vector m_font_weight_list; + Vector m_font_slope_list; bool m_font_metadata { true }; }; diff --git a/Userland/Applications/FontEditor/FontEditorWindow.gml b/Userland/Applications/FontEditor/FontEditorWindow.gml index 0ccf0577d63..cdc4b4d5d2f 100644 --- a/Userland/Applications/FontEditor/FontEditorWindow.gml +++ b/Userland/Applications/FontEditor/FontEditorWindow.gml @@ -132,16 +132,15 @@ } @GUI::Label { - name: "presentation_label" + name: "slope_label" fixed_width: 100 text_alignment: "CenterLeft" - text: "Presentation size:" + text: "Slope:" } - @GUI::SpinBox { - name: "presentation_spinbox" - min: 0 - max: 255 + @GUI::ComboBox { + name: "slope_combobox" + model_only: true } } @@ -150,14 +149,14 @@ } @GUI::Label { - name: "spacing_label" + name: "presentation_label" fixed_width: 100 text_alignment: "CenterLeft" - text: "Glyph spacing:" + text: "Presentation size:" } @GUI::SpinBox { - name: "spacing_spinbox" + name: "presentation_spinbox" min: 0 max: 255 } @@ -202,6 +201,19 @@ layout: @GUI::HorizontalBoxLayout { } + @GUI::Label { + name: "spacing_label" + fixed_width: 100 + text_alignment: "CenterLeft" + text: "Glyph spacing:" + } + + @GUI::SpinBox { + name: "spacing_spinbox" + min: 0 + max: 255 + } + @GUI::CheckBox { name: "fixed_width_checkbox" text: "Fixed width" diff --git a/Userland/Applications/FontEditor/NewFontDialog.cpp b/Userland/Applications/FontEditor/NewFontDialog.cpp index f6024a3226e..bc3a3936107 100644 --- a/Userland/Applications/FontEditor/NewFontDialog.cpp +++ b/Userland/Applications/FontEditor/NewFontDialog.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -20,6 +20,7 @@ #include #include #include +#include #include static constexpr int s_max_width = 32; @@ -135,13 +136,19 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window) m_name_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named("name_textbox"); m_family_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named("family_textbox"); m_weight_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named("weight_combobox"); + m_slope_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named("slope_combobox"); m_presentation_spinbox = m_font_properties_page->body_widget().find_descendant_of_type_named("presentation_spinbox"); - for (auto& it : GUI::font_weight_names) + for (auto& it : Gfx::font_weight_names) m_font_weight_list.append(it.name); m_weight_combobox->set_model(*GUI::ItemListModel::create(m_font_weight_list)); m_weight_combobox->set_selected_index(3); + for (auto& it : Gfx::font_slope_names) + m_font_slope_list.append(it.name); + m_slope_combobox->set_model(*GUI::ItemListModel::create(m_font_slope_list)); + m_slope_combobox->set_selected_index(0); + m_presentation_spinbox->set_value(12); m_font_properties_page->on_page_enter = [&]() { @@ -208,7 +215,8 @@ void NewFontDialog::save_metadata() { m_new_font_metadata.name = m_name_textbox->text(); m_new_font_metadata.family = m_family_textbox->text(); - m_new_font_metadata.weight = GUI::name_to_weight(m_weight_combobox->text()); + m_new_font_metadata.weight = Gfx::name_to_weight(m_weight_combobox->text()); + m_new_font_metadata.slope = Gfx::name_to_slope(m_slope_combobox->text()); m_new_font_metadata.presentation_size = m_presentation_spinbox->value(); m_new_font_metadata.baseline = m_baseline_spinbox->value(); diff --git a/Userland/Applications/FontEditor/NewFontDialog.h b/Userland/Applications/FontEditor/NewFontDialog.h index 6245848ed48..2516ed6f4d0 100644 --- a/Userland/Applications/FontEditor/NewFontDialog.h +++ b/Userland/Applications/FontEditor/NewFontDialog.h @@ -34,6 +34,7 @@ private: u8 mean_line; u8 presentation_size; u16 weight; + u8 slope; String name; String family; bool is_fixed_width; @@ -47,6 +48,7 @@ private: RefPtr m_name_textbox; RefPtr m_family_textbox; RefPtr m_weight_combobox; + RefPtr m_slope_combobox; RefPtr m_presentation_spinbox; RefPtr m_glyph_properties_page; @@ -60,4 +62,5 @@ private: Vector m_font_list; Vector m_font_weight_list; + Vector m_font_slope_list; }; diff --git a/Userland/Applications/FontEditor/NewFontDialogPage1.gml b/Userland/Applications/FontEditor/NewFontDialogPage1.gml index d70bc5a7936..d08c7f3531b 100644 --- a/Userland/Applications/FontEditor/NewFontDialogPage1.gml +++ b/Userland/Applications/FontEditor/NewFontDialogPage1.gml @@ -4,7 +4,7 @@ } @GUI::Widget { - fixed_height: 138 + fixed_height: 160 layout: @GUI::VerticalBoxLayout { } @@ -59,6 +59,23 @@ } } + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + } + + @GUI::Label { + fixed_width: 100 + text_alignment: "CenterLeft" + text: "Slope:" + } + + @GUI::ComboBox { + name: "slope_combobox" + fixed_width: 180 + model_only: true + } + } + @GUI::Widget { layout: @GUI::HorizontalBoxLayout { }