Font API for loading a font (truetype), getting glyph metrics and bitmap/sdf data
| Namespace: | Font |
| Include: | #include <dmsdk/font/font.h> |
| ENUMS | |
|---|---|
| FontGlyphBitmapFlags | FontGlyphBitmapFlags |
| FontResult | FontResult |
| FontType | FontType |
| STRUCTS | |
|---|---|
| struct FontGlyph | Represents a glyph |
| struct FontGlyphBitmap | Holds the bitmap data of a glyph |
| struct FontGlyphOptions | Holds the bitmap data of a glyph |
void FontDestroy(HFont font)
Destroys a loaded font
PARAMETERS
HFont |
font |
The font to deallocate |
dmFont::FontResult FontFreeGlyph(HFont font, dmFont::Glyph* glyph)
Free the bitmap of the glyph
PARAMETERS
HFont |
font |
The font |
dmFont::Glyph* |
glyph |
The glyph |
RETURNS
dmFont::FontResult |
The result |
float FontGetAscent(HFont font, float scale)
Get the max ascent of the font
PARAMETERS
HFont |
font |
The font |
float |
scale |
The scale factor |
RETURNS
float |
The max ascent |
float FontGetDescent(HFont font, float scale)
Get the max descent of the font
PARAMETERS
HFont |
font |
The font |
float |
scale |
The scale factor |
RETURNS
float |
The max descent |
FontFontResult FontGetGlyph(HFont font, uint32_t codepoint, options, glyph)
Get the metrics of a glyph
PARAMETERS
HFont |
font |
The font |
uint32_t |
codepoint |
The unicode code point |
|
options |
(in) FontGlyphOptions* The glyph options |
|
glyph |
(out) FontGlyph* The glyph |
RETURNS
FontFontResult |
If successful, user must call FreeGlyph() on the result to clear any image data. |
FontFontResult FontGetGlyphByIndex(HFont font, uint32_t glyph_index, options, glyph)
Get the metrics of a glyph
PARAMETERS
HFont |
font |
The font |
uint32_t |
glyph_index |
The unicode code point |
|
options |
(in) FontGlyphOptions* The glyph options |
|
glyph |
(out) FontGlyph* The glyph |
RETURNS
FontFontResult |
If successful, user must call FreeGlyph() on the result to clear any image data. |
uint32_t FontGetGlyphIndex(HFont font, uint32_t codepoint)
Get glyph index of a codepoint
PARAMETERS
HFont |
font |
The font |
uint32_t |
codepoint |
The unicode code point |
RETURNS
uint32_t |
0 if no index was found |
float FontGetLineGap(HFont font, float scale)
Get the line gap of the font
PARAMETERS
HFont |
font |
The font |
float |
scale |
The scale factor |
RETURNS
float |
The line gap |
const char* FontGetPath(HFont font)
Gets the path of the loaded font
PARAMETERS
HFont |
font |
The font |
RETURNS
const char* |
The path |
uint32_t FontGetPathHash(HFont font)
Gets the path hash of the loaded font
PARAMETERS
HFont |
font |
The font |
RETURNS
uint32_t |
The path |
uint32_t FontGetResourceSize(HFont font)
Get the bytes used by this resource
PARAMETERS
HFont |
font |
The font |
RETURNS
uint32_t |
The resource size |
float FontGetScaleFromSize(HFont font, float size)
Get the scale factor from a given pixel size. Used to convert from points to pixel size
PARAMETERS
HFont |
font |
The font |
float |
size |
The font size (in pixel height) |
RETURNS
float |
The scale factor |
dmFont::FontType FontGetType(HFont font)
Gets the specific implementation of the loaded font
PARAMETERS
HFont |
font |
The font |
RETURNS
dmFont::FontType |
The type |
HFont FontLoadFromMemory(const char* name, void* data, uint32_t data_size, bool allocate)
Loads a font from memory
PARAMETERS
const char* |
name |
The name of the resource. For easier debugging |
void* |
data |
The raw data |
uint32_t |
data_size |
The length of the data (in bytes) |
bool |
allocate |
If true, the font may allocate a copy of the data (if needed) |
RETURNS
HFont |
The loaded font, or null if it failed to load. |
HFont FontLoadFromPath(const char* path)
Loads a font using a path
PARAMETERS
const char* |
path |
The path to the resource |
RETURNS
HFont |
The loaded font, or null if it failed to load. |
TYPE
struct FontGlyphRepresents a glyph. If there's an associated image, it is of size width * height * channels.
MEMBERS
FontGlyphBitmap |
m_Bitmap |
The bitmap data of the glyph. |
uint32_t |
m_Codepoint |
The unicode code point |
float |
m_Width |
The glyph bounding width |
float |
m_Height |
The glyph bounding height |
float |
m_Advance |
The advance step of the glyph (in pixels) |
float |
m_LeftBearing |
The left bearing of the glyph (in pixels) |
float |
m_Ascent |
The ascent of the glyph. (in pixels) |
float |
m_Descent |
The descent of the glyph. Positive! (in pixels) |
TYPE
struct FontGlyphBitmapHolds the bitmap data of a glyph. If there's an associated image, it is of size width * height * channels.
MEMBERS
uint16_t |
m_Width |
The glyph image width |
uint16_t |
m_Height |
The glyph image height |
uint8_t |
m_Channels |
The number of color channels |
uint8_t |
m_Flags |
Flags describing the data. See #FontGlyphBitmapFlags. |
uint8_t* |
m_Data |
The bitmap data, or null if no data available. |
uint32_t |
m_DataSize |
The bitmap data size (e.g. if the data is compressed) |
TYPE
struct FontGlyphOptionsHolds the bitmap data of a glyph. If there's an associated image, it is of size width * height * channels.
MEMBERS
float |
m_Scale |
The font scale |
bool |
m_GenerateImage |
If true, generates an SDF image, and fills out the glyph.m_Bitmap structure. |
int |
m_StbttSDFPadding |
The sdk padding value (valid for FONT_TYPE_STBTTF fonts) |
int |
m_StbttSDFOnEdgeValue |
Where the edge value is located (valid for FONT_TYPE_STBTTF fonts) |
FontGlyphBitmapFlags
GLYPH_BM_FLAG_COMPRESSION_NONE |
= 0 |
GLYPH_BM_FLAG_COMPRESSION_DEFLATE |
= 1 |
FontResult
FONT_RESULT_OK |
|
FONT_RESULT_NOT_SUPPORTED |
|
FONT_RESULT_ERROR |
FontType
FONT_TYPE_STBTTF |
|
FONT_TYPE_STBOTF |
|
FONT_TYPE_UNKNOWN |
= 0xFFFFFFFF |