• 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 #if !defined(HB_OT_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)
28 #error "Include <hb-ot.h> instead."
29 #endif
30 
31 #ifndef HB_OT_MATH_H
32 #define HB_OT_MATH_H
33 
34 #include "hb.h"
35 
36 HB_BEGIN_DECLS
37 
38 
39 /*
40  * MATH
41  */
42 
43 /**
44  * HB_OT_TAG_MATH:
45  *
46  * OpenType [Mathematical Typesetting Table](https://docs.microsoft.com/en-us/typography/opentype/spec/math).
47  *
48  * Since: 1.3.3
49  */
50 #define HB_OT_TAG_MATH HB_TAG('M','A','T','H')
51 
52 /**
53  * HB_OT_MATH_SCRIPT:
54  *
55  * OpenType script tag for math shaping, for use with
56  * Use with hb_buffer_set_script().
57  *
58  * Since: 1.3.3
59  */
60 #define HB_OT_MATH_SCRIPT HB_TAG('m','a','t','h')
61 
62 /* Types */
63 
64 /**
65  * hb_ot_math_constant_t:
66  * @HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN: scriptPercentScaleDown
67  * @HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN: scriptScriptPercentScaleDown
68  * @HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT: delimitedSubFormulaMinHeight
69  * @HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT: displayOperatorMinHeight
70  * @HB_OT_MATH_CONSTANT_MATH_LEADING: mathLeading
71  * @HB_OT_MATH_CONSTANT_AXIS_HEIGHT: axisHeight
72  * @HB_OT_MATH_CONSTANT_ACCENT_BASE_HEIGHT: accentBaseHeight
73  * @HB_OT_MATH_CONSTANT_FLATTENED_ACCENT_BASE_HEIGHT: flattenedAccentBaseHeight
74  * @HB_OT_MATH_CONSTANT_SUBSCRIPT_SHIFT_DOWN: subscriptShiftDown
75  * @HB_OT_MATH_CONSTANT_SUBSCRIPT_TOP_MAX: subscriptTopMax
76  * @HB_OT_MATH_CONSTANT_SUBSCRIPT_BASELINE_DROP_MIN: subscriptBaselineDropMin
77  * @HB_OT_MATH_CONSTANT_SUPERSCRIPT_SHIFT_UP: superscriptShiftUp
78  * @HB_OT_MATH_CONSTANT_SUPERSCRIPT_SHIFT_UP_CRAMPED: superscriptShiftUpCramped
79  * @HB_OT_MATH_CONSTANT_SUPERSCRIPT_BOTTOM_MIN: superscriptBottomMin
80  * @HB_OT_MATH_CONSTANT_SUPERSCRIPT_BASELINE_DROP_MAX: superscriptBaselineDropMax
81  * @HB_OT_MATH_CONSTANT_SUB_SUPERSCRIPT_GAP_MIN: subSuperscriptGapMin
82  * @HB_OT_MATH_CONSTANT_SUPERSCRIPT_BOTTOM_MAX_WITH_SUBSCRIPT: superscriptBottomMaxWithSubscript
83  * @HB_OT_MATH_CONSTANT_SPACE_AFTER_SCRIPT: spaceAfterScript
84  * @HB_OT_MATH_CONSTANT_UPPER_LIMIT_GAP_MIN: upperLimitGapMin
85  * @HB_OT_MATH_CONSTANT_UPPER_LIMIT_BASELINE_RISE_MIN: upperLimitBaselineRiseMin
86  * @HB_OT_MATH_CONSTANT_LOWER_LIMIT_GAP_MIN: lowerLimitGapMin
87  * @HB_OT_MATH_CONSTANT_LOWER_LIMIT_BASELINE_DROP_MIN: lowerLimitBaselineDropMin
88  * @HB_OT_MATH_CONSTANT_STACK_TOP_SHIFT_UP: stackTopShiftUp
89  * @HB_OT_MATH_CONSTANT_STACK_TOP_DISPLAY_STYLE_SHIFT_UP: stackTopDisplayStyleShiftUp
90  * @HB_OT_MATH_CONSTANT_STACK_BOTTOM_SHIFT_DOWN: stackBottomShiftDown
91  * @HB_OT_MATH_CONSTANT_STACK_BOTTOM_DISPLAY_STYLE_SHIFT_DOWN: stackBottomDisplayStyleShiftDown
92  * @HB_OT_MATH_CONSTANT_STACK_GAP_MIN: stackGapMin
93  * @HB_OT_MATH_CONSTANT_STACK_DISPLAY_STYLE_GAP_MIN: stackDisplayStyleGapMin
94  * @HB_OT_MATH_CONSTANT_STRETCH_STACK_TOP_SHIFT_UP: stretchStackTopShiftUp
95  * @HB_OT_MATH_CONSTANT_STRETCH_STACK_BOTTOM_SHIFT_DOWN: stretchStackBottomShiftDown
96  * @HB_OT_MATH_CONSTANT_STRETCH_STACK_GAP_ABOVE_MIN: stretchStackGapAboveMin
97  * @HB_OT_MATH_CONSTANT_STRETCH_STACK_GAP_BELOW_MIN: stretchStackGapBelowMin
98  * @HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_SHIFT_UP: fractionNumeratorShiftUp
99  * @HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_DISPLAY_STYLE_SHIFT_UP: fractionNumeratorDisplayStyleShiftUp
100  * @HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_SHIFT_DOWN: fractionDenominatorShiftDown
101  * @HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_DISPLAY_STYLE_SHIFT_DOWN: fractionDenominatorDisplayStyleShiftDown
102  * @HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_GAP_MIN: fractionNumeratorGapMin
103  * @HB_OT_MATH_CONSTANT_FRACTION_NUM_DISPLAY_STYLE_GAP_MIN: fractionNumDisplayStyleGapMin
104  * @HB_OT_MATH_CONSTANT_FRACTION_RULE_THICKNESS: fractionRuleThickness
105  * @HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_GAP_MIN: fractionDenominatorGapMin
106  * @HB_OT_MATH_CONSTANT_FRACTION_DENOM_DISPLAY_STYLE_GAP_MIN: fractionDenomDisplayStyleGapMin
107  * @HB_OT_MATH_CONSTANT_SKEWED_FRACTION_HORIZONTAL_GAP: skewedFractionHorizontalGap
108  * @HB_OT_MATH_CONSTANT_SKEWED_FRACTION_VERTICAL_GAP: skewedFractionVerticalGap
109  * @HB_OT_MATH_CONSTANT_OVERBAR_VERTICAL_GAP: overbarVerticalGap
110  * @HB_OT_MATH_CONSTANT_OVERBAR_RULE_THICKNESS: overbarRuleThickness
111  * @HB_OT_MATH_CONSTANT_OVERBAR_EXTRA_ASCENDER: overbarExtraAscender
112  * @HB_OT_MATH_CONSTANT_UNDERBAR_VERTICAL_GAP: underbarVerticalGap
113  * @HB_OT_MATH_CONSTANT_UNDERBAR_RULE_THICKNESS: underbarRuleThickness
114  * @HB_OT_MATH_CONSTANT_UNDERBAR_EXTRA_DESCENDER: underbarExtraDescender
115  * @HB_OT_MATH_CONSTANT_RADICAL_VERTICAL_GAP: radicalVerticalGap
116  * @HB_OT_MATH_CONSTANT_RADICAL_DISPLAY_STYLE_VERTICAL_GAP: radicalDisplayStyleVerticalGap
117  * @HB_OT_MATH_CONSTANT_RADICAL_RULE_THICKNESS: radicalRuleThickness
118  * @HB_OT_MATH_CONSTANT_RADICAL_EXTRA_ASCENDER: radicalExtraAscender
119  * @HB_OT_MATH_CONSTANT_RADICAL_KERN_BEFORE_DEGREE: radicalKernBeforeDegree
120  * @HB_OT_MATH_CONSTANT_RADICAL_KERN_AFTER_DEGREE: radicalKernAfterDegree
121  * @HB_OT_MATH_CONSTANT_RADICAL_DEGREE_BOTTOM_RAISE_PERCENT: radicalDegreeBottomRaisePercent
122  *
123  * The 'MATH' table constants, refer to
124  * [OpenType documentation](https://docs.microsoft.com/en-us/typography/opentype/spec/math#mathconstants-table)
125  * For more explanations.
126  *
127  * Since: 1.3.3
128  */
129 typedef enum {
130   HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN = 0,
131   HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN = 1,
132   HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT = 2,
133   HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT = 3,
134   HB_OT_MATH_CONSTANT_MATH_LEADING = 4,
135   HB_OT_MATH_CONSTANT_AXIS_HEIGHT = 5,
136   HB_OT_MATH_CONSTANT_ACCENT_BASE_HEIGHT = 6,
137   HB_OT_MATH_CONSTANT_FLATTENED_ACCENT_BASE_HEIGHT = 7,
138   HB_OT_MATH_CONSTANT_SUBSCRIPT_SHIFT_DOWN = 8,
139   HB_OT_MATH_CONSTANT_SUBSCRIPT_TOP_MAX = 9,
140   HB_OT_MATH_CONSTANT_SUBSCRIPT_BASELINE_DROP_MIN = 10,
141   HB_OT_MATH_CONSTANT_SUPERSCRIPT_SHIFT_UP = 11,
142   HB_OT_MATH_CONSTANT_SUPERSCRIPT_SHIFT_UP_CRAMPED = 12,
143   HB_OT_MATH_CONSTANT_SUPERSCRIPT_BOTTOM_MIN = 13,
144   HB_OT_MATH_CONSTANT_SUPERSCRIPT_BASELINE_DROP_MAX = 14,
145   HB_OT_MATH_CONSTANT_SUB_SUPERSCRIPT_GAP_MIN = 15,
146   HB_OT_MATH_CONSTANT_SUPERSCRIPT_BOTTOM_MAX_WITH_SUBSCRIPT = 16,
147   HB_OT_MATH_CONSTANT_SPACE_AFTER_SCRIPT = 17,
148   HB_OT_MATH_CONSTANT_UPPER_LIMIT_GAP_MIN = 18,
149   HB_OT_MATH_CONSTANT_UPPER_LIMIT_BASELINE_RISE_MIN = 19,
150   HB_OT_MATH_CONSTANT_LOWER_LIMIT_GAP_MIN = 20,
151   HB_OT_MATH_CONSTANT_LOWER_LIMIT_BASELINE_DROP_MIN = 21,
152   HB_OT_MATH_CONSTANT_STACK_TOP_SHIFT_UP = 22,
153   HB_OT_MATH_CONSTANT_STACK_TOP_DISPLAY_STYLE_SHIFT_UP = 23,
154   HB_OT_MATH_CONSTANT_STACK_BOTTOM_SHIFT_DOWN = 24,
155   HB_OT_MATH_CONSTANT_STACK_BOTTOM_DISPLAY_STYLE_SHIFT_DOWN = 25,
156   HB_OT_MATH_CONSTANT_STACK_GAP_MIN = 26,
157   HB_OT_MATH_CONSTANT_STACK_DISPLAY_STYLE_GAP_MIN = 27,
158   HB_OT_MATH_CONSTANT_STRETCH_STACK_TOP_SHIFT_UP = 28,
159   HB_OT_MATH_CONSTANT_STRETCH_STACK_BOTTOM_SHIFT_DOWN = 29,
160   HB_OT_MATH_CONSTANT_STRETCH_STACK_GAP_ABOVE_MIN = 30,
161   HB_OT_MATH_CONSTANT_STRETCH_STACK_GAP_BELOW_MIN = 31,
162   HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_SHIFT_UP = 32,
163   HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_DISPLAY_STYLE_SHIFT_UP = 33,
164   HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_SHIFT_DOWN = 34,
165   HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_DISPLAY_STYLE_SHIFT_DOWN = 35,
166   HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_GAP_MIN = 36,
167   HB_OT_MATH_CONSTANT_FRACTION_NUM_DISPLAY_STYLE_GAP_MIN = 37,
168   HB_OT_MATH_CONSTANT_FRACTION_RULE_THICKNESS = 38,
169   HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_GAP_MIN = 39,
170   HB_OT_MATH_CONSTANT_FRACTION_DENOM_DISPLAY_STYLE_GAP_MIN = 40,
171   HB_OT_MATH_CONSTANT_SKEWED_FRACTION_HORIZONTAL_GAP = 41,
172   HB_OT_MATH_CONSTANT_SKEWED_FRACTION_VERTICAL_GAP = 42,
173   HB_OT_MATH_CONSTANT_OVERBAR_VERTICAL_GAP = 43,
174   HB_OT_MATH_CONSTANT_OVERBAR_RULE_THICKNESS = 44,
175   HB_OT_MATH_CONSTANT_OVERBAR_EXTRA_ASCENDER = 45,
176   HB_OT_MATH_CONSTANT_UNDERBAR_VERTICAL_GAP = 46,
177   HB_OT_MATH_CONSTANT_UNDERBAR_RULE_THICKNESS = 47,
178   HB_OT_MATH_CONSTANT_UNDERBAR_EXTRA_DESCENDER = 48,
179   HB_OT_MATH_CONSTANT_RADICAL_VERTICAL_GAP = 49,
180   HB_OT_MATH_CONSTANT_RADICAL_DISPLAY_STYLE_VERTICAL_GAP = 50,
181   HB_OT_MATH_CONSTANT_RADICAL_RULE_THICKNESS = 51,
182   HB_OT_MATH_CONSTANT_RADICAL_EXTRA_ASCENDER = 52,
183   HB_OT_MATH_CONSTANT_RADICAL_KERN_BEFORE_DEGREE = 53,
184   HB_OT_MATH_CONSTANT_RADICAL_KERN_AFTER_DEGREE = 54,
185   HB_OT_MATH_CONSTANT_RADICAL_DEGREE_BOTTOM_RAISE_PERCENT = 55
186 } hb_ot_math_constant_t;
187 
188 /**
189  * hb_ot_math_kern_t:
190  * @HB_OT_MATH_KERN_TOP_RIGHT: The top right corner of the glyph.
191  * @HB_OT_MATH_KERN_TOP_LEFT: The top left corner of the glyph.
192  * @HB_OT_MATH_KERN_BOTTOM_RIGHT: The bottom right corner of the glyph.
193  * @HB_OT_MATH_KERN_BOTTOM_LEFT: The bottom left corner of the glyph.
194  *
195  * The math kerning-table types defined for the four corners
196  * of a glyph.
197  *
198  * Since: 1.3.3
199  */
200 typedef enum {
201   HB_OT_MATH_KERN_TOP_RIGHT = 0,
202   HB_OT_MATH_KERN_TOP_LEFT = 1,
203   HB_OT_MATH_KERN_BOTTOM_RIGHT = 2,
204   HB_OT_MATH_KERN_BOTTOM_LEFT = 3
205 } hb_ot_math_kern_t;
206 
207 /**
208  * hb_ot_math_glyph_variant_t:
209  * @glyph: The glyph index of the variant
210  * @advance: The advance width of the variant
211  *
212  * Data type to hold math-variant information for a glyph.
213  *
214  * Since: 1.3.3
215  */
216 typedef struct hb_ot_math_glyph_variant_t {
217   hb_codepoint_t glyph;
218   hb_position_t advance;
219 } hb_ot_math_glyph_variant_t;
220 
221 /**
222  * hb_ot_math_glyph_part_flags_t:
223  * @HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER: This is an extender glyph part that
224  * can be repeated to reach the desired length.
225  *
226  * Flags for math glyph parts.
227  *
228  * Since: 1.3.3
229  */
230 typedef enum { /*< flags >*/
231   HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER	= 0x00000001u  /* Extender glyph */
232 } hb_ot_math_glyph_part_flags_t;
233 
234 /**
235  * hb_ot_math_glyph_part_t:
236  * @glyph: The glyph index of the variant part
237  * @start_connector_length: The length of the connector on the starting side of the variant part
238  * @end_connector_length: The length of the connector on the ending side of the variant part
239  * @full_advance: The total advance of the part
240  * @flags: #hb_ot_math_glyph_part_flags_t flags for the part
241  *
242  * Data type to hold information for a "part" component of a math-variant glyph.
243  * Large variants for stretchable math glyphs (such as parentheses) can be constructed
244  * on the fly from parts.
245  *
246  * Since: 1.3.3
247  */
248 typedef struct hb_ot_math_glyph_part_t {
249   hb_codepoint_t glyph;
250   hb_position_t start_connector_length;
251   hb_position_t end_connector_length;
252   hb_position_t full_advance;
253   hb_ot_math_glyph_part_flags_t flags;
254 } hb_ot_math_glyph_part_t;
255 
256 /* Methods */
257 
258 HB_EXTERN hb_bool_t
259 hb_ot_math_has_data (hb_face_t *face);
260 
261 HB_EXTERN hb_position_t
262 hb_ot_math_get_constant (hb_font_t *font,
263 			 hb_ot_math_constant_t constant);
264 
265 HB_EXTERN hb_position_t
266 hb_ot_math_get_glyph_italics_correction (hb_font_t *font,
267 					 hb_codepoint_t glyph);
268 
269 HB_EXTERN hb_position_t
270 hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font,
271 					    hb_codepoint_t glyph);
272 
273 HB_EXTERN hb_bool_t
274 hb_ot_math_is_glyph_extended_shape (hb_face_t *face,
275 				    hb_codepoint_t glyph);
276 
277 HB_EXTERN hb_position_t
278 hb_ot_math_get_glyph_kerning (hb_font_t *font,
279 			      hb_codepoint_t glyph,
280 			      hb_ot_math_kern_t kern,
281 			      hb_position_t correction_height);
282 
283 HB_EXTERN unsigned int
284 hb_ot_math_get_glyph_variants (hb_font_t *font,
285 			       hb_codepoint_t glyph,
286 			       hb_direction_t direction,
287 			       unsigned int start_offset,
288 			       unsigned int *variants_count, /* IN/OUT */
289 			       hb_ot_math_glyph_variant_t *variants /* OUT */);
290 
291 HB_EXTERN hb_position_t
292 hb_ot_math_get_min_connector_overlap (hb_font_t *font,
293 				      hb_direction_t direction);
294 
295 HB_EXTERN unsigned int
296 hb_ot_math_get_glyph_assembly (hb_font_t *font,
297 			       hb_codepoint_t glyph,
298 			       hb_direction_t direction,
299 			       unsigned int start_offset,
300 			       unsigned int *parts_count, /* IN/OUT */
301 			       hb_ot_math_glyph_part_t *parts, /* OUT */
302 			       hb_position_t *italics_correction /* OUT */);
303 
304 
305 HB_END_DECLS
306 
307 #endif /* HB_OT_MATH_H */
308