Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 1 | /* |
Michiharu Ariza | 0dfa584 | 2018-11-12 08:47:07 -0800 | [diff] [blame] | 2 | * Copyright © 2018 Adobe Inc. |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Adobe Author(s): Michiharu Ariza |
| 25 | */ |
| 26 | |
| 27 | #ifndef HB_OT_CFF2_TABLE_HH |
| 28 | #define HB_OT_CFF2_TABLE_HH |
| 29 | |
Michiharu Ariza | 8af9690 | 2018-08-29 13:26:17 -0700 | [diff] [blame] | 30 | #include "hb-ot-cff-common.hh" |
Behdad Esfahbod | 5f39913 | 2023-06-23 11:22:01 -0600 | [diff] [blame] | 31 | #include "hb-subset-cff-common.hh" |
Ebrahim Byagowi | 9fe0dc3 | 2020-02-26 17:40:44 +0330 | [diff] [blame] | 32 | #include "hb-draw.hh" |
Matthias Clasen | 3e39dd4 | 2022-12-16 23:46:15 -0500 | [diff] [blame] | 33 | #include "hb-paint.hh" |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 34 | |
| 35 | namespace CFF { |
| 36 | |
| 37 | /* |
| 38 | * CFF2 -- Compact Font Format (CFF) Version 2 |
| 39 | * https://docs.microsoft.com/en-us/typography/opentype/spec/cff2 |
| 40 | */ |
Khaled Hosny | b6516f3 | 2023-05-08 15:31:24 +0300 | [diff] [blame] | 41 | #define HB_OT_TAG_CFF2 HB_TAG('C','F','F','2') |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 42 | |
Michiharu Ariza | f57d6bc | 2018-08-16 08:03:46 -0700 | [diff] [blame] | 43 | typedef CFFIndex<HBUINT32> CFF2Index; |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 44 | |
| 45 | typedef CFF2Index CFF2CharStrings; |
Michiharu Ariza | 633ce88 | 2018-08-15 12:00:19 -0700 | [diff] [blame] | 46 | typedef Subrs<HBUINT32> CFF2Subrs; |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 47 | |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 48 | typedef FDSelect3_4<HBUINT32, HBUINT16> FDSelect4; |
| 49 | typedef FDSelect3_4_Range<HBUINT32, HBUINT16> FDSelect4_Range; |
| 50 | |
| 51 | struct CFF2FDSelect |
| 52 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 53 | bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs) |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 54 | { |
| 55 | TRACE_SERIALIZE (this); |
| 56 | unsigned int size = src.get_size (num_glyphs); |
| 57 | CFF2FDSelect *dest = c->allocate_size<CFF2FDSelect> (size); |
Ebrahim Byagowi | 2be859d | 2020-04-20 23:48:23 +0430 | [diff] [blame] | 58 | if (unlikely (!dest)) return_trace (false); |
Behdad Esfahbod | 59c45f6 | 2022-11-22 12:54:50 -0700 | [diff] [blame] | 59 | hb_memcpy (dest, &src, size); |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 60 | return_trace (true); |
| 61 | } |
| 62 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 63 | unsigned int get_size (unsigned int num_glyphs) const |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 64 | { |
Ebrahim Byagowi | 9b853f7 | 2019-06-09 11:49:25 +0430 | [diff] [blame] | 65 | switch (format) |
| 66 | { |
| 67 | case 0: return format.static_size + u.format0.get_size (num_glyphs); |
| 68 | case 3: return format.static_size + u.format3.get_size (); |
| 69 | case 4: return format.static_size + u.format4.get_size (); |
| 70 | default:return 0; |
| 71 | } |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 74 | hb_codepoint_t get_fd (hb_codepoint_t glyph) const |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 75 | { |
Ebrahim Byagowi | 9b853f7 | 2019-06-09 11:49:25 +0430 | [diff] [blame] | 76 | if (this == &Null (CFF2FDSelect)) |
Michiharu Ariza | 633ce88 | 2018-08-15 12:00:19 -0700 | [diff] [blame] | 77 | return 0; |
Ebrahim Byagowi | 9b853f7 | 2019-06-09 11:49:25 +0430 | [diff] [blame] | 78 | |
| 79 | switch (format) |
| 80 | { |
| 81 | case 0: return u.format0.get_fd (glyph); |
| 82 | case 3: return u.format3.get_fd (glyph); |
| 83 | case 4: return u.format4.get_fd (glyph); |
| 84 | default:return 0; |
| 85 | } |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ebrahim Byagowi | 9b853f7 | 2019-06-09 11:49:25 +0430 | [diff] [blame] | 88 | bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const |
| 89 | { |
| 90 | TRACE_SANITIZE (this); |
| 91 | if (unlikely (!c->check_struct (this))) |
| 92 | return_trace (false); |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 93 | |
Ebrahim Byagowi | 9b853f7 | 2019-06-09 11:49:25 +0430 | [diff] [blame] | 94 | switch (format) |
| 95 | { |
| 96 | case 0: return_trace (u.format0.sanitize (c, fdcount)); |
| 97 | case 3: return_trace (u.format3.sanitize (c, fdcount)); |
| 98 | case 4: return_trace (u.format4.sanitize (c, fdcount)); |
| 99 | default:return_trace (false); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | HBUINT8 format; |
| 104 | union { |
| 105 | FDSelect0 format0; |
| 106 | FDSelect3 format3; |
| 107 | FDSelect4 format4; |
| 108 | } u; |
| 109 | public: |
Michiharu Ariza | 5561b81 | 2018-08-06 10:04:53 -0700 | [diff] [blame] | 110 | DEFINE_SIZE_MIN (2); |
| 111 | }; |
| 112 | |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 113 | struct CFF2VariationStore |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 114 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 115 | bool sanitize (hb_sanitize_context_t *c) const |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 116 | { |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 117 | TRACE_SANITIZE (this); |
Michiharu Ariza | c31092a | 2018-12-05 17:04:55 -0800 | [diff] [blame] | 118 | return_trace (likely (c->check_struct (this)) && c->check_range (&varStore, size) && varStore.sanitize (c)); |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 121 | bool serialize (hb_serialize_context_t *c, const CFF2VariationStore *varStore) |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 122 | { |
Michiharu Ariza | 693ae80 | 2018-08-02 11:22:42 -0700 | [diff] [blame] | 123 | TRACE_SERIALIZE (this); |
Michiharu Ariza | 16f4dc9 | 2018-08-01 16:06:52 -0700 | [diff] [blame] | 124 | unsigned int size_ = varStore->get_size (); |
| 125 | CFF2VariationStore *dest = c->allocate_size<CFF2VariationStore> (size_); |
Ebrahim Byagowi | 2be859d | 2020-04-20 23:48:23 +0430 | [diff] [blame] | 126 | if (unlikely (!dest)) return_trace (false); |
Behdad Esfahbod | 59c45f6 | 2022-11-22 12:54:50 -0700 | [diff] [blame] | 127 | hb_memcpy (dest, varStore, size_); |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 128 | return_trace (true); |
| 129 | } |
| 130 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 131 | unsigned int get_size () const { return HBUINT16::static_size + size; } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 132 | |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 133 | HBUINT16 size; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 134 | VariationStore varStore; |
| 135 | |
| 136 | DEFINE_SIZE_MIN (2 + VariationStore::min_size); |
| 137 | }; |
| 138 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 139 | struct cff2_top_dict_values_t : top_dict_values_t<> |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 140 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 141 | void init () |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 142 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 143 | top_dict_values_t<>::init (); |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 144 | vstoreOffset = 0; |
| 145 | FDSelectOffset = 0; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 146 | } |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 147 | void fini () { top_dict_values_t<>::fini (); } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 148 | |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 149 | unsigned int vstoreOffset; |
| 150 | unsigned int FDSelectOffset; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 153 | struct cff2_top_dict_opset_t : top_dict_opset_t<> |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 154 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 155 | static void process_op (op_code_t op, num_interp_env_t& env, cff2_top_dict_values_t& dictval) |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 156 | { |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 157 | switch (op) { |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 158 | case OpCode_FontMatrix: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 159 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 160 | dict_val_t val; |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 161 | val.init (); |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 162 | dictval.add_op (op, env.str_ref); |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 163 | env.clear_args (); |
| 164 | } |
| 165 | break; |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 166 | |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 167 | case OpCode_vstore: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 168 | dictval.vstoreOffset = env.argStack.pop_uint (); |
| 169 | env.clear_args (); |
| 170 | break; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 171 | case OpCode_FDSelect: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 172 | dictval.FDSelectOffset = env.argStack.pop_uint (); |
| 173 | env.clear_args (); |
| 174 | break; |
Behdad Esfahbod | 592f39b | 2018-11-30 22:54:57 -0500 | [diff] [blame] | 175 | |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 176 | default: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 177 | SUPER::process_op (op, env, dictval); |
| 178 | /* Record this operand below if stack is empty, otherwise done */ |
| 179 | if (!env.argStack.is_empty ()) return; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 180 | } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 181 | |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 182 | if (unlikely (env.in_error ())) return; |
| 183 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 184 | dictval.add_op (op, env.str_ref); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 185 | } |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 186 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 187 | typedef top_dict_opset_t<> SUPER; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 190 | struct cff2_font_dict_values_t : dict_values_t<op_str_t> |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 191 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 192 | void init () |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 193 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 194 | dict_values_t<op_str_t>::init (); |
ariza | 0b29053 | 2020-03-04 22:31:21 -0800 | [diff] [blame] | 195 | privateDictInfo.init (); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 196 | } |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 197 | void fini () { dict_values_t<op_str_t>::fini (); } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 198 | |
ariza | 0b29053 | 2020-03-04 22:31:21 -0800 | [diff] [blame] | 199 | table_info_t privateDictInfo; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 202 | struct cff2_font_dict_opset_t : dict_opset_t |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 203 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 204 | static void process_op (op_code_t op, num_interp_env_t& env, cff2_font_dict_values_t& dictval) |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 205 | { |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 206 | switch (op) { |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 207 | case OpCode_Private: |
ariza | 0b29053 | 2020-03-04 22:31:21 -0800 | [diff] [blame] | 208 | dictval.privateDictInfo.offset = env.argStack.pop_uint (); |
| 209 | dictval.privateDictInfo.size = env.argStack.pop_uint (); |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 210 | env.clear_args (); |
| 211 | break; |
Behdad Esfahbod | 592f39b | 2018-11-30 22:54:57 -0500 | [diff] [blame] | 212 | |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 213 | default: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 214 | SUPER::process_op (op, env); |
| 215 | if (!env.argStack.is_empty ()) |
| 216 | return; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 217 | } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 218 | |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 219 | if (unlikely (env.in_error ())) return; |
| 220 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 221 | dictval.add_op (op, env.str_ref); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 222 | } |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 223 | |
| 224 | private: |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 225 | typedef dict_opset_t SUPER; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 226 | }; |
| 227 | |
Michiharu Ariza | 00970dd | 2018-08-03 14:35:09 -0700 | [diff] [blame] | 228 | template <typename VAL> |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 229 | struct cff2_private_dict_values_base_t : dict_values_t<VAL> |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 230 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 231 | void init () |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 232 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 233 | dict_values_t<VAL>::init (); |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 234 | subrsOffset = 0; |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 235 | localSubrs = &Null (CFF2Subrs); |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 236 | ivs = 0; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 237 | } |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 238 | void fini () { dict_values_t<VAL>::fini (); } |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 239 | |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 240 | unsigned int subrsOffset; |
| 241 | const CFF2Subrs *localSubrs; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 242 | unsigned int ivs; |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 245 | typedef cff2_private_dict_values_base_t<op_str_t> cff2_private_dict_values_subset_t; |
| 246 | typedef cff2_private_dict_values_base_t<num_dict_val_t> cff2_private_dict_values_t; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 247 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 248 | struct cff2_priv_dict_interp_env_t : num_interp_env_t |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 249 | { |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 250 | cff2_priv_dict_interp_env_t (const hb_ubytes_t &str) : |
| 251 | num_interp_env_t (str) {} |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 252 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 253 | void process_vsindex () |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 254 | { |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 255 | if (likely (!seen_vsindex)) |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 256 | { |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 257 | set_ivs (argStack.pop_uint ()); |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 258 | } |
| 259 | seen_vsindex = true; |
| 260 | } |
| 261 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 262 | unsigned int get_ivs () const { return ivs; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 263 | void set_ivs (unsigned int ivs_) { ivs = ivs_; } |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 264 | |
| 265 | protected: |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 266 | unsigned int ivs = 0; |
| 267 | bool seen_vsindex = false; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 270 | struct cff2_private_dict_opset_t : dict_opset_t |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 271 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 272 | static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_private_dict_values_t& dictval) |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 273 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 274 | num_dict_val_t val; |
Michiharu Ariza | 00970dd | 2018-08-03 14:35:09 -0700 | [diff] [blame] | 275 | val.init (); |
| 276 | |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 277 | switch (op) { |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 278 | case OpCode_StdHW: |
| 279 | case OpCode_StdVW: |
| 280 | case OpCode_BlueScale: |
| 281 | case OpCode_BlueShift: |
| 282 | case OpCode_BlueFuzz: |
| 283 | case OpCode_ExpansionFactor: |
| 284 | case OpCode_LanguageGroup: |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 285 | case OpCode_BlueValues: |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 286 | case OpCode_OtherBlues: |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 287 | case OpCode_FamilyBlues: |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 288 | case OpCode_FamilyOtherBlues: |
Michiharu Ariza | 00970dd | 2018-08-03 14:35:09 -0700 | [diff] [blame] | 289 | case OpCode_StemSnapH: |
| 290 | case OpCode_StemSnapV: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 291 | env.clear_args (); |
| 292 | break; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 293 | case OpCode_Subrs: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 294 | dictval.subrsOffset = env.argStack.pop_uint (); |
| 295 | env.clear_args (); |
| 296 | break; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 297 | case OpCode_vsindexdict: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 298 | env.process_vsindex (); |
| 299 | dictval.ivs = env.get_ivs (); |
| 300 | env.clear_args (); |
| 301 | break; |
Michiharu Ariza | 633ce88 | 2018-08-15 12:00:19 -0700 | [diff] [blame] | 302 | case OpCode_blenddict: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 303 | break; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 304 | |
| 305 | default: |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 306 | dict_opset_t::process_op (op, env); |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 307 | if (!env.argStack.is_empty ()) return; |
| 308 | break; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 309 | } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 310 | |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 311 | if (unlikely (env.in_error ())) return; |
| 312 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 313 | dictval.add_op (op, env.str_ref, val); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 314 | } |
| 315 | }; |
| 316 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 317 | struct cff2_private_dict_opset_subset_t : dict_opset_t |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 318 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 319 | static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_private_dict_values_subset_t& dictval) |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 320 | { |
| 321 | switch (op) { |
| 322 | case OpCode_BlueValues: |
| 323 | case OpCode_OtherBlues: |
| 324 | case OpCode_FamilyBlues: |
| 325 | case OpCode_FamilyOtherBlues: |
| 326 | case OpCode_StdHW: |
| 327 | case OpCode_StdVW: |
| 328 | case OpCode_BlueScale: |
| 329 | case OpCode_BlueShift: |
| 330 | case OpCode_BlueFuzz: |
| 331 | case OpCode_StemSnapH: |
| 332 | case OpCode_StemSnapV: |
| 333 | case OpCode_LanguageGroup: |
| 334 | case OpCode_ExpansionFactor: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 335 | env.clear_args (); |
| 336 | break; |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 337 | |
Michiharu Ariza | 633ce88 | 2018-08-15 12:00:19 -0700 | [diff] [blame] | 338 | case OpCode_blenddict: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 339 | env.clear_args (); |
| 340 | return; |
Michiharu Ariza | 00970dd | 2018-08-03 14:35:09 -0700 | [diff] [blame] | 341 | |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 342 | case OpCode_Subrs: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 343 | dictval.subrsOffset = env.argStack.pop_uint (); |
| 344 | env.clear_args (); |
| 345 | break; |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 346 | |
| 347 | default: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 348 | SUPER::process_op (op, env); |
| 349 | if (!env.argStack.is_empty ()) return; |
| 350 | break; |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 353 | if (unlikely (env.in_error ())) return; |
| 354 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 355 | dictval.add_op (op, env.str_ref); |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 356 | } |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 357 | |
| 358 | private: |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 359 | typedef dict_opset_t SUPER; |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 362 | typedef dict_interpreter_t<cff2_top_dict_opset_t, cff2_top_dict_values_t> cff2_top_dict_interpreter_t; |
| 363 | typedef dict_interpreter_t<cff2_font_dict_opset_t, cff2_font_dict_values_t> cff2_font_dict_interpreter_t; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 364 | |
ariza | c05458e | 2020-03-02 16:51:19 -0800 | [diff] [blame] | 365 | struct CFF2FDArray : FDArray<HBUINT32> |
| 366 | { |
| 367 | /* FDArray::serialize does not compile without this partial specialization */ |
| 368 | template <typename ITER, typename OP_SERIALIZER> |
| 369 | bool serialize (hb_serialize_context_t *c, ITER it, OP_SERIALIZER& opszr) |
| 370 | { return FDArray<HBUINT32>::serialize<cff2_font_dict_values_t, table_info_t> (c, it, opszr); } |
| 371 | }; |
| 372 | |
Behdad Esfahbod | d25a2f1 | 2018-12-23 20:19:52 -0500 | [diff] [blame] | 373 | } /* namespace CFF */ |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 374 | |
| 375 | namespace OT { |
| 376 | |
| 377 | using namespace CFF; |
| 378 | |
| 379 | struct cff2 |
| 380 | { |
Khaled Hosny | b6516f3 | 2023-05-08 15:31:24 +0300 | [diff] [blame] | 381 | static constexpr hb_tag_t tableTag = HB_OT_TAG_CFF2; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 382 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 383 | bool sanitize (hb_sanitize_context_t *c) const |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 384 | { |
| 385 | TRACE_SANITIZE (this); |
| 386 | return_trace (c->check_struct (this) && |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 387 | likely (version.major == 2)); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 390 | template <typename PRIVOPSET, typename PRIVDICTVAL> |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 391 | struct accelerator_templ_t |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 392 | { |
Behdad Esfahbod | 557653a | 2023-07-09 10:18:04 -0600 | [diff] [blame] | 393 | static constexpr hb_tag_t tableTag = cff2::tableTag; |
| 394 | |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 395 | accelerator_templ_t (hb_face_t *face) |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 396 | { |
Behdad Esfahbod | c4b2950 | 2023-06-23 11:55:39 -0600 | [diff] [blame] | 397 | if (!face) return; |
| 398 | |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 399 | topDict.init (); |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 400 | fontDicts.init (); |
| 401 | privateDicts.init (); |
Behdad Esfahbod | 592f39b | 2018-11-30 22:54:57 -0500 | [diff] [blame] | 402 | |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 403 | this->blob = sc.reference_table<cff2> (face); |
| 404 | |
| 405 | /* setup for run-time santization */ |
| 406 | sc.init (this->blob); |
| 407 | sc.start_processing (); |
Behdad Esfahbod | 592f39b | 2018-11-30 22:54:57 -0500 | [diff] [blame] | 408 | |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 409 | const OT::cff2 *cff2 = this->blob->template as<OT::cff2> (); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 410 | |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 411 | if (cff2 == &Null (OT::cff2)) |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 412 | goto fail; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 413 | |
| 414 | { /* parse top dict */ |
Behdad Esfahbod | 8aa54aa | 2022-05-09 16:09:56 -0600 | [diff] [blame] | 415 | hb_ubytes_t topDictStr = (cff2 + cff2->topDict).as_ubytes (cff2->topDictSize); |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 416 | if (unlikely (!topDictStr.sanitize (&sc))) goto fail; |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 417 | num_interp_env_t env (topDictStr); |
| 418 | cff2_top_dict_interpreter_t top_interp (env); |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 419 | topDict.init (); |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 420 | if (unlikely (!top_interp.interpret (topDict))) goto fail; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 421 | } |
Behdad Esfahbod | 592f39b | 2018-11-30 22:54:57 -0500 | [diff] [blame] | 422 | |
Michiharu Ariza | 64c5412 | 2018-08-10 11:07:07 -0700 | [diff] [blame] | 423 | globalSubrs = &StructAtOffset<CFF2Subrs> (cff2, cff2->topDict + cff2->topDictSize); |
| 424 | varStore = &StructAtOffsetOrNull<CFF2VariationStore> (cff2, topDict.vstoreOffset); |
| 425 | charStrings = &StructAtOffsetOrNull<CFF2CharStrings> (cff2, topDict.charStringsOffset); |
| 426 | fdArray = &StructAtOffsetOrNull<CFF2FDArray> (cff2, topDict.FDArrayOffset); |
| 427 | fdSelect = &StructAtOffsetOrNull<CFF2FDSelect> (cff2, topDict.FDSelectOffset); |
Behdad Esfahbod | 592f39b | 2018-11-30 22:54:57 -0500 | [diff] [blame] | 428 | |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 429 | if (((varStore != &Null (CFF2VariationStore)) && unlikely (!varStore->sanitize (&sc))) || |
| 430 | (charStrings == &Null (CFF2CharStrings)) || unlikely (!charStrings->sanitize (&sc)) || |
| 431 | (globalSubrs == &Null (CFF2Subrs)) || unlikely (!globalSubrs->sanitize (&sc)) || |
| 432 | (fdArray == &Null (CFF2FDArray)) || unlikely (!fdArray->sanitize (&sc)) || |
| 433 | (((fdSelect != &Null (CFF2FDSelect)) && unlikely (!fdSelect->sanitize (&sc, fdArray->count))))) |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 434 | goto fail; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 435 | |
| 436 | num_glyphs = charStrings->count; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 437 | if (num_glyphs != sc.get_num_glyphs ()) |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 438 | goto fail; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 439 | |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 440 | fdCount = fdArray->count; |
Garret Rieger | 7f358a5 | 2020-07-30 13:57:30 -0700 | [diff] [blame] | 441 | if (!privateDicts.resize (fdCount)) |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 442 | goto fail; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 443 | |
Michiharu Ariza | 633ce88 | 2018-08-15 12:00:19 -0700 | [diff] [blame] | 444 | /* parse font dicts and gather private dicts */ |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 445 | for (unsigned int i = 0; i < fdCount; i++) |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 446 | { |
Behdad Esfahbod | 8aa54aa | 2022-05-09 16:09:56 -0600 | [diff] [blame] | 447 | const hb_ubytes_t fontDictStr = (*fdArray)[i]; |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 448 | if (unlikely (!fontDictStr.sanitize (&sc))) goto fail; |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 449 | cff2_font_dict_values_t *font; |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 450 | num_interp_env_t env (fontDictStr); |
| 451 | cff2_font_dict_interpreter_t font_interp (env); |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 452 | font = fontDicts.push (); |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 453 | if (unlikely (font == &Crap (cff2_font_dict_values_t))) goto fail; |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 454 | font->init (); |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 455 | if (unlikely (!font_interp.interpret (*font))) goto fail; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 456 | |
Behdad Esfahbod | 8aa54aa | 2022-05-09 16:09:56 -0600 | [diff] [blame] | 457 | const hb_ubytes_t privDictStr = StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset).as_ubytes (font->privateDictInfo.size); |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 458 | if (unlikely (!privDictStr.sanitize (&sc))) goto fail; |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 459 | cff2_priv_dict_interp_env_t env2 (privDictStr); |
| 460 | dict_interpreter_t<PRIVOPSET, PRIVDICTVAL, cff2_priv_dict_interp_env_t> priv_interp (env2); |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 461 | privateDicts[i].init (); |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 462 | if (unlikely (!priv_interp.interpret (privateDicts[i]))) goto fail; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 463 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 464 | privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (&privDictStr[0], privateDicts[i].subrsOffset); |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 465 | if (privateDicts[i].localSubrs != &Null (CFF2Subrs) && |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 466 | unlikely (!privateDicts[i].localSubrs->sanitize (&sc))) |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 467 | goto fail; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 468 | } |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 469 | |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 470 | return; |
| 471 | |
| 472 | fail: |
| 473 | _fini (); |
| 474 | } |
| 475 | ~accelerator_templ_t () { _fini (); } |
| 476 | void _fini () |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 477 | { |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 478 | sc.end_processing (); |
Michiharu Ariza | 09fa536 | 2018-12-27 08:33:09 -0800 | [diff] [blame] | 479 | topDict.fini (); |
Behdad Esfahbod | 4eb6e6e | 2022-01-18 12:07:05 -0700 | [diff] [blame] | 480 | fontDicts.fini (); |
| 481 | privateDicts.fini (); |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 482 | hb_blob_destroy (blob); |
Michiharu Ariza | 9c4cada | 2018-07-30 14:28:40 -0700 | [diff] [blame] | 483 | blob = nullptr; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Behdad Esfahbod | ffc6899 | 2023-06-05 14:16:47 -0600 | [diff] [blame] | 486 | hb_vector_t<uint16_t> *create_glyph_to_sid_map () const |
Behdad Esfahbod | 32dd981 | 2022-11-30 13:15:58 -0700 | [diff] [blame] | 487 | { |
| 488 | return nullptr; |
| 489 | } |
| 490 | |
Behdad Esfahbod | 43ec78f | 2023-06-23 10:22:30 -0600 | [diff] [blame] | 491 | hb_blob_t *get_blob () const { return blob; } |
| 492 | |
Ebrahim Byagowi | 2be859d | 2020-04-20 23:48:23 +0430 | [diff] [blame] | 493 | bool is_valid () const { return blob; } |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 494 | |
Michiharu Ariza | 58279c3 | 2018-08-02 10:18:01 -0700 | [diff] [blame] | 495 | protected: |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 496 | hb_sanitize_context_t sc; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 497 | |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 498 | public: |
Garret Rieger | 8d5c899 | 2022-11-25 20:33:39 +0000 | [diff] [blame] | 499 | hb_blob_t *blob = nullptr; |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 500 | cff2_top_dict_values_t topDict; |
Behdad Esfahbod | a8b7f18 | 2022-01-21 07:38:33 -0700 | [diff] [blame] | 501 | const CFF2Subrs *globalSubrs = nullptr; |
| 502 | const CFF2VariationStore *varStore = nullptr; |
| 503 | const CFF2CharStrings *charStrings = nullptr; |
| 504 | const CFF2FDArray *fdArray = nullptr; |
| 505 | const CFF2FDSelect *fdSelect = nullptr; |
| 506 | unsigned int fdCount = 0; |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 507 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 508 | hb_vector_t<cff2_font_dict_values_t> fontDicts; |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 509 | hb_vector_t<PRIVDICTVAL> privateDicts; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 510 | |
Behdad Esfahbod | a8b7f18 | 2022-01-21 07:38:33 -0700 | [diff] [blame] | 511 | unsigned int num_glyphs = 0; |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 512 | }; |
| 513 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 514 | struct accelerator_t : accelerator_templ_t<cff2_private_dict_opset_t, cff2_private_dict_values_t> |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 515 | { |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 516 | accelerator_t (hb_face_t *face) : accelerator_templ_t (face) {} |
| 517 | |
Michiharu Ariza | 2840a10 | 2018-11-01 16:18:13 -0700 | [diff] [blame] | 518 | HB_INTERNAL bool get_extents (hb_font_t *font, |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 519 | hb_codepoint_t glyph, |
| 520 | hb_glyph_extents_t *extents) const; |
Matthias Clasen | 9be01b6 | 2022-12-21 14:04:32 -0500 | [diff] [blame] | 521 | HB_INTERNAL bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const; |
Behdad Esfahbod | 370bec9 | 2022-02-04 18:40:44 -0600 | [diff] [blame] | 522 | HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 523 | }; |
| 524 | |
Behdad Esfahbod | 43ec78f | 2023-06-23 10:22:30 -0600 | [diff] [blame] | 525 | struct accelerator_subset_t : accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> |
| 526 | { |
| 527 | accelerator_subset_t (hb_face_t *face) : SUPER (face) {} |
Behdad Esfahbod | 5f39913 | 2023-06-23 11:22:01 -0600 | [diff] [blame] | 528 | ~accelerator_subset_t () |
| 529 | { |
| 530 | if (cff_accelerator) |
| 531 | cff_subset_accelerator_t::destroy (cff_accelerator); |
| 532 | } |
Behdad Esfahbod | 43ec78f | 2023-06-23 10:22:30 -0600 | [diff] [blame] | 533 | |
| 534 | HB_INTERNAL bool subset (hb_subset_context_t *c) const; |
Behdad Esfahbod | 97d63e8 | 2023-06-23 10:43:34 -0600 | [diff] [blame] | 535 | HB_INTERNAL bool serialize (hb_serialize_context_t *c, |
| 536 | struct cff2_subset_plan &plan, |
| 537 | hb_array_t<int> normalized_coords) const; |
Behdad Esfahbod | 43ec78f | 2023-06-23 10:22:30 -0600 | [diff] [blame] | 538 | |
Behdad Esfahbod | 5f39913 | 2023-06-23 11:22:01 -0600 | [diff] [blame] | 539 | mutable CFF::cff_subset_accelerator_t* cff_accelerator = nullptr; |
| 540 | |
Behdad Esfahbod | 43ec78f | 2023-06-23 10:22:30 -0600 | [diff] [blame] | 541 | typedef accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> SUPER; |
| 542 | }; |
Michiharu Ariza | 76f7397 | 2018-08-02 16:28:10 -0700 | [diff] [blame] | 543 | |
Michiharu Ariza | b2ff582 | 2018-08-01 11:30:38 -0700 | [diff] [blame] | 544 | public: |
Behdad Esfahbod | b1152d5 | 2019-01-17 18:17:04 -0500 | [diff] [blame] | 545 | FixedVersion<HBUINT8> version; /* Version of CFF2 table. set to 0x0200u */ |
| 546 | NNOffsetTo<TopDict, HBUINT8> topDict; /* headerSize = Offset to Top DICT. */ |
| 547 | HBUINT16 topDictSize; /* Top DICT size */ |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 548 | |
| 549 | public: |
| 550 | DEFINE_SIZE_STATIC (5); |
| 551 | }; |
| 552 | |
Behdad Esfahbod | ac1bb3e | 2022-01-20 11:47:17 -0700 | [diff] [blame] | 553 | struct cff2_accelerator_t : cff2::accelerator_t { |
| 554 | cff2_accelerator_t (hb_face_t *face) : cff2::accelerator_t (face) {} |
| 555 | }; |
| 556 | |
Behdad Esfahbod | 43ec78f | 2023-06-23 10:22:30 -0600 | [diff] [blame] | 557 | struct cff2_subset_accelerator_t : cff2::accelerator_subset_t { |
| 558 | cff2_subset_accelerator_t (hb_face_t *face) : cff2::accelerator_subset_t (face) {} |
| 559 | }; |
| 560 | |
Michiharu Ariza | 3a61c3e | 2018-07-18 14:17:52 -0700 | [diff] [blame] | 561 | } /* namespace OT */ |
| 562 | |
| 563 | #endif /* HB_OT_CFF2_TABLE_HH */ |