def ttf.coverage.ranges
gralha-truetype@0.1.0.1 · font.bend:585
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
585def ttf.coverage.ranges(+b: Bin.Bytes, fuel: Nat, +base: U32, +lo: U32, +hi: U32, +gid: U32) -> U32:
586 match fuel:
587 case 0n: 0
588 case 1n+d:
589 +dd = d
590 +mid = U32.div((lo + hi : U32), 2)
591 +at = (base + mid * 6 : U32)
592 +start = ttf.u16(b, at)
593 +end = ttf.u16(b, (at + 2 : U32))
594 U.branch(U32, U32.is_ge(lo, hi), _ => 0,
595 _ => U.branch(U32, U32.is_lt(gid, start), _ => ttf.coverage.ranges(b, dd, base, lo, mid, gid),
596 _ => U.branch(U32, U32.is_gt(gid, end), _ => ttf.coverage.ranges(b, dd, base, (mid + 1 : U32), hi, gid),
597 _ => (ttf.u16(b, (at + 4 : U32)) + gid - start + 1 : U32))))