#pragma once #include #include #include #include #define PSF_FONT_MAGIC 0x864ab572 namespace ui { class Font : public Shareable { public: enum FontWeight { Regular, Bold, }; static Result> load(const os::Path& path); static Result> load_builtin(StringView name, FontWeight weight); static SharedPtr default_font(); static SharedPtr 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; }; };