Copyright | (c) 2018 Schell Scivally 2023 Adrian Cochrane |
---|---|
License | MIT |
Maintainer | Schell Scivally <schell@takt.com> & Adrian Cochrane <alcinnz@argonaut-constellation.org> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides a font-character atlas to use in font rendering with opengl.
Synopsis
- data TypograffitiError
- = TypograffitiErrorNoMetricsForGlyph Int
- | TypograffitiErrorFreetype String Int32
- | TypograffitiErrorGL String
- data GlyphMetrics = GlyphMetrics {
- glyphTexBB :: (V2 Int, V2 Int)
- glyphSize :: V2 Int
- glyphOffset :: V2 Int
- data Atlas = Atlas {
- atlasTexture :: GLuint
- atlasTextureSize :: V2 Int
- atlasMetrics :: IntMap GlyphMetrics
- atlasScale :: (Float, Float)
- emptyAtlas :: GLuint -> Atlas
- data AtlasMeasure = AM {}
- emptyAM :: AtlasMeasure
- spacing :: Int
- type GlyphRetriever m = Word32 -> m (FT_Bitmap, FT_Glyph_Metrics)
- glyphRetriever :: (MonadIO m, MonadError TypograffitiError m) => FT_Face -> GlyphRetriever m
- measure :: (MonadIO m, MonadError TypograffitiError m) => GlyphRetriever m -> Int -> AtlasMeasure -> Word32 -> m AtlasMeasure
- texturize :: (MonadIO m, MonadError TypograffitiError m) => GlyphRetriever m -> IntMap (V2 Int) -> Atlas -> Word32 -> m Atlas
- allocAtlas :: (MonadIO m, MonadFail m, MonadError TypograffitiError m) => GlyphRetriever m -> [Word32] -> (Float, Float) -> m Atlas
- freeAtlas :: MonadIO m => Atlas -> m ()
- type Quads = (Float, Float, [Vector (V2 Float, V2 Float)])
- makeCharQuad :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> Quads -> (GlyphInfo, GlyphPos) -> m Quads
- stringTris :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> [(GlyphInfo, GlyphPos)] -> m Quads
- stringTris' :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> [(GlyphInfo, GlyphPos)] -> m (Vector (V2 Float, V2 Float))
- liftFreetype :: (MonadIO m, MonadError TypograffitiError m) => IO a -> m a
Documentation
data TypograffitiError Source #
Represents a failure to render text.
TypograffitiErrorNoMetricsForGlyph Int | The are no glyph metrics for this character. This probably means the character has not been loaded into the atlas. |
TypograffitiErrorFreetype String Int32 | There was a problem while interacting with the freetype2 library. |
TypograffitiErrorGL String | There was a problem while interacting with OpenGL. |
Instances
Show TypograffitiError Source # | |
Defined in Typograffiti.Atlas showsPrec :: Int -> TypograffitiError -> ShowS show :: TypograffitiError -> String showList :: [TypograffitiError] -> ShowS | |
Eq TypograffitiError Source # | |
Defined in Typograffiti.Atlas (==) :: TypograffitiError -> TypograffitiError -> Bool (/=) :: TypograffitiError -> TypograffitiError -> Bool |
data GlyphMetrics Source #
Size & position of a Glyph in the Atlas
.
GlyphMetrics | |
|
Instances
Show GlyphMetrics Source # | |
Defined in Typograffiti.Atlas showsPrec :: Int -> GlyphMetrics -> ShowS show :: GlyphMetrics -> String showList :: [GlyphMetrics] -> ShowS | |
Eq GlyphMetrics Source # | |
Defined in Typograffiti.Atlas (==) :: GlyphMetrics -> GlyphMetrics -> Bool (/=) :: GlyphMetrics -> GlyphMetrics -> Bool |
Cache of rendered glyphs to be composited into place on the GPU.
Atlas | |
|
emptyAtlas :: GLuint -> Atlas Source #
Initializes an empty atlas.
data AtlasMeasure Source #
Precomputed positioning of glyphs in an Atlas
texture.
Instances
Show AtlasMeasure Source # | |
Defined in Typograffiti.Atlas showsPrec :: Int -> AtlasMeasure -> ShowS show :: AtlasMeasure -> String showList :: [AtlasMeasure] -> ShowS | |
Eq AtlasMeasure Source # | |
Defined in Typograffiti.Atlas (==) :: AtlasMeasure -> AtlasMeasure -> Bool (/=) :: AtlasMeasure -> AtlasMeasure -> Bool |
emptyAM :: AtlasMeasure Source #
Initializes a new AtlasMeasure
.
type GlyphRetriever m = Word32 -> m (FT_Bitmap, FT_Glyph_Metrics) Source #
Callback for looking up a glyph from an atlas. Useful for applying synthetic styles to fonts which lack them, when calling the low-level APIs.
glyphRetriever :: (MonadIO m, MonadError TypograffitiError m) => FT_Face -> GlyphRetriever m Source #
Default callback for glyph lookups, with no modifications.
measure :: (MonadIO m, MonadError TypograffitiError m) => GlyphRetriever m -> Int -> AtlasMeasure -> Word32 -> m AtlasMeasure Source #
Extract the measurements of a character in the FT_Face and append it to the given AtlasMeasure.
texturize :: (MonadIO m, MonadError TypograffitiError m) => GlyphRetriever m -> IntMap (V2 Int) -> Atlas -> Word32 -> m Atlas Source #
Uploads glyphs into an Atlas
texture for the GPU to composite.
allocAtlas :: (MonadIO m, MonadFail m, MonadError TypograffitiError m) => GlyphRetriever m -> [Word32] -> (Float, Float) -> m Atlas Source #
freeAtlas :: MonadIO m => Atlas -> m () Source #
Releases all resources associated with the given Atlas
.
type Quads = (Float, Float, [Vector (V2 Float, V2 Float)]) Source #
The geometry needed to render some text, with the position for the next glyph.
makeCharQuad :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> Quads -> (GlyphInfo, GlyphPos) -> m Quads Source #
Construct the geometry needed to render the given character.
stringTris :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> [(GlyphInfo, GlyphPos)] -> m Quads Source #
Generate the geometry of the given string, with next-glyph position.
stringTris' :: (MonadIO m, MonadError TypograffitiError m) => Atlas -> [(GlyphInfo, GlyphPos)] -> m (Vector (V2 Float, V2 Float)) Source #
Generate the geometry of the given string.
liftFreetype :: (MonadIO m, MonadError TypograffitiError m) => IO a -> m a Source #
Internal utility to propagate FreeType errors into Typograffiti errors.