View Source Idmlx.Components.Rectangle (idmlx v0.2.1)

Represents a rectangle shape in an InDesign document.

This module provides functionality for handling rectangular elements, including:

  • Geometric properties (coordinates, dimensions)
  • Layer information
  • Style attributes
  • HTML conversion capabilities

Rectangle Structure

  • name - Unique identifier for the rectangle
  • layer - Layer containing the rectangle
  • content_type - Type of content (e.g., "GraphicType")
  • coordinates - Bounding box coordinates
  • item_transform - Transformation matrix [a, b, c, d, tx, ty]
  • dimensions - Width and height of the rectangle
  • object_style - Applied object style reference
  • draggable - Whether the rectangle can be dragged
  • attributes - Raw XML attributes

Examples

%Idmlx.Components.Rectangle{
  name: "rect_1",
  content_type: "GraphicType",
  coordinates: %{"x1" => 0.0, "y1" => 0.0, "x2" => 100.0, "y2" => 100.0},
  dimensions: %{"width" => 100.0, "height" => 100.0}
}

Summary

Functions

Parses a rectangle element from an XML fragment.

Converts a rectangle to HTML representation.

Types

coordinates()

@type coordinates() :: %{required(String.t()) => float()}

dimensions()

@type dimensions() :: %{required(String.t()) => float()}

t()

@type t() :: %Idmlx.Components.Rectangle{
  attributes: [map()] | nil,
  content_type: String.t() | nil,
  coordinates: coordinates() | nil,
  dimensions: dimensions() | nil,
  draggable: boolean() | nil,
  item_transform: [float()] | nil,
  layer: any() | nil,
  name: String.t() | nil,
  object_style: String.t() | nil
}

Functions

parse(xml_fragment, layer \\ nil, story \\ nil)

@spec parse(SweetXml.t(), any(), any()) :: t()

Parses a rectangle element from an XML fragment.

Processes the rectangle geometry, transforms, and attributes to create a complete rectangle representation.

Parameters

  • xml_fragment: XML fragment containing rectangle data
  • layer: Optional layer information
  • _story: Optional story reference (unused for rectangles)

Returns

A Rectangle struct with calculated properties

Examples

iex> xml = get_rectangle_xml()
iex> Idmlx.Components.Rectangle.parse(xml)
%Rectangle{
  name: "rect_1",
  content_type: "GraphicType",
  coordinates: %{"x1" => 0.0, "y1" => 0.0, "x2" => 100.0, "y2" => 100.0}
}

to_html(rectangle, assign, mode)

@spec to_html(t(), map(), atom()) :: String.t() | nil

Converts a rectangle to HTML representation.

Creates an HTML img element with appropriate styling and positioning based on the rectangle's properties and object style.

Parameters

  • rectangle: The Rectangle struct to convert
  • assign: Map of assignments including 'src' for the image source
  • _mode: Rendering mode (unused)

Returns

HTML string representation of the rectangle as an img element, or nil if no src

Examples

iex> rect = %Rectangle{name: "rect_1", content_type: "GraphicType"}
iex> Rectangle.to_html(rect, %{"src" => "image.jpg"}, :filled)
"""
<img
  id="rect_1"
  class="style1"
  style="position: absolute; left: 0px; top: 0px; width: 100px; height: 100px;"
  src="image.jpg"
  crossorigin="anonymous"
/>
"""