PaperForge.Margins (PaperForge v0.2.0)

Copy Markdown View Source

Represents page margins.

Margins can be created from:

  • one number, applied to every side;
  • a keyword list with individual values;
  • an existing PaperForge.Margins struct.

Examples

PaperForge.Margins.new(72)

PaperForge.Margins.new(
  top: 40,
  right: 50,
  bottom: 40,
  left: 50
)

Summary

Functions

Returns the content height for a page.

Returns the content width for a page.

Returns the total horizontal margin.

Creates margins with zero on every side.

Creates margins from one value, a keyword list, or an existing margins struct.

Converts margins to a keyword list.

Validates that margins fit inside a page.

Returns the total vertical margin.

Types

t()

@type t() :: %PaperForge.Margins{
  bottom: number(),
  left: number(),
  right: number(),
  top: number()
}

Functions

content_height(margins, page_height)

@spec content_height(t(), number()) :: number()

Returns the content height for a page.

Raises when the margins consume all available page height.

content_width(margins, page_width)

@spec content_width(t(), number()) :: number()

Returns the content width for a page.

Raises when the margins consume all available page width.

horizontal(margins)

@spec horizontal(t()) :: number()

Returns the total horizontal margin.

This is the sum of the left and right margins.

new()

@spec new() :: t()

Creates margins with zero on every side.

new(margins)

@spec new(number() | keyword() | t()) :: t()

Creates margins from one value, a keyword list, or an existing margins struct.

A numeric value is applied to all four sides.

Missing keyword values default to zero.

to_keyword(margins)

@spec to_keyword(t()) :: keyword()

Converts margins to a keyword list.

validate_page!(margins, page_width, page_height)

@spec validate_page!(t(), number(), number()) :: t()

Validates that margins fit inside a page.

Returns the margins unchanged when valid.

vertical(margins)

@spec vertical(t()) :: number()

Returns the total vertical margin.

This is the sum of the top and bottom margins.