1 <chapter id="buffers-language-script-and-direction">
2 <title>Buffers, language, script and direction</title>
4 The input to Harfbuzz is a series of Unicode characters, stored in a
5 buffer. In this chapter, we'll look at how to set up a buffer with
6 the text that we want and then customize the properties of the
9 <section id="creating-and-destroying-buffers">
10 <title>Creating and destroying buffers</title>
12 As we saw in our initial example, a buffer is created and
13 initialized with <literal>hb_buffer_create()</literal>. This
14 produces a new, empty buffer object, instantiated with some
15 default values and ready to accept your Unicode strings.
18 Harfbuzz manages the memory of objects that it creates (such as
19 buffers), so you don't have to. When you have finished working on
20 a buffer, you can call <literal>hb_buffer_destroy()</literal>:
22 <programlisting language="C">
23 hb_buffer_t *buffer = hb_buffer_create();
25 hb_buffer_destroy(buffer);
28 This will destroy the object and free its associated memory -
29 unless some other part of the program holds a reference to this
30 buffer. If you acquire a Harfbuzz buffer from another subsystem
31 and want to ensure that it is not garbage collected by someone
32 else destroying it, you should increase its reference count:
34 <programlisting language="C">
35 void somefunc(hb_buffer_t *buffer) {
36 buffer = hb_buffer_reference(buffer);
40 And then decrease it once you're done with it:
42 <programlisting language="C">
43 hb_buffer_destroy(buffer);
47 To throw away all the data in your buffer and start from scratch,
48 call <literal>hb_buffer_reset(buffer)</literal>. If you want to
49 throw away the string in the buffer but keep the options, you can
50 instead call <literal>hb_buffer_clear_contents(buffer)</literal>.
53 <section id="adding-text-to-the-buffer">
54 <title>Adding text to the buffer</title>
56 Now we have a brand new Harfbuzz buffer. Let's start filling it
57 with text! From Harfbuzz's perspective, a buffer is just a stream
58 of Unicode codepoints, but your input string is probably in one of
59 the standard Unicode character encodings (UTF-8, UTF-16, UTF-32)
62 <section id="setting-buffer-properties">
63 <title>Setting buffer properties</title>
67 <section id="what-about-the-other-scripts">
68 <title>What about the other scripts?</title>
72 <section id="customizing-unicode-functions">
73 <title>Customizing Unicode functions</title>