def pattern.tile

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

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
import gralha-image@0.1.0.1/image.bend as Img

2986def pattern.tile(e: XML.Element, box: Bounds, +w: F32, +h: F32, opacity: F32,
2987  build: String -> F32 -> List<&2, XML.Element> -> Matrix -> F32 -> F32 -> List<&2, Scene<Brush>>, +pixels: F32) -> Brush:
2988  XML.Element{n, attrs, kids, txt} = e
2989  Bounds{x0, y0, x1, y1} = box
2990  +as = CSS.properties(attrs)
2991  +bx = x0
2992  +by = y0
2993  +bw = (x1 - bx : F32)
2994  +bh = (y1 - by : F32)
2995  +user = U.string.equal(XML.attr.get(as, "patternUnits", "objectBoundingBox"), "userSpaceOnUse")
2996  +contentUser = U.string.equal(XML.attr.get(as, "patternContentUnits", "userSpaceOnUse"), "userSpaceOnUse")
2997  +uw = U.choose(F32, user, w, 1.0)
2998  +uh = U.choose(F32, user, h, 1.0)
2999  +width = dimension(as, "width", uw, "0")
3000  +height = dimension(as, "height", uh, "0")
3001  +view = U.numbers(XML.attr.get(as, "viewBox", ""))
3002  +hasView = Bool.not(U.string.equal(XML.attr.get(as, "viewBox", ""), ""))
3003  +vw = U.choose(F32, hasView, U.nth(view, 2n, 0.0), U.choose(F32, contentUser, w, 1.0))
3004  +vh = U.choose(F32, hasView, U.nth(view, 3n, 0.0), U.choose(F32, contentUser, h, 1.0))
3005  +units = U.choose(Matrix, user, identity(), matrix.mul(translate(bx, by), scale(bw, bh)))
3006  +content = U.choose(Matrix, hasView,
3007    viewbox.matrix(view, width, height, XML.attr.get(as, "preserveAspectRatio", "xMidYMid meet")),
3008    scale((U.choose(F32, contentUser, 1.0, bw) / U.choose(F32, user, 1.0, U.max(bw, 0.0000001)) : F32),
3009      (U.choose(F32, contentUser, 1.0, bh) / U.choose(F32, user, 1.0, U.max(bh, 0.0000001)) : F32)))
3010  U.branch(Brush, F32.is_gt(width, 0.0) && F32.is_gt(height, 0.0) && F32.is_gt(vw, 0.0) && F32.is_gt(vh, 0.0)
3011      && (user || (F32.is_gt(bw, 0.0) && F32.is_gt(bh, 0.0))),
3012    _ => pattern.paint(build(XML.attr.get(as, "id", ""))((pixels * matrix.norm(pattern.frame(as, units, uw, uh)) : F32))(Con{XML.Element{"g", Con{XML.Attr{"display", "inline"}, as}, kids, txt}, Nil{}})(content)(vw)(vh),
3013      matrix.inverse(pattern.frame(as, units, uw, uh)), width, height, opacity),
3014    _ => Solid{Img.clear(), Img.clear()})

Uses (35)

Used by (1)