def ttf.cmap4.find

gralha-truetype@0.1.0.1 · font.bend:675

import gralha-truetype@0.1.0.1/font.bend as Font
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-bytes@0.1.0.1/bytes.bend as Bin

675# Glyph index of a code point through the picked subtable: a binary search over
676# format 4 segments (first end code at or above the code point) or format 12 groups.
677def ttf.cmap4.find(+b: Bin.Bytes, fuel: Nat, +sub: U32, +lo: U32, +hi: U32, +cp: U32) -> U32:
678  match fuel:
679    case 0n: lo
680    case 1n+d:
681      +dd = d
682      +mid = U32.div((lo + hi : U32), 2)
683      U.branch(U32, U32.is_ge(lo, hi), _ => lo,
684        _ => U.branch(U32, U32.is_lt(ttf.u16(b, (sub + 14 + mid * 2 : U32)), cp), _ => ttf.cmap4.find(b, dd, sub, (mid + 1 : U32), hi, cp), _ => ttf.cmap4.find(b, dd, sub, lo, mid, cp)))

Uses (10)

Used by (1)