# vim: set filetype=python:
# Doctests for string functions on Linux.

>>> from pagebot import getContext
>>> from pagebot.toolbox.units import em, pt, upt
>>> from pagebot.constants import DEFAULT_LEADING
>>> context = getContext('Flat')
>>> context
<FlatContext>
>>> bs = context.newString('ABCD')
>>> bs.context
<FlatContext>
>>> bs.cs
ABCD
>>> bs.cs.__class__.__name__
'FlatBabelData'
>>> FONTSIZE = pt(24)
>>> style = dict(font='PageBot-Regular', fontSize=FONTSIZE)
>>> bs = context.newString('Testing 123...', style)
>>> bs.style
{'font': 'PageBot-Regular', 'fontSize': 24pt, 'leading': 1.4em}
>>> # Text width and height.
>>> bs.tw, bs.th
(119.38pt, 24pt)
>>> # Same but different call. Flat calculates ascender + descender size by
>>> # default.
>>> context.textSize(bs)
(119.38pt, 24pt)
>>> # Font size multiplied by leading, just like DrawBot.
>>> tw, th = context.textSize(bs, ascDesc=False)
>>> th
33.6pt
>>> # Calculates line height by using leading with font size as base.
>>> DEFAULT_LEADING.base = upt(FONTSIZE)
>>> pt(DEFAULT_LEADING) == th
True
>>> # Box width and height.
>>> # Only when explicitely set.
>>> bs.w, bs.h
(None, None)
>>> len(bs.lines)
1
>>> baselines = context.getBaselines(bs)
>>> len(baselines)
1
>>> baselines[0].y == round(bs.topLineAscender)
True
>>> baselines = context.getBaselines(bs)
>>> keys = sorted(baselines.keys())
>>> len(keys)
1
>>> keys
[0]
>>> # TODO: also test for multiple lines and element level text boxes.
