blob: d8868efa53f9cf95810aca7dd8c8e052e645dc3b [file] [log] [blame]
Michiharu Ariza633ce882018-08-15 12:00:19 -07001/*
Michiharu Ariza0dfa5842018-11-12 08:47:07 -08002 * Copyright © 2018 Adobe Inc.
Michiharu Ariza633ce882018-08-15 12:00:19 -07003 *
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 */
Michiharu Arizafdbfa182018-08-16 00:13:09 -070026#ifndef HB_CFF1_INTERP_CS_HH
27#define HB_CFF1_INTERP_CS_HH
Michiharu Ariza633ce882018-08-15 12:00:19 -070028
Michiharu Ariza8af96902018-08-29 13:26:17 -070029#include "hb.hh"
30#include "hb-cff-interp-cs-common.hh"
Michiharu Ariza633ce882018-08-15 12:00:19 -070031
32namespace CFF {
33
34using namespace OT;
35
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -080036typedef biased_subrs_t<CFF1Subrs> cff1_biased_subrs_t;
Michiharu Arizad56e3382018-10-31 22:30:34 -070037
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -080038struct cff1_cs_interp_env_t : cs_interp_env_t<number_t, CFF1Subrs>
Michiharu Ariza633ce882018-08-15 12:00:19 -070039{
Michiharu Arizaf2d299b2018-09-04 10:25:21 -070040 template <typename ACC>
Behdad Esfahbodc632a162023-01-06 11:01:25 -070041 cff1_cs_interp_env_t (const hb_ubytes_t &str, ACC &acc, unsigned int fd,
42 const int *coords_=nullptr, unsigned int num_coords_=0)
Behdad Esfahbodbff78e62022-05-10 16:33:37 -060043 : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs)
Michiharu Ariza633ce882018-08-15 12:00:19 -070044 {
Michiharu Arizaa11420b2018-08-29 12:14:30 -070045 processed_width = false;
46 has_width = false;
Michiharu Arizad56e3382018-10-31 22:30:34 -070047 arg_start = 0;
Michiharu Ariza13735572018-11-15 12:10:23 -080048 in_seac = false;
Michiharu Ariza633ce882018-08-15 12:00:19 -070049 }
50
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033051 void set_width (bool has_width_)
Michiharu Ariza633ce882018-08-15 12:00:19 -070052 {
Michiharu Arizad56e3382018-10-31 22:30:34 -070053 if (likely (!processed_width && (SUPER::argStack.get_count () > 0)))
Michiharu Ariza633ce882018-08-15 12:00:19 -070054 {
Michiharu Ariza049ce072018-11-01 08:46:21 -070055 if (has_width_)
56 {
Behdad Esfahbod825df6d2018-11-30 23:04:59 -050057 width = SUPER::argStack[0];
58 has_width = true;
59 arg_start = 1;
Michiharu Ariza049ce072018-11-01 08:46:21 -070060 }
Michiharu Ariza633ce882018-08-15 12:00:19 -070061 }
Michiharu Ariza049ce072018-11-01 08:46:21 -070062 processed_width = true;
Michiharu Arizad56e3382018-10-31 22:30:34 -070063 }
64
Ebrahim Byagowie4120082018-12-17 21:31:01 +033065 void clear_args ()
Michiharu Arizad56e3382018-10-31 22:30:34 -070066 {
67 arg_start = 0;
68 SUPER::clear_args ();
Michiharu Ariza633ce882018-08-15 12:00:19 -070069 }
70
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +033071 void set_in_seac (bool _in_seac) { in_seac = _in_seac; }
Michiharu Ariza13735572018-11-15 12:10:23 -080072
Behdad Esfahbod825df6d2018-11-30 23:04:59 -050073 bool processed_width;
74 bool has_width;
Michiharu Arizad56e3382018-10-31 22:30:34 -070075 unsigned int arg_start;
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -080076 number_t width;
Behdad Esfahbod825df6d2018-11-30 23:04:59 -050077 bool in_seac;
Michiharu Ariza633ce882018-08-15 12:00:19 -070078
Michiharu Arizafcf17782018-08-31 16:28:47 -070079 private:
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -080080 typedef cs_interp_env_t<number_t, CFF1Subrs> SUPER;
Michiharu Ariza633ce882018-08-15 12:00:19 -070081};
82
Ebrahim Byagowi92588782019-04-30 13:05:10 -070083template <typename OPSET, typename PARAM, typename PATH=path_procs_null_t<cff1_cs_interp_env_t, PARAM>>
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -080084struct cff1_cs_opset_t : cs_opset_t<number_t, OPSET, cff1_cs_interp_env_t, PARAM, PATH>
Michiharu Ariza633ce882018-08-15 12:00:19 -070085{
Michiharu Arizabe746002018-10-25 13:40:40 -070086 /* PostScript-originated legacy opcodes (OpCode_add etc) are unsupported */
Michiharu Ariza3787c072018-11-14 13:38:03 -080087 /* Type 1-originated deprecated opcodes, seac behavior of endchar and dotsection are supported */
88
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -080089 static void process_op (op_code_t op, cff1_cs_interp_env_t &env, PARAM& param)
Michiharu Ariza3787c072018-11-14 13:38:03 -080090 {
91 switch (op) {
92 case OpCode_dotsection:
Behdad Esfahbod825df6d2018-11-30 23:04:59 -050093 SUPER::flush_args_and_op (op, env, param);
94 break;
Michiharu Ariza3787c072018-11-14 13:38:03 -080095
96 case OpCode_endchar:
Behdad Esfahbod825df6d2018-11-30 23:04:59 -050097 OPSET::check_width (op, env, param);
98 if (env.argStack.get_count () >= 4)
99 {
100 OPSET::process_seac (env, param);
101 }
102 OPSET::flush_args_and_op (op, env, param);
103 env.set_endchar (true);
104 break;
Michiharu Ariza3787c072018-11-14 13:38:03 -0800105
106 default:
Behdad Esfahbod825df6d2018-11-30 23:04:59 -0500107 SUPER::process_op (op, env, param);
Michiharu Ariza3787c072018-11-14 13:38:03 -0800108 }
109 }
Michiharu Arizaa11420b2018-08-29 12:14:30 -0700110
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -0800111 static void check_width (op_code_t op, cff1_cs_interp_env_t &env, PARAM& param)
Michiharu Arizaa11420b2018-08-29 12:14:30 -0700112 {
Michiharu Arizad56e3382018-10-31 22:30:34 -0700113 if (!env.processed_width)
114 {
115 bool has_width = false;
116 switch (op)
117 {
Behdad Esfahbod825df6d2018-11-30 23:04:59 -0500118 case OpCode_endchar:
119 case OpCode_hstem:
120 case OpCode_hstemhm:
121 case OpCode_vstem:
122 case OpCode_vstemhm:
123 case OpCode_hintmask:
124 case OpCode_cntrmask:
125 has_width = ((env.argStack.get_count () & 1) != 0);
126 break;
127 case OpCode_hmoveto:
128 case OpCode_vmoveto:
129 has_width = (env.argStack.get_count () > 1);
130 break;
131 case OpCode_rmoveto:
132 has_width = (env.argStack.get_count () > 2);
133 break;
134 default:
135 return;
Michiharu Arizad56e3382018-10-31 22:30:34 -0700136 }
Michiharu Ariza049ce072018-11-01 08:46:21 -0700137 env.set_width (has_width);
Michiharu Arizad56e3382018-10-31 22:30:34 -0700138 }
139 }
140
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -0800141 static void process_seac (cff1_cs_interp_env_t &env, PARAM& param)
Michiharu Ariza3787c072018-11-14 13:38:03 -0800142 {
143 }
144
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -0800145 static void flush_args (cff1_cs_interp_env_t &env, PARAM& param)
Michiharu Arizad56e3382018-10-31 22:30:34 -0700146 {
147 SUPER::flush_args (env, param);
Michiharu Ariza8679d022018-10-18 13:04:21 -0700148 env.clear_args (); /* pop off width */
Michiharu Arizaa11420b2018-08-29 12:14:30 -0700149 }
150
151 private:
Michiharu Ariza29f0b6b2018-12-22 07:47:04 -0800152 typedef cs_opset_t<number_t, OPSET, cff1_cs_interp_env_t, PARAM, PATH> SUPER;
Michiharu Ariza633ce882018-08-15 12:00:19 -0700153};
154
155template <typename OPSET, typename PARAM>
Behdad Esfahbodbff78e62022-05-10 16:33:37 -0600156using cff1_cs_interpreter_t = cs_interpreter_t<cff1_cs_interp_env_t, OPSET, PARAM>;
Michiharu Ariza633ce882018-08-15 12:00:19 -0700157
158} /* namespace CFF */
159
Michiharu Arizafdbfa182018-08-16 00:13:09 -0700160#endif /* HB_CFF1_INTERP_CS_HH */