github ↗
docs menu

Module Hugin_text.Text

Rich text.

A text is a sequence of Unicode characters, each with a style: bold or not, italic or not, a size factor, a baseline shift and an optional colour. Layout sets a text in a list of faces at a size as the glyph runs (Hugin_font.Run) that draw it, and measures them.

Texts and layouts are immutable, every function is pure, and values may be shared between domains.

Texts

#type t

The type for texts.

#val v : string -> t

v s is the characters of the UTF-8 string s, neither bold nor italic, with size factor 1., shift 0. and no colour. Each maximal invalid subpart of s, as String.get_utf_8_uchar decodes it, becomes U+FFFD. Newlines end lines (Lines).

#val concat : t list -> t

concat ts is the characters of ts in order, each with its style. concat [] is v "".

Styles

A character of size factor k and shift d in a text set at size s is set at size k *. s with its baseline d *. s below the line's, above it if d is negative.

Each combinator restyles every character of its argument and keeps what an inner combinator set: in color c (concat [ a; color c' b ]) the characters of b keep c'.

#val bold : t -> t

bold t is t with every character bold.

#val italic : t -> t

italic t is t with every character italic.

#val scale : float -> t -> t

scale s t is t with every size factor and shift multiplied by s.

Raises Invalid_argument if s is not finite and positive.

#val color : Hugin_gg.Color.t -> t -> t

color c t is t with the colour c on every character that has none.

#val sup : t -> t

sup t is t as a superscript: every size factor k and shift d become 0.7 *. k and 0.7 *. d -. 0.4.

#val sub : t -> t

sub t is t as a subscript: every size factor k and shift d become 0.7 *. k and 0.7 *. d +. 0.2.

Comparing and formatting

#val equal : t -> t -> bool

equal t t' is true iff t and t' have the same characters with the same styles, size factors and shifts compared by Float.equal and colours by Hugin_gg.Color.equal.

#val compare : t -> t -> int

compare t t' is a total order on texts compatible with equal.

#val pp : Stdlib.Format.formatter -> t -> unit

pp ppf t formats t for debugging, in spans of one style.

Layout

#module Layout : sig ... end

A layout is a text set in a list of faces at a size: lines of glyph runs placed about an origin, the point its alignment names. Lengths are in the unit of that size.