< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_font library

Description

gh_font is the module that manages TrueType Fonts (TTF) or OpenType Fonts (OTF). This module is available on all platforms (Windows, Linux, macOS, Raspberry Pi and Tinker Board).


Number of functions: 19

  1. gh_font.build_texture ()
  2. gh_font.clear ()
  3. gh_font.create ()
  4. gh_font.create_from_buffer ()
  5. gh_font.create_from_sqlite3_blob ()
  6. gh_font.create_from_zip ()
  7. gh_font.create_v2 ()
  8. gh_font.create_v3 ()
  9. gh_font.get_text_width ()
  10. gh_font.get_texture ()
  11. gh_font.render ()
  12. gh_font.set_scale ()
  13. gh_font.text_2d ()
  14. gh_font.text_2d_v2 ()
  15. gh_font.text_3d ()
  16. gh_font.update ()
  17. gh_font.update_texture_2d_array_layer ()
  18. gh_font.wtext_2d ()
  19. gh_font.wtext_2d_v2 ()



build_texture

Description

Builds the font texture.


Syntax

gh_font.build_texture(
 font_id,
 tex_unit
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.build_texture(font_id, 0)
			


clear

Description

This function clears the draw text list. This function is used with dynamic texts.


Syntax

gh_font.clear(
 font_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.clear(font_id)
gh_font.text_2d(font_id, x, y, r, g, b, a, "Hello!")
gh_font.update(font_id, 0)
gh_font.render(font_id)
			


create

Description

Creates a font object from a TTF or an OTF file.


Syntax

font_id = gh_font.create(
 font_filename,
 font_height,
 font_tex_width,
 font_texture_height
)

Languages


Parameters


Return Values


Code sample


local demo_dir = gh_utils.get_demo_dir()
font_id = gh_font.create(demo_dir .. "./data/kool.ttf", 24, 512, 512)
			


create_from_buffer

Description

Creates a font from a memory buffer.


Syntax

font_id = gh_font.create_from_buffer(
 buff_ptr,
 buff_size,
 font_height,
 font_tex_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages


Parameters


Return Values


Code sample


local demo_dir = gh_utils.get_demo_dir()
filename = demo_dir .. "assets/arial.ttf"
buffer, buffer_size = gh_utils.file_buffer_create(filename)

font_id = gh_font.create_from_buffer(buffer, buffer_size, 24, 512, 512, 32, 256)

gh_utils.file_buffer_kill(buffer)
			


create_from_sqlite3_blob

Description

Creates a font from raw data stored a in a SQLite3 blob.


Syntax

font_id = gh_font.create_from_sqlite3_blob(
 db_id,
 column,
 font_height,
 font_tex_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages


Parameters


Return Values


Code sample


font_id = gh_font.create_from_sqlite3_blob(db_id, column, 24, 512, 512, 32, 256)
			


create_from_zip

Description

Creates a font from a file stored in a zip archive.


Syntax

font_id = gh_font.create_from_zip(
 zip_filename,
 filename,
 font_height,
 font_tex_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages


Parameters


Return Values


Code sample


zip_filename = demo_dir .. "data.zip"
font_id = gh_font.create_from_zip_v1(zip_filename, "fonts/arial.ttf", 24, 512, 512, 32, 256)
			


create_v2

Description

Creates a font object from a built-in TrueType (TTF) font.


Syntax

font_id = gh_font.create_v2(
 font_name,
 font_height,
 font_tex_width,
 font_texture_height
)

Languages


Parameters


Return Values


Code sample


local built_in_fonts = {"roboto_bold", "roboto_medium", "roboto_medium_italic", "technott", "hacked", "top_secret", "timeless_bold", "vcr_osd_mono1"}

font_id = gh_font.create_v2(built_in_fonts[1], 24, 512, 512)
			


create_v3

Description

Creates a font object from a TTF or an OTF file. The range of characters that must be loaded is also specified. Useful to load fonts with Chinese characters for example.


Syntax

font_id = gh_font.create_v3(
 font_filename,
 font_height,
 font_tex_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages


Parameters


Return Values


Code sample


char_offset_start = 32
num_chars = 256
font_id = gh_font.create(demo_dir .. "data/kool.ttf", 24, 512, 512, char_offset_start, num_chars)
			


get_text_width

Description

Returns the width of the text in pixels according to the TrueType font and the font size.


Syntax

width = gh_font.get_text_width(
 font_id,
 text
)

Languages


Parameters


Return Values


Code sample


text_width = gh_font.get_text_width(font_id, "Hello!")
			


get_texture

Description

Gets the front texture identifier.


Syntax

font_tex_id = gh_font.get_texture(
 font_id
)

Languages


Parameters


Return Values


Code sample


font_tex = gh_font.get_texture(font_id)
...
gh_texture.bind(font_tex, 0)
			


render

Description

Renders the font. Performs the real drawing.


Syntax

gh_font.render(
 font_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.render(font_id)
			


set_scale

Description

Sets the scale for rendering.


Syntax

gh_font.set_scale(
 font_id,
 scale
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.set_scale(font_id, 2.0)
			


text_2d

Description

Sets a text in 2D. The text is added in a list and the real draw will occur later with a call to gh_font.render().


Syntax

gh_font.text_2d(
 font_id,
 x, y,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.text_2d(font_id, x, y, r, g, b, a, "Hello!")
			


text_2d_v2

Description

Like text_2d(), text_2d_v2() sets a text in 2D. But this function takes no position. It simply appends the text on the same line than the previous one.


Syntax

gh_font.text_2d_v2(
 font_id,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.text_2d(font_id, x, y, r, g, b, a, "Hello...")
gh_font.text_2d_v2(font_id, r, g, b, a, " from GeeXLab!")
			


text_3d

Description

Sets a text in 3D. The text is added in a list and the real draw will occur later with a call to gh_font.render().


Syntax

gh_font.text_3d(
 font_id,
 x, y, z,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.text_3d(font_id, x, y, z, r, g, b, a, "Hello!")
			


update

Description

Updates the font before the real rendering.


Syntax

gh_font.update(
 font_id,
 mapped_gpu_memory
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.clear(font_id)
gh_font.text_2d(font_id, x, y, r, g, b, a, "Hello!")
gh_font.update(font_id, 0)
gh_font.render(font_id)
			


update_texture_2d_array_layer

Description

Update a layer of a texture array with the font texture.


Syntax

gh_font.update_texture_2d_array_layer(
 font_id,
 texarray_id,
 layer
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


layer = 0
gh_font.update_texture_2d_array_layer(font_id, texarray_id, layer)
			


wtext_2d

Description

Sets a text in 2D. The text is added in a list and the real draw will occur later with a call to gh_font.render().


Syntax

gh_font.wtext_2d(
 font_id,
 x, y,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.wtext_2d(font_id, x, y, r, g, b, a, "Hello!")
			


wtext_2d_v2

Description

Like wtext_2d(), wtext_2d_v2() sets a text in 2D. But this function takes no position. It simply appends the text on the same line than the previous one.


Syntax

gh_font.wtext_2d_v2(
 font_id,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.wtext_2d(font_id, x, y, r, g, b, a, "Hello...")
gh_font.wtext_2d_v2(font_id, r, g, b, a, " from GeeXLab!")
			






GeeXLab Rootard Guide | Downloads | Contact | Newsletter