Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2009 Red Hat, Inc. |
| 3 | * Copyright © 2011 Google, Inc. |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Red Hat Author(s): Behdad Esfahbod |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 29 | #ifndef HB_FONT_HH |
| 30 | #define HB_FONT_HH |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 32 | #include "hb.hh" |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 33 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 34 | #include "hb-face.hh" |
| 35 | #include "hb-shaper.hh" |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 36 | |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 37 | |
| 38 | /* |
Behdad Esfahbod | 5c44188 | 2009-08-10 20:05:16 -0400 | [diff] [blame] | 39 | * hb_font_funcs_t |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 40 | */ |
| 41 | |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 42 | #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \ |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 43 | HB_FONT_FUNC_IMPLEMENT (get_,font_h_extents) \ |
| 44 | HB_FONT_FUNC_IMPLEMENT (get_,font_v_extents) \ |
| 45 | HB_FONT_FUNC_IMPLEMENT (get_,nominal_glyph) \ |
| 46 | HB_FONT_FUNC_IMPLEMENT (get_,nominal_glyphs) \ |
| 47 | HB_FONT_FUNC_IMPLEMENT (get_,variation_glyph) \ |
| 48 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_h_advance) \ |
| 49 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_v_advance) \ |
| 50 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_h_advances) \ |
| 51 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_v_advances) \ |
| 52 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_h_origin) \ |
| 53 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_v_origin) \ |
| 54 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_h_kerning) \ |
| 55 | HB_IF_NOT_DEPRECATED (HB_FONT_FUNC_IMPLEMENT (get_,glyph_v_kerning)) \ |
| 56 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_extents) \ |
| 57 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_contour_point) \ |
| 58 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_name) \ |
| 59 | HB_FONT_FUNC_IMPLEMENT (get_,glyph_from_name) \ |
Matthias Clasen | 14b026f | 2022-12-19 13:53:49 -0500 | [diff] [blame] | 60 | HB_FONT_FUNC_IMPLEMENT (,draw_glyph) \ |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 61 | HB_FONT_FUNC_IMPLEMENT (,paint_glyph) \ |
Behdad Esfahbod | 4b6317c | 2011-07-07 23:14:42 -0400 | [diff] [blame] | 62 | /* ^--- Add new callbacks here */ |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 63 | |
Behdad Esfahbod | 3506672 | 2018-08-06 06:17:48 -0700 | [diff] [blame] | 64 | struct hb_font_funcs_t |
| 65 | { |
Behdad Esfahbod | 4b6317c | 2011-07-07 23:14:42 -0400 | [diff] [blame] | 66 | hb_object_header_t header; |
| 67 | |
Behdad Esfahbod | b9d975b | 2011-05-10 20:41:13 -0400 | [diff] [blame] | 68 | struct { |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 69 | #define HB_FONT_FUNC_IMPLEMENT(get_,name) void *name; |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 70 | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 71 | #undef HB_FONT_FUNC_IMPLEMENT |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 72 | } *user_data; |
Behdad Esfahbod | b9d975b | 2011-05-10 20:41:13 -0400 | [diff] [blame] | 73 | |
| 74 | struct { |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 75 | #define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_destroy_func_t name; |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 76 | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 77 | #undef HB_FONT_FUNC_IMPLEMENT |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 78 | } *destroy; |
Behdad Esfahbod | 28de104 | 2015-11-04 22:00:25 -0800 | [diff] [blame] | 79 | |
| 80 | /* Don't access these directly. Call font->get_*() instead. */ |
| 81 | union get_t { |
| 82 | struct get_funcs_t { |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 83 | #define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_func_t name; |
Behdad Esfahbod | 28de104 | 2015-11-04 22:00:25 -0800 | [diff] [blame] | 84 | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 85 | #undef HB_FONT_FUNC_IMPLEMENT |
| 86 | } f; |
Behdad Esfahbod | 8c94511 | 2018-03-28 14:06:58 -0700 | [diff] [blame] | 87 | void (*array[0 |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 88 | #define HB_FONT_FUNC_IMPLEMENT(get_,name) +1 |
Behdad Esfahbod | 8c94511 | 2018-03-28 14:06:58 -0700 | [diff] [blame] | 89 | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 90 | #undef HB_FONT_FUNC_IMPLEMENT |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 91 | ]) (); |
Behdad Esfahbod | 28de104 | 2015-11-04 22:00:25 -0800 | [diff] [blame] | 92 | } get; |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 93 | }; |
Behdad Esfahbod | 3506672 | 2018-08-06 06:17:48 -0700 | [diff] [blame] | 94 | DECLARE_NULL_INSTANCE (hb_font_funcs_t); |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 95 | |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * hb_font_t |
| 99 | */ |
| 100 | |
Behdad Esfahbod | ce5da0f | 2018-11-16 02:29:13 -0500 | [diff] [blame] | 101 | #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INSTANTIATE_SHAPERS(shaper, font); |
| 102 | #include "hb-shaper-list.hh" |
| 103 | #undef HB_SHAPER_IMPLEMENT |
| 104 | |
Behdad Esfahbod | 3506672 | 2018-08-06 06:17:48 -0700 | [diff] [blame] | 105 | struct hb_font_t |
| 106 | { |
Behdad Esfahbod | fca368c | 2011-04-21 18:24:02 -0400 | [diff] [blame] | 107 | hb_object_header_t header; |
Behdad Esfahbod | a2015cd | 2022-05-20 12:15:00 -0600 | [diff] [blame] | 108 | unsigned int serial; |
| 109 | unsigned int serial_coords; |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 110 | |
Behdad Esfahbod | defc45b | 2011-05-10 20:02:49 -0400 | [diff] [blame] | 111 | hb_font_t *parent; |
Behdad Esfahbod | 72657e4 | 2011-05-02 20:46:32 -0400 | [diff] [blame] | 112 | hb_face_t *face; |
| 113 | |
Behdad Esfahbod | b847769 | 2019-07-05 13:52:09 -0700 | [diff] [blame] | 114 | int32_t x_scale; |
| 115 | int32_t y_scale; |
Behdad Esfahbod | e39104b | 2023-02-01 16:56:56 -0700 | [diff] [blame] | 116 | |
| 117 | float x_embolden; |
| 118 | float y_embolden; |
Behdad Esfahbod | aef002e | 2023-02-07 11:29:49 -0700 | [diff] [blame] | 119 | bool embolden_in_place; |
| 120 | int32_t x_strength; /* x_embolden, in scaled units. */ |
| 121 | int32_t y_strength; /* y_embolden, in scaled units. */ |
Behdad Esfahbod | e39104b | 2023-02-01 16:56:56 -0700 | [diff] [blame] | 122 | |
Behdad Esfahbod | 810f5d7 | 2021-12-18 15:12:26 -0700 | [diff] [blame] | 123 | float slant; |
Behdad Esfahbod | ff697de | 2021-12-19 07:25:37 -0700 | [diff] [blame] | 124 | float slant_xy; |
Behdad Esfahbod | e39104b | 2023-02-01 16:56:56 -0700 | [diff] [blame] | 125 | |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 126 | float x_multf; |
| 127 | float y_multf; |
Behdad Esfahbod | b847769 | 2019-07-05 13:52:09 -0700 | [diff] [blame] | 128 | int64_t x_mult; |
| 129 | int64_t y_mult; |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 130 | |
| 131 | unsigned int x_ppem; |
| 132 | unsigned int y_ppem; |
Behdad Esfahbod | 5c44188 | 2009-08-10 20:05:16 -0400 | [diff] [blame] | 133 | |
Behdad Esfahbod | b57f18d | 2017-10-11 11:47:47 +0200 | [diff] [blame] | 134 | float ptem; |
| 135 | |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 136 | /* Font variation coordinates. */ |
Behdad Esfahbod | d195e07 | 2023-01-15 10:44:04 -0700 | [diff] [blame] | 137 | unsigned int instance_index; |
Behdad Esfahbod | ca28670 | 2016-03-01 19:29:36 +0900 | [diff] [blame] | 138 | unsigned int num_coords; |
Behdad Esfahbod | 26648ce | 2016-09-10 02:11:05 -0700 | [diff] [blame] | 139 | int *coords; |
Ebrahim Byagowi | ab2d3ec | 2019-08-14 18:42:51 +0430 | [diff] [blame] | 140 | float *design_coords; |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 141 | |
Behdad Esfahbod | 8fb3d1a | 2009-11-03 18:34:20 -0500 | [diff] [blame] | 142 | hb_font_funcs_t *klass; |
Behdad Esfahbod | 8fb3d1a | 2009-11-03 18:34:20 -0500 | [diff] [blame] | 143 | void *user_data; |
Behdad Esfahbod | 5668189 | 2011-04-20 03:03:32 -0400 | [diff] [blame] | 144 | hb_destroy_func_t destroy; |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 145 | |
Behdad Esfahbod | ce5da0f | 2018-11-16 02:29:13 -0500 | [diff] [blame] | 146 | hb_shaper_object_dataset_t<hb_font_t> data; /* Various shaper data. */ |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 147 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 148 | |
| 149 | /* Convert from font-space to user-space */ |
Behdad Esfahbod | f18ea1d | 2019-07-05 13:56:45 -0700 | [diff] [blame] | 150 | int64_t dir_mult (hb_direction_t direction) |
| 151 | { return HB_DIRECTION_IS_VERTICAL(direction) ? y_mult : x_mult; } |
| 152 | hb_position_t em_scale_x (int16_t v) { return em_mult (v, x_mult); } |
| 153 | hb_position_t em_scale_y (int16_t v) { return em_mult (v, y_mult); } |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 154 | hb_position_t em_scalef_x (float v) { return em_multf (v, x_multf); } |
| 155 | hb_position_t em_scalef_y (float v) { return em_multf (v, y_multf); } |
| 156 | float em_fscale_x (int16_t v) { return em_fmult (v, x_multf); } |
| 157 | float em_fscale_y (int16_t v) { return em_fmult (v, y_multf); } |
| 158 | float em_fscalef_x (float v) { return em_fmultf (v, x_multf); } |
| 159 | float em_fscalef_y (float v) { return em_fmultf (v, y_multf); } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 160 | hb_position_t em_scale_dir (int16_t v, hb_direction_t direction) |
Behdad Esfahbod | f18ea1d | 2019-07-05 13:56:45 -0700 | [diff] [blame] | 161 | { return em_mult (v, dir_mult (direction)); } |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 162 | |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 163 | /* Convert from parent-font user-space to our user-space */ |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 164 | hb_position_t parent_scale_x_distance (hb_position_t v) |
| 165 | { |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 166 | if (unlikely (parent && parent->x_scale != x_scale)) |
Behdad Esfahbod | 83408cf | 2013-11-06 14:46:04 -0500 | [diff] [blame] | 167 | return (hb_position_t) (v * (int64_t) this->x_scale / this->parent->x_scale); |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 168 | return v; |
| 169 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 170 | hb_position_t parent_scale_y_distance (hb_position_t v) |
| 171 | { |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 172 | if (unlikely (parent && parent->y_scale != y_scale)) |
Behdad Esfahbod | 83408cf | 2013-11-06 14:46:04 -0500 | [diff] [blame] | 173 | return (hb_position_t) (v * (int64_t) this->y_scale / this->parent->y_scale); |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 174 | return v; |
| 175 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 176 | hb_position_t parent_scale_x_position (hb_position_t v) |
| 177 | { return parent_scale_x_distance (v); } |
| 178 | hb_position_t parent_scale_y_position (hb_position_t v) |
| 179 | { return parent_scale_y_distance (v); } |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 180 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 181 | void parent_scale_distance (hb_position_t *x, hb_position_t *y) |
| 182 | { |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 183 | *x = parent_scale_x_distance (*x); |
| 184 | *y = parent_scale_y_distance (*y); |
| 185 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 186 | void parent_scale_position (hb_position_t *x, hb_position_t *y) |
| 187 | { |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 188 | *x = parent_scale_x_position (*x); |
| 189 | *y = parent_scale_y_position (*y); |
| 190 | } |
| 191 | |
Behdad Esfahbod | b0abbfd | 2022-12-22 07:26:14 -0700 | [diff] [blame] | 192 | void scale_glyph_extents (hb_glyph_extents_t *extents) |
| 193 | { |
Behdad Esfahbod | 30adbc2 | 2023-01-09 11:54:44 -0700 | [diff] [blame] | 194 | float x1 = em_fscale_x (extents->x_bearing); |
| 195 | float y1 = em_fscale_y (extents->y_bearing); |
| 196 | float x2 = em_fscale_x (extents->x_bearing + extents->width); |
| 197 | float y2 = em_fscale_y (extents->y_bearing + extents->height); |
Behdad Esfahbod | 9194e13 | 2022-12-22 07:31:16 -0700 | [diff] [blame] | 198 | |
| 199 | /* Apply slant. */ |
Behdad Esfahbod | d2aa239 | 2023-01-09 13:43:56 -0700 | [diff] [blame] | 200 | if (slant_xy) |
| 201 | { |
| 202 | x1 += hb_min (y1 * slant_xy, y2 * slant_xy); |
| 203 | x2 += hb_max (y1 * slant_xy, y2 * slant_xy); |
| 204 | } |
Behdad Esfahbod | 30adbc2 | 2023-01-09 11:54:44 -0700 | [diff] [blame] | 205 | |
| 206 | extents->x_bearing = floorf (x1); |
| 207 | extents->y_bearing = floorf (y1); |
| 208 | extents->width = ceilf (x2) - extents->x_bearing; |
| 209 | extents->height = ceilf (y2) - extents->y_bearing; |
| 210 | |
Behdad Esfahbod | 560a65e | 2023-02-07 13:46:13 -0700 | [diff] [blame] | 211 | if (x_strength || y_strength) |
| 212 | { |
| 213 | /* Y */ |
| 214 | int y_shift = y_strength; |
| 215 | if (y_scale < 0) y_shift = -y_shift; |
| 216 | extents->y_bearing += y_shift; |
| 217 | extents->height -= y_shift; |
| 218 | |
| 219 | /* X */ |
| 220 | int x_shift = x_strength; |
| 221 | if (x_scale < 0) x_shift = -x_shift; |
| 222 | if (embolden_in_place) |
| 223 | extents->x_bearing -= x_shift / 2; |
| 224 | extents->width += x_shift; |
| 225 | } |
Behdad Esfahbod | b0abbfd | 2022-12-22 07:26:14 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Behdad Esfahbod | 63d646f | 2011-05-11 00:15:37 -0400 | [diff] [blame] | 228 | |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 229 | /* Public getters */ |
| 230 | |
Behdad Esfahbod | 762770c | 2015-11-04 21:42:55 -0800 | [diff] [blame] | 231 | HB_INTERNAL bool has_func (unsigned int i); |
Behdad Esfahbod | 08b7172 | 2018-10-19 19:12:33 -0700 | [diff] [blame] | 232 | HB_INTERNAL bool has_func_set (unsigned int i); |
Behdad Esfahbod | 762770c | 2015-11-04 21:42:55 -0800 | [diff] [blame] | 233 | |
| 234 | /* has_* ... */ |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 235 | #define HB_FONT_FUNC_IMPLEMENT(get_,name) \ |
Behdad Esfahbod | 762770c | 2015-11-04 21:42:55 -0800 | [diff] [blame] | 236 | bool \ |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 237 | has_##name##_func () \ |
Behdad Esfahbod | 762770c | 2015-11-04 21:42:55 -0800 | [diff] [blame] | 238 | { \ |
| 239 | hb_font_funcs_t *funcs = this->klass; \ |
| 240 | unsigned int i = offsetof (hb_font_funcs_t::get_t::get_funcs_t, name) / sizeof (funcs->get.array[0]); \ |
| 241 | return has_func (i); \ |
Behdad Esfahbod | 08b7172 | 2018-10-19 19:12:33 -0700 | [diff] [blame] | 242 | } \ |
| 243 | bool \ |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 244 | has_##name##_func_set () \ |
Behdad Esfahbod | 08b7172 | 2018-10-19 19:12:33 -0700 | [diff] [blame] | 245 | { \ |
| 246 | hb_font_funcs_t *funcs = this->klass; \ |
| 247 | unsigned int i = offsetof (hb_font_funcs_t::get_t::get_funcs_t, name) / sizeof (funcs->get.array[0]); \ |
| 248 | return has_func_set (i); \ |
Behdad Esfahbod | 762770c | 2015-11-04 21:42:55 -0800 | [diff] [blame] | 249 | } |
| 250 | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 251 | #undef HB_FONT_FUNC_IMPLEMENT |
| 252 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 253 | hb_bool_t get_font_h_extents (hb_font_extents_t *extents) |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 254 | { |
Behdad Esfahbod | ac0efaf | 2022-11-22 12:50:36 -0700 | [diff] [blame] | 255 | hb_memset (extents, 0, sizeof (*extents)); |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 256 | return klass->get.f.font_h_extents (this, user_data, |
| 257 | extents, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 258 | !klass->user_data ? nullptr : klass->user_data->font_h_extents); |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 259 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 260 | hb_bool_t get_font_v_extents (hb_font_extents_t *extents) |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 261 | { |
Behdad Esfahbod | ac0efaf | 2022-11-22 12:50:36 -0700 | [diff] [blame] | 262 | hb_memset (extents, 0, sizeof (*extents)); |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 263 | return klass->get.f.font_v_extents (this, user_data, |
| 264 | extents, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 265 | !klass->user_data ? nullptr : klass->user_data->font_v_extents); |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 266 | } |
| 267 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 268 | bool has_glyph (hb_codepoint_t unicode) |
Behdad Esfahbod | 8de20b1 | 2014-01-02 14:30:45 +0800 | [diff] [blame] | 269 | { |
| 270 | hb_codepoint_t glyph; |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 271 | return get_nominal_glyph (unicode, &glyph); |
Behdad Esfahbod | 8de20b1 | 2014-01-02 14:30:45 +0800 | [diff] [blame] | 272 | } |
| 273 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 274 | hb_bool_t get_nominal_glyph (hb_codepoint_t unicode, |
Behdad Esfahbod | da50056 | 2021-10-26 08:02:29 -0600 | [diff] [blame] | 275 | hb_codepoint_t *glyph, |
| 276 | hb_codepoint_t not_found = 0) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 277 | { |
Behdad Esfahbod | da50056 | 2021-10-26 08:02:29 -0600 | [diff] [blame] | 278 | *glyph = not_found; |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 279 | return klass->get.f.nominal_glyph (this, user_data, |
| 280 | unicode, glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 281 | !klass->user_data ? nullptr : klass->user_data->nominal_glyph); |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 282 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 283 | unsigned int get_nominal_glyphs (unsigned int count, |
| 284 | const hb_codepoint_t *first_unicode, |
| 285 | unsigned int unicode_stride, |
| 286 | hb_codepoint_t *first_glyph, |
| 287 | unsigned int glyph_stride) |
Behdad Esfahbod | b314c4e | 2018-10-09 09:23:51 -0400 | [diff] [blame] | 288 | { |
| 289 | return klass->get.f.nominal_glyphs (this, user_data, |
| 290 | count, |
| 291 | first_unicode, unicode_stride, |
| 292 | first_glyph, glyph_stride, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 293 | !klass->user_data ? nullptr : klass->user_data->nominal_glyphs); |
Behdad Esfahbod | b314c4e | 2018-10-09 09:23:51 -0400 | [diff] [blame] | 294 | } |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 295 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 296 | hb_bool_t get_variation_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_selector, |
Behdad Esfahbod | da50056 | 2021-10-26 08:02:29 -0600 | [diff] [blame] | 297 | hb_codepoint_t *glyph, |
| 298 | hb_codepoint_t not_found = 0) |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 299 | { |
Behdad Esfahbod | da50056 | 2021-10-26 08:02:29 -0600 | [diff] [blame] | 300 | *glyph = not_found; |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 301 | return klass->get.f.variation_glyph (this, user_data, |
| 302 | unicode, variation_selector, glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 303 | !klass->user_data ? nullptr : klass->user_data->variation_glyph); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 304 | } |
| 305 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 306 | hb_position_t get_glyph_h_advance (hb_codepoint_t glyph) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 307 | { |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 308 | return klass->get.f.glyph_h_advance (this, user_data, |
| 309 | glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 310 | !klass->user_data ? nullptr : klass->user_data->glyph_h_advance); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 313 | hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 314 | { |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 315 | return klass->get.f.glyph_v_advance (this, user_data, |
| 316 | glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 317 | !klass->user_data ? nullptr : klass->user_data->glyph_v_advance); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 320 | void get_glyph_h_advances (unsigned int count, |
| 321 | const hb_codepoint_t *first_glyph, |
| 322 | unsigned int glyph_stride, |
| 323 | hb_position_t *first_advance, |
| 324 | unsigned int advance_stride) |
Behdad Esfahbod | 79e2198 | 2018-08-06 09:45:17 -0700 | [diff] [blame] | 325 | { |
| 326 | return klass->get.f.glyph_h_advances (this, user_data, |
| 327 | count, |
| 328 | first_glyph, glyph_stride, |
| 329 | first_advance, advance_stride, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 330 | !klass->user_data ? nullptr : klass->user_data->glyph_h_advances); |
Behdad Esfahbod | 79e2198 | 2018-08-06 09:45:17 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 333 | void get_glyph_v_advances (unsigned int count, |
| 334 | const hb_codepoint_t *first_glyph, |
| 335 | unsigned int glyph_stride, |
| 336 | hb_position_t *first_advance, |
| 337 | unsigned int advance_stride) |
Behdad Esfahbod | 79e2198 | 2018-08-06 09:45:17 -0700 | [diff] [blame] | 338 | { |
| 339 | return klass->get.f.glyph_v_advances (this, user_data, |
| 340 | count, |
| 341 | first_glyph, glyph_stride, |
| 342 | first_advance, advance_stride, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 343 | !klass->user_data ? nullptr : klass->user_data->glyph_v_advances); |
Behdad Esfahbod | 79e2198 | 2018-08-06 09:45:17 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 346 | hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph, |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 347 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 348 | { |
| 349 | *x = *y = 0; |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 350 | return klass->get.f.glyph_h_origin (this, user_data, |
| 351 | glyph, x, y, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 352 | !klass->user_data ? nullptr : klass->user_data->glyph_h_origin); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 355 | hb_bool_t get_glyph_v_origin (hb_codepoint_t glyph, |
| 356 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 357 | { |
| 358 | *x = *y = 0; |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 359 | return klass->get.f.glyph_v_origin (this, user_data, |
| 360 | glyph, x, y, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 361 | !klass->user_data ? nullptr : klass->user_data->glyph_v_origin); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 364 | hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, |
| 365 | hb_codepoint_t right_glyph) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 366 | { |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame] | 367 | #ifdef HB_DISABLE_DEPRECATED |
| 368 | return 0; |
| 369 | #else |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 370 | return klass->get.f.glyph_h_kerning (this, user_data, |
| 371 | left_glyph, right_glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 372 | !klass->user_data ? nullptr : klass->user_data->glyph_h_kerning); |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame] | 373 | #endif |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 376 | hb_position_t get_glyph_v_kerning (hb_codepoint_t top_glyph, |
| 377 | hb_codepoint_t bottom_glyph) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 378 | { |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame] | 379 | #ifdef HB_DISABLE_DEPRECATED |
| 380 | return 0; |
| 381 | #else |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 382 | return klass->get.f.glyph_v_kerning (this, user_data, |
| 383 | top_glyph, bottom_glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 384 | !klass->user_data ? nullptr : klass->user_data->glyph_v_kerning); |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame] | 385 | #endif |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 386 | } |
| 387 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 388 | hb_bool_t get_glyph_extents (hb_codepoint_t glyph, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 389 | hb_glyph_extents_t *extents) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 390 | { |
Behdad Esfahbod | ac0efaf | 2022-11-22 12:50:36 -0700 | [diff] [blame] | 391 | hb_memset (extents, 0, sizeof (*extents)); |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 392 | return klass->get.f.glyph_extents (this, user_data, |
| 393 | glyph, |
| 394 | extents, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 395 | !klass->user_data ? nullptr : klass->user_data->glyph_extents); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 398 | hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int point_index, |
Ebrahim Byagowi | d0e2add | 2020-07-18 22:14:52 +0430 | [diff] [blame] | 399 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 400 | { |
| 401 | *x = *y = 0; |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 402 | return klass->get.f.glyph_contour_point (this, user_data, |
| 403 | glyph, point_index, |
| 404 | x, y, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 405 | !klass->user_data ? nullptr : klass->user_data->glyph_contour_point); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 406 | } |
| 407 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 408 | hb_bool_t get_glyph_name (hb_codepoint_t glyph, |
| 409 | char *name, unsigned int size) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 410 | { |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 411 | if (size) *name = '\0'; |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 412 | return klass->get.f.glyph_name (this, user_data, |
| 413 | glyph, |
| 414 | name, size, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 415 | !klass->user_data ? nullptr : klass->user_data->glyph_name); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 418 | hb_bool_t get_glyph_from_name (const char *name, int len, /* -1 means nul-terminated */ |
| 419 | hb_codepoint_t *glyph) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 420 | { |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 421 | *glyph = 0; |
| 422 | if (len == -1) len = strlen (name); |
Behdad Esfahbod | 88e9a9b | 2015-11-04 21:16:26 -0800 | [diff] [blame] | 423 | return klass->get.f.glyph_from_name (this, user_data, |
| 424 | name, len, |
| 425 | glyph, |
Behdad Esfahbod | 88ccbd2 | 2022-06-01 08:44:07 -0600 | [diff] [blame] | 426 | !klass->user_data ? nullptr : klass->user_data->glyph_from_name); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Matthias Clasen | 14b026f | 2022-12-19 13:53:49 -0500 | [diff] [blame] | 429 | void draw_glyph (hb_codepoint_t glyph, |
| 430 | hb_draw_funcs_t *draw_funcs, void *draw_data) |
Behdad Esfahbod | 8b4f429 | 2022-02-03 01:14:47 -0600 | [diff] [blame] | 431 | { |
Matthias Clasen | 14b026f | 2022-12-19 13:53:49 -0500 | [diff] [blame] | 432 | klass->get.f.draw_glyph (this, user_data, |
| 433 | glyph, |
| 434 | draw_funcs, draw_data, |
| 435 | !klass->user_data ? nullptr : klass->user_data->draw_glyph); |
Behdad Esfahbod | 8b4f429 | 2022-02-03 01:14:47 -0600 | [diff] [blame] | 436 | } |
| 437 | |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 438 | void paint_glyph (hb_codepoint_t glyph, |
Matthias Clasen | 9be01b6 | 2022-12-21 14:04:32 -0500 | [diff] [blame] | 439 | hb_paint_funcs_t *paint_funcs, void *paint_data, |
| 440 | unsigned int palette, |
| 441 | hb_color_t foreground) |
Matthias Clasen | 71efa0d | 2022-12-14 06:22:00 -0500 | [diff] [blame] | 442 | { |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 443 | klass->get.f.paint_glyph (this, user_data, |
Matthias Clasen | 71efa0d | 2022-12-14 06:22:00 -0500 | [diff] [blame] | 444 | glyph, |
| 445 | paint_funcs, paint_data, |
Matthias Clasen | 9be01b6 | 2022-12-21 14:04:32 -0500 | [diff] [blame] | 446 | palette, foreground, |
Matthias Clasen | 0f287e7 | 2022-12-19 13:45:45 -0500 | [diff] [blame] | 447 | !klass->user_data ? nullptr : klass->user_data->paint_glyph); |
Matthias Clasen | 71efa0d | 2022-12-14 06:22:00 -0500 | [diff] [blame] | 448 | } |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 449 | |
| 450 | /* A bit higher-level, and with fallback */ |
| 451 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 452 | void get_h_extents_with_fallback (hb_font_extents_t *extents) |
Behdad Esfahbod | a7b32f2 | 2016-10-26 18:08:41 +0200 | [diff] [blame] | 453 | { |
| 454 | if (!get_font_h_extents (extents)) |
| 455 | { |
| 456 | extents->ascender = y_scale * .8; |
| 457 | extents->descender = extents->ascender - y_scale; |
| 458 | extents->line_gap = 0; |
| 459 | } |
| 460 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 461 | void get_v_extents_with_fallback (hb_font_extents_t *extents) |
Behdad Esfahbod | a7b32f2 | 2016-10-26 18:08:41 +0200 | [diff] [blame] | 462 | { |
| 463 | if (!get_font_v_extents (extents)) |
| 464 | { |
| 465 | extents->ascender = x_scale / 2; |
| 466 | extents->descender = extents->ascender - x_scale; |
| 467 | extents->line_gap = 0; |
| 468 | } |
| 469 | } |
| 470 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 471 | void get_extents_for_direction (hb_direction_t direction, |
| 472 | hb_font_extents_t *extents) |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 473 | { |
Behdad Esfahbod | a7b32f2 | 2016-10-26 18:08:41 +0200 | [diff] [blame] | 474 | if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
| 475 | get_h_extents_with_fallback (extents); |
| 476 | else |
| 477 | get_v_extents_with_fallback (extents); |
Simon Cozens | 6f2e6de | 2015-10-26 16:23:22 +0900 | [diff] [blame] | 478 | } |
| 479 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 480 | void get_glyph_advance_for_direction (hb_codepoint_t glyph, |
| 481 | hb_direction_t direction, |
| 482 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 483 | { |
Behdad Esfahbod | 9967751 | 2018-08-07 09:44:01 -0700 | [diff] [blame] | 484 | *x = *y = 0; |
| 485 | if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 486 | *x = get_glyph_h_advance (glyph); |
Behdad Esfahbod | 9967751 | 2018-08-07 09:44:01 -0700 | [diff] [blame] | 487 | else |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 488 | *y = get_glyph_v_advance (glyph); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 489 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 490 | void get_glyph_advances_for_direction (hb_direction_t direction, |
| 491 | unsigned int count, |
| 492 | const hb_codepoint_t *first_glyph, |
| 493 | unsigned glyph_stride, |
| 494 | hb_position_t *first_advance, |
| 495 | unsigned advance_stride) |
Behdad Esfahbod | b0ff79a | 2018-08-07 09:52:06 -0700 | [diff] [blame] | 496 | { |
| 497 | if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
| 498 | get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); |
| 499 | else |
| 500 | get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); |
| 501 | } |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 502 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 503 | void guess_v_origin_minus_h_origin (hb_codepoint_t glyph, |
| 504 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 505 | { |
| 506 | *x = get_glyph_h_advance (glyph) / 2; |
| 507 | |
Behdad Esfahbod | 2b11772 | 2016-10-26 18:12:50 +0200 | [diff] [blame] | 508 | hb_font_extents_t extents; |
| 509 | get_h_extents_with_fallback (&extents); |
| 510 | *y = extents.ascender; |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 511 | } |
| 512 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 513 | void get_glyph_h_origin_with_fallback (hb_codepoint_t glyph, |
| 514 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 515 | { |
| 516 | if (!get_glyph_h_origin (glyph, x, y) && |
| 517 | get_glyph_v_origin (glyph, x, y)) |
| 518 | { |
| 519 | hb_position_t dx, dy; |
| 520 | guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
| 521 | *x -= dx; *y -= dy; |
| 522 | } |
| 523 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 524 | void get_glyph_v_origin_with_fallback (hb_codepoint_t glyph, |
| 525 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 526 | { |
| 527 | if (!get_glyph_v_origin (glyph, x, y) && |
| 528 | get_glyph_h_origin (glyph, x, y)) |
| 529 | { |
| 530 | hb_position_t dx, dy; |
| 531 | guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
| 532 | *x += dx; *y += dy; |
| 533 | } |
| 534 | } |
| 535 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 536 | void get_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 537 | hb_direction_t direction, |
| 538 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 539 | { |
Behdad Esfahbod | 7235f33 | 2013-06-10 14:39:51 -0400 | [diff] [blame] | 540 | if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 541 | get_glyph_h_origin_with_fallback (glyph, x, y); |
Behdad Esfahbod | 7235f33 | 2013-06-10 14:39:51 -0400 | [diff] [blame] | 542 | else |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 543 | get_glyph_v_origin_with_fallback (glyph, x, y); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 546 | void add_glyph_h_origin (hb_codepoint_t glyph, |
| 547 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 548 | { |
| 549 | hb_position_t origin_x, origin_y; |
| 550 | |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 551 | get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y); |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 552 | |
| 553 | *x += origin_x; |
| 554 | *y += origin_y; |
| 555 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 556 | void add_glyph_v_origin (hb_codepoint_t glyph, |
| 557 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 558 | { |
| 559 | hb_position_t origin_x, origin_y; |
| 560 | |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 561 | get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y); |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 562 | |
| 563 | *x += origin_x; |
| 564 | *y += origin_y; |
| 565 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 566 | void add_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 567 | hb_direction_t direction, |
| 568 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 569 | { |
| 570 | hb_position_t origin_x, origin_y; |
| 571 | |
| 572 | get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); |
| 573 | |
| 574 | *x += origin_x; |
| 575 | *y += origin_y; |
| 576 | } |
| 577 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 578 | void subtract_glyph_h_origin (hb_codepoint_t glyph, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 579 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 580 | { |
| 581 | hb_position_t origin_x, origin_y; |
| 582 | |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 583 | get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y); |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 584 | |
| 585 | *x -= origin_x; |
| 586 | *y -= origin_y; |
| 587 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 588 | void subtract_glyph_v_origin (hb_codepoint_t glyph, |
| 589 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 590 | { |
| 591 | hb_position_t origin_x, origin_y; |
| 592 | |
Behdad Esfahbod | 9ee23c4 | 2016-10-26 17:44:16 +0200 | [diff] [blame] | 593 | get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y); |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 594 | |
| 595 | *x -= origin_x; |
| 596 | *y -= origin_y; |
| 597 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 598 | void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 599 | hb_direction_t direction, |
| 600 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 601 | { |
| 602 | hb_position_t origin_x, origin_y; |
| 603 | |
| 604 | get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); |
| 605 | |
| 606 | *x -= origin_x; |
| 607 | *y -= origin_y; |
| 608 | } |
| 609 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 610 | void get_glyph_kerning_for_direction (hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, |
| 611 | hb_direction_t direction, |
| 612 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 613 | { |
| 614 | if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 615 | *y = 0; |
Behdad Esfahbod | 683c3a9 | 2018-10-08 23:09:48 -0400 | [diff] [blame] | 616 | *x = get_glyph_h_kerning (first_glyph, second_glyph); |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 617 | } else { |
| 618 | *x = 0; |
| 619 | *y = get_glyph_v_kerning (first_glyph, second_glyph); |
| 620 | } |
| 621 | } |
| 622 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 623 | hb_bool_t get_glyph_extents_for_origin (hb_codepoint_t glyph, |
| 624 | hb_direction_t direction, |
| 625 | hb_glyph_extents_t *extents) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 626 | { |
| 627 | hb_bool_t ret = get_glyph_extents (glyph, extents); |
| 628 | |
| 629 | if (ret) |
| 630 | subtract_glyph_origin_for_direction (glyph, direction, &extents->x_bearing, &extents->y_bearing); |
| 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 635 | hb_bool_t get_glyph_contour_point_for_origin (hb_codepoint_t glyph, unsigned int point_index, |
| 636 | hb_direction_t direction, |
| 637 | hb_position_t *x, hb_position_t *y) |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 638 | { |
| 639 | hb_bool_t ret = get_glyph_contour_point (glyph, point_index, x, y); |
| 640 | |
| 641 | if (ret) |
| 642 | subtract_glyph_origin_for_direction (glyph, direction, x, y); |
| 643 | |
| 644 | return ret; |
| 645 | } |
| 646 | |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 647 | /* Generates gidDDD if glyph has no name. */ |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 648 | void |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 649 | glyph_to_string (hb_codepoint_t glyph, |
| 650 | char *s, unsigned int size) |
| 651 | { |
| 652 | if (get_glyph_name (glyph, s, size)) return; |
| 653 | |
Behdad Esfahbod | 38b8b40 | 2013-08-27 11:44:09 -0400 | [diff] [blame] | 654 | if (size && snprintf (s, size, "gid%u", glyph) < 0) |
| 655 | *s = '\0'; |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /* Parses gidDDD and uniUUUU strings automatically. */ |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 659 | hb_bool_t |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 660 | glyph_from_string (const char *s, int len, /* -1 means nul-terminated */ |
| 661 | hb_codepoint_t *glyph) |
| 662 | { |
| 663 | if (get_glyph_from_name (s, len, glyph)) return true; |
| 664 | |
| 665 | if (len == -1) len = strlen (s); |
| 666 | |
| 667 | /* Straight glyph index. */ |
| 668 | if (hb_codepoint_parse (s, len, 10, glyph)) |
| 669 | return true; |
| 670 | |
| 671 | if (len > 3) |
| 672 | { |
| 673 | /* gidDDD syntax for glyph indices. */ |
| 674 | if (0 == strncmp (s, "gid", 3) && |
| 675 | hb_codepoint_parse (s + 3, len - 3, 10, glyph)) |
| 676 | return true; |
| 677 | |
| 678 | /* uniUUUU and other Unicode character indices. */ |
| 679 | hb_codepoint_t unichar; |
| 680 | if (0 == strncmp (s, "uni", 3) && |
| 681 | hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 682 | get_nominal_glyph (unichar, glyph)) |
Behdad Esfahbod | 6f3a300 | 2012-08-07 22:13:25 -0400 | [diff] [blame] | 683 | return true; |
| 684 | } |
| 685 | |
| 686 | return false; |
| 687 | } |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 688 | |
Behdad Esfahbod | b847769 | 2019-07-05 13:52:09 -0700 | [diff] [blame] | 689 | void mults_changed () |
| 690 | { |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 691 | float upem = face->get_upem (); |
Behdad Esfahbod | e39104b | 2023-02-01 16:56:56 -0700 | [diff] [blame] | 692 | |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 693 | x_multf = x_scale / upem; |
| 694 | y_multf = y_scale / upem; |
Behdad Esfahbod | cd05d18 | 2022-06-01 07:27:30 -0600 | [diff] [blame] | 695 | bool x_neg = x_scale < 0; |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 696 | x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) / upem; |
Behdad Esfahbod | cd05d18 | 2022-06-01 07:27:30 -0600 | [diff] [blame] | 697 | bool y_neg = y_scale < 0; |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 698 | y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) / upem; |
Behdad Esfahbod | e39104b | 2023-02-01 16:56:56 -0700 | [diff] [blame] | 699 | |
Behdad Esfahbod | 8c1b47d | 2023-02-19 20:38:43 -0700 | [diff] [blame] | 700 | x_strength = fabsf (roundf (x_scale * x_embolden)); |
| 701 | y_strength = fabsf (roundf (y_scale * y_embolden)); |
Behdad Esfahbod | e39104b | 2023-02-01 16:56:56 -0700 | [diff] [blame] | 702 | |
Behdad Esfahbod | ff697de | 2021-12-19 07:25:37 -0700 | [diff] [blame] | 703 | slant_xy = y_scale ? slant * x_scale / y_scale : 0.f; |
Behdad Esfahbod | c1c78ad | 2022-06-28 13:19:12 -0600 | [diff] [blame] | 704 | |
| 705 | data.fini (); |
Behdad Esfahbod | b847769 | 2019-07-05 13:52:09 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Behdad Esfahbod | f18ea1d | 2019-07-05 13:56:45 -0700 | [diff] [blame] | 708 | hb_position_t em_mult (int16_t v, int64_t mult) |
Behdad Esfahbod | bbaccf2 | 2021-11-01 16:45:36 -0600 | [diff] [blame] | 709 | { return (hb_position_t) ((v * mult + 32768) >> 16); } |
Behdad Esfahbod | d3308f4 | 2022-06-27 11:28:44 -0600 | [diff] [blame] | 710 | hb_position_t em_multf (float v, float mult) |
| 711 | { return (hb_position_t) roundf (em_fmultf (v, mult)); } |
| 712 | float em_fmultf (float v, float mult) |
| 713 | { return v * mult; } |
| 714 | float em_fmult (int16_t v, float mult) |
| 715 | { return (float) v * mult; } |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 716 | }; |
Behdad Esfahbod | 3506672 | 2018-08-06 06:17:48 -0700 | [diff] [blame] | 717 | DECLARE_NULL_INSTANCE (hb_font_t); |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 718 | |
Behdad Esfahbod | c62b503 | 2009-08-01 19:54:49 -0400 | [diff] [blame] | 719 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 720 | #endif /* HB_FONT_HH */ |