Tincture.Layout.Box (Tincture v0.1.0)

Copy Markdown View Source

Text flow within a bounded region, and across several of them.

flow_text/7 fills one box and reports what did not fit. flow_across_boxes/4 threads a single body of text through a list of boxes in order, which is how multi-column layouts work: each column is a box, and text continues into the next when one fills.

columns = [{50, 700, 240, 600}, {310, 700, 240, 600}]

{pdf, result} = Box.flow_across_boxes(pdf, rich_text, columns, line_height: 14)

if result.overflow? do
  # result.spill_text is what did not fit in any box
end

Boxes are {x, y, width, height} in PDF user space, with y at the box's top edge — text flows downward from there.

Summary

Types

box()

@type box() :: {number(), number(), number(), number()}

option()

@type option() :: Tincture.Typography.option() | {:rotate, number()}

Functions

flow_across_boxes(pdf, rich_text, boxes, opts \\ [])

flow_text(pdf, x, y, width, height, rich_text, opts \\ [])