Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/fw/applib/fonts/codepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,3 @@ bool codepoint_is_special(const Codepoint codepoint) {
return (codepoint >= MIN_SPECIAL_CODEPOINT &&
codepoint <= MAX_SPECIAL_CODEPOINT);
}

bool codepoint_is_rtl(const Codepoint codepoint) {
return (codepoint >= MIN_ARABIC_CODEPOINT && codepoint <= MAX_ARABIC_CODEPOINT) ||
(codepoint >= MIN_HEBREW_CODEPOINT && codepoint <= MAX_HEBREW_CODEPOINT);
}
3 changes: 0 additions & 3 deletions src/fw/applib/fonts/codepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,3 @@ Codepoint emoji_shape_pair(const Codepoint curr_cp, const Codepoint next_cp,
// This is a least dirty hack to enable special rendering when a special codepoint is hit in the
// text being rendered
bool codepoint_is_special(const Codepoint codepoint);

// Check if a codepoint is from a right-to-left script (Arabic, Hebrew)
bool codepoint_is_rtl(const Codepoint codepoint);
16 changes: 7 additions & 9 deletions src/fw/applib/graphics/arabic_shaping.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

#include <string.h>

// Caps codepoints per shaping call. Sized to match walk_line's 128-byte
// shape buffer (~64 Arabic codepoints at 2 UTF-8 bytes each).
#define MAX_SHAPE_CODEPOINTS 64

// Connectivity flags for Arabic letters
#define JOIN_NONE 0x00 // Does not connect (space, punctuation)
#define JOIN_RIGHT_ONLY 0x01 // Connects only to the right (non-connecting letters)
Expand Down Expand Up @@ -304,13 +300,13 @@ bool arabic_is_transparent(Codepoint cp) {
}

size_t arabic_shape_text(const utf8_t *src, size_t src_len,
utf8_t *dest, size_t dest_size) {
if (src == NULL || dest == NULL || src_len == 0 || dest_size == 0) {
utf8_t *dest, size_t dest_size, Codepoint *cp_scratch) {
if (src == NULL || dest == NULL || cp_scratch == NULL || src_len == 0 || dest_size == 0) {
return 0;
}

// First pass: collect all codepoints into an array
Codepoint codepoints[MAX_SHAPE_CODEPOINTS];
// First pass: collect all codepoints into the caller's scratch array
Codepoint *codepoints = cp_scratch;
size_t num_codepoints = 0;

utf8_t *ptr = (utf8_t *)src;
Expand Down Expand Up @@ -355,7 +351,9 @@ size_t arabic_shape_text(const utf8_t *src, size_t src_len,
}
}

// Lam-Alef collapses two letters into one ligature glyph.
// Lam-Alef collapses two letters into one ligature glyph. Emoji pairs are
// NOT folded here: regional indicators must reach the bidi engine as their
// UCD class L, so the draw pass folds them after reordering.
bool consumed_next = false;
Codepoint shaped_cp = arabic_shape_pair(prev_cp, curr_cp, next_cp, &consumed_next);

Expand Down
10 changes: 9 additions & 1 deletion src/fw/applib/graphics/arabic_shaping.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Codepoint arabic_shape_codepoint(Codepoint prev_cp, Codepoint curr_cp, Codepoint
Codepoint arabic_shape_pair(Codepoint prev_cp, Codepoint curr_cp, Codepoint next_cp,
bool *consumed_next);

//! Caps codepoints per arabic_shape_text() call. The bidi render path shapes
//! per codepoint with paragraph context and no longer uses this helper; the
//! cap covers its remaining (test and utility) callers.
#define MAX_SHAPE_CODEPOINTS 96

//! Shape Arabic text by converting basic Arabic letters to their
//! contextual presentation forms based on position in words.
//!
Expand All @@ -59,7 +64,10 @@ Codepoint arabic_shape_pair(Codepoint prev_cp, Codepoint curr_cp, Codepoint next
//! @param src_len Length of source string in bytes
//! @param dest Destination buffer for shaped text
//! @param dest_size Size of destination buffer in bytes
//! @param cp_scratch Working array for at least MAX_SHAPE_CODEPOINTS
//! codepoints. Caller-provided so the render path can keep it off the
//! 2-4 KiB task stacks (it reuses the bidi heap scratch).
//! @return Number of bytes written to dest (excluding null terminator),
//! or 0 on failure
size_t arabic_shape_text(const utf8_t *src, size_t src_len,
utf8_t *dest, size_t dest_size);
utf8_t *dest, size_t dest_size, Codepoint *cp_scratch);
Loading