LDKTextSize
typedef LDKSizef LDKTextSize;
Load font faces, manage font instances and glyph atlases, and measure text.
typedef LDKSizef LDKTextSize;
typedef struct LDKFontFace LDKFontFace;
typedef struct LDKFontInstance LDKFontInstance;
typedef struct LDKFontAtlasDesc{
u16 page_width;
u16 page_height;
u16 padding;
}LDKFontAtlasDesc;
typedef struct LDKFontMetrics{
float ascent;
float descent;
float line_gap;
float line_height;
}LDKFontMetrics;
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;
typedef struct LDKFontPageInfo{
u32 page_index;
u32 width;
u32 height;
u8 const *pixels;
bool dirty;
}LDKFontPageInfo;
Consumes one UTF-8 codepoint and advances the input cursor.
LDK_API bool ldk_ttf_utf8_consume_codepoint(
char const **cursor,
u32 *out_codepoint
);
char const **cursoru32 *out_codepointtrue if a codepoint was consumed, false if input is invalid or the cursor is at the string terminator.
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
);
char const **cursorchar const *endu32 *out_codepointtrue if a codepoint was consumed, false if input is invalid, the cursor is at the string terminator, or the cursor reached end.
Creates a font face from TrueType font data.
LDK_API LDKFontFace * ldk_ttf_face_create(
void const *data,
u32 data_size
);
void const *datau32 data_sizeNew font face, or NULL on failure.
Destroys a font face and all font instances created from it.
LDK_API void ldk_ttf_face_destroy(LDKFontFace *face);
LDKFontFace *faceGets 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
);
LDKFontFace *facefloat pixel_heightLDKFontAtlasDesc const *atlas_descFont instance, or NULL on failure.
Gets the pixel height used by a font instance.
LDK_API float ldk_ttf_get_pixel_height(LDKFontInstance const *instance);
LDKFontInstance const *instancePixel height, or 0 if instance is NULL.
Gets scaled font metrics for a font instance.
LDK_API LDKFontMetrics ldk_ttf_get_metrics(LDKFontInstance const *instance);
LDKFontInstance const *instanceFont metrics. Returns zeroed metrics if instance is NULL.
Gets a glyph, rasterizing and caching it if necessary.
LDK_API LDKGlyph const * ldk_ttf_get_glyph(
LDKFontInstance *instance,
u32 codepoint
);
LDKFontInstance *instanceu32 codepointGlyph data, or NULL on failure.
Gets the horizontal kerning adjustment between two codepoints.
LDK_API float ldk_ttf_get_kerning(
LDKFontInstance const *instance,
u32 left_codepoint,
u32 right_codepoint
);
LDKFontInstance const *instanceu32 left_codepointu32 right_codepointKerning adjustment in pixels, or 0 if unavailable.
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
);
LDKFontInstance *instanceu32 first_codepointu32 last_codepointtrue if all glyphs were processed, false on failure.
Preloads printable basic ASCII glyphs.
LDK_API bool ldk_ttf_preload_basic_ascii(LDKFontInstance *instance);
LDKFontInstance *instancetrue if all glyphs were processed, false on failure.
Gets the number of atlas pages owned by a font instance.
LDK_API u32 ldk_ttf_get_page_count(LDKFontInstance const *instance);
LDKFontInstance const *instanceNumber of atlas pages, or 0 if instance is NULL.
Gets information for a font atlas page.
LDK_API bool ldk_ttf_get_page_info(
LDKFontInstance const *instance,
u32 page_index,
LDKFontPageInfo *out_page
);
LDKFontInstance const *instanceu32 page_indexLDKFontPageInfo *out_pagetrue if page information was written, false on failure.
Clears the dirty flag of an atlas page.
LDK_API void ldk_ttf_clear_page_dirty(
LDKFontInstance *instance,
u32 page_index
);
LDKFontInstance *instanceu32 page_indexGets the scaled line height for a font instance.
LDK_API float ldk_ttf_get_line_height(LDKFontInstance *instance);
LDKFontInstance *instanceLine height in pixels, or 0 if instance is NULL.
Measures a null-terminated UTF-8 string.
LDK_API LDKTextSize ldk_ttf_measure_text_cstr(
LDKFontInstance *instance,
char const *text
);
LDKFontInstance *instancechar const *textText size in pixels.
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
);
LDKFontInstance *instancechar const *textu32 byte_countText size in pixels.
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
);
LDKFontInstance *instancechar const *textfloat max_widthWrapped text size in pixels.