How text is laid out
Shaping
Section titled “Shaping”Text starts as characters; the page needs glyphs, the shapes a font draws, each at a position. Turning one into the other is shaping: choosing glyphs for ligatures (fi), placing accents, kerning pairs (AV), joining Arabic letters. Paprika shapes with HarfBuzz, the shaper browsers and operating systems use, from the font file in the template.
HarfBuzz is the only authority on text geometry: which glyphs, their advances and offsets, and the font’s ascent and descent. Everything after builds on its answers. The renderer that draws glyphs on the editor’s canvas never changes where they go, and a PDF viewer draws them from the embedded font at the positions given.
Each run of text in one style is shaped as a whole, so kerning across spaces is kept, then cut into words where the shaper allows a break. Right-to-left and mixed-direction text is ordered by the Unicode bidirectional algorithm before it is shaped.
Words go on a line while they fit its width; the next starts a new line. Each line is as tall as the largest text on it, and lines are spaced by the paragraph’s line spacing, a multiple of each font’s own line height. A word too wide for its frame is broken between characters, with a warning. Tabs move to their stops, and list markers sit before the first line of each item.
Text that wraps around another frame meets a shorter line where the two overlap; the line’s width is worked out for each band of the page.
Frames that grow
Section titled “Frames that grow”A text frame can keep its size or grow to fit its text: taller, wider, or both, between the sizes it is given. A frame that grows can move others: an anchored frame follows the frame it is anchored to, so a body below a growing headline moves down. Layout settles a page in the order frames depend on each other, and a loop of frames that depend on each other is an error that names them.
When text still doesn’t fit, it is an overflow: an error, never text silently cut off. A template with an error can be saved and previewed, but a document isn’t produced from it.
Text that fits
Section titled “Text that fits”A frame can fit its text: all of its text is set at one percentage of its sizes, the largest between a minimum and a maximum that fits. A frame that grows grows first and shrinks its text only then. Because one percentage applies to the whole frame, a long name shrinks evenly rather than word by word.
A font is found by family, weight, style and width. If the text has a character the font has no glyph for, that is an error rather than a fallback to another font, so a document never shows a font no one chose. Only the glyphs used are embedded in each PDF, with the mapping back to the characters, so text can be selected, searched and copied.