diagrams-cairo-0.5: Cairo backend for diagrams drawing EDSL

Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellSafe-Infered

Diagrams.Backend.Cairo.Text

Contents

Description

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.

Synopsis

Cairo 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.

type StyleParam = forall a. HasStyle a => a -> aSource

Existential type for mutations on objects that "have style". This is used as a parameter to getTextExtents and getFontExtents in order to set font-size and font-face.

cairoWithStyle :: Render a -> StyleParam -> 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.

Extents

Data Structures

data TextExtents Source

A more convenient data structure for the results of a text-extents query.

Constructors

TextExtents 

Fields

bearing :: R2
 
textSize :: R2
 
advance :: R2
 

data FontExtents Source

A more convenient data structure for the results of a font-extents query.

Constructors

FontExtents 

Queries

getTextExtents :: StyleParam -> String -> Render TextExtentsSource

Get the extents of a string of text, given a style to render it with.

getFontExtents :: StyleParam -> Render FontExtentsSource

Gets the intrinsic extents of a font.

getExtents :: StyleParam -> 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 :: StyleParam -> 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.

Primitives

These create diagrams instantiated with extents-based envelopes

textLineBoundedIO :: StyleParam -> 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 :: StyleParam -> 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).