def text.length.fit
gralha-svg-render@0.1.0.1 · svg.bend:3486
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
3486def text.length.fit(+result: TextLayout, +m: TextMeasure, +target: F32, +stretch: Bool, +skip: String) -> TextLayout:
3487 TextLayout{nodes, cursor} = result
3488 TextMeasure{count, lo, hi, extra, fixed} = m
3489 +natural = (hi - lo - extra : F32)
3490 +free = (natural - fixed : F32)
3491 +ratio = U.choose(F32, stretch && F32.is_gt(free, 0.0), (U.max(0.0, (target - fixed : F32)) / U.max(free, 0.000001) : F32), 1.0)
3492 +step = U.choose(F32, Bool.not(stretch) && U32.is_gt(count, 1), ((target - natural) / U.max(1.0, (U32.to_f32(count) - 1.0 : F32)) : F32), 0.0)
3493 +delta = U.choose(F32, stretch, (free * (ratio - 1.0) - extra : F32), U.choose(F32, U32.is_gt(count, 1), (target - natural - extra : F32), 0.0))
3494 U.branch(TextLayout, U32.is_gt(count, 0) && F32.is_gt(natural, 0.0),
3495 _ => text.length.finish(text.fit.nodes(nodes, lo, ratio, step, skip, 0, 0.0), cursor, delta), _ => result)