27 #include "precompiled.h"
38 typedef std::map<u16, UnifontGlyphData>
glyphmap;
79 shared_ptr<u8> buf;
size_t size;
82 std::istringstream FNTStream(std::string((
const char*)buf.get(), size));
86 if (Version < 100 || Version > 101)
89 int TextureWidth, TextureHeight;
90 FNTStream >> TextureWidth >> TextureHeight;
98 else if (Format ==
"a")
105 FNTStream >> NumGlyphs;
115 for (
int i = 0; i < NumGlyphs; ++i)
117 int Codepoint, TextureX, TextureY, Width, Height, OffsetX, OffsetY, Advance;
118 FNTStream >> Codepoint>>TextureX>>TextureY>>Width>>Height>>OffsetX>>OffsetY>>Advance;
120 if (Codepoint < 0 || Codepoint > 0xFFFF)
126 if (Version < 101 && Codepoint ==
'I')
131 GLfloat u = (GLfloat)TextureX / (GLfloat)TextureWidth;
132 GLfloat v = (GLfloat)TextureY / (GLfloat)TextureHeight;
133 GLfloat w = (GLfloat)Width / (GLfloat)TextureWidth;
134 GLfloat h = (GLfloat)Height / (GLfloat)TextureHeight;
203 return h_alloc(H_UniFont, vfs, pathname, flags);
210 return h_free(h, H_UniFont);
240 glyphmap::iterator it = f->
glyphs->find(c);
242 if (it == f->
glyphs->end())
243 it = f->
glyphs->find(0xFFFD);
245 return it->second.xadvance;
255 size_t len = wcslen(text);
257 for (
size_t i = 0; i < len; ++i)
259 glyphmap::iterator it = f->
glyphs->find(text[i]);
261 if (it == f->
glyphs->end())
262 it = f->
glyphs->find(0xFFFD);
264 if (it == f->
glyphs->end())
270 width += it->second.xadvance;
Status h_free(Handle &h, H_Type type)
bool unifont_has_rgb(const Handle h)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
const glyphmap & unifont_get_glyphs(const Handle h)
static Status UniFont_reload(UniFont *f, const PIVFS &vfs, const VfsPath &basename, Handle h)
int unifont_linespacing(const Handle h)
Status ogl_tex_free(Handle &ht)
Release this texture reference.
int swprintf_s(wchar_t *buf, size_t max_chars, const wchar_t *fmt,...) WPRINTF_ARGS(3)
VfsPath h_filename(const Handle h)
const Status INVALID_HANDLE
int unifont_character_width(const Handle h, wchar_t c)
Handle h_alloc(H_Type type, const PIVFS &vfs, const VfsPath &pathname, size_t flags,...)
Status unifont_stringsize(const Handle h, const wchar_t *text, int &width, int &height)
Determine pixel extents of a string.
static void UniFont_init(UniFont *f, va_list args)
#define H_DEREF(h, type, var)
#define H_TYPE_DEFINE(type)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
LIB_API int debug_IsPointerBogus(const void *p)
check if a pointer appears to be totally invalid.
const String & string() const
static Status UniFont_to_string(const UniFont *f, wchar_t *buf)
#define SAFE_DELETE(p)
delete memory ensuing from new and set the pointer to zero (thus making double-frees safe / a no-op) ...
i64 Status
Error handling system.
i64 Handle
`handle' representing a reference to a resource (sound, texture, etc.)
Handle ogl_tex_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load and return a handle to the texture.
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
Handle unifont_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load a font.
static void UniFont_dtor(UniFont *f)
Path ChangeExtension(Path extension) const
int unifont_height(const Handle h)
Status ogl_tex_set_filter(Handle ht, GLint filter)
Override default filter (see ogl_tex_set_defaults) for this texture.
std::map< u16, UnifontGlyphData > glyphmap
#define WARN_RETURN(status)
#define debug_warn(expr)
display the error dialog with the given text.
const size_t H_STRING_LEN
Status unifont_unload(Handle &h)
Release a handle to a previously loaded font (subject to reference counting).
static Status UniFont_validate(const UniFont *f)
#define H_USER_DATA(h, type)
Handle unifont_get_texture(const Handle h)
Status ogl_tex_upload(const Handle ht, GLenum fmt_ovr, int q_flags_ovr, GLint int_fmt_ovr)
Upload texture to OpenGL.
#define RETURN_STATUS_IF_ERR(expression)