NativeElixirPdfUtilities.HtmlToPdf.PageGeometry (native_elixir_pdf_utilities v0.12.0)

View Source

Shared page-option cascade helpers and vertical layout-box geometry.

This module parses page-size and margin inputs into the renderer's canonical geometry values. The HTML validator remains the semantic authority that decides whether those canonical values are valid for an operation.

Summary

Functions

Returns the vertical {top, bottom} bounds for a drawable layout box.

Returns a scalar for uniform margins and the four-sided map for asymmetric margins.

Converts an applicable CSS page-margin value to a renderer margin value.

Converts an applicable CSS page-size descriptor to a renderer page-size value.

Merges a later page-margin declaration over an earlier declaration.

Merges extracted page options while cascading partial margin longhands by side.

Resolves a nonnegative renderer margin into top, right, bottom, and left points.

Resolves a renderer page-size value to a positive {width, height} point tuple.

Returns whether a four-sided margin leaves positive printable page geometry.

Types

margin_input()

@type margin_input() :: number() | String.t() | map()

margins()

@type margins() :: %{top: float(), right: float(), bottom: float(), left: float()}

orientation()

@type orientation() :: :portrait | :landscape

page_size_input()

@type page_size_input() ::
  page_size_name()
  | :"jis-b5"
  | :"jis-b4"
  | {page_size_name() | :"jis-b5" | :"jis-b4", orientation()}
  | {orientation(), page_size_name() | :"jis-b5" | :"jis-b4"}
  | {number(), number()}
  | String.t()

page_size_name()

@type page_size_name() ::
  :a5 | :a4 | :a3 | :b5 | :b4 | :jis_b5 | :jis_b4 | :letter | :legal | :ledger

Functions

box_vertical_bounds(box)

@spec box_vertical_bounds(term()) :: {number(), number()}

Returns the vertical {top, bottom} bounds for a drawable layout box.

Text bounds account for both the font ascent and the full line height so all rendering stages agree about the vertical space occupied by a line.

compact_margins(margins)

@spec compact_margins(margins()) :: float() | margins()

Returns a scalar for uniform margins and the four-sided map for asymmetric margins.

css_margin_option(value)

@spec css_margin_option(String.t()) :: number() | String.t() | margins() | nil

Converts an applicable CSS page-margin value to a renderer margin value.

css_page_size_option(value)

@spec css_page_size_option(String.t()) :: page_size_input() | nil

Converts an applicable CSS page-size descriptor to a renderer page-size value.

merge_margin_defaults(previous, override)

@spec merge_margin_defaults(term(), term()) :: term()

Merges a later page-margin declaration over an earlier declaration.

merge_page_options(previous, override)

@spec merge_page_options(keyword(), keyword()) :: keyword()

Merges extracted page options while cascading partial margin longhands by side.

normalize_margins(margin)

@spec normalize_margins(term()) :: {:ok, margins()} | {:error, :invalid_margin}

Resolves a nonnegative renderer margin into top, right, bottom, and left points.

normalize_page_size(page_size)

@spec normalize_page_size(term()) ::
  {:ok, {float(), float()}} | {:error, :invalid_page_size}

Resolves a renderer page-size value to a positive {width, height} point tuple.

valid_printable_area?(page_size, margins)

@spec valid_printable_area?(
  {number(), number()},
  margins()
) :: boolean()

Returns whether a four-sided margin leaves positive printable page geometry.