2018-08-17 22:13:18 +02:00
|
|
|
/*
|
2018-11-12 17:47:07 +01:00
|
|
|
* Copyright © 2018 Adobe Inc.
|
2018-08-17 22:13:18 +02:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Adobe Author(s): Michiharu Ariza
|
|
|
|
*/
|
|
|
|
#ifndef HB_CFF2_INTERP_CS_HH
|
|
|
|
#define HB_CFF2_INTERP_CS_HH
|
|
|
|
|
2018-08-29 22:26:17 +02:00
|
|
|
#include "hb.hh"
|
|
|
|
#include "hb-cff-interp-cs-common.hh"
|
2018-08-17 22:13:18 +02:00
|
|
|
|
|
|
|
namespace CFF {
|
|
|
|
|
|
|
|
using namespace OT;
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct blend_arg_t : number_t
|
2018-09-04 19:25:21 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
void set_int (int v) { reset_blends (); number_t::set_int (v); }
|
|
|
|
void set_fixed (int32_t v) { reset_blends (); number_t::set_fixed (v); }
|
|
|
|
void set_real (double v) { reset_blends (); number_t::set_real (v); }
|
2018-09-04 19:25:21 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void set_blends (unsigned int numValues_, unsigned int valueIndex_,
|
2022-11-26 23:16:11 +01:00
|
|
|
hb_array_t<const blend_arg_t> blends_)
|
2018-09-04 19:25:21 +02:00
|
|
|
{
|
|
|
|
numValues = numValues_;
|
|
|
|
valueIndex = valueIndex_;
|
2022-11-26 23:16:11 +01:00
|
|
|
unsigned numBlends = blends_.length;
|
2023-01-03 02:08:45 +01:00
|
|
|
if (unlikely (!deltas.resize_exact (numBlends)))
|
2022-11-26 23:14:52 +01:00
|
|
|
return;
|
2018-09-04 19:25:21 +02:00
|
|
|
for (unsigned int i = 0; i < numBlends; i++)
|
2022-11-26 23:14:52 +01:00
|
|
|
deltas.arrayZ[i] = blends_.arrayZ[i];
|
2018-09-04 19:25:21 +02:00
|
|
|
}
|
|
|
|
|
2018-12-22 00:46:51 +01:00
|
|
|
bool blending () const { return deltas.length > 0; }
|
2018-12-17 19:01:01 +01:00
|
|
|
void reset_blends ()
|
2018-09-04 19:25:21 +02:00
|
|
|
{
|
|
|
|
numValues = valueIndex = 0;
|
2023-01-02 02:41:19 +01:00
|
|
|
deltas.shrink (0);
|
2018-09-04 19:25:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int numValues;
|
|
|
|
unsigned int valueIndex;
|
2018-12-22 16:47:04 +01:00
|
|
|
hb_vector_t<number_t> deltas;
|
2018-09-04 19:25:21 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef biased_subrs_t<CFF2Subrs> cff2_biased_subrs_t;
|
2018-09-04 19:25:21 +02:00
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
template <typename ELEM>
|
|
|
|
struct cff2_cs_interp_env_t : cs_interp_env_t<ELEM, CFF2Subrs>
|
2018-08-17 22:13:18 +02:00
|
|
|
{
|
2018-09-04 19:25:21 +02:00
|
|
|
template <typename ACC>
|
2022-05-11 00:33:37 +02:00
|
|
|
cff2_cs_interp_env_t (const hb_ubytes_t &str, ACC &acc, unsigned int fd,
|
|
|
|
const int *coords_=nullptr, unsigned int num_coords_=0)
|
|
|
|
: SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs)
|
2018-08-17 22:13:18 +02:00
|
|
|
{
|
2018-10-09 00:05:36 +02:00
|
|
|
coords = coords_;
|
2018-10-09 00:38:05 +02:00
|
|
|
num_coords = num_coords_;
|
|
|
|
varStore = acc.varStore;
|
2018-10-09 00:05:36 +02:00
|
|
|
seen_blend = false;
|
2018-11-07 23:48:37 +01:00
|
|
|
seen_vsindex_ = false;
|
2018-10-09 00:05:36 +02:00
|
|
|
scalars.init ();
|
2020-04-20 21:18:23 +02:00
|
|
|
do_blend = num_coords && coords && varStore->size;
|
2018-10-09 00:05:36 +02:00
|
|
|
set_ivs (acc.privateDicts[fd].ivs);
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void fini ()
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
scalars.fini ();
|
|
|
|
SUPER::fini ();
|
2018-08-17 22:13:18 +02:00
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
op_code_t fetch_op ()
|
2018-08-17 22:13:18 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
if (this->str_ref.avail ())
|
2018-10-12 11:16:07 +02:00
|
|
|
return SUPER::fetch_op ();
|
2018-08-17 22:13:18 +02:00
|
|
|
|
|
|
|
/* make up return or endchar op */
|
2018-10-12 11:16:07 +02:00
|
|
|
if (this->callStack.is_empty ())
|
|
|
|
return OpCode_endchar;
|
2018-08-17 22:13:18 +02:00
|
|
|
else
|
2018-10-12 11:16:07 +02:00
|
|
|
return OpCode_return;
|
2018-08-17 22:13:18 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
const ELEM& eval_arg (unsigned int i)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
return SUPER::argStack[i];
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
const ELEM& pop_arg ()
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
return SUPER::argStack.pop ();
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void process_blend ()
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
if (!seen_blend)
|
|
|
|
{
|
|
|
|
region_count = varStore->varStore.get_region_index_count (get_ivs ());
|
|
|
|
if (do_blend)
|
|
|
|
{
|
2023-01-03 02:08:45 +01:00
|
|
|
if (unlikely (!scalars.resize_exact (region_count)))
|
2022-05-10 20:05:19 +02:00
|
|
|
SUPER::set_error ();
|
2020-07-31 06:28:53 +02:00
|
|
|
else
|
2021-07-29 02:02:52 +02:00
|
|
|
varStore->varStore.get_region_scalars (get_ivs (), coords, num_coords,
|
|
|
|
&scalars[0], region_count);
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
seen_blend = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void process_vsindex ()
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
unsigned int index = SUPER::argStack.pop_uint ();
|
2018-11-07 23:48:37 +01:00
|
|
|
if (unlikely (seen_vsindex () || seen_blend))
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
SUPER::set_error ();
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
2018-11-07 23:48:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
set_ivs (index);
|
|
|
|
}
|
|
|
|
seen_vsindex_ = true;
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_region_count () const { return region_count; }
|
2018-12-16 20:08:10 +01:00
|
|
|
void set_region_count (unsigned int region_count_) { region_count = region_count_; }
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_ivs () const { return ivs; }
|
2018-12-16 20:08:10 +01:00
|
|
|
void set_ivs (unsigned int ivs_) { ivs = ivs_; }
|
2018-12-17 19:01:01 +01:00
|
|
|
bool seen_vsindex () const { return seen_vsindex_; }
|
2018-08-17 22:13:18 +02:00
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
double blend_deltas (hb_array_t<const ELEM> deltas) const
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
double v = 0;
|
|
|
|
if (do_blend)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
if (likely (scalars.length == deltas.length))
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2022-11-26 23:11:32 +01:00
|
|
|
unsigned count = scalars.length;
|
|
|
|
for (unsigned i = 0; i < count; i++)
|
|
|
|
v += (double) scalars.arrayZ[i] * deltas.arrayZ[i].to_real ();
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-10 20:05:19 +02:00
|
|
|
return v;
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const int *coords;
|
|
|
|
unsigned int num_coords;
|
2018-12-01 05:04:59 +01:00
|
|
|
const CFF2VariationStore *varStore;
|
2018-09-04 19:25:21 +02:00
|
|
|
unsigned int region_count;
|
2018-10-09 00:05:36 +02:00
|
|
|
unsigned int ivs;
|
|
|
|
hb_vector_t<float> scalars;
|
2018-12-01 05:04:59 +01:00
|
|
|
bool do_blend;
|
|
|
|
bool seen_vsindex_;
|
|
|
|
bool seen_blend;
|
2018-09-01 01:28:47 +02:00
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
typedef cs_interp_env_t<ELEM, CFF2Subrs> SUPER;
|
2018-08-17 22:13:18 +02:00
|
|
|
};
|
2022-05-10 20:05:19 +02:00
|
|
|
template <typename OPSET, typename PARAM, typename ELEM, typename PATH=path_procs_null_t<cff2_cs_interp_env_t<ELEM>, PARAM>>
|
|
|
|
struct cff2_cs_opset_t : cs_opset_t<ELEM, OPSET, cff2_cs_interp_env_t<ELEM>, PARAM, PATH>
|
2018-08-17 22:13:18 +02:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
static void process_op (op_code_t op, cff2_cs_interp_env_t<ELEM> &env, PARAM& param)
|
2018-08-17 22:13:18 +02:00
|
|
|
{
|
|
|
|
switch (op) {
|
2018-09-04 19:25:21 +02:00
|
|
|
case OpCode_callsubr:
|
|
|
|
case OpCode_callgsubr:
|
Fix various typos
Found via `codespell -q 3 -S ./perf/texts -L actualy,ba,beng,fo,gir,inout,nd,ot,pres,ro,te,teh,timne`
2022-01-16 13:00:53 +01:00
|
|
|
/* a subroutine number shouldn't be a blended value */
|
2022-05-10 20:05:19 +02:00
|
|
|
#if 0
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (env.argStack.peek ().blending ()))
|
|
|
|
{
|
|
|
|
env.set_error ();
|
|
|
|
break;
|
|
|
|
}
|
2022-05-10 20:05:19 +02:00
|
|
|
#endif
|
2018-12-01 05:04:59 +01:00
|
|
|
SUPER::process_op (op, env, param);
|
|
|
|
break;
|
2018-08-17 22:13:18 +02:00
|
|
|
|
|
|
|
case OpCode_blendcs:
|
2018-12-01 05:04:59 +01:00
|
|
|
OPSET::process_blend (env, param);
|
|
|
|
break;
|
2018-08-30 03:18:18 +02:00
|
|
|
|
2018-08-17 22:13:18 +02:00
|
|
|
case OpCode_vsindexcs:
|
2022-05-10 20:05:19 +02:00
|
|
|
#if 0
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (env.argStack.peek ().blending ()))
|
|
|
|
{
|
|
|
|
env.set_error ();
|
|
|
|
break;
|
|
|
|
}
|
2022-05-10 20:05:19 +02:00
|
|
|
#endif
|
2018-12-01 05:04:59 +01:00
|
|
|
OPSET::process_vsindex (env, param);
|
|
|
|
break;
|
2018-08-30 03:18:18 +02:00
|
|
|
|
2018-08-17 22:13:18 +02:00
|
|
|
default:
|
2018-12-01 05:04:59 +01:00
|
|
|
SUPER::process_op (op, env, param);
|
2018-08-17 22:13:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-30 03:18:18 +02:00
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
template <typename T = ELEM,
|
|
|
|
hb_enable_if (hb_is_same (T, blend_arg_t))>
|
|
|
|
static void process_arg_blend (cff2_cs_interp_env_t<ELEM> &env,
|
|
|
|
ELEM &arg,
|
|
|
|
const hb_array_t<const ELEM> blends,
|
|
|
|
unsigned n, unsigned i)
|
|
|
|
{
|
2022-11-26 23:16:11 +01:00
|
|
|
arg.set_blends (n, i, blends);
|
2022-05-10 20:05:19 +02:00
|
|
|
}
|
|
|
|
template <typename T = ELEM,
|
|
|
|
hb_enable_if (!hb_is_same (T, blend_arg_t))>
|
|
|
|
static void process_arg_blend (cff2_cs_interp_env_t<ELEM> &env,
|
|
|
|
ELEM &arg,
|
|
|
|
const hb_array_t<const ELEM> blends,
|
|
|
|
unsigned n, unsigned i)
|
|
|
|
{
|
|
|
|
arg.set_real (arg.to_real () + env.blend_deltas (blends));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void process_blend (cff2_cs_interp_env_t<ELEM> &env, PARAM& param)
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2018-09-04 19:25:21 +02:00
|
|
|
unsigned int n, k;
|
|
|
|
|
2018-10-09 00:05:36 +02:00
|
|
|
env.process_blend ();
|
2018-09-04 19:25:21 +02:00
|
|
|
k = env.get_region_count ();
|
2018-10-12 11:16:07 +02:00
|
|
|
n = env.argStack.pop_uint ();
|
2018-12-06 22:36:26 +01:00
|
|
|
/* copy the blend values into blend array of the default values */
|
|
|
|
unsigned int start = env.argStack.get_count () - ((k+1) * n);
|
|
|
|
/* let an obvious error case fail, but note CFF2 spec doesn't forbid n==0 */
|
|
|
|
if (unlikely (start > env.argStack.get_count ()))
|
2018-12-06 06:33:29 +01:00
|
|
|
{
|
|
|
|
env.set_error ();
|
|
|
|
return;
|
|
|
|
}
|
2018-09-04 19:25:21 +02:00
|
|
|
for (unsigned int i = 0; i < n; i++)
|
2018-12-06 22:36:26 +01:00
|
|
|
{
|
2022-05-10 20:05:19 +02:00
|
|
|
const hb_array_t<const ELEM> blends = env.argStack.sub_array (start + n + (i * k), k);
|
|
|
|
process_arg_blend (env, env.argStack[start + i], blends, n, i);
|
2018-12-06 22:36:26 +01:00
|
|
|
}
|
2018-09-04 19:25:21 +02:00
|
|
|
|
|
|
|
/* pop off blend values leaving default values now adorned with blend values */
|
2018-09-17 20:14:56 +02:00
|
|
|
env.argStack.pop (k * n);
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
static void process_vsindex (cff2_cs_interp_env_t<ELEM> &env, PARAM& param)
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2018-08-31 22:28:16 +02:00
|
|
|
env.process_vsindex ();
|
2018-11-07 18:16:12 +01:00
|
|
|
env.clear_args ();
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
2018-09-01 01:28:47 +02:00
|
|
|
|
|
|
|
private:
|
2022-05-10 20:05:19 +02:00
|
|
|
typedef cs_opset_t<ELEM, OPSET, cff2_cs_interp_env_t<ELEM>, PARAM, PATH> SUPER;
|
2018-08-17 22:13:18 +02:00
|
|
|
};
|
|
|
|
|
2022-05-10 20:05:19 +02:00
|
|
|
template <typename OPSET, typename PARAM, typename ELEM>
|
2022-05-11 00:33:37 +02:00
|
|
|
using cff2_cs_interpreter_t = cs_interpreter_t<cff2_cs_interp_env_t<ELEM>, OPSET, PARAM>;
|
2018-08-17 22:13:18 +02:00
|
|
|
|
|
|
|
} /* namespace CFF */
|
|
|
|
|
|
|
|
#endif /* HB_CFF2_INTERP_CS_HH */
|