HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

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.

Contents
  1. General
  2. Loading
  3. Rendering
  4. Attributes
  5. Glyphs
Synopsis
  • Packagesdl2-ttf-2.1.3
  • Exports43
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFont.hs

General

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

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

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

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.

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

datadata Style

Possible styles that can be applied to a Font.

Instances8Bounded, Enum, Eq, Ord, Read, Show, …
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.

Glyphs

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.