< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_font library

Description

gh_font is the module that manages True Type Fonts (TTF) or Open Type Fonts (OTF). This module is available on all platforms (Windows, Linux, mac OS and Raspberry Pi).


Number of functions: 14

  1. gh_font.build_texture (Lua - Python)
  2. gh_font.clear (Lua - Python)
  3. gh_font.create (Lua - Python)
  4. gh_font.create_v2 (Lua - Python)
  5. gh_font.create_from_zip (Lua - Python)
  6. gh_font.create_from_buffer (Lua - Python)
  7. gh_font.create_from_sqlite3_blob (Lua - Python)
  8. gh_font.get_texture (Lua - Python)
  9. gh_font.get_text_width (Lua - Python)
  10. gh_font.render (Lua - Python)
  11. gh_font.text_2d (Lua - Python)
  12. gh_font.text_2d_v2 (Lua - Python)
  13. gh_font.text_3d (Lua - Python)
  14. gh_font.update (Lua - Python)



build_texture

Description

Builds the font texture.


Syntax

gh_font.build_texture(
 font_id,
 texture_unit
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.build_texture(font, 0)
            


clear

Description

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


Syntax

gh_font.clear(
 font_id
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


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


create

Description

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


Syntax

font = gh_font.create(
 font_filename,
 font_height,
 font_texture_width,
 font_texture_height
)

Languages

Lua - Python


Parameters


Return Values


Code sample


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


create_v2

Description

Creates a font object from built-in TTF font.


Syntax

font = gh_font.create_v2(
 font_name,
 font_height,
 font_texture_width,
 font_texture_height
)

Languages

Lua - Python


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 = gh_font.create_v2(built_in_fonts[1], 24, 512, 512)
            


create_from_zip

Description

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


Syntax

font = gh_font.create_from_zip(
 zip_filename,
 filename,
 font_height,
 font_texture_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages

Lua - Python


Parameters


Return Values


Code sample

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


create_from_buffer

Description

Creates a font from a memory buffer.


Syntax

font = gh_font.create_from_buffer(
 buffer_ptr,
 buffer_size,
 font_height,
 font_texture_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages

Lua - Python


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 = 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 = gh_font.create_from_sqlite3_blob(
 dbid,
 column,
 font_height,
 font_texture_width,
 font_texture_height,
 char_offset_start,
 num_chars
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
font = gh_font.create_from_sqlite3_blob(dbid, column, 24, 512, 512, 32, 256)
            


get_texture

Description

Gets the front texture identifier.


Syntax

font_tex = gh_font.get_texture(
 font_id
)

Languages

Lua - Python


Parameters


Return Values


Code sample


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


get_text_width

Description

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


Syntax

width = gh_font.get_text_width(
 font_id,
 text
)

Languages

Lua - Python


Parameters


Return Values


Code sample


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


render

Description

Renders the font. Performs the real drawing.


Syntax

gh_font.render(
 font_id
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.render(font)
            


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
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.text_2d(font, 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
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.text_2d(font, x, y, r, g, b, a, "Hello...")
gh_font.text_2d_v2(font, 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

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_font.text_3d(font, 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

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


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






GeeXLab Rootard Guide | Downloads | Contact | Newsletter