Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / docs / html / fonts-and-faces-variable.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>Working with OpenType Variable Fonts: HarfBuzz Manual</title>
6 <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
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-native-opentype.html" title="Font objects and HarfBuzz's native OpenType implementation">
10 <link rel="next" href="shaping-and-shape-plans.html" title="Shaping and shape plans">
11 <meta name="generator" content="GTK-Doc V1.32.1 (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-native-opentype.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
20 <td><a accesskey="n" href="shaping-and-shape-plans.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-variable"></a>Working with OpenType Variable Fonts</h2></div></div></div>
25 <p>
26       If you are working with OpenType Variable Fonts, there are a few
27       additional functions you should use to specify the
28       variation-axis settings of your font object. Without doing so,
29       your variable font's font object can still be used, but only at
30       the default setting for every axis (which, of course, is
31       sometimes what you want, but does not cover general usage).
32     </p>
33 <p>
34       HarfBuzz manages variation settings in the
35       <span class="type">hb_variation_t</span> data type, which holds a <span class="property">tag</span> for the
36       variation-axis identifier tag and a <span class="property">value</span> for its
37       setting. You can retrieve the list of variation axes in a font
38       binary from the face object (not from a font object, notably) by
39       calling <code class="function">hb_ot_var_get_axis_count(face)</code> to
40       find the number of axes, then using
41       <code class="function">hb_ot_var_get_axis_infos()</code> to collect the 
42       axis structures:
43     </p>
44 <pre class="programlisting">
45       axes = hb_ot_var_get_axis_count(face);
46       ...
47       hb_ot_var_get_axis_infos(face, 0, axes, axes_array);
48     </pre>
49 <p>
50       For each axis returned in the array, you can can access the
51       identifier in its <span class="property">tag</span>. HarfBuzz also has
52       tag definitions predefined for the five standard axes specified
53       in OpenType (<code class="literal">ital</code> for italic,
54       <code class="literal">opsz</code> for optical size,
55       <code class="literal">slnt</code> for slant, <code class="literal">wdth</code> for
56       width, and <code class="literal">wght</code> for weight). Each axis also
57       has a <span class="property">min_value</span>, a
58       <span class="property">default_value</span>, and a <span class="property">max_value</span>.
59     </p>
60 <p>
61       To set your font object's variation settings, you call the
62       <code class="function">hb_font_set_variations()</code> function with an
63       array of <span class="type">hb_variation_t</span> variation settings. Let's
64       say our font has weight and width axes. We need to specify each
65       of the axes by tag and assign a value on the axis:
66     </p>
67 <pre class="programlisting">
68       unsigned int variation_count = 2;
69       hb_variation_t variation_data[variation_count];
70       variation_data[0].tag = HB_OT_TAG_VAR_AXIS_WIDTH;
71       variation_data[1].tag = HB_OT_TAG_VAR_AXIS_WEIGHT;
72       variation_data[0].value = 80;
73       variation_data[1].value = 750;
74       ...
75       hb_font_set_variations(font, variation_data, variation_count);
76     </pre>
77 <p>
78       That should give us a slightly condensed font ("normal" on the
79       <code class="literal">wdth</code> axis is 100) at a noticeably bolder
80       weight ("regular" is 400 on the <code class="literal">wght</code> axis).
81     </p>
82 <p>
83       In practice, though, you should always check that the value you
84       want to set on the axis is within the
85       [<span class="property">min_value</span>,<span class="property">max_value</span>]
86       range actually implemented in the font's variation axis. After
87       all, a font might only provide lighter-than-regular weights, and
88       setting a heavier value on the <code class="literal">wght</code> axis will
89       not change that. 
90     </p>
91 <p>
92       Once your variation settings are specified on your font object,
93       however, shaping with a variable font is just like shaping a
94       static font.
95     </p>
96 </div>
97 <div class="footer">
98 <hr>Generated by GTK-Doc V1.32.1</div>
99 </body>
100 </html>