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

Copyright | (c) 2011-2015 diagrams-lib team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None
Language | Haskell2010

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 n = Text (T2 n) (TextAlignment n) String
- data TextAlignment n
  - = BaselineText
  - | BoxAlignedText n n
- text :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any
- topLeftText :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any
- alignedText :: (TypeableFloat n, Renderable (Text n) b) => n -> n -> String -> QDiagram b V2 n Any
- baselineText :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any
- mkText :: (TypeableFloat n, Renderable (Text n) b) => TextAlignment n -> String -> QDiagram b V2 n Any
- mkText' :: (TypeableFloat n, Renderable (Text n) b) => TextAlignment n -> String -> QDiagram b V2 n Any
- newtype Font = Font (Last String)
- _Font :: Iso' Font String
- getFont :: Font -> String
- font :: HasStyle a => String -> a -> a
- _font :: Lens' (Style v n) (Maybe String)
- newtype FontSize n = FontSize (Recommend (Last n))
- _FontSize :: Iso' (FontSize n) (Recommend n)
- fontSize :: (N a ~ n, Typeable n, HasStyle a) => Measure n -> a -> a
- recommendFontSize :: (N a ~ n, Typeable n, HasStyle a) => Measure n -> a -> a
- fontSizeN :: (N a ~ n, Typeable n, Num n, HasStyle a) => n -> a -> a
- fontSizeO :: (N a ~ n, Typeable n, HasStyle a) => n -> a -> a
- fontSizeL :: (N a ~ n, Typeable n, Num n, HasStyle a) => n -> a -> a
- fontSizeG :: (N a ~ n, Typeable n, Num n, HasStyle a) => n -> a -> a
- getFontSize :: FontSize n -> n
- fontSizeM :: (N a ~ n, Typeable n, HasStyle a) => FontSizeM n -> a -> a
- _fontSizeR :: (Typeable n, OrderedField n) => Lens' (Style v n) (Measured n (Recommend n))
- _fontSize :: (Typeable n, OrderedField n) => Lens' (Style v n) (Measure n)
- _fontSizeU :: Typeable n => Lens' (Style v n) (Maybe n)
- data FontSlant
  - = FontSlantNormal
  - | FontSlantItalic
  - | FontSlantOblique
- getFontSlant :: FontSlant -> FontSlant
- fontSlant :: HasStyle a => FontSlant -> a -> a
- italic :: HasStyle a => a -> a
- oblique :: HasStyle a => a -> a
- _fontSlant :: Lens' (Style v n) FontSlant
- data FontWeight
  - = FontWeightNormal
  - | FontWeightBold
  - | FontWeightBolder
  - | FontWeightLighter
  - | FontWeightThin
  - | FontWeightUltraLight
  - | FontWeightLight
  - | FontWeightMedium
  - | FontWeightSemiBold
  - | FontWeightUltraBold
  - | FontWeightHeavy
- getFontWeight :: FontWeight -> FontWeight
- fontWeight :: HasStyle a => FontWeight -> a -> a
- bold :: HasStyle a => a -> a
- bolder :: HasStyle a => a -> a
- lighter :: HasStyle a => a -> a
- _fontWeight :: Lens' (Style v n) FontWeight
- thinWeight :: HasStyle a => a -> a
- ultraLight :: HasStyle a => a -> a
- light :: HasStyle a => a -> a
- mediumWeight :: HasStyle a => a -> a
- heavy :: HasStyle a => a -> a
- semiBold :: HasStyle a => a -> a
- ultraBold :: HasStyle a => a -> a

# Creating text diagrams

data Text n Source #

A `Text` primitive consists of the string contents, text alignment and the transformation to be applied. The transformation is scale invarient, the average scale of the transform should always be 1. All text scaling is obtained from the `FontSize` attribute.

This constructor should not be used directly. Use `text`, `alignedText` or `baselineText`.

Constructors

Text (T2 n) (TextAlignment n) String |

Instances

Floating n => Transformable (Text n) Source # |
Instance details Defined in Diagrams.TwoD.Text Methods transform :: Transformation (V (Text n)) (N (Text n)) -> Text n -> Text n Source #
Floating n => HasOrigin (Text n) Source # |
Instance details Defined in Diagrams.TwoD.Text Methods moveOriginTo :: Point (V (Text n)) (N (Text n)) -> Text n -> Text n Source #
Floating n => Renderable (Text n) NullBackend Source # |
Instance details Defined in Diagrams.TwoD.Text Methods render :: NullBackend -> Text n -> Render NullBackend (V (Text n)) (N (Text n)) Source #
type V (Text n) Source # |
Instance details Defined in Diagrams.TwoD.Text type V (Text n) = V2
type N (Text n) Source # |
Instance details Defined in Diagrams.TwoD.Text type N (Text n) = n

data TextAlignment n Source #

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

Constructors

BaselineText |
BoxAlignedText n n |

text :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any 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 :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any 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 :: (TypeableFloat n, Renderable (Text n) b) => n -> n -> String -> QDiagram b V2 n Any 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). Some backends do not implement this and instead snap to closest corner or the center.

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 :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any 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.

mkText :: (TypeableFloat n, Renderable (Text n) b) => TextAlignment n -> String -> QDiagram b V2 n Any Source #

Make a text from a `TextAlignment`, recommending a fill colour of `black` and `fontSize` of ``local` 1`.

mkText' :: (TypeableFloat n, Renderable (Text n) b) => TextAlignment n -> String -> QDiagram b V2 n Any Source #

Make a text from a `TextAlignment` without any default size or fill colour. This is useful is you want to recommend your own using `recommendFillColor` or `recommendFontSize`.

# 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 Source # |
Instance details Defined in Diagrams.TwoD.Text Methods (==) :: Font -> Font -> Bool Source # (/=) :: Font -> Font -> Bool Source #
Semigroup Font Source # |
Instance details Defined in Diagrams.TwoD.Text Methods (<>) :: Font -> Font -> Font Source # sconcat :: NonEmpty Font -> Font Source # stimes :: Integral b => b -> Font -> Font Source #
AttributeClass Font Source # |
Instance details Defined in Diagrams.TwoD.Text

_Font :: Iso' Font String Source #

getFont :: Font -> String Source #

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

font :: HasStyle a => String -> a -> a Source #

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

_font :: Lens' (Style v n) (Maybe String) Source #

Lens onto the font name of a style.

## Font size

newtype FontSize n Source #

The `FontSize` attribute specifies the size of a font's em-square. Inner `FontSize` attributes override outer ones.

Constructors

FontSize (Recommend (Last n)) |

Instances

Functor FontSize Source # |
Instance details Defined in Diagrams.TwoD.Text Methods fmap :: (a -> b) -> FontSize a -> FontSize b Source # (<$) :: a -> FontSize b -> FontSize a Source #
Semigroup (FontSize n) Source # |
Instance details Defined in Diagrams.TwoD.Text Methods (<>) :: FontSize n -> FontSize n -> FontSize n Source # sconcat :: NonEmpty (FontSize n) -> FontSize n Source # stimes :: Integral b => b -> FontSize n -> FontSize n Source #
Typeable n => AttributeClass (FontSize n) Source # |
Instance details Defined in Diagrams.TwoD.Text

_FontSize :: Iso' (FontSize n) (Recommend n) Source #

fontSize :: (N a ~ n, Typeable n, HasStyle a) => Measure n -> a -> a Source #

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 `local 1` (which is applied by `recommendFontSize`).

recommendFontSize :: (N a ~ n, Typeable n, HasStyle a) => Measure n -> a -> a Source #

`Recommend` a font size. Any use of `fontSize` above this will overwrite any recommended size. This should only be used with `mkText'`, other text functions already has a recommended font size so this will be ignored.

fontSizeN :: (N a ~ n, Typeable n, Num n, HasStyle a) => n -> a -> a Source #

A convenient synonym for 'fontSize (Normalized w)'.

fontSizeO :: (N a ~ n, Typeable n, HasStyle a) => n -> a -> a Source #

A convenient synonym for 'fontSize (Output w)'.

fontSizeL :: (N a ~ n, Typeable n, Num n, HasStyle a) => n -> a -> a Source #

A convenient sysnonym for 'fontSize (Local w)'.

fontSizeG :: (N a ~ n, Typeable n, Num n, HasStyle a) => n -> a -> a Source #

A convenient synonym for 'fontSize (Global w)'.

getFontSize :: FontSize n -> n Source #

Extract the size from a `FontSize` attribute.

fontSizeM :: (N a ~ n, Typeable n, HasStyle a) => FontSizeM n -> a -> a Source #

Apply a `FontSize` attribute.

_fontSizeR :: (Typeable n, OrderedField n) => Lens' (Style v n) (Measured n (Recommend n)) Source #

_fontSize :: (Typeable n, OrderedField n) => Lens' (Style v n) (Measure n) Source #

