def clip.build
gralha-svg-render@0.1.0.1 · svg.bend:2517
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-xml-doc@0.1.0.1/xml.bend as XML
import gralha-css-style@0.1.0.1/css.bend as CSS
2517def clip.build(fuel: Nat, +xs: List<&2, XML.Element>, +all: List<&2, XML.Element>, +m: Matrix,
2518 +w: F32, +h: F32, +even: Bool, +scale: F32) -> Clip:
2519 match fuel:
2520 case 0n: clip.empty()
2521 case 1n+d:
2522 match xs:
2523 case Nil{}: clip.empty()
2524 case Con{XML.Element{n, attrs, kids, txt}, rest}:
2525 +dd = d
2526 +as = CSS.properties(attrs)
2527 +matrix = matrix.mul(matrix.mul(m, transform(XML.attr.get(as, "transform", ""), identity())),
2528 U.choose(Matrix, U.string.equal(n, "use"), translate(dimension(as, "x", w, "0"), dimension(as, "y", h, "0")), identity()))
2529 +rule = U.string.equal(XML.attr.get(as, "clip-rule", U.choose(String, even, "evenodd", "nonzero")), "evenodd")
2530 +es = shape.children(n, as, kids, w, h, local.tolerance(matrix, scale), XML.attr.get(as, "d", ""))
2531 +box = bounds(es, Bounds{1000000000.0, 1000000000.0, F32.neg(1000000000.0), F32.neg(1000000000.0)})
2532 U.branch(Clip, U.string.equal(XML.attr.get(as, "display", "inline"), "none"),
2533 _ => clip.build(1n+dd, rest, all, m, w, h, even, scale),
2534 _ => ClipUnion{ClipIntersect{
2535 ClipUnion{ClipShape{edge.tree(es), matrix.inverse(matrix), rule, cover.none()}, clip.build(1n+dd, kids, all, matrix, w, h, rule, scale)},
2536 clip.attach(as, all, box, matrix, nodes => mat => clip.build(dd, nodes, all, mat, w, h, False{}, scale))},
2537 clip.build(1n+dd, rest, all, m, w, h, even, scale)})