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