Lens to commit a font size. This is *not* a valid lens (see `commited`.

_fontSizeU :: Typeable n => Lens' (Style v n) (Maybe n) Source #

## Font slant

data FontSlant 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.

Constructors

FontSlantNormal |
FontSlantItalic |
FontSlantOblique |

Instances

Eq FontSlant Source # |
Instance details Defined in Diagrams.TwoD.Text Methods (==) :: FontSlant -> FontSlant -> Bool Source # (/=) :: FontSlant -> FontSlant -> Bool Source #
Ord FontSlant Source # |

Instance details

Defined in Diagrams.TwoD.Text

Methods

compare :: FontSlant -> FontSlant -> Ordering Source #

(<) :: FontSlant -> FontSlant -> Bool Source #

(<=) :: FontSlant -> FontSlant -> Bool Source #

(>) :: FontSlant -> FontSlant -> Bool Source #

(>=) :: FontSlant -> FontSlant -> Bool Source #

max :: FontSlant -> FontSlant -> FontSlant Source #

min :: FontSlant -> FontSlant -> FontSlant Source #

Show FontSlant Source # |
Instance details Defined in Diagrams.TwoD.Text Methods showsPrec :: Int -> FontSlant -> ShowS Source # show :: FontSlant -> String Source # showList :: [FontSlant] -> ShowS Source #
Semigroup FontSlant Source # |
Instance details Defined in Diagrams.TwoD.Text Methods (<>) :: FontSlant -> FontSlant -> FontSlant Source # sconcat :: NonEmpty FontSlant -> FontSlant Source # stimes :: Integral b => b -> FontSlant -> FontSlant Source #
Default FontSlant Source # |
Instance details Defined in Diagrams.TwoD.Text Methods def :: FontSlant Source #
AttributeClass FontSlant Source # |
Instance details Defined in Diagrams.TwoD.Text

getFontSlant :: FontSlant -> FontSlant Source #

Extract the font slant from a `FontSlantA` attribute.

fontSlant :: HasStyle a => FontSlant -> a -> a Source #

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 -> a Source #

Set all text in italics.

oblique :: HasStyle a => a -> a Source #

Set all text using an oblique slant.

_fontSlant :: Lens' (Style v n) FontSlant Source #

Lens onto the font slant in a style.

## Font weight

data FontWeight 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.

Constructors

FontWeightNormal |
FontWeightBold |
FontWeightBolder |
FontWeightLighter |
FontWeightThin |
FontWeightUltraLight |
FontWeightLight |
FontWeightMedium |
FontWeightSemiBold |
FontWeightUltraBold |
FontWeightHeavy |

Instances

Eq FontWeight Source # |
Instance details Defined in Diagrams.TwoD.Text Methods (==) :: FontWeight -> FontWeight -> Bool Source # (/=) :: FontWeight -> FontWeight -> Bool Source #
Ord FontWeight Source # |

Instance details

Defined in Diagrams.TwoD.Text

Methods

compare :: FontWeight -> FontWeight -> Ordering Source #

(<) :: FontWeight -> FontWeight -> Bool Source #

(<=) :: FontWeight -> FontWeight -> Bool Source #

(>) :: FontWeight -> FontWeight -> Bool Source #

(>=) :: FontWeight -> FontWeight -> Bool Source #

max :: FontWeight -> FontWeight -> FontWeight Source #

min :: FontWeight -> FontWeight -> FontWeight Source #

Show FontWeight Source # |
Instance details Defined in Diagrams.TwoD.Text Methods showsPrec :: Int -> FontWeight -> ShowS Source # show :: FontWeight -> String Source # showList :: [FontWeight] -> ShowS Source #
Semigroup FontWeight Source # | Last semigroup structure
Instance details Defined in Diagrams.TwoD.Text Methods (<>) :: FontWeight -> FontWeight -> FontWeight Source # sconcat :: NonEmpty FontWeight -> FontWeight Source # stimes :: Integral b => b -> FontWeight -> FontWeight Source #
Default FontWeight Source # |
Instance details Defined in Diagrams.TwoD.Text Methods def :: FontWeight Source #
AttributeClass FontWeight Source # |
Instance details Defined in Diagrams.TwoD.Text

getFontWeight :: FontWeight -> FontWeight Source #

Extract the font weight.

fontWeight :: HasStyle a => FontWeight -> a -> a Source #

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

bold :: HasStyle a => a -> a Source #

Set all text using a bold font weight.

bolder :: HasStyle a => a -> a Source #

Set all text to be bolder than the inherited font weight.

lighter :: HasStyle a => a -> a Source #

Set all text to be lighter than the inherited font weight.

_fontWeight :: Lens' (Style v n) FontWeight Source #

Lens onto the font weight in a style.

thinWeight :: HasStyle a => a -> a Source #

Set all text using a thin font weight.

ultraLight :: HasStyle a => a -> a Source #

Set all text using a extra light font weight.

light :: HasStyle a => a -> a Source #

Set all text using a light font weight.

mediumWeight :: HasStyle a => a -> a Source #

Set all text using a medium font weight.

heavy :: HasStyle a => a -> a Source #

Set all text using a heavy/black font weight.

semiBold :: HasStyle a => a -> a Source #

Set all text using a semi-bold font weight.

ultraBold :: HasStyle a => a -> a Source #

Set all text using an ultra-bold font weight.