def text.place

gralha-svg-render@0.1.0.1 · svg.bend:3374

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-truetype@0.1.0.1/font.bend as Font

3374def text.place(+cursor: TextCursor, +font: TextFont, +glyph: Font.FontGlyph, +pos: TextPosition, +ch: U32) -> TextLayout:
3375  TextCursor{oldx, oldy, index, oldchunk, start, oldanchor, prev, pc, pf, ps, seen, wasSpace, trailing, spacing, chunks} = cursor
3376  TextFont{size, face, weight, slant, anchor, letter, word, shift, baseline, kern, preserve, book} = font
3377  Font.FontGlyph{advance, outline, gid, leftClass, rightClass} = glyph
3378  TextPosition{TextValue{xx, setx}, TextValue{yy, sety}, TextValue{dx, setdx}, TextValue{dy, setdy}, TextValue{angle, seta}} = pos
3379  +fresh = setx || sety || Bool.not(seen)
3380  +factor = (size / 1000.0 : F32)
3381  +kerning = U.choose(F32, kern && Bool.not(fresh) && U32.is_eq(face, pf) && F32.is_eq(size, ps),
3382    (Font.font.kern(book, face, prev, pc, gid, rightClass) * factor : F32), 0.0)
3383  +x = (U.choose(F32, setx, xx, oldx) + dx + kerning : F32)
3384  +y = (U.choose(F32, sety, yy, oldy) + dy : F32)
3385  +chunk = U.choose(U32, fresh, U32.inc(oldchunk), oldchunk)
3386  +blank = U32.is_eq(ch, 32)
3387  +width = (advance * factor + letter + U.choose(F32, blank, word, 0.0) : F32)
3388  TextLayout{Con{text.glyph.node(outline, advance, width, (letter + U.choose(F32, blank, word, 0.0) : F32), x, matrix.mul(translate(x, (y + text.baseline(font) : F32)),
3389    matrix.mul(rotate(angle), scale(factor, F32.neg(factor)))), chunk, index), Nil{}},
3390    TextCursor{(x + width : F32), y, U32.inc(index), chunk, U.choose(F32, fresh, x, start), U.choose(String, fresh, anchor, oldanchor),
3391      gid, leftClass, face, size, True{}, blank, U.choose(F32, blank && Bool.not(preserve), width, 0.0), U.choose(F32, blank && Bool.not(preserve), spacing, letter),
3392      U.choose(List<&2, TextChunk>, fresh, text.chunk(cursor), chunks)}}

Uses (31)

Used by (1)