blob: 3a26c553cf168a08006989a629f79db386a15c42 [file] [log] [blame]
Simon Cozens11a07c42015-08-31 10:39:10 +01001<chapter id="buffers-language-script-and-direction">
Simon Cozens5470e742015-08-29 08:21:18 +01002 <title>Buffers, language, script and direction</title>
3 <para>
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
7 buffer.
8 </para>
Simon Cozens11a07c42015-08-31 10:39:10 +01009 <section id="creating-and-destroying-buffers">
Simon Cozens5470e742015-08-29 08:21:18 +010010 <title>Creating and destroying buffers</title>
11 <para>
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.
16 </para>
17 <para>
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>:
21 </para>
22 <programlisting language="C">
23 hb_buffer_t *buffer = hb_buffer_create();
24 ...
25 hb_buffer_destroy(buffer);
26</programlisting>
27 <para>
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:
33 </para>
34 <programlisting language="C">
35void somefunc(hb_buffer_t *buffer) {
36 buffer = hb_buffer_reference(buffer);
37 ...
38</programlisting>
39 <para>
40 And then decrease it once you're done with it:
41 </para>
42 <programlisting language="C">
43 hb_buffer_destroy(buffer);
44}
45</programlisting>
46 <para>
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>.
51 </para>
Simon Cozens11a07c42015-08-31 10:39:10 +010052 </section>
53 <section id="adding-text-to-the-buffer">
Simon Cozens5470e742015-08-29 08:21:18 +010054 <title>Adding text to the buffer</title>
55 <para>
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
Behdad Esfahbodd2059652015-08-31 10:12:05 +010059 the standard Unicode character encodings (UTF-8, UTF-16, UTF-32)
Simon Cozens5470e742015-08-29 08:21:18 +010060 </para>
Simon Cozens11a07c42015-08-31 10:39:10 +010061 </section>
62 <section id="setting-buffer-properties">
Simon Cozens5470e742015-08-29 08:21:18 +010063 <title>Setting buffer properties</title>
64 <para>
65 </para>
Simon Cozens11a07c42015-08-31 10:39:10 +010066 </section>
67 <section id="what-about-the-other-scripts">
Simon Cozens5470e742015-08-29 08:21:18 +010068 <title>What about the other scripts?</title>
69 <para>
70 </para>
Simon Cozens11a07c42015-08-31 10:39:10 +010071 </section>
72 <section id="customizing-unicode-functions">
Simon Cozens5470e742015-08-29 08:21:18 +010073 <title>Customizing Unicode functions</title>
74 <para>
75 </para>
Simon Cozens11a07c42015-08-31 10:39:10 +010076 </section>
77</chapter>