NativeElixirPdfUtilities.HtmlToPdf.PageGeometry (native_elixir_pdf_utilities v0.9.0)

View Source

Normalizes page sizes and four-sided page margins for rendering stages.

Numeric custom page-size tuples retain the renderer's compatibility rule: values up to 20 x 20 are inches and larger values are PDF points. CSS page-size strings always retain their declared units.

Summary

Functions

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

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.

Valid CSS values that require unresolved percentages, relative units, functions, keywords, auto, or negative geometry return nil and remain compatibility no-ops.

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.

Existing A4 and Letter return values are retained. Valid values that need unresolved CSS context return nil and remain compatibility no-ops.

merge_margin_defaults(previous, override)

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

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

Scalar and shorthand values replace all sides. A partial side map replaces only its declared sides, allowing @page longhands to cascade across rules and stylesheets.

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.

Strings use CSS shorthand order and accept one to four absolute lengths. Margin maps may contain any of the :top, :right, :bottom, and :left keys; omitted sides default to zero.

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.