mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +00:00
Add a simple Font class.
This commit is contained in:
parent
a6e0577f30
commit
110d01941a
6 changed files with 79 additions and 22 deletions
31
Widgets/Font.cpp
Normal file
31
Widgets/Font.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "Font.h"
|
||||
#include "Peanut8x10.h"
|
||||
#include <AK/RetainPtr.h>
|
||||
#include <cstdio>
|
||||
|
||||
Font& Font::defaultFont()
|
||||
{
|
||||
static auto* f = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
|
||||
return *f;
|
||||
}
|
||||
|
||||
Font::Font(const char* const* glyphs, unsigned glyphWidth, unsigned glyphHeight, byte firstGlyph, byte lastGlyph)
|
||||
: m_glyphs(glyphs)
|
||||
, m_glyphWidth(glyphWidth)
|
||||
, m_glyphHeight(glyphHeight)
|
||||
, m_firstGlyph(firstGlyph)
|
||||
, m_lastGlyph(lastGlyph)
|
||||
{
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
}
|
||||
|
||||
const char* Font::glyph(char ch) const
|
||||
{
|
||||
if (ch < m_firstGlyph || ch > m_lastGlyph)
|
||||
return nullptr;
|
||||
return m_glyphs[(unsigned)ch - m_firstGlyph];
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue