package stk

  1. Overview
  2. Docs

Fonts.

This module provides functions to use fonts through Tsdl_ttf.Ttf.

Tsdl_ttf.Ttf.fonts are accessed through font descriptions font_desc. A caching mecanism avoids loading a SDL font each time a it is required.

val default_font_size : int Stdlib.ref

Default font size (set to 12 by default).

type font_metrics = {
  1. font_height : int;
  2. font_ascent : int;
  3. font_descent : int;
  4. font_line_skip : int;
  5. font_is_fixed_width : int;
}

Font metrics, to gather information from Tsdl_ttf.

val font_metrics : Tsdl_ttf.Ttf.font -> font_metrics

Get all font metrics from the given Tsdl_ttf.Ttf.font.

type font_desc = {
  1. size : int;
  2. italic : bool;
  3. bold : bool;
  4. family : string;
  5. underline : bool;
  6. strikethrough : bool;
  7. kerning : bool;
  8. outline : int;
}

A font description describes a font: family, size, style, ...

val default_font_desc : font_desc

A default font description.

val font_desc_wrapper : font_desc Ocf.Wrapper.t
val font_desc_compare : font_desc -> font_desc -> int
val font_desc : ?size:int -> ?italic:bool -> ?bold:bool -> ?underline:bool -> ?strikethrough:bool -> ?kerning:bool -> ?outline:int -> string -> font_desc

Convenient function to create a font_desc. Default value for optional arguments are:

  • size: !default_font_size,
  • italic: false,
  • bold: false,
  • strikethrough: false,
  • kerning: true,
  • outline: 0.
val pp_font_desc : Stdlib.Format.formatter -> font_desc -> unit
val fallback_font : int -> string option

Get a fallback font family associated to given unicode codepoint.

val add_fallback_font : int -> int -> string -> unit

add_fallback_font start stop family adds a font family to use as fallback font for the given range (start..stop) of unicode codepoints.

val font_exts : string list Stdlib.ref

Font file extensions. Use when looking for font files in directories. Default is [".ttf"].

val font_dirs : (string * bool) list Stdlib.ref

Font directories where to look for fonts, in the form (directory, rec-flag) where rec-flag indicates whether this directory should be inspected recursively when looking for fonts. App.init will call load_fonts which uses font_dirs to look for available fonts, so additional directories must be set before initializing application. Default value is [ Filename.current_dir_name, false ; "/usr/share/fonts/truetype", true ].

val load_fonts : ?size:int -> ?dirs:(string * bool) list -> unit -> unit Lwt.t

load_fonts () look for available fonts. Options arguments are:

val string_of_font_desc : font_desc -> string

Short string for given font desc.

val close_fonts : unit -> unit

Close all open font files. A font file remains open because of our caching system. If a font file cannot be opened because of two many open files, font files will be closed. But in case where a lot of fonts are used and the application must open a lot of files, this function may be useful to close font files before the application opens files.

val get : font_desc -> Tsdl_ttf.Ttf.font

Get a SDL font from a font description.

val fonts : unit -> font_desc list

Available fonts. The available fonts are added by calls to load_fonts.

OCaml

Innovation. Community. Security.