Font API for loading a font (truetype), getting glyph metrics and bitmap/sdf data
Namespace: | dmFont |
Include: | #include <dmsdk/font/font.h> |
TYPES | |
---|---|
HFont | Font handle. Holds the info about a loaded font |
ENUMS | |
---|---|
FontResult | FontResult |
FontType | FontType |
GlyphBitmapFlags | GlyphBitmapFlags |
STRUCTS | |
---|---|
struct Glyph | Represents a glyph |
struct GlyphBitmap | Holds the bitmap data of a glyph |
struct GlyphOptions | Holds the bitmap data of a glyph |
void DestroyFont(dmFont::HFont font)
Destroys a loaded font
PARAMETERS
dmFont::HFont |
font |
The font to deallocate |
dmFont::FontResult FreeGlyph(dmFont::HFont font, dmFont::Glyph* glyph)
Free the bitmap of the glyph
PARAMETERS
dmFont::HFont |
font |
The font |
dmFont::Glyph* |
glyph |
The glyph |
RETURNS
dmFont::FontResult |
The result |
float GetAscent(dmFont::HFont font, float scale)
Get the max ascent of the font
PARAMETERS
dmFont::HFont |
font |
The font |
float |
scale |
The scale factor |
RETURNS
float |
The max ascent |
float GetDescent(dmFont::HFont font, float scale)
Get the max descent of the font
PARAMETERS
dmFont::HFont |
font |
The font |
float |
scale |
The scale factor |
RETURNS
float |
The max descent |
dmFont::FontResult GetGlyph(dmFont::HFont font, uint32_t codepoint, options, glyph)
Get the metrics and possibly the rasterized image data of a glyph
PARAMETERS
dmFont::HFont |
font |
The font |
uint32_t |
codepoint |
The unicode code point |
|
options |
(in) dmFont::GlyphOptions* The glyph options |
|
glyph |
(out) dmFont::Glyph* The glyph |
RETURNS
dmFont::FontResult |
The result |
float GetLineGap(dmFont::HFont font, float scale)
Get the line gap of the font
PARAMETERS
dmFont::HFont |
font |
The font |
float |
scale |
The scale factor |
RETURNS
float |
The line gap |
const char* GetPath(dmFont::HFont font)
Gets the path of the loaded font
PARAMETERS
dmFont::HFont |
font |
The font |
RETURNS
const char* |
The path |
float GetPixelScaleFromSize(dmFont::HFont font, float size)
Get the scale factor from a given pixel size.
PARAMETERS
dmFont::HFont |
font |
The font |
float |
size |
The font size (in pixel height) |
RETURNS
float |
The scale factor |
uint32_t GetResourceSize(dmFont::HFont font)
Get the bytes used by this resource
PARAMETERS
dmFont::HFont |
font |
The font |
RETURNS
uint32_t |
The resource size |
dmFont::FontType GetType(dmFont::HFont font)
Gets the specific implementation of the loaded font
PARAMETERS
dmFont::HFont |
font |
The font |
RETURNS
dmFont::FontType |
The type |
dmFont::HFont LoadFontFromMemory(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
dmFont::HFont |
The loaded font, or null if it failed to load. |
dmFont::HFont LoadFontFromPath(const char* path)
Loads a font using a path
PARAMETERS
const char* |
path |
The path to the resource |
RETURNS
dmFont::HFont |
The loaded font, or null if it failed to load. |
TYPE
struct Glyph
Represents a glyph. If there's an associated image, it is of size width * height * channels.
MEMBERS
GlyphBitmap |
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 GlyphBitmap
Holds 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 |
uint16_t |
m_Channels |
The number of channels in the glyph image |
uint8_t |
m_Flags |
Flags describing the data. See `dmFont::GlyphBitmapFlags`. |
uint8_t* |
m_Data |
The bitmap data, or null if no data available. |
TYPE
struct GlyphOptions
Holds 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. |
float |
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) |
Font handle. Holds the info about a loaded font
FontResult
RESULT_OK |
|
RESULT_NOT_SUPPORTED |
|
RESULT_ERROR |
FontType
FONT_TYPE_UNKNOWN |
-1 |
FONT_TYPE_STBTTF |
|
FONT_TYPE_STBOTF |
|
FONT_TYPE_MAX |
GlyphBitmapFlags
GLYPH_BM_FLAG_COMPRESSION_NONE |
0 |
GLYPH_BM_FLAG_COMPRESSION_DEFLATE |
1 |