Macaw.Frame.Style.Sizes (macaw_frame v0.1.0)

Copy Markdown View Source

Sizes in units (spec/02 §3.9): a size written in any common unit ({1.5, :pt}, {1.2, :em}, {2, :mm}) is a number of user units when the style resolves, so every backend gets a number and a canvas and SVG agree. A bare number keeps its meaning.

UnitUser units
px1
pt4/3
pc16
in96
cm96 / 2.54
mm96 / 25.4
em× the font size the element inherits
pcta share of the key's box: the inherited font size at font.size, the labeled box at a text offset, the layer's band at a marker size; elsewhere {:no_box, key}

em resolves here, never written as a CSS em. A marker size in a unit is the side of the square whose area it is.

iex> Macaw.Frame.Style.Sizes.convert({3, :pt}, :width, %{})
{:ok, 4.0}
iex> Macaw.Frame.Style.Sizes.convert({1.5, :em}, :width, %{font_size: 12})
{:ok, 18.0}
iex> Macaw.Frame.Style.Sizes.convert({50, :pct}, :width, %{})
{:error, {:no_box, :width}}

Summary

Types

What a relative size is a share of: the inherited font size, and a box where the key has one.

Functions

A size at a key in user units: {:ok, number}, or {:error, reason}: a unit no table has {:type, :size}, a pct where the key has no box {:no_box, key}, a unit at an opacity {:no_unit, key}. A number is itself; the default font size is 10.

A marker's size in user units (§3.9): a number is an area; a unit value is the side of the square, so its area is the side squared, a pct of the layer's band.

The length units a unit value names (§3.9).

Types

context()

@type context() :: %{
  optional(:font_size) => number(),
  optional(:box) => number(),
  optional(:band) => number()
}

What a relative size is a share of: the inherited font size, and a box where the key has one.

Functions

convert(n, key, context)

@spec convert(term(), term(), term()) :: {:ok, number()} | {:error, term()}

A size at a key in user units: {:ok, number}, or {:error, reason}: a unit no table has {:type, :size}, a pct where the key has no box {:no_box, key}, a unit at an opacity {:no_unit, key}. A number is itself; the default font size is 10.

marker(area, context)

@spec marker(term(), term()) :: {:ok, number()} | {:error, term()}

A marker's size in user units (§3.9): a number is an area; a unit value is the side of the square, so its area is the side squared, a pct of the layer's band.

iex> Macaw.Frame.Style.Sizes.marker({4, :px}, %{})
{:ok, 16.0}

units()

@spec units() :: [atom(), ...]

The length units a unit value names (§3.9).