Font

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
FUNCTIONS
void FontDestroy(HFont font) Destroys a loaded font
dmFont::FontResult FontFreeGlyph(HFont font, dmFont::Glyph* glyph) Free the bitmap of the glyph
float FontGetAscent(HFont font, float scale) Get the max ascent of the font
float FontGetDescent(HFont font, float scale) Get the max descent of the font
FontFontResult FontGetGlyph(HFont font, uint32_t codepoint,  options,  glyph) Get the metrics of a glyph
FontFontResult FontGetGlyphByIndex(HFont font, uint32_t glyph_index,  options,  glyph) Get the metrics of a glyph
uint32_t FontGetGlyphIndex(HFont font, uint32_t codepoint) Get glyph index of a codepoint
float FontGetLineGap(HFont font, float scale) Get the line gap of the font
const char* FontGetPath(HFont font) Gets the path of the loaded font
uint32_t FontGetPathHash(HFont font) Gets the path hash of the loaded font
uint32_t FontGetResourceSize(HFont font) Get the bytes used by this resource
float FontGetScaleFromSize(HFont font, float size) Get the scale factor from a given pixel size
dmFont::FontType FontGetType(HFont font) Gets the specific implementation of the loaded fon...
HFont FontLoadFromMemory(const char* name, void* data, uint32_t data_size, bool allocate) Loads a font from memory
HFont FontLoadFromPath(const char* path) Loads a font using a path

Functions

FontDestroy

void FontDestroy(HFont font)

Destroys a loaded font

PARAMETERS

HFont font The font to deallocate

FontFreeGlyph

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

FontGetAscent

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

FontGetDescent

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

FontGetGlyph

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.

FontGetGlyphByIndex

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.

FontGetGlyphIndex

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

FontGetLineGap

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

FontGetPath

const char* FontGetPath(HFont font)

Gets the path of the loaded font

PARAMETERS

HFont font The font

RETURNS

const char* The path

FontGetPathHash

uint32_t FontGetPathHash(HFont font)

Gets the path hash of the loaded font

PARAMETERS

HFont font The font

RETURNS

uint32_t The path

FontGetResourceSize

uint32_t FontGetResourceSize(HFont font)

Get the bytes used by this resource

PARAMETERS

HFont font The font

RETURNS

uint32_t The resource size

FontGetScaleFromSize

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

FontGetType

dmFont::FontType FontGetType(HFont font)

Gets the specific implementation of the loaded font

PARAMETERS

HFont font The font

RETURNS

dmFont::FontType The type

FontLoadFromMemory

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.

FontLoadFromPath

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.

Structs

FontGlyph

TYPE

struct FontGlyph

Represents 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)


FontGlyphBitmap

TYPE

struct FontGlyphBitmap

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
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)


FontGlyphOptions

TYPE

struct FontGlyphOptions

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.
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)


Enums

FontGlyphBitmapFlags

FontGlyphBitmapFlags

GLYPH_BM_FLAG_COMPRESSION_NONE = 0
GLYPH_BM_FLAG_COMPRESSION_DEFLATE = 1

FontResult

FontResult

FONT_RESULT_OK
FONT_RESULT_NOT_SUPPORTED
FONT_RESULT_ERROR

FontType

FontType

FONT_TYPE_STBTTF
FONT_TYPE_STBOTF
FONT_TYPE_UNKNOWN = 0xFFFFFFFF