mirror of https://github.com/Chlumsky/msdfgen.git
Added API to load a font from bytes
This commit is contained in:
parent
5f27bdfb1c
commit
cf78977b47
|
|
@ -20,6 +20,7 @@ class FreetypeHandle {
|
||||||
friend FreetypeHandle * initializeFreetype();
|
friend FreetypeHandle * initializeFreetype();
|
||||||
friend void deinitializeFreetype(FreetypeHandle *library);
|
friend void deinitializeFreetype(FreetypeHandle *library);
|
||||||
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
||||||
|
friend FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
|
||||||
|
|
||||||
FT_Library library;
|
FT_Library library;
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ class FreetypeHandle {
|
||||||
class FontHandle {
|
class FontHandle {
|
||||||
friend FontHandle * adoptFreetypeFont(FT_Face ftFace);
|
friend FontHandle * adoptFreetypeFont(FT_Face ftFace);
|
||||||
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
friend FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
||||||
|
friend FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
|
||||||
friend void destroyFont(FontHandle *font);
|
friend void destroyFont(FontHandle *font);
|
||||||
friend bool getFontMetrics(FontMetrics &metrics, FontHandle *font);
|
friend bool getFontMetrics(FontMetrics &metrics, FontHandle *font);
|
||||||
friend bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font);
|
friend bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font);
|
||||||
|
|
@ -129,6 +131,19 @@ FontHandle * loadFont(FreetypeHandle *library, const char *filename) {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length) {
|
||||||
|
if (!library)
|
||||||
|
return NULL;
|
||||||
|
FontHandle *handle = new FontHandle;
|
||||||
|
FT_Error error = FT_New_Memory_Face(library->library, data, length, 0, &handle->face);
|
||||||
|
if (error) {
|
||||||
|
delete handle;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
handle->ownership = true;
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
void destroyFont(FontHandle *font) {
|
void destroyFont(FontHandle *font) {
|
||||||
if (font->ownership)
|
if (font->ownership)
|
||||||
FT_Done_Face(font->face);
|
FT_Done_Face(font->face);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
namespace msdfgen {
|
namespace msdfgen {
|
||||||
|
|
||||||
|
typedef unsigned char byte;
|
||||||
typedef unsigned unicode_t;
|
typedef unsigned unicode_t;
|
||||||
|
|
||||||
class FreetypeHandle;
|
class FreetypeHandle;
|
||||||
|
|
@ -46,6 +47,8 @@ FontHandle * adoptFreetypeFont(FT_Face ftFace);
|
||||||
#endif
|
#endif
|
||||||
/// Loads a font file and returns its handle.
|
/// Loads a font file and returns its handle.
|
||||||
FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
||||||
|
/// Loads a font from binary data and returns its handle.
|
||||||
|
FontHandle * loadFontData(FreetypeHandle *library, const byte *data, int length);
|
||||||
/// Unloads a font file.
|
/// Unloads a font file.
|
||||||
void destroyFont(FontHandle *font);
|
void destroyFont(FontHandle *font);
|
||||||
/// Outputs the metrics of a font file.
|
/// Outputs the metrics of a font file.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue