summaryrefslogtreecommitdiff
path: root/src/hb-ot-math.cc
blob: c693f4807be3eb571a82a17a86631761e9b655e0 (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * Copyright © 2016  Igalia S.L.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Igalia Author(s): Frédéric Wang
 */

#include "hb-open-type.hh"

#include "hb-ot-face.hh"
#include "hb-ot-math-table.hh"

static inline const OT::MATH&
_get_math (hb_face_t *face)
{
  if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::MATH);
  hb_ot_face_data_t * data = hb_ot_face_data (face);
  return *(data->MATH.get ());
}

/*
 * OT::MATH
 */

/**
 * hb_ot_math_has_data:
 * @face: #hb_face_t to test
 *
 * This function allows to verify the presence of an OpenType MATH table on the
 * face.
 *
 * Return value: true if face has a MATH table, false otherwise
 *
 * Since: 1.3.3
 **/
hb_bool_t
hb_ot_math_has_data (hb_face_t *face)
{
  return _get_math (face).has_data ();
}

/**
 * hb_ot_math_get_constant:
 * @font: #hb_font_t from which to retrieve the value
 * @constant: #hb_ot_math_constant_t the constant to retrieve
 *
 * This function returns the requested math constants as a #hb_position_t.
 * If the request constant is HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN,
 * HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN or
 * HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN then the return value is
 * actually an integer between 0 and 100 representing that percentage.
 *
 * Return value: the requested constant or 0
 *
 * Since: 1.3.3
 **/
hb_position_t
hb_ot_math_get_constant (hb_font_t *font,
			 hb_ot_math_constant_t constant)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_constant(constant, font);
}

/**
 * hb_ot_math_get_glyph_italics_correction:
 * @font: #hb_font_t from which to retrieve the value
 * @glyph: glyph index from which to retrieve the value
 *
 * Return value: the italics correction of the glyph or 0
 *
 * Since: 1.3.3
 **/
hb_position_t
hb_ot_math_get_glyph_italics_correction (hb_font_t *font,
					 hb_codepoint_t glyph)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_math_glyph_info().get_italics_correction (glyph, font);
}

/**
 * hb_ot_math_get_glyph_top_accent_attachment:
 * @font: #hb_font_t from which to retrieve the value
 * @glyph: glyph index from which to retrieve the value
 *
 * Return value: the top accent attachment of the glyph or 0
 *
 * Since: 1.3.3
 **/
hb_position_t
hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font,
					    hb_codepoint_t glyph)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_math_glyph_info().get_top_accent_attachment (glyph, font);
}

/**
 * hb_ot_math_is_glyph_extended_shape:
 * @face: a #hb_face_t to test
 * @glyph: a glyph index to test
 *
 * Return value: true if the glyph is an extended shape, false otherwise
 *
 * Since: 1.3.3
 **/
hb_bool_t
hb_ot_math_is_glyph_extended_shape (hb_face_t *face,
				    hb_codepoint_t glyph)
{
  const OT::MATH &math = _get_math (face);
  return math.get_math_glyph_info().is_extended_shape (glyph);
}

/**
 * hb_ot_math_get_glyph_kerning:
 * @font: #hb_font_t from which to retrieve the value
 * @glyph: glyph index from which to retrieve the value
 * @kern: the #hb_ot_math_kern_t from which to retrieve the value
 * @correction_height: the correction height to use to determine the kerning.
 *
 * This function tries to retrieve the MathKern table for the specified font,
 * glyph and #hb_ot_math_kern_t. Then it browses the list of heights from the
 * MathKern table to find one value that is greater or equal to specified
 * correction_height. If one is found the corresponding value from the list of
 * kerns is returned and otherwise the last kern value is returned.
 *
 * Return value: requested kerning or 0
 *
 * Since: 1.3.3
 **/
hb_position_t
hb_ot_math_get_glyph_kerning (hb_font_t *font,
			      hb_codepoint_t glyph,
			      hb_ot_math_kern_t kern,
			      hb_position_t correction_height)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_math_glyph_info().get_kerning (glyph, kern, correction_height, font);
}

/**
 * hb_ot_math_get_glyph_variants:
 * @font: #hb_font_t from which to retrieve the values
 * @glyph: index of the glyph to stretch
 * @direction: direction of the stretching
 * @start_offset: offset of the first variant to retrieve
 * @variants_count: maximum number of variants to retrieve after start_offset
 * (IN) and actual number of variants retrieved (OUT)
 * @variants: array of size at least @variants_count to store the result
 *
 * This function tries to retrieve the MathGlyphConstruction for the specified
 * font, glyph and direction. Note that only the value of
 * #HB_DIRECTION_IS_HORIZONTAL is considered. It provides the corresponding list
 * of size variants as an array of hb_ot_math_glyph_variant_t structs.
 *
 * Return value: the total number of size variants available or 0
 *
 * Since: 1.3.3
 **/
unsigned int
hb_ot_math_get_glyph_variants (hb_font_t *font,
			       hb_codepoint_t glyph,
			       hb_direction_t direction,
			       unsigned int start_offset,
			       unsigned int *variants_count, /* IN/OUT */
			       hb_ot_math_glyph_variant_t *variants /* OUT */)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_math_variants().get_glyph_variants (glyph, direction, font,
						      start_offset,
						      variants_count,
						      variants);
}

/**
 * hb_ot_math_get_min_connector_overlap:
 * @font: #hb_font_t from which to retrieve the value
 * @direction: direction of the stretching
 *
 * This function tries to retrieve the MathVariants table for the specified
 * font and returns the minimum overlap of connecting glyphs to draw a glyph
 * assembly in the specified direction. Note that only the value of
 * #HB_DIRECTION_IS_HORIZONTAL is considered.
 *
 * Return value: requested min connector overlap or 0
 *
 * Since: 1.3.3
 **/
hb_position_t
hb_ot_math_get_min_connector_overlap (hb_font_t *font,
				      hb_direction_t direction)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_math_variants().get_min_connector_overlap (direction, font);
}

/**
 * hb_ot_math_get_glyph_assembly:
 * @font: #hb_font_t from which to retrieve the values
 * @glyph: index of the glyph to stretch
 * @direction: direction of the stretching
 * @start_offset: offset of the first glyph part to retrieve
 * @parts_count: maximum number of glyph parts to retrieve after start_offset
 * (IN) and actual number of parts retrieved (OUT)
 * @parts: array of size at least @parts_count to store the result
 * @italics_correction: italic correction of the glyph assembly
 *
 * This function tries to retrieve the GlyphAssembly for the specified font,
 * glyph and direction. Note that only the value of #HB_DIRECTION_IS_HORIZONTAL
 * is considered. It provides the information necessary to draw the glyph
 * assembly as an array of #hb_ot_math_glyph_part_t.
 *
 * Return value: the total number of parts in the glyph assembly
 *
 * Since: 1.3.3
 **/
unsigned int
hb_ot_math_get_glyph_assembly (hb_font_t *font,
			       hb_codepoint_t glyph,
			       hb_direction_t direction,
			       unsigned int start_offset,
			       unsigned int *parts_count, /* IN/OUT */
			       hb_ot_math_glyph_part_t *parts, /* OUT */
			       hb_position_t *italics_correction /* OUT */)
{
  const OT::MATH &math = _get_math (font->face);
  return math.get_math_variants().get_glyph_parts (glyph, direction, font,
						   start_offset,
						   parts_count,
						   parts,
						   italics_correction);
}