Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 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 | |
Behdad Esfahbod | da51a2c | 2019-06-18 13:09:22 -0700 | [diff] [blame] | 27 | #include "hb.hh" |
| 28 | |
| 29 | #ifndef HB_NO_MATH |
| 30 | |
Behdad Esfahbod | 93ef684 | 2017-01-09 21:11:00 -0800 | [diff] [blame] | 31 | #include "hb-ot-math-table.hh" |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 32 | |
Behdad Esfahbod | 80d9a42 | 2018-10-27 04:58:32 -0700 | [diff] [blame] | 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. |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 | * |
Behdad Esfahbod | 80d9a42 | 2018-10-27 04:58:32 -0700 | [diff] [blame] | 46 | **/ |
| 47 | |
| 48 | |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 49 | /* |
| 50 | * OT::MATH |
| 51 | */ |
| 52 | |
| 53 | /** |
| 54 | * hb_ot_math_has_data: |
| 55 | * @face: #hb_face_t to test |
| 56 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 57 | * Tests whether a face has a `MATH` table. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 58 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 59 | * Return value: true if the table is found, false otherwise |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 60 | * |
| 61 | * Since: 1.3.3 |
| 62 | **/ |
| 63 | hb_bool_t |
| 64 | hb_ot_math_has_data (hb_face_t *face) |
| 65 | { |
Behdad Esfahbod | a35c92c | 2018-11-05 22:58:43 -0500 | [diff] [blame] | 66 | return face->table.MATH->has_data (); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * hb_ot_math_get_constant: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 71 | * @font: #hb_font_t to work upon |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 72 | * @constant: #hb_ot_math_constant_t the constant to retrieve |
| 73 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 74 | * Fetches the specified math constant. For most constants, the value returned |
| 75 | * is an #hb_position_t. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 76 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 83 | * |
| 84 | * Since: 1.3.3 |
| 85 | **/ |
| 86 | hb_position_t |
| 87 | hb_ot_math_get_constant (hb_font_t *font, |
| 88 | hb_ot_math_constant_t constant) |
| 89 | { |
Behdad Esfahbod | a35c92c | 2018-11-05 22:58:43 -0500 | [diff] [blame] | 90 | return font->face->table.MATH->get_constant(constant, font); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
| 94 | * hb_ot_math_get_glyph_italics_correction: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 100 | * |
n8willis | ddc6dd4 | 2019-05-11 14:10:11 +0100 | [diff] [blame] | 101 | * Return value: the italics correction of the glyph or zero |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 102 | * |
| 103 | * Since: 1.3.3 |
| 104 | **/ |
| 105 | hb_position_t |
| 106 | hb_ot_math_get_glyph_italics_correction (hb_font_t *font, |
| 107 | hb_codepoint_t glyph) |
| 108 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 109 | return font->face->table.MATH->get_glyph_info().get_italics_correction (glyph, font); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
| 113 | * hb_ot_math_get_glyph_top_accent_attachment: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 119 | * |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 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 |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 128 | * |
| 129 | * Since: 1.3.3 |
| 130 | **/ |
| 131 | hb_position_t |
| 132 | hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font, |
| 133 | hb_codepoint_t glyph) |
| 134 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 135 | return font->face->table.MATH->get_glyph_info().get_top_accent_attachment (glyph, font); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * hb_ot_math_is_glyph_extended_shape: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 144 | * |
Behdad Esfahbod | 272b511 | 2017-01-19 19:33:07 -0800 | [diff] [blame] | 145 | * Return value: true if the glyph is an extended shape, false otherwise |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 146 | * |
| 147 | * Since: 1.3.3 |
| 148 | **/ |
| 149 | hb_bool_t |
| 150 | hb_ot_math_is_glyph_extended_shape (hb_face_t *face, |
| 151 | hb_codepoint_t glyph) |
| 152 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 153 | return face->table.MATH->get_glyph_info().is_extended_shape (glyph); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /** |
| 157 | * hb_ot_math_get_glyph_kerning: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 161 | * @correction_height: the correction height to use to determine the kerning. |
| 162 | * |
n8willis | bcd8193 | 2019-05-11 14:10:32 +0100 | [diff] [blame] | 163 | * Fetches the math kerning (cut-ins) value for the specified font, glyph index, and |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 164 | * @kern. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 165 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 172 | * |
| 173 | * Since: 1.3.3 |
| 174 | **/ |
| 175 | hb_position_t |
| 176 | hb_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 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 181 | return font->face->table.MATH->get_glyph_info().get_kerning (glyph, |
| 182 | kern, |
| 183 | correction_height, |
| 184 | font); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /** |
| 188 | * hb_ot_math_get_glyph_variants: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 189 | * @font: #hb_font_t to work upon |
| 190 | * @glyph: The index of the glyph to stretch |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 191 | * @direction: The direction of the stretching (horizontal or vertical) |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 192 | * @start_offset: offset of the first variant to retrieve |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 196 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 200 | * |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 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> |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 205 | * |
| 206 | * Return value: the total number of size variants available or zero |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 207 | * |
| 208 | * Since: 1.3.3 |
| 209 | **/ |
| 210 | unsigned int |
| 211 | hb_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 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 218 | return font->face->table.MATH->get_variants().get_glyph_variants (glyph, direction, font, |
| 219 | start_offset, |
| 220 | variants_count, |
| 221 | variants); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
| 225 | * hb_ot_math_get_min_connector_overlap: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 226 | * @font: #hb_font_t to work upon |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 227 | * @direction: direction of the stretching (horizontal or vertical) |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 228 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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. |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 232 | * |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 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> |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 237 | * |
| 238 | * Return value: requested minimum connector overlap or zero |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 239 | * |
| 240 | * Since: 1.3.3 |
| 241 | **/ |
| 242 | hb_position_t |
| 243 | hb_ot_math_get_min_connector_overlap (hb_font_t *font, |
| 244 | hb_direction_t direction) |
| 245 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 246 | return font->face->table.MATH->get_variants().get_min_connector_overlap (direction, font); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
| 250 | * hb_ot_math_get_glyph_assembly: |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 251 | * @font: #hb_font_t to work upon |
| 252 | * @glyph: The index of the glyph to stretch |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 253 | * @direction: direction of the stretching (horizontal or vertical) |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 254 | * @start_offset: offset of the first glyph part to retrieve |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 259 | * |
Nathan Willis | cd9889c | 2019-04-14 15:33:56 +0100 | [diff] [blame] | 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 | * |
Nathan Willis | 301f509 | 2019-05-11 20:11:36 +0100 | [diff] [blame] | 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> |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 269 | * |
| 270 | * Return value: the total number of parts in the glyph assembly |
| 271 | * |
| 272 | * Since: 1.3.3 |
| 273 | **/ |
| 274 | unsigned int |
| 275 | hb_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 | { |
Behdad Esfahbod | 61f5223 | 2018-11-05 23:28:52 -0500 | [diff] [blame] | 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); |
Frédéric Wang | ae00af4 | 2017-01-03 05:55:09 +0100 | [diff] [blame] | 290 | } |
Behdad Esfahbod | da51a2c | 2019-06-18 13:09:22 -0700 | [diff] [blame] | 291 | |
| 292 | |
| 293 | #endif |