mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
Font: Eagerly load all 256 glyphs. It's not that many.
This commit is contained in:
parent
2e370fa4d5
commit
c7b005c47b
4 changed files with 11 additions and 28 deletions
|
@ -47,12 +47,7 @@ void GTextBox::paint_event(GPaintEvent&)
|
||||||
if (ch == ' ')
|
if (ch == ' ')
|
||||||
continue;
|
continue;
|
||||||
int x = innerRect.x() + (i * font().glyph_width());
|
int x = innerRect.x() + (i * font().glyph_width());
|
||||||
auto* bitmap = font().glyph_bitmap(ch);
|
painter.draw_bitmap({x, y}, font().glyph_bitmap(ch), Color::Black);
|
||||||
if (!bitmap) {
|
|
||||||
dbgprintf("GTextBox: glyph missing: %02x\n", ch);
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
painter.draw_bitmap({x, y}, *bitmap, Color::Black);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_focused() && m_cursorBlinkState) {
|
if (is_focused() && m_cursorBlinkState) {
|
||||||
|
|
|
@ -26,20 +26,16 @@ Font::Font(const char* const* glyphs, byte glyph_width, byte glyph_height, byte
|
||||||
, m_last_glyph(last_glyph)
|
, m_last_glyph(last_glyph)
|
||||||
{
|
{
|
||||||
m_error_bitmap = CharacterBitmap::create_from_ascii(DEFAULT_FONT_NAME::error_glyph, m_glyph_width, m_glyph_height);
|
m_error_bitmap = CharacterBitmap::create_from_ascii(DEFAULT_FONT_NAME::error_glyph, m_glyph_width, m_glyph_height);
|
||||||
|
for (unsigned ch = 0; ch < 256; ++ch) {
|
||||||
|
if (ch < m_first_glyph || ch > m_last_glyph) {
|
||||||
|
m_bitmaps[ch] = m_error_bitmap.copyRef();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const char* data = m_glyphs[(unsigned)ch - m_first_glyph];
|
||||||
|
m_bitmaps[ch] = CharacterBitmap::create_from_ascii(data, m_glyph_width, m_glyph_height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::~Font()
|
Font::~Font()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const CharacterBitmap* Font::glyph_bitmap(byte ch) const
|
|
||||||
{
|
|
||||||
if (!m_bitmaps[ch]) {
|
|
||||||
if (ch < m_first_glyph || ch > m_last_glyph)
|
|
||||||
return nullptr;
|
|
||||||
const char* data = m_glyphs[(unsigned)ch - m_first_glyph];
|
|
||||||
m_bitmaps[ch] = CharacterBitmap::create_from_ascii(data, m_glyph_width, m_glyph_height);
|
|
||||||
}
|
|
||||||
ASSERT(ch >= m_first_glyph && ch <= m_last_glyph);
|
|
||||||
return m_bitmaps[ch].ptr();
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,8 +11,7 @@ public:
|
||||||
|
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
const CharacterBitmap* glyph_bitmap(byte) const;
|
const CharacterBitmap& glyph_bitmap(char ch) const { return *m_bitmaps[(byte)ch]; }
|
||||||
const CharacterBitmap* error_bitmap() const { return m_error_bitmap.ptr(); }
|
|
||||||
|
|
||||||
byte glyph_width() const { return m_glyph_width; }
|
byte glyph_width() const { return m_glyph_width; }
|
||||||
byte glyph_height() const { return m_glyph_height; }
|
byte glyph_height() const { return m_glyph_height; }
|
||||||
|
|
|
@ -184,14 +184,7 @@ void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color c
|
||||||
|
|
||||||
void Painter::draw_glyph(const Point& point, char ch, Color color)
|
void Painter::draw_glyph(const Point& point, char ch, Color color)
|
||||||
{
|
{
|
||||||
auto* bitmap = font().glyph_bitmap(ch);
|
draw_bitmap(point, font().glyph_bitmap(ch), color);
|
||||||
if (!bitmap) {
|
|
||||||
dbgprintf("Font doesn't have 0x%b ('%c')\n", (byte)ch, ch);
|
|
||||||
bitmap = font().error_bitmap();
|
|
||||||
}
|
|
||||||
int x = point.x();
|
|
||||||
int y = point.y();
|
|
||||||
draw_bitmap({ x, y }, *bitmap, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alignment, Color color)
|
void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alignment, Color color)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue