def viewbox.matrix

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

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

2635# SVG viewports establish local units and intersect their children with overflow clips.
2636def viewbox.matrix(+v: List<&2, F32>, +w: F32, +h: F32, +aspect: String) -> Matrix:
2637  +x = U.nth(v, 0n, 0.0)
2638  +y = U.nth(v, 1n, 0.0)
2639  +vw = U.nth(v, 2n, w)
2640  +vh = U.nth(v, 3n, h)
2641  +sx = (w / U.max(0.000001, vw) : F32)
2642  +sy = (h / U.max(0.000001, vh) : F32)
2643  +s = U.choose(F32, U.prefix(U.through(aspect, " "), "slice"), U.max(sx, sy), U.min(sx, sy))
2644  +tx = U.choose(F32, U.prefix(aspect, "xMin"), 0.0, U.choose(F32, U.prefix(aspect, "xMax"), 1.0, 0.5))
2645  +ty = U.choose(F32, U.prefix(U.drop(aspect, "xxxx"), "YMin"), 0.0,
2646    U.choose(F32, U.prefix(U.drop(aspect, "xxxx"), "YMax"), 1.0, 0.5))
2647  U.branch(Matrix, U.string.equal(aspect, "none"), _ => matrix.mul(scale(sx, sy), translate(F32.neg(x), F32.neg(y))),
2648    _ => matrix.mul(translate(((w - vw * s) * tx : F32), ((h - vh * s) * ty : F32)),
2649      matrix.mul(scale(s, s), translate(F32.neg(x), F32.neg(y)))))

Uses (20)

Used by (4)