1/*
2 * Copyright © 2017 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#include "hb.hh"
28
29#ifndef HB_NO_VAR
30
31#include "hb-ot-var.h"
32
33#include "hb-ot-var-avar-table.hh"
34#include "hb-ot-var-fvar-table.hh"
35#include "hb-ot-var-mvar-table.hh"
36
37
38/**
39 * SECTION:hb-ot-var
40 * @title: hb-ot-var
41 * @short_description: OpenType Font Variations
42 * @include: hb-ot.h
43 *
44 * Functions for fetching information about OpenType Variable Fonts.
45 **/
46
47
48/*
49 * fvar/avar
50 */
51
52
53/**
54 * hb_ot_var_has_data:
55 * @face: #hb_face_t to test
56 *
57 * This function allows to verify the presence of OpenType variation data on the face.
58 *
59 * Return value: true if face has a `fvar' table and false otherwise
60 *
61 * Since: 1.4.2
62 **/
63hb_bool_t
64hb_ot_var_has_data (hb_face_t *face)
65{
66 return face->table.fvar->has_data ();
67}
68
69/**
70 * hb_ot_var_get_axis_count:
71 *
72 * Since: 1.4.2
73 **/
74unsigned int
75hb_ot_var_get_axis_count (hb_face_t *face)
76{
77 return face->table.fvar->get_axis_count ();
78}
79
80#ifndef HB_DISABLE_DEPRECATED
81/**
82 * hb_ot_var_get_axes:
83 *
84 * Since: 1.4.2
85 * Deprecated: 2.2.0
86 **/
87unsigned int
88hb_ot_var_get_axes (hb_face_t *face,
89 unsigned int start_offset,
90 unsigned int *axes_count /* IN/OUT */,
91 hb_ot_var_axis_t *axes_array /* OUT */)
92{
93 return face->table.fvar->get_axes_deprecated (start_offset, axes_count, axes_array);
94}
95
96/**
97 * hb_ot_var_find_axis:
98 *
99 * Since: 1.4.2
100 * Deprecated: 2.2.0
101 **/
102hb_bool_t
103hb_ot_var_find_axis (hb_face_t *face,
104 hb_tag_t axis_tag,
105 unsigned int *axis_index,
106 hb_ot_var_axis_t *axis_info)
107{
108 return face->table.fvar->find_axis_deprecated (axis_tag, axis_index, axis_info);
109}
110#endif
111
112/**
113 * hb_ot_var_get_axis_infos:
114 *
115 * Since: 2.2.0
116 **/
117HB_EXTERN unsigned int
118hb_ot_var_get_axis_infos (hb_face_t *face,
119 unsigned int start_offset,
120 unsigned int *axes_count /* IN/OUT */,
121 hb_ot_var_axis_info_t *axes_array /* OUT */)
122{
123 return face->table.fvar->get_axis_infos (start_offset, axes_count, axes_array);
124}
125
126/**
127 * hb_ot_var_find_axis_info:
128 *
129 * Since: 2.2.0
130 **/
131HB_EXTERN hb_bool_t
132hb_ot_var_find_axis_info (hb_face_t *face,
133 hb_tag_t axis_tag,
134 hb_ot_var_axis_info_t *axis_info)
135{
136 return face->table.fvar->find_axis_info (axis_tag, axis_info);
137}
138
139
140/*
141 * Named instances.
142 */
143
144unsigned int
145hb_ot_var_get_named_instance_count (hb_face_t *face)
146{
147 return face->table.fvar->get_instance_count ();
148}
149
150hb_ot_name_id_t
151hb_ot_var_named_instance_get_subfamily_name_id (hb_face_t *face,
152 unsigned int instance_index)
153{
154 return face->table.fvar->get_instance_subfamily_name_id (instance_index);
155}
156
157hb_ot_name_id_t
158hb_ot_var_named_instance_get_postscript_name_id (hb_face_t *face,
159 unsigned int instance_index)
160{
161 return face->table.fvar->get_instance_postscript_name_id (instance_index);
162}
163
164unsigned int
165hb_ot_var_named_instance_get_design_coords (hb_face_t *face,
166 unsigned int instance_index,
167 unsigned int *coords_length, /* IN/OUT */
168 float *coords /* OUT */)
169{
170 return face->table.fvar->get_instance_coords (instance_index, coords_length, coords);
171}
172
173
174/**
175 * hb_ot_var_normalize_variations:
176 *
177 * Since: 1.4.2
178 **/
179void
180hb_ot_var_normalize_variations (hb_face_t *face,
181 const hb_variation_t *variations, /* IN */
182 unsigned int variations_length,
183 int *coords, /* OUT */
184 unsigned int coords_length)
185{
186 for (unsigned int i = 0; i < coords_length; i++)
187 coords[i] = 0;
188
189 const OT::fvar &fvar = *face->table.fvar;
190 for (unsigned int i = 0; i < variations_length; i++)
191 {
192 hb_ot_var_axis_info_t info;
193 if (hb_ot_var_find_axis_info (face, variations[i].tag, &info) &&
194 info.axis_index < coords_length)
195 coords[info.axis_index] = fvar.normalize_axis_value (info.axis_index, variations[i].value);
196 }
197
198 face->table.avar->map_coords (coords, coords_length);
199}
200
201/**
202 * hb_ot_var_normalize_coords:
203 *
204 * Since: 1.4.2
205 **/
206void
207hb_ot_var_normalize_coords (hb_face_t *face,
208 unsigned int coords_length,
209 const float *design_coords, /* IN */
210 int *normalized_coords /* OUT */)
211{
212 const OT::fvar &fvar = *face->table.fvar;
213 for (unsigned int i = 0; i < coords_length; i++)
214 normalized_coords[i] = fvar.normalize_axis_value (i, design_coords[i]);
215
216 face->table.avar->map_coords (normalized_coords, coords_length);
217}
218
219
220#endif
221