Skip to content
modkitv0.2

text_layout.h

#include <modkit/text_layout.h>21 functions · 11 structs · 4 enums · 15 typedefs · 2 macros

Retained multilingual paragraph layout.

This package is available when MODKIT_HAS_SHAPING is enabled. Layouts own a copy of their UTF-8 text and style spans. Drawing scale is deliberately separate from layout size so zooming does not reshape or rewrap text.

Functions

mk_font_family_countfunction

uint16_t mk_font_family_count(mk_font_family_t family)

Perform the font family count operation.

ParameterTypeDescription
familymk_font_family_tValue for family.

Returns The resulting value.

mk_font_family_createfunction

mk_font_family_t mk_font_family_create(const mk_font_t *fonts, uint16_t font_count)

Create font family.

ParameterTypeDescription
fontsconst mk_font_t *Value for fonts.
font_countuint16_tNumber of font entries.

Returns The resulting handle or value.

mk_font_family_destroyfunction

void mk_font_family_destroy(mk_font_family_t family)

Destroy the font family.

ParameterTypeDescription
familymk_font_family_tValue for family.

mk_font_family_fontfunction

mk_font_t mk_font_family_font(mk_font_family_t family, uint16_t index)

Perform the font family font operation.

ParameterTypeDescription
familymk_font_family_tValue for family.
indexuint16_tZero-based index.

Returns The resulting handle or value.

mk_font_family_is_validfunction

bool mk_font_family_is_valid(mk_font_family_t family)

Test whether the font family is valid.

ParameterTypeDescription
familymk_font_family_tValue for family.

Returns True when the condition holds.

mk_font_family_updatefunction

bool mk_font_family_update(mk_font_family_t family, const mk_font_t *fonts, uint16_t font_count)

Update font family.

ParameterTypeDescription
familymk_font_family_tValue for family.
fontsconst mk_font_t *Value for fonts.
font_countuint16_tNumber of font entries.

Returns True when the operation succeeds.

mk_text_layout_cache_get_statsfunction

void mk_text_layout_cache_get_stats(mk_text_layout_cache_stats_t *stats)

Get stats from the text layout cache.

ParameterTypeDescription
statsmk_text_layout_cache_stats_t *Value for stats.

mk_text_layout_cache_reset_statsfunction

void mk_text_layout_cache_reset_stats(void)

Reset the stats for the text layout cache.

mk_text_layout_caret_rectfunction

bool mk_text_layout_caret_rect(mk_text_layout_t layout, uint32_t byte_offset, mk_text_caret_affinity_t affinity, mk_text_rect_t *rect)

Perform the text layout caret rect operation.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
byte_offsetuint32_tValue for byte offset.
affinitymk_text_caret_affinity_tValue for affinity.
rectmk_text_rect_t *Value for rect.

Returns True when the operation succeeds.

mk_text_layout_composition_rectsfunction

uint32_t mk_text_layout_composition_rects(mk_text_layout_t layout, uint32_t byte_start, uint32_t byte_end, float thickness, mk_text_rect_t *rects, uint32_t max_rects)

Return underline rectangles for an IME composition byte range.

The range is snapped to grapheme-safe caret stops.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
byte_startuint32_tValue for byte start.
byte_enduint32_tValue for byte end.
thicknessfloatValue for thickness.
rectsmk_text_rect_t *Value for rects.
max_rectsuint32_tValue for max rects.

Returns The resulting value.

mk_text_layout_createfunction

mk_text_layout_t mk_text_layout_create(const mk_text_layout_desc_t *desc)

Create text layout.

ParameterTypeDescription
descconst mk_text_layout_desc_t *Configuration descriptor.

Returns The resulting handle or value.

mk_text_layout_destroyfunction

void mk_text_layout_destroy(mk_text_layout_t layout)

Destroy the text layout.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.

mk_text_layout_drawfunction

void mk_text_layout_draw(mk_text_layout_t layout, float x, float y, float scale)

Draw inside mk_text_begin()/mk_text_end() without changing layout metrics.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
xfloatValue for x.
yfloatValue for y.
scalefloatValue for scale.

mk_text_layout_get_intrinsicsfunction

bool mk_text_layout_get_intrinsics(mk_text_layout_t layout, mk_text_layout_intrinsics_t *intrinsics)

Query shaped intrinsic widths for an existing layout.

Hard line breaks are honored; the current width, height, and overflow constraints are ignored.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
intrinsicsmk_text_layout_intrinsics_t *Value for intrinsics.

Returns True when the operation succeeds.

mk_text_layout_get_linefunction

bool mk_text_layout_get_line(mk_text_layout_t layout, uint32_t line_index, mk_text_line_metrics_t *line)

