|
Packit |
874993 |
<chapter id="buffers-language-script-and-direction">
|
|
Packit |
874993 |
<title>Buffers, language, script and direction</title>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
The input to Harfbuzz is a series of Unicode characters, stored in a
|
|
Packit |
874993 |
buffer. In this chapter, we'll look at how to set up a buffer with
|
|
Packit |
874993 |
the text that we want and then customize the properties of the
|
|
Packit |
874993 |
buffer.
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
<section id="creating-and-destroying-buffers">
|
|
Packit |
874993 |
<title>Creating and destroying buffers</title>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
As we saw in our initial example, a buffer is created and
|
|
Packit |
874993 |
initialized with <literal>hb_buffer_create()</literal>. This
|
|
Packit |
874993 |
produces a new, empty buffer object, instantiated with some
|
|
Packit |
874993 |
default values and ready to accept your Unicode strings.
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
Harfbuzz manages the memory of objects that it creates (such as
|
|
Packit |
874993 |
buffers), so you don't have to. When you have finished working on
|
|
Packit |
874993 |
a buffer, you can call <literal>hb_buffer_destroy()</literal>:
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
<programlisting language="C">
|
|
Packit |
874993 |
hb_buffer_t *buffer = hb_buffer_create();
|
|
Packit |
874993 |
...
|
|
Packit |
874993 |
hb_buffer_destroy(buffer);
|
|
Packit |
874993 |
</programlisting>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
This will destroy the object and free its associated memory -
|
|
Packit |
874993 |
unless some other part of the program holds a reference to this
|
|
Packit |
874993 |
buffer. If you acquire a Harfbuzz buffer from another subsystem
|
|
Packit |
874993 |
and want to ensure that it is not garbage collected by someone
|
|
Packit |
874993 |
else destroying it, you should increase its reference count:
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
<programlisting language="C">
|
|
Packit |
874993 |
void somefunc(hb_buffer_t *buffer) {
|
|
Packit |
874993 |
buffer = hb_buffer_reference(buffer);
|
|
Packit |
874993 |
...
|
|
Packit |
874993 |
</programlisting>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
And then decrease it once you're done with it:
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
<programlisting language="C">
|
|
Packit |
874993 |
hb_buffer_destroy(buffer);
|
|
Packit |
874993 |
}
|
|
Packit |
874993 |
</programlisting>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
To throw away all the data in your buffer and start from scratch,
|
|
Packit |
874993 |
call <literal>hb_buffer_reset(buffer)</literal>. If you want to
|
|
Packit |
874993 |
throw away the string in the buffer but keep the options, you can
|
|
Packit |
874993 |
instead call <literal>hb_buffer_clear_contents(buffer)</literal>.
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
</section>
|
|
Packit |
874993 |
<section id="adding-text-to-the-buffer">
|
|
Packit |
874993 |
<title>Adding text to the buffer</title>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
Now we have a brand new Harfbuzz buffer. Let's start filling it
|
|
Packit |
874993 |
with text! From Harfbuzz's perspective, a buffer is just a stream
|
|
Packit |
874993 |
of Unicode codepoints, but your input string is probably in one of
|
|
Packit |
874993 |
the standard Unicode character encodings (UTF-8, UTF-16, UTF-32)
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
</section>
|
|
Packit |
874993 |
<section id="setting-buffer-properties">
|
|
Packit |
874993 |
<title>Setting buffer properties</title>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
</section>
|
|
Packit |
874993 |
<section id="what-about-the-other-scripts">
|
|
Packit |
874993 |
<title>What about the other scripts?</title>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
</section>
|
|
Packit |
874993 |
<section id="customizing-unicode-functions">
|
|
Packit |
874993 |
<title>Customizing Unicode functions</title>
|
|
Packit |
874993 |
<para>
|
|
Packit |
874993 |
</para>
|
|
Packit |
874993 |
</section>
|
|
Packit |
874993 |
</chapter>
|