HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulesdl2-ttf-2.1.3Haskell2010

SDL.Font

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.

  • 8 types
  • 35 values
  • Packagesdl2-ttf-2.1.3
  • Exports43
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFont.hs

General

3 declarations
valueinitialize :: MonadIO m => m ()
#

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.

valueversion :: (Integral a, MonadIO m) => m (a, a, a)
#

Gets the major, minor, patch versions of the linked SDL2_ttf library.

You may call this without initializing the library with initialize.

valuequit :: MonadIO m => m ()
#

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

8 declarations

Use the following functions to load TTF and FON file formats.

newtypenewtype Font
#

Represents a loaded font.

Constructors

Instances2Eq, Show
  • Eq FontDefined in sdl2-ttf-2.1.3 · SDL.Font
  • Show FontDefined in sdl2-ttf-2.1.3 · SDL.Font
typetype PointSize = Int
#

Point size (based on 72DPI) to load font as. Translates to pixel height.

typetype Index = Int
#

Designates a font face, the default and first one being 0.

Rendering

5 declarations

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.

valuesolid :: MonadIO m => Font -> Color -> Text -> m Surface
#

Renders Text using the quick and dirty method.

Is the fastest of the rendering methods, but results in text that isn't as smooth.

valueshaded :: MonadIO m => Font -> Color -> Color -> Text -> m Surface
#

Uses the slow and nice, but with a solid box method.

Renders slower than solid, but in about the same time as blended.

Results in a Surface containing antialiased text of a foreground color surrounded by a box of a background color. This Surface will blit as fast as the one from solid.

valueblended :: MonadIO m => Font -> Color -> Text -> m Surface
#

The slow slow slow, but ultra nice over another image method, blended renders text at high quality.

The text is antialiased and surrounded by a transparent box. Renders slower than solid, but in about the same time as shaded.

The resulting Surface will blit slower than the ones from solid or shaded.

valuesize :: MonadIO m => Font -> Text -> m (Int, Int)
#

Use this function to discover how wide and tall a Surface needs to be in order to accommodate a given text when it is rendered.

Note that no actual rendering takes place.

The values returned are the width and height, respectively, in pixels. The height returned is the same one returned by height.

Attributes

20 declarations
datadata Style
#

Possible styles that can be applied to a Font.

Instances8Bounded, Enum, Eq, Ord, Read, Show, …
valuegetStyle :: MonadIO m => Font -> m [Style]
#

Gets the rendering styles of a given Font.

If none were ever set, this will be an empty list.

typetype Outline = Int
#

The size of the Font outline, in pixels.

Use 0 to turn off outlining.

datadata Hinting
#

The hinting setting of a Font.

Instances8Bounded, Enum, Eq, Ord, Read, Show, …
typetype Kerning = Bool
#

Whether kerning is enabled or not.

The default for a newly-loaded Font is enabled.

valueascent :: MonadIO m => Font -> m Int
#

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.

valuedescent :: MonadIO m => Font -> m Int
#

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.

valuelineSkip :: MonadIO m => Font -> m Int
#

Gets the recommended pixel height of a rendered line of text of a given Font.

This is usually larger than what height would return.

Glyphs

7 declarations

Functions that work with individual glyphs.

valueglyphMetrics
  1. :: MonadIO m
  2. => Font
  3. -> Char
  4. -> m (Maybe (Int, Int, Int, Int, Int))
#

Get glyph metrics for a given unicode character. The values returned are:

  1. minimum x offset

  2. maximum x offset

  3. minimum y offset

  4. maximum y offset

  5. advance offset

You can see more information about these values in the original SDL2_ttf documentation here.