Luna/libui/include/ui/Font.h

56 lines
1.2 KiB
C++

#pragma once
#include <luna/Buffer.h>
#include <luna/SharedPtr.h>
#include <os/Path.h>
#include <ui/Canvas.h>
#define PSF_FONT_MAGIC 0x864ab572
namespace ui
{
class Font : public Shareable
{
public:
enum FontWeight
{
Regular,
Bold,
};
static Result<SharedPtr<Font>> load(const os::Path& path);
static Result<SharedPtr<Font>> load_builtin(StringView name, FontWeight weight);
static SharedPtr<Font> default_font();
static SharedPtr<Font> default_bold_font();
void render(wchar_t codepoint, ui::Color color, ui::Canvas& canvas);
void render(const wchar_t* text, ui::Color color, ui::Canvas& canvas);
int width() const
{
return m_psf_header.width;
}
int height() const
{
return m_psf_header.height;
}
private:
struct PSFHeader
{
u32 magic;
u32 version; // zero
u32 headersize;
u32 flags; // 0 if there's no unicode table
u32 numglyph;
u32 bytesperglyph;
int height;
int width;
};
PSFHeader m_psf_header;
Buffer m_font_data;
};
};