From 95eeb321f90d326f93fe7ce2ceb0f71c03ab9ab6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Sep 2020 18:01:32 +0200 Subject: [PATCH] LibGfx+FontEditor+Base: Add "baseline" value to all fonts This does nothing at the moment but will soon allow us to improve the vertical positioning of text. --- Applications/FontEditor/FontEditor.cpp | 28 +++++++++++++++++++++++-- Base/res/fonts/CsillaBold7x10.font | Bin 15822 -> 15822 bytes Base/res/fonts/CsillaThin7x10.font | Bin 15822 -> 15822 bytes Base/res/fonts/Katica10.font | Bin 15822 -> 15822 bytes Base/res/fonts/KaticaBold10.font | Bin 15822 -> 15822 bytes Base/res/fonts/LizaBold18x24.font | Bin 24910 -> 37326 bytes Base/res/fonts/LizaBold26x36.font | Bin 37198 -> 55758 bytes Base/res/fonts/LizaBold8x10.font | Bin 10319 -> 15822 bytes Base/res/fonts/LizaRegular18x24.font | Bin 24910 -> 37326 bytes Base/res/fonts/LizaRegular26x36.font | Bin 37198 -> 55758 bytes Base/res/fonts/LizaRegular8x10.font | Bin 10319 -> 15822 bytes Base/res/fonts/LizaThin18x24.font | Bin 24910 -> 37326 bytes Base/res/fonts/LizaThin26x36.font | Bin 37198 -> 55758 bytes Base/res/fonts/LizaThin8x10.font | Bin 10319 -> 15822 bytes Base/res/fonts/Pebbleton14.font | Bin 14670 -> 21966 bytes Base/res/fonts/PebbletonBold14.font | Bin 14670 -> 21966 bytes Libraries/LibGfx/Font.cpp | 13 +++++++----- Libraries/LibGfx/Font.h | 6 +++++- 18 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp index 0d8e68340d..3b07b27084 100644 --- a/Applications/FontEditor/FontEditor.cpp +++ b/Applications/FontEditor/FontEditor.cpp @@ -121,7 +121,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite font_metadata_group_box.set_layout(); font_metadata_group_box.layout()->set_margins({ 5, 15, 5, 5 }); font_metadata_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - font_metadata_group_box.set_preferred_size(0, 145); + font_metadata_group_box.set_preferred_size(0, 165); font_metadata_group_box.set_title("Font metadata"); //// Name Row @@ -199,6 +199,25 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite glyph_header_width_spinbox.set_value(m_edited_font->glyph_fixed_width()); glyph_header_width_spinbox.set_enabled(false); + //// Baseline Row + auto& baseline_container = font_metadata_group_box.add(); + baseline_container.set_layout(); + baseline_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + baseline_container.set_preferred_size(0, 22); + + auto& baseline_label = baseline_container.add(); + baseline_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + baseline_label.set_preferred_size(100, 0); + baseline_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + baseline_label.set_text("Baseline:"); + + auto& baseline_spinbox = baseline_container.add(); + baseline_spinbox.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + baseline_spinbox.set_preferred_size(100, 0); + baseline_spinbox.set_min(0); + baseline_spinbox.set_max(m_edited_font->glyph_height() - 1); + baseline_spinbox.set_value(m_edited_font->baseline()); + //// Fixed checkbox Row auto& fixed_width_checkbox = font_metadata_group_box.add(); fixed_width_checkbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); @@ -240,7 +259,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite right_site_width = max(right_site_width, m_glyph_map_widget->preferred_width()); m_preferred_width = m_glyph_editor_widget->width() + right_site_width + 20; - m_preferred_height = m_glyph_map_widget->relative_rect().height() + 2 * m_edited_font->glyph_height() + 250; + m_preferred_height = m_glyph_map_widget->relative_rect().height() + 2 * m_edited_font->glyph_height() + 270; }; m_glyph_editor_widget->on_glyph_altered = [this, update_demo](u8 glyph) { @@ -283,6 +302,11 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite update_demo(); }; + baseline_spinbox.on_change = [this, update_demo](int value) { + m_edited_font->set_baseline(value); + update_demo(); + }; + // init widget calculate_prefed_sizes(); m_glyph_map_widget->set_selected_glyph('A'); diff --git a/Base/res/fonts/CsillaBold7x10.font b/Base/res/fonts/CsillaBold7x10.font index e7b1df67d16c316c6202e1624c194bcee3622d1b..1af5564228a1803609f5055b046cbf152629a1a6 100644 GIT binary patch delta 19 acmX?CeXg2I(Jilpor{ryfny`r5nBL4?ghL6 delta 19 acmX?CeXg2I(Jilpor{ryfng)p5nBL4#s#zh diff --git a/Base/res/fonts/CsillaThin7x10.font b/Base/res/fonts/CsillaThin7x10.font index 1f3582e741831f39591d1fb4cc51556b09b7efca..463c9397c46df0917aecf6adf41b47e47dc16335 100644 GIT binary patch delta 19 acmX?CeXg2I(Jilpor{ryfny`r5nBL4?ghL6 delta 19 acmX?CeXg2I(Jilpor{ryfng)p5nBL4#s#zh diff --git a/Base/res/fonts/Katica10.font b/Base/res/fonts/Katica10.font index 81f0311f859396b63295ec57348bd815416fdb8a..7655bbbc6fb4ff14c4b5e7bbecc96a32b92394ac 100644 GIT binary patch delta 19 acmX?CeXg2I(Jilpor{r?kz*s*5nBL4`vtxL delta 19 acmX?CeXg2I(Jilpor{r?kzpg(5nBL4(*?Ew diff --git a/Base/res/fonts/KaticaBold10.font b/Base/res/fonts/KaticaBold10.font index 85c6b54abbd25c5413ab6d3cc8a285a472ca87d1..089abeb7fbf56d0190d930edc31790eb5b89f8a1 100644 GIT binary patch delta 19 acmX?CeXg2I(Jilpor{r?kz*s*5nBL4`vtxL delta 19 acmX?CeXg2I(Jilpor{r?kzpg(5nBL4(*?Ew diff --git a/Base/res/fonts/LizaBold18x24.font b/Base/res/fonts/LizaBold18x24.font index 615d540ca9c84d91e837552e00d678c61129c921..e090c4d0c405d997a3491edb32fc71dc65d8eff6 100644 GIT binary patch delta 299 xcmX?ii1FNFCN4#{yb>V^Mg|7qja)8?8x7ic5IB#sUT9#!K-V^1_lO(ja)8?08Y3C;s5{u diff --git a/Base/res/fonts/LizaBold26x36.font b/Base/res/fonts/LizaBold26x36.font index 43a9da8a474600c018b9f51d575c4f66fa8d1669..057b1d013dd5219a287b9dd6f16c2966a9d96228 100644 GIT binary patch delta 299 xcmX@Ni0RyBW-djyyb>uDMg|7Cja)7hHyZ2~Lg4d!^-=>12HJimDXEEy4FHAcDKP*5 delta 21 ccmX@NnfcrzCN4#{yb>uD1_lO(ja)7h0Z!)z7ytkO diff --git a/Base/res/fonts/LizaBold8x10.font b/Base/res/fonts/LizaBold8x10.font index 3497562f4ef6430c5683b079f6ad47d58de3a980..9620a3e9de1a31da62fe2d85c78c27d989196492 100644 GIT binary patch delta 285 rcmX>faITt5(JilpgNu=Yfny_=i^gID5s`Y1fdvC?KNAPXM8yUGVweys delta 21 ccmX?CeLjFo(JilpgNuQIfng(;iv}YX07(i300000 diff --git a/Base/res/fonts/LizaRegular18x24.font b/Base/res/fonts/LizaRegular18x24.font index 39e20eb04c26ea6ab22631bbf3301051febf6614..d7920f449d34d7c110a1bdea107190cef355c592 100644 GIT binary patch delta 292 zcmX?ii1FNFCN4#{yb>V^Mg|7qja)8?n;+=c>uxk?WULn&STNA`GYJVzRBQkMzj__{ delta 21 ccmX@NnCaXhMlMCSyb>V^1_lO(ja)8?08Y3C;s5{u diff --git a/Base/res/fonts/LizaRegular26x36.font b/Base/res/fonts/LizaRegular26x36.font index 1669fb65123ba2cf7818e5ebe944718394e5502a..a8e57fb08643ce2fb7974e8a3a697fadf1e615f7 100644 GIT binary patch delta 299 xcmX@Ni0RyBW-djyyb>uDMg|7Cja)7hHyZ2~Lg4d!^-=>12HJimDXEEy4FHAcDKP*5 delta 21 ccmX@NnfcrzCN4#{yb>uD1_lO(ja)7h0Z!)z7ytkO diff --git a/Base/res/fonts/LizaRegular8x10.font b/Base/res/fonts/LizaRegular8x10.font index bf048aa07cdfbcc3e750384926160e9eb8851abe..8f993d13851ee5ec480927e813b7dc607991df33 100644 GIT binary patch delta 290 wcmX>faITt5(JilpgNu=Yfny_=i^gURkyk<+4a6AhIR+LCwEavR91|5A0DUqN6951J delta 21 ccmX?CeLjFo(JilpgNuQIfng(;iv}YX07(i300000 diff --git a/Base/res/fonts/LizaThin18x24.font b/Base/res/fonts/LizaThin18x24.font index 7b7af3caac781df41205fa7ac8855c218320e96d..2d17d71fd8253a670357c6790c0957919abf3387 100644 GIT binary patch delta 292 zcmX?ii1FNFCN4#{yb>V^Mg|7qja)8?n;+=c>uxk?WULn&STNA`GYJVzRBQkMzj__{ delta 21 ccmX@NnCaXhMlMCSyb>V^1_lO(ja)8?08Y3C;s5{u diff --git a/Base/res/fonts/LizaThin26x36.font b/Base/res/fonts/LizaThin26x36.font index ff661caa58ae8fb97f193e47fcb6160236f6226f..cbc9ba51fd3d0a01c329e5e997d4d2b1539ad4bd 100644 GIT binary patch delta 299 xcmX@Ni0RyBW-djyyb>uDMg|7Cja)7hHyZ2~Lg4d!^-=>12HJimDXEEy4FHAcDKP*5 delta 21 ccmX@NnfcrzCN4#{yb>uD1_lO(ja)7h0Z!)z7ytkO diff --git a/Base/res/fonts/LizaThin8x10.font b/Base/res/fonts/LizaThin8x10.font index 54cedd987a3b27bb6256ab30cc24c19dc07ee8de..5371128edd356294aa288bd13255996165627d84 100644 GIT binary patch delta 285 rcmX>faITt5(JilpgNu=Yfny_=i^gID5s`Y1fdvC?KNAPXM8yUGVweys delta 21 ccmX?CeLjFo(JilpgNuQIfng(;iv}YX07(i300000 diff --git a/Base/res/fonts/Pebbleton14.font b/Base/res/fonts/Pebbleton14.font index 55eb7afa077c2b2e1f708178cef9482d3cb232da..52769ee0305eea079c1c159d0da40666e4cd6224 100644 GIT binary patch delta 36 scmX?CbZ#{xm!ex<2@fA5BO}*FE*Fc<0y1?{8x5Km7yDT-PE>3F0LyagRf diff --git a/Base/res/fonts/PebbletonBold14.font b/Base/res/fonts/PebbletonBold14.font index 11c7a3bc2606bf2d28b9fa0c9c21d407390f8511..c4ab28f30fb19dd4bd43bfb11b1d7dbbed503199 100644 GIT binary patch delta 36 scmX?CbZ#{xm!ex<2@fA5BO}*FE*Fc<0y1?{8x5Km7yDT-PE>3F0LyagRf diff --git a/Libraries/LibGfx/Font.cpp b/Libraries/LibGfx/Font.cpp index 3b05960405..7837c01cdf 100644 --- a/Libraries/LibGfx/Font.cpp +++ b/Libraries/LibGfx/Font.cpp @@ -53,7 +53,8 @@ struct [[gnu::packed]] FontFileHeader u8 type; u8 is_variable_width; u8 glyph_spacing; - u8 unused[5]; + u8 baseline; + u8 unused[4]; char name[64]; }; @@ -112,7 +113,7 @@ NonnullRefPtr Font::clone() const memcpy(new_widths, m_glyph_widths, m_glyph_count); else memset(new_widths, m_glyph_width, m_glyph_count); - return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height, m_glyph_spacing, m_type)); + return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height, m_glyph_spacing, m_type, m_baseline)); } NonnullRefPtr Font::create(u8 glyph_height, u8 glyph_width, bool fixed, FontTypes type) @@ -124,10 +125,10 @@ NonnullRefPtr Font::create(u8 glyph_height, u8 glyph_width, bool fixed, Fo memset(new_rows, 0, bytes_per_glyph * count); auto* new_widths = static_cast(malloc(count)); memset(new_widths, glyph_width, count); - return adopt(*new Font("Untitled", new_rows, new_widths, fixed, glyph_width, glyph_height, 1, type)); + return adopt(*new Font("Untitled", new_rows, new_widths, fixed, glyph_width, glyph_height, 1, type, 0)); } -Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type) +Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type, u8 baseline) : m_name(name) , m_type(type) , m_rows(rows) @@ -137,6 +138,7 @@ Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_wid , m_min_glyph_width(glyph_width) , m_max_glyph_width(glyph_width) , m_glyph_spacing(glyph_spacing) + , m_baseline(baseline) , m_fixed_width(is_fixed_width) { // FIXME: This is just a dumb guess. It would be cool to know the actual x-height of the font! @@ -189,7 +191,7 @@ RefPtr Font::load_from_memory(const u8* data) u8* widths = nullptr; if (header.is_variable_width) widths = (u8*)(rows) + count * bytes_per_glyph; - return adopt(*new Font(String(header.name), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height, header.glyph_spacing, type)); + return adopt(*new Font(String(header.name), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height, header.glyph_spacing, type, header.baseline)); } size_t Font::glyph_count_by_type(FontTypes type) @@ -240,6 +242,7 @@ bool Font::write_to_file(const StringView& path) header.glyph_width = m_glyph_width; header.glyph_height = m_glyph_height; header.type = m_type; + header.baseline = m_baseline; header.is_variable_width = !m_fixed_width; header.glyph_spacing = m_glyph_spacing; memcpy(header.name, m_name.characters(), min(m_name.length(), (size_t)63)); diff --git a/Libraries/LibGfx/Font.h b/Libraries/LibGfx/Font.h index 830e038397..1d465668b2 100644 --- a/Libraries/LibGfx/Font.h +++ b/Libraries/LibGfx/Font.h @@ -100,6 +100,9 @@ public: u8 max_glyph_width() const { return m_max_glyph_width; } u8 glyph_fixed_width() const { return m_glyph_width; } + u8 baseline() const { return m_baseline; } + void set_baseline(u8 baseline) { m_baseline = baseline; } + int width(const StringView&) const; int width(const Utf8View&) const; int width(const Utf32View&) const; @@ -129,7 +132,7 @@ public: void set_type(FontTypes type); private: - Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type); + Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type, u8 baseline); static RefPtr load_from_memory(const u8*); static size_t glyph_count_by_type(FontTypes type); @@ -151,6 +154,7 @@ private: u8 m_min_glyph_width { 0 }; u8 m_max_glyph_width { 0 }; u8 m_glyph_spacing { 0 }; + u8 m_baseline { 0 }; bool m_fixed_width { false }; bool m_boldface { false };