Behaviour for text shaping adapters.
Implement this behaviour to provide a custom text shaping engine.
The default implementation is Rendro.Text.Shaper.Simple (pure Elixir, cmap + advance widths).
For complex scripts (Arabic, Indic, Thai, etc.) configure Rendro.Adapters.HarfBuzz.
Configuration
config :rendro, shaper: Rendro.Adapters.HarfBuzzPer-render override
Rendro.render(doc, shaper: Rendro.Adapters.HarfBuzz)Precedence: per-render :shaper option > application config > Rendro.Text.Shaper.Simple.
The per-render option is threaded through the pipeline as the :shaper key in
the opts passed to shape/3.
Summary
Callbacks
Shapes text for font, returning shaped glyphs in the engine's output order.
Functions
Shapes text with the effective shaper implementation.
Types
@type glyph() :: %{ :gid => non_neg_integer(), :cluster => non_neg_integer(), :x_advance => integer(), :y_advance => integer(), :x_offset => integer(), :y_offset => integer(), optional(:name) => String.t() }
A shaped glyph.
:gid— glyph id in the font, or0when the shaping engine does not expose glyph ids.:cluster— byte offset (into the input text) of the first byte of the cluster this glyph belongs to, non-decreasing in logical order. A shaper that does not compute cluster boundaries MUST return0for every glyph; such output is interpreted as one-glyph-per-grapheme when the glyph count equals the input grapheme count, and as a single atomic cluster spanning the whole input text otherwise.:x_advance/:y_advance/:x_offset/:y_offset— metrics in font units (the caller scales by the font'sunits_per_em).:name— optional glyph (or grapheme) name;".notdef"marks a missing glyph.
Callbacks
@callback shape(Rendro.PDF.Font.t(), String.t(), opts :: keyword()) :: {:ok, [glyph()]} | {:error, term()}
Shapes text for font, returning shaped glyphs in the engine's output order.
Options
:script— OpenType script tag atom for the run (e.g.:latn,:arab) as produced by the Bidi itemizer; defaults to:latn.Rendro.Text.Shaper.Simpleuses it to gate requires-shaping scripts.:shaper— effective shaper module for this render (per-render override, resolved byRendro.Text.Shaper.shape/3); implementations may ignore it.