Module Stk.Font

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 init : unit -> unit

Initializing. This function is called from App.init.

type font
val default_font_size : int Stdlib.ref

Default font size (set to 12 by default).

val compare : font -> font -> int
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 : font -> font_metrics

Get all font metrics from the given 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 desc_of_font : font -> font_desc
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 : unit -> (string * bool) list

font_dirs () returns thee list of 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. See Config.options to specifiy font directories.

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

load_fonts () looks for available fonts. Optional arguments are:

val load_fonts_from_dir : ?size:int -> ?recur:bool -> ?override:bool -> string -> font_desc list Lwt.t

load_fonts_from_dir dir looks for available fonts in the given directory. Optional arguments are:

  • size: size used to load a font; default is default_font_size.
  • recur: whether to look recursively in sub directories; default is true.
  • override: whether to replace existing fonts when a new one with same name is found; default is false.
val string_of_font_desc : font_desc -> string

Short string for given font desc.

val close_unused_fonts : unit -> unit

Close open fonts unused since some time. A font file remains open because of our caching system.

val family_is_available : string -> bool

Returns whether a font from the given family is available.

val get : font_desc -> font

Get a font from a font description.

val fonts : unit -> font_desc list

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

Using fonts

These functions correspond to those of Tsdl_ttf.Ttf, but using font value.

val glyph_metrics : font -> int -> Tsdl_ttf.Ttf.GlyphMetrics.t Tsdl.Sdl.result
val get_font_hinting : font -> Tsdl_ttf.Ttf.Hinting.t
val get_font_kerning_size : font -> int -> int -> int
val font_height : font -> int
val font_ascent : font -> int
val font_descent : font -> int
val font_line_skip : font -> int
val get_font_kerning : font -> bool
val font_faces : font -> int64
val font_face_is_fixed_width : font -> int
val font_face_family_name : font -> string
val font_face_style_name : font -> string
val size_utf8 : font -> string -> (int * int) Tsdl.Sdl.result
val glyph_is_provided : font -> int -> bool
val render_utf8_blended : font -> string -> Tsdl.Sdl.color -> Tsdl.Sdl.surface Tsdl.Sdl.result
val render_glyph_blended : font -> int -> Tsdl.Sdl.color -> Tsdl.Sdl.surface Tsdl.Sdl.result