From edc35807562967899e84d531886c42589efc8488 Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Mon, 30 Dec 2019 11:36:55 +0100 Subject: [PATCH] LibDraw: Store glyph spacing information in the fonts headers --- Libraries/LibDraw/Font.cpp | 11 +++++++---- Libraries/LibDraw/Font.h | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Libraries/LibDraw/Font.cpp b/Libraries/LibDraw/Font.cpp index 561f78ca1d..b250d5fb65 100644 --- a/Libraries/LibDraw/Font.cpp +++ b/Libraries/LibDraw/Font.cpp @@ -19,7 +19,8 @@ struct [[gnu::packed]] FontFileHeader u8 glyph_height; u8 type; u8 is_variable_width; - u8 unused[6]; + u8 glyph_spacing; + u8 unused[5]; char name[64]; }; @@ -78,10 +79,10 @@ RefPtr Font::clone() const memcpy(new_widths, m_glyph_widths, 256); else memset(new_widths, m_glyph_width, 256); - return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height)); + return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height, m_glyph_spacing)); } -Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height) +Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing) : m_name(name) , m_rows(rows) , m_glyph_widths(widths) @@ -89,6 +90,7 @@ Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_wid , m_glyph_height(glyph_height) , m_min_glyph_width(glyph_width) , m_max_glyph_width(glyph_width) + , m_glyph_spacing(glyph_spacing) , m_fixed_width(is_fixed_width) { if (!m_fixed_width) { @@ -125,7 +127,7 @@ RefPtr Font::load_from_memory(const u8* data) u8* widths = nullptr; if (header.is_variable_width) widths = (u8*)(rows) + 256 * bytes_per_glyph; - return adopt(*new Font(String(header.name), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height)); + return adopt(*new Font(String(header.name), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height, header.glyph_spacing)); } RefPtr Font::load_from_file(const StringView& path) @@ -154,6 +156,7 @@ bool Font::write_to_file(const StringView& path) header.glyph_height = m_glyph_height; header.type = 0; 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)); size_t bytes_per_glyph = sizeof(unsigned) * m_glyph_height; diff --git a/Libraries/LibDraw/Font.h b/Libraries/LibDraw/Font.h index 3e3a754e0e..c3719b45bc 100644 --- a/Libraries/LibDraw/Font.h +++ b/Libraries/LibDraw/Font.h @@ -63,7 +63,6 @@ public: u8 glyph_height() const { return m_glyph_height; } u8 min_glyph_width() const { return m_min_glyph_width; } u8 max_glyph_width() const { return m_max_glyph_width; } - u8 glyph_spacing() const { return m_fixed_width ? 0 : 1; } int width(const StringView&) const; int width(const Utf8View&) const; @@ -73,6 +72,9 @@ public: bool is_fixed_width() const { return m_fixed_width; } void set_fixed_width(bool b) { m_fixed_width = b; } + u8 glyph_spacing() const { return m_glyph_spacing; } + void set_glyph_spacing(u8 spacing) { m_glyph_spacing = spacing; } + void set_glyph_width(char ch, u8 width) { ASSERT(m_glyph_widths); @@ -80,7 +82,7 @@ public: } private: - Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height); + Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing); static RefPtr load_from_memory(const u8*); @@ -94,6 +96,7 @@ private: u8 m_glyph_height { 0 }; u8 m_min_glyph_width { 0 }; u8 m_max_glyph_width { 0 }; + u8 m_glyph_spacing { 0 }; bool m_fixed_width { false }; };