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.
type font_metrics = {
font_height : int;
font_ascent : int;
font_descent : int;
font_line_skip : int;
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 = {
size : int;
italic : bool;
bold : bool;
family : string;
underline : bool;
strikethrough : bool;
kerning : bool;
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 :
?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
Get a fallback font family associated to given unicode codepoint.
add_fallback_font start stop family
adds a font family
to use as fallback font for the given range (start..stop)
of unicode codepoints.
Font file extensions. Use when looking for font files in directories. Default is [".ttf"]
.
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 ]
.
load_fonts ()
look for available fonts. Options arguments are:
size
: size used to load a font; default is default_font_size
.dirs
: directories to inspect. Default is font_dirs
.val string_of_font_desc : font_desc -> string
Short string for given font desc.
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
.