diagrams-lib-0.7.1.1: Embedded domain-specific language for declarative graphics

Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None

Diagrams.TwoD.Text

Contents

- Creating text diagrams
- Text attributes
  - Font family
  - Font size
  - Font slant
  - Font weight

Description

Very basic text primitives along with associated attributes.

Synopsis

- data Text = Text T2 TextAlignment String
- data TextAlignment
  - = BaselineText
  - | BoxAlignedText Double Double
- text :: Renderable Text b => String -> Diagram b R2
- topLeftText :: Renderable Text b => String -> Diagram b R2
- alignedText :: Renderable Text b => Double -> Double -> String -> Diagram b R2
- baselineText :: Renderable Text b => String -> Diagram b R2
- newtype Font = Font (Last String)
- getFont :: Font -> String
- font :: HasStyle a => String -> a -> a
- newtype FontSize = FontSize (Last Double)
- getFontSize :: FontSize -> Double
- fontSize :: HasStyle a => Double -> a -> a
- fontSizeA :: HasStyle a => FontSize -> a -> a
- data FontSlant
  - = FontSlantNormal
  - | FontSlantItalic
  - | FontSlantOblique
- data FontSlantA
- getFontSlant :: FontSlantA -> FontSlant
- fontSlant :: HasStyle a => FontSlant -> a -> a
- italic :: HasStyle a => a -> a
- oblique :: HasStyle a => a -> a
- data FontWeight
  - = FontWeightNormal
  - | FontWeightBold
- data FontWeightA
- getFontWeight :: FontWeightA -> FontWeight
- fontWeight :: HasStyle a => FontWeight -> a -> a
- bold :: HasStyle a => a -> a

# Creating text diagrams

data Text Source

A text primitive consists of the string contents and alignment specification, along with a transformation mapping from the local vector space of the text to the vector space in which it is embedded.

Constructors

Text T2 TextAlignment String |

Instances

IsPrim Text |
Transformable Text |
HasOrigin Text |
Renderable Text NullBackend |

data TextAlignment Source

`TextAlignment` specifies the alignment of the text's origin.

Constructors

BaselineText |
BoxAlignedText Double Double |

text :: Renderable Text b => String -> Diagram b R2 Source

Create a primitive text diagram from the given string, with center alignment, equivalent to ``alignedText` 0.5 0.5`.

Note that it takes up no space, as text size information is not available.

topLeftText :: Renderable Text b => String -> Diagram b R2 Source

Create a primitive text diagram from the given string, origin at the top left corner of the text's bounding box, equivalent to ``alignedText` 0 1`.

Note that it takes up no space.

alignedText :: Renderable Text b => Double -> Double -> String -> Diagram b R2 Source

Create a primitive text diagram from the given string, with the origin set to a point interpolated within the bounding box. The first parameter varies from 0 (left) to 1 (right), and the second parameter from 0 (bottom) to 1 (top).

The height of this box is determined by the font's potential ascent and descent, rather than the height of the particular string.

Note that it takes up no space.

baselineText :: Renderable Text b => String -> Diagram b R2 Source

Create a primitive text diagram from the given string, with the origin set to be on the baseline, at the beginning (although not bounding). This is the reference point of showText in the Cairo graphics library.

Note that it takes up no space.

# Text attributes

## Font family

newtype Font Source

The `Font` attribute specifies the name of a font family. Inner `Font` attributes override outer ones.

Constructors

Font (Last String) |

Instances

Eq Font |
Typeable Font |
Semigroup Font |
AttributeClass Font |

getFont :: Font -> String Source

Extract the font family name from a `Font` attribute.

font :: HasStyle a => String -> a -> aSource

Specify a font family to be used for all text within a diagram.

## Font size

newtype FontSize Source

The `FontSize` attribute specifies the size of a font's em-square, measured with respect to the current local vector space. Inner `FontSize` attributes override outer ones.

Constructors

FontSize (Last Double) |

Instances

Eq FontSize |
Typeable FontSize |
Semigroup FontSize |
Default FontSize |
AttributeClass FontSize |

getFontSize :: FontSize -> Double Source

Extract the size from a `FontSize` attribute.

fontSize :: HasStyle a => Double -> a -> aSource

Set the font size, that is, the size of the font's em-square as measured within the current local vector space. The default size is `1`.

fontSizeA :: HasStyle a => FontSize -> a -> aSource

Apply a `FontSize` attribute.

## Font slant

data FontSlant Source

Constructors

FontSlantNormal |
FontSlantItalic |
FontSlantOblique |

Instances

Eq FontSlant |

data FontSlantA Source

The `FontSlantA` attribute specifies the slant (normal, italic, or oblique) that should be used for all text within a diagram. Inner `FontSlantA` attributes override outer ones.

Instances

Eq FontSlantA |
Typeable FontSlantA |
Semigroup FontSlantA |
AttributeClass FontSlantA |

getFontSlant :: FontSlantA -> FontSlant Source

Extract the font slant from a `FontSlantA` attribute.

fontSlant :: HasStyle a => FontSlant -> a -> aSource

Specify the slant (normal, italic, or oblique) that should be used for all text within a diagram. See also `italic` and `oblique` for useful special cases.

italic :: HasStyle a => a -> aSource

Set all text in italics.

oblique :: HasStyle a => a -> aSource

Set all text using an oblique slant.

## Font weight

data FontWeight Source

Constructors

FontWeightNormal |
FontWeightBold |

Instances

Eq FontWeight |

data FontWeightA Source

The `FontWeightA` attribute specifies the weight (normal or bold) that should be used for all text within a diagram. Inner `FontWeightA` attributes override outer ones.

Instances

Eq FontWeightA |
Typeable FontWeightA |
Semigroup FontWeightA |
AttributeClass FontWeightA |

getFontWeight :: FontWeightA -> FontWeight Source

Extract the font weight from a `FontWeightA` attribute.

fontWeight :: HasStyle a => FontWeight -> a -> aSource

Specify the weight (normal or bold) that should be used for all text within a diagram. See also `bold` for a useful special case.

bold :: HasStyle a => a -> aSource

Set all text using a bold font weight.