NativeElixirPdfUtilities.HtmlToPdf.Layout (native_elixir_pdf_utilities v1.1.0)

View Source

Layout engine for the native HTML-to-PDF renderer.

Lays out block text elements, inline text runs, box styling, lists, link annotation bounds, deterministic tables, a documented flexbox/grid subset, image boxes, embedded-font text metrics, and pagination metadata.

Replaced inline images retain styled-node display: :image with image_display: :inline and become explicit :inline_image runs. Atomic measurements use _inline_content_width, _inline_content_height, and _inline_baseline_depth measured down from the border-box top. The bottom margin edge supplies an image's baseline. Painted boxes keep PDF bottom-left coordinates; optional link_rect is the clickable border box, independent of fitted image ink. Relative positioning and pagination move both rectangles.

Summary

Functions

Converts a styled document tree into a layout tree.

Lays out an existing styled surface at explicit nonnegative point dimensions, including a zero client area.

Measures an already styled child in its existing issued document context.

Paints a validator-prepared CSS background in an already allocated content rectangle.

Paints canonically validated closed editor text using the ordinary inline line, glyph and clipping geometry.

Resolves a validator-prepared CSS box content dimension with the shared min/max and box-sizing rules.

Resolves issued lazy image candidates and SVG viewports from the surviving final layout boxes.

Types

box()

@type box() :: map()

layout_tree()

@type layout_tree() :: %{
  type: :layout,
  page_size: term(),
  margin: term(),
  margins: NativeElixirPdfUtilities.HtmlToPdf.PageGeometry.margins(),
  boxes: [box()]
}

render_option()

Functions

layout(styled_tree, opts \\ [])

@spec layout(term(), term()) ::
  {:ok, layout_tree()}
  | {:error, :invalid_layout | :invalid_margin | :invalid_page_size}
  | {:error,
     {:invalid_layout | :unsupported_html | :resource_limit_exceeded,
      NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Converts a styled document tree into a layout tree.

layout_viewport(styled_tree, width, height)

@spec layout_viewport(term(), term(), term()) ::
  {:ok, layout_tree()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Lays out an existing styled surface at explicit nonnegative point dimensions, including a zero client area.

measure_child(node, context, constraints \\ %{})

@spec measure_child(term(), term(), term()) ::
  {:ok, map()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Measures an already styled child in its existing issued document context.

Returns intrinsic widths, layout/ink extents and ordered native paint boxes in points relative to the alphabetic baseline, positive y upwards. Forced breaks, links, images, decorations and form metadata retain their native representation. No parsing, font registration, resource-context creation, pagination or implicit viewport clipping occurs. Atomic elements retain their existing baseline rules. Prepared MathML retains its preferred widths independently of actual advance and paint geometry. Ordinary block boxes use their allocated containing width, while their preferred widths use the shared CSS intrinsic and min/max sizing rules with an indefinite percentage basis. Authored box sizing applies to both axes. first_alphabetic_baseline records the first content baseline relative to the atomic alphabetic baseline, for MathML Core block-box composition. typographic_width records the unpositioned final line endpoint: occupied predecessor fragments followed by the final fragment's actual advance. Relative offsets and transforms affect paint, independently of this extent. The optional :formatting_context is :flow by default. :math, :flex and :grid use CSS's block-container box for authored inline flow items; the source node and its computed display remain unchanged.

paint_background(style, x, y, width, height)

@spec paint_background(map(), number(), number(), number(), number()) :: [map()]

Paints a validator-prepared CSS background in an already allocated content rectangle.

paint_source_editor(nodes, style, editor)

@spec paint_source_editor([map()], map(), map()) ::
  {:ok, map()} | {:error, {atom(), map()}}

Paints canonically validated closed editor text using the ordinary inline line, glyph and clipping geometry.

resolve_content_size(style, property, available_size, default)

@spec resolve_content_size(map(), :width | :height, number() | nil, number() | nil) ::
  number() | nil

Resolves a validator-prepared CSS box content dimension with the shared min/max and box-sizing rules.

resolve_images(layout)

@spec resolve_images(layout_tree()) ::
  {:ok, layout_tree()} | {:error, {atom(), map()}}

Resolves issued lazy image candidates and SVG viewports from the surviving final layout boxes.