summaryrefslogtreecommitdiff
path: root/Userland/Applications/FontEditor
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2021-09-23 20:07:34 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-24 14:59:39 +0200
commitfde48f1a7a210abf5288ef2f8234da6a3441e199 (patch)
treeb5f501d28801c20bd804ee8acbf217f06fa644a0 /Userland/Applications/FontEditor
parent91b3e9b7ae9b6f91de3834f85b1926516dd12460 (diff)
downloadserenity-fde48f1a7a210abf5288ef2f8234da6a3441e199.zip
FontEditor: Allow editing new font header
And make use of mapping functions moved from LibGUI/FontPickerWeightModel.h => LibGfx/FontStyleMapping.h
Diffstat (limited to 'Userland/Applications/FontEditor')
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp35
-rw-r--r--Userland/Applications/FontEditor/FontEditor.h2
-rw-r--r--Userland/Applications/FontEditor/FontEditorWindow.gml30
-rw-r--r--Userland/Applications/FontEditor/NewFontDialog.cpp14
-rw-r--r--Userland/Applications/FontEditor/NewFontDialog.h3
-rw-r--r--Userland/Applications/FontEditor/NewFontDialogPage1.gml19
6 files changed, 81 insertions, 22 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index f4c25e2da2..c730fd7925 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -20,9 +20,9 @@
#include <LibGUI/Clipboard.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/FilePicker.h>
-#include <LibGUI/FontPickerWeightModel.h>
#include <LibGUI/GroupBox.h>
#include <LibGUI/InputBox.h>
+#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
@@ -34,6 +34,7 @@
#include <LibGUI/ToolbarContainer.h>
#include <LibGUI/Window.h>
#include <LibGfx/BitmapFont.h>
+#include <LibGfx/FontStyleMapping.h>
#include <LibGfx/Palette.h>
#include <LibGfx/TextDirection.h>
#include <stdlib.h>
@@ -120,6 +121,7 @@ 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_slope_combobox = *find_descendant_of_type_named<GUI::ComboBox>("slope_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");
@@ -154,6 +156,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
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<Gfx::BitmapFont>&&
};
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<String>::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<String>::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<Gfx::BitmapFont>&&
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<String>::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 4915dce3d9..a79152adc5 100644
--- a/Userland/Applications/FontEditor/FontEditor.h
+++ b/Userland/Applications/FontEditor/FontEditor.h
@@ -80,6 +80,7 @@ private:
RefPtr<GUI::Widget> m_left_column_container;
RefPtr<GUI::Widget> m_glyph_editor_container;
RefPtr<GUI::ComboBox> m_weight_combobox;
+ RefPtr<GUI::ComboBox> m_slope_combobox;
RefPtr<GUI::SpinBox> m_spacing_spinbox;
RefPtr<GUI::SpinBox> m_baseline_spinbox;
RefPtr<GUI::SpinBox> m_mean_line_spinbox;
@@ -93,5 +94,6 @@ private:
String m_path;
Vector<String> m_font_weight_list;
+ Vector<String> m_font_slope_list;
bool m_font_metadata { true };
};
diff --git a/Userland/Applications/FontEditor/FontEditorWindow.gml b/Userland/Applications/FontEditor/FontEditorWindow.gml
index 0ccf0577d6..cdc4b4d5d2 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 f6024a3226..bc3a393610 100644
--- a/Userland/Applications/FontEditor/NewFontDialog.cpp
+++ b/Userland/Applications/FontEditor/NewFontDialog.cpp
@@ -11,7 +11,7 @@
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/ComboBox.h>
-#include <LibGUI/FontPickerWeightModel.h>
+#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
@@ -20,6 +20,7 @@
#include <LibGUI/Widget.h>
#include <LibGUI/Wizards/WizardDialog.h>
#include <LibGfx/BitmapFont.h>
+#include <LibGfx/FontStyleMapping.h>
#include <LibGfx/Palette.h>
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<GUI::TextBox>("name_textbox");
m_family_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("family_textbox");
m_weight_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::ComboBox>("weight_combobox");
+ m_slope_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::ComboBox>("slope_combobox");
m_presentation_spinbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("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<String>::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<String>::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 6245848ed4..2516ed6f4d 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<GUI::TextBox> m_name_textbox;
RefPtr<GUI::TextBox> m_family_textbox;
RefPtr<GUI::ComboBox> m_weight_combobox;
+ RefPtr<GUI::ComboBox> m_slope_combobox;
RefPtr<GUI::SpinBox> m_presentation_spinbox;
RefPtr<GUI::WizardPage> m_glyph_properties_page;
@@ -60,4 +62,5 @@ private:
Vector<String> m_font_list;
Vector<String> m_font_weight_list;
+ Vector<String> m_font_slope_list;
};
diff --git a/Userland/Applications/FontEditor/NewFontDialogPage1.gml b/Userland/Applications/FontEditor/NewFontDialogPage1.gml
index d70bc5a793..d08c7f3531 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 {
}
@@ -66,6 +66,23 @@
@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 {
+ }
+
+ @GUI::Label {
+ fixed_width: 100
+ text_alignment: "CenterLeft"
text: "Presentation size:"
}