1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
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 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-native-opentype.html" title="Font objects and HarfBuzz's native OpenType implementation">
10 <link rel="next" href="glyphs-and-rendering.html" title="Glyphs and rendering">
11 <meta name="generator" content="GTK-Doc V1.32 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
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="glyphs-and-rendering.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
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>
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).
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
44 <pre class="programlisting">
45 axes = hb_ot_var_get_axis_count(face);
47 hb_ot_var_get_axis_infos(face, 0, axes, axes_array);
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>.
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:
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;
75 hb_font_set_variations(font, variation_data, variation_count);
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).
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
92 Once your variation settings are specified on your font object,
93 however, shaping with a variable font is just like shaping a
97 In addition to providing the variation axes themselves, fonts may also
98 pre-define certain variation coordinates as named instances. HarfBuzz
99 makes these coordinates (and their associated names) available via
100 <code class="function">hb_ot_var_named_instance_get_design_coords()</code> and
101 <code class="function">hb_ot_var_named_instance_get_subfamily_name_id()</code>.
104 Applications should treat named instances like multiple independent,
109 <hr>Generated by GTK-Doc V1.32</div>