Buffers containing input characters still need several properties set before HarfBuzz can shape their text correctly.
Initially, all buffers are set to the
type. After adding text, the buffer should be set to
HB_BUFFER_CONTENT_TYPE_UNICODE instead, which
indicates that it contains un-shaped input
characters. After shaping, the buffer will have the
HB_BUFFER_CONTENT_TYPE_GLYPHS content type.
hb_buffer_add_utf8() and the
other UTF functions set the content type of their buffer
automatically. But if you are reusing a buffer you may want to
check its state with
necessary you can set the content type with
to prepare for shaping.
Buffers also need to carry information about the script, language, and text direction of their contents. You can set these properties individually:
hb_buffer_set_direction(buf, HB_DIRECTION_LTR); hb_buffer_set_script(buf, HB_SCRIPT_LATIN); hb_buffer_set_language(buf, hb_language_from_string("en", -1));
However, since these properties are often repeated for
multiple text runs, you can also save them in a
hb_segment_properties_t for reuse:
hb_segment_properties_t *savedprops; hb_buffer_get_segment_properties (buf, savedprops); ... hb_buffer_set_segment_properties (buf2, savedprops);
HarfBuzz also provides getter functions to retrieve a buffer's direction, script, and language properties individually.
HarfBuzz recognizes four text directions in
HB_DIRECTION_LTR), right-to-left (
HB_DIRECTION_BTT). For the
script property, HarfBuzz uses identifiers based on the
standard. For languages, HarfBuzz uses tags based on the
IETF BCP 47 standard.
Helper functions are provided to convert character strings into the necessary script and language tag types.
Two additional buffer properties to be aware of are the
"invisible glyph" and the replacement code point. The
replacement code point is inserted into buffer output in place of
any invalid code points encountered in the input. By default, it
is the Unicode
REPLACEMENT CHARACTER code
U+FFFD "�". You can change this with
passing in the replacement Unicode code point as the
The invisible glyph is used to replace all output glyphs that
are invisible. By default, the standard space character
U+0020 is used; you can replace this (for
example, when using a font that provides script-specific
Do note that in the
parameter, you must provide the glyph ID of the replacement you
wish to use, not the Unicode code point.
HarfBuzz supports a few additional flags you might want to set
on your buffer under certain circumstances. The
HB_BUFFER_FLAG_EOT flags tell HarfBuzz
that the buffer represents the beginning or end (respectively)
of a text element (such as a paragraph or other block). Knowing
this allows HarfBuzz to apply certain contextual font features
when shaping, such as initial or final variants in connected
tells HarfBuzz not to hide glyphs with the
Default_Ignorable property in Unicode. This
property designates control characters and other non-printing
code points, such as joiners and variation selectors. Normally
HarfBuzz replaces them in the output buffer with zero-width
space glyphs (using the "invisible glyph" property discussed
above); setting this flag causes them to be printed, which can
be helpful for troubleshooting.
Conversely, setting the
tells HarfBuzz to remove
glyphs from the output buffer entirely. Finally, setting the
flag tells HarfBuzz not to insert the dotted-circle glyph
U+25CC, "◌"), which is normally
inserted into buffer output when broken character sequences are
encountered (such as combining marks that are not attached to a