Hylograph.Flow.Render.Text
- Package
- purescript-hylograph-flow-render
- Repository
- afcondon/purescript-hylograph-flow-render
Words in a node, set without a DOM.
The layout is pure and runs in node, so it cannot ask a browser how
wide a string is. It estimates. estimateWidth adds up an advance for
each character from a table of five classes, in ems, taken from the
metrics of Helvetica and Arial (the same numbers to within a hundredth
of an em): narrow letters and marks a quarter of an em, f t r and
brackets a third, m w M W near nine tenths, capitals seven tenths,
and everything else (lower case, figures) 0.56. Semibold is taken as
six per cent wider.
HOW WRONG IT CAN BE. For Helvetica, Arial and Liberation Sans the
classes are within about 0.06 em of each glyph's true advance, and over
a label of ordinary words and figures the errors mostly cancel. Measured
once, in Chrome, on 276 lines of cell ranges and short phrases set in
Helvetica Neue: what the browser drew was between 0.87 and 1.01 of the
estimate, 0.97 at the median. So the estimate ran as much as a seventh
too wide (a line wrapped that would have fitted) and a hundredth too
narrow. A face of other proportions is another matter: a condensed face
runs a fifth narrower, a wide one (Verdana) a fifth wider, and the
estimate knows nothing of kerning, letter-spacing or a text-transform
set by a stylesheet (upper-casing a label makes it a quarter wider than
estimated). caution (1.08 by default) is the factor the estimate is
multiplied by before a line is judged to fit, so that an estimate a
little low still wraps in time; raise it for a wider face. A page can
measure what was drawn (getComputedTextLength) against the estimate.
wrap breaks at spaces, and inside a word only where the word alone
is wider than the line. Text that would need more than the lines
allowed ends in an ellipsis on the last line.
#Lettering Source
type Lettering = { caution :: Number, detailLines :: Int, detailSize :: Number, inset :: Number, leading :: Number, margin :: Number, outset :: Number, titleLines :: Int, titleSize :: Number }titleSize, detailSize: font sizes, in pixels. leading: a line's
height over its font size. margin: above the first line and below the
last. inset, outset: from the box's left side to the text, and from
the text to its right side. titleLines, detailLines: the most lines
each may take. caution: see the module's header.
#estimateWidth Source
estimateWidth :: Number -> String -> NumberThe width of a string at a font size, in pixels, at regular weight: an estimate (see the module's header).
#breadthOf Source
breadthOf :: Lettering -> SetWords -> NumberHow broad a box must be to hold words as set (0.5): the widest line,
as estimated and judged (caution, and heavier for the title), with
the inset and the outset. available of it is that widest line, so the
words set in a box this broad are within their room.
- Modules
- Hylograph.
Flow. Render. Columns - Hylograph.
Flow. Render. Continuity - Hylograph.
Flow. Render. Engine - Hylograph.
Flow. Render. Internal. Bands - Hylograph.
Flow. Render. Keys - Hylograph.
Flow. Render. Laws - Hylograph.
Flow. Render. Layout - Hylograph.
Flow. Render. Measures - Hylograph.
Flow. Render. Motion - Hylograph.
Flow. Render. Present - Hylograph.
Flow. Render. Reshape - Hylograph.
Flow. Render. Route - Hylograph.
Flow. Render. Sankey - Hylograph.
Flow. Render. Signal - Hylograph.
Flow. Render. Text - Hylograph.
Flow. Render. Transition - Hylograph.
Flow. Render. Tree - Hylograph.
Flow. Render. Unfold