Podium.Freeform (Podium v0.3.0)

Copy Markdown View Source

Builder for freeform (custom geometry) shapes.

Freeform shapes let you draw custom vector paths using a builder pattern. Start with new/3, add segments with line_to/3 and move_to/3, and close contours with close/1. Add the finished shape to a slide with Podium.add_freeform/3.

Example

freeform =
  Podium.Freeform.new({1, :inches}, {1, :inches})
  |> Podium.Freeform.line_to({3, :inches}, {1, :inches})
  |> Podium.Freeform.line_to({2, :inches}, {3, :inches})
  |> Podium.Freeform.close()

slide = Podium.add_freeform(slide, freeform, fill: "4472C4")

See the Connectors and Freeform Shapes guide for more examples.

Summary

Functions

Adds multiple line segments from a list of {x, y} vertices.

Computes the bounding box in local coordinates (before scale). Returns {min_x, min_y, dx, dy}.

Closes the current contour.

Adds a line segment to (x, y).

Starts a new contour at (x, y) without drawing a line.

Creates a new freeform builder starting at (start_x, start_y).

Returns operations with coordinates translated so the bounding box origin is (0, 0). Includes the initial move_to from the start point.

Types

t()

@type t() :: %Podium.Freeform{
  operations: [
    {:line_to, number(), number()} | {:move_to, number(), number()} | :close
  ],
  start_x: number(),
  start_y: number(),
  x_scale: float(),
  y_scale: float()
}

Functions

add_line_segments(fb, vertices, opts \\ [])

@spec add_line_segments(
  t(),
  [{Podium.dimension() | number(), Podium.dimension() | number()}],
  keyword()
) :: t()

Adds multiple line segments from a list of {x, y} vertices.

Options

  • :close - if true, closes the contour after the last segment

bounding_box(fb)

@spec bounding_box(t()) :: {number(), number(), number(), number()}

Computes the bounding box in local coordinates (before scale). Returns {min_x, min_y, dx, dy}.

close(fb)

@spec close(t()) :: t()

Closes the current contour.

line_to(fb, x, y)

@spec line_to(t(), Podium.dimension() | number(), Podium.dimension() | number()) ::
  t()

Adds a line segment to (x, y).

move_to(fb, x, y)

@spec move_to(t(), Podium.dimension() | number(), Podium.dimension() | number()) ::
  t()

Starts a new contour at (x, y) without drawing a line.

new(start_x, start_y, opts \\ [])

@spec new(Podium.dimension() | number(), Podium.dimension() | number(), keyword()) ::
  t()

Creates a new freeform builder starting at (start_x, start_y).

Coordinates can be {value, unit} tuples (converted to EMU) or raw integers. When raw integers are used with scale: N, coordinates are multiplied by N to get EMU values.

Options

  • :scale - scale factor for raw integer coords (default 1.0, meaning EMU)
  • :x_scale / :y_scale - per-axis scale factors (override :scale)

shape_operations(fb)

@spec shape_operations(t()) :: [{:move_to | :line_to, number(), number()} | :close]

Returns operations with coordinates translated so the bounding box origin is (0, 0). Includes the initial move_to from the start point.