2018-08-06 19:04:53 +02:00
|
|
|
/*
|
2018-11-12 17:47:07 +01:00
|
|
|
* Copyright © 2018 Adobe Inc.
|
2018-08-06 19:04:53 +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
|
|
|
|
*/
|
|
|
|
|
2018-08-29 22:36:39 +02:00
|
|
|
#ifndef HB_SUBSET_CFF_COMMON_HH
|
|
|
|
#define HB_SUBSET_CFF_COMMON_HH
|
2018-08-06 19:04:53 +02:00
|
|
|
|
2018-08-29 22:26:17 +02:00
|
|
|
#include "hb.hh"
|
2018-08-06 19:04:53 +02:00
|
|
|
|
|
|
|
#include "hb-subset-plan.hh"
|
2018-08-29 22:26:17 +02:00
|
|
|
#include "hb-cff-interp-cs-common.hh"
|
2018-08-15 21:00:19 +02:00
|
|
|
|
|
|
|
namespace CFF {
|
|
|
|
|
2018-08-29 21:14:30 +02:00
|
|
|
/* Used for writing a temporary charstring */
|
2018-12-22 16:47:04 +01:00
|
|
|
struct str_encoder_t
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
str_encoder_t (str_buff_t &buff_)
|
2022-11-22 01:17:15 +01:00
|
|
|
: buff (buff_) {}
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-05-18 19:37:57 +02:00
|
|
|
void reset () { buff.reset (); }
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void encode_byte (unsigned char b)
|
2022-11-23 21:00:23 +01:00
|
|
|
{
|
|
|
|
if (likely ((signed) buff.length < buff.allocated))
|
|
|
|
buff.arrayZ[buff.length++] = b;
|
|
|
|
else
|
|
|
|
buff.push (b);
|
|
|
|
}
|
2018-08-29 21:14:30 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void encode_int (int v)
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2018-09-04 19:25:21 +02:00
|
|
|
if ((-1131 <= v) && (v <= 1131))
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2018-09-04 19:25:21 +02:00
|
|
|
if ((-107 <= v) && (v <= 107))
|
2018-12-01 05:04:59 +01:00
|
|
|
encode_byte (v + 139);
|
2018-09-04 19:25:21 +02:00
|
|
|
else if (v > 0)
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
v -= 108;
|
|
|
|
encode_byte ((v >> 8) + OpCode_TwoBytePosInt0);
|
|
|
|
encode_byte (v & 0xFF);
|
2018-08-29 21:14:30 +02:00
|
|
|
}
|
2018-09-04 19:25:21 +02:00
|
|
|
else
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
v = -v - 108;
|
|
|
|
encode_byte ((v >> 8) + OpCode_TwoByteNegInt0);
|
|
|
|
encode_byte (v & 0xFF);
|
2018-09-04 19:25:21 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (unlikely (v < -32768))
|
2018-12-01 05:04:59 +01:00
|
|
|
v = -32768;
|
2018-11-01 06:30:34 +01:00
|
|
|
else if (unlikely (v > 32767))
|
2018-12-01 05:04:59 +01:00
|
|
|
v = 32767;
|
2018-11-01 06:30:34 +01:00
|
|
|
encode_byte (OpCode_shortint);
|
|
|
|
encode_byte ((v >> 8) & 0xFF);
|
|
|
|
encode_byte (v & 0xFF);
|
|
|
|
}
|
2018-09-04 19:25:21 +02:00
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void encode_num (const number_t& n)
|
2018-09-04 19:25:21 +02:00
|
|
|
{
|
|
|
|
if (n.in_int_range ())
|
|
|
|
{
|
2018-11-01 06:30:34 +01:00
|
|
|
encode_int (n.to_int ());
|
2018-08-29 21:14:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int32_t v = n.to_fixed ();
|
2018-11-01 06:30:34 +01:00
|
|
|
encode_byte (OpCode_fixedcs);
|
|
|
|
encode_byte ((v >> 24) & 0xFF);
|
|
|
|
encode_byte ((v >> 16) & 0xFF);
|
|
|
|
encode_byte ((v >> 8) & 0xFF);
|
|
|
|
encode_byte (v & 0xFF);
|
2018-08-29 21:14:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void encode_op (op_code_t op)
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
|
|
|
if (Is_OpCode_ESC (op))
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
encode_byte (OpCode_escape);
|
|
|
|
encode_byte (Unmake_OpCode_ESC (op));
|
|
|
|
}
|
2018-08-29 21:14:30 +02:00
|
|
|
else
|
2018-11-01 06:30:34 +01:00
|
|
|
encode_byte (op);
|
2018-08-29 21:14:30 +02:00
|
|
|
}
|
|
|
|
|
2022-11-22 05:37:38 +01:00
|
|
|
void copy_str (const unsigned char *str, unsigned length)
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2022-12-02 04:02:38 +01:00
|
|
|
assert ((signed) (buff.length + length) <= buff.allocated);
|
|
|
|
hb_memcpy (buff.arrayZ + buff.length, str, length);
|
|
|
|
buff.length += length;
|
2018-08-29 21:14:30 +02:00
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-11-24 22:02:46 +01:00
|
|
|
bool in_error () const { return buff.in_error (); }
|
2018-11-01 06:30:34 +01:00
|
|
|
|
|
|
|
protected:
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
str_buff_t &buff;
|
2018-08-29 21:14:30 +02:00
|
|
|
};
|
|
|
|
|
2020-03-03 01:51:19 +01:00
|
|
|
struct cff_sub_table_info_t {
|
|
|
|
cff_sub_table_info_t ()
|
|
|
|
: fd_array_link (0),
|
2020-03-05 01:54:27 +01:00
|
|
|
char_strings_link (0)
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2020-03-03 01:51:19 +01:00
|
|
|
fd_select.init ();
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
|
|
|
|
2020-03-03 01:51:19 +01:00
|
|
|
table_info_t fd_select;
|
|
|
|
objidx_t fd_array_link;
|
|
|
|
objidx_t char_strings_link;
|
2018-08-30 03:18:18 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
template <typename OPSTR=op_str_t>
|
|
|
|
struct cff_top_dict_op_serializer_t : op_serializer_t
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
const OPSTR &opstr,
|
2020-03-03 01:51:19 +01:00
|
|
|
const cff_sub_table_info_t &info) const
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
|
|
|
|
switch (opstr.op)
|
|
|
|
{
|
|
|
|
case OpCode_CharStrings:
|
2020-03-03 01:51:19 +01:00
|
|
|
return_trace (FontDict::serialize_link4_op(c, opstr.op, info.char_strings_link, whence_t::Absolute));
|
2018-08-30 03:18:18 +02:00
|
|
|
|
|
|
|
case OpCode_FDArray:
|
2020-03-03 01:51:19 +01:00
|
|
|
return_trace (FontDict::serialize_link4_op(c, opstr.op, info.fd_array_link, whence_t::Absolute));
|
2018-08-30 03:18:18 +02:00
|
|
|
|
|
|
|
case OpCode_FDSelect:
|
2020-03-03 01:51:19 +01:00
|
|
|
return_trace (FontDict::serialize_link4_op(c, opstr.op, info.fd_select.link, whence_t::Absolute));
|
2018-08-30 03:18:18 +02:00
|
|
|
|
|
|
|
default:
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (copy_opstr (c, opstr));
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff_font_dict_op_serializer_t : op_serializer_t
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
2018-12-22 16:47:04 +01:00
|
|
|
const op_str_t &opstr,
|
2020-03-05 07:31:21 +01:00
|
|
|
const table_info_t &privateDictInfo) const
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
|
|
|
|
if (opstr.op == OpCode_Private)
|
|
|
|
{
|
2018-09-11 01:00:20 +02:00
|
|
|
/* serialize the private dict size & offset as 2-byte & 4-byte integers */
|
2020-03-05 07:31:21 +01:00
|
|
|
return_trace (UnsizedByteStr::serialize_int2 (c, privateDictInfo.size) &&
|
|
|
|
Dict::serialize_link4_op (c, opstr.op, privateDictInfo.link, whence_t::Absolute));
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-22 20:46:25 +01:00
|
|
|
unsigned char *d = c->allocate_size<unsigned char> (opstr.length);
|
2020-04-20 21:18:23 +02:00
|
|
|
if (unlikely (!d)) return_trace (false);
|
2022-11-22 20:54:50 +01:00
|
|
|
/* Faster than hb_memcpy for small strings. */
|
2022-11-22 20:46:25 +01:00
|
|
|
for (unsigned i = 0; i < opstr.length; i++)
|
|
|
|
d[i] = opstr.ptr[i];
|
|
|
|
//hb_memcpy (d, opstr.ptr, opstr.length);
|
2018-08-30 03:18:18 +02:00
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff_private_dict_op_serializer_t : op_serializer_t
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
cff_private_dict_op_serializer_t (bool desubroutinize_, bool drop_hints_)
|
2018-11-01 06:30:34 +01:00
|
|
|
: desubroutinize (desubroutinize_), drop_hints (drop_hints_) {}
|
2018-08-30 03:18:18 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
2018-12-22 16:47:04 +01:00
|
|
|
const op_str_t &opstr,
|
2020-03-03 01:51:19 +01:00
|
|
|
objidx_t subrs_link) const
|
2018-08-30 03:18:18 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
if (drop_hints && dict_opset_t::is_hint_op (opstr.op))
|
2018-08-30 03:18:18 +02:00
|
|
|
return true;
|
|
|
|
if (opstr.op == OpCode_Subrs)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2020-03-03 01:51:19 +01:00
|
|
|
if (desubroutinize || !subrs_link)
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (true);
|
2018-11-01 06:30:34 +01:00
|
|
|
else
|
2020-03-03 01:51:19 +01:00
|
|
|
return_trace (FontDict::serialize_link2_op (c, opstr.op, subrs_link));
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
2018-08-30 03:18:18 +02:00
|
|
|
else
|
|
|
|
return_trace (copy_opstr (c, opstr));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-11-01 06:30:34 +01:00
|
|
|
const bool desubroutinize;
|
2018-08-30 03:18:18 +02:00
|
|
|
const bool drop_hints;
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct flatten_param_t
|
2018-08-31 02:21:56 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
str_buff_t &flatStr;
|
2018-12-01 05:04:59 +01:00
|
|
|
bool drop_hints;
|
2023-01-06 19:01:25 +01:00
|
|
|
const hb_subset_plan_t *plan;
|
2018-08-31 02:21:56 +02:00
|
|
|
};
|
2018-08-29 21:14:30 +02:00
|
|
|
|
2019-01-31 23:16:37 +01:00
|
|
|
template <typename ACC, typename ENV, typename OPSET, op_code_t endchar_op=OpCode_Invalid>
|
2018-12-22 16:47:04 +01:00
|
|
|
struct subr_flattener_t
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
subr_flattener_t (const ACC &acc_,
|
2019-01-31 23:16:37 +01:00
|
|
|
const hb_subset_plan_t *plan_)
|
|
|
|
: acc (acc_), plan (plan_) {}
|
2018-08-29 21:14:30 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
bool flatten (str_buff_vec_t &flat_charstrings)
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2022-11-28 21:31:40 +01:00
|
|
|
unsigned count = plan->num_output_glyphs ();
|
2023-01-03 02:05:43 +01:00
|
|
|
if (!flat_charstrings.resize_exact (count))
|
2018-08-29 21:14:30 +02:00
|
|
|
return false;
|
2022-11-28 21:31:40 +01:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2018-08-29 21:14:30 +02:00
|
|
|
{
|
2019-01-31 23:16:37 +01:00
|
|
|
hb_codepoint_t glyph;
|
|
|
|
if (!plan->old_gid_for_new_gid (i, &glyph))
|
|
|
|
{
|
2019-12-31 13:23:02 +01:00
|
|
|
/* add an endchar only charstring for a missing glyph if CFF1 */
|
|
|
|
if (endchar_op != OpCode_Invalid) flat_charstrings[i].push (endchar_op);
|
|
|
|
continue;
|
2019-01-31 23:16:37 +01:00
|
|
|
}
|
2022-05-10 00:09:56 +02:00
|
|
|
const hb_ubytes_t str = (*acc.charStrings)[glyph];
|
2018-08-29 21:14:30 +02:00
|
|
|
unsigned int fd = acc.fdSelect->get_fd (glyph);
|
2018-12-13 02:36:01 +01:00
|
|
|
if (unlikely (fd >= acc.fdCount))
|
2019-12-31 13:23:02 +01:00
|
|
|
return false;
|
2023-01-06 19:01:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
ENV env (str, acc, fd,
|
|
|
|
plan->normalized_coords.arrayZ, plan->normalized_coords.length);
|
2022-05-11 00:33:37 +02:00
|
|
|
cs_interpreter_t<ENV, OPSET, flatten_param_t> interp (env);
|
2021-07-30 00:07:13 +02:00
|
|
|
flatten_param_t param = {
|
2022-11-28 21:31:40 +01:00
|
|
|
flat_charstrings.arrayZ[i],
|
2023-01-06 19:01:25 +01:00
|
|
|
(bool) (plan->flags & HB_SUBSET_FLAGS_NO_HINTING),
|
|
|
|
plan
|
2021-07-30 00:07:13 +02:00
|
|
|
};
|
2018-08-31 02:21:56 +02:00
|
|
|
if (unlikely (!interp.interpret (param)))
|
2018-12-01 05:04:59 +01:00
|
|
|
return false;
|
2018-08-29 21:14:30 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-04 19:25:21 +02:00
|
|
|
const ACC &acc;
|
2019-01-31 23:16:37 +01:00
|
|
|
const hb_subset_plan_t *plan;
|
2018-08-29 21:14:30 +02:00
|
|
|
};
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct subr_closures_t
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-27 01:57:44 +01:00
|
|
|
subr_closures_t (unsigned int fd_count) : global_closure (), local_closures ()
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2023-01-03 02:05:43 +01:00
|
|
|
local_closures.resize_exact (fd_count);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void reset ()
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-01-18 19:29:04 +01:00
|
|
|
global_closure.clear();
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < local_closures.length; i++)
|
2022-01-18 19:29:04 +01:00
|
|
|
local_closures[i].clear();
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2022-11-27 01:57:44 +01:00
|
|
|
bool in_error () const { return local_closures.in_error (); }
|
2022-01-18 19:29:04 +01:00
|
|
|
hb_set_t global_closure;
|
|
|
|
hb_vector_t<hb_set_t> local_closures;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct parsed_cs_op_t : op_str_t
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-28 21:51:16 +01:00
|
|
|
parsed_cs_op_t (unsigned int subr_num_ = 0) :
|
|
|
|
subr_num (subr_num_) {}
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-11-28 20:28:13 +01:00
|
|
|
bool is_hinting () const { return hinting_flag; }
|
|
|
|
void set_hinting () { hinting_flag = true; }
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-11-22 06:02:17 +01:00
|
|
|
/* The layout of this struct is designed to fit within the
|
|
|
|
* padding of op_str_t! */
|
|
|
|
|
2018-11-02 23:28:01 +01:00
|
|
|
protected:
|
2022-11-28 21:51:16 +01:00
|
|
|
bool hinting_flag = false;
|
2022-11-22 05:59:51 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
uint16_t subr_num;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct parsed_cs_str_t : parsed_values_t<parsed_cs_op_t>
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-28 21:58:44 +01:00
|
|
|
parsed_cs_str_t () :
|
|
|
|
parsed (false),
|
|
|
|
hint_dropped (false),
|
|
|
|
has_prefix_ (false),
|
|
|
|
has_calls_ (false)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
SUPER::init ();
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void add_op (op_code_t op, const byte_str_ref_t& str_ref)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
if (!is_parsed ())
|
2018-12-22 16:47:04 +01:00
|
|
|
SUPER::add_op (op, str_ref);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void add_call_op (op_code_t op, const byte_str_ref_t& str_ref, unsigned int subr_num)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
if (!is_parsed ())
|
|
|
|
{
|
2022-11-27 01:49:21 +01:00
|
|
|
has_calls_ = true;
|
|
|
|
|
2022-11-28 21:54:24 +01:00
|
|
|
/* Pop the subroutine number. */
|
|
|
|
values.pop ();
|
2022-11-27 02:12:14 +01:00
|
|
|
|
2022-11-28 21:51:16 +01:00
|
|
|
SUPER::add_op (op, str_ref, {subr_num});
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void set_prefix (const number_t &num, op_code_t op = OpCode_Invalid)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
has_prefix_ = true;
|
|
|
|
prefix_op_ = op;
|
|
|
|
prefix_num_ = num;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool at_end (unsigned int pos) const
|
2018-11-08 02:58:45 +01:00
|
|
|
{
|
2018-12-22 00:46:51 +01:00
|
|
|
return ((pos + 1 >= values.length) /* CFF2 */
|
2018-12-01 05:04:59 +01:00
|
|
|
|| (values[pos + 1].op == OpCode_return));
|
2018-11-08 02:58:45 +01:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_parsed () const { return parsed; }
|
|
|
|
void set_parsed () { parsed = true; }
|
|
|
|
|
|
|
|
bool is_hint_dropped () const { return hint_dropped; }
|
|
|
|
void set_hint_dropped () { hint_dropped = true; }
|
|
|
|
|
|
|
|
bool is_vsindex_dropped () const { return vsindex_dropped; }
|
|
|
|
void set_vsindex_dropped () { vsindex_dropped = true; }
|
|
|
|
|
|
|
|
bool has_prefix () const { return has_prefix_; }
|
2018-12-22 16:47:04 +01:00
|
|
|
op_code_t prefix_op () const { return prefix_op_; }
|
|
|
|
const number_t &prefix_num () const { return prefix_num_; }
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-11-27 01:49:21 +01:00
|
|
|
bool has_calls () const { return has_calls_; }
|
|
|
|
|
2023-01-02 20:05:11 +01:00
|
|
|
void compact ()
|
|
|
|
{
|
|
|
|
unsigned count = values.length;
|
2023-01-03 01:41:31 +01:00
|
|
|
if (!count) return;
|
2023-01-02 20:05:11 +01:00
|
|
|
auto &opstr = values.arrayZ;
|
|
|
|
unsigned j = 0;
|
|
|
|
for (unsigned i = 1; i < count; i++)
|
|
|
|
{
|
|
|
|
/* See if we can combine op j and op i. */
|
|
|
|
bool combine =
|
|
|
|
(opstr[j].op != OpCode_callsubr && opstr[j].op != OpCode_callgsubr) &&
|
|
|
|
(opstr[i].op != OpCode_callsubr && opstr[i].op != OpCode_callgsubr) &&
|
|
|
|
(opstr[j].is_hinting () == opstr[i].is_hinting ()) &&
|
|
|
|
(opstr[j].ptr + opstr[j].length == opstr[i].ptr) &&
|
|
|
|
(opstr[j].length + opstr[i].length <= 255);
|
|
|
|
|
|
|
|
if (combine)
|
|
|
|
{
|
|
|
|
opstr[j].length += opstr[i].length;
|
|
|
|
opstr[j].op = OpCode_Invalid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opstr[++j] = opstr[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
values.shrink (j + 1);
|
|
|
|
}
|
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
protected:
|
2022-11-27 01:49:21 +01:00
|
|
|
bool parsed : 1;
|
|
|
|
bool hint_dropped : 1;
|
|
|
|
bool vsindex_dropped : 1;
|
|
|
|
bool has_prefix_ : 1;
|
|
|
|
bool has_calls_ : 1;
|
2018-12-22 16:47:04 +01:00
|
|
|
op_code_t prefix_op_;
|
2019-12-31 13:23:02 +01:00
|
|
|
number_t prefix_num_;
|
2018-11-01 06:30:34 +01:00
|
|
|
|
|
|
|
private:
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef parsed_values_t<parsed_cs_op_t> SUPER;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct parsed_cs_str_vec_t : hb_vector_t<parsed_cs_str_t>
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-11-05 01:19:15 +01:00
|
|
|
private:
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef hb_vector_t<parsed_cs_str_t> SUPER;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2022-11-23 21:51:51 +01:00
|
|
|
struct cff_subset_accelerator_t
|
|
|
|
{
|
2022-11-25 19:38:13 +01:00
|
|
|
static cff_subset_accelerator_t* create (
|
2022-11-25 21:33:39 +01:00
|
|
|
hb_blob_t* original_blob,
|
2022-11-23 22:02:39 +01:00
|
|
|
const parsed_cs_str_vec_t& parsed_charstrings,
|
|
|
|
const parsed_cs_str_vec_t& parsed_global_subrs,
|
|
|
|
const hb_vector_t<parsed_cs_str_vec_t>& parsed_local_subrs) {
|
2022-11-23 21:51:51 +01:00
|
|
|
cff_subset_accelerator_t* accel =
|
|
|
|
(cff_subset_accelerator_t*) hb_malloc (sizeof(cff_subset_accelerator_t));
|
2022-11-25 21:33:39 +01:00
|
|
|
new (accel) cff_subset_accelerator_t (original_blob,
|
2022-11-24 23:47:29 +01:00
|
|
|
parsed_charstrings,
|
2022-11-23 22:02:39 +01:00
|
|
|
parsed_global_subrs,
|
|
|
|
parsed_local_subrs);
|
2022-11-23 21:51:51 +01:00
|
|
|
return accel;
|
|
|
|
}
|
|
|
|
|
2022-11-25 19:38:13 +01:00
|
|
|
static void destroy (void* value) {
|
2022-11-23 21:51:51 +01:00
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
cff_subset_accelerator_t* accel = (cff_subset_accelerator_t*) value;
|
|
|
|
accel->~cff_subset_accelerator_t ();
|
|
|
|
hb_free (accel);
|
|
|
|
}
|
|
|
|
|
2022-11-23 22:02:39 +01:00
|
|
|
cff_subset_accelerator_t(
|
2022-11-25 21:33:39 +01:00
|
|
|
hb_blob_t* original_blob_,
|
2022-11-23 22:02:39 +01:00
|
|
|
const parsed_cs_str_vec_t& parsed_charstrings_,
|
|
|
|
const parsed_cs_str_vec_t& parsed_global_subrs_,
|
|
|
|
const hb_vector_t<parsed_cs_str_vec_t>& parsed_local_subrs_)
|
|
|
|
{
|
|
|
|
parsed_charstrings = parsed_charstrings_;
|
|
|
|
parsed_global_subrs = parsed_global_subrs_;
|
|
|
|
parsed_local_subrs = parsed_local_subrs_;
|
2022-11-25 21:33:39 +01:00
|
|
|
|
|
|
|
// the parsed charstrings point to memory in the original CFF table so we must hold a reference
|
|
|
|
// to it to keep the memory valid.
|
|
|
|
original_blob = hb_blob_reference (original_blob_);
|
2022-11-23 22:02:39 +01:00
|
|
|
}
|
|
|
|
|
2022-11-24 23:47:29 +01:00
|
|
|
~cff_subset_accelerator_t() {
|
2022-11-25 21:33:39 +01:00
|
|
|
hb_blob_destroy (original_blob);
|
2022-11-30 21:15:58 +01:00
|
|
|
hb_map_destroy (glyph_to_sid_map.get_relaxed ());
|
2022-11-24 23:47:29 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 22:02:39 +01:00
|
|
|
parsed_cs_str_vec_t parsed_charstrings;
|
2022-11-23 21:51:51 +01:00
|
|
|
parsed_cs_str_vec_t parsed_global_subrs;
|
2022-11-23 22:02:39 +01:00
|
|
|
hb_vector_t<parsed_cs_str_vec_t> parsed_local_subrs;
|
2022-11-30 21:15:58 +01:00
|
|
|
mutable hb_atomic_ptr_t<hb_map_t> glyph_to_sid_map = nullptr;
|
2022-11-23 22:02:39 +01:00
|
|
|
|
2022-11-24 23:47:29 +01:00
|
|
|
private:
|
2022-11-25 21:33:39 +01:00
|
|
|
hb_blob_t* original_blob;
|
2022-11-23 21:51:51 +01:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct subr_subset_param_t
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-05-10 23:38:37 +02:00
|
|
|
subr_subset_param_t (parsed_cs_str_t *parsed_charstring_,
|
|
|
|
parsed_cs_str_vec_t *parsed_global_subrs_,
|
|
|
|
parsed_cs_str_vec_t *parsed_local_subrs_,
|
|
|
|
hb_set_t *global_closure_,
|
|
|
|
hb_set_t *local_closure_,
|
|
|
|
bool drop_hints_) :
|
|
|
|
current_parsed_str (parsed_charstring_),
|
|
|
|
parsed_charstring (parsed_charstring_),
|
|
|
|
parsed_global_subrs (parsed_global_subrs_),
|
|
|
|
parsed_local_subrs (parsed_local_subrs_),
|
|
|
|
global_closure (global_closure_),
|
|
|
|
local_closure (local_closure_),
|
|
|
|
drop_hints (drop_hints_) {}
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
parsed_cs_str_t *get_parsed_str_for_context (call_context_t &context)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
switch (context.type)
|
|
|
|
{
|
|
|
|
case CSType_CharString:
|
2018-12-01 05:04:59 +01:00
|
|
|
return parsed_charstring;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
case CSType_LocalSubr:
|
2018-12-22 00:46:51 +01:00
|
|
|
if (likely (context.subr_num < parsed_local_subrs->length))
|
2018-12-01 05:04:59 +01:00
|
|
|
return &(*parsed_local_subrs)[context.subr_num];
|
|
|
|
break;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
case CSType_GlobalSubr:
|
2018-12-22 00:46:51 +01:00
|
|
|
if (likely (context.subr_num < parsed_global_subrs->length))
|
2018-12-01 05:04:59 +01:00
|
|
|
return &(*parsed_global_subrs)[context.subr_num];
|
|
|
|
break;
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
2018-11-04 06:42:22 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ENV>
|
2018-12-16 20:08:10 +01:00
|
|
|
void set_current_str (ENV &env, bool calling)
|
2018-11-04 06:42:22 +01:00
|
|
|
{
|
2020-04-20 21:18:23 +02:00
|
|
|
parsed_cs_str_t *parsed_str = get_parsed_str_for_context (env.context);
|
|
|
|
if (unlikely (!parsed_str))
|
2018-12-11 21:21:24 +01:00
|
|
|
{
|
2020-04-20 21:18:23 +02:00
|
|
|
env.set_error ();
|
|
|
|
return;
|
2018-12-11 21:21:24 +01:00
|
|
|
}
|
2020-04-20 21:18:23 +02:00
|
|
|
/* If the called subroutine is parsed partially but not completely yet,
|
|
|
|
* it must be because we are calling it recursively.
|
|
|
|
* Handle it as an error. */
|
|
|
|
if (unlikely (calling && !parsed_str->is_parsed () && (parsed_str->values.length > 0)))
|
2018-11-04 06:42:22 +01:00
|
|
|
env.set_error ();
|
2020-04-20 21:18:23 +02:00
|
|
|
else
|
2022-11-22 02:18:48 +01:00
|
|
|
{
|
|
|
|
if (!parsed_str->is_parsed ())
|
2023-01-02 02:31:32 +01:00
|
|
|
parsed_str->alloc (env.str_ref.total_size ());
|
2020-04-20 21:18:23 +02:00
|
|
|
current_parsed_str = parsed_str;
|
2022-11-22 02:18:48 +01:00
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
parsed_cs_str_t *current_parsed_str;
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
parsed_cs_str_t *parsed_charstring;
|
|
|
|
parsed_cs_str_vec_t *parsed_global_subrs;
|
|
|
|
parsed_cs_str_vec_t *parsed_local_subrs;
|
2018-11-01 06:30:34 +01:00
|
|
|
hb_set_t *global_closure;
|
|
|
|
hb_set_t *local_closure;
|
2018-12-01 05:04:59 +01:00
|
|
|
bool drop_hints;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2019-06-18 07:12:40 +02:00
|
|
|
struct subr_remap_t : hb_inc_bimap_t
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-01-18 19:29:04 +01:00
|
|
|
void create (const hb_set_t *closure)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
/* create a remapping of subroutine numbers from old to new.
|
|
|
|
* no optimization based on usage counts. fonttools doesn't appear doing that either.
|
|
|
|
*/
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2022-05-18 20:39:55 +02:00
|
|
|
resize (closure->get_population ());
|
2019-06-18 07:12:40 +02:00
|
|
|
hb_codepoint_t old_num = HB_SET_VALUE_INVALID;
|
|
|
|
while (hb_set_next (closure, &old_num))
|
|
|
|
add (old_num);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2019-06-18 07:12:40 +02:00
|
|
|
if (get_population () < 1240)
|
2018-11-01 06:30:34 +01:00
|
|
|
bias = 107;
|
2019-06-18 07:12:40 +02:00
|
|
|
else if (get_population () < 33900)
|
2018-11-01 06:30:34 +01:00
|
|
|
bias = 1131;
|
|
|
|
else
|
|
|
|
bias = 32768;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int biased_num (unsigned int old_num) const
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2019-06-20 23:33:09 +02:00
|
|
|
hb_codepoint_t new_num = get (old_num);
|
2018-11-04 06:42:22 +01:00
|
|
|
return (int)new_num - bias;
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int bias;
|
|
|
|
};
|
|
|
|
|
2019-02-22 01:34:49 +01:00
|
|
|
struct subr_remaps_t
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-01-18 19:29:04 +01:00
|
|
|
subr_remaps_t (unsigned int fdCount)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-01-18 17:21:31 +01:00
|
|
|
local_remaps.resize (fdCount);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2020-07-30 22:45:04 +02:00
|
|
|
bool in_error()
|
|
|
|
{
|
|
|
|
return local_remaps.in_error ();
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void create (subr_closures_t& closures)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-01-18 19:29:04 +01:00
|
|
|
global_remap.create (&closures.global_closure);
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < local_remaps.length; i++)
|
2022-11-24 22:00:59 +01:00
|
|
|
local_remaps.arrayZ[i].create (&closures.local_closures[i]);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
subr_remap_t global_remap;
|
|
|
|
hb_vector_t<subr_remap_t> local_remaps;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2019-01-31 23:16:37 +01:00
|
|
|
template <typename SUBSETTER, typename SUBRS, typename ACC, typename ENV, typename OPSET, op_code_t endchar_op=OpCode_Invalid>
|
2018-12-22 16:47:04 +01:00
|
|
|
struct subr_subsetter_t
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2019-01-31 23:16:37 +01:00
|
|
|
subr_subsetter_t (ACC &acc_, const hb_subset_plan_t *plan_)
|
2022-11-27 20:58:04 +01:00
|
|
|
: acc (acc_), plan (plan_), closures(acc_.fdCount),
|
2022-11-26 00:17:05 +01:00
|
|
|
remaps(acc_.fdCount)
|
2022-01-18 17:32:58 +01:00
|
|
|
{}
|
2018-11-01 06:30:34 +01:00
|
|
|
|
|
|
|
/* Subroutine subsetting with --no-desubroutinize runs in phases:
|
|
|
|
*
|
|
|
|
* 1. execute charstrings/subroutines to determine subroutine closures
|
|
|
|
* 2. parse out all operators and numbers
|
|
|
|
* 3. mark hint operators and operands for removal if --no-hinting
|
|
|
|
* 4. re-encode all charstrings and subroutines with new subroutine numbers
|
|
|
|
*
|
|
|
|
* Phases #1 and #2 are done at the same time in collect_subrs ().
|
2018-11-02 23:28:01 +01:00
|
|
|
* Phase #3 walks charstrings/subroutines forward then backward (hence parsing required),
|
|
|
|
* because we can't tell if a number belongs to a hint op until we see the first moveto.
|
2018-11-01 06:30:34 +01:00
|
|
|
*
|
|
|
|
* Assumption: a callsubr/callgsubr operator must immediately follow a (biased) subroutine number
|
|
|
|
* within the same charstring/subroutine, e.g., not split across a charstring and a subroutine.
|
|
|
|
*/
|
2019-01-31 23:16:37 +01:00
|
|
|
bool subset (void)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-25 19:04:44 +01:00
|
|
|
unsigned fd_count = acc.fdCount;
|
2022-11-30 01:04:16 +01:00
|
|
|
const cff_subset_accelerator_t* cff_accelerator = nullptr;
|
2022-11-25 19:04:44 +01:00
|
|
|
if (plan->accelerator && plan->accelerator->cff_accelerator) {
|
|
|
|
cff_accelerator = plan->accelerator->cff_accelerator;
|
|
|
|
fd_count = cff_accelerator->parsed_local_subrs.length;
|
|
|
|
}
|
|
|
|
|
2022-11-28 19:39:24 +01:00
|
|
|
if (cff_accelerator) {
|
2022-11-26 00:17:05 +01:00
|
|
|
// If we are not dropping hinting then charstrings are not modified so we can
|
|
|
|
// just use a reference to the cached copies.
|
2023-01-03 02:05:43 +01:00
|
|
|
cached_charstrings.resize_exact (plan->num_output_glyphs ());
|
2022-11-28 21:35:34 +01:00
|
|
|
parsed_global_subrs = &cff_accelerator->parsed_global_subrs;
|
|
|
|
parsed_local_subrs = &cff_accelerator->parsed_local_subrs;
|
2022-11-26 00:17:05 +01:00
|
|
|
} else {
|
2023-01-03 02:05:43 +01:00
|
|
|
parsed_charstrings.resize_exact (plan->num_output_glyphs ());
|
|
|
|
parsed_global_subrs_storage.resize_exact (acc.globalSubrs->count);
|
2022-11-28 21:35:34 +01:00
|
|
|
|
|
|
|
if (unlikely (!parsed_local_subrs_storage.resize (fd_count))) return false;
|
2022-11-26 00:17:05 +01:00
|
|
|
|
2022-11-28 21:35:34 +01:00
|
|
|
for (unsigned int i = 0; i < acc.fdCount; i++)
|
|
|
|
{
|
|
|
|
unsigned count = acc.privateDicts[i].localSubrs->count;
|
|
|
|
parsed_local_subrs_storage[i].resize (count);
|
|
|
|
if (unlikely (parsed_local_subrs_storage[i].in_error ())) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
parsed_global_subrs = &parsed_global_subrs_storage;
|
|
|
|
parsed_local_subrs = &parsed_local_subrs_storage;
|
|
|
|
}
|
2022-11-26 00:17:05 +01:00
|
|
|
|
|
|
|
if (unlikely (remaps.in_error()
|
|
|
|
|| cached_charstrings.in_error ()
|
|
|
|
|| parsed_charstrings.in_error ()
|
2022-11-28 21:35:34 +01:00
|
|
|
|| parsed_global_subrs->in_error ()
|
|
|
|
|| closures.in_error ())) {
|
2022-11-26 00:17:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-11-25 19:04:44 +01:00
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
/* phase 1 & 2 */
|
2019-01-31 23:16:37 +01:00
|
|
|
for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2019-01-31 23:16:37 +01:00
|
|
|
hb_codepoint_t glyph;
|
|
|
|
if (!plan->old_gid_for_new_gid (i, &glyph))
|
2022-11-26 00:17:05 +01:00
|
|
|
continue;
|
2022-11-23 23:24:39 +01:00
|
|
|
|
2022-05-10 00:09:56 +02:00
|
|
|
const hb_ubytes_t str = (*acc.charStrings)[glyph];
|
2018-11-01 06:30:34 +01:00
|
|
|
unsigned int fd = acc.fdSelect->get_fd (glyph);
|
2018-12-13 02:36:01 +01:00
|
|
|
if (unlikely (fd >= acc.fdCount))
|
2022-11-26 00:17:05 +01:00
|
|
|
return false;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2022-11-25 19:04:44 +01:00
|
|
|
if (cff_accelerator)
|
2022-11-23 23:24:39 +01:00
|
|
|
{
|
|
|
|
// parsed string already exists in accelerator, copy it and move
|
|
|
|
// on.
|
2022-11-26 00:17:05 +01:00
|
|
|
if (cached_charstrings)
|
|
|
|
cached_charstrings[i] = &cff_accelerator->parsed_charstrings[glyph];
|
|
|
|
else
|
|
|
|
parsed_charstrings[i] = cff_accelerator->parsed_charstrings[glyph];
|
|
|
|
|
2022-11-23 23:24:39 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-05-11 00:33:37 +02:00
|
|
|
ENV env (str, acc, fd);
|
|
|
|
cs_interpreter_t<ENV, OPSET, subr_subset_param_t> interp (env);
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-12-31 21:18:32 +01:00
|
|
|
parsed_charstrings[i].alloc (str.length);
|
2022-05-10 23:38:37 +02:00
|
|
|
subr_subset_param_t param (&parsed_charstrings[i],
|
2022-11-28 21:35:34 +01:00
|
|
|
&parsed_global_subrs_storage,
|
|
|
|
&parsed_local_subrs_storage[fd],
|
2022-11-26 00:17:05 +01:00
|
|
|
&closures.global_closure,
|
|
|
|
&closures.local_closures[fd],
|
|
|
|
plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
2018-11-01 06:30:34 +01:00
|
|
|
|
|
|
|
if (unlikely (!interp.interpret (param)))
|
2022-11-26 00:17:05 +01:00
|
|
|
return false;
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2019-02-21 00:48:29 +01:00
|
|
|
/* complete parsed string esp. copy CFF1 width or CFF2 vsindex to the parsed charstring for encoding */
|
|
|
|
SUBSETTER::complete_parsed_str (interp.env, param, parsed_charstrings[i]);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
/* mark hint ops and arguments for drop */
|
2023-01-02 02:58:08 +01:00
|
|
|
if ((plan->flags & HB_SUBSET_FLAGS_NO_HINTING) || plan->inprogress_accelerator)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-05-10 23:38:37 +02:00
|
|
|
subr_subset_param_t param (&parsed_charstrings[i],
|
2022-11-28 21:35:34 +01:00
|
|
|
&parsed_global_subrs_storage,
|
|
|
|
&parsed_local_subrs_storage[fd],
|
2022-05-10 23:38:37 +02:00
|
|
|
&closures.global_closure,
|
|
|
|
&closures.local_closures[fd],
|
|
|
|
plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
2018-12-01 05:04:59 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
drop_hints_param_t drop;
|
2018-12-01 05:04:59 +01:00
|
|
|
if (drop_hints_in_str (parsed_charstrings[i], param, drop))
|
|
|
|
{
|
|
|
|
parsed_charstrings[i].set_hint_dropped ();
|
|
|
|
if (drop.vsindex_dropped)
|
|
|
|
parsed_charstrings[i].set_vsindex_dropped ();
|
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
2023-01-02 03:00:04 +01:00
|
|
|
|
|
|
|
/* Doing this here one by one instead of compacting all at the en
|
2023-01-02 18:38:30 +01:00
|
|
|
* has massive peak-memory saving.
|
|
|
|
*
|
|
|
|
* The compacting both saves memory and makes further operations
|
|
|
|
* faster.
|
|
|
|
*/
|
2023-01-03 01:33:04 +01:00
|
|
|
parsed_charstrings[i].compact ();
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2023-01-02 18:38:30 +01:00
|
|
|
/* Since parsed strings were loaded from accelerator, we still need
|
|
|
|
* to compute the subroutine closures which would have normally happened during
|
|
|
|
* parsing.
|
|
|
|
*
|
|
|
|
* Or if we are dropping hinting, redo closure to get actually used subrs.
|
|
|
|
*/
|
2023-01-02 02:58:08 +01:00
|
|
|
if ((cff_accelerator ||
|
|
|
|
(!cff_accelerator && plan->flags & HB_SUBSET_FLAGS_NO_HINTING)) &&
|
|
|
|
!closure_subroutines(*parsed_global_subrs,
|
|
|
|
*parsed_local_subrs))
|
|
|
|
return false;
|
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
remaps.create (closures);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2022-12-02 02:49:09 +01:00
|
|
|
populate_subset_accelerator ();
|
2018-11-01 06:30:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-31 23:16:37 +01:00
|
|
|
bool encode_charstrings (str_buff_vec_t &buffArray) const
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2023-01-03 02:05:43 +01:00
|
|
|
if (unlikely (!buffArray.resize_exact (plan->num_output_glyphs ())))
|
2018-11-01 06:30:34 +01:00
|
|
|
return false;
|
2019-01-31 23:16:37 +01:00
|
|
|
for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2019-01-31 23:16:37 +01:00
|
|
|
hb_codepoint_t glyph;
|
|
|
|
if (!plan->old_gid_for_new_gid (i, &glyph))
|
|
|
|
{
|
2019-12-31 13:23:02 +01:00
|
|
|
/* add an endchar only charstring for a missing glyph if CFF1 */
|
2022-12-02 05:48:35 +01:00
|
|
|
if (endchar_op != OpCode_Invalid) buffArray.arrayZ[i].push (endchar_op);
|
2019-12-31 13:23:02 +01:00
|
|
|
continue;
|
2019-01-31 23:16:37 +01:00
|
|
|
}
|
|
|
|
unsigned int fd = acc.fdSelect->get_fd (glyph);
|
2018-12-13 02:36:01 +01:00
|
|
|
if (unlikely (fd >= acc.fdCount))
|
2019-12-31 13:23:02 +01:00
|
|
|
return false;
|
2022-12-02 05:48:35 +01:00
|
|
|
if (unlikely (!encode_str (get_parsed_charstring (i), fd, buffArray.arrayZ[i])))
|
2018-12-01 05:04:59 +01:00
|
|
|
return false;
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
bool encode_subrs (const parsed_cs_str_vec_t &subrs, const subr_remap_t& remap, unsigned int fd, str_buff_vec_t &buffArray) const
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2019-06-18 07:12:40 +02:00
|
|
|
unsigned int count = remap.get_population ();
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2023-01-03 02:05:43 +01:00
|
|
|
if (unlikely (!buffArray.resize_exact (count)))
|
2018-11-01 06:30:34 +01:00
|
|
|
return false;
|
2022-12-02 21:58:36 +01:00
|
|
|
for (unsigned int new_num = 0; new_num < count; new_num++)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-12-02 21:58:36 +01:00
|
|
|
hb_codepoint_t old_num = remap.backward (new_num);
|
|
|
|
assert (old_num != CFF_UNDEF_CODE);
|
|
|
|
|
|
|
|
if (unlikely (!encode_str (subrs[old_num], fd, buffArray[new_num])))
|
|
|
|
return false;
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
bool encode_globalsubrs (str_buff_vec_t &buffArray)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-28 21:35:34 +01:00
|
|
|
return encode_subrs (*parsed_global_subrs, remaps.global_remap, 0, buffArray);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
bool encode_localsubrs (unsigned int fd, str_buff_vec_t &buffArray) const
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-28 21:35:34 +01:00
|
|
|
return encode_subrs ((*parsed_local_subrs)[fd], remaps.local_remaps[fd], fd, buffArray);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-12-22 16:47:04 +01:00
|
|
|
struct drop_hints_param_t
|
2018-11-07 23:48:37 +01:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
drop_hints_param_t ()
|
2018-11-07 23:48:37 +01:00
|
|
|
: seen_moveto (false),
|
2018-12-01 05:04:59 +01:00
|
|
|
ends_in_hint (false),
|
2019-02-13 00:10:43 +01:00
|
|
|
all_dropped (false),
|
2018-12-01 05:04:59 +01:00
|
|
|
vsindex_dropped (false) {}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-07 23:48:37 +01:00
|
|
|
bool seen_moveto;
|
|
|
|
bool ends_in_hint;
|
2019-02-13 00:10:43 +01:00
|
|
|
bool all_dropped;
|
2018-11-07 23:48:37 +01:00
|
|
|
bool vsindex_dropped;
|
|
|
|
};
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
bool drop_hints_in_subr (parsed_cs_str_t &str, unsigned int pos,
|
|
|
|
parsed_cs_str_vec_t &subrs, unsigned int subr_num,
|
|
|
|
const subr_subset_param_t ¶m, drop_hints_param_t &drop)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-11-07 23:48:37 +01:00
|
|
|
drop.ends_in_hint = false;
|
|
|
|
bool has_hint = drop_hints_in_str (subrs[subr_num], param, drop);
|
2018-11-02 23:28:01 +01:00
|
|
|
|
2019-02-13 00:10:43 +01:00
|
|
|
/* if this subr ends with a stem hint (i.e., not a number; potential argument for moveto),
|
2018-11-02 23:28:01 +01:00
|
|
|
* then this entire subroutine must be a hint. drop its call. */
|
2018-11-07 23:48:37 +01:00
|
|
|
if (drop.ends_in_hint)
|
2018-11-08 02:58:45 +01:00
|
|
|
{
|
2022-11-28 20:28:13 +01:00
|
|
|
str.values[pos].set_hinting ();
|
2018-11-08 02:58:45 +01:00
|
|
|
/* if this subr call is at the end of the parent subr, propagate the flag
|
|
|
|
* otherwise reset the flag */
|
|
|
|
if (!str.at_end (pos))
|
2018-12-01 05:04:59 +01:00
|
|
|
drop.ends_in_hint = false;
|
2018-11-08 02:58:45 +01:00
|
|
|
}
|
2019-02-13 00:10:43 +01:00
|
|
|
else if (drop.all_dropped)
|
|
|
|
{
|
2022-11-28 20:28:13 +01:00
|
|
|
str.values[pos].set_hinting ();
|
2019-02-13 00:10:43 +01:00
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-02 23:28:01 +01:00
|
|
|
return has_hint;
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 23:28:01 +01:00
|
|
|
/* returns true if it sees a hint op before the first moveto */
|
2018-12-22 16:47:04 +01:00
|
|
|
bool drop_hints_in_str (parsed_cs_str_t &str, const subr_subset_param_t ¶m, drop_hints_param_t &drop)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
bool seen_hint = false;
|
|
|
|
|
2022-11-27 22:54:39 +01:00
|
|
|
unsigned count = str.values.length;
|
|
|
|
auto *values = str.values.arrayZ;
|
|
|
|
for (unsigned int pos = 0; pos < count; pos++)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-11-02 23:28:01 +01:00
|
|
|
bool has_hint = false;
|
2022-11-27 22:54:39 +01:00
|
|
|
switch (values[pos].op)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
case OpCode_callsubr:
|
|
|
|
has_hint = drop_hints_in_subr (str, pos,
|
2022-11-27 22:54:39 +01:00
|
|
|
*param.parsed_local_subrs, values[pos].subr_num,
|
2018-12-01 05:04:59 +01:00
|
|
|
param, drop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OpCode_callgsubr:
|
|
|
|
has_hint = drop_hints_in_subr (str, pos,
|
2022-11-27 22:54:39 +01:00
|
|
|
*param.parsed_global_subrs, values[pos].subr_num,
|
2018-12-01 05:04:59 +01:00
|
|
|
param, drop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OpCode_rmoveto:
|
|
|
|
case OpCode_hmoveto:
|
|
|
|
case OpCode_vmoveto:
|
|
|
|
drop.seen_moveto = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OpCode_hintmask:
|
|
|
|
case OpCode_cntrmask:
|
|
|
|
if (drop.seen_moveto)
|
|
|
|
{
|
2022-11-28 20:28:13 +01:00
|
|
|
values[pos].set_hinting ();
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
HB_FALLTHROUGH;
|
|
|
|
|
|
|
|
case OpCode_hstemhm:
|
|
|
|
case OpCode_vstemhm:
|
|
|
|
case OpCode_hstem:
|
|
|
|
case OpCode_vstem:
|
|
|
|
has_hint = true;
|
2022-11-28 20:28:13 +01:00
|
|
|
values[pos].set_hinting ();
|
2018-12-01 05:04:59 +01:00
|
|
|
if (str.at_end (pos))
|
|
|
|
drop.ends_in_hint = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OpCode_dotsection:
|
2022-11-28 20:28:13 +01:00
|
|
|
values[pos].set_hinting ();
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* NONE */
|
|
|
|
break;
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
2018-11-02 23:28:01 +01:00
|
|
|
if (has_hint)
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
for (int i = pos - 1; i >= 0; i--)
|
|
|
|
{
|
2022-11-27 22:54:39 +01:00
|
|
|
parsed_cs_op_t &csop = values[(unsigned)i];
|
2022-11-28 20:28:13 +01:00
|
|
|
if (csop.is_hinting ())
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
2022-11-28 20:28:13 +01:00
|
|
|
csop.set_hinting ();
|
2018-12-01 05:04:59 +01:00
|
|
|
if (csop.op == OpCode_vsindexcs)
|
|
|
|
drop.vsindex_dropped = true;
|
|
|
|
}
|
|
|
|
seen_hint |= has_hint;
|
2018-11-02 23:28:01 +01:00
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2019-02-13 00:10:43 +01:00
|
|
|
/* Raise all_dropped flag if all operators except return are dropped from a subr.
|
|
|
|
* It may happen even after seeing the first moveto if a subr contains
|
|
|
|
* only (usually one) hintmask operator, then calls to this subr can be dropped.
|
|
|
|
*/
|
|
|
|
drop.all_dropped = true;
|
2022-11-27 22:54:39 +01:00
|
|
|
for (unsigned int pos = 0; pos < count; pos++)
|
2019-02-13 00:10:43 +01:00
|
|
|
{
|
2022-11-27 22:54:39 +01:00
|
|
|
parsed_cs_op_t &csop = values[pos];
|
2019-02-13 00:10:43 +01:00
|
|
|
if (csop.op == OpCode_return)
|
2019-12-31 13:23:02 +01:00
|
|
|
break;
|
2022-11-28 20:28:13 +01:00
|
|
|
if (!csop.is_hinting ())
|
2019-02-13 00:10:43 +01:00
|
|
|
{
|
2019-12-31 13:23:02 +01:00
|
|
|
drop.all_dropped = false;
|
|
|
|
break;
|
2019-02-13 00:10:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
return seen_hint;
|
|
|
|
}
|
|
|
|
|
2022-12-02 21:41:06 +01:00
|
|
|
bool closure_subroutines (const parsed_cs_str_vec_t& global_subrs,
|
2022-11-30 01:04:16 +01:00
|
|
|
const hb_vector_t<parsed_cs_str_vec_t>& local_subrs)
|
2022-11-23 23:24:39 +01:00
|
|
|
{
|
|
|
|
closures.reset ();
|
|
|
|
for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t glyph;
|
|
|
|
if (!plan->old_gid_for_new_gid (i, &glyph))
|
|
|
|
continue;
|
|
|
|
unsigned int fd = acc.fdSelect->get_fd (glyph);
|
|
|
|
if (unlikely (fd >= acc.fdCount))
|
|
|
|
return false;
|
2022-11-30 01:04:16 +01:00
|
|
|
|
|
|
|
// Note: const cast is safe here because the collect_subr_refs_in_str only performs a
|
|
|
|
// closure and does not modify any of the charstrings.
|
|
|
|
subr_subset_param_t param (const_cast<parsed_cs_str_t*> (&get_parsed_charstring (i)),
|
|
|
|
const_cast<parsed_cs_str_vec_t*> (&global_subrs),
|
|
|
|
const_cast<parsed_cs_str_vec_t*> (&local_subrs[fd]),
|
2022-11-23 23:24:39 +01:00
|
|
|
&closures.global_closure,
|
|
|
|
&closures.local_closures[fd],
|
|
|
|
plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
2022-12-02 21:41:06 +01:00
|
|
|
collect_subr_refs_in_str (get_parsed_charstring (i), param);
|
2022-11-23 23:24:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-02 21:41:06 +01:00
|
|
|
void collect_subr_refs_in_subr (unsigned int subr_num, parsed_cs_str_vec_t &subrs,
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_set_t *closure,
|
2018-12-22 16:47:04 +01:00
|
|
|
const subr_subset_param_t ¶m)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-22 06:26:44 +01:00
|
|
|
if (closure->has (subr_num))
|
|
|
|
return;
|
2019-10-08 11:54:26 +02:00
|
|
|
closure->add (subr_num);
|
2022-12-02 21:41:06 +01:00
|
|
|
collect_subr_refs_in_str (subrs[subr_num], param);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 21:41:06 +01:00
|
|
|
void collect_subr_refs_in_str (const parsed_cs_str_t &str,
|
2022-11-30 01:04:16 +01:00
|
|
|
const subr_subset_param_t ¶m)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-27 01:49:21 +01:00
|
|
|
if (!str.has_calls ())
|
|
|
|
return;
|
|
|
|
|
2022-12-02 04:08:59 +01:00
|
|
|
for (auto &opstr : str.values)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-12-02 21:41:06 +01:00
|
|
|
if (!param.drop_hints || !opstr.is_hinting ())
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-12-02 04:08:59 +01:00
|
|
|
switch (opstr.op)
|
2018-12-01 05:04:59 +01:00
|
|
|
{
|
|
|
|
case OpCode_callsubr:
|
2022-12-02 21:41:06 +01:00
|
|
|
collect_subr_refs_in_subr (opstr.subr_num, *param.parsed_local_subrs,
|
2018-12-01 05:04:59 +01:00
|
|
|
param.local_closure, param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OpCode_callgsubr:
|
2022-12-02 21:41:06 +01:00
|
|
|
collect_subr_refs_in_subr (opstr.subr_num, *param.parsed_global_subrs,
|
2018-12-01 05:04:59 +01:00
|
|
|
param.global_closure, param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
bool encode_str (const parsed_cs_str_t &str, const unsigned int fd, str_buff_t &buff) const
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
str_encoder_t encoder (buff);
|
2018-11-01 06:30:34 +01:00
|
|
|
encoder.reset ();
|
2022-11-28 19:39:24 +01:00
|
|
|
bool hinting = !(plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
2018-11-01 06:30:34 +01:00
|
|
|
/* if a prefix (CFF1 width or CFF2 vsindex) has been removed along with hints,
|
|
|
|
* re-insert it at the beginning of charstreing */
|
2022-11-28 19:39:24 +01:00
|
|
|
if (str.has_prefix () && !hinting && str.is_hint_dropped ())
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
encoder.encode_num (str.prefix_num ());
|
|
|
|
if (str.prefix_op () != OpCode_Invalid)
|
2018-12-01 05:04:59 +01:00
|
|
|
encoder.encode_op (str.prefix_op ());
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
2022-12-02 03:43:48 +01:00
|
|
|
|
|
|
|
unsigned size = 0;
|
2022-12-02 04:08:59 +01:00
|
|
|
for (auto &opstr : str.values)
|
2022-12-02 04:02:38 +01:00
|
|
|
{
|
2022-12-02 04:08:59 +01:00
|
|
|
size += opstr.length;
|
|
|
|
if (opstr.op == OpCode_callsubr || opstr.op == OpCode_callgsubr)
|
2022-12-02 04:02:38 +01:00
|
|
|
size += 3;
|
|
|
|
}
|
2022-12-31 21:55:41 +01:00
|
|
|
if (!buff.alloc (buff.length + size, true))
|
2022-12-02 04:02:38 +01:00
|
|
|
return false;
|
2022-12-02 03:43:48 +01:00
|
|
|
|
2022-12-02 04:08:59 +01:00
|
|
|
for (auto &opstr : str.values)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2022-11-28 20:28:13 +01:00
|
|
|
if (hinting || !opstr.is_hinting ())
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
switch (opstr.op)
|
|
|
|
{
|
|
|
|
case OpCode_callsubr:
|
|
|
|
encoder.encode_int (remaps.local_remaps[fd].biased_num (opstr.subr_num));
|
2022-12-02 04:05:20 +01:00
|
|
|
encoder.copy_str (opstr.ptr, opstr.length);
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OpCode_callgsubr:
|
|
|
|
encoder.encode_int (remaps.global_remap.biased_num (opstr.subr_num));
|
2022-12-02 04:05:20 +01:00
|
|
|
encoder.copy_str (opstr.ptr, opstr.length);
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-11-22 05:37:38 +01:00
|
|
|
encoder.copy_str (opstr.ptr, opstr.length);
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-24 22:02:46 +01:00
|
|
|
return !encoder.in_error ();
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
|
2023-01-02 03:00:04 +01:00
|
|
|
void compact_parsed_subrs () const
|
2022-12-02 02:49:09 +01:00
|
|
|
{
|
|
|
|
for (auto &cs : parsed_global_subrs_storage)
|
2023-01-02 20:05:11 +01:00
|
|
|
cs.compact ();
|
2022-12-02 02:49:09 +01:00
|
|
|
for (auto &vec : parsed_local_subrs_storage)
|
|
|
|
for (auto &cs : vec)
|
2023-01-02 20:05:11 +01:00
|
|
|
cs.compact ();
|
2022-12-02 02:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void populate_subset_accelerator () const
|
2022-11-23 22:02:39 +01:00
|
|
|
{
|
|
|
|
if (!plan->inprogress_accelerator) return;
|
|
|
|
|
2023-01-02 03:00:04 +01:00
|
|
|
compact_parsed_subrs ();
|
2022-12-02 02:49:09 +01:00
|
|
|
|
2022-11-23 22:02:39 +01:00
|
|
|
plan->inprogress_accelerator->cff_accelerator =
|
2022-11-25 21:33:39 +01:00
|
|
|
cff_subset_accelerator_t::create(acc.blob,
|
2022-11-24 23:47:29 +01:00
|
|
|
parsed_charstrings,
|
2022-11-28 21:35:34 +01:00
|
|
|
parsed_global_subrs_storage,
|
|
|
|
parsed_local_subrs_storage);
|
2022-11-25 19:38:13 +01:00
|
|
|
plan->inprogress_accelerator->destroy_cff_accelerator =
|
|
|
|
cff_subset_accelerator_t::destroy;
|
2022-11-23 22:02:39 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 00:17:05 +01:00
|
|
|
const parsed_cs_str_t& get_parsed_charstring (unsigned i) const
|
|
|
|
{
|
|
|
|
if (cached_charstrings) return *(cached_charstrings[i]);
|
|
|
|
return parsed_charstrings[i];
|
|
|
|
}
|
|
|
|
|
2018-11-01 06:30:34 +01:00
|
|
|
protected:
|
2019-12-31 13:23:02 +01:00
|
|
|
const ACC &acc;
|
2019-01-31 23:16:37 +01:00
|
|
|
const hb_subset_plan_t *plan;
|
|
|
|
|
|
|
|
subr_closures_t closures;
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2022-11-30 01:04:16 +01:00
|
|
|
hb_vector_t<const parsed_cs_str_t*> cached_charstrings;
|
|
|
|
const parsed_cs_str_vec_t* parsed_global_subrs;
|
|
|
|
const hb_vector_t<parsed_cs_str_vec_t>* parsed_local_subrs;
|
2018-11-01 06:30:34 +01:00
|
|
|
|
2019-02-22 01:34:49 +01:00
|
|
|
subr_remaps_t remaps;
|
2018-11-01 06:30:34 +01:00
|
|
|
|
|
|
|
private:
|
2022-11-28 21:35:34 +01:00
|
|
|
|
2022-11-30 01:04:16 +01:00
|
|
|
parsed_cs_str_vec_t parsed_charstrings;
|
2022-11-28 21:35:34 +01:00
|
|
|
parsed_cs_str_vec_t parsed_global_subrs_storage;
|
|
|
|
hb_vector_t<parsed_cs_str_vec_t> parsed_local_subrs_storage;
|
2018-11-01 06:30:34 +01:00
|
|
|
typedef typename SUBRS::count_type subr_count_type;
|
|
|
|
};
|
2018-12-24 02:19:52 +01:00
|
|
|
|
|
|
|
} /* namespace CFF */
|
2018-08-06 19:04:53 +02:00
|
|
|
|
|
|
|
HB_INTERNAL bool
|
2019-01-31 23:16:37 +01:00
|
|
|
hb_plan_subset_cff_fdselect (const hb_subset_plan_t *plan,
|
2018-12-01 05:04:59 +01:00
|
|
|
unsigned int fdCount,
|
|
|
|
const CFF::FDSelect &src, /* IN */
|
|
|
|
unsigned int &subset_fd_count /* OUT */,
|
|
|
|
unsigned int &subset_fdselect_size /* OUT */,
|
|
|
|
unsigned int &subset_fdselect_format /* OUT */,
|
2018-12-22 16:47:04 +01:00
|
|
|
hb_vector_t<CFF::code_pair_t> &fdselect_ranges /* OUT */,
|
2019-06-18 07:12:40 +02:00
|
|
|
hb_inc_bimap_t &fdmap /* OUT */);
|
2018-08-06 19:04:53 +02:00
|
|
|
|
|
|
|
HB_INTERNAL bool
|
|
|
|
hb_serialize_cff_fdselect (hb_serialize_context_t *c,
|
2018-12-01 05:04:59 +01:00
|
|
|
unsigned int num_glyphs,
|
|
|
|
const CFF::FDSelect &src,
|
|
|
|
unsigned int fd_count,
|
|
|
|
unsigned int fdselect_format,
|
|
|
|
unsigned int size,
|
2018-12-22 16:47:04 +01:00
|
|
|
const hb_vector_t<CFF::code_pair_t> &fdselect_ranges);
|
2018-08-06 19:04:53 +02:00
|
|
|
|
2018-08-29 22:36:39 +02:00
|
|
|
#endif /* HB_SUBSET_CFF_COMMON_HH */
|