Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2009 Red Hat, Inc. |
| 3 | * Copyright © 2012 Google, Inc. |
| 4 | * |
| 5 | * This is part of HarfBuzz, a text shaping library. |
| 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 |
| 26 | * Google Author(s): Behdad Esfahbod |
| 27 | */ |
| 28 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 29 | #include "hb.hh" |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 30 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 31 | #include "hb-face.hh" |
| 32 | #include "hb-blob.hh" |
| 33 | #include "hb-open-file.hh" |
Behdad Esfahbod | a84309a | 2018-08-26 09:33:01 -0700 | [diff] [blame] | 34 | #include "hb-ot-face.hh" |
Behdad Esfahbod | 3a0b3a2 | 2018-08-26 15:11:24 -0700 | [diff] [blame] | 35 | #include "hb-ot-cmap-table.hh" |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 36 | |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 37 | |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 38 | /** |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 39 | * SECTION:hb-face |
Behdad Esfahbod | cf5fa57 | 2018-10-27 04:50:38 -0700 | [diff] [blame] | 40 | * @title: hb-face |
Behdad Esfahbod | 5dd86aa | 2018-10-27 04:28:40 -0700 | [diff] [blame] | 41 | * @short_description: Font face objects |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 42 | * @include: hb.h |
| 43 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 44 | * A font face is an object that represents a single face from within a |
| 45 | * font family. |
| 46 | * |
| 47 | * More precisely, a font face represents a single face in a binary font file. |
Behdad Esfahbod | 00cf4e5 | 2018-10-27 04:07:33 -0700 | [diff] [blame] | 48 | * Font faces are typically built from a binary blob and a face index. |
| 49 | * Font faces are used to create fonts. |
| 50 | **/ |
| 51 | |
| 52 | |
| 53 | /** |
Behdad Esfahbod | 55bae68 | 2018-09-24 10:43:06 -0400 | [diff] [blame] | 54 | * hb_face_count: |
| 55 | * @blob: a blob. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 56 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 57 | * Fetches the number of faces in a blob. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 58 | * |
Behdad Esfahbod | 55bae68 | 2018-09-24 10:43:06 -0400 | [diff] [blame] | 59 | * Return value: Number of faces in @blob |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 60 | * |
Behdad Esfahbod | df01f3e | 2018-06-05 15:17:39 -0700 | [diff] [blame] | 61 | * Since: 1.7.7 |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 62 | **/ |
| 63 | unsigned int |
| 64 | hb_face_count (hb_blob_t *blob) |
| 65 | { |
| 66 | if (unlikely (!blob)) |
| 67 | return 0; |
| 68 | |
Behdad Esfahbod | 1e9e344 | 2018-07-17 19:17:59 +0200 | [diff] [blame] | 69 | /* TODO We shouldn't be sanitizing blob. Port to run sanitizer and return if not sane. */ |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 70 | /* Make API signature const after. */ |
Behdad Esfahbod | ed7b2e5 | 2018-08-01 23:59:09 -0700 | [diff] [blame] | 71 | hb_blob_t *sanitized = hb_sanitize_context_t ().sanitize_blob<OT::OpenTypeFontFile> (hb_blob_reference (blob)); |
Ebrahim Byagowi | 8220ef8 | 2018-06-05 22:50:53 +0430 | [diff] [blame] | 72 | const OT::OpenTypeFontFile& ot = *sanitized->as<OT::OpenTypeFontFile> (); |
Behdad Esfahbod | 1e9e344 | 2018-07-17 19:17:59 +0200 | [diff] [blame] | 73 | unsigned int ret = ot.get_face_count (); |
| 74 | hb_blob_destroy (sanitized); |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 75 | |
Behdad Esfahbod | 1e9e344 | 2018-07-17 19:17:59 +0200 | [diff] [blame] | 76 | return ret; |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 77 | } |
| 78 | |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 79 | /* |
| 80 | * hb_face_t |
| 81 | */ |
| 82 | |
Behdad Esfahbod | 3506672 | 2018-08-06 06:17:48 -0700 | [diff] [blame] | 83 | DEFINE_NULL_INSTANCE (hb_face_t) = |
| 84 | { |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 85 | HB_OBJECT_HEADER_STATIC, |
| 86 | |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 87 | nullptr, /* reference_table_func */ |
| 88 | nullptr, /* user_data */ |
| 89 | nullptr, /* destroy */ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 90 | |
| 91 | 0, /* index */ |
Behdad Esfahbod | 140797d | 2020-06-29 03:51:09 -0700 | [diff] [blame] | 92 | 1000, /* upem */ |
| 93 | 0, /* num_glyphs */ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 94 | |
Behdad Esfahbod | e88d47b | 2018-11-11 16:25:43 -0500 | [diff] [blame] | 95 | /* Zero for the rest is fine. */ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 99 | /** |
| 100 | * hb_face_create_for_tables: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 101 | * @reference_table_func: (closure user_data) (destroy destroy) (scope notified): Table-referencing function |
| 102 | * @user_data: A pointer to the user data |
Khaled Hosny | 9936490 | 2020-12-31 00:19:29 +0200 | [diff] [blame] | 103 | * @destroy: (nullable): A callback to call when @data is not needed anymore |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 104 | * |
Khaled Hosny | cc7b3a1 | 2020-09-26 10:22:39 +0200 | [diff] [blame] | 105 | * Variant of hb_face_create(), built for those cases where it is more |
| 106 | * convenient to provide data for individual tables instead of the whole font |
| 107 | * data. With the caveat that hb_face_get_table_tags() does not currently work |
| 108 | * with faces created this way. |
Khaled Hosny | 4811e8f | 2021-06-07 10:54:36 +0200 | [diff] [blame] | 109 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 110 | * Creates a new face object from the specified @user_data and @reference_table_func, |
Khaled Hosny | 4811e8f | 2021-06-07 10:54:36 +0200 | [diff] [blame] | 111 | * with the @destroy callback. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 112 | * |
n8willis | 41b46a3 | 2020-04-26 16:01:31 +0100 | [diff] [blame] | 113 | * Return value: (transfer full): The new face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 114 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 115 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 116 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 117 | hb_face_t * |
| 118 | hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, |
| 119 | void *user_data, |
| 120 | hb_destroy_func_t destroy) |
| 121 | { |
| 122 | hb_face_t *face; |
| 123 | |
| 124 | if (!reference_table_func || !(face = hb_object_create<hb_face_t> ())) { |
| 125 | if (destroy) |
| 126 | destroy (user_data); |
| 127 | return hb_face_get_empty (); |
| 128 | } |
| 129 | |
| 130 | face->reference_table_func = reference_table_func; |
| 131 | face->user_data = user_data; |
| 132 | face->destroy = destroy; |
| 133 | |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 134 | face->num_glyphs = -1; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 135 | |
Behdad Esfahbod | ce5da0f | 2018-11-16 02:29:13 -0500 | [diff] [blame] | 136 | face->data.init0 (face); |
Behdad Esfahbod | 914b595 | 2018-11-05 22:39:50 -0500 | [diff] [blame] | 137 | face->table.init0 (face); |
| 138 | |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 139 | return face; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | typedef struct hb_face_for_data_closure_t { |
| 144 | hb_blob_t *blob; |
Behdad Esfahbod | da7dba0 | 2022-01-01 11:20:20 -0700 | [diff] [blame] | 145 | uint16_t index; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 146 | } hb_face_for_data_closure_t; |
| 147 | |
| 148 | static hb_face_for_data_closure_t * |
| 149 | _hb_face_for_data_closure_create (hb_blob_t *blob, unsigned int index) |
| 150 | { |
| 151 | hb_face_for_data_closure_t *closure; |
| 152 | |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 153 | closure = (hb_face_for_data_closure_t *) hb_calloc (1, sizeof (hb_face_for_data_closure_t)); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 154 | if (unlikely (!closure)) |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 155 | return nullptr; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 156 | |
| 157 | closure->blob = blob; |
Behdad Esfahbod | da7dba0 | 2022-01-01 11:20:20 -0700 | [diff] [blame] | 158 | closure->index = (uint16_t) (index & 0xFFFFu); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 159 | |
| 160 | return closure; |
| 161 | } |
| 162 | |
| 163 | static void |
Behdad Esfahbod | e1b6d92 | 2017-10-11 15:51:31 +0200 | [diff] [blame] | 164 | _hb_face_for_data_closure_destroy (void *data) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 165 | { |
Behdad Esfahbod | e1b6d92 | 2017-10-11 15:51:31 +0200 | [diff] [blame] | 166 | hb_face_for_data_closure_t *closure = (hb_face_for_data_closure_t *) data; |
| 167 | |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 168 | hb_blob_destroy (closure->blob); |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 169 | hb_free (closure); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static hb_blob_t * |
| 173 | _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) |
| 174 | { |
| 175 | hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) user_data; |
| 176 | |
| 177 | if (tag == HB_TAG_NONE) |
| 178 | return hb_blob_reference (data->blob); |
| 179 | |
Behdad Esfahbod | eba1c16 | 2018-05-08 02:47:42 -0700 | [diff] [blame] | 180 | const OT::OpenTypeFontFile &ot_file = *data->blob->as<OT::OpenTypeFontFile> (); |
Behdad Esfahbod | 9479ffe | 2018-09-11 16:41:26 +0200 | [diff] [blame] | 181 | unsigned int base_offset; |
| 182 | const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index, &base_offset); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 183 | |
| 184 | const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag); |
| 185 | |
Behdad Esfahbod | 9479ffe | 2018-09-11 16:41:26 +0200 | [diff] [blame] | 186 | hb_blob_t *blob = hb_blob_create_sub_blob (data->blob, base_offset + table.offset, table.length); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 187 | |
| 188 | return blob; |
| 189 | } |
| 190 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 191 | /** |
Behdad Esfahbod | f78a250 | 2022-06-05 00:55:35 -0600 | [diff] [blame] | 192 | * hb_face_create: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 193 | * @blob: #hb_blob_t to work upon |
| 194 | * @index: The index of the face within @blob |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 195 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 196 | * Constructs a new face object from the specified blob and |
Behdad Esfahbod | da7dba0 | 2022-01-01 11:20:20 -0700 | [diff] [blame] | 197 | * a face index into that blob. |
| 198 | * |
| 199 | * The face index is used for blobs of file formats such as TTC and |
| 200 | * and DFont that can contain more than one face. Face indices within |
| 201 | * such collections are zero-based. |
| 202 | * |
| 203 | * <note>Note: If the blob font format is not a collection, @index |
| 204 | * is ignored. Otherwise, only the lower 16-bits of @index are used. |
| 205 | * The unmodified @index can be accessed via hb_face_get_index().</note> |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 206 | * |
Behdad Esfahbod | 2d42fc9 | 2022-01-02 07:45:10 -0700 | [diff] [blame] | 207 | * <note>Note: The high 16-bits of @index, if non-zero, are used by |
| 208 | * hb_font_create() to load named-instances in variable fonts. See |
| 209 | * hb_font_create() for details.</note> |
| 210 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 211 | * Return value: (transfer full): The new face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 212 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 213 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 214 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 215 | hb_face_t * |
| 216 | hb_face_create (hb_blob_t *blob, |
| 217 | unsigned int index) |
| 218 | { |
| 219 | hb_face_t *face; |
| 220 | |
Behdad Esfahbod | eb0bf3a | 2014-08-06 15:36:41 -0400 | [diff] [blame] | 221 | if (unlikely (!blob)) |
| 222 | blob = hb_blob_get_empty (); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 223 | |
Sebastian Rasmussen | 12a9d57 | 2020-06-24 03:25:43 +0800 | [diff] [blame] | 224 | blob = hb_sanitize_context_t ().sanitize_blob<OT::OpenTypeFontFile> (hb_blob_reference (blob)); |
| 225 | |
| 226 | hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (blob, index); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 227 | |
| 228 | if (unlikely (!closure)) |
Sebastian Rasmussen | 12a9d57 | 2020-06-24 03:25:43 +0800 | [diff] [blame] | 229 | { |
| 230 | hb_blob_destroy (blob); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 231 | return hb_face_get_empty (); |
Sebastian Rasmussen | 12a9d57 | 2020-06-24 03:25:43 +0800 | [diff] [blame] | 232 | } |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 233 | |
| 234 | face = hb_face_create_for_tables (_hb_face_for_data_reference_table, |
| 235 | closure, |
Behdad Esfahbod | e1b6d92 | 2017-10-11 15:51:31 +0200 | [diff] [blame] | 236 | _hb_face_for_data_closure_destroy); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 237 | |
Behdad Esfahbod | d3d3691 | 2017-02-03 15:42:03 -0800 | [diff] [blame] | 238 | face->index = index; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 239 | |
| 240 | return face; |
| 241 | } |
| 242 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 243 | /** |
| 244 | * hb_face_get_empty: |
| 245 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 246 | * Fetches the singleton empty face object. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 247 | * |
Khaled Hosny | 3d7a361 | 2020-12-30 23:58:37 +0200 | [diff] [blame] | 248 | * Return value: (transfer full): The empty face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 249 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 250 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 251 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 252 | hb_face_t * |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 253 | hb_face_get_empty () |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 254 | { |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 255 | return const_cast<hb_face_t *> (&Null (hb_face_t)); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 259 | /** |
| 260 | * hb_face_reference: (skip) |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 261 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 262 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 263 | * Increases the reference count on a face object. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 264 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 265 | * Return value: The @face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 266 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 267 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 268 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 269 | hb_face_t * |
| 270 | hb_face_reference (hb_face_t *face) |
| 271 | { |
| 272 | return hb_object_reference (face); |
| 273 | } |
| 274 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 275 | /** |
| 276 | * hb_face_destroy: (skip) |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 277 | * @face: A face object |
Khaled Hosny | 4811e8f | 2021-06-07 10:54:36 +0200 | [diff] [blame] | 278 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 279 | * Decreases the reference count on a face object. When the |
| 280 | * reference count reaches zero, the face is destroyed, |
| 281 | * freeing all memory. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 282 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 283 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 284 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 285 | void |
| 286 | hb_face_destroy (hb_face_t *face) |
| 287 | { |
| 288 | if (!hb_object_destroy (face)) return; |
| 289 | |
Behdad Esfahbod | 1a5c749 | 2022-12-04 15:20:51 -0700 | [diff] [blame] | 290 | #ifndef HB_NO_SHAPER |
Behdad Esfahbod | f6fc557 | 2018-11-05 13:23:54 -0500 | [diff] [blame] | 291 | for (hb_face_t::plan_node_t *node = face->shape_plans; node; ) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 292 | { |
| 293 | hb_face_t::plan_node_t *next = node->next; |
| 294 | hb_shape_plan_destroy (node->shape_plan); |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 295 | hb_free (node); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 296 | node = next; |
| 297 | } |
Behdad Esfahbod | 1a5c749 | 2022-12-04 15:20:51 -0700 | [diff] [blame] | 298 | #endif |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 299 | |
Behdad Esfahbod | ce5da0f | 2018-11-16 02:29:13 -0500 | [diff] [blame] | 300 | face->data.fini (); |
Behdad Esfahbod | 914b595 | 2018-11-05 22:39:50 -0500 | [diff] [blame] | 301 | face->table.fini (); |
| 302 | |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 303 | if (face->destroy) |
| 304 | face->destroy (face->user_data); |
| 305 | |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 306 | hb_free (face); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 307 | } |
| 308 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 309 | /** |
| 310 | * hb_face_set_user_data: (skip) |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 311 | * @face: A face object |
| 312 | * @key: The user-data key to set |
| 313 | * @data: A pointer to the user data |
Khaled Hosny | 9936490 | 2020-12-31 00:19:29 +0200 | [diff] [blame] | 314 | * @destroy: (nullable): A callback to call when @data is not needed anymore |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 315 | * @replace: Whether to replace an existing data with the same key |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 316 | * |
Khaled Hosny | 4811e8f | 2021-06-07 10:54:36 +0200 | [diff] [blame] | 317 | * Attaches a user-data key/data pair to the given face object. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 318 | * |
Khaled Hosny | 98e90cc | 2022-06-30 08:43:57 +0200 | [diff] [blame] | 319 | * Return value: `true` if success, `false` otherwise |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 320 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 321 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 322 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 323 | hb_bool_t |
| 324 | hb_face_set_user_data (hb_face_t *face, |
| 325 | hb_user_data_key_t *key, |
| 326 | void * data, |
| 327 | hb_destroy_func_t destroy, |
| 328 | hb_bool_t replace) |
| 329 | { |
| 330 | return hb_object_set_user_data (face, key, data, destroy, replace); |
| 331 | } |
| 332 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 333 | /** |
| 334 | * hb_face_get_user_data: (skip) |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 335 | * @face: A face object |
| 336 | * @key: The user-data key to query |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 337 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 338 | * Fetches the user data associated with the specified key, |
| 339 | * attached to the specified face object. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 340 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 341 | * Return value: (transfer none): A pointer to the user data |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 342 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 343 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 344 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 345 | void * |
Behdad Esfahbod | 1945b40 | 2022-07-25 10:45:55 -0600 | [diff] [blame] | 346 | hb_face_get_user_data (const hb_face_t *face, |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 347 | hb_user_data_key_t *key) |
| 348 | { |
| 349 | return hb_object_get_user_data (face, key); |
| 350 | } |
| 351 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 352 | /** |
| 353 | * hb_face_make_immutable: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 354 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 355 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 356 | * Makes the given face object immutable. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 357 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 358 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 359 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 360 | void |
| 361 | hb_face_make_immutable (hb_face_t *face) |
| 362 | { |
Behdad Esfahbod | 5570c87 | 2018-11-03 14:51:38 -0400 | [diff] [blame] | 363 | if (hb_object_is_immutable (face)) |
Behdad Esfahbod | 90a0f9f | 2018-09-26 15:03:07 -0400 | [diff] [blame] | 364 | return; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 365 | |
Behdad Esfahbod | 5570c87 | 2018-11-03 14:51:38 -0400 | [diff] [blame] | 366 | hb_object_make_immutable (face); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 369 | /** |
| 370 | * hb_face_is_immutable: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 371 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 372 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 373 | * Tests whether the given face object is immutable. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 374 | * |
Khaled Hosny | 98e90cc | 2022-06-30 08:43:57 +0200 | [diff] [blame] | 375 | * Return value: `true` is @face is immutable, `false` otherwise |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 376 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 377 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 378 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 379 | hb_bool_t |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 380 | hb_face_is_immutable (const hb_face_t *face) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 381 | { |
Behdad Esfahbod | 5570c87 | 2018-11-03 14:51:38 -0400 | [diff] [blame] | 382 | return hb_object_is_immutable (face); |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 386 | /** |
| 387 | * hb_face_reference_table: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 388 | * @face: A face object |
| 389 | * @tag: The #hb_tag_t of the table to query |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 390 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 391 | * Fetches a reference to the specified table within |
| 392 | * the specified face. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 393 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 394 | * Return value: (transfer full): A pointer to the @tag table within @face |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 395 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 396 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 397 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 398 | hb_blob_t * |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 399 | hb_face_reference_table (const hb_face_t *face, |
| 400 | hb_tag_t tag) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 401 | { |
Ebrahim Byagowi | f441a7c | 2019-09-01 02:18:09 +0430 | [diff] [blame] | 402 | if (unlikely (tag == HB_TAG_NONE)) |
| 403 | return hb_blob_get_empty (); |
| 404 | |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 405 | return face->reference_table (tag); |
| 406 | } |
| 407 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 408 | /** |
| 409 | * hb_face_reference_blob: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 410 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 411 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 412 | * Fetches a pointer to the binary blob that contains the |
Khaled Hosny | cc7b3a1 | 2020-09-26 10:22:39 +0200 | [diff] [blame] | 413 | * specified face. Returns an empty blob if referencing face data is not |
| 414 | * possible. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 415 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 416 | * Return value: (transfer full): A pointer to the blob for @face |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 417 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 418 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 419 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 420 | hb_blob_t * |
| 421 | hb_face_reference_blob (hb_face_t *face) |
| 422 | { |
| 423 | return face->reference_table (HB_TAG_NONE); |
| 424 | } |
| 425 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 426 | /** |
| 427 | * hb_face_set_index: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 428 | * @face: A face object |
| 429 | * @index: The index to assign |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 430 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 431 | * Assigns the specified face-index to @face. Fails if the |
| 432 | * face is immutable. |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 433 | * |
Behdad Esfahbod | da7dba0 | 2022-01-01 11:20:20 -0700 | [diff] [blame] | 434 | * <note>Note: changing the index has no effect on the face itself |
| 435 | * This only changes the value returned by hb_face_get_index().</note> |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 436 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 437 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 438 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 439 | void |
| 440 | hb_face_set_index (hb_face_t *face, |
| 441 | unsigned int index) |
| 442 | { |
Behdad Esfahbod | 5570c87 | 2018-11-03 14:51:38 -0400 | [diff] [blame] | 443 | if (hb_object_is_immutable (face)) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | face->index = index; |
| 447 | } |
| 448 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 449 | /** |
| 450 | * hb_face_get_index: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 451 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 452 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 453 | * Fetches the face-index corresponding to the given face. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 454 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 455 | * <note>Note: face indices within a collection are zero-based.</note> |
Ebrahim Byagowi | 32da0c6 | 2018-06-05 18:56:26 +0430 | [diff] [blame] | 456 | * |
Khaled Hosny | 4811e8f | 2021-06-07 10:54:36 +0200 | [diff] [blame] | 457 | * Return value: The index of @face. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 458 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 459 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 460 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 461 | unsigned int |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 462 | hb_face_get_index (const hb_face_t *face) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 463 | { |
| 464 | return face->index; |
| 465 | } |
| 466 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 467 | /** |
| 468 | * hb_face_set_upem: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 469 | * @face: A face object |
| 470 | * @upem: The units-per-em value to assign |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 471 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 472 | * Sets the units-per-em (upem) for a face object to the specified value. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 473 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 474 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 475 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 476 | void |
| 477 | hb_face_set_upem (hb_face_t *face, |
| 478 | unsigned int upem) |
| 479 | { |
Behdad Esfahbod | 5570c87 | 2018-11-03 14:51:38 -0400 | [diff] [blame] | 480 | if (hb_object_is_immutable (face)) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 481 | return; |
| 482 | |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 483 | face->upem = upem; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 484 | } |
| 485 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 486 | /** |
| 487 | * hb_face_get_upem: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 488 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 489 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 490 | * Fetches the units-per-em (upem) value of the specified face object. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 491 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 492 | * Return value: The upem value of @face |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 493 | * |
Behdad Esfahbod | 5d74ff0 | 2015-09-03 14:55:59 +0430 | [diff] [blame] | 494 | * Since: 0.9.2 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 495 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 496 | unsigned int |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 497 | hb_face_get_upem (const hb_face_t *face) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 498 | { |
| 499 | return face->get_upem (); |
| 500 | } |
| 501 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 502 | /** |
| 503 | * hb_face_set_glyph_count: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 504 | * @face: A face object |
| 505 | * @glyph_count: The glyph-count value to assign |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 506 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 507 | * Sets the glyph count for a face object to the specified value. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 508 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 509 | * Since: 0.9.7 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 510 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 511 | void |
| 512 | hb_face_set_glyph_count (hb_face_t *face, |
| 513 | unsigned int glyph_count) |
| 514 | { |
Behdad Esfahbod | 5570c87 | 2018-11-03 14:51:38 -0400 | [diff] [blame] | 515 | if (hb_object_is_immutable (face)) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 516 | return; |
| 517 | |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 518 | face->num_glyphs = glyph_count; |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 521 | /** |
| 522 | * hb_face_get_glyph_count: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 523 | * @face: A face object |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 524 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 525 | * Fetches the glyph-count value of the specified face object. |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 526 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 527 | * Return value: The glyph-count value of @face |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 528 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 529 | * Since: 0.9.7 |
Behdad Esfahbod | 288f289 | 2013-09-06 15:40:22 -0400 | [diff] [blame] | 530 | **/ |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 531 | unsigned int |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 532 | hb_face_get_glyph_count (const hb_face_t *face) |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 533 | { |
| 534 | return face->get_num_glyphs (); |
| 535 | } |
| 536 | |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 537 | /** |
| 538 | * hb_face_get_table_tags: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 539 | * @face: A face object |
| 540 | * @start_offset: The index of first table tag to retrieve |
| 541 | * @table_count: (inout): Input = the maximum number of table tags to return; |
| 542 | * Output = the actual number of table tags returned (may be zero) |
| 543 | * @table_tags: (out) (array length=table_count): The array of table tags found |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 544 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 545 | * Fetches a list of all table tags for a face, if possible. The list returned will |
| 546 | * begin at the offset provided |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 547 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 548 | * Return value: Total number of tables, or zero if it is not possible to list |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 549 | * |
| 550 | * Since: 1.6.0 |
| 551 | **/ |
| 552 | unsigned int |
Behdad Esfahbod | 16ccfaf | 2018-08-01 22:50:06 -0700 | [diff] [blame] | 553 | hb_face_get_table_tags (const hb_face_t *face, |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 554 | unsigned int start_offset, |
| 555 | unsigned int *table_count, /* IN/OUT */ |
| 556 | hb_tag_t *table_tags /* OUT */) |
| 557 | { |
prrace | 498e437 | 2018-06-09 16:04:28 -0700 | [diff] [blame] | 558 | if (face->destroy != (hb_destroy_func_t) _hb_face_for_data_closure_destroy) |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 559 | { |
| 560 | if (table_count) |
| 561 | *table_count = 0; |
| 562 | return 0; |
| 563 | } |
Behdad Esfahbod | 2e3a07a | 2013-08-26 18:49:07 -0400 | [diff] [blame] | 564 | |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 565 | hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) face->user_data; |
| 566 | |
Behdad Esfahbod | eba1c16 | 2018-05-08 02:47:42 -0700 | [diff] [blame] | 567 | const OT::OpenTypeFontFile &ot_file = *data->blob->as<OT::OpenTypeFontFile> (); |
Behdad Esfahbod | 94b3caf | 2017-10-11 17:22:44 +0200 | [diff] [blame] | 568 | const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); |
| 569 | |
| 570 | return ot_face.get_table_tags (start_offset, table_count, table_tags); |
| 571 | } |
Behdad Esfahbod | aadb2a9 | 2018-08-25 08:18:53 -0700 | [diff] [blame] | 572 | |
| 573 | |
| 574 | /* |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 575 | * Character set. |
| 576 | */ |
| 577 | |
Behdad Esfahbod | a84309a | 2018-08-26 09:33:01 -0700 | [diff] [blame] | 578 | |
Behdad Esfahbod | 27de7c4 | 2019-06-19 20:07:02 -0700 | [diff] [blame] | 579 | #ifndef HB_NO_FACE_COLLECT_UNICODES |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 580 | /** |
| 581 | * hb_face_collect_unicodes: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 582 | * @face: A face object |
Behdad Esfahbod | c54debc | 2023-01-05 11:54:06 -0700 | [diff] [blame^] | 583 | * @out: (out): The set to add Unicode characters to |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 584 | * |
| 585 | * Collects all of the Unicode characters covered by @face and adds |
| 586 | * them to the #hb_set_t set @out. |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 587 | * |
Behdad Esfahbod | 54d332d | 2018-09-10 11:37:24 +0200 | [diff] [blame] | 588 | * Since: 1.9.0 |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 589 | */ |
| 590 | void |
| 591 | hb_face_collect_unicodes (hb_face_t *face, |
| 592 | hb_set_t *out) |
| 593 | { |
Michiharu Ariza | 5ab50ee | 2020-02-29 01:32:29 -0800 | [diff] [blame] | 594 | face->table.cmap->collect_unicodes (out, face->get_num_glyphs ()); |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 595 | } |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 596 | /** |
Behdad Esfahbod | c54debc | 2023-01-05 11:54:06 -0700 | [diff] [blame^] | 597 | * hb_face_collect_nominal_glyph_mapping: |
| 598 | * @face: A face object |
| 599 | * @mapping: (out): The map to add Unicode-to-glyph mapping to |
| 600 | * @unicodes: (nullable) (out): The set to add Unicode characters to, or %NULL |
| 601 | * |
| 602 | * Collects the mapping from Unicode characters to nominal glyphs of the @face, |
| 603 | * and optionall all of the Unicode characters covered by @face. |
| 604 | * |
| 605 | * Since: REPLACEME |
| 606 | */ |
| 607 | void |
| 608 | hb_face_collect_nominal_glyph_mapping (hb_face_t *face, |
| 609 | hb_map_t *mapping, |
| 610 | hb_set_t *unicodes) |
| 611 | { |
| 612 | hb_set_t static_unicodes; |
| 613 | if (!unicodes) |
| 614 | unicodes = &static_unicodes; |
| 615 | face->table.cmap->collect_mapping (unicodes, mapping, face->get_num_glyphs ()); |
| 616 | } |
| 617 | /** |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 618 | * hb_face_collect_variation_selectors: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 619 | * @face: A face object |
Behdad Esfahbod | c54debc | 2023-01-05 11:54:06 -0700 | [diff] [blame^] | 620 | * @out: (out): The set to add Variation Selector characters to |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 621 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 622 | * Collects all Unicode "Variation Selector" characters covered by @face and adds |
| 623 | * them to the #hb_set_t set @out. |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 624 | * |
Behdad Esfahbod | 54d332d | 2018-09-10 11:37:24 +0200 | [diff] [blame] | 625 | * Since: 1.9.0 |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 626 | */ |
| 627 | void |
| 628 | hb_face_collect_variation_selectors (hb_face_t *face, |
| 629 | hb_set_t *out) |
| 630 | { |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 631 | face->table.cmap->collect_variation_selectors (out); |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 632 | } |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 633 | /** |
| 634 | * hb_face_collect_variation_unicodes: |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 635 | * @face: A face object |
| 636 | * @variation_selector: The Variation Selector to query |
Behdad Esfahbod | c54debc | 2023-01-05 11:54:06 -0700 | [diff] [blame^] | 637 | * @out: (out): The set to add Unicode characters to |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 638 | * |
Nathan Willis | 3e72feb | 2019-04-22 19:21:27 +0100 | [diff] [blame] | 639 | * Collects all Unicode characters for @variation_selector covered by @face and adds |
| 640 | * them to the #hb_set_t set @out. |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 641 | * |
Behdad Esfahbod | 54d332d | 2018-09-10 11:37:24 +0200 | [diff] [blame] | 642 | * Since: 1.9.0 |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 643 | */ |
| 644 | void |
| 645 | hb_face_collect_variation_unicodes (hb_face_t *face, |
| 646 | hb_codepoint_t variation_selector, |
| 647 | hb_set_t *out) |
| 648 | { |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 649 | face->table.cmap->collect_variation_unicodes (variation_selector, out); |
Behdad Esfahbod | dae39c5 | 2018-08-25 22:44:39 -0700 | [diff] [blame] | 650 | } |
Behdad Esfahbod | 27de7c4 | 2019-06-19 20:07:02 -0700 | [diff] [blame] | 651 | #endif |