RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
text_shape.h File Reference

text_shape.h — opt-in bidi, font fallback and host shaping. More...

#include "shaper.h"
#include "bidi.h"
#include "fallback.h"
#include "draw_target.h"

Data Structures

struct  rmgui_text_glyph_t
 One positioned glyph, in visual paint order; clusters remain logical byte offsets into the original input, including across wraps. More...
struct  rmgui_text_shaped_line_t
 One visual line, with logical [start,end) and its consumed next offset. More...
struct  rmgui_text_shape_storage_t
 Caller-owned mutable workspace. More...
struct  rmgui_text_options_t
 NULL options at existing entry points preserves legacy behaviour. More...
struct  rmgui_text_shaped_t
 Borrowed workspace result. More...

Enumerations

enum  rmgui_text_caret_policy_t { RMGUI_TEXT_CARET_AUTO , RMGUI_TEXT_CARET_LOGICAL , RMGUI_TEXT_CARET_VISUAL }
 Arrow policy. More...
enum  rmgui_text_affinity_t { RMGUI_TEXT_AFFINITY_AFTER , RMGUI_TEXT_AFFINITY_BEFORE }
 Boundary association: the following or preceding logical cluster. More...

Functions

int rmgui_text_shape (const rmgui_font_t *font, const char *text, size_t length, int font_px, int max_w, const rmgui_text_options_t *options, rmgui_text_shaped_t *out)
 Shapes and wraps text using bidi -> fallback -> shaper, visually reordered separately on each line.
int rmgui_text_caret (const rmgui_text_shaped_t *text, size_t offset, rmgui_text_affinity_t affinity, int *x, int *y)
 Caret geometry at a cluster boundary.
int rmgui_text_hit (const rmgui_text_shaped_t *text, int x, int y, size_t *offset, rmgui_text_affinity_t *affinity)
 Nearest visual cluster edge on the nearest line; ties choose the earlier visual edge.
int rmgui_text_move (const rmgui_text_shaped_t *text, size_t offset, rmgui_text_affinity_t affinity, int direction, rmgui_text_caret_policy_t policy, size_t *out_offset, rmgui_text_affinity_t *out_affinity)
 Moves one cluster edge according to policy, preserving directional boundary affinity.
int rmgui_text_selection (const rmgui_text_shaped_t *text, size_t start, size_t end, rmgui_rect_t *rects, size_t capacity, size_t *count)
 Union of visual cluster pieces intersecting logical [start,end), one rect per contiguous piece per line.
int rmgui_text_shape_prepare_to (const rmgui_text_shaped_t *text, rmgui_target_t *target)
 Prepare glyph ids, including host substitutions, outside painting.
void rmgui_text_shape_draw_to (const rmgui_text_shaped_t *text, rmgui_target_t *target, rmgui_rect_t clip, int x, int y, rmgui_color_t color)
 Paint a prepared layout at (x,y).

Detailed Description

text_shape.h — opt-in bidi, font fallback and host shaping.

Enumeration Type Documentation

◆ rmgui_text_caret_policy_t

Arrow policy.

AUTO is visual in odd-level runs and logical elsewhere.

Enumerator
RMGUI_TEXT_CARET_AUTO 
RMGUI_TEXT_CARET_LOGICAL 
RMGUI_TEXT_CARET_VISUAL 

◆ rmgui_text_affinity_t

Boundary association: the following or preceding logical cluster.

Enumerator
RMGUI_TEXT_AFFINITY_AFTER 
RMGUI_TEXT_AFFINITY_BEFORE 

Function Documentation

◆ rmgui_text_shape()

int rmgui_text_shape ( const rmgui_font_t * font,
const char * text,
size_t length,
int font_px,
int max_w,
const rmgui_text_options_t * options,
rmgui_text_shaped_t * out )

Shapes and wraps text using bidi -> fallback -> shaper, visually reordered separately on each line.

max_w >= 0 (0 unwrapped). font_px > 0. Refuses malformed arguments, insufficient workspace, callback failure or geometry overflow with -1 and *out unchanged. Input may contain malformed UTF-8; maximal subparts become U+FFFD as in the legacy path.

◆ rmgui_text_caret()

int rmgui_text_caret ( const rmgui_text_shaped_t * text,
size_t offset,
rmgui_text_affinity_t affinity,
int * x,
int * y )

Caret geometry at a cluster boundary.

Interior ligature offsets snap to its leading edge for AFTER, trailing for BEFORE. Returns -1 unchanged for an out-of-range offset or NULL; empty text has the caret (0,0).

◆ rmgui_text_hit()

int rmgui_text_hit ( const rmgui_text_shaped_t * text,
int x,
int y,
size_t * offset,
rmgui_text_affinity_t * affinity )

Nearest visual cluster edge on the nearest line; ties choose the earlier visual edge.

Returns logical byte offset and edge affinity. -1 unchanged on invalid arguments.

◆ rmgui_text_move()

int rmgui_text_move ( const rmgui_text_shaped_t * text,
size_t offset,
rmgui_text_affinity_t affinity,
int direction,
rmgui_text_caret_policy_t policy,
size_t * out_offset,
rmgui_text_affinity_t * out_affinity )

Moves one cluster edge according to policy, preserving directional boundary affinity.

direction must be -1 or +1. Refuses invalid arguments unchanged; edges clamp. Logical movement skips ligature interiors.

◆ rmgui_text_selection()

int rmgui_text_selection ( const rmgui_text_shaped_t * text,
size_t start,
size_t end,
rmgui_rect_t * rects,
size_t capacity,
size_t * count )

Union of visual cluster pieces intersecting logical [start,end), one rect per contiguous piece per line.

A ligature is selected as a whole. NULL rects queries count; insufficient capacity returns -1 without changing count or rects. Coordinates relative to the text origin; line boxes have font_px+2 height. Empty ranges produce no rectangles.

◆ rmgui_text_shape_prepare_to()

int rmgui_text_shape_prepare_to ( const rmgui_text_shaped_t * text,
rmgui_target_t * target )

Prepare glyph ids, including host substitutions, outside painting.

May fill the existing allocating CPU raster cache; RECORD captures immutable coverage. Returns -1 on raster/resource failure, including CPU cache eviction during this call. RECORD storage can retain layouts larger than that cache. Fonts' caches may change on refusal; RECORD also latches its resource refusal.

◆ rmgui_text_shape_draw_to()

void rmgui_text_shape_draw_to ( const rmgui_text_shaped_t * text,
rmgui_target_t * target,
rmgui_rect_t clip,
int x,
int y,
rmgui_color_t color )

Paint a prepared layout at (x,y).

Every glyph must have been prepared for this target; CPU cache eviction requires preparation again. No allocation. Invalid/missing preparation or coordinate overflow refuses before CPU pixels change. RECORD failure remains latched for atomic submit. Images use legacy sizing.