Maintainer | diagrams-discuss@googlegroups.com |
---|---|
Safe Haskell | None |
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
envelopes, use textLineBounded
, textLineBoundedIO
,
textVisualBounded
, or textVisualBoundedIO
.
Many of these functions take a Style
R2
parameter, determining the
style to apply to the text before rendering / querying information about
the text. These Style
R2
parameters can be created a variety of ways,
but the most direct will likely be by applying style-transforming functions
such as font
, fontSize
, fontSlant
, and fontWeight
to mempty
.
This works because there are instances of HasStyle
and Monoid
for
.
Style
v
- 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 {}
- data FontExtents = FontExtents {}
- 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
Primitives
These create diagrams instantiated with extents-based envelopes
textLineBoundedIO :: Style R2 -> String -> IO (Diagram Cairo R2)Source
Creates text diagrams with their envelopes set such that using
vcat . map (textLineBounded style)
stacks them in the way that
the font designer intended.
textVisualBoundedIO :: Style R2 -> String -> IO (Diagram Cairo R2)Source
Creates a text diagram with its envelope set to enclose the glyphs of the text, including leading (though not trailing) whitespace.
Unsafe
These are convenient unsafe variants of the above operations postfixed with "IO". They should be pretty well-behaved as the results just depend on the parameters and the font information (which ought to stay the same during a given execution).
Extents
Data Structures
data TextExtents Source
A more convenient data structure for the results of a text-extents query.
data FontExtents Source
A more convenient data structure for the results of a font-extents query.
Queries
getTextExtents :: Style R2 -> String -> Render TextExtentsSource
Get the extents of a string of text, given a style to render it with.
getFontExtents :: Style R2 -> Render FontExtentsSource
Gets the intrinsic extents of a font.
getExtents :: Style R2 -> String -> Render (FontExtents, TextExtents)Source
Gets both the FontExtents and TextExtents of the string with the a
particular style applied. This is more efficient than calling both
getFontExtents
and getTextExtents
.
kerningCorrectionIO :: Style R2 -> Char -> Char -> IO DoubleSource
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 hcat
-ed
baselineText
.
Utilities
queryCairo :: Render a -> IO aSource
Executes a cairo action on a dummy, zero-size image surface, in order to query things like font information.
unsafeCairo :: Render a -> aSource
Unsafely invokes queryCairo
.
cairoWithStyle :: Render a -> Style R2 -> Render aSource
Executes the given cairo action, with styling applied. This does not do all styling - just attributes that are processed by "cairoMiscStyle", which does clip, fill color, fill rule, and, importantly for this module, font face, style, and weight.