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