2018-10-11 23:45:57 +02:00
|
|
|
#include "Font.h"
|
|
|
|
#include "Peanut8x10.h"
|
|
|
|
#include <AK/RetainPtr.h>
|
2019-01-10 23:19:29 +01:00
|
|
|
|
|
|
|
static Font* s_default_font;
|
|
|
|
|
|
|
|
void Font::initialize()
|
|
|
|
{
|
|
|
|
s_default_font = nullptr;
|
|
|
|
}
|
2018-10-11 23:45:57 +02:00
|
|
|
|
|
|
|
Font& Font::defaultFont()
|
|
|
|
{
|
2019-01-10 23:19:29 +01:00
|
|
|
if (!s_default_font)
|
|
|
|
s_default_font = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
|
|
|
|
return *s_default_font;
|
2018-10-11 23:45:57 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 23:54:34 +02:00
|
|
|
Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph)
|
2018-10-11 23:45:57 +02:00
|
|
|
: m_glyphs(glyphs)
|
|
|
|
, m_glyphWidth(glyphWidth)
|
|
|
|
, m_glyphHeight(glyphHeight)
|
|
|
|
, m_firstGlyph(firstGlyph)
|
|
|
|
, m_lastGlyph(lastGlyph)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Font::~Font()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-10 05:41:49 +01:00
|
|
|
const CharacterBitmap* Font::glyphBitmap(byte ch) const
|
2018-10-11 23:45:57 +02:00
|
|
|
{
|
2018-10-12 12:49:45 +02:00
|
|
|
if (!m_bitmaps[ch]) {
|
|
|
|
if (ch < m_firstGlyph || ch > m_lastGlyph)
|
|
|
|
return nullptr;
|
|
|
|
const char* data = m_glyphs[(unsigned)ch - m_firstGlyph];
|
2019-01-10 05:41:49 +01:00
|
|
|
m_bitmaps[ch] = CharacterBitmap::createFromASCII(data, m_glyphWidth, m_glyphHeight);
|
2018-10-12 12:49:45 +02:00
|
|
|
}
|
2018-10-12 20:55:06 +02:00
|
|
|
ASSERT(ch >= m_firstGlyph && ch <= m_lastGlyph);
|
2018-10-12 12:49:45 +02:00
|
|
|
return m_bitmaps[ch].ptr();
|
2018-10-11 23:45:57 +02:00
|
|
|
}
|