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.
| Unit | User units |
|---|---|
px | 1 |
pt | 4/3 |
pc | 16 |
in | 96 |
cm | 96 / 2.54 |
mm | 96 / 25.4 |
em | × the font size the element inherits |
pct | a 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
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.
iex> Macaw.Frame.Style.Sizes.marker({4, :px}, %{})
{:ok, 16.0}
@spec units() :: [atom(), ...]
The length units a unit value names (§3.9).