# `Macaw.Layers.Text.Estimate`
[🔗](https://github.com/dcoai/macaw_layers/blob/v0.6.0/lib/macaw/layers/text/estimate.ex#L1)

The estimating measurer (spec/05 §2): 0.6 em per grapheme, whatever the font, from
visualize's `Visualize.Chart.Text.width/2`.

    iex> Macaw.Layers.Text.Estimate.width("Wednesday", "sans-serif", 11)
    59.4
    iex> Macaw.Layers.Text.Estimate.lines("one two three", "sans-serif", 10, 50)
    ["one two", "three"]

`width(text, font, size) = 0.6 × size × String.length(text)`, the number visualize's
estimate and macaw_frame's `Macaw.Draw.Text.width/2` give for the text at that size, so
a layout moving onto the seam keeps its numbers. No font is read: a wide glyph runs over
the estimate. It is `Macaw.Layers.Text`'s default measurer.

`lines/4` breaks at word boundaries: each line of the text (a newline always breaks) is
its words, separated by whitespace, set greedily, one space apart, as many to a line as
fit `max_width` by `width/3`. A word wider than `max_width` stands alone on its line,
never cut, and a line holding no word is `""`.

Both answer a value on any input: an argument of the wrong type is `{:type, type}` at
its name (`[:text]`, `[:font]`, `[:size]`, `[:max_width]`), every one at once.

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t(), ...]}
```

A refusal: every fault with its path.

# `em`

```elixir
@spec em() :: float()
```

`0.6`, the advance per grapheme in ems.

# `lines`

```elixir
@spec lines(String.t(), String.t(), number(), number()) :: [String.t()] | error()
```

The lines `text` wraps to at `size` pixels within `max_width` pixels, broken at word
boundaries by `width/3`.

# `width`

```elixir
@spec width(String.t(), String.t(), number()) :: float() | error()
```

The estimated width of `text` at `size` pixels: `0.6 × size × String.length(text)`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
