On this page

text_shape.h

Arabic joining through presentation forms B. With ISOLEN_TEXT_SHAPING off every call is an inline stub.

#include "isolenui/text/text_shape.h". The guide starts at Direction and bidi.

Arabic shaping

Explained in Direction and bidi.

text_shape_enabletext_shape_enabledtext_shape_wantedtext_shape_arabicISOLEN_TEXT_SHAPING

Example

bidi_text.cpp
#include "isolenui/gfx/gfx.h"
#include "isolenui/text/text_font.h"
#include "isolenui/text/text_shape.h"

// a font you own with the fallback atlas behind it for hebrew and arabic
struct fonts {
    text_font main;
    text_font fallback;
    gfx_font main_h;
};

static bool fonts_open(fonts* t, gfx_device* dev)
{
    if (!text_font_load(&t->main, "assets/objectivity.atlas")) {
        return false;
    }
    t->main_h = gfx_font_bind(dev, &t->main);
    // missing glyphs are measured from here and drawn with its handle
    if (text_font_load(&t->fallback, "assets/fallback.atlas")) {
        t->main.fallback = &t->fallback;
        t->main.fallback_handle = gfx_font_bind(dev, &t->fallback);
    }
    return t->main_h != GFX_NONE;
}

// one line, reordered, shaped and aligned to its start side
static float draw_title(const fonts* t, gfx_list* out, const char* utf8, float x, float width,
                        float baseline)
{
    return text_font_draw_fit_dir(&t->main, out, t->main_h, 0u, utf8, TEXT_FONT_TERMINATED, x,
                                  width, baseline, 18.0f, 0.0f, 0xffe6e6e6u, text_font_start,
                                  text_dir_auto);
}

// breaks stay logical, each line is drawn in visual order off one analysis
static void draw_paragraph(const fonts* t, gfx_list* out, const char* utf8, uint32_t len, float x,
                           float y, float width)
{
    const float px = 16.0f;
    text_line lines[32];
    const uint32_t n = text_font_wrap_dir(&t->main, 0u, utf8, len, px, 0.0f, width, lines, 32u,
                                          text_dir_rtl);
    const float step = text_font_line_height(&t->main, px);
    float base = y + text_font_ascent(&t->main, px);
    for (uint32_t i = 0; i < n && i < 32u; ++i) {
        text_font_draw_line_dir(&t->main, out, t->main_h, 0u, utf8, len, lines[i].start,
                                lines[i].len, x, width, base, px, 0.0f, 0xffe6e6e6u,
                                text_font_start, text_dir_rtl);
        base += step;
    }
}

// shaping can be switched off at run time, arabic then draws unjoined
static void set_shaping(bool on)
{
    text_shape_enable(on);
}

Last updated 23 October 2026