xref: /aosp_15_r20/external/harfbuzz_ng/docs/usermanual-fonts-and-faces.xml (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1*2d1272b8SAndroid Build Coastguard Worker<?xml version="1.0"?>
2*2d1272b8SAndroid Build Coastguard Worker<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3*2d1272b8SAndroid Build Coastguard Worker               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4*2d1272b8SAndroid Build Coastguard Worker  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
5*2d1272b8SAndroid Build Coastguard Worker  <!ENTITY version SYSTEM "version.xml">
6*2d1272b8SAndroid Build Coastguard Worker]>
7*2d1272b8SAndroid Build Coastguard Worker<chapter id="fonts-and-faces">
8*2d1272b8SAndroid Build Coastguard Worker  <title>Fonts, faces, and output</title>
9*2d1272b8SAndroid Build Coastguard Worker    <para>
10*2d1272b8SAndroid Build Coastguard Worker      In the previous chapter, we saw how to set up a buffer and fill
11*2d1272b8SAndroid Build Coastguard Worker      it with text as Unicode code points. In order to shape this
12*2d1272b8SAndroid Build Coastguard Worker      buffer text with HarfBuzz, you will need also need a font
13*2d1272b8SAndroid Build Coastguard Worker      object.
14*2d1272b8SAndroid Build Coastguard Worker    </para>
15*2d1272b8SAndroid Build Coastguard Worker    <para>
16*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz provides abstractions to help you cache and reuse the
17*2d1272b8SAndroid Build Coastguard Worker      heavier parts of working with binary fonts, so we will look at
18*2d1272b8SAndroid Build Coastguard Worker      how to do that. We will also look at how to work with the
19*2d1272b8SAndroid Build Coastguard Worker      FreeType font-rendering library and at how you can customize
20*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz to work with other libraries.
21*2d1272b8SAndroid Build Coastguard Worker    </para>
22*2d1272b8SAndroid Build Coastguard Worker    <para>
23*2d1272b8SAndroid Build Coastguard Worker      Finally, we will look at how to work with OpenType variable
24*2d1272b8SAndroid Build Coastguard Worker      fonts, the latest update to the OpenType font format, and at
25*2d1272b8SAndroid Build Coastguard Worker      some other recent additions to OpenType.
26*2d1272b8SAndroid Build Coastguard Worker    </para>
27*2d1272b8SAndroid Build Coastguard Worker
28*2d1272b8SAndroid Build Coastguard Worker  <section id="fonts-and-faces-objects">
29*2d1272b8SAndroid Build Coastguard Worker    <title>Font and face objects</title>
30*2d1272b8SAndroid Build Coastguard Worker    <para>
31*2d1272b8SAndroid Build Coastguard Worker      The outcome of shaping a run of text depends on the contents of
32*2d1272b8SAndroid Build Coastguard Worker      a specific font file (such as the substitutions and positioning
33*2d1272b8SAndroid Build Coastguard Worker      moves in the 'GSUB' and 'GPOS' tables), so HarfBuzz makes
34*2d1272b8SAndroid Build Coastguard Worker      accessing those internals fast.
35*2d1272b8SAndroid Build Coastguard Worker    </para>
36*2d1272b8SAndroid Build Coastguard Worker    <para>
37*2d1272b8SAndroid Build Coastguard Worker      An <type>hb_face_t</type> represents a <emphasis>face</emphasis>
38*2d1272b8SAndroid Build Coastguard Worker      in HarfBuzz. This data type is a wrapper around an
39*2d1272b8SAndroid Build Coastguard Worker      <type>hb_blob_t</type> blob that holds the contents of a binary
40*2d1272b8SAndroid Build Coastguard Worker      font file. Since HarfBuzz supports TrueType Collections and
41*2d1272b8SAndroid Build Coastguard Worker      OpenType Collections (each of which can include multiple
42*2d1272b8SAndroid Build Coastguard Worker      typefaces), a HarfBuzz face also requires an index number
43*2d1272b8SAndroid Build Coastguard Worker      specifying which typeface in the file you want to use. Most of
44*2d1272b8SAndroid Build Coastguard Worker      the font files you will encounter in the wild include just a
45*2d1272b8SAndroid Build Coastguard Worker      single face, however, so most of the time you would pass in
46*2d1272b8SAndroid Build Coastguard Worker      <literal>0</literal> as the index when you create a face:
47*2d1272b8SAndroid Build Coastguard Worker    </para>
48*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
49*2d1272b8SAndroid Build Coastguard Worker      hb_blob_t* blob = hb_blob_create_from_file(file);
50*2d1272b8SAndroid Build Coastguard Worker      ...
51*2d1272b8SAndroid Build Coastguard Worker      hb_face_t* face = hb_face_create(blob, 0);
52*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
53*2d1272b8SAndroid Build Coastguard Worker    <para>
54*2d1272b8SAndroid Build Coastguard Worker      On its own, a face object is not quite ready to use for
55*2d1272b8SAndroid Build Coastguard Worker      shaping. The typeface must be set to a specific point size in
56*2d1272b8SAndroid Build Coastguard Worker      order for some details (such as hinting) to work. In addition,
57*2d1272b8SAndroid Build Coastguard Worker      if the font file in question is an OpenType Variable Font, then
58*2d1272b8SAndroid Build Coastguard Worker      you may need to specify one or more variation-axis settings (or a
59*2d1272b8SAndroid Build Coastguard Worker      named instance) in order to get the output you need.
60*2d1272b8SAndroid Build Coastguard Worker    </para>
61*2d1272b8SAndroid Build Coastguard Worker    <para>
62*2d1272b8SAndroid Build Coastguard Worker      In HarfBuzz, you do this by creating a <emphasis>font</emphasis>
63*2d1272b8SAndroid Build Coastguard Worker      object from your face.
64*2d1272b8SAndroid Build Coastguard Worker    </para>
65*2d1272b8SAndroid Build Coastguard Worker    <para>
66*2d1272b8SAndroid Build Coastguard Worker      Font objects also have the advantage of being considerably
67*2d1272b8SAndroid Build Coastguard Worker      lighter-weight than face objects (remember that a face contains
68*2d1272b8SAndroid Build Coastguard Worker      the contents of a binary font file mapped into memory). As a
69*2d1272b8SAndroid Build Coastguard Worker      result, you can cache and reuse a font object, but you could
70*2d1272b8SAndroid Build Coastguard Worker      also create a new one for each additional size you needed.
71*2d1272b8SAndroid Build Coastguard Worker      Creating new fonts incurs some additional overhead, of course,
72*2d1272b8SAndroid Build Coastguard Worker      but whether or not it is excessive is your call in the end. In
73*2d1272b8SAndroid Build Coastguard Worker      contrast, face objects are substantially larger, and you really
74*2d1272b8SAndroid Build Coastguard Worker      should cache them and reuse them whenever possible.
75*2d1272b8SAndroid Build Coastguard Worker    </para>
76*2d1272b8SAndroid Build Coastguard Worker    <para>
77*2d1272b8SAndroid Build Coastguard Worker      You can create a font object from a face object:
78*2d1272b8SAndroid Build Coastguard Worker    </para>
79*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
80*2d1272b8SAndroid Build Coastguard Worker      hb_font_t* hb_font = hb_font_create(hb_face);
81*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
82*2d1272b8SAndroid Build Coastguard Worker    <para>
83*2d1272b8SAndroid Build Coastguard Worker      After creating a font, there are a few properties you should
84*2d1272b8SAndroid Build Coastguard Worker      set. Many fonts enable and disable hints based on the size it
85*2d1272b8SAndroid Build Coastguard Worker      is used at, so setting this is important for font
86*2d1272b8SAndroid Build Coastguard Worker      objects. <function>hb_font_set_ppem(font, x_ppem,
87*2d1272b8SAndroid Build Coastguard Worker      y_ppem)</function> sets the pixels-per-EM value of the font. You
88*2d1272b8SAndroid Build Coastguard Worker      can also set the point size of the font with
89*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_set_ptem(font, ptem)</function>. HarfBuzz uses the
90*2d1272b8SAndroid Build Coastguard Worker      industry standard 72 points per inch.
91*2d1272b8SAndroid Build Coastguard Worker    </para>
92*2d1272b8SAndroid Build Coastguard Worker    <para>
93*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz lets you specify the degree subpixel precision you want
94*2d1272b8SAndroid Build Coastguard Worker      through a scaling factor. You can set horizontal and
95*2d1272b8SAndroid Build Coastguard Worker      vertical scaling factors on the
96*2d1272b8SAndroid Build Coastguard Worker      font by calling <function>hb_font_set_scale(font, x_scale,
97*2d1272b8SAndroid Build Coastguard Worker      y_scale)</function>.
98*2d1272b8SAndroid Build Coastguard Worker    </para>
99*2d1272b8SAndroid Build Coastguard Worker    <para>
100*2d1272b8SAndroid Build Coastguard Worker      There may be times when you are handed a font object and need to
101*2d1272b8SAndroid Build Coastguard Worker      access the face object that it comes from. For that, you can call
102*2d1272b8SAndroid Build Coastguard Worker    </para>
103*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
104*2d1272b8SAndroid Build Coastguard Worker      hb_face = hb_font_get_face(hb_font);
105*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
106*2d1272b8SAndroid Build Coastguard Worker    <para>
107*2d1272b8SAndroid Build Coastguard Worker      You can also create a font object from an existing font object
108*2d1272b8SAndroid Build Coastguard Worker      using the <function>hb_font_create_sub_font()</function>
109*2d1272b8SAndroid Build Coastguard Worker      function. This creates a child font object that is initiated
110*2d1272b8SAndroid Build Coastguard Worker      with the same attributes as its parent; it can be used to
111*2d1272b8SAndroid Build Coastguard Worker      quickly set up a new font for the purpose of overriding a specific
112*2d1272b8SAndroid Build Coastguard Worker      font-functions method.
113*2d1272b8SAndroid Build Coastguard Worker    </para>
114*2d1272b8SAndroid Build Coastguard Worker    <para>
115*2d1272b8SAndroid Build Coastguard Worker      All face objects and font objects are lifecycle-managed by
116*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz. After creating a face, you increase its reference
117*2d1272b8SAndroid Build Coastguard Worker      count with <function>hb_face_reference(face)</function> and
118*2d1272b8SAndroid Build Coastguard Worker      decrease it with
119*2d1272b8SAndroid Build Coastguard Worker      <function>hb_face_destroy(face)</function>. Likewise, you
120*2d1272b8SAndroid Build Coastguard Worker      increase the reference count on a font with
121*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_reference(font)</function> and decrease it
122*2d1272b8SAndroid Build Coastguard Worker      with <function>hb_font_destroy(font)</function>.
123*2d1272b8SAndroid Build Coastguard Worker    </para>
124*2d1272b8SAndroid Build Coastguard Worker    <para>
125*2d1272b8SAndroid Build Coastguard Worker      You can also attach user data to face objects and font objects.
126*2d1272b8SAndroid Build Coastguard Worker    </para>
127*2d1272b8SAndroid Build Coastguard Worker  </section>
128*2d1272b8SAndroid Build Coastguard Worker
129*2d1272b8SAndroid Build Coastguard Worker <section id="fonts-and-faces-custom-functions">
130*2d1272b8SAndroid Build Coastguard Worker    <title>Customizing font functions</title>
131*2d1272b8SAndroid Build Coastguard Worker    <para>
132*2d1272b8SAndroid Build Coastguard Worker      During shaping, HarfBuzz frequently needs to query font objects
133*2d1272b8SAndroid Build Coastguard Worker      to get at the contents and parameters of the glyphs in a font
134*2d1272b8SAndroid Build Coastguard Worker      file. It includes a built-in set of functions that is tailored
135*2d1272b8SAndroid Build Coastguard Worker      to working with OpenType fonts. However, as was the case with
136*2d1272b8SAndroid Build Coastguard Worker      Unicode functions in the buffers chapter, HarfBuzz also wants to
137*2d1272b8SAndroid Build Coastguard Worker      make it easy for you to assign a substitute set of font
138*2d1272b8SAndroid Build Coastguard Worker      functions if you are developing a program to work with a library
139*2d1272b8SAndroid Build Coastguard Worker      or platform that provides its own font functions.
140*2d1272b8SAndroid Build Coastguard Worker    </para>
141*2d1272b8SAndroid Build Coastguard Worker    <para>
142*2d1272b8SAndroid Build Coastguard Worker      Therefore, the HarfBuzz API defines a set of virtual
143*2d1272b8SAndroid Build Coastguard Worker      methods for accessing font-object properties, and you can
144*2d1272b8SAndroid Build Coastguard Worker      replace the defaults with your own selections without
145*2d1272b8SAndroid Build Coastguard Worker      interfering with the shaping process. Each font object in
146*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz includes a structure called
147*2d1272b8SAndroid Build Coastguard Worker      <literal>font_funcs</literal> that serves as a vtable for the
148*2d1272b8SAndroid Build Coastguard Worker      font object. The virtual methods in
149*2d1272b8SAndroid Build Coastguard Worker      <literal>font_funcs</literal> are:
150*2d1272b8SAndroid Build Coastguard Worker    </para>
151*2d1272b8SAndroid Build Coastguard Worker    <itemizedlist>
152*2d1272b8SAndroid Build Coastguard Worker      <listitem>
153*2d1272b8SAndroid Build Coastguard Worker    <para>
154*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_font_h_extents_func_t</function>: returns
155*2d1272b8SAndroid Build Coastguard Worker      the extents of the font for horizontal text.
156*2d1272b8SAndroid Build Coastguard Worker    </para>
157*2d1272b8SAndroid Build Coastguard Worker      </listitem>
158*2d1272b8SAndroid Build Coastguard Worker      <listitem>
159*2d1272b8SAndroid Build Coastguard Worker    <para>
160*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_font_v_extents_func_t</function>: returns
161*2d1272b8SAndroid Build Coastguard Worker      the extents of the font for vertical text.
162*2d1272b8SAndroid Build Coastguard Worker    </para>
163*2d1272b8SAndroid Build Coastguard Worker      </listitem>
164*2d1272b8SAndroid Build Coastguard Worker      <listitem>
165*2d1272b8SAndroid Build Coastguard Worker    <para>
166*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_nominal_glyph_func_t</function>: returns
167*2d1272b8SAndroid Build Coastguard Worker      the font's nominal glyph for a given code point.
168*2d1272b8SAndroid Build Coastguard Worker    </para>
169*2d1272b8SAndroid Build Coastguard Worker      </listitem>
170*2d1272b8SAndroid Build Coastguard Worker      <listitem>
171*2d1272b8SAndroid Build Coastguard Worker    <para>
172*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_variation_glyph_func_t</function>: returns
173*2d1272b8SAndroid Build Coastguard Worker      the font's glyph for a given code point when it is followed by a
174*2d1272b8SAndroid Build Coastguard Worker      given Variation Selector.
175*2d1272b8SAndroid Build Coastguard Worker    </para>
176*2d1272b8SAndroid Build Coastguard Worker      </listitem>
177*2d1272b8SAndroid Build Coastguard Worker      <listitem>
178*2d1272b8SAndroid Build Coastguard Worker    <para>
179*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_nominal_glyphs_func_t</function>: returns
180*2d1272b8SAndroid Build Coastguard Worker      the font's nominal glyphs for a series of code points.
181*2d1272b8SAndroid Build Coastguard Worker    </para>
182*2d1272b8SAndroid Build Coastguard Worker      </listitem>
183*2d1272b8SAndroid Build Coastguard Worker      <listitem>
184*2d1272b8SAndroid Build Coastguard Worker    <para>
185*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_advance_func_t</function>: returns
186*2d1272b8SAndroid Build Coastguard Worker      the advance for a glyph.
187*2d1272b8SAndroid Build Coastguard Worker    </para>
188*2d1272b8SAndroid Build Coastguard Worker      </listitem>
189*2d1272b8SAndroid Build Coastguard Worker      <listitem>
190*2d1272b8SAndroid Build Coastguard Worker    <para>
191*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_h_advance_func_t</function>: returns
192*2d1272b8SAndroid Build Coastguard Worker      the advance for a glyph for horizontal text.
193*2d1272b8SAndroid Build Coastguard Worker    </para>
194*2d1272b8SAndroid Build Coastguard Worker      </listitem>
195*2d1272b8SAndroid Build Coastguard Worker      <listitem>
196*2d1272b8SAndroid Build Coastguard Worker    <para>
197*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_v_advance_func_t</function>:returns
198*2d1272b8SAndroid Build Coastguard Worker      the advance for a glyph for vertical text.
199*2d1272b8SAndroid Build Coastguard Worker    </para>
200*2d1272b8SAndroid Build Coastguard Worker      </listitem>
201*2d1272b8SAndroid Build Coastguard Worker      <listitem>
202*2d1272b8SAndroid Build Coastguard Worker    <para>
203*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_advances_func_t</function>: returns
204*2d1272b8SAndroid Build Coastguard Worker      the advances for a series of glyphs.
205*2d1272b8SAndroid Build Coastguard Worker    </para>
206*2d1272b8SAndroid Build Coastguard Worker      </listitem>
207*2d1272b8SAndroid Build Coastguard Worker      <listitem>
208*2d1272b8SAndroid Build Coastguard Worker    <para>
209*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_h_advances_func_t</function>: returns
210*2d1272b8SAndroid Build Coastguard Worker      the advances for a series of glyphs for horizontal text .
211*2d1272b8SAndroid Build Coastguard Worker    </para>
212*2d1272b8SAndroid Build Coastguard Worker      </listitem>
213*2d1272b8SAndroid Build Coastguard Worker      <listitem>
214*2d1272b8SAndroid Build Coastguard Worker    <para>
215*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_v_advances_func_t</function>: returns
216*2d1272b8SAndroid Build Coastguard Worker      the advances for a series of glyphs for vertical text.
217*2d1272b8SAndroid Build Coastguard Worker    </para>
218*2d1272b8SAndroid Build Coastguard Worker      </listitem>
219*2d1272b8SAndroid Build Coastguard Worker      <listitem>
220*2d1272b8SAndroid Build Coastguard Worker    <para>
221*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_origin_func_t</function>: returns
222*2d1272b8SAndroid Build Coastguard Worker      the origin coordinates of a glyph.
223*2d1272b8SAndroid Build Coastguard Worker    </para>
224*2d1272b8SAndroid Build Coastguard Worker      </listitem>
225*2d1272b8SAndroid Build Coastguard Worker      <listitem>
226*2d1272b8SAndroid Build Coastguard Worker    <para>
227*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_h_origin_func_t</function>: returns
228*2d1272b8SAndroid Build Coastguard Worker      the origin coordinates of a glyph for horizontal text.
229*2d1272b8SAndroid Build Coastguard Worker    </para>
230*2d1272b8SAndroid Build Coastguard Worker      </listitem>
231*2d1272b8SAndroid Build Coastguard Worker      <listitem>
232*2d1272b8SAndroid Build Coastguard Worker    <para>
233*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_v_origin_func_t</function>: returns
234*2d1272b8SAndroid Build Coastguard Worker      the origin coordinates of a glyph for vertical text.
235*2d1272b8SAndroid Build Coastguard Worker    </para>
236*2d1272b8SAndroid Build Coastguard Worker      </listitem>
237*2d1272b8SAndroid Build Coastguard Worker      <listitem>
238*2d1272b8SAndroid Build Coastguard Worker    <para>
239*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_extents_func_t</function>: returns
240*2d1272b8SAndroid Build Coastguard Worker      the extents for a glyph.
241*2d1272b8SAndroid Build Coastguard Worker    </para>
242*2d1272b8SAndroid Build Coastguard Worker      </listitem>
243*2d1272b8SAndroid Build Coastguard Worker      <listitem>
244*2d1272b8SAndroid Build Coastguard Worker    <para>
245*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_contour_point_func_t</function>:
246*2d1272b8SAndroid Build Coastguard Worker      returns the coordinates of a specific contour point from a glyph.
247*2d1272b8SAndroid Build Coastguard Worker    </para>
248*2d1272b8SAndroid Build Coastguard Worker      </listitem>
249*2d1272b8SAndroid Build Coastguard Worker      <listitem>
250*2d1272b8SAndroid Build Coastguard Worker    <para>
251*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_name_func_t</function>: returns the
252*2d1272b8SAndroid Build Coastguard Worker      name of a glyph (from its glyph index).
253*2d1272b8SAndroid Build Coastguard Worker    </para>
254*2d1272b8SAndroid Build Coastguard Worker      </listitem>
255*2d1272b8SAndroid Build Coastguard Worker      <listitem>
256*2d1272b8SAndroid Build Coastguard Worker    <para>
257*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_glyph_from_name_func_t</function>: returns
258*2d1272b8SAndroid Build Coastguard Worker      the glyph index that corresponds to a given glyph name.
259*2d1272b8SAndroid Build Coastguard Worker    </para>
260*2d1272b8SAndroid Build Coastguard Worker      </listitem>
261*2d1272b8SAndroid Build Coastguard Worker      <listitem>
262*2d1272b8SAndroid Build Coastguard Worker    <para>
263*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_draw_glyph_func_t</function>: gets the outlines
264*2d1272b8SAndroid Build Coastguard Worker      of a glyph (by calling #hb_draw_funcs_t callbacks).
265*2d1272b8SAndroid Build Coastguard Worker    </para>
266*2d1272b8SAndroid Build Coastguard Worker      </listitem>
267*2d1272b8SAndroid Build Coastguard Worker      <listitem>
268*2d1272b8SAndroid Build Coastguard Worker    <para>
269*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_paint_glyph_func_t</function>: paints a glyph
270*2d1272b8SAndroid Build Coastguard Worker      (by calling #hb_paint_funcs_t callbacks).
271*2d1272b8SAndroid Build Coastguard Worker    </para>
272*2d1272b8SAndroid Build Coastguard Worker      </listitem>
273*2d1272b8SAndroid Build Coastguard Worker    </itemizedlist>
274*2d1272b8SAndroid Build Coastguard Worker    <para>
275*2d1272b8SAndroid Build Coastguard Worker      You can create new font-functions by calling
276*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_funcs_create()</function>:
277*2d1272b8SAndroid Build Coastguard Worker    </para>
278*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
279*2d1272b8SAndroid Build Coastguard Worker      hb_font_funcs_t *ffunctions = hb_font_funcs_create ();
280*2d1272b8SAndroid Build Coastguard Worker      hb_font_set_funcs (font, ffunctions, font_data, destroy);
281*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
282*2d1272b8SAndroid Build Coastguard Worker    <para>
283*2d1272b8SAndroid Build Coastguard Worker      The individual methods can each be set with their own setter
284*2d1272b8SAndroid Build Coastguard Worker      function, such as
285*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_funcs_set_nominal_glyph_func(ffunctions,
286*2d1272b8SAndroid Build Coastguard Worker      func, user_data, destroy)</function>.
287*2d1272b8SAndroid Build Coastguard Worker    </para>
288*2d1272b8SAndroid Build Coastguard Worker    <para>
289*2d1272b8SAndroid Build Coastguard Worker      Font-functions structures can be reused for multiple font
290*2d1272b8SAndroid Build Coastguard Worker      objects, and can be reference counted with
291*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_funcs_reference()</function> and
292*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_funcs_destroy()</function>. Just like other
293*2d1272b8SAndroid Build Coastguard Worker      objects in HarfBuzz, you can set user-data for each
294*2d1272b8SAndroid Build Coastguard Worker      font-functions structure and assign a destroy callback for
295*2d1272b8SAndroid Build Coastguard Worker      it.
296*2d1272b8SAndroid Build Coastguard Worker    </para>
297*2d1272b8SAndroid Build Coastguard Worker    <para>
298*2d1272b8SAndroid Build Coastguard Worker      You can also mark a font-functions structure as immutable,
299*2d1272b8SAndroid Build Coastguard Worker      with <function>hb_font_funcs_make_immutable()</function>. This
300*2d1272b8SAndroid Build Coastguard Worker      is especially useful if your code is a library or framework that
301*2d1272b8SAndroid Build Coastguard Worker      will have its own client programs. By marking your
302*2d1272b8SAndroid Build Coastguard Worker      font-functions structures as immutable, you prevent your client
303*2d1272b8SAndroid Build Coastguard Worker      programs from changing the configuration and introducing
304*2d1272b8SAndroid Build Coastguard Worker      inconsistencies and errors downstream.
305*2d1272b8SAndroid Build Coastguard Worker    </para>
306*2d1272b8SAndroid Build Coastguard Worker    <para>
307*2d1272b8SAndroid Build Coastguard Worker      To override only some functions while using the default implementation
308*2d1272b8SAndroid Build Coastguard Worker      for the others, you will need to create a sub-font. By default, the
309*2d1272b8SAndroid Build Coastguard Worker      sub-font uses the font functions of its parent except for the functions
310*2d1272b8SAndroid Build Coastguard Worker      that were explicitly set. The following code will override only the
311*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_get_nominal_glyph_func_t</function> for the sub-font:
312*2d1272b8SAndroid Build Coastguard Worker    </para>
313*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
314*2d1272b8SAndroid Build Coastguard Worker      hb_font_t *subfont = hb_font_create_sub_font (font)
315*2d1272b8SAndroid Build Coastguard Worker      hb_font_funcs_t *ffunctions = hb_font_funcs_create ();
316*2d1272b8SAndroid Build Coastguard Worker      hb_font_funcs_set_nominal_glyph_func (ffunctions, func, user_data, destroy);
317*2d1272b8SAndroid Build Coastguard Worker      hb_font_set_funcs (subfont, ffunctions, font_data, destroy);
318*2d1272b8SAndroid Build Coastguard Worker      hb_font_funcs_destroy (ffunctions);
319*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
320*2d1272b8SAndroid Build Coastguard Worker  </section>
321*2d1272b8SAndroid Build Coastguard Worker
322*2d1272b8SAndroid Build Coastguard Worker  <section id="fonts-and-faces-native-opentype">
323*2d1272b8SAndroid Build Coastguard Worker    <title>Font objects and HarfBuzz's native OpenType implementation</title>
324*2d1272b8SAndroid Build Coastguard Worker    <para>
325*2d1272b8SAndroid Build Coastguard Worker      By default, whenever HarfBuzz creates a font object, it will
326*2d1272b8SAndroid Build Coastguard Worker      configure the font to use a built-in set of font functions that
327*2d1272b8SAndroid Build Coastguard Worker      supports contemporary OpenType font internals. If you want to
328*2d1272b8SAndroid Build Coastguard Worker      work with OpenType or TrueType fonts, you should be able to use
329*2d1272b8SAndroid Build Coastguard Worker      these functions without difficulty.
330*2d1272b8SAndroid Build Coastguard Worker    </para>
331*2d1272b8SAndroid Build Coastguard Worker    <para>
332*2d1272b8SAndroid Build Coastguard Worker      Many of the methods in the font-functions structure deal with
333*2d1272b8SAndroid Build Coastguard Worker      the fundamental properties of glyphs that are required for
334*2d1272b8SAndroid Build Coastguard Worker      shaping text: extents (the maximums and minimums on each axis),
335*2d1272b8SAndroid Build Coastguard Worker      origins (the <literal>(0,0)</literal> coordinate point which
336*2d1272b8SAndroid Build Coastguard Worker      glyphs are drawn in reference to), and advances (the amount that
337*2d1272b8SAndroid Build Coastguard Worker      the cursor needs to be moved after drawing each glyph, including
338*2d1272b8SAndroid Build Coastguard Worker      any empty space for the glyph's side bearings).
339*2d1272b8SAndroid Build Coastguard Worker    </para>
340*2d1272b8SAndroid Build Coastguard Worker    <para>
341*2d1272b8SAndroid Build Coastguard Worker      As you can see in the list of functions, there are separate "horizontal"
342*2d1272b8SAndroid Build Coastguard Worker      and "vertical" variants depending on whether the text is set in
343*2d1272b8SAndroid Build Coastguard Worker      the horizontal or vertical direction. For some scripts, fonts
344*2d1272b8SAndroid Build Coastguard Worker      that are designed to support text set horizontally or vertically (for
345*2d1272b8SAndroid Build Coastguard Worker      example, in Japanese) may include metrics for both text
346*2d1272b8SAndroid Build Coastguard Worker      directions. When fonts don't include this information, HarfBuzz
347*2d1272b8SAndroid Build Coastguard Worker      does its best to transform what the font provides.
348*2d1272b8SAndroid Build Coastguard Worker    </para>
349*2d1272b8SAndroid Build Coastguard Worker    <para>
350*2d1272b8SAndroid Build Coastguard Worker      In addition to the direction-specific functions, HarfBuzz
351*2d1272b8SAndroid Build Coastguard Worker      provides some higher-level functions for fetching information
352*2d1272b8SAndroid Build Coastguard Worker      like extents and advances for a glyph. If you call
353*2d1272b8SAndroid Build Coastguard Worker    </para>
354*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
355*2d1272b8SAndroid Build Coastguard Worker      hb_font_get_glyph_advance_for_direction(font, direction, extents);
356*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
357*2d1272b8SAndroid Build Coastguard Worker    <para>
358*2d1272b8SAndroid Build Coastguard Worker      then you can provide any <type>hb_direction_t</type> as the
359*2d1272b8SAndroid Build Coastguard Worker      <parameter>direction</parameter> parameter, and HarfBuzz will
360*2d1272b8SAndroid Build Coastguard Worker      use the correct function variant for the text direction. There
361*2d1272b8SAndroid Build Coastguard Worker      are similar higher-level versions of the functions for fetching
362*2d1272b8SAndroid Build Coastguard Worker      extents, origin coordinates, and contour-point
363*2d1272b8SAndroid Build Coastguard Worker      coordinates. There are also addition and subtraction functions
364*2d1272b8SAndroid Build Coastguard Worker      for moving points with respect to the origin.
365*2d1272b8SAndroid Build Coastguard Worker    </para>
366*2d1272b8SAndroid Build Coastguard Worker    <para>
367*2d1272b8SAndroid Build Coastguard Worker      There are also methods for fetching the glyph ID that
368*2d1272b8SAndroid Build Coastguard Worker      corresponds to a Unicode code point (possibly when followed by a
369*2d1272b8SAndroid Build Coastguard Worker      variation-selector code point), fetching the glyph name from the
370*2d1272b8SAndroid Build Coastguard Worker      font, and fetching the glyph ID that corresponds to a glyph name
371*2d1272b8SAndroid Build Coastguard Worker      you already have.
372*2d1272b8SAndroid Build Coastguard Worker    </para>
373*2d1272b8SAndroid Build Coastguard Worker    <para>
374*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz also provides functions for converting between glyph
375*2d1272b8SAndroid Build Coastguard Worker      names and string
376*2d1272b8SAndroid Build Coastguard Worker      variables. <function>hb_font_glyph_to_string(font, glyph, s,
377*2d1272b8SAndroid Build Coastguard Worker      size)</function> retrieves the name for the glyph ID
378*2d1272b8SAndroid Build Coastguard Worker      <parameter>glyph</parameter> from the font object. It generates a
379*2d1272b8SAndroid Build Coastguard Worker      generic name of the form <literal>gidDDD</literal> (where DDD is
380*2d1272b8SAndroid Build Coastguard Worker      the glyph index) if there is no name for the glyph in the
381*2d1272b8SAndroid Build Coastguard Worker      font. The <function>hb_font_glyph_from_string(font, s, len,
382*2d1272b8SAndroid Build Coastguard Worker      glyph)</function> takes an input string <parameter>s</parameter>
383*2d1272b8SAndroid Build Coastguard Worker      and looks for a glyph with that name in the font, returning its
384*2d1272b8SAndroid Build Coastguard Worker      glyph ID in the <parameter>glyph</parameter>
385*2d1272b8SAndroid Build Coastguard Worker      output parameter. It automatically parses
386*2d1272b8SAndroid Build Coastguard Worker      <literal>gidDDD</literal> and <literal>uniUUUU</literal> strings.
387*2d1272b8SAndroid Build Coastguard Worker    </para>
388*2d1272b8SAndroid Build Coastguard Worker  </section>
389*2d1272b8SAndroid Build Coastguard Worker
390*2d1272b8SAndroid Build Coastguard Worker  <section id="fonts-and-faces-variable">
391*2d1272b8SAndroid Build Coastguard Worker    <title>Working with OpenType Variable Fonts</title>
392*2d1272b8SAndroid Build Coastguard Worker    <para>
393*2d1272b8SAndroid Build Coastguard Worker      If you are working with OpenType Variable Fonts, there are a few
394*2d1272b8SAndroid Build Coastguard Worker      additional functions you should use to specify the
395*2d1272b8SAndroid Build Coastguard Worker      variation-axis settings of your font object. Without doing so,
396*2d1272b8SAndroid Build Coastguard Worker      your variable font's font object can still be used, but only at
397*2d1272b8SAndroid Build Coastguard Worker      the default setting for every axis (which, of course, is
398*2d1272b8SAndroid Build Coastguard Worker      sometimes what you want, but does not cover general usage).
399*2d1272b8SAndroid Build Coastguard Worker    </para>
400*2d1272b8SAndroid Build Coastguard Worker    <para>
401*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz manages variation settings in the
402*2d1272b8SAndroid Build Coastguard Worker      <type>hb_variation_t</type> data type, which holds a <property>tag</property> for the
403*2d1272b8SAndroid Build Coastguard Worker      variation-axis identifier tag and a <property>value</property> for its
404*2d1272b8SAndroid Build Coastguard Worker      setting. You can retrieve the list of variation axes in a font
405*2d1272b8SAndroid Build Coastguard Worker      binary from the face object (not from a font object, notably) by
406*2d1272b8SAndroid Build Coastguard Worker      calling <function>hb_ot_var_get_axis_count(face)</function> to
407*2d1272b8SAndroid Build Coastguard Worker      find the number of axes, then using
408*2d1272b8SAndroid Build Coastguard Worker      <function>hb_ot_var_get_axis_infos()</function> to collect the
409*2d1272b8SAndroid Build Coastguard Worker      axis structures:
410*2d1272b8SAndroid Build Coastguard Worker    </para>
411*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
412*2d1272b8SAndroid Build Coastguard Worker      axes = hb_ot_var_get_axis_count(face);
413*2d1272b8SAndroid Build Coastguard Worker      ...
414*2d1272b8SAndroid Build Coastguard Worker      hb_ot_var_get_axis_infos(face, 0, axes, axes_array);
415*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
416*2d1272b8SAndroid Build Coastguard Worker    <para>
417*2d1272b8SAndroid Build Coastguard Worker      For each axis returned in the array, you can can access the
418*2d1272b8SAndroid Build Coastguard Worker      identifier in its <property>tag</property>. HarfBuzz also has
419*2d1272b8SAndroid Build Coastguard Worker      tag definitions predefined for the five standard axes specified
420*2d1272b8SAndroid Build Coastguard Worker      in OpenType (<literal>ital</literal> for italic,
421*2d1272b8SAndroid Build Coastguard Worker      <literal>opsz</literal> for optical size,
422*2d1272b8SAndroid Build Coastguard Worker      <literal>slnt</literal> for slant, <literal>wdth</literal> for
423*2d1272b8SAndroid Build Coastguard Worker      width, and <literal>wght</literal> for weight). Each axis also
424*2d1272b8SAndroid Build Coastguard Worker      has a <property>min_value</property>, a
425*2d1272b8SAndroid Build Coastguard Worker      <property>default_value</property>, and a <property>max_value</property>.
426*2d1272b8SAndroid Build Coastguard Worker    </para>
427*2d1272b8SAndroid Build Coastguard Worker    <para>
428*2d1272b8SAndroid Build Coastguard Worker      To set your font object's variation settings, you call the
429*2d1272b8SAndroid Build Coastguard Worker      <function>hb_font_set_variations()</function> function with an
430*2d1272b8SAndroid Build Coastguard Worker      array of <type>hb_variation_t</type> variation settings. Let's
431*2d1272b8SAndroid Build Coastguard Worker      say our font has weight and width axes. We need to specify each
432*2d1272b8SAndroid Build Coastguard Worker      of the axes by tag and assign a value on the axis:
433*2d1272b8SAndroid Build Coastguard Worker    </para>
434*2d1272b8SAndroid Build Coastguard Worker    <programlisting language="C">
435*2d1272b8SAndroid Build Coastguard Worker      unsigned int variation_count = 2;
436*2d1272b8SAndroid Build Coastguard Worker      hb_variation_t variation_data[variation_count];
437*2d1272b8SAndroid Build Coastguard Worker      variation_data[0].tag = HB_OT_TAG_VAR_AXIS_WIDTH;
438*2d1272b8SAndroid Build Coastguard Worker      variation_data[1].tag = HB_OT_TAG_VAR_AXIS_WEIGHT;
439*2d1272b8SAndroid Build Coastguard Worker      variation_data[0].value = 80;
440*2d1272b8SAndroid Build Coastguard Worker      variation_data[1].value = 750;
441*2d1272b8SAndroid Build Coastguard Worker      ...
442*2d1272b8SAndroid Build Coastguard Worker      hb_font_set_variations(font, variation_data, variation_count);
443*2d1272b8SAndroid Build Coastguard Worker    </programlisting>
444*2d1272b8SAndroid Build Coastguard Worker    <para>
445*2d1272b8SAndroid Build Coastguard Worker      That should give us a slightly condensed font ("normal" on the
446*2d1272b8SAndroid Build Coastguard Worker      <literal>wdth</literal> axis is 100) at a noticeably bolder
447*2d1272b8SAndroid Build Coastguard Worker      weight ("regular" is 400 on the <literal>wght</literal> axis).
448*2d1272b8SAndroid Build Coastguard Worker    </para>
449*2d1272b8SAndroid Build Coastguard Worker    <para>
450*2d1272b8SAndroid Build Coastguard Worker      In practice, though, you should always check that the value you
451*2d1272b8SAndroid Build Coastguard Worker      want to set on the axis is within the
452*2d1272b8SAndroid Build Coastguard Worker      [<property>min_value</property>,<property>max_value</property>]
453*2d1272b8SAndroid Build Coastguard Worker      range actually implemented in the font's variation axis. After
454*2d1272b8SAndroid Build Coastguard Worker      all, a font might only provide lighter-than-regular weights, and
455*2d1272b8SAndroid Build Coastguard Worker      setting a heavier value on the <literal>wght</literal> axis will
456*2d1272b8SAndroid Build Coastguard Worker      not change that.
457*2d1272b8SAndroid Build Coastguard Worker    </para>
458*2d1272b8SAndroid Build Coastguard Worker    <para>
459*2d1272b8SAndroid Build Coastguard Worker      Once your variation settings are specified on your font object,
460*2d1272b8SAndroid Build Coastguard Worker      however, shaping with a variable font is just like shaping a
461*2d1272b8SAndroid Build Coastguard Worker      static font.
462*2d1272b8SAndroid Build Coastguard Worker    </para>
463*2d1272b8SAndroid Build Coastguard Worker    <para>
464*2d1272b8SAndroid Build Coastguard Worker      In addition to providing the variation axes themselves, fonts may also
465*2d1272b8SAndroid Build Coastguard Worker      pre-define certain variation coordinates as named instances. HarfBuzz
466*2d1272b8SAndroid Build Coastguard Worker      makes these coordinates (and their associated names) available via
467*2d1272b8SAndroid Build Coastguard Worker      <function>hb_ot_var_named_instance_get_design_coords()</function> and
468*2d1272b8SAndroid Build Coastguard Worker      <function>hb_ot_var_named_instance_get_subfamily_name_id()</function>.
469*2d1272b8SAndroid Build Coastguard Worker    </para>
470*2d1272b8SAndroid Build Coastguard Worker    <para>
471*2d1272b8SAndroid Build Coastguard Worker      Applications should treat named instances like multiple independent,
472*2d1272b8SAndroid Build Coastguard Worker      static fonts.
473*2d1272b8SAndroid Build Coastguard Worker    </para>
474*2d1272b8SAndroid Build Coastguard Worker  </section>
475*2d1272b8SAndroid Build Coastguard Worker
476*2d1272b8SAndroid Build Coastguard Worker  <section id="glyphs-and-rendering">
477*2d1272b8SAndroid Build Coastguard Worker    <title>Glyphs and rendering</title>
478*2d1272b8SAndroid Build Coastguard Worker
479*2d1272b8SAndroid Build Coastguard Worker    <para>
480*2d1272b8SAndroid Build Coastguard Worker      The main purpose of HarfBuzz is shaping, which creates a list of positioned
481*2d1272b8SAndroid Build Coastguard Worker      glyphs as output. The remaining task for text layout is to convert this list
482*2d1272b8SAndroid Build Coastguard Worker      into rendered output. While HarfBuzz does not handle rasterization of glyphs
483*2d1272b8SAndroid Build Coastguard Worker      per se, it does have APIs that provide access to the font data that is needed
484*2d1272b8SAndroid Build Coastguard Worker      to perform this task.
485*2d1272b8SAndroid Build Coastguard Worker    </para>
486*2d1272b8SAndroid Build Coastguard Worker    <para>
487*2d1272b8SAndroid Build Coastguard Worker      Traditionally, the shapes of glyphs in scalable fonts are provided as quadratic
488*2d1272b8SAndroid Build Coastguard Worker      or cubic Beziér curves defining outlines to be filled. To obtain the outlines
489*2d1272b8SAndroid Build Coastguard Worker      for a glyph, call <function>hb_font_draw_glyph()</function> and pass a
490*2d1272b8SAndroid Build Coastguard Worker      <type>hb_draw_funcs_t</type> struct. The callbacks in that struct will be called
491*2d1272b8SAndroid Build Coastguard Worker      for each segment of the outline. Note that this API provides access to outlines
492*2d1272b8SAndroid Build Coastguard Worker      as they are defined in the font, without applying hinting to fit the curves
493*2d1272b8SAndroid Build Coastguard Worker      to the pixel grid.
494*2d1272b8SAndroid Build Coastguard Worker    </para>
495*2d1272b8SAndroid Build Coastguard Worker    <para>
496*2d1272b8SAndroid Build Coastguard Worker      Fonts may provide pre-rendered images for glyphs instead of or in addition to
497*2d1272b8SAndroid Build Coastguard Worker      outlines. This is most common for fonts that contain colored glyphs, such as
498*2d1272b8SAndroid Build Coastguard Worker      Emoji. To access these images, use <function>hb_ot_color_reference_png()</function>
499*2d1272b8SAndroid Build Coastguard Worker      or <function>hb_ot_color_reference_svg()</function>.
500*2d1272b8SAndroid Build Coastguard Worker    </para>
501*2d1272b8SAndroid Build Coastguard Worker    <para>
502*2d1272b8SAndroid Build Coastguard Worker      Another way in which fonts provide colored glyphs is via paint graphs that
503*2d1272b8SAndroid Build Coastguard Worker      combine glyph outlines with gradients and allow for transformations and
504*2d1272b8SAndroid Build Coastguard Worker      compositing. In its simplest form, this can be presented as a series of
505*2d1272b8SAndroid Build Coastguard Worker      layers that are rendered on top of each other, each with its own color.
506*2d1272b8SAndroid Build Coastguard Worker      HarfBuzz has the <function>hb_ot_color_glyph_get_layers()</function> to
507*2d1272b8SAndroid Build Coastguard Worker      access glyph data in this form.
508*2d1272b8SAndroid Build Coastguard Worker    </para>
509*2d1272b8SAndroid Build Coastguard Worker    <para>
510*2d1272b8SAndroid Build Coastguard Worker      In the general case, you have to use <function>hb_font_paint_glyph()</function>
511*2d1272b8SAndroid Build Coastguard Worker      and pass a <type>hb_paint_funcs_t</type> struct with callbacks to obtain paint
512*2d1272b8SAndroid Build Coastguard Worker      graphs for glyphs that have them. The <function>hb_font_paint_glyph()</function>
513*2d1272b8SAndroid Build Coastguard Worker      API can handle outline and image glyphs as well, so it provides a unified API for
514*2d1272b8SAndroid Build Coastguard Worker      access to glyph rendering information.
515*2d1272b8SAndroid Build Coastguard Worker    </para>
516*2d1272b8SAndroid Build Coastguard Worker  </section>
517*2d1272b8SAndroid Build Coastguard Worker
518*2d1272b8SAndroid Build Coastguard Worker </chapter>
519