Get line from the text layout.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
line_indexuint32_tValue for line index.
linemk_text_line_metrics_t *Value for line.

Returns True when the operation succeeds.

mk_text_layout_get_metricsfunction

bool mk_text_layout_get_metrics(mk_text_layout_t layout, mk_text_layout_metrics_t *metrics)

Get metrics from the text layout.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
metricsmk_text_layout_metrics_t *Value for metrics.

Returns True when the operation succeeds.

mk_text_layout_hit_testfunction

bool mk_text_layout_hit_test(mk_text_layout_t layout, float x, float y, mk_text_hit_t *hit)

Perform the text layout hit test operation.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
xfloatValue for x.
yfloatValue for y.
hitmk_text_hit_t *Value for hit.

Returns True when the operation succeeds.

mk_text_layout_is_validfunction

bool mk_text_layout_is_valid(mk_text_layout_t layout)

Test whether the text layout is valid.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.

Returns True when the condition holds.

mk_text_layout_preparefunction

bool mk_text_layout_prepare(mk_text_layout_t layout, uint32_t budget_us)

Prepare shaping and raster data.

budget_us is a soft interactive budget; zero requests blocking preparation suitable for loading screens. A budgeted call returns true when preparation is complete and false when the caller should continue it on a later frame.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
budget_usuint32_tValue for budget us.

Returns True when the operation succeeds.

mk_text_layout_selection_rectsfunction

uint32_t mk_text_layout_selection_rects(mk_text_layout_t layout, uint32_t byte_start, uint32_t byte_end, mk_text_rect_t *rects, uint32_t max_rects)

Perform the text layout selection rects operation.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
byte_startuint32_tValue for byte start.
byte_enduint32_tValue for byte end.
rectsmk_text_rect_t *Value for rects.
max_rectsuint32_tValue for max rects.

Returns The resulting value.

mk_text_layout_updatefunction

bool mk_text_layout_update(mk_text_layout_t layout, const mk_text_layout_desc_t *desc)

Atomically replace layout content.

ParameterTypeDescription
layoutmk_text_layout_tValue for layout.
descconst mk_text_layout_desc_t *Configuration descriptor.

Returns True when the operation succeeds.

Structs

mk_font_familystruct

Data for font family.

FieldTypeDescription
idxuint16_tThe idx.
generationuint16_tThe generation.

mk_text_hitstruct

Data for text hit.

FieldTypeDescription
byte_offsetuint32_tThe byte offset.
line_indexuint32_tThe line index.
affinitymk_text_caret_affinity_tThe affinity.
trailingboolThe trailing.

mk_text_layoutstruct

Data for text layout.

FieldTypeDescription
idxuint16_tThe idx.
generationuint16_tThe generation.

mk_text_layout_cache_statsstruct

Data for text layout cache stats.

FieldTypeDescription
shaping_hitsuint64_tThe shaping hits.
shaping_missesuint64_tThe shaping misses.
layout_hitsuint64_tThe layout hits.
layout_missesuint64_tThe layout misses.
rasterizationsuint64_tThe rasterizations.
uploadsuint64_tThe uploads.
pagesuint64_tThe pages.
atlas_bytesuint64_tThe atlas bytes.
evictionsuint64_tThe evictions.
draw_batchesuint64_tThe draw batches.

mk_text_layout_descstruct

Data for text layout desc.

FieldTypeDescription
textconst char *The text.
text_lensize_tThe text len.
default_stylemk_text_span_style_tThe default style.
spansconst mk_text_style_span_t *The spans.
span_countuint32_tThe span count.
widthfloatThe width.
heightfloatThe height.
max_linesuint32_tThe max lines.
wrapmk_text_wrap_tThe wrap.
overflowmk_text_overflow_tThe overflow.
alignmk_text_paragraph_align_tThe align.
directionmk_text_direction_tThe direction.
localeconst char *The locale.
line_heightfloatThe line height.
tab_widthfloatThe tab width.

mk_text_layout_intrinsicsstruct

Widths derived from shaped text before applying a soft width constraint.

FieldTypeDescription
min_widthfloatThe min width.
preferred_widthfloatThe preferred width.

mk_text_layout_metricsstruct

Data for text layout metrics.

FieldTypeDescription
widthfloatThe width.
heightfloatThe height.
content_widthfloatThe content width.
content_heightfloatThe content height.
line_countuint32_tThe line count.
glyph_countuint32_tThe glyph count.
source_bytesuint32_tThe source bytes.
draw_batchesuint32_tThe draw batches.
truncatedboolThe truncated.

mk_text_line_metricsstruct

