Struct in ldk_ttf.h

LDKFontFace

typedef struct LDKFontFace LDKFontFace;
Struct in ldk_ttf.h

LDKFontInstance

typedef struct LDKFontInstance LDKFontInstance;
Struct in ldk_ttf.h

LDKFontAtlasDesc

typedef struct LDKFontAtlasDesc{
  u16 page_width;
  u16 page_height;
  u16 padding;
}LDKFontAtlasDesc;
Struct in ldk_ttf.h

LDKFontMetrics

typedef struct LDKFontMetrics{
  float ascent;
  float descent;
  float line_gap;
  float line_height;
}LDKFontMetrics;
Struct in ldk_ttf.h

LDKGlyph

typedef struct LDKGlyph{
  u32 codepoint;
  u32 glyph_index;
  u16 page_index;
  u16 atlas_x0;
  u16 atlas_y0;
  u16 atlas_x1;
  u16 atlas_y1;
  i16 offset_x;
  i16 offset_y;
  i16 advance_x;
  bool valid;
}LDKGlyph;
Struct in ldk_ttf.h

LDKFontPageInfo

typedef struct LDKFontPageInfo{
  u32 page_index;
  u32 width;
  u32 height;
  u8 const *pixels;
  bool dirty;
}LDKFontPageInfo;
Function in ldk_ttf.h

ldk_ttf_utf8_consume_codepoint

Consumes one UTF-8 codepoint and advances the input cursor.

LDK_API bool ldk_ttf_utf8_consume_codepoint(
 char const **cursor,
 u32 *out_codepoint
);

Parameters

char const **cursor
Pointer to the current UTF-8 string position. Updated to the next byte after the decoded sequence.
u32 *out_codepoint
Destination for the decoded Unicode codepoint.

Returns

true if a codepoint was consumed, false if input is invalid or the cursor is at the string terminator.

Function in ldk_ttf.h

ldk_ttf_utf8_consume_codepoint_range

Consumes one UTF-8 codepoint within a bounded byte range and advances the input cursor.

LDK_API bool ldk_ttf_utf8_consume_codepoint_range(
 char const **cursor,
 char const *end,
 u32 *out_codepoint
);

Parameters

char const **cursor
Pointer to the current UTF-8 string position. Updated to the next byte after the decoded sequence.
char const *end
Exclusive end pointer for the UTF-8 byte range.
u32 *out_codepoint
Destination for the decoded Unicode codepoint.

Returns

true if a codepoint was consumed, false if input is invalid, the cursor is at the string terminator, or the cursor reached end.

Function in ldk_ttf.h

ldk_ttf_face_create

Creates a font face from TrueType font data.

LDK_API LDKFontFace * ldk_ttf_face_create(
 void const *data,
 u32 data_size
);

Parameters

void const *data
Source font file data.
u32 data_size
Size of the source font data in bytes.

Returns

New font face, or NULL on failure.

Function in ldk_ttf.h

ldk_ttf_face_destroy

Destroys a font face and all font instances created from it.

LDK_API void ldk_ttf_face_destroy(LDKFontFace *face);

Parameters

LDKFontFace *face
Font face to destroy. May be NULL.
Function in ldk_ttf.h

ldk_ttf_get_instance

Gets or creates a font instance for a specific pixel height.

LDK_API LDKFontInstance * ldk_ttf_get_instance(
 LDKFontFace *face,
 float pixel_height,
 LDKFontAtlasDesc const *atlas_desc
);

Parameters

LDKFontFace *face
Source font face.
float pixel_height
Requested font pixel height.
LDKFontAtlasDesc const *atlas_desc
Optional atlas configuration. NULL uses default atlas settings.

Returns

Font instance, or NULL on failure.

Function in ldk_ttf.h

ldk_ttf_get_pixel_height

Gets the pixel height used by a font instance.

LDK_API float ldk_ttf_get_pixel_height(LDKFontInstance const *instance);

Parameters

LDKFontInstance const *instance
Font instance.

Returns

Pixel height, or 0 if instance is NULL.

Function in ldk_ttf.h

ldk_ttf_get_glyph

Gets a glyph, rasterizing and caching it if necessary.

LDK_API LDKGlyph const * ldk_ttf_get_glyph(
 LDKFontInstance *instance,
 u32 codepoint
);

Parameters

