Module Hugin_font.Run
Glyph runs.
A run is text set in one font at one size: glyphs, each placed relative to the run's origin on its baseline, and the text they render. Text layout makes runs and pictures draw them. Every renderer puts each glyph where the run says, so raster, SVG and PDF output agree with the layout that measured them, and the text keeps PDF and SVG output searchable and selectable.
Positions and sizes are in the units of the picture that draws the run, in the y-down plane of the geometry conventions.
Types
type tThe type for glyph runs.
Constructors
val v :
?ys:float array ->
?clusters:int array ->
font:Font.t ->
size:float ->
text:string ->
glyphs:Font.glyph array ->
xs:float array ->
unit ->
tv ~ys ~clusters ~font ~size ~text ~glyphs ~xs () is the run of the glyphs of font at em size size rendering text, glyph i with its origin at (xs.(i), ys.(i)), where:
ysdefaults to zeros, every glyph on the baseline.clustersmaps glyphs totext:clusters.(i)is the byte index intextof the first Unicode character glyphirenders. Glyphs with equal indices form a cluster, which renders the bytes from its index to the next larger index or to the end oftext. Clusters describe ligatures, one glyph for several characters, and decompositions, several glyphs for one character. Defaults to one glyph per character:clusters.(i)is the index of theith Unicode character oftext.
The arrays are copied.
Raises Invalid_argument if:
glyphs,xs,ysorclustersdiffer in length;- a glyph is not in [
0;Font.glyph_count font - 1]; sizeis negative, orsizeor a position is not finite;textis not valid UTF-8;glyphsis empty andtextis not;clustersdoes not start at0, decreases, or holds an index that does not start a Unicode character oftext(0for an emptytext);clustersis absent andtextdoes not have one Unicode character per glyph.
Accessors
Glyphs
Functions that take a glyph index raise Invalid_argument if it is not in [0;length r - 1].
val glyph : t -> int -> Font.glyphglyph r i is the glyph at index i of r.
cluster r i is the byte index in text r of the first Unicode character that glyph i of r renders.
Bounds
val bounds : t -> Hugin_gg.Box2.t optionbounds r is the smallest box containing the ink boxes (Font.ink) of the glyphs of r, each scaled by size r and moved to its glyph's origin, or None if no glyph has ink.
Raises Invalid_argument if a corner of that box is not finite, which takes a size or a position near max_float.
Comparing and formatting
equal r r' is true iff r and r' have Font.equal fonts, and equal sizes, texts, glyphs, positions and clusters.