|Copyright||(c) 2011 Diagrams-cairo team (see LICENSE)|
|License||BSD-style (see LICENSE)|
This module provides convenience functions for querying information
from cairo. In particular, this provides utilities for information
about fonts, and creating text primitives with bounds based on the
font being used. To render text with automatically determined
Many of these functions take a
R2 parameter, determining the
style to apply to the text before rendering / querying information about
the text. These
R2 parameters can be created a variety of ways,
but the most direct will likely be by applying style-transforming functions
This works because there are instances of
NOTE that this module has a couple significant caveats:
- There are some known bugs (https://github.com/diagrams/diagrams-cairo/issues/19) which are not easily fixable (they are probably bugs in cairo itself, but since we are using the "toy text API" they will never be fixed).
- The functions in this module will only
work with text whose font size is measured in
This module should thus be considered experimental/unsupported; if
it works for you, great, but if not you are probably out of luck.
SVGFonts package for better-supported ways to accomplish
- textLineBoundedIO :: Style R2 -> String -> IO (Diagram Cairo R2)
- textVisualBoundedIO :: Style R2 -> String -> IO (Diagram Cairo R2)
- kerningCorrection :: Style R2 -> Char -> Char -> Double
- textLineBounded :: Style R2 -> String -> Diagram Cairo R2
- textVisualBounded :: Style R2 -> String -> Diagram Cairo R2
- data TextExtents = TextExtents R2 R2 R2
- bearing :: Lens' TextExtents R2
- textSize :: Lens' TextExtents R2
- advance :: Lens' TextExtents R2
- data FontExtents = FontExtents Double Double Double R2
- ascent :: Lens' FontExtents Double
- descent :: Lens' FontExtents Double
- height :: Lens' FontExtents Double
- maxAdvance :: Lens' FontExtents R2
- getTextExtents :: Style R2 -> String -> Render TextExtents
- getFontExtents :: Style R2 -> Render FontExtents
- getExtents :: Style R2 -> String -> Render (FontExtents, TextExtents)
- kerningCorrectionIO :: Style R2 -> Char -> Char -> IO Double
- queryCairo :: Render a -> IO a
- unsafeCairo :: Render a -> a
- cairoWithStyle :: Render a -> Style R2 -> Render a
These create diagrams instantiated with extent-based envelopes.
Creates text diagrams with their envelopes set such that using
stacks them in the way that
the font designer intended.
vcat . map (
Creates a text diagram with its envelope set to enclose the glyphs of the text, including leading (though not trailing) whitespace.
These are convenient unsafe variants of the above operations
unsafePerformIO. In practice, they should be fairly
safe as the results depend only on the parameters and the
font information (which ought to stay the same during a given
A more convenient data structure for the results of a text-extents query.
|TextExtents R2 R2 R2|
A more convenient data structure for the results of a font-extents query.
Get the extents of a string of text, given a style to render it with.
Queries the amount of horizontal offset that needs to be applied in order to
position the second character properly, in the event that it is
Executes a cairo action on a dummy, zero-size image surface, in order to query things like font information.