2018-10-12 00:45:57 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-17 02:36:55 +03:00
|
|
|
#include <SharedGraphics/Rect.h>
|
2018-10-12 00:45:57 +03:00
|
|
|
#include <AK/Retainable.h>
|
2018-10-12 13:49:45 +03:00
|
|
|
#include <AK/RetainPtr.h>
|
2019-02-03 01:13:12 +03:00
|
|
|
#include <AK/AKString.h>
|
2018-10-12 00:45:57 +03:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2019-02-05 08:43:33 +03:00
|
|
|
// FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead?
|
|
|
|
class GlyphBitmap {
|
|
|
|
friend class Font;
|
|
|
|
public:
|
|
|
|
const unsigned* rows() const { return m_rows; }
|
|
|
|
unsigned row(unsigned index) const { return m_rows[index]; }
|
|
|
|
|
|
|
|
bool bit_at(int x, int y) const { return row(y) & (1 << x); }
|
|
|
|
void set_bit_at(int x, int y, bool b)
|
|
|
|
{
|
|
|
|
auto& mutable_row = const_cast<unsigned*>(m_rows)[y];
|
|
|
|
if (b)
|
|
|
|
mutable_row |= 1 << x;
|
|
|
|
else
|
|
|
|
mutable_row &= ~(1 << x);
|
|
|
|
}
|
|
|
|
|
|
|
|
Size size() const { return m_size; }
|
|
|
|
int width() const { return m_size.width(); }
|
|
|
|
int height() const { return m_size.height(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
GlyphBitmap(const unsigned* rows, Size size)
|
|
|
|
: m_rows(rows)
|
|
|
|
, m_size(size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned* m_rows { nullptr };
|
|
|
|
Size m_size;
|
|
|
|
};
|
|
|
|
|
2018-10-12 00:45:57 +03:00
|
|
|
class Font : public Retainable<Font> {
|
|
|
|
public:
|
2019-01-16 19:54:06 +03:00
|
|
|
static Font& default_font();
|
2019-02-04 13:37:15 +03:00
|
|
|
static Font& default_bold_font();
|
2018-10-12 00:45:57 +03:00
|
|
|
|
2019-03-06 16:06:40 +03:00
|
|
|
static Font& default_fixed_width_font();
|
|
|
|
|
2019-02-02 10:05:14 +03:00
|
|
|
RetainPtr<Font> clone() const;
|
|
|
|
|
2019-02-03 03:36:25 +03:00
|
|
|
static RetainPtr<Font> load_from_memory(const byte*);
|
|
|
|
|
2019-02-03 01:13:12 +03:00
|
|
|
static RetainPtr<Font> load_from_file(const String& path);
|
|
|
|
bool write_to_file(const String& path);
|
|
|
|
|
2018-10-12 00:45:57 +03:00
|
|
|
~Font();
|
|
|
|
|
2019-03-06 16:50:27 +03:00
|
|
|
GlyphBitmap glyph_bitmap(char ch) const { return GlyphBitmap(&m_rows[(byte)ch * m_glyph_height], { glyph_width(ch), m_glyph_height }); }
|
2018-10-12 00:45:57 +03:00
|
|
|
|
2019-03-06 13:03:10 +03:00
|
|
|
byte glyph_width(char ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[(byte)ch]; }
|
2019-01-16 19:54:06 +03:00
|
|
|
byte glyph_height() const { return m_glyph_height; }
|
2019-03-06 13:03:10 +03:00
|
|
|
byte min_glyph_width() const { return m_min_glyph_width; }
|
|
|
|
byte max_glyph_width() const { return m_max_glyph_width; }
|
2019-03-06 14:52:41 +03:00
|
|
|
byte glyph_spacing() const { return m_fixed_width ? 0 : 1; }
|
2019-03-06 13:03:10 +03:00
|
|
|
int width(const String& string) const;
|
2018-10-12 00:45:57 +03:00
|
|
|
|
2019-02-03 05:06:58 +03:00
|
|
|
String name() const { return m_name; }
|
|
|
|
void set_name(const String& name) { m_name = name; }
|
|
|
|
|
2019-03-06 13:03:10 +03:00
|
|
|
bool is_fixed_width() const { return m_fixed_width; }
|
2019-03-06 14:52:41 +03:00
|
|
|
void set_fixed_width(bool b) { m_fixed_width = b; }
|
|
|
|
|
|
|
|
void set_glyph_width(char ch, byte width)
|
|
|
|
{
|
|
|
|
ASSERT(m_glyph_widths);
|
|
|
|
m_glyph_widths[(byte)ch] = width;
|
|
|
|
}
|
2019-03-06 13:03:10 +03:00
|
|
|
|
2018-10-12 00:45:57 +03:00
|
|
|
private:
|
2019-03-06 14:52:41 +03:00
|
|
|
Font(const String& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height);
|
2019-02-03 01:13:12 +03:00
|
|
|
|
|
|
|
String m_name;
|
2018-10-12 00:45:57 +03:00
|
|
|
|
2019-02-05 08:43:33 +03:00
|
|
|
unsigned* m_rows { nullptr };
|
2019-03-06 13:03:10 +03:00
|
|
|
byte* m_glyph_widths { nullptr };
|
2019-02-17 02:13:47 +03:00
|
|
|
void* m_mmap_ptr { nullptr };
|
2019-02-05 08:43:33 +03:00
|
|
|
|
2019-01-16 19:54:06 +03:00
|
|
|
byte m_glyph_width { 0 };
|
|
|
|
byte m_glyph_height { 0 };
|
2019-03-06 13:03:10 +03:00
|
|
|
byte m_min_glyph_width { 0 };
|
|
|
|
byte m_max_glyph_width { 0 };
|
|
|
|
|
|
|
|
bool m_fixed_width { false };
|
2018-10-12 00:45:57 +03:00
|
|
|
};
|