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-open-type-private.hh"
28
29#include "hb-ot-layout-private.hh"
30#include "hb-ot-math-table.hh"
31
32static inline const OT::MATH&
33_get_math (hb_face_t *face)
34{
35 if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::MATH);
36 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
37 return *(layout->math.get ());
38}
39
40/*
41 * OT::MATH
42 */
43
44/**
45 * hb_ot_math_has_data:
46 * @face: #hb_face_t to test
47 *
48 * This function allows to verify the presence of an OpenType MATH table on the
49 * face.
50 *
51 * Return value: true if face has a MATH table, false otherwise
52 *
53 * Since: 1.3.3
54 **/
55hb_bool_t
56hb_ot_math_has_data (hb_face_t *face)
57{
58 return &_get_math (face) != &OT::Null(OT::MATH);
59}
60
61/**
62 * hb_ot_math_get_constant:
63 * @font: #hb_font_t from which to retrieve the value
64 * @constant: #hb_ot_math_constant_t the constant to retrieve
65 *
66 * This function returns the requested math constants as a #hb_position_t.
67 * If the request constant is HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN,
68 * HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN or
69 * HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN then the return value is
70 * actually an integer between 0 and 100 representing that percentage.
71 *
72 * Return value: the requested constant or 0
73 *
74 * Since: 1.3.3
75 **/
76hb_position_t
77hb_ot_math_get_constant (hb_font_t *font,
78 hb_ot_math_constant_t constant)
79{
80 const OT::MATH &math = _get_math (face: font->face);
81 return math.get_constant(constant, font);
82}
83
84/**
85 * hb_ot_math_get_glyph_italics_correction:
86 * @font: #hb_font_t from which to retrieve the value
87 * @glyph: glyph index from which to retrieve the value
88 *
89 * Return value: the italics correction of the glyph or 0
90 *
91 * Since: 1.3.3
92 **/
93hb_position_t
94hb_ot_math_get_glyph_italics_correction (hb_font_t *font,
95 hb_codepoint_t glyph)
96{
97 const OT::MATH &math = _get_math (face: font->face);
98 return math.get_math_glyph_info().get_italics_correction (glyph, font);
99}
100
101/**
102 * hb_ot_math_get_glyph_top_accent_attachment:
103 * @font: #hb_font_t from which to retrieve the value
104 * @glyph: glyph index from which to retrieve the value
105 *
106 * Return value: the top accent attachment of the glyph or 0
107 *
108 * Since: 1.3.3
109 **/
110hb_position_t
111hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font,
112 hb_codepoint_t glyph)
113{
114 const OT::MATH &math = _get_math (face: font->face);
115 return math.get_math_glyph_info().get_top_accent_attachment (glyph, font);
116}
117
118/**
119 * hb_ot_math_is_glyph_extended_shape:
120 * @face: a #hb_face_t to test
121 * @glyph: a glyph index to test
122 *
123 * Return value: true if the glyph is an extended shape, false otherwise
124 *
125 * Since: 1.3.3
126 **/
127hb_bool_t
128hb_ot_math_is_glyph_extended_shape (hb_face_t *face,
129 hb_codepoint_t glyph)
130{
131 const OT::MATH &math = _get_math (face);
132 return math.get_math_glyph_info().is_extended_shape (glyph);
133}
134
135/**
136 * hb_ot_math_get_glyph_kerning:
137 * @font: #hb_font_t from which to retrieve the value
138 * @glyph: glyph index from which to retrieve the value
139 * @kern: the #hb_ot_math_kern_t from which to retrieve the value
140 * @correction_height: the correction height to use to determine the kerning.
141 *
142 * This function tries to retrieve the MathKern table for the specified font,
143 * glyph and #hb_ot_math_kern_t. Then it browses the list of heights from the
144 * MathKern table to find one value that is greater or equal to specified
145 * correction_height. If one is found the corresponding value from the list of
146 * kerns is returned and otherwise the last kern value is returned.
147 *
148 * Return value: requested kerning or 0
149 *
150 * Since: 1.3.3
151 **/
152hb_position_t
153hb_ot_math_get_glyph_kerning (hb_font_t *font,
154 hb_codepoint_t glyph,
155 hb_ot_math_kern_t kern,
156 hb_position_t correction_height)
157{
158 const OT::MATH &math = _get_math (face: font->face);
159 return math.get_math_glyph_info().get_kerning (glyph, kern, correction_height, font);
160}
161
162/**
163 * hb_ot_math_get_glyph_variants:
164 * @font: #hb_font_t from which to retrieve the values
165 * @glyph: index of the glyph to stretch
166 * @direction: direction of the stretching
167 * @start_offset: offset of the first variant to retrieve
168 * @variants_count: maximum number of variants to retrieve after start_offset
169 * (IN) and actual number of variants retrieved (OUT)
170 * @variants: array of size at least @variants_count to store the result
171 *
172 * This function tries to retrieve the MathGlyphConstruction for the specified
173 * font, glyph and direction. Note that only the value of
174 * #HB_DIRECTION_IS_HORIZONTAL is considered. It provides the corresponding list
175 * of size variants as an array of hb_ot_math_glyph_variant_t structs.
176 *
177 * Return value: the total number of size variants available or 0
178 *
179 * Since: 1.3.3
180 **/
181unsigned int
182hb_ot_math_get_glyph_variants (hb_font_t *font,
183 hb_codepoint_t glyph,
184 hb_direction_t direction,
185 unsigned int start_offset,
186 unsigned int *variants_count, /* IN/OUT */
187 hb_ot_math_glyph_variant_t *variants /* OUT */)
188{
189 const OT::MATH &math = _get_math (face: font->face);
190 return math.get_math_variants().get_glyph_variants (glyph, direction, font,
191 start_offset,
192 variants_count,
193 variants);
194}
195
196/**
197 * hb_ot_math_get_min_connector_overlap:
198 * @font: #hb_font_t from which to retrieve the value
199 * @direction: direction of the stretching
200 *
201 * This function tries to retrieve the MathVariants table for the specified
202 * font and returns the minimum overlap of connecting glyphs to draw a glyph
203 * assembly in the specified direction. Note that only the value of
204 * #HB_DIRECTION_IS_HORIZONTAL is considered.
205 *
206 * Return value: requested min connector overlap or 0
207 *
208 * Since: 1.3.3
209 **/
210hb_position_t
211hb_ot_math_get_min_connector_overlap (hb_font_t *font,
212 hb_direction_t direction)
213{
214 const OT::MATH &math = _get_math (face: font->face);
215 return math.get_math_variants().get_min_connector_overlap (direction, font);
216}
217
218/**
219 * hb_ot_math_get_glyph_assembly:
220 * @font: #hb_font_t from which to retrieve the values
221 * @glyph: index of the glyph to stretch
222 * @direction: direction of the stretching
223 * @start_offset: offset of the first glyph part to retrieve
224 * @parts_count: maximum number of glyph parts to retrieve after start_offset
225 * (IN) and actual number of parts retrieved (OUT)
226 * @parts: array of size at least @parts_count to store the result
227 * @italics_correction: italic correction of the glyph assembly
228 *
229 * This function tries to retrieve the GlyphAssembly for the specified font,
230 * glyph and direction. Note that only the value of #HB_DIRECTION_IS_HORIZONTAL
231 * is considered. It provides the information necessary to draw the glyph
232 * assembly as an array of #hb_ot_math_glyph_part_t.
233 *
234 * Return value: the total number of parts in the glyph assembly
235 *
236 * Since: 1.3.3
237 **/
238unsigned int
239hb_ot_math_get_glyph_assembly (hb_font_t *font,
240 hb_codepoint_t glyph,
241 hb_direction_t direction,
242 unsigned int start_offset,
243 unsigned int *parts_count, /* IN/OUT */
244 hb_ot_math_glyph_part_t *parts, /* OUT */
245 hb_position_t *italics_correction /* OUT */)
246{
247 const OT::MATH &math = _get_math (face: font->face);
248 return math.get_math_variants().get_glyph_parts (glyph, direction, font,
249 start_offset,
250 parts_count,
251 parts,
252 italics_correction);
253}
254

source code of qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-math.cc