Copyright | (c) 2015 Siniša Biđin |
---|---|
License | MIT |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Bindings to the SDL2_ttf
library
http://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html
which itself is a wrapper around the FreeType library.
The bindings should allow you to load fonts and
render Text
in various styles to an SDL
Surface
.
You can safely assume that any monadic function listed here is capable of
throwing an SDLException
in case it encounters an error.
Synopsis
- initialize :: MonadIO m => m ()
- version :: (Integral a, MonadIO m) => m (a, a, a)
- quit :: MonadIO m => m ()
- newtype Font = Font {}
- type PointSize = Int
- load :: MonadIO m => FilePath -> PointSize -> m Font
- type Index = Int
- loadIndex :: MonadIO m => FilePath -> PointSize -> Index -> m Font
- decode :: MonadIO m => ByteString -> PointSize -> m Font
- decodeIndex :: MonadIO m => ByteString -> PointSize -> Index -> m Font
- free :: MonadIO m => Font -> m ()
- type Color = V4 Word8
- solid :: MonadIO m => Font -> Color -> Text -> m Surface
- shaded :: MonadIO m => Font -> Color -> Color -> Text -> m Surface
- blended :: MonadIO m => Font -> Color -> Text -> m Surface
- size :: MonadIO m => Font -> Text -> m (Int, Int)
- data Style
- = Bold
- | Italic
- | Underline
- | Strikethrough
- getStyle :: MonadIO m => Font -> m [Style]
- setStyle :: MonadIO m => Font -> [Style] -> m ()
- type Outline = Int
- getOutline :: MonadIO m => Font -> m Outline
- setOutline :: MonadIO m => Font -> Outline -> m ()
- data Hinting
- getHinting :: MonadIO m => Font -> m Hinting
- setHinting :: MonadIO m => Font -> Hinting -> m ()
- type Kerning = Bool
- getKerning :: MonadIO m => Font -> m Kerning
- setKerning :: MonadIO m => Font -> Kerning -> m ()
- isMonospace :: MonadIO m => Font -> m Bool
- familyName :: MonadIO m => Font -> m (Maybe Text)
- styleName :: MonadIO m => Font -> m (Maybe Text)
- height :: MonadIO m => Font -> m Int
- ascent :: MonadIO m => Font -> m Int
- descent :: MonadIO m => Font -> m Int
- lineSkip :: MonadIO m => Font -> m Int
- getKerningSize :: MonadIO m => Font -> Index -> Index -> m Int
- glyphProvided :: MonadIO m => Font -> Char -> m Bool
- glyphIndex :: MonadIO m => Font -> Char -> m (Maybe Int)
- glyphMetrics :: MonadIO m => Font -> Char -> m (Maybe (Int, Int, Int, Int, Int))
- solidGlyph :: MonadIO m => Font -> Color -> Char -> m Surface
- shadedGlyph :: MonadIO m => Font -> Color -> Color -> Char -> m Surface
- blendedGlyph :: MonadIO m => Font -> Color -> Char -> m Surface
- blendedWrapped :: MonadIO m => Font -> Color -> Int -> Text -> m Surface
General
initialize :: MonadIO m => m () Source #
Initializes the library.
Unless noted otherwise, this must be called before any other part of the library is used.
You may call this multiple times.
version :: (Integral a, MonadIO m) => m (a, a, a) Source #
Gets the major, minor, patch versions of the linked SDL2_ttf
library.
You may call this without initializing the library with initialize
.
quit :: MonadIO m => m () Source #
Cleans up any resources still in use by the library.
If called, you must call initialize
again before using any other parts of
the library.
Loading
Use the following functions to load TTF
and FON
file formats.
Represents a loaded font.
Point size (based on 72DPI) to load font as. Translates to pixel height.
decode :: MonadIO m => ByteString -> PointSize -> m Font Source #
Same as load
, but accepts a ByteString
containing a font instead.
decodeIndex :: MonadIO m => ByteString -> PointSize -> Index -> m Font Source #
Same as loadIndex
, but accepts a ByteString
containing a font instead.
Rendering
Use the following functions to render text to a Surface
.
The methods available are described in more detail in the original
SDL2_ttf
documentation
here.
solid :: MonadIO m => Font -> Color -> Text -> m Surface Source #
Renders Text
using the quick and dirty method.
Is the fastest of the rendering methods, but results in text that isn't as smooth.
Attributes
Possible styles that can be applied to a Font
.
Instances
Bounded Style Source # | |
Enum Style Source # | |
Eq Style Source # | |
Ord Style Source # | |
Read Style Source # | |
Show Style Source # | |
Generic Style Source # | |
type Rep Style Source # | |
Defined in SDL.Font type Rep Style = D1 ('MetaData "Style" "SDL.Font" "sdl2-ttf-2.1.1-inplace" 'False) ((C1 ('MetaCons "Bold" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Italic" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Underline" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Strikethrough" 'PrefixI 'False) (U1 :: Type -> Type))) |
getStyle :: MonadIO m => Font -> m [Style] Source #
Gets the rendering styles of a given Font
.
If none were ever set, this will be an empty list.
setStyle :: MonadIO m => Font -> [Style] -> m () Source #
Sets the rendering style of a Font
.
Use an empty list to reset the style.
setOutline :: MonadIO m => Font -> Outline -> m () Source #
Sets the outline size for a given Font
.
Use 0 to turn off outlining.
The hinting setting of a Font
.
Instances
Bounded Hinting Source # | |
Enum Hinting Source # | |
Eq Hinting Source # | |
Ord Hinting Source # | |
Read Hinting Source # | |
Show Hinting Source # | |
Generic Hinting Source # | |
type Rep Hinting Source # | |
Defined in SDL.Font type Rep Hinting = D1 ('MetaData "Hinting" "SDL.Font" "sdl2-ttf-2.1.1-inplace" 'False) ((C1 ('MetaCons "Normal" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Light" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Mono" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "None" 'PrefixI 'False) (U1 :: Type -> Type))) |
Whether kerning is enabled or not.
The default for a newly-loaded Font
is enabled.
getKerning :: MonadIO m => Font -> m Kerning Source #
Gets the current kerning setting of a given Font
.
isMonospace :: MonadIO m => Font -> m Bool Source #
Tests whether the current face of a Font
is a fixed width font or not.
familyName :: MonadIO m => Font -> m (Maybe Text) Source #
Gets the current font face family name, if any.
styleName :: MonadIO m => Font -> m (Maybe Text) Source #
Gets the current font face style name, if any.
height :: MonadIO m => Font -> m Int Source #
Gets the maximum pixel height of all glyphs of a given Font
.
ascent :: MonadIO m => Font -> m Int Source #
Gets the maximum pixel ascent of all glyphs of a given Font
.
This can be interpreted as the distance from the top of the font to the baseline.
descent :: MonadIO m => Font -> m Int Source #
Gets the maximum pixel descent of all glyphs of a given Font
.
Also interpreted as the distance from the baseline to the bottom of the font.
getKerningSize :: MonadIO m => Font -> Index -> Index -> m Int Source #
From a given Font
get the kerning size of two glyphs.
Glyphs
Functions that work with individual glyphs.
glyphProvided :: MonadIO m => Font -> Char -> m Bool Source #
Does a Font
provide a certain unicode character?
glyphIndex :: MonadIO m => Font -> Char -> m (Maybe Int) Source #
Same as glyphProvided
, but returns an index of the glyph for the given
character instead, if one is provided.
glyphMetrics :: MonadIO m => Font -> Char -> m (Maybe (Int, Int, Int, Int, Int)) Source #
Get glyph metrics for a given unicode character. The values returned are:
- minimum x offset
- maximum x offset
- minimum y offset
- maximum y offset
- advance offset
You can see more information about these values in the original SDL2_ttf
documentation
here.
solidGlyph :: MonadIO m => Font -> Color -> Char -> m Surface Source #
Same as solid
, but renders a single glyph instead.
shadedGlyph :: MonadIO m => Font -> Color -> Color -> Char -> m Surface Source #
Same as shaded
, but renders a single glyph instead.