Font.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "Font.h"
  2. #include "Peanut8x10.h"
  3. #include <AK/RetainPtr.h>
  4. static Font* s_default_font;
  5. void Font::initialize()
  6. {
  7. s_default_font = nullptr;
  8. }
  9. Font& Font::defaultFont()
  10. {
  11. if (!s_default_font)
  12. s_default_font = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
  13. return *s_default_font;
  14. }
  15. Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph)
  16. : m_glyphs(glyphs)
  17. , m_glyphWidth(glyphWidth)
  18. , m_glyphHeight(glyphHeight)
  19. , m_firstGlyph(firstGlyph)
  20. , m_lastGlyph(lastGlyph)
  21. {
  22. }
  23. Font::~Font()
  24. {
  25. }
  26. const CharacterBitmap* Font::glyphBitmap(byte ch) const
  27. {
  28. if (!m_bitmaps[ch]) {
  29. if (ch < m_firstGlyph || ch > m_lastGlyph)
  30. return nullptr;
  31. const char* data = m_glyphs[(unsigned)ch - m_firstGlyph];
  32. m_bitmaps[ch] = CharacterBitmap::createFromASCII(data, m_glyphWidth, m_glyphHeight);
  33. }
  34. ASSERT(ch >= m_firstGlyph && ch <= m_lastGlyph);
  35. return m_bitmaps[ch].ptr();
  36. }