Visualize.IR.Paint (Visualize v0.7.0)

Copy Markdown View Source

A paint that is not one color: the value of an element's :fill or :stroke when it is a gradient (spec/02 §2.1, #652, D-175).

id names the definition an SVG document holds for it — the SVG backend writes url(#id) and the producer puts definition/1 in a :defs — and geometry is in the units of the element's bounding box, 0 to 1 across it (SVG's objectBoundingBox): %{x1, y1, x2, y2} for a :linear gradient, the line it runs along, and %{cx, cy, r} for a :radial one, centered at its focus. stops are {at, color, opacity} in at order. A canvas builds the paint over each element's tight bounding box, bounds/1 (spec/09 §3.3.3).

iex> paint = %Visualize.IR.Paint{id: "fade", type: :linear,
...>   geometry: %{x1: 0.5, y1: 0.0, x2: 0.5, y2: 1.0},
...>   stops: [{0.0, "#3b6fa8", 0.8}, {1.0, "#3b6fa8", 0.1}]}
iex> Visualize.IR.Paint.url(paint)
"url(#fade)"

Summary

Types

A box {x, y, width, height} in an element's user units.

t()

Functions

The tight bounding box {x, y, width, height} of a shape element in its own user units: a path's curves and arcs by their extremes, never their control points — what SVG's objectBoundingBox is measured over. nil for an element that is not a shape, or a shape with no points.

The :linear_gradient or :radial_gradient element that defines the paint under its id, in objectBoundingBox units, with one :stop per stop; for a hatch, its :pattern: a tile of its spacing in user units, turned by its angle, holding its background and, centered, its line, its two lines or its dot (spec/14 §2.7, #673).

What SVG writes for the paint: url(#<id>).

Types

box()

@type box() :: {number(), number(), number(), number()}

A box {x, y, width, height} in an element's user units.

stop()

@type stop() :: {number(), String.t(), number()}

t()

@type t() :: %Visualize.IR.Paint{
  background: String.t() | nil,
  color: String.t() | nil,
  geometry: %{required(atom()) => number() | atom()},
  id: String.t(),
  stops: [stop()],
  type: :linear | :radial | :hatch
}

Functions

bounds(element)

@spec bounds(Visualize.IR.Element.t()) :: box() | nil

The tight bounding box {x, y, width, height} of a shape element in its own user units: a path's curves and arcs by their extremes, never their control points — what SVG's objectBoundingBox is measured over. nil for an element that is not a shape, or a shape with no points.

iex> Visualize.IR.Paint.bounds(Visualize.IR.Element.circle(10, 20, 5))
{5, 15, 10, 10}

definition(paint)

@spec definition(t()) :: Visualize.IR.Element.t()

The :linear_gradient or :radial_gradient element that defines the paint under its id, in objectBoundingBox units, with one :stop per stop; for a hatch, its :pattern: a tile of its spacing in user units, turned by its angle, holding its background and, centered, its line, its two lines or its dot (spec/14 §2.7, #673).

url(paint)

@spec url(t()) :: String.t()

What SVG writes for the paint: url(#<id>).