mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
LibDraw: Store glyph spacing information in the fonts headers
This commit is contained in:
parent
edba444aa9
commit
edc3580756
2 changed files with 12 additions and 6 deletions
|
@ -19,7 +19,8 @@ struct [[gnu::packed]] FontFileHeader
|
||||||
u8 glyph_height;
|
u8 glyph_height;
|
||||||
u8 type;
|
u8 type;
|
||||||
u8 is_variable_width;
|
u8 is_variable_width;
|
||||||
u8 unused[6];
|
u8 glyph_spacing;
|
||||||
|
u8 unused[5];
|
||||||
char name[64];
|
char name[64];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,10 +79,10 @@ RefPtr<Font> Font::clone() const
|
||||||
memcpy(new_widths, m_glyph_widths, 256);
|
memcpy(new_widths, m_glyph_widths, 256);
|
||||||
else
|
else
|
||||||
memset(new_widths, m_glyph_width, 256);
|
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_name(name)
|
||||||
, m_rows(rows)
|
, m_rows(rows)
|
||||||
, m_glyph_widths(widths)
|
, 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_glyph_height(glyph_height)
|
||||||
, m_min_glyph_width(glyph_width)
|
, m_min_glyph_width(glyph_width)
|
||||||
, m_max_glyph_width(glyph_width)
|
, m_max_glyph_width(glyph_width)
|
||||||
|
, m_glyph_spacing(glyph_spacing)
|
||||||
, m_fixed_width(is_fixed_width)
|
, m_fixed_width(is_fixed_width)
|
||||||
{
|
{
|
||||||
if (!m_fixed_width) {
|
if (!m_fixed_width) {
|
||||||
|
@ -125,7 +127,7 @@ RefPtr<Font> Font::load_from_memory(const u8* data)
|
||||||
u8* widths = nullptr;
|
u8* widths = nullptr;
|
||||||
if (header.is_variable_width)
|
if (header.is_variable_width)
|
||||||
widths = (u8*)(rows) + 256 * bytes_per_glyph;
|
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> Font::load_from_file(const StringView& path)
|
RefPtr<Font> 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.glyph_height = m_glyph_height;
|
||||||
header.type = 0;
|
header.type = 0;
|
||||||
header.is_variable_width = !m_fixed_width;
|
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));
|
memcpy(header.name, m_name.characters(), min(m_name.length(), (size_t)63));
|
||||||
|
|
||||||
size_t bytes_per_glyph = sizeof(unsigned) * m_glyph_height;
|
size_t bytes_per_glyph = sizeof(unsigned) * m_glyph_height;
|
||||||
|
|
|
@ -63,7 +63,6 @@ public:
|
||||||
u8 glyph_height() const { return m_glyph_height; }
|
u8 glyph_height() const { return m_glyph_height; }
|
||||||
u8 min_glyph_width() const { return m_min_glyph_width; }
|
u8 min_glyph_width() const { return m_min_glyph_width; }
|
||||||
u8 max_glyph_width() const { return m_max_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 StringView&) const;
|
||||||
int width(const Utf8View&) const;
|
int width(const Utf8View&) const;
|
||||||
|
|
||||||
|
@ -73,6 +72,9 @@ public:
|
||||||
bool is_fixed_width() const { return m_fixed_width; }
|
bool is_fixed_width() const { return m_fixed_width; }
|
||||||
void set_fixed_width(bool b) { m_fixed_width = b; }
|
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)
|
void set_glyph_width(char ch, u8 width)
|
||||||
{
|
{
|
||||||
ASSERT(m_glyph_widths);
|
ASSERT(m_glyph_widths);
|
||||||
|
@ -80,7 +82,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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<Font> load_from_memory(const u8*);
|
static RefPtr<Font> load_from_memory(const u8*);
|
||||||
|
|
||||||
|
@ -94,6 +96,7 @@ private:
|
||||||
u8 m_glyph_height { 0 };
|
u8 m_glyph_height { 0 };
|
||||||
u8 m_min_glyph_width { 0 };
|
u8 m_min_glyph_width { 0 };
|
||||||
u8 m_max_glyph_width { 0 };
|
u8 m_max_glyph_width { 0 };
|
||||||
|
u8 m_glyph_spacing { 0 };
|
||||||
|
|
||||||
bool m_fixed_width { false };
|
bool m_fixed_width { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue