~/bend-docscommunity

font.bend relies on unsafe/foreign

raw source on the hub · import gralha-truetype@0.1.0.0/font.bend as Font

Font book: glyph outlines, advances, kerning and metrics.

3 imports
import Base
import gralha-text-scan@0.1.0.0/scan.bend as U
import gralha-bytes@0.1.0.0/bytes.bend as Bin

Types

type TTFont source · line 6 · raw

Data

type TTPairs source · line 9 · raw

Data

type TTFace source · line 14 · raw

Data

A TrueType face stays as its bytes plus table offsets; glyphs and kerning are read from it on demand (see font.glyph and font.kern at the end).

type FontGlyph source · line 17 · raw

Data

type FontBook source · line 22 · raw

Data

The glyph, kerning and metric maps hold text-format fonts (font.parse) and every face's metrics; faces holds the lazily read TrueType faces by number.

type TTPoint source · line 154 · raw

Data

type TTGlyph source · line 158 · raw

Data

Flat point list with the last point index of every contour.

type TTPlace source · line 282 · raw

Data

A component's placement: an affine 2x2 with either an explicit offset or two matched point indices (parent point a1 meets child point a2).

type TTFrame source · line 313 · raw

Data

A composite being assembled: the next component offset (0 once all are read), the points so far and how the finished glyph is placed into its parent.

Definitions

def font.empty source · line 25 · raw

FontBook

def font.missing source · line 28 · raw

FontGlyph

def font.glyph.result source · line 31 · raw

@got:Pair(Map<&2, FontGlyph>, FontGlyph) -> FontGlyph

def font.number.result source · line 35 · raw

@got:Pair(Map<&2, F32>, F32) -> F32

def font.metric source · line 39 · raw

@book:FontBook -> @face:U32 -> @name:String -> @fallback:F32 -> F32

def font.glyph.map source · line 43 · raw

@+glyphs:Map<&2, FontGlyph> -> @+face:U32 -> @ch:U32 -> FontGlyph

def font.kern.value source · line 46 · raw

@+specific:F32 -> @fallback:(@_:Unit -> F32) -> F32

def font.kern.map source · line 49 · raw

@+kerning:Map<&2, F32> -> @+face:U32 -> @left:U32 -> @leftClass:U32 -> @right:U32 -> @rightClass:U32 -> F32

def font.parse.glyph source · line 53 · raw

@key:String -> @scan:0xaff2b2d0565125a37b5df94a39451ef8/scan.Scan -> @book:FontBook -> FontBook

def font.parse.record source · line 60 · raw

@kind:String -> @+scan:0xaff2b2d0565125a37b5df94a39451ef8/scan.Scan -> @+book:FontBook -> FontBook

def font.parse.row source · line 67 · raw

@scan:0xaff2b2d0565125a37b5df94a39451ef8/scan.Scan -> @book:FontBook -> FontBook

def font.parse.line source · line 71 · raw

@scan:0xaff2b2d0565125a37b5df94a39451ef8/scan.Scan -> @book:FontBook -> @next:(@_:String -> @_:FontBook -> FontBook) -> FontBook

def ttf.u8 source · line 88 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> U32

def ttf.u16 source · line 91 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> U32

def ttf.u32 source · line 94 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> U32

def ttf.i16 source · line 97 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> F32

def ttf.i8 source · line 101 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> F32

def ttf.f2dot14 source · line 105 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> F32

def ttf.bit source · line 108 · raw

@+flags:U32 -> @+mask:U32 -> Bool

def ttf.table.find source · line 111 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+at:U32 -> @+tag:U32 -> U32

def ttf.table source · line 117 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+tag:U32 -> U32

Table offset by tag, read as a big-endian word; 0 when absent.

def ttf.font source · line 120 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> TTFont

def ttf.valid source · line 127 · raw

@+f:TTFont -> Bool

def ttf.units source · line 131 · raw

@+f:TTFont -> F32

def ttf.glyf source · line 135 · raw

@+f:TTFont -> U32

def ttf.advance source · line 139 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @+gid:U32 -> F32

def ttf.location source · line 146 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @+gid:U32 -> Pair(U32, U32)

Absolute offset of a glyph's data and its byte length (0 for empty or invalid glyphs).

def ttf.glyph.empty source · line 161 · raw

TTGlyph

def ttf.glyph.points source · line 164 · raw

@+g:TTGlyph -> List<&2, TTPoint>

def ttf.ends source · line 168 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+at:U32 -> List<&2, U32>

def ttf.last source · line 173 · raw

@xs:List<&2, U32> -> @+fallback:U32 -> U32

def ttf.after.flag source · line 178 · raw

@+f:U32 -> @got:Pair(List<&2, U32>, U32) -> Pair(List<&2, U32>, U32)

def ttf.flags source · line 183 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+at:U32 -> @+pending:U32 -> @+last:U32 -> Pair(List<&2, U32>, U32)

Point flags with repeat counts expanded; returns the flags and the next byte offset.

def ttf.after.coord source · line 195 · raw

@+v:F32 -> @got:Pair(List<&2, F32>, U32) -> Pair(List<&2, F32>, U32)

def ttf.coords source · line 200 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @flags:List<&2, U32> -> @+at:U32 -> @+prev:F32 -> @+short:U32 -> @+same:U32 -> Pair(List<&2, F32>, U32)

One coordinate axis: short bytes with a sign flag, repeated values, or signed word deltas.

def ttf.points source · line 211 · raw

@flags:List<&2, U32> -> @xs:List<&2, F32> -> @ys:List<&2, F32> -> List<&2, TTPoint>

def ttf.simple.y source · line 216 · raw

@flags:List<&2, U32> -> @xs:List<&2, F32> -> @ends:List<&2, U32> -> @+count:U32 -> @got:Pair(List<&2, F32>, U32) -> TTGlyph

def ttf.simple.x source · line 220 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+flags:List<&2, U32> -> @ends:List<&2, U32> -> @+count:U32 -> @got:Pair(List<&2, F32>, U32) -> TTGlyph

def ttf.simple.flags source · line 224 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @ends:List<&2, U32> -> @+count:U32 -> @got:Pair(List<&2, U32>, U32) -> TTGlyph

def ttf.simple source · line 230 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+g:U32 -> @+contours:U32 -> TTGlyph

A simple glyph at absolute offset g with the given contour count.

def ttf.point source · line 236 · raw

@pts:List<&2, TTPoint> -> @i:Nat -> TTPoint

def ttf.transform source · line 242 · raw

@pts:List<&2, TTPoint> -> @+a:F32 -> @+bb:F32 -> @+c:F32 -> @+d:F32 -> @+dx:F32 -> @+dy:F32 -> List<&2, TTPoint>

def ttf.append.points source · line 250 · raw

@xs:List<&2, TTPoint> -> @ys:List<&2, TTPoint> -> List<&2, TTPoint>

def ttf.shift.ends source · line 255 · raw

@ys:List<&2, U32> -> @+offset:U32 -> List<&2, U32>

def ttf.append.ends source · line 260 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> @+offset:U32 -> List<&2, U32>

def ttf.merge source · line 265 · raw

@parent:TTGlyph -> @child:TTGlyph -> TTGlyph

def ttf.xy source · line 271 · raw

@p:TTPoint -> Pair(F32, F32)

def ttf.matched source · line 275 · raw

@pp:Pair(F32, F32) -> @cp:Pair(F32, F32) -> Pair(F32, F32)

def ttf.place.identity source · line 285 · raw

TTPlace

def ttf.place.offset source · line 288 · raw

@+parent:TTGlyph -> @+child:TTGlyph -> @+place:TTPlace -> Pair(F32, F32)

def ttf.place.scaled source · line 296 · raw

@child:TTGlyph -> @+place:TTPlace -> TTGlyph

def ttf.place.shifted source · line 301 · raw

@child:TTGlyph -> @off:Pair(F32, F32) -> TTGlyph

def ttf.place source · line 307 · raw

@+parent:TTGlyph -> @+child:TTGlyph -> @+place:TTPlace -> TTGlyph

Scale the child, then offset it (explicitly or by point matching) and append it to the parent.

def ttf.component.place source · line 316 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> @+flags:U32 -> TTPlace

def ttf.component.next source · line 332 · raw

@+at:U32 -> @+flags:U32 -> U32

Byte offset of the component after the one at at, or 0 when it was the last.

def ttf.frame.at source · line 337 · raw

@+frame:TTFrame -> U32

def ttf.frame.acc source · line 341 · raw

@+frame:TTFrame -> TTGlyph

def ttf.assemble.pop source · line 346 · raw

@frame:TTFrame -> @parents:List<&2, TTFrame> -> List<&2, TTFrame>

Pop a finished frame into its parent frame.

def ttf.assemble.child source · line 352 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @frame:TTFrame -> @parents:List<&2, TTFrame> -> @loc:Pair(U32, U32) -> @+place:TTPlace -> @+next:U32 -> List<&2, TTFrame>

def ttf.assemble.step source · line 367 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @frame:TTFrame -> @parents:List<&2, TTFrame> -> List<&2, TTFrame>

Read the component at the frame's offset: a simple child is placed at once, a composite child opens a new frame above the advanced parent.

def ttf.assemble.next source · line 373 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @stack:List<&2, TTFrame> -> List<&2, TTFrame>

def ttf.stack.top source · line 381 · raw

@stack:List<&2, TTFrame> -> TTGlyph

def ttf.stack.done source · line 386 · raw

@stack:List<&2, TTFrame> -> Bool

def ttf.assemble source · line 393 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @fuel:Nat -> @+stack:List<&2, TTFrame> -> TTGlyph

Iterative composite assembly over an explicit frame stack; fuel bounds the component count.

def ttf.glyph.at source · line 398 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @loc:Pair(U32, U32) -> TTGlyph

def ttf.glyph source · line 407 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+f:TTFont -> @+gid:U32 -> TTGlyph

def ttf.pair source · line 412 · raw

@p:TTPoint -> String

def ttf.mid source · line 416 · raw

@a:TTPoint -> @b:TTPoint -> TTPoint

def ttf.walk.on source · line 421 · raw

@p:TTPoint -> @pending:Maybe<&2, TTPoint> -> String

def ttf.walk.between source · line 426 · raw

@c:TTPoint -> @p:TTPoint -> String

def ttf.walk.off source · line 433 · raw

@p:TTPoint -> @pending:Maybe<&2, TTPoint> -> String

An off-curve point after another emits the implied on-curve midpoint between them.

def ttf.walk.close source · line 438 · raw

@pending:Maybe<&2, TTPoint> -> @+start:TTPoint -> String

def ttf.walk source · line 443 · raw

@pts:List<&2, TTPoint> -> @+pending:Maybe<&2, TTPoint> -> @+start:TTPoint -> String

def ttf.init source · line 454 · raw

@pts:List<&2, TTPoint> -> List<&2, TTPoint>

def ttf.last.point source · line 460 · raw

@pts:List<&2, TTPoint> -> @fallback:TTPoint -> TTPoint

def ttf.contour.implied source · line 465 · raw

@+start:TTPoint -> @first:TTPoint -> @rest:List<&2, TTPoint> -> String

def ttf.contour.last source · line 470 · raw

@+first:TTPoint -> @+rest:List<&2, TTPoint> -> @last:TTPoint -> String

A contour starts at its first on-curve point; when the first point is off-curve, the last point starts it if on-curve, else the implied midpoint between last and first.

def ttf.contour.off source · line 478 · raw

@+first:TTPoint -> @+rest:List<&2, TTPoint> -> String

def ttf.contour source · line 481 · raw

@pts:List<&2, TTPoint> -> String

def ttf.take source · line 492 · raw

@n:Nat -> @pts:List<&2, TTPoint> -> List<&2, TTPoint>

def ttf.drop source · line 498 · raw

@n:Nat -> @pts:List<&2, TTPoint> -> List<&2, TTPoint>

def ttf.outline source · line 513 · raw

@g:TTGlyph -> String

def ttf.pairs.empty source · line 520 · raw

TTPairs

Format 1 subtables list specific glyph pairs; the first format 2 subtable supplies classes.

def ttf.pairs.add1 source · line 523 · raw

@+sub:U32 -> @acc:TTPairs -> TTPairs

def ttf.pairs.add2 source · line 527 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @acc:TTPairs -> TTPairs

def ttf.pairs.unclassed source · line 531 · raw

@+acc:TTPairs -> Bool

def ttf.pairs.add source · line 535 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @+acc:TTPairs -> TTPairs

def ttf.pairs.any.list source · line 540 · raw

@specific:List<&2, U32> -> @+classes:U32 -> Bool

def ttf.pairs.any source · line 545 · raw

@+p:TTPairs -> Bool

def ttf.pairs.subtables source · line 549 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+lookup:U32 -> @+at:U32 -> @+kind:U32 -> @+acc:TTPairs -> TTPairs

def ttf.pairs.lookups source · line 560 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+list:U32 -> @+at:U32 -> TTPairs

The first lookup holding pair subtables supplies both kinds of kerning.

def ttf.pairs source · line 568 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> TTPairs

def ttf.coverage.array source · line 574 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @fuel:Nat -> @+base:U32 -> @+lo:U32 -> @+hi:U32 -> @+gid:U32 -> U32

Coverage index plus one (0 when absent), by binary search over sorted glyphs or ranges.

def ttf.coverage.ranges source · line 585 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @fuel:Nat -> @+base:U32 -> @+lo:U32 -> @+hi:U32 -> @+gid:U32 -> U32

def ttf.coverage source · line 599 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+cov:U32 -> @+gid:U32 -> U32

def ttf.coverage.walk source · line 604 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+at:U32 -> @+index:U32 -> U32

def ttf.coverage.glyph source · line 614 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+cov:U32 -> @+index:U32 -> U32

The glyph at a coverage index (format 2 walks its ranges).

def ttf.classdef.ranges source · line 618 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @fuel:Nat -> @+base:U32 -> @+lo:U32 -> @+hi:U32 -> @+gid:U32 -> U32

def ttf.classdef source · line 631 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+cd:U32 -> @+gid:U32 -> U32

