package graphv_gles2_native

  1. Overview
  2. Docs

Module Graphv_gles2_native.TextSource

Module for text rendering. Text is rendered using a glyph bitmap. The default bitmap size is 2048x2048. It is possible to run out of space in this bitmap so try to be conservative with font sizes and number of fonts. Glyphs are grouped by font, size, and blur. A glyph will be rendered once per combination of properties.

Sourcetype font
Sourcetype bounds = {
  1. box : Bounds.t;
  2. advance : float;
}
Sourceval text : t -> x:float -> y:float -> ?start:int -> ?end_:int -> string -> unit

Draw a text substring with the current font at the specified location.

  • parameter x

    The x location to draw the font at. Depending on the current alignment this parameter may represent the center, bottom left, right, etc.

  • parameter y

    The y location to draw the font at. Depending on the current alignment this parameter may represent the center, bottom, top, etc.

  • parameter start

    The starting index of the string. Defaults to 0.

  • parameter end_

    The ending index. Defaults to the end of the string.

Sourceval text_w : t -> x:float -> y:float -> ?start:int -> ?end_:int -> string -> float

Same as text except it returns the rendered length.

Sourceval find_font : t -> name:string -> font option
Sourceval set_size : t -> size:float -> unit

Set the font size in pixel units. Warning: If this font size has not been used yet the glyphs will be generated on demand. This may cause a performance hit on the first rendering at this size. Try to avoid using many different sizes.

Sourceval set_blur : t -> blur:float -> unit

Set the current blur, in pixel units

Sourceval set_line_height : t -> height:float -> unit

Set the spacing between lines

Sourceval set_letter_spacing : t -> spacing:float -> unit

Set the spacing between letters

Sourceval set_align : t -> align:Align.t -> unit

Set the alignment for rendered text. This changes the x,y origin for the rendered text.

Sourceval set_font_face : t -> name:string -> unit

Change the font by name

Sourceval set_font_face_id : t -> id:int -> unit

Change the font by id

Sourceval create : t -> name:string -> file:string -> font option

Create a new font

Sourceval bounds : t -> x:float -> y:float -> ?start:int -> ?end_:int -> string -> bounds
Sourcetype metrics = {
  1. ascender : float;
  2. descender : float;
  3. line_height : float;
}
Sourceval metrics : t -> metrics
Sourcetype text_row = {
  1. start_index : int;
  2. end_index : int;
  3. width : float;
  4. minx : float;
  5. maxx : float;
  6. next : int;
}
Sourceval break_lines : t -> break_width:float -> max_rows:int -> ?start:int -> ?end_:int -> lines:text_row array -> string -> int

Layout lines of text in break_width size rows.

  • parameter break_width

    The maximum width of a row

  • parameter max_rows

    The maximum number of rows to layout. This allows the lines parameter to be used accross different calls to save allocations.

  • parameter start

    The starting index of the string to layout, defaults to 0.

  • parameter end_

    The ending index of the string to layout, default to the end of the string.

  • returns

    The number of rows created.

Sourceval make_empty_rows : int -> text_row array

Helper function to initialize an empty array of rows

Sourcetype glyph_position = {
  1. index : int;
  2. x : float;
  3. min_x : float;
  4. max_x : float;
}

Used to get glyph positions within a rendered string. Can be used for selections or other screen based picking.

Sourceval empty_glyph_position : glyph_position

A glyph_position initialized to all zeros.

Sourceval glyph_positions : t -> x:float -> y:float -> ?start:int -> ?end_:int -> glyphs:glyph_position array -> string -> int
Sourceval text_box : t -> x:float -> y:float -> break_width:float -> ?start:int -> ?end_:int -> string -> unit
Sourceval box_bounds : t -> x:float -> y:float -> break_width:float -> ?start:int -> ?end_:int -> string -> Bounds.t
Sourceval add_fallback_id : t -> font:font -> fallback:font -> unit
Sourceval add_fallback : t -> name:string -> fallback:string -> unit
Sourceval reset_fallback_id : t -> font:font -> unit
Sourceval reset_fallback : t -> name:string -> unit