A paint that is not one color (spec/10 §1.4), copied from visualize's
Visualize.IR.Paint: the value of a node's :fill or :stroke when it is a gradient
or a hatch (visualize spec/02 §2.1, #652, D-175).
%Macaw.Draw.IR.Paint{id, type, geometry, stops, color, background}: a :linear
gradient (%{x1, y1, x2, y2} in box units, 0 to 1 across the node's bounding box),
a :radial one (%{cx, cy, r}, focused at its center), or a :hatch
(%{pattern, angle, spacing, width} in user units, pattern :lines, :crosshatch or
:dots, drawn in color over background, nil for none). A gradient's stops are
{at, color, opacity} in at order; every color is a %Macaw.Layers.Color{} or a
string the theme resolved (macaw_layers 04), written by Macaw.Layers.Color.to_css/1
where a target writes text.
iex> paint = %Macaw.Draw.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> Macaw.Draw.IR.Paint.url(paint)
"url(#fade)"
Summary
Types
A box {x, y, width, height} in a node's user units.
A refusal: faults with their paths.
A gradient stop: where it is, 0 to 1, its color and its opacity.
Functions
The tight bounding box {x, y, width, height} of a geometric node in its own user units
(spec/10 §1.4): a path's curves and arcs by their extremes, never their control points,
what SVG's objectBoundingBox is measured over. nil for a node without geometry, a
shape with no points, or one whose geometry is not numbers.
The definition the paint's id names (spec/10 §1.4): a :linear_gradient or
:radial_gradient with gradientUnits="objectBoundingBox" and one :stop per stop,
or, for a hatch, its :pattern tile in userSpaceOnUse units, its spacing square,
turned by its angle, holding its background and, centered, its line, its two lines or
its dot (visualize spec/14 §2.7, #673). A paint whose geometry lacks a key its type
reads is {[:geometry], {:missing, key}}.
What SVG writes for the paint: url(#<id>).
Types
A box {x, y, width, height} in a node's user units.
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
@type stop() :: {number(), Macaw.Layers.Color.t() | String.t(), number()}
A gradient stop: where it is, 0 to 1, its color and its opacity.
@type t() :: %Macaw.Draw.IR.Paint{ background: Macaw.Layers.Color.t() | String.t() | nil, color: Macaw.Layers.Color.t() | String.t() | nil, geometry: %{required(atom()) => number() | atom()}, id: String.t(), stops: [stop()], type: :linear | :radial | :hatch }
Functions
@spec bounds(Macaw.Draw.IR.Element.t()) :: box() | nil | error()
The tight bounding box {x, y, width, height} of a geometric node in its own user units
(spec/10 §1.4): a path's curves and arcs by their extremes, never their control points,
what SVG's objectBoundingBox is measured over. nil for a node without geometry, a
shape with no points, or one whose geometry is not numbers.
iex> Macaw.Draw.IR.Paint.bounds(Macaw.Draw.IR.Element.circle(10, 20, 5))
{5, 15, 10, 10}
@spec definition(t()) :: Macaw.Draw.IR.Element.t() | error()
The definition the paint's id names (spec/10 §1.4): a :linear_gradient or
:radial_gradient with gradientUnits="objectBoundingBox" and one :stop per stop,
or, for a hatch, its :pattern tile in userSpaceOnUse units, its spacing square,
turned by its angle, holding its background and, centered, its line, its two lines or
its dot (visualize spec/14 §2.7, #673). A paint whose geometry lacks a key its type
reads is {[:geometry], {:missing, key}}.
iex> paint = %Macaw.Draw.IR.Paint{id: "h", type: :hatch, color: "#333",
...> geometry: %{pattern: :lines, angle: 45, spacing: 6, width: 1}}
iex> %{type: :pattern, attrs: attrs} = Macaw.Draw.IR.Paint.definition(paint)
iex> {attrs.pattern_units, attrs.pattern_transform}
{"userSpaceOnUse", "rotate(45)"}
What SVG writes for the paint: url(#<id>).