Skip to content

class HbBuffer

The main structure holding the input text and its properties before shaping, and output glyphs and their information after shaping.

Lua wrapper for hb_buffer_t type.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!


methods


HbBuffer.new


function HbBuffer.new() ->  HbBuffer {
    CLUSTER_LEVEL_MONOTONE_GRAPHEMES = 0,
    CLUSTER_LEVEL_MONOTONE_CHARACTERS = 1,
    CLUSTER_LEVEL_CHARACTERS = 2,
    CLUSTER_LEVEL_DEFAULT = 0,
    GLYPH_FLAG_UNSAFE_TO_BREAK = 1,
    GLYPH_FLAG_DEFINED = 3,
    new = function,
    add_utf8 = function,
    add_codepoints = function,
    set_direction = function,
    get_direction = function,
    set_script = function,
    ...(+9)
}

Create a new Buffer object with all properties to defaults.

Wraps hb_buffer_create.

Reference:

HbBuffer.add_utf8


function HbBuffer.add_utf8(
  text: string,
  item_offset: integer?,
  item_length: integer?
)
@param text - UTF8 encoded string.

@param item_offset - The offset of the first character to add to the buffer.

@param item_length - The number of characters to add to the buffer , or -1 for the end of text.

😱 Types incomplete or incorrect? 🙏 Please contribute!

Replace invalid UTF-8 characters with the buffer replacement code point.

Wraps hb_buffer_add_utf8.

Reference:

HbBuffer.add_codepoints


function HbBuffer.add_codepoints(
  text: integer[],
  item_offset: integer?,
  item_length: integer?
)
@param text - with codepoints as lua numbers.

@param item_offset - The offset of the first character to add to the buffer.

@param item_length - The number of characters to add to the buffer , or -1 for the end of text.

😱 Types incomplete or incorrect? 🙏 Please contribute!

Appends characters from text array to buffer .

The item_offset is the position of the first character from text that will be appended, and item_length is the number of character. When shaping part of a larger text (e.g. a run of text from a paragraph), instead of passing just the substring corresponding to the run, it is preferable to pass the whole paragraph and specify the run start and length as item_offset and item_length, respectively, to give HarfBuzz the full context to be able, for example, to do cross-run Arabic shaping or properly handle combining marks at stat of run.

This function does not check the validity of text, it is up to the caller to ensure it contains a valid Unicode scalar values. In contrast, Buffer:add_utf8() can be used that takes similar input but performs sanity-check on the input.

Wraps hb_buffer_add_codepoints.

Reference:

@see HbBuffer.add_utf8

HbBuffer.set_direction


function HbBuffer.set_direction(dir: HbDirection {
    LTR = integer?,
    RTL = integer?,
    TTB = integer?,
    BTT = integer?,
    new = function,
    __to_string = function,
    __eq = function,
    is_valid = function,
    is_horizontal = function,
    is_vertical = function,
    is_forward = function,
    is_backward = function,
    ...(+0)
})
@param dir - A Direction object.

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_set_direction.

Reference:

HbBuffer.get_direction


function HbBuffer.get_direction() ->  HbDirection {
    LTR = integer?,
    RTL = integer?,
    TTB = integer?,
    BTT = integer?,
    new = function,
    __to_string = function,
    __eq = function,
    is_valid = function,
    is_horizontal = function,
    is_vertical = function,
    is_forward = function,
    is_backward = function,
    ...(+0)
}

@return - A Direction object.

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_get_direction.

Reference:

HbBuffer.set_script


function HbBuffer.set_script(script: HbScript {
    COMMON = string,
    INHERITED = string,
    UNKNOWN = string,
    INVALID = string,
    new = function,
    from_iso15924_tag = function,
    to_iso15924_tag = function,
    __to_string = function,
    __eq = function,
})
@param script - A Script object.

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_set_script.

Reference:

HbBuffer.get_script


function HbBuffer.get_script() ->  HbScript {
    COMMON = string,
    INHERITED = string,
    UNKNOWN = string,
    INVALID = string,
    new = function,
    from_iso15924_tag = function,
    to_iso15924_tag = function,
    __to_string = function,
    __eq = function,
}

@return - A Script object.

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_get_script.

Reference:

HbBuffer.set_language


function HbBuffer.set_language(lang: HbLanguage {
    INVALID = HbLanguage,
    new = function,
    __tostring = function,
    __eq = function,
})
@param lang - A Language object

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_set_language.

Reference:

HbBuffer.get_language


function HbBuffer.get_language() ->  HbLanguage {
    INVALID = HbLanguage,
    new = function,
    __tostring = function,
    __eq = function,
}

@return - A Language object

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_get_language.

Reference:

HbBuffer.reverse


function HbBuffer.reverse()

Wraps hb_buffer_reverse.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.get_length


function HbBuffer.get_length()

Wraps hb_buffer_get_length.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.get_cluster_level


function HbBuffer.get_cluster_level() -> level integer

@return level - see Cluster Levels

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_get_cluster_level.

Reference:

HbBuffer.set_cluster_level


function HbBuffer.set_cluster_level(level: integer)
@param level - see Cluster Levels

😱 Types incomplete or incorrect? 🙏 Please contribute!

Wraps hb_buffer_set_cluster_level.

Reference:

HbBuffer.guess_segment_properties


function HbBuffer.guess_segment_properties()

Wraps hb_buffer_guess_segment_properties.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.get_glyphs


function HbBuffer.get_glyphs() ->  HbGlyph[]

Helper method to get shaped glyph data. Calls hb_buffer_get_glyph_infos, hb_buffer_get_glyph_positions and hb_glyph_info_get_glyph_flags, and assembles the data into a Lua table.

Reference:

fields


HbBuffer.CLUSTER_LEVEL_MONOTONE_GRAPHEMES


HbBuffer.CLUSTER_LEVEL_MONOTONE_GRAPHEMES: integer = 0

Cluster Levels. See Harfbuzz docs for more details about what each of these levels mean.

Wraps HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.CLUSTER_LEVEL_MONOTONE_CHARACTERS


HbBuffer.CLUSTER_LEVEL_MONOTONE_CHARACTERS: integer = 1

Wraps HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.CLUSTER_LEVEL_CHARACTERS


HbBuffer.CLUSTER_LEVEL_CHARACTERS: integer = 2

Wraps HB_BUFFER_CLUSTER_LEVEL_CHARACTERS.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.CLUSTER_LEVEL_DEFAULT


HbBuffer.CLUSTER_LEVEL_DEFAULT: integer = 0

Wraps HB_BUFFER_CLUSTER_LEVEL_DEFAULT.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.GLYPH_FLAG_UNSAFE_TO_BREAK


HbBuffer.GLYPH_FLAG_UNSAFE_TO_BREAK: integer = 1

Wraps HB_GLYPH_FLAG_UNSAFE_TO_BREAK.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

HbBuffer.GLYPH_FLAG_DEFINED


HbBuffer.GLYPH_FLAG_DEFINED: integer = 3

Wraps HB_GLYPH_FLAG_DEFINED.

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!