mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
FontEditor: Allow editing new font header
And make use of mapping functions moved from LibGUI/FontPickerWeightModel.h => LibGfx/FontStyleMapping.h
This commit is contained in:
parent
91b3e9b7ae
commit
fde48f1a7a
6 changed files with 81 additions and 22 deletions
|
@ -20,9 +20,9 @@
|
||||||
#include <LibGUI/Clipboard.h>
|
#include <LibGUI/Clipboard.h>
|
||||||
#include <LibGUI/ComboBox.h>
|
#include <LibGUI/ComboBox.h>
|
||||||
#include <LibGUI/FilePicker.h>
|
#include <LibGUI/FilePicker.h>
|
||||||
#include <LibGUI/FontPickerWeightModel.h>
|
|
||||||
#include <LibGUI/GroupBox.h>
|
#include <LibGUI/GroupBox.h>
|
||||||
#include <LibGUI/InputBox.h>
|
#include <LibGUI/InputBox.h>
|
||||||
|
#include <LibGUI/ItemListModel.h>
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Menubar.h>
|
#include <LibGUI/Menubar.h>
|
||||||
|
@ -34,6 +34,7 @@
|
||||||
#include <LibGUI/ToolbarContainer.h>
|
#include <LibGUI/ToolbarContainer.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/BitmapFont.h>
|
#include <LibGfx/BitmapFont.h>
|
||||||
|
#include <LibGfx/FontStyleMapping.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <LibGfx/TextDirection.h>
|
#include <LibGfx/TextDirection.h>
|
||||||
#include <stdlib.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_family_textbox = *find_descendant_of_type_named<GUI::TextBox>("family_textbox");
|
||||||
m_presentation_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("presentation_spinbox");
|
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_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_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_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");
|
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_family(metadata.family);
|
||||||
new_font->set_presentation_size(metadata.presentation_size);
|
new_font->set_presentation_size(metadata.presentation_size);
|
||||||
new_font->set_weight(metadata.weight);
|
new_font->set_weight(metadata.weight);
|
||||||
|
new_font->set_slope(metadata.slope);
|
||||||
new_font->set_baseline(metadata.baseline);
|
new_font->set_baseline(metadata.baseline);
|
||||||
new_font->set_mean_line(metadata.mean_line);
|
new_font->set_mean_line(metadata.mean_line);
|
||||||
window()->set_modified(true);
|
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_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();
|
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_presentation_spinbox->on_change = [this](int value) {
|
||||||
m_edited_font->set_presentation_size(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_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_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;
|
int i = 0;
|
||||||
for (auto it : GUI::font_weight_names) {
|
for (auto& it : Gfx::font_weight_names) {
|
||||||
if (it.weight == m_edited_font->weight()) {
|
if (it.style == m_edited_font->weight()) {
|
||||||
m_weight_combobox->set_selected_index(i);
|
m_weight_combobox->set_selected_index(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
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] {
|
deferred_invoke([this] {
|
||||||
m_glyph_map_widget->set_focus(true);
|
m_glyph_map_widget->set_focus(true);
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
RefPtr<GUI::Widget> m_left_column_container;
|
RefPtr<GUI::Widget> m_left_column_container;
|
||||||
RefPtr<GUI::Widget> m_glyph_editor_container;
|
RefPtr<GUI::Widget> m_glyph_editor_container;
|
||||||
RefPtr<GUI::ComboBox> m_weight_combobox;
|
RefPtr<GUI::ComboBox> m_weight_combobox;
|
||||||
|
RefPtr<GUI::ComboBox> m_slope_combobox;
|
||||||
RefPtr<GUI::SpinBox> m_spacing_spinbox;
|
RefPtr<GUI::SpinBox> m_spacing_spinbox;
|
||||||
RefPtr<GUI::SpinBox> m_baseline_spinbox;
|
RefPtr<GUI::SpinBox> m_baseline_spinbox;
|
||||||
RefPtr<GUI::SpinBox> m_mean_line_spinbox;
|
RefPtr<GUI::SpinBox> m_mean_line_spinbox;
|
||||||
|
@ -93,5 +94,6 @@ private:
|
||||||
|
|
||||||
String m_path;
|
String m_path;
|
||||||
Vector<String> m_font_weight_list;
|
Vector<String> m_font_weight_list;
|
||||||
|
Vector<String> m_font_slope_list;
|
||||||
bool m_font_metadata { true };
|
bool m_font_metadata { true };
|
||||||
};
|
};
|
||||||
|
|
|
@ -132,16 +132,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::Label {
|
@GUI::Label {
|
||||||
name: "presentation_label"
|
name: "slope_label"
|
||||||
fixed_width: 100
|
fixed_width: 100
|
||||||
text_alignment: "CenterLeft"
|
text_alignment: "CenterLeft"
|
||||||
text: "Presentation size:"
|
text: "Slope:"
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::SpinBox {
|
@GUI::ComboBox {
|
||||||
name: "presentation_spinbox"
|
name: "slope_combobox"
|
||||||
min: 0
|
model_only: true
|
||||||
max: 255
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,14 +149,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::Label {
|
@GUI::Label {
|
||||||
name: "spacing_label"
|
name: "presentation_label"
|
||||||
fixed_width: 100
|
fixed_width: 100
|
||||||
text_alignment: "CenterLeft"
|
text_alignment: "CenterLeft"
|
||||||
text: "Glyph spacing:"
|
text: "Presentation size:"
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::SpinBox {
|
@GUI::SpinBox {
|
||||||
name: "spacing_spinbox"
|
name: "presentation_spinbox"
|
||||||
min: 0
|
min: 0
|
||||||
max: 255
|
max: 255
|
||||||
}
|
}
|
||||||
|
@ -202,6 +201,19 @@
|
||||||
layout: @GUI::HorizontalBoxLayout {
|
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 {
|
@GUI::CheckBox {
|
||||||
name: "fixed_width_checkbox"
|
name: "fixed_width_checkbox"
|
||||||
text: "Fixed width"
|
text: "Fixed width"
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/CheckBox.h>
|
#include <LibGUI/CheckBox.h>
|
||||||
#include <LibGUI/ComboBox.h>
|
#include <LibGUI/ComboBox.h>
|
||||||
#include <LibGUI/FontPickerWeightModel.h>
|
#include <LibGUI/ItemListModel.h>
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/MessageBox.h>
|
#include <LibGUI/MessageBox.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <LibGUI/Wizards/WizardDialog.h>
|
#include <LibGUI/Wizards/WizardDialog.h>
|
||||||
#include <LibGfx/BitmapFont.h>
|
#include <LibGfx/BitmapFont.h>
|
||||||
|
#include <LibGfx/FontStyleMapping.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
static constexpr int s_max_width = 32;
|
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_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_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_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");
|
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_font_weight_list.append(it.name);
|
||||||
m_weight_combobox->set_model(*GUI::ItemListModel<String>::create(m_font_weight_list));
|
m_weight_combobox->set_model(*GUI::ItemListModel<String>::create(m_font_weight_list));
|
||||||
m_weight_combobox->set_selected_index(3);
|
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_presentation_spinbox->set_value(12);
|
||||||
|
|
||||||
m_font_properties_page->on_page_enter = [&]() {
|
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.name = m_name_textbox->text();
|
||||||
m_new_font_metadata.family = m_family_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.presentation_size = m_presentation_spinbox->value();
|
||||||
|
|
||||||
m_new_font_metadata.baseline = m_baseline_spinbox->value();
|
m_new_font_metadata.baseline = m_baseline_spinbox->value();
|
||||||
|
|
|
@ -34,6 +34,7 @@ private:
|
||||||
u8 mean_line;
|
u8 mean_line;
|
||||||
u8 presentation_size;
|
u8 presentation_size;
|
||||||
u16 weight;
|
u16 weight;
|
||||||
|
u8 slope;
|
||||||
String name;
|
String name;
|
||||||
String family;
|
String family;
|
||||||
bool is_fixed_width;
|
bool is_fixed_width;
|
||||||
|
@ -47,6 +48,7 @@ private:
|
||||||
RefPtr<GUI::TextBox> m_name_textbox;
|
RefPtr<GUI::TextBox> m_name_textbox;
|
||||||
RefPtr<GUI::TextBox> m_family_textbox;
|
RefPtr<GUI::TextBox> m_family_textbox;
|
||||||
RefPtr<GUI::ComboBox> m_weight_combobox;
|
RefPtr<GUI::ComboBox> m_weight_combobox;
|
||||||
|
RefPtr<GUI::ComboBox> m_slope_combobox;
|
||||||
RefPtr<GUI::SpinBox> m_presentation_spinbox;
|
RefPtr<GUI::SpinBox> m_presentation_spinbox;
|
||||||
|
|
||||||
RefPtr<GUI::WizardPage> m_glyph_properties_page;
|
RefPtr<GUI::WizardPage> m_glyph_properties_page;
|
||||||
|
@ -60,4 +62,5 @@ private:
|
||||||
|
|
||||||
Vector<String> m_font_list;
|
Vector<String> m_font_list;
|
||||||
Vector<String> m_font_weight_list;
|
Vector<String> m_font_weight_list;
|
||||||
|
Vector<String> m_font_slope_list;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::Widget {
|
@GUI::Widget {
|
||||||
fixed_height: 138
|
fixed_height: 160
|
||||||
layout: @GUI::VerticalBoxLayout {
|
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 {
|
@GUI::Widget {
|
||||||
layout: @GUI::HorizontalBoxLayout {
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue