mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 19:19:44 +03: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
Notes:
sideshowbarker
2024-07-18 03:29:48 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/fde48f1a7a2 Pull-request: https://github.com/SerenityOS/serenity/pull/10193 Issue: https://github.com/SerenityOS/serenity/issues/9384 Reviewed-by: https://github.com/alimpfard
@ -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);
|
||||
|
@ -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 };
|
||||
};
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user