1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Make a preparation pass for variable-width fonts.

This commit is contained in:
Andreas Kling 2019-03-06 11:03:10 +01:00
parent b85fe0bd07
commit 0a86366c71
9 changed files with 72 additions and 32 deletions

View file

@ -55,7 +55,16 @@ Font::Font(const String& name, unsigned* rows, byte glyph_width, byte glyph_heig
, m_rows(rows)
, m_glyph_width(glyph_width)
, m_glyph_height(glyph_height)
, m_min_glyph_width(glyph_width)
, m_max_glyph_width(glyph_width)
{
m_fixed_width = true;
if (!m_fixed_width) {
byte minimum = 255;
for (int i = 0; i < 256; ++i)
minimum = min(minimum, m_glyph_widths[i]);
m_min_glyph_width = minimum;
}
}
Font::~Font()
@ -137,3 +146,14 @@ bool Font::write_to_file(const String& path)
ASSERT(rc == 0);
return true;
}
int Font::width(const String& string) const
{
if (m_fixed_width)
return string.length() * m_glyph_width;
int width = 0;
for (int i = 0; i < string.length(); ++i)
width += glyph_width(string[i]);
return width;
}