1/*
2 * Copyright © 2016 Igalia S.L.
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 * Igalia Author(s): Frédéric Wang
25 */
26
27#include "hb.hh"
28
29#ifndef HB_NO_MATH
30
31#include "hb-ot-math-table.hh"
32
33
34/**
35 * SECTION:hb-ot-math
36 * @title: hb-ot-math
37 * @short_description: OpenType Math information
38 * @include: hb-ot.h
39 *
40 * Functions for fetching mathematics layout data from OpenType fonts.
41 *
42 * HarfBuzz itself does not implement a math layout solution. The
43 * functions and types provided can be used by client programs to access
44 * the font data necessary for typesetting OpenType Math layout.
45 *
46 **/
47
48
49/*
50 * OT::MATH
51 */
52
53/**
54 * hb_ot_math_has_data:
55 * @face: #hb_face_t to test
56 *
57 * Tests whether a face has a `MATH` table.
58 *
59 * Return value: true if the table is found, false otherwise
60 *
61 * Since: 1.3.3
62 **/
63hb_bool_t
64hb_ot_math_has_data (hb_face_t *face)
65{
66 return face->table.MATH->has_data ();
67}
68
69/**
70 * hb_ot_math_get_constant:
71 * @font: #hb_font_t to work upon
72 * @constant: #hb_ot_math_constant_t the constant to retrieve
73 *
74 * Fetches the specified math constant. For most constants, the value returned
75 * is an #hb_position_t.
76 *
77 * However, if the requested constant is #HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN,
78 * #HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN or
79 * #HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN, then the return value is
80 * an integer between 0 and 100 representing that percentage.
81 *
82 * Return value: the requested constant or zero
83 *
84 * Since: 1.3.3
85 **/
86hb_position_t
87hb_ot_math_get_constant (hb_font_t *font,
88 hb_ot_math_constant_t constant)
89{
90 return font->face->table.MATH->get_constant(constant, font);
91}
92
93/**
94 * hb_ot_math_get_glyph_italics_correction:
95 * @font: #hb_font_t to work upon
96 * @glyph: The glyph index from which to retrieve the value
97 *
98 * Fetches an italics-correction value (if one exists) for the specified
99 * glyph index.
100 *
101 * Return value: the italics correction of the glyph or zero
102 *
103 * Since: 1.3.3
104 **/
105hb_position_t
106hb_ot_math_get_glyph_italics_correction (hb_font_t *font,
107 hb_codepoint_t glyph)
108{
109 return font->face->table.MATH->get_glyph_info().get_italics_correction (glyph, font);
110}
111
112/**
113 * hb_ot_math_get_glyph_top_accent_attachment:
114 * @font: #hb_font_t to work upon
115 * @glyph: The glyph index from which to retrieve the value
116 *
117 * Fetches a top-accent-attachment value (if one exists) for the specified
118 * glyph index.
119 *
120 * For any glyph that does not have a top-accent-attachment value - that is,
121 * a glyph not covered by the `MathTopAccentAttachment` table (or, when
122 * @font has no `MathTopAccentAttachment` table or no `MATH` table, any
123 * glyph) - the function synthesizes a value, returning the position at
124 * one-half the glyph's advance width.
125 *
126 * Return value: the top accent attachment of the glyph or 0.5 * the advance
127 * width of @glyph
128 *
129 * Since: 1.3.3
130 **/
131hb_position_t
132hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font,
133 hb_codepoint_t glyph)
134{
135 return font->face->table.MATH->get_glyph_info().get_top_accent_attachment (glyph, font);
136}
137
138/**
139 * hb_ot_math_is_glyph_extended_shape:
140 * @face: #hb_face_t to work upon
141 * @glyph: The glyph index to test
142 *
143 * Tests whether the given glyph index is an extended shape in the face.
144 *
145 * Return value: true if the glyph is an extended shape, false otherwise
146 *
147 * Since: 1.3.3
148 **/
149hb_bool_t
150hb_ot_math_is_glyph_extended_shape (hb_face_t *face,
151 hb_codepoint_t glyph)
152{
153 return face->table.MATH->get_glyph_info().is_extended_shape (glyph);
154}
155
156/**
157 * hb_ot_math_get_glyph_kerning:
158 * @font: #hb_font_t to work upon
159 * @glyph: The glyph index from which to retrieve the value
160 * @kern: The #hb_ot_math_kern_t from which to retrieve the value
161 * @correction_height: the correction height to use to determine the kerning.
162 *
163 * Fetches the math kerning (cut-ins) value for the specified font, glyph index, and
164 * @kern.
165 *
166 * If the MathKern table is found, the function examines it to find a height
167 * value that is greater or equal to @correction_height. If such a height
168 * value is found, corresponding kerning value from the table is returned. If
169 * no such height value is found, the last kerning value is returned.
170 *
171 * Return value: requested kerning value or zero
172 *
173 * Since: 1.3.3
174 **/
175hb_position_t
176hb_ot_math_get_glyph_kerning (hb_font_t *font,
177 hb_codepoint_t glyph,
178 hb_ot_math_kern_t kern,
179 hb_position_t correction_height)
180{
181 return font->face->table.MATH->get_glyph_info().get_kerning (glyph,
182 kern,
183 correction_height,
184 font);
185}
186
187/**
188 * hb_ot_math_get_glyph_variants:
189 * @font: #hb_font_t to work upon
190 * @glyph: The index of the glyph to stretch
191 * @direction: The direction of the stretching (horizontal or vertical)
192 * @start_offset: offset of the first variant to retrieve
193 * @variants_count: (inout): Input = the maximum number of variants to return;
194 * Output = the actual number of variants returned
195 * @variants: (out) (array length=variants_count): array of variants returned
196 *
197 * Fetches the MathGlyphConstruction for the specified font, glyph index, and
198 * direction. The corresponding list of size variants is returned as a list of
199 * #hb_ot_math_glyph_variant_t structs.
200 *
201 * <note>The @direction parameter is only used to select between horizontal
202 * or vertical directions for the construction. Even though all #hb_direction_t
203 * values are accepted, only the result of #HB_DIRECTION_IS_HORIZONTAL is
204 * considered.</note>
205 *
206 * Return value: the total number of size variants available or zero
207 *
208 * Since: 1.3.3
209 **/
210unsigned int
211hb_ot_math_get_glyph_variants (hb_font_t *font,
212 hb_codepoint_t glyph,
213 hb_direction_t direction,
214 unsigned int start_offset,
215 unsigned int *variants_count, /* IN/OUT */
216 hb_ot_math_glyph_variant_t *variants /* OUT */)
217{
218 return font->face->table.MATH->get_variants().get_glyph_variants (glyph, direction, font,
219 start_offset,
220 variants_count,
221 variants);
222}
223
224/**
225 * hb_ot_math_get_min_connector_overlap:
226 * @font: #hb_font_t to work upon
227 * @direction: direction of the stretching (horizontal or vertical)
228 *
229 * Fetches the MathVariants table for the specified font and returns the
230 * minimum overlap of connecting glyphs that are required to draw a glyph
231 * assembly in the specified direction.
232 *
233 * <note>The @direction parameter is only used to select between horizontal
234 * or vertical directions for the construction. Even though all #hb_direction_t
235 * values are accepted, only the result of #HB_DIRECTION_IS_HORIZONTAL is
236 * considered.</note>
237 *
238 * Return value: requested minimum connector overlap or zero
239 *
240 * Since: 1.3.3
241 **/
242hb_position_t
243hb_ot_math_get_min_connector_overlap (hb_font_t *font,
244 hb_direction_t direction)
245{
246 return font->face->table.MATH->get_variants().get_min_connector_overlap (direction, font);
247}
248
249/**
250 * hb_ot_math_get_glyph_assembly:
251 * @font: #hb_font_t to work upon
252 * @glyph: The index of the glyph to stretch
253 * @direction: direction of the stretching (horizontal or vertical)
254 * @start_offset: offset of the first glyph part to retrieve
255 * @parts_count: (inout): Input = maximum number of glyph parts to return;
256 * Output = actual number of parts returned
257 * @parts: (out) (array length=parts_count): the glyph parts returned
258 * @italics_correction: (out): italics correction of the glyph assembly
259 *
260 * Fetches the GlyphAssembly for the specified font, glyph index, and direction.
261 * Returned are a list of #hb_ot_math_glyph_part_t glyph parts that can be
262 * used to draw the glyph and an italics-correction value (if one is defined
263 * in the font).
264 *
265 * <note>The @direction parameter is only used to select between horizontal
266 * or vertical directions for the construction. Even though all #hb_direction_t
267 * values are accepted, only the result of #HB_DIRECTION_IS_HORIZONTAL is
268 * considered.</note>
269 *
270 * Return value: the total number of parts in the glyph assembly
271 *
272 * Since: 1.3.3
273 **/
274unsigned int
275hb_ot_math_get_glyph_assembly (hb_font_t *font,
276 hb_codepoint_t glyph,
277 hb_direction_t direction,
278 unsigned int start_offset,
279 unsigned int *parts_count, /* IN/OUT */
280 hb_ot_math_glyph_part_t *parts, /* OUT */
281 hb_position_t *italics_correction /* OUT */)
282{
283 return font->face->table.MATH->get_variants().get_glyph_parts (glyph,
284 direction,
285 font,
286 start_offset,
287 parts_count,
288 parts,
289 italics_correction);
290}
291
292
293#endif
294