Module Stk.FontSource

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.

Sourceval init : unit -> unit

Initializing. This function is called from App.init.

Sourcetype font
Sourceval default_font_size : int ref

Default font size (set to 12 by default).

Sourcetype 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.

Sourceval font_metrics : font -> font_metrics

Get all font metrics from the given font.

Sourcetype 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, ...

Sourceval default_font_desc : font_desc

A default font description.

Sourceval font_desc_wrapper : font_desc Ocf.Wrapper.t
Sourceval font_desc_compare : font_desc -> font_desc -> int
Sourceval 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.
Sourceval pp_font_desc : Format.formatter -> font_desc -> unit
Sourceval fallback_font : int -> string option

Get a fallback font family associated to given unicode codepoint.

Sourceval 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.

Sourceval font_exts : string list ref

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

Sourceval font_dirs : (string * bool) list 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 ].

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

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

Sourceval load_fonts_from_dir : ?size:int -> ?recur: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.
Sourceval string_of_font_desc : font_desc -> string

Short string for given font desc.

Sourceval close_unused_fonts : unit -> unit

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

Sourceval family_is_available : string -> bool

Returns whether a font from the given family is available.

Sourceval get : font_desc -> font

Get a font from a font description.

Sourceval 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.

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