Skip to content
modkitv0.2

shaping.h

#include <modkit/shaping.h>10 functions · 5 structs · 3 enums · 8 typedefs · 4 macros

Optional HarfBuzz-backed text shaping package.

A shaped run has one font, size, script, language, and direction. HarfBuzz performs glyph selection and positioning. Use text_layout.h for retained paragraph bidi, Unicode line breaking, fallback, and mixed styles.

Functions

mk_text_run_advancefunction

bool mk_text_run_advance(mk_text_run_t run, float *x_advance, float *y_advance)

Get total pen advance in modkit layout coordinates.

ParameterTypeDescription
runmk_text_run_tValue for run.
x_advancefloat *Value for x advance.
y_advancefloat *Value for y advance.

Returns True when the operation succeeds.

mk_text_run_boundsfunction

bool mk_text_run_bounds(mk_text_run_t run, mk_text_bounds_t *bounds)

Get the visible glyph bounds relative to the run origin.

ParameterTypeDescription
runmk_text_run_tValue for run.
boundsmk_text_bounds_t *Value for bounds.

Returns True when the operation succeeds.

mk_text_run_buildfunction

uint32_t mk_text_run_build(mk_text_run_t run, mk_glyph_quad *out_quads, uint32_t max_quads, mk_text_geometry *out_geom)

Build atlas-backed glyph quads without drawing.

ParameterTypeDescription
runmk_text_run_tValue for run.
out_quadsmk_glyph_quad *Receives the quads.
max_quadsuint32_tValue for max quads.
out_geommk_text_geometry *Receives the geom.

Returns The resulting value.

mk_text_run_createfunction

mk_text_run_t mk_text_run_create(mk_font_t font, const mk_text_shape_desc_t *desc)

Shape one uniform text run.

ParameterTypeDescription
fontmk_font_tValue for font.
descconst mk_text_shape_desc_t *Configuration descriptor.

Returns The resulting handle or value.

mk_text_run_destroyfunction

void mk_text_run_destroy(mk_text_run_t run)

Destroy the text run.

ParameterTypeDescription
runmk_text_run_tValue for run.

mk_text_run_drawfunction

float mk_text_run_draw(mk_text_run_t run, float x, float y, const mk_text_style_t *style, int align)

Draw a shaped run inside mk_text_begin()/mk_text_end().

Returns the run's horizontal advance.

ParameterTypeDescription
runmk_text_run_tValue for run.
xfloatValue for x.
yfloatValue for y.
styleconst mk_text_style_t *Value for style.
alignintValue for align.

Returns The resulting value.

mk_text_run_draw_instancesfunction

float mk_text_run_draw_instances(mk_text_run_t run, float x, float y, const mk_text_style_t *style, int align, const mk_text_glyph_instance_t *instances, uint32_t instance_count)

Draw a shaped run with optional one-to-one per-glyph transform and tint overrides.

Missing entries inherit identity and the run style.

ParameterTypeDescription
runmk_text_run_tValue for run.
xfloatValue for x.
yfloatValue for y.
styleconst mk_text_style_t *Value for style.
alignintValue for align.
instancesconst mk_text_glyph_instance_t *Value for instances.
instance_countuint32_tNumber of instance entries.

Returns The resulting value.

mk_text_run_glyphfunction

bool mk_text_run_glyph(mk_text_run_t run, uint32_t index, mk_shaped_glyph_t *glyph)

Copy one glyph.

ParameterTypeDescription
runmk_text_run_tValue for run.
indexuint32_tZero-based index.
glyphmk_shaped_glyph_t *Value for glyph.

Returns True when the operation succeeds.

mk_text_run_glyph_countfunction

uint32_t mk_text_run_glyph_count(mk_text_run_t run)

Perform the text run glyph count operation.

ParameterTypeDescription
runmk_text_run_tValue for run.

Returns The resulting value.

mk_text_run_is_validfunction

bool mk_text_run_is_valid(mk_text_run_t run)

Return whether a run handle currently refers to a live shaped run.

ParameterTypeDescription
runmk_text_run_tValue for run.

Returns True when the condition holds.

Structs

mk_shaped_glyphstruct

Positioned glyph output.

Coordinates use modkit layout space: +X right and +Y down. cluster is a UTF-8 byte offset into the input string.

FieldTypeDescription
glyph_iduint32_tThe glyph ID.
clusteruint32_tThe cluster.
x_advancefloatThe x advance.
y_advancefloatThe y advance.
x_offsetfloatThe x offset.
y_offsetfloatThe y offset.
flagsuint32_tThe flags.

