mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:07:34 +00:00
Start working on a simple graphical font editor.
Editing fonts by editing text files is really slow and boring. A simple font editor seems like a good way to take LibGUI for a spin.
This commit is contained in:
parent
5e0b7f1a56
commit
6fc3c38324
18 changed files with 390 additions and 19 deletions
|
@ -4,6 +4,21 @@
|
|||
|
||||
#define DEFAULT_FONT_NAME Liza8x10
|
||||
|
||||
static const byte error_glyph_width = 8;
|
||||
static const byte error_glyph_height = 10;
|
||||
static constexpr const char* error_glyph {
|
||||
" #### "
|
||||
" # # "
|
||||
" # # "
|
||||
" # ## # "
|
||||
" # ## # "
|
||||
" #### "
|
||||
" ## "
|
||||
" ###### "
|
||||
" ## "
|
||||
" ## ",
|
||||
};
|
||||
|
||||
static Font* s_default_font;
|
||||
|
||||
void Font::initialize()
|
||||
|
@ -18,6 +33,22 @@ Font& Font::default_font()
|
|||
return *s_default_font;
|
||||
}
|
||||
|
||||
RetainPtr<Font> Font::clone() const
|
||||
{
|
||||
size_t bytes_per_glyph = glyph_width() * glyph_height();
|
||||
// FIXME: This is leaked!
|
||||
char** new_glyphs = static_cast<char**>(malloc(sizeof(char*) * 256));
|
||||
for (unsigned i = 0; i < 256; ++i) {
|
||||
new_glyphs[i] = static_cast<char*>(malloc(bytes_per_glyph));
|
||||
if (i >= m_first_glyph && i <= m_last_glyph) {
|
||||
memcpy(new_glyphs[i], m_glyphs[i - m_first_glyph], bytes_per_glyph);
|
||||
} else {
|
||||
memset(new_glyphs[i], ' ', bytes_per_glyph);
|
||||
}
|
||||
}
|
||||
return adopt(*new Font(new_glyphs, m_glyph_width, m_glyph_height, 0, 255));
|
||||
}
|
||||
|
||||
Font::Font(const char* const* glyphs, byte glyph_width, byte glyph_height, byte first_glyph, byte last_glyph)
|
||||
: m_glyphs(glyphs)
|
||||
, m_glyph_width(glyph_width)
|
||||
|
@ -25,7 +56,9 @@ Font::Font(const char* const* glyphs, byte glyph_width, byte glyph_height, byte
|
|||
, m_first_glyph(first_glyph)
|
||||
, m_last_glyph(last_glyph)
|
||||
{
|
||||
m_error_bitmap = CharacterBitmap::create_from_ascii(DEFAULT_FONT_NAME::error_glyph, m_glyph_width, m_glyph_height);
|
||||
ASSERT(m_glyph_width == error_glyph_width);
|
||||
ASSERT(m_glyph_height == error_glyph_height);
|
||||
m_error_bitmap = CharacterBitmap::create_from_ascii(error_glyph, error_glyph_width, error_glyph_height);
|
||||
for (unsigned ch = 0; ch < 256; ++ch) {
|
||||
if (ch < m_first_glyph || ch > m_last_glyph) {
|
||||
m_bitmaps[ch] = m_error_bitmap.copy_ref();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue