wumpus-core-0.40.0: Pure Haskell PostScript and SVG generation.

PortabilityGHC
Stabilityunstable
Maintainerstephen.tetley@gmail.com

Wumpus.Core.FontSize

Contents

Description

Approximate glyph size calculations for Label's and their bounding boxes.

Calculations are based on metrics derived from the Courier font. As Courier is a monospaced font, applying these metrics to other font families will usually produce over-estimates (bounding boxes will be longer than the true visual length of the text). Furthermore, even italic or bold Courier will have different metrics.

This is a deficiency of Wumpus, and limits its text handling capabilities - for example, text cannot be reliably centered or right aligned as its true length is not known. However, more powerful alternatives would need access to the metrics embedded within font files. This would require a font loader and add significant implementation complexity.

Synopsis

Type synonyms

data PtScale Source

Wrapped Double representing 1/1000 of the scale factor (Point size) of a font. AFM files encode all measurements as these units.

Scaling values derived from Courier

mono_width :: PtScaleSource

The ratio of width to point size of a letter in Courier.

 mono_width = 0.6 

mono_cap_height :: PtScaleSource

The ratio of cap height to point size of a letter in Courier.

 mono_cap_height = 0.562

mono_x_height :: PtScaleSource

The ratio of x height to point size of a letter in Courier.

This is also known as the "body height".

 mono_x_height = 0.426

mono_descender :: PtScaleSource

The ratio of descender depth to point size of a letter in Courier.

 mono_descender = -0.157

mono_ascender :: PtScaleSource

The ratio of ascender to point size of a letter in Courier.

 mono_ascender = 0.629

mono_left_margin :: PtScaleSource

The left margin for the bounding box of printed text as a ratio to point size for Courier.

 mono_left_margin = -0.046

mono_right_margin :: PtScaleSource

The right margin for the bounding box of printed text as a ratio to point size for Courier.

 mono_right_margin = 0.050

Courier metrics

charWidth :: FontSize -> PtSizeSource

Approximate the width of a monospace character using metrics derived from the Courier font.

textWidth :: FontSize -> CharCount -> PtSizeSource

Text width at sz point size of the string s. All characters are counted literally - it is expected that CharCount has been calculated with the charCount function.

Note - this does not account for left and right margins around the printed text.

capHeight :: FontSize -> PtSizeSource

Height of capitals e.g. 'A' using metrics derived the Courier monospaced font.

xcharHeight :: FontSize -> PtSizeSource

Height of the lower-case char 'x' using metrics derived the Courier monospaced font.

totalCharHeight :: FontSize -> PtSizeSource

The total height span of the glyph bounding box for the Courier monospaced font.

ascenderHeight :: FontSize -> PtSizeSource

Ascender height for font size sz using metrics from the Courier monospaced font.

descenderDepth :: FontSize -> PtSizeSource

Descender depth for font size sz using metrics from the Courier monospaced font.

Size calculation

textBounds :: (Num u, Ord u, FromPtSize u) => FontSize -> Point2 u -> String -> BoundingBox uSource

textBounds : font_size * baseline_left * text -> BBox

Find the bounding box for the character count at the supplied font-size.

The supplied point represents the baseline left corner of the a regular upper-case letter (that is without descenders). The bounding box adds a margin around all sides of the text.

The metrics used are derived from Courier - a monospaced font. For proportional fonts the calculated bounding box will usually be too long.

textBoundsEsc :: (Num u, Ord u, FromPtSize u) => FontSize -> Point2 u -> EscapedText -> BoundingBox uSource

textBoundsEnc : font_size * baseline_left * escaped_text -> BBox

Version of textBounds for EscapedText.

charCount :: String -> CharCountSource

Count the charcters in the supplied string.

Note escapes count as one character - for instance the length of this string:

 abcd&#egrave;f

... is 6.