LDKFontInstance *instance
Font instance.
u32 codepoint
Unicode codepoint.

Returns

Glyph data, or NULL on failure.

Function in ldk_ttf.h

ldk_ttf_get_kerning

Gets the horizontal kerning adjustment between two codepoints.

LDK_API float ldk_ttf_get_kerning(
 LDKFontInstance const *instance,
 u32 left_codepoint,
 u32 right_codepoint
);

Parameters

LDKFontInstance const *instance
Font instance.
u32 left_codepoint
Previous Unicode codepoint.
u32 right_codepoint
Current Unicode codepoint.

Returns

Kerning adjustment in pixels, or 0 if unavailable.

Function in ldk_ttf.h

ldk_ttf_preload_range

Preloads and caches all glyphs in an inclusive codepoint range.

LDK_API bool ldk_ttf_preload_range(
 LDKFontInstance *instance,
 u32 first_codepoint,
 u32 last_codepoint
);

Parameters

LDKFontInstance *instance
Font instance.
u32 first_codepoint
First Unicode codepoint to preload.
u32 last_codepoint
Last Unicode codepoint to preload.

Returns

true if all glyphs were processed, false on failure.

Function in ldk_ttf.h

ldk_ttf_preload_basic_ascii

Preloads printable basic ASCII glyphs.

LDK_API bool ldk_ttf_preload_basic_ascii(LDKFontInstance *instance);

Parameters

LDKFontInstance *instance
Font instance.

Returns

true if all glyphs were processed, false on failure.

Function in ldk_ttf.h

ldk_ttf_get_page_count

Gets the number of atlas pages owned by a font instance.

LDK_API u32 ldk_ttf_get_page_count(LDKFontInstance const *instance);

Parameters

LDKFontInstance const *instance
Font instance.

Returns

Number of atlas pages, or 0 if instance is NULL.

Function in ldk_ttf.h

ldk_ttf_get_page_info

Gets information for a font atlas page.

LDK_API bool ldk_ttf_get_page_info(
 LDKFontInstance const *instance,
 u32 page_index,
 LDKFontPageInfo *out_page
);

Parameters

LDKFontInstance const *instance
Font instance.
u32 page_index
Atlas page index.
LDKFontPageInfo *out_page
Destination page information.

Returns

true if page information was written, false on failure.

Function in ldk_ttf.h

ldk_ttf_clear_page_dirty

Clears the dirty flag of an atlas page.

LDK_API void ldk_ttf_clear_page_dirty(
 LDKFontInstance *instance,
 u32 page_index
);

Parameters

LDKFontInstance *instance
Font instance.
u32 page_index
Atlas page index.
Function in ldk_ttf.h

ldk_ttf_get_line_height

Gets the scaled line height for a font instance.

LDK_API float ldk_ttf_get_line_height(LDKFontInstance *instance);

Parameters

LDKFontInstance *instance
Font instance.

Returns

Line height in pixels, or 0 if instance is NULL.

Function in ldk_ttf.h

ldk_ttf_measure_text_cstr

Measures a null-terminated UTF-8 string.

LDK_API LDKTextSize ldk_ttf_measure_text_cstr(
 LDKFontInstance *instance,
 char const *text
);

Parameters

LDKFontInstance *instance
Font instance.
char const *text
Null-terminated UTF-8 string.

Returns

Text size in pixels.

Function in ldk_ttf.h

ldk_ttf_measure_text_cstrn

Measures a UTF-8 string with a byte limit.

LDK_API LDKTextSize ldk_ttf_measure_text_cstrn(
 LDKFontInstance *instance,
 char const *text,
 u32 byte_count
);

Parameters

LDKFontInstance *instance
Font instance.
char const *text
UTF-8 string.
u32 byte_count
Maximum number of bytes to read. If 0, measures an empty string.

Returns

Text size in pixels.

Function in ldk_ttf.h

ldk_ttf_measure_text_cstr_wrapped

Measures a null-terminated UTF-8 string with word wrapping.

LDK_API LDKSizef ldk_ttf_measure_text_cstr_wrapped(
 LDKFontInstance *instance,
 char const *text,
 float max_width
);

Parameters

LDKFontInstance *instance
Font instance.
char const *text
Null-terminated UTF-8 string.
float max_width
Maximum line width in pixels. If less than or equal to 0, wrapping is disabled.

Returns

Wrapped text size in pixels.