def ttf.left source · line 639 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+pairs:TTPairs -> @+gid:U32 -> U32

def ttf.right source · line 643 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+pairs:TTPairs -> @+gid:U32 -> U32

def ttf.cmap.score source · line 651 · raw

@+platform:U32 -> @+encoding:U32 -> U32

def ttf.cmap.pick source · line 658 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+cmap:U32 -> @+at:U32 -> @+best:U32 -> @+score:U32 -> U32

def ttf.cmap4.indexed source · line 668 · raw

@+g:U32 -> @+delta:U32 -> U32

def ttf.cmap4.glyph source · line 671 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+cp:U32 -> @+start:U32 -> @+delta:U32 -> @+roAt:U32 -> @+ro:U32 -> U32

def ttf.cmap4.find source · line 677 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @fuel:Nat -> @+sub:U32 -> @+lo:U32 -> @+hi:U32 -> @+cp:U32 -> U32

Glyph index of a code point through the picked subtable: a binary search over format 4 segments (first end code at or above the code point) or format 12 groups.

def ttf.cmap4.gid source · line 686 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @+cp:U32 -> U32

def ttf.cmap12.find source · line 695 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @fuel:Nat -> @+at:U32 -> @+lo:U32 -> @+hi:U32 -> @+cp:U32 -> U32

def ttf.cmap12.gid source · line 704 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @+cp:U32 -> U32

def ttf.cmap.gid source · line 711 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @+cp:U32 -> U32

def ttf.cmap.subtable source · line 718 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> U32

The best Unicode subtable (formats 4 and 12), 0 when the font has none.

def ttf.bits source · line 724 · raw

@+v:U32 -> U32

def ttf.value.size source · line 728 · raw

@+vf:U32 -> U32

A value record holds two bytes per set format bit; XAdvance follows the two placement fields.

def ttf.xadvance source · line 731 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+at:U32 -> @+vf:U32 -> F32

def ttf.kern.records source · line 735 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @n:Nat -> @+at:U32 -> @+vf1:U32 -> @+vf2:U32 -> @+right:U32 -> F32

A format 1 pair set: the record whose second glyph matches, 1000000 when none.

def ttf.kern.subtable source · line 742 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @+left:U32 -> @+right:U32 -> F32

def ttf.kern.specific source · line 750 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @subs:List<&2, U32> -> @+left:U32 -> @+right:U32 -> F32

Every format 1 subtable in turn; the first pair found wins.

def ttf.kern.classes source · line 758 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+sub:U32 -> @+leftClass:U32 -> @+rightClass:U32 -> F32

The format 2 class grid; leftClass counts from one (0 means uncovered).

def ttf.kern source · line 767 · raw

@+fc:TTFace -> @+left:U32 -> @+leftClass:U32 -> @+right:U32 -> @+rightClass:U32 -> F32

def ttf.metric source · line 774 · raw

@+face:U32 -> @+name:String -> @+value:F32 -> @book:FontBook -> FontBook

def ttf.metrics source · line 778 · raw

@+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+face:U32 -> @+os2:U32 -> @+units:F32 -> @book:FontBook -> FontBook

def font.ttf source · line 790 · raw

@+face:U32 -> @+b:0xb4c178c822e0e37d625a581d728097d3/bytes.Bytes -> @+book:FontBook -> FontBook

Adds one face from TrueType bytes: the face record for on-demand glyphs and kerning, and its OS/2 metrics. Fonts without glyf/loca/hmtx leave the book unchanged.

def font.ttf.base64 source · line 797 · raw

@+face:U32 -> @+text:String -> @book:FontBook -> FontBook

def font.face.absent source · line 802 · raw

TTFace

def font.face.result source · line 805 · raw

@got:Pair(Map<&2, TTFace>, TTFace) -> TTFace

def font.face source · line 809 · raw

@+faces:Map<&2, TTFace> -> @+face:U32 -> TTFace

def font.face.present source · line 812 · raw

@+fc:TTFace -> Bool

def ttf.lookup source · line 818 · raw

@+fc:TTFace -> @+ch:U32 -> FontGlyph

A glyph read on demand: cmap to glyph index (0, the missing glyph, when unmapped), then advance, outline and kerning classes from the tables.

def font.glyph source · line 823 · raw

@+book:FontBook -> @+face:U32 -> @+ch:U32 -> FontGlyph

def font.kern source · line 828 · raw

@+book:FontBook -> @+face:U32 -> @+left:U32 -> @+leftClass:U32 -> @+right:U32 -> @+rightClass:U32 -> F32

Unsafe

unsafe font.parse source · line 76 · raw

@s:String -> @book:FontBook -> FontBook

unsafe ttf.contours source · line 505 · raw

@+pts:List<&2, TTPoint> -> @ends:List<&2, U32> -> @+index:U32 -> String