diff --git a/src/jes/gui/font.d b/src/jes/gui/font.d new file mode 100644 index 0000000..24b21b7 --- /dev/null +++ b/src/jes/gui/font.d @@ -0,0 +1,63 @@ +module jes.gui.font; +import std.string; + +struct CFont; + +struct CGlyph +{ + ubyte * bitmap; + int width; + int height; + int left; + int top; + int advance; +} + +private extern(C) CGlyph * Font_LoadGlyph(CFont * font, uint char_code); +private extern(C) void Font_FreeGlyph(CGlyph * glyph); +private extern(C) CFont * Font_Load(const char * fname, int size); +private extern(C) void Font_Free(CFont * font); + +class Font +{ + class Glyph + { + int advance; + void render() + { + } + } + + CFont * font; + + this(const char * fname, int size) + { + font = Font_Load(fname, size); + if (font == null) + { + throw new Exception("Could not load font"); + } + } + + this(string fname, int size) + { + this(fname.toStringz(), size); + } + + ~this() + { + Font_Free(font); + } + + uint next_power_of_2(uint n) + { + n--; + n |= n >> 1u; + n |= n >> 2u; + n |= n >> 4u; + n |= n >> 8u; + n |= n >> 16u; + n++; + return n; + } +}