mk_text_featurestruct

Data for text feature.

FieldTypeDescription
taguint32_tFour-byte OpenType tag, for example 'liga'.
valueuint32_tFeature value; 0 disables and 1 usually enables.
startuint32_tFirst UTF-8 byte offset, inclusive.
enduint32_tLast UTF-8 byte offset, exclusive, or GLOBAL_END.

mk_text_glyph_instancestruct

Optional overrides for one shaped glyph.

The affine matrix is [a,b,c,d,tx,ty] and is applied around the glyph's shaped pen origin.

FieldTypeDescription
transformfloatThe transform.
tintuint32_tThe tint.
flagsuint32_tThe flags.

mk_text_runstruct

Data for text run.

FieldTypeDescription
idxuint16_tThe idx.
generationuint16_tThe generation.

mk_text_shape_descstruct

Data for text shape desc.

FieldTypeDescription
textconst char *UTF-8 input.
text_lensize_tBytes, or 0 for a NUL-terminated string.
size_pxfloatPixel size, or 0 for the font default.
directionmk_text_direction_tAUTO asks HarfBuzz to infer direction.
scriptuint32_tISO 15924 tag, or 0 to infer it.
languageconst char *BCP-47 language, or NULL.
featuresconst mk_text_feature_t *Optional OpenType features.
feature_countuint32_tThe feature count.

Enums

mk_shaped_glyph_flagsenum

Values for shaped glyph flags.

ValueDescription
MK_SHAPED_GLYPH_UNSAFE_TO_BREAKSelects unsafe to break.
MK_SHAPED_GLYPH_UNSAFE_TO_CONCATSelects unsafe to concat.
MK_SHAPED_GLYPH_SAFE_TO_INSERT_TATWEELSelects safe to insert tatweel.

mk_text_directionenum

Values for text direction.

ValueDescription
MK_TEXT_DIRECTION_AUTOSelects auto.
MK_TEXT_DIRECTION_LTRSelects ltr.
MK_TEXT_DIRECTION_RTLSelects rtl.
MK_TEXT_DIRECTION_TTBSelects ttb.
MK_TEXT_DIRECTION_BTTSelects btt.

mk_text_glyph_instance_flagsenum

Values for text glyph instance flags.

ValueDescription
MK_TEXT_GLYPH_INSTANCE_TRANSFORMSelects transform.
MK_TEXT_GLYPH_INSTANCE_TINTSelects tint.

Typedefs

mk_shaped_glyph_flags_ttypedef

typedef enum mk_shaped_glyph_flags mk_shaped_glyph_flags_t

Values for shaped glyph flags.

mk_shaped_glyph_ttypedef

typedef struct mk_shaped_glyph mk_shaped_glyph_t

Positioned glyph output.

Coordinates use modkit layout space: +X right and +Y down. cluster is a UTF-8 byte offset into the input string.

mk_text_direction_ttypedef

typedef enum mk_text_direction mk_text_direction_t

Values for text direction.

mk_text_feature_ttypedef

typedef struct mk_text_feature mk_text_feature_t

Data for text feature.

mk_text_glyph_instance_flags_ttypedef

typedef enum mk_text_glyph_instance_flags mk_text_glyph_instance_flags_t

Values for text glyph instance flags.

mk_text_glyph_instance_ttypedef

typedef struct mk_text_glyph_instance mk_text_glyph_instance_t

Optional overrides for one shaped glyph.

The affine matrix is [a,b,c,d,tx,ty] and is applied around the glyph's shaped pen origin.

mk_text_run_ttypedef

typedef struct mk_text_run mk_text_run_t

Data for text run.

mk_text_shape_desc_ttypedef

typedef struct mk_text_shape_desc mk_text_shape_desc_t

Data for text shape desc.

Macros

MK_TEXT_FEATURE_GLOBAL_ENDdefine

MK_TEXT_FEATURE_GLOBAL_END

Constant for text feature global end.

MK_TEXT_GLYPH_INSTANCE_DEFAULTdefine

MK_TEXT_GLYPH_INSTANCE_DEFAULT

Constant for text glyph instance default.

MK_TEXT_RUN_INVALIDdefine

MK_TEXT_RUN_INVALID

Invalid sentinel for text run.

MK_TEXT_TAGdefine

MK_TEXT_TAG(a, b, c, d)

Four-byte OpenType/ISO 15924 tag in HarfBuzz byte order.