Data for text line metrics.

FieldTypeDescription
byte_startuint32_tThe byte start.
byte_enduint32_tThe byte end.
xfloatThe x.
baseline_yfloatThe baseline y.
widthfloatThe width.
ascenderfloatThe ascender.
descenderfloatThe descender.

mk_text_rectstruct

Data for text rect.

FieldTypeDescription
xfloatThe x.
yfloatThe y.
widthfloatThe width.
heightfloatThe height.
byte_startuint32_tThe byte start.
byte_enduint32_tThe byte end.

mk_text_span_stylestruct

Data for text span style.

FieldTypeDescription
familymk_font_family_tThe family.
size_pxfloatThe size px.
paintmk_text_style_tThe paint.
featuresconst mk_text_feature_t *The features.
feature_countuint16_tThe feature count.
axesconst mk_font_axis_value_t *The axes.
axis_countuint16_tThe axis count.
background_coloruint32_tThe background color.
underlineboolThe underline.
strike_throughboolThe strike through.

mk_text_style_spanstruct

Data for text style span.

FieldTypeDescription
byte_startuint32_tThe byte start.
byte_enduint32_tThe byte end.
stylemk_text_span_style_tThe style.

Enums

mk_text_caret_affinityenum

Values for text caret affinity.

ValueDescription
MK_TEXT_AFFINITY_UPSTREAMSelects upstream.
MK_TEXT_AFFINITY_DOWNSTREAMSelects downstream.

mk_text_overflowenum

Values for text overflow.

ValueDescription
MK_TEXT_OVERFLOW_VISIBLESelects visible.
MK_TEXT_OVERFLOW_CLIPSelects clip.
MK_TEXT_OVERFLOW_ELLIPSISSelects ellipsis.

mk_text_paragraph_alignenum

Values for text paragraph align.

ValueDescription
MK_TEXT_PARAGRAPH_STARTSelects start.
MK_TEXT_PARAGRAPH_CENTERSelects center.
MK_TEXT_PARAGRAPH_ENDSelects end.
MK_TEXT_PARAGRAPH_JUSTIFYSelects justify.

mk_text_wrapenum

Values for text wrap.

ValueDescription
MK_TEXT_WRAP_NONESelects none.
MK_TEXT_WRAP_WORDSelects word.
MK_TEXT_WRAP_GRAPHEMESelects grapheme.

Typedefs

mk_font_family_ttypedef

typedef struct mk_font_family mk_font_family_t

Data for font family.

mk_text_caret_affinity_ttypedef

typedef enum mk_text_caret_affinity mk_text_caret_affinity_t

Values for text caret affinity.

mk_text_hit_ttypedef

typedef struct mk_text_hit mk_text_hit_t

Data for text hit.

mk_text_layout_cache_stats_ttypedef

typedef struct mk_text_layout_cache_stats mk_text_layout_cache_stats_t

Data for text layout cache stats.

mk_text_layout_desc_ttypedef

typedef struct mk_text_layout_desc mk_text_layout_desc_t

Data for text layout desc.

mk_text_layout_intrinsics_ttypedef

typedef struct mk_text_layout_intrinsics mk_text_layout_intrinsics_t

Widths derived from shaped text before applying a soft width constraint.

mk_text_layout_metrics_ttypedef

typedef struct mk_text_layout_metrics mk_text_layout_metrics_t

Data for text layout metrics.

mk_text_layout_ttypedef

typedef struct mk_text_layout mk_text_layout_t

Data for text layout.

mk_text_line_metrics_ttypedef

typedef struct mk_text_line_metrics mk_text_line_metrics_t

Data for text line metrics.

mk_text_overflow_ttypedef

typedef enum mk_text_overflow mk_text_overflow_t

Values for text overflow.

mk_text_paragraph_align_ttypedef

typedef enum mk_text_paragraph_align mk_text_paragraph_align_t

Values for text paragraph align.

mk_text_rect_ttypedef

typedef struct mk_text_rect mk_text_rect_t

Data for text rect.

mk_text_span_style_ttypedef

typedef struct mk_text_span_style mk_text_span_style_t

Data for text span style.

mk_text_style_span_ttypedef

typedef struct mk_text_style_span mk_text_style_span_t

Data for text style span.

mk_text_wrap_ttypedef

typedef enum mk_text_wrap mk_text_wrap_t

Values for text wrap.

Macros

MK_FONT_FAMILY_INVALIDdefine

MK_FONT_FAMILY_INVALID

Invalid sentinel for font family.

MK_TEXT_LAYOUT_INVALIDdefine

MK_TEXT_LAYOUT_INVALID

Invalid sentinel for text layout.