Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 1 | /* |
Michiharu Ariza | 0dfa584 | 2018-11-12 08:47:07 -0800 | [diff] [blame] | 2 | * Copyright © 2018 Adobe Inc. |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -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 | #ifndef HB_CFF2_INTERP_CS_HH |
| 27 | #define HB_CFF2_INTERP_CS_HH |
| 28 | |
Michiharu Ariza | 8af9690 | 2018-08-29 13:26:17 -0700 | [diff] [blame] | 29 | #include "hb.hh" |
| 30 | #include "hb-cff-interp-cs-common.hh" |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 31 | |
| 32 | namespace CFF { |
| 33 | |
| 34 | using namespace OT; |
| 35 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 36 | struct blend_arg_t : number_t |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 37 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 38 | void set_int (int v) { reset_blends (); number_t::set_int (v); } |
| 39 | void set_fixed (int32_t v) { reset_blends (); number_t::set_fixed (v); } |
Behdad Esfahbod | cb320d2 | 2023-07-27 10:43:07 -0600 | [diff] [blame] | 40 | void set_real (double v) { reset_blends (); number_t::set_real (v); } |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 41 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 42 | void set_blends (unsigned int numValues_, unsigned int valueIndex_, |
Behdad Esfahbod | 70d97d0 | 2022-11-26 15:16:11 -0700 | [diff] [blame] | 43 | hb_array_t<const blend_arg_t> blends_) |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 44 | { |
| 45 | numValues = numValues_; |
| 46 | valueIndex = valueIndex_; |
Behdad Esfahbod | 70d97d0 | 2022-11-26 15:16:11 -0700 | [diff] [blame] | 47 | unsigned numBlends = blends_.length; |
Behdad Esfahbod | 8f2345c | 2023-01-02 18:08:45 -0700 | [diff] [blame] | 48 | if (unlikely (!deltas.resize_exact (numBlends))) |
Behdad Esfahbod | 4167e93 | 2022-11-26 15:14:52 -0700 | [diff] [blame] | 49 | return; |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 50 | for (unsigned int i = 0; i < numBlends; i++) |
Behdad Esfahbod | 4167e93 | 2022-11-26 15:14:52 -0700 | [diff] [blame] | 51 | deltas.arrayZ[i] = blends_.arrayZ[i]; |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Behdad Esfahbod | 474a120 | 2018-12-21 18:46:51 -0500 | [diff] [blame] | 54 | bool blending () const { return deltas.length > 0; } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 55 | void reset_blends () |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 56 | { |
| 57 | numValues = valueIndex = 0; |
Behdad Esfahbod | b1c4cb0 | 2023-01-01 18:41:19 -0700 | [diff] [blame] | 58 | deltas.shrink (0); |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | unsigned int numValues; |
| 62 | unsigned int valueIndex; |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 63 | hb_vector_t<number_t> deltas; |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 66 | typedef biased_subrs_t<CFF2Subrs> cff2_biased_subrs_t; |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 67 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 68 | template <typename ELEM> |
| 69 | struct cff2_cs_interp_env_t : cs_interp_env_t<ELEM, CFF2Subrs> |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 70 | { |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 71 | template <typename ACC> |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 72 | cff2_cs_interp_env_t (const hb_ubytes_t &str, ACC &acc, unsigned int fd, |
| 73 | const int *coords_=nullptr, unsigned int num_coords_=0) |
| 74 | : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs) |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 75 | { |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 76 | coords = coords_; |
Michiharu Ariza | df964a0 | 2018-10-08 15:38:05 -0700 | [diff] [blame] | 77 | num_coords = num_coords_; |
| 78 | varStore = acc.varStore; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 79 | seen_blend = false; |
Michiharu Ariza | 0996c0f | 2018-11-07 14:48:37 -0800 | [diff] [blame] | 80 | seen_vsindex_ = false; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 81 | scalars.init (); |
Ebrahim Byagowi | 2be859d | 2020-04-20 23:48:23 +0430 | [diff] [blame] | 82 | do_blend = num_coords && coords && varStore->size; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 83 | set_ivs (acc.privateDicts[fd].ivs); |
| 84 | } |
| 85 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 86 | void fini () |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 87 | { |
| 88 | scalars.fini (); |
| 89 | SUPER::fini (); |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 92 | op_code_t fetch_op () |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 93 | { |
Michiharu Ariza | 29f0b6b | 2018-12-22 07:47:04 -0800 | [diff] [blame] | 94 | if (this->str_ref.avail ()) |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 95 | return SUPER::fetch_op (); |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 96 | |
| 97 | /* make up return or endchar op */ |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 98 | if (this->callStack.is_empty ()) |
| 99 | return OpCode_endchar; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 100 | else |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 101 | return OpCode_return; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 104 | const ELEM& eval_arg (unsigned int i) |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 105 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 106 | return SUPER::argStack[i]; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 109 | const ELEM& pop_arg () |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 110 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 111 | return SUPER::argStack.pop (); |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 114 | void process_blend () |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 115 | { |
| 116 | if (!seen_blend) |
| 117 | { |
| 118 | region_count = varStore->varStore.get_region_index_count (get_ivs ()); |
| 119 | if (do_blend) |
| 120 | { |
Behdad Esfahbod | 8f2345c | 2023-01-02 18:08:45 -0700 | [diff] [blame] | 121 | if (unlikely (!scalars.resize_exact (region_count))) |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 122 | SUPER::set_error (); |
Ebrahim Byagowi | efd716d | 2020-07-31 08:58:53 +0430 | [diff] [blame] | 123 | else |
Behdad Esfahbod | ff1fe25 | 2021-07-28 18:02:52 -0600 | [diff] [blame] | 124 | varStore->varStore.get_region_scalars (get_ivs (), coords, num_coords, |
| 125 | &scalars[0], region_count); |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 126 | } |
| 127 | seen_blend = true; |
| 128 | } |
| 129 | } |
| 130 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 131 | void process_vsindex () |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 132 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 133 | unsigned int index = SUPER::argStack.pop_uint (); |
Michiharu Ariza | 0996c0f | 2018-11-07 14:48:37 -0800 | [diff] [blame] | 134 | if (unlikely (seen_vsindex () || seen_blend)) |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 135 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 136 | SUPER::set_error (); |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 137 | } |
Michiharu Ariza | 0996c0f | 2018-11-07 14:48:37 -0800 | [diff] [blame] | 138 | else |
| 139 | { |
| 140 | set_ivs (index); |
| 141 | } |
| 142 | seen_vsindex_ = true; |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 145 | unsigned int get_region_count () const { return region_count; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 146 | void set_region_count (unsigned int region_count_) { region_count = region_count_; } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 147 | unsigned int get_ivs () const { return ivs; } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 148 | void set_ivs (unsigned int ivs_) { ivs = ivs_; } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 149 | bool seen_vsindex () const { return seen_vsindex_; } |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 150 | |
Behdad Esfahbod | cb320d2 | 2023-07-27 10:43:07 -0600 | [diff] [blame] | 151 | double blend_deltas (hb_array_t<const ELEM> deltas) const |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 152 | { |
Behdad Esfahbod | cb320d2 | 2023-07-27 10:43:07 -0600 | [diff] [blame] | 153 | double v = 0; |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 154 | if (do_blend) |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 155 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 156 | if (likely (scalars.length == deltas.length)) |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 157 | { |
Behdad Esfahbod | f159bf0 | 2022-11-26 15:11:32 -0700 | [diff] [blame] | 158 | unsigned count = scalars.length; |
| 159 | for (unsigned i = 0; i < count; i++) |
Behdad Esfahbod | cb320d2 | 2023-07-27 10:43:07 -0600 | [diff] [blame] | 160 | v += (double) scalars.arrayZ[i] * deltas.arrayZ[i].to_real (); |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 163 | return v; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Behdad Esfahbod | 76879c5 | 2023-01-06 11:47:04 -0700 | [diff] [blame] | 166 | bool have_coords () const { return num_coords; } |
| 167 | |
| 168 | protected: |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 169 | const int *coords; |
| 170 | unsigned int num_coords; |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 171 | const CFF2VariationStore *varStore; |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 172 | unsigned int region_count; |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 173 | unsigned int ivs; |
| 174 | hb_vector_t<float> scalars; |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 175 | bool do_blend; |
| 176 | bool seen_vsindex_; |
| 177 | bool seen_blend; |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 178 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 179 | typedef cs_interp_env_t<ELEM, CFF2Subrs> SUPER; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 180 | }; |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 181 | template <typename OPSET, typename PARAM, typename ELEM, typename PATH=path_procs_null_t<cff2_cs_interp_env_t<ELEM>, PARAM>> |
| 182 | struct cff2_cs_opset_t : cs_opset_t<ELEM, OPSET, cff2_cs_interp_env_t<ELEM>, PARAM, PATH> |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 183 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 184 | static void process_op (op_code_t op, cff2_cs_interp_env_t<ELEM> &env, PARAM& param) |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 185 | { |
| 186 | switch (op) { |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 187 | case OpCode_callsubr: |
| 188 | case OpCode_callgsubr: |
luz paz | e2e3050 | 2022-01-16 07:00:53 -0500 | [diff] [blame] | 189 | /* a subroutine number shouldn't be a blended value */ |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 190 | #if 0 |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 191 | if (unlikely (env.argStack.peek ().blending ())) |
| 192 | { |
| 193 | env.set_error (); |
| 194 | break; |
| 195 | } |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 196 | #endif |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 197 | SUPER::process_op (op, env, param); |
| 198 | break; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 199 | |
| 200 | case OpCode_blendcs: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 201 | OPSET::process_blend (env, param); |
| 202 | break; |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 203 | |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 204 | case OpCode_vsindexcs: |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 205 | #if 0 |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 206 | if (unlikely (env.argStack.peek ().blending ())) |
| 207 | { |
| 208 | env.set_error (); |
| 209 | break; |
| 210 | } |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 211 | #endif |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 212 | OPSET::process_vsindex (env, param); |
| 213 | break; |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 214 | |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 215 | default: |
Behdad Esfahbod | 825df6d | 2018-11-30 23:04:59 -0500 | [diff] [blame] | 216 | SUPER::process_op (op, env, param); |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 217 | } |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 218 | } |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 219 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 220 | template <typename T = ELEM, |
| 221 | hb_enable_if (hb_is_same (T, blend_arg_t))> |
| 222 | static void process_arg_blend (cff2_cs_interp_env_t<ELEM> &env, |
| 223 | ELEM &arg, |
| 224 | const hb_array_t<const ELEM> blends, |
| 225 | unsigned n, unsigned i) |
| 226 | { |
Behdad Esfahbod | 76879c5 | 2023-01-06 11:47:04 -0700 | [diff] [blame] | 227 | if (env.have_coords ()) |
Behdad Esfahbod | 4867e0b | 2023-01-06 11:39:13 -0700 | [diff] [blame] | 228 | arg.set_int (round (arg.to_real () + env.blend_deltas (blends))); |
| 229 | else |
| 230 | arg.set_blends (n, i, blends); |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 231 | } |
| 232 | template <typename T = ELEM, |
| 233 | hb_enable_if (!hb_is_same (T, blend_arg_t))> |
| 234 | static void process_arg_blend (cff2_cs_interp_env_t<ELEM> &env, |
| 235 | ELEM &arg, |
| 236 | const hb_array_t<const ELEM> blends, |
| 237 | unsigned n, unsigned i) |
| 238 | { |
Behdad Esfahbod | 576b36a | 2023-01-06 11:40:21 -0700 | [diff] [blame] | 239 | arg.set_real (arg.to_real () + env.blend_deltas (blends)); |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static void process_blend (cff2_cs_interp_env_t<ELEM> &env, PARAM& param) |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 243 | { |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 244 | unsigned int n, k; |
| 245 | |
Michiharu Ariza | b51418f | 2018-10-08 15:05:36 -0700 | [diff] [blame] | 246 | env.process_blend (); |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 247 | k = env.get_region_count (); |
Michiharu Ariza | 7d99a6c | 2018-10-12 02:16:07 -0700 | [diff] [blame] | 248 | n = env.argStack.pop_uint (); |
Michiharu Ariza | 59345cd | 2018-12-06 13:36:26 -0800 | [diff] [blame] | 249 | /* copy the blend values into blend array of the default values */ |
| 250 | unsigned int start = env.argStack.get_count () - ((k+1) * n); |
| 251 | /* let an obvious error case fail, but note CFF2 spec doesn't forbid n==0 */ |
| 252 | if (unlikely (start > env.argStack.get_count ())) |
Michiharu Ariza | 14d29a1 | 2018-12-05 21:33:29 -0800 | [diff] [blame] | 253 | { |
| 254 | env.set_error (); |
| 255 | return; |
| 256 | } |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 257 | for (unsigned int i = 0; i < n; i++) |
Michiharu Ariza | 59345cd | 2018-12-06 13:36:26 -0800 | [diff] [blame] | 258 | { |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 259 | const hb_array_t<const ELEM> blends = env.argStack.sub_array (start + n + (i * k), k); |
| 260 | process_arg_blend (env, env.argStack[start + i], blends, n, i); |
Michiharu Ariza | 59345cd | 2018-12-06 13:36:26 -0800 | [diff] [blame] | 261 | } |
Michiharu Ariza | f2d299b | 2018-09-04 10:25:21 -0700 | [diff] [blame] | 262 | |
| 263 | /* pop off blend values leaving default values now adorned with blend values */ |
Michiharu Ariza | c0c85b8 | 2018-09-17 11:14:56 -0700 | [diff] [blame] | 264 | env.argStack.pop (k * n); |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 267 | static void process_vsindex (cff2_cs_interp_env_t<ELEM> &env, PARAM& param) |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 268 | { |
Michiharu Ariza | 968168b | 2018-08-31 13:28:16 -0700 | [diff] [blame] | 269 | env.process_vsindex (); |
Michiharu Ariza | ae8fd0d | 2018-11-07 09:16:12 -0800 | [diff] [blame] | 270 | env.clear_args (); |
Michiharu Ariza | 9fd08cc | 2018-08-29 18:18:18 -0700 | [diff] [blame] | 271 | } |
Michiharu Ariza | fcf1778 | 2018-08-31 16:28:47 -0700 | [diff] [blame] | 272 | |
| 273 | private: |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 274 | typedef cs_opset_t<ELEM, OPSET, cff2_cs_interp_env_t<ELEM>, PARAM, PATH> SUPER; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
Behdad Esfahbod | 0a42410 | 2022-05-10 12:05:19 -0600 | [diff] [blame] | 277 | template <typename OPSET, typename PARAM, typename ELEM> |
Behdad Esfahbod | bff78e6 | 2022-05-10 16:33:37 -0600 | [diff] [blame] | 278 | using cff2_cs_interpreter_t = cs_interpreter_t<cff2_cs_interp_env_t<ELEM>, OPSET, PARAM>; |
Michiharu Ariza | cef75ea | 2018-08-17 13:13:18 -0700 | [diff] [blame] | 279 | |
| 280 | } /* namespace CFF */ |
| 281 | |
| 282 | #endif /* HB_CFF2_INTERP_CS_HH */ |