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