Copyright | (c) 2018 Schell Scivally |
---|---|
License | MIT |
Maintainer | Schell Scivally <schell@takt.com> |
Safe Haskell | None |
Language | Haskell2010 |
This module provides easy freetype2-based font rendering with a nice Haskell interface.
Synopsis
- data RenderedText t m = RenderedText {
- drawRenderedText :: t -> m ()
- sizeOfRenderedText :: V2 Int
- data TextRenderingData t = TextRenderingData {
- textRenderingDataAllocWord :: Atlas -> String -> IO (Either TypograffitiError (AllocatedRendering t))
- textRenderingDataFontMap :: Map (FilePath, GlyphSize) (Font t)
- textRenderingDataCharSet :: Set Char
- data FontStore t
- newDefaultFontStore :: (MonadIO m, MonadError TypograffitiError m, Integral i) => IO (V2 i) -> m (FontStore [TextTransform])
- getTextRendering :: (MonadIO m, MonadError TypograffitiError m, Layout t) => FontStore t -> FilePath -> GlyphSize -> String -> m (RenderedText t m)
- data TextTransform
- move :: Float -> Float -> TextTransform
- scale :: Float -> Float -> TextTransform
- rotate :: Float -> TextTransform
- color :: Float -> Float -> Float -> Float -> TextTransform
- alpha :: Float -> TextTransform
- class Layout t where
- allocAtlas :: (MonadIO m, MonadError TypograffitiError m) => FilePath -> GlyphSize -> String -> m Atlas
- loadText :: forall m t. (MonadIO m, MonadError TypograffitiError m, Layout t) => (Atlas -> String -> m (AllocatedRendering t)) -> Atlas -> WordCache t -> String -> m (t -> IO (), V2 Int, WordCache t)
- unloadMissingWords :: MonadIO m => WordCache t -> String -> m (WordCache t)
- stringTris :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> Bool -> String -> m (Vector (V2 Float, V2 Float))
- makeDefaultAllocateWord :: (MonadIO m, MonadError TypograffitiError m, Integral i) => IO (V2 i) -> m (Atlas -> String -> IO (Either TypograffitiError (AllocatedRendering [TextTransform])))
- asciiChars :: String
- data GlyphSize
- data CharSize = CharSize {}
- data Atlas = Atlas {}
- newtype WordCache t = WordCache {
- unWordCache :: Map String (AllocatedRendering t)
- data AllocatedRendering t = AllocatedRendering {}
- data TypograffitiError
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.
RenderedText | |
|
data TextRenderingData t Source #
TextRenderingData | |
|
newDefaultFontStore :: (MonadIO m, MonadError TypograffitiError m, Integral i) => IO (V2 i) -> m (FontStore [TextTransform]) Source #
:: (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
data TextTransform Source #
Instances
Layout [TextTransform] Source # | |
Defined in Typograffiti.Cache translate :: [TextTransform] -> V2 Float -> [TextTransform] Source # |
rotate :: Float -> TextTransform Source #
alpha :: Float -> TextTransform Source #
Generic operations for text layout.
Instances
Layout [TextTransform] Source # | |
Defined in Typograffiti.Cache translate :: [TextTransform] -> V2 Float -> [TextTransform] Source # |
Getting low
:: (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 |
-> m Atlas |
:: (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.
:: 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.
:: (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 #
:: (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]))) |
A default operation for allocating one word worth of geometry. This is "word" as in an English word, not a data type.
asciiChars :: String Source #
A string containing all standard ASCII characters.
This is often passed as the String
parameter in allocAtlas
.
Types
The size of one freetype font character. https://www.freetype.org/freetype2/docs/tutorial/step1.html#section-5
CharSize | |
|
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.
Errors
data TypograffitiError Source #
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. |
Instances
Eq TypograffitiError Source # | |
Defined in Typograffiti.Atlas (==) :: TypograffitiError -> TypograffitiError -> Bool # (/=) :: TypograffitiError -> TypograffitiError -> Bool # | |
Show TypograffitiError Source # | |
Defined in Typograffiti.Atlas showsPrec :: Int -> TypograffitiError -> ShowS # show :: TypograffitiError -> String # showList :: [TypograffitiError] -> ShowS # |