typograffiti-0.1.0.0: Display TTF fonts in OpenGL. Includes caching for fast rendering.

Copyright(c) 2018 Schell Scivally
LicenseMIT
MaintainerSchell Scivally <schell@takt.com>
Safe HaskellNone
LanguageHaskell2010

Typograffiti

Contents

Description

This module provides easy freetype2-based font rendering with a nice Haskell interface.

Synopsis

Some simple default text rendering operations

data RenderedText t m Source #

A pre-rendered bit of text, ready to display given some post compilition transformations. Also contains the text size.

Constructors

RenderedText 

Fields

data TextRenderingData t Source #

Constructors

TextRenderingData 

Fields

data FontStore t Source #

Stored fonts at specific sizes.

getTextRendering Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m, Layout t) 
=> FontStore t

The font store.

-> FilePath

The path to the font to use for rendering.

-> GlyphSize

The size of the font glyphs.

-> String

The string to render.

-> m (RenderedText t m)

The rendered text, ready to draw to the screen.

Transforming rendered text

class Layout t where Source #

Generic operations for text layout.

Minimal complete definition

translate

Methods

translate :: t -> V2 Float -> t Source #

Instances
Layout [TextTransform] Source # 
Instance details

Defined in Typograffiti.Cache

Getting low

allocAtlas Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m) 
=> FilePath

Path to the font file to use for this Atlas.

-> GlyphSize

Size of glyphs in this Atlas.

-> String

The characters to include in this Atlas.

-> m Atlas 

Allocate a new Atlas. When creating a new Atlas you must pass all the characters that you might need during the life of the Atlas. Character texturization only happens once.

loadText Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m, Layout t) 
=> (Atlas -> String -> m (AllocatedRendering t))

Operation used to allocate a word.

-> Atlas

The character atlas that holds our letters.

-> WordCache t

The WordCache to load AllocatedRenderings into.

-> String

The string to render. This string may contain newlines, which will be respected.

-> m (t -> IO (), V2 Int, WordCache t)

Returns a function for rendering the text, the size of the text and the new WordCache with the allocated renderings of the text.

Constructs a Renderer2 from the given color and string. The WordMap record of the given Atlas is used to construct the string geometry, greatly improving performance and allowing longer strings to be compiled and renderered in real time. To create a new Atlas see allocAtlas.

Note that since word geometries are stored in the Atlas WordMap and multiple renderers can reference the same Atlas, the returned Renderer2 contains a clean up operation that does nothing. It is expected that the programmer will call freeAtlas manually when the Atlas is no longer needed.

unloadMissingWords Source #

Arguments

:: MonadIO m 
=> WordCache t

The WordCache to unload words from.

-> String

The source string.

-> m (WordCache t) 

Unload any words from the cache that are not contained in the source string.

stringTris Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m) 
=> Atlas

The font atlas.

-> Bool

Whether or not to use kerning.

-> String

The string.

-> m (Vector (V2 Float, V2 Float)) 

Generate the geometry of the given string.

makeDefaultAllocateWord Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m, Integral i) 
=> IO (V2 i)

A monadic operation that returns the current context's dimentions. This is used to set the orthographic projection for rendering text.

-> m (Atlas -> String -> IO (Either TypograffitiError (AllocatedRendering [TextTransform]))) 

asciiChars :: String Source #

A string containing all standard ASCII characters. This is often passed as the String parameter in allocAtlas.

Types

data CharSize Source #

Constructors

CharSize 

Fields

Instances
Eq CharSize Source # 
Instance details

Defined in Typograffiti.Glyph

Ord CharSize Source # 
Instance details

Defined in Typograffiti.Glyph

Show CharSize Source # 
Instance details

Defined in Typograffiti.Glyph

newtype WordCache t Source #

Constructors

WordCache 
Instances
Semigroup (WordCache t) Source # 
Instance details

Defined in Typograffiti.Cache

Methods

(<>) :: WordCache t -> WordCache t -> WordCache t #

sconcat :: NonEmpty (WordCache t) -> WordCache t #

stimes :: Integral b => b -> WordCache t -> WordCache t #

Monoid (WordCache t) Source # 
Instance details

Defined in Typograffiti.Cache

data AllocatedRendering t Source #

Holds an allocated draw function for some amount of text. The function takes one parameter that can be used to transform the text in various ways. This type is generic and can be used to take advantage of your own font rendering shaders.

Constructors

AllocatedRendering 

Fields

  • arDraw :: t -> IO ()

    Draw the text with some transformation in some monad.

  • arRelease :: IO ()

    Release the allocated draw function in some monad.

  • arSize :: V2 Int

    The size (in pixels) of the drawn text.

Errors

data TypograffitiError Source #

Constructors

TypograffitiErrorNoGlyphMetricsForChar Char

The are no glyph metrics for this character. This probably means the character has not been loaded into the atlas.

TypograffitiErrorFreetype String String

There was a problem while interacting with the freetype2 library.

TypograffitiErrorGL String

There was a problem while interacting with OpenGL.