Imported Upstream version 8.2.2
[platform/upstream/harfbuzz.git] / docs / html / fonts-and-faces-custom-functions.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Customizing font functions: HarfBuzz Manual</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="index.html" title="HarfBuzz Manual">
8 <link rel="up" href="fonts-and-faces.html" title="Fonts, faces, and output">
9 <link rel="prev" href="fonts-and-faces.html" title="Fonts, faces, and output">
10 <link rel="next" href="fonts-and-faces-native-opentype.html" title="Font objects and HarfBuzz's native OpenType implementation">
11 <meta name="generator" content="GTK-Doc V1.32 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
16 <td width="100%" align="left" class="shortcuts"></td>
17 <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
18 <td><a accesskey="u" href="fonts-and-faces.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
19 <td><a accesskey="p" href="fonts-and-faces.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
20 <td><a accesskey="n" href="fonts-and-faces-native-opentype.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
21 </tr></table>
22 <div class="section">
23 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
24 <a name="fonts-and-faces-custom-functions"></a>Customizing font functions</h2></div></div></div>
25 <p>
26       During shaping, HarfBuzz frequently needs to query font objects
27       to get at the contents and parameters of the glyphs in a font
28       file. It includes a built-in set of functions that is tailored
29       to working with OpenType fonts. However, as was the case with
30       Unicode functions in the buffers chapter, HarfBuzz also wants to
31       make it easy for you to assign a substitute set of font
32       functions if you are developing a program to work with a library
33       or platform that provides its own font functions. 
34     </p>
35 <p>
36       Therefore, the HarfBuzz API defines a set of virtual
37       methods for accessing font-object properties, and you can
38       replace the defaults with your own selections without
39       interfering with the shaping process. Each font object in
40       HarfBuzz includes a structure called
41       <code class="literal">font_funcs</code> that serves as a vtable for the
42       font object. The virtual methods in
43       <code class="literal">font_funcs</code> are:
44     </p>
45 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
46 <li class="listitem"><p>
47       <code class="function">hb_font_get_font_h_extents_func_t</code>: returns
48       the extents of the font for horizontal text.
49     </p></li>
50 <li class="listitem"><p>
51       <code class="function">hb_font_get_font_v_extents_func_t</code>: returns
52       the extents of the font for vertical text.
53     </p></li>
54 <li class="listitem"><p>
55       <code class="function">hb_font_get_nominal_glyph_func_t</code>: returns
56       the font's nominal glyph for a given code point.
57     </p></li>
58 <li class="listitem"><p>
59       <code class="function">hb_font_get_variation_glyph_func_t</code>: returns
60       the font's glyph for a given code point when it is followed by a
61       given Variation Selector.
62     </p></li>
63 <li class="listitem"><p>
64       <code class="function">hb_font_get_nominal_glyphs_func_t</code>: returns
65       the font's nominal glyphs for a series of code points.
66     </p></li>
67 <li class="listitem"><p>
68       <code class="function">hb_font_get_glyph_advance_func_t</code>: returns
69       the advance for a glyph.
70     </p></li>
71 <li class="listitem"><p>
72       <code class="function">hb_font_get_glyph_h_advance_func_t</code>: returns
73       the advance for a glyph for horizontal text.
74     </p></li>
75 <li class="listitem"><p>
76       <code class="function">hb_font_get_glyph_v_advance_func_t</code>:returns
77       the advance for a glyph for vertical text.
78     </p></li>
79 <li class="listitem"><p>
80       <code class="function">hb_font_get_glyph_advances_func_t</code>: returns
81       the advances for a series of glyphs.
82     </p></li>
83 <li class="listitem"><p>
84       <code class="function">hb_font_get_glyph_h_advances_func_t</code>: returns
85       the advances for a series of glyphs for horizontal text .
86     </p></li>
87 <li class="listitem"><p>
88       <code class="function">hb_font_get_glyph_v_advances_func_t</code>: returns
89       the advances for a series of glyphs for vertical text.
90     </p></li>
91 <li class="listitem"><p>
92       <code class="function">hb_font_get_glyph_origin_func_t</code>: returns
93       the origin coordinates of a glyph.
94     </p></li>
95 <li class="listitem"><p>
96       <code class="function">hb_font_get_glyph_h_origin_func_t</code>: returns
97       the origin coordinates of a glyph for horizontal text.
98     </p></li>
99 <li class="listitem"><p>
100       <code class="function">hb_font_get_glyph_v_origin_func_t</code>: returns
101       the origin coordinates of a glyph for vertical text.
102     </p></li>
103 <li class="listitem"><p>
104       <code class="function">hb_font_get_glyph_extents_func_t</code>: returns
105       the extents for a glyph.
106     </p></li>
107 <li class="listitem"><p>
108       <code class="function">hb_font_get_glyph_contour_point_func_t</code>:
109       returns the coordinates of a specific contour point from a glyph.
110     </p></li>
111 <li class="listitem"><p>
112       <code class="function">hb_font_get_glyph_name_func_t</code>: returns the
113       name of a glyph (from its glyph index).
114     </p></li>
115 <li class="listitem"><p>
116       <code class="function">hb_font_get_glyph_from_name_func_t</code>: returns
117       the glyph index that corresponds to a given glyph name.
118     </p></li>
119 <li class="listitem"><p>
120       <code class="function">hb_font_draw_glyph_func_t</code>: gets the outlines
121       of a glyph (by calling #hb_draw_funcs_t callbacks).
122     </p></li>
123 <li class="listitem"><p>
124       <code class="function">hb_font_paint_glyph_func_t</code>: paints a glyph
125       (by calling #hb_paint_funcs_t callbacks).
126     </p></li>
127 </ul></div>
128 <p>
129       You can create new font-functions by calling
130       <code class="function">hb_font_funcs_create()</code>:
131     </p>
132 <pre class="programlisting">
133       hb_font_funcs_t *ffunctions = hb_font_funcs_create ();
134       hb_font_set_funcs (font, ffunctions, font_data, destroy);
135     </pre>
136 <p>
137       The individual methods can each be set with their own setter
138       function, such as
139       <code class="function">hb_font_funcs_set_nominal_glyph_func(ffunctions,
140       func, user_data, destroy)</code>.
141     </p>
142 <p>
143       Font-functions structures can be reused for multiple font
144       objects, and can be reference counted with
145       <code class="function">hb_font_funcs_reference()</code> and
146       <code class="function">hb_font_funcs_destroy()</code>. Just like other
147       objects in HarfBuzz, you can set user-data for each
148       font-functions structure and assign a destroy callback for
149       it.
150     </p>
151 <p>
152       You can also mark a font-functions structure as immutable,
153       with <code class="function">hb_font_funcs_make_immutable()</code>. This
154       is especially useful if your code is a library or framework that
155       will have its own client programs. By marking your
156       font-functions structures as immutable, you prevent your client
157       programs from changing the configuration and introducing
158       inconsistencies and errors downstream.
159     </p>
160 <p>
161       To override only some functions while using the default implementation
162       for the others, you will need to create a sub-font. By default, the
163       sub-font uses the font functions of its parent except for the functions
164       that were explicitly set. The following code will override only the
165       <code class="function">hb_font_get_nominal_glyph_func_t</code> for the sub-font:
166     </p>
167 <pre class="programlisting">
168       hb_font_t *subfont = hb_font_create_sub_font (font)
169       hb_font_funcs_t *ffunctions = hb_font_funcs_create ();
170       hb_font_funcs_set_nominal_glyph_func (ffunctions, func, user_data, destroy);
171       hb_font_set_funcs (subfont, ffunctions, font_data, destroy);
172       hb_font_funcs_destroy (ffunctions);
173     </pre>
174 </div>
175 <div class="footer">
176 <hr>Generated by GTK-Doc V1.32</div>
177 </body>
178 </html>