Scenic.FromSVG (scenic_from_svg v0.1.0-rc.0)

Derives Scenic.Primitives from Scalable Vector Graphics (SVG).

Summary

Functions

Converts the drawing primitive into a deferred graph.

Converts the SVG into a deferred graph.

Parses the SVG into a (complex) drawing primitive. As :group is a drawing primitive, this returns a single primitive.

Types

@type prim() ::
  {:rect, {Float.t(), Float.t()}, prim_opts()}
  | {:circle, Float.t(), prim_opts()}
  | {:ellipse, {Float.t(), Float.t()}, prim_opts()}
  | {:text, String.t(), prim_opts()}
  | {:path, [Scenic.Primitive.Path.cmd()], prim_opts()}
  | {:group, [prim()], prim_opts()}
@type prim_opts() :: [any()]

Functions

@spec prim_spec(prim()) :: Scenic.Graph.deferred()

Converts the drawing primitive into a deferred graph.

@spec svg_spec(binary()) :: Scenic.Graph.deferred()

Converts the SVG into a deferred graph.

Link to this function

svg_to_prim(svg)

@spec svg_to_prim(binary()) :: prim()

Parses the SVG into a (complex) drawing primitive. As :group is a drawing primitive, this returns a single primitive.

Examples

iex> ~s(
...>     <svg>
...>       <rect x="10" y="10" width="100" height="100" style="fill:#ff0000;" />
...>       <text x="80" y="80">
...>          <tspan x="80" y="80" style="font-size:64px;fill:#000000">Hello</tspan>
...>       </text>
...>       <circle style="fill:#ad1c1c;fill-opacity:0.71" cx="180" cy="180" r="20" />
...>       <g style="fill:white; stroke-width: 2; stroke: black;">
...>         <path d="m 458.94046,243.85936 h 40 l 20,34.64 -20,34.64 h -40 l -20,-34.64 z" />
...>         <path d="m 218.94046,243.85936 h 40 l 20,34.64 -20,34.64 h -40 l -20,-34.64 z" />
...>       </g>
...>     </svg>
...> )
...> |> Scenic.FromSVG.svg_to_prim()
{:group,
 [
   {:rect, {100.0, 100.0}, [fill: {255, 0, 0, 255}, t: {10.0, 10.0}]},
   {:group,
    [
      {:text, "Hello",
       [fill: {0, 0, 0, 255}, font_size: 64, text_align: :left, font: :roboto, t: {80, 80}]}
    ], []},
   {:circle, 20.0, [fill: {173, 28, 28, 181}, t: {180.0, 180.0}]},
   {:group,
    [
      {:path,
       [
         :begin,
         {:move_to, 458.94046, 243.85936},
         {:line_to, 498.94046, 243.85936},
         {:line_to, 518.94046, 278.49936},
         {:line_to, 498.94046000000003, 313.13936},
         {:line_to, 458.94046000000003, 313.13936},
         {:line_to, 438.94046000000003, 278.49936},
         :close_path
       ], []},
      {:path,
       [
         :begin,
         {:move_to, 218.94046, 243.85936},
         {:line_to, 258.94046000000003, 243.85936},
         {:line_to, 278.94046000000003, 278.49936},
         {:line_to, 258.94046000000003, 313.13936},
         {:line_to, 218.94046000000003, 313.13936},
         {:line_to, 198.94046000000003, 278.49936},
         :close_path
       ], []}
    ], [{:fill, {255, 255, 255, 255}}, {:stroke, {2, {0, 0, 0}}}]}
 ], []}