2018-07-18 23:17:52 +02:00
|
|
|
/*
|
2018-11-12 17:47:07 +01:00
|
|
|
* Copyright © 2018 Adobe Inc.
|
2018-07-18 23:17:52 +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_OT_CFF2_TABLE_HH
|
|
|
|
#define HB_OT_CFF2_TABLE_HH
|
|
|
|
|
2018-08-29 22:26:17 +02:00
|
|
|
#include "hb-ot-cff-common.hh"
|
2018-07-18 23:17:52 +02:00
|
|
|
#include "hb-subset-cff2.hh"
|
2020-02-26 15:10:44 +01:00
|
|
|
#include "hb-draw.hh"
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
namespace CFF {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CFF2 -- Compact Font Format (CFF) Version 2
|
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/cff2
|
|
|
|
*/
|
|
|
|
#define HB_OT_TAG_cff2 HB_TAG('C','F','F','2')
|
|
|
|
|
2018-08-16 17:03:46 +02:00
|
|
|
typedef CFFIndex<HBUINT32> CFF2Index;
|
2018-09-07 02:28:15 +02:00
|
|
|
template <typename Type> struct CFF2IndexOf : CFFIndexOf<HBUINT32, Type> {};
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
typedef CFF2Index CFF2CharStrings;
|
2018-08-15 21:00:19 +02:00
|
|
|
typedef Subrs<HBUINT32> CFF2Subrs;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
typedef FDSelect3_4<HBUINT32, HBUINT16> FDSelect4;
|
|
|
|
typedef FDSelect3_4_Range<HBUINT32, HBUINT16> FDSelect4_Range;
|
|
|
|
|
|
|
|
struct CFF2FDSelect
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs)
|
2018-08-06 19:04:53 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
unsigned int size = src.get_size (num_glyphs);
|
|
|
|
CFF2FDSelect *dest = c->allocate_size<CFF2FDSelect> (size);
|
2020-04-20 21:18:23 +02:00
|
|
|
if (unlikely (!dest)) return_trace (false);
|
2018-08-06 19:04:53 +02:00
|
|
|
memcpy (dest, &src, size);
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_size (unsigned int num_glyphs) const
|
2018-08-06 19:04:53 +02:00
|
|
|
{
|
2019-06-09 09:19:25 +02:00
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case 0: return format.static_size + u.format0.get_size (num_glyphs);
|
|
|
|
case 3: return format.static_size + u.format3.get_size ();
|
|
|
|
case 4: return format.static_size + u.format4.get_size ();
|
|
|
|
default:return 0;
|
|
|
|
}
|
2018-08-06 19:04:53 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_fd (hb_codepoint_t glyph) const
|
2018-08-06 19:04:53 +02:00
|
|
|
{
|
2019-06-09 09:19:25 +02:00
|
|
|
if (this == &Null (CFF2FDSelect))
|
2018-08-15 21:00:19 +02:00
|
|
|
return 0;
|
2019-06-09 09:19:25 +02:00
|
|
|
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case 0: return u.format0.get_fd (glyph);
|
|
|
|
case 3: return u.format3.get_fd (glyph);
|
|
|
|
case 4: return u.format4.get_fd (glyph);
|
|
|
|
default:return 0;
|
|
|
|
}
|
2018-08-06 19:04:53 +02:00
|
|
|
}
|
|
|
|
|
2019-06-09 09:19:25 +02:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
if (unlikely (!c->check_struct (this)))
|
|
|
|
return_trace (false);
|
|
|
|
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case 0: return_trace (u.format0.sanitize (c, fdcount));
|
|
|
|
case 3: return_trace (u.format3.sanitize (c, fdcount));
|
|
|
|
case 4: return_trace (u.format4.sanitize (c, fdcount));
|
|
|
|
default:return_trace (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HBUINT8 format;
|
2018-08-06 19:04:53 +02:00
|
|
|
union {
|
2019-06-09 09:19:25 +02:00
|
|
|
FDSelect0 format0;
|
|
|
|
FDSelect3 format3;
|
|
|
|
FDSelect4 format4;
|
2018-08-06 19:04:53 +02:00
|
|
|
} u;
|
2019-06-09 09:19:25 +02:00
|
|
|
public:
|
2018-08-06 19:04:53 +02:00
|
|
|
DEFINE_SIZE_MIN (2);
|
|
|
|
};
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
struct CFF2VariationStore
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-12-06 02:04:55 +01:00
|
|
|
return_trace (likely (c->check_struct (this)) && c->check_range (&varStore, size) && varStore.sanitize (c));
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const CFF2VariationStore *varStore)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-02 20:22:42 +02:00
|
|
|
TRACE_SERIALIZE (this);
|
2018-08-02 01:06:52 +02:00
|
|
|
unsigned int size_ = varStore->get_size ();
|
|
|
|
CFF2VariationStore *dest = c->allocate_size<CFF2VariationStore> (size_);
|
2020-04-20 21:18:23 +02:00
|
|
|
if (unlikely (!dest)) return_trace (false);
|
2018-08-02 01:06:52 +02:00
|
|
|
memcpy (dest, varStore, size_);
|
2018-08-01 20:30:38 +02:00
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const { return HBUINT16::static_size + size; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-12-01 05:04:59 +01:00
|
|
|
HBUINT16 size;
|
2018-08-01 20:30:38 +02:00
|
|
|
VariationStore varStore;
|
|
|
|
|
|
|
|
DEFINE_SIZE_MIN (2 + VariationStore::min_size);
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_top_dict_values_t : top_dict_values_t<>
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
top_dict_values_t<>::init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
vstoreOffset = 0;
|
|
|
|
FDSelectOffset = 0;
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
2018-12-22 16:47:04 +01:00
|
|
|
void fini () { top_dict_values_t<>::fini (); }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
unsigned int vstoreOffset;
|
|
|
|
unsigned int FDSelectOffset;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_top_dict_opset_t : top_dict_opset_t<>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, num_interp_env_t& env, cff2_top_dict_values_t& dictval)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
switch (op) {
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_FontMatrix:
|
2018-12-01 05:04:59 +01:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
dict_val_t val;
|
2018-12-01 05:04:59 +01:00
|
|
|
val.init ();
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.add_op (op, env.str_ref);
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
}
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
case OpCode_vstore:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.vstoreOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-07-18 23:17:52 +02:00
|
|
|
case OpCode_FDSelect:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.FDSelectOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
default:
|
2018-12-01 05:04:59 +01:00
|
|
|
SUPER::process_op (op, env, dictval);
|
|
|
|
/* Record this operand below if stack is empty, otherwise done */
|
|
|
|
if (!env.argStack.is_empty ()) return;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-10-12 11:16:07 +02:00
|
|
|
if (unlikely (env.in_error ())) return;
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.add_op (op, env.str_ref);
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-09-01 01:28:47 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef top_dict_opset_t<> SUPER;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_font_dict_values_t : dict_values_t<op_str_t>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
dict_values_t<op_str_t>::init ();
|
2020-03-05 07:31:21 +01:00
|
|
|
privateDictInfo.init ();
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-12-22 16:47:04 +01:00
|
|
|
void fini () { dict_values_t<op_str_t>::fini (); }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2020-03-05 07:31:21 +01:00
|
|
|
table_info_t privateDictInfo;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_font_dict_opset_t : dict_opset_t
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, num_interp_env_t& env, cff2_font_dict_values_t& dictval)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
switch (op) {
|
2018-07-18 23:17:52 +02:00
|
|
|
case OpCode_Private:
|
2020-03-05 07:31:21 +01:00
|
|
|
dictval.privateDictInfo.offset = env.argStack.pop_uint ();
|
|
|
|
dictval.privateDictInfo.size = env.argStack.pop_uint ();
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
default:
|
2018-12-01 05:04:59 +01:00
|
|
|
SUPER::process_op (op, env);
|
|
|
|
if (!env.argStack.is_empty ())
|
|
|
|
return;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-10-12 11:16:07 +02:00
|
|
|
if (unlikely (env.in_error ())) return;
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.add_op (op, env.str_ref);
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-09-01 01:28:47 +02:00
|
|
|
|
|
|
|
private:
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef dict_opset_t SUPER;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-03 23:35:09 +02:00
|
|
|
template <typename VAL>
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_private_dict_values_base_t : dict_values_t<VAL>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
dict_values_t<VAL>::init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
subrsOffset = 0;
|
2020-04-20 11:42:45 +02:00
|
|
|
localSubrs = &Null (CFF2Subrs);
|
2018-10-09 00:05:36 +02:00
|
|
|
ivs = 0;
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
2018-12-22 16:47:04 +01:00
|
|
|
void fini () { dict_values_t<VAL>::fini (); }
|
2018-08-03 01:28:10 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
unsigned int subrsOffset;
|
|
|
|
const CFF2Subrs *localSubrs;
|
2018-10-09 00:05:36 +02:00
|
|
|
unsigned int ivs;
|
2018-08-03 01:28:10 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef cff2_private_dict_values_base_t<op_str_t> cff2_private_dict_values_subset_t;
|
|
|
|
typedef cff2_private_dict_values_base_t<num_dict_val_t> cff2_private_dict_values_t;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_priv_dict_interp_env_t : num_interp_env_t
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
void init (const byte_str_t &str)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
num_interp_env_t::init (str);
|
2018-10-09 00:05:36 +02:00
|
|
|
ivs = 0;
|
|
|
|
seen_vsindex = false;
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void process_vsindex ()
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2018-10-12 11:16:07 +02:00
|
|
|
if (likely (!seen_vsindex))
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2018-10-12 11:16:07 +02:00
|
|
|
set_ivs (argStack.pop_uint ());
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
seen_vsindex = true;
|
|
|
|
}
|
|
|
|
|
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-10-09 00:05:36 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
unsigned int ivs;
|
2018-12-01 05:04:59 +01:00
|
|
|
bool seen_vsindex;
|
2018-10-09 00:05:36 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_private_dict_opset_t : dict_opset_t
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_private_dict_values_t& dictval)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
num_dict_val_t val;
|
2018-08-03 23:35:09 +02:00
|
|
|
val.init ();
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
switch (op) {
|
2018-07-18 23:17:52 +02:00
|
|
|
case OpCode_StdHW:
|
|
|
|
case OpCode_StdVW:
|
|
|
|
case OpCode_BlueScale:
|
|
|
|
case OpCode_BlueShift:
|
|
|
|
case OpCode_BlueFuzz:
|
2018-08-03 23:35:09 +02:00
|
|
|
case OpCode_ExpansionFactor:
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_LanguageGroup:
|
2018-12-01 05:04:59 +01:00
|
|
|
val.single_val = env.argStack.pop_num ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_BlueValues:
|
|
|
|
case OpCode_OtherBlues:
|
|
|
|
case OpCode_FamilyBlues:
|
|
|
|
case OpCode_FamilyOtherBlues:
|
|
|
|
case OpCode_StemSnapH:
|
|
|
|
case OpCode_StemSnapV:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-07-18 23:17:52 +02:00
|
|
|
case OpCode_Subrs:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.subrsOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-17 22:13:18 +02:00
|
|
|
case OpCode_vsindexdict:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.process_vsindex ();
|
|
|
|
dictval.ivs = env.get_ivs ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-15 21:00:19 +02:00
|
|
|
case OpCode_blenddict:
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
default:
|
2018-12-22 16:47:04 +01:00
|
|
|
dict_opset_t::process_op (op, env);
|
2018-12-01 05:04:59 +01:00
|
|
|
if (!env.argStack.is_empty ()) return;
|
|
|
|
break;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-10-12 11:16:07 +02:00
|
|
|
if (unlikely (env.in_error ())) return;
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.add_op (op, env.str_ref, val);
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff2_private_dict_opset_subset_t : dict_opset_t
|
2018-08-03 01:28:10 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_private_dict_values_subset_t& dictval)
|
2018-08-03 01:28:10 +02:00
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case OpCode_BlueValues:
|
|
|
|
case OpCode_OtherBlues:
|
|
|
|
case OpCode_FamilyBlues:
|
|
|
|
case OpCode_FamilyOtherBlues:
|
|
|
|
case OpCode_StdHW:
|
|
|
|
case OpCode_StdVW:
|
|
|
|
case OpCode_BlueScale:
|
|
|
|
case OpCode_BlueShift:
|
|
|
|
case OpCode_BlueFuzz:
|
|
|
|
case OpCode_StemSnapH:
|
|
|
|
case OpCode_StemSnapV:
|
|
|
|
case OpCode_LanguageGroup:
|
|
|
|
case OpCode_ExpansionFactor:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-03 01:28:10 +02:00
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
case OpCode_blenddict:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
return;
|
2018-08-03 23:35:09 +02:00
|
|
|
|
2018-08-03 01:28:10 +02:00
|
|
|
case OpCode_Subrs:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.subrsOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-03 01:28:10 +02:00
|
|
|
|
|
|
|
default:
|
2018-12-01 05:04:59 +01:00
|
|
|
SUPER::process_op (op, env);
|
|
|
|
if (!env.argStack.is_empty ()) return;
|
|
|
|
break;
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 11:16:07 +02:00
|
|
|
if (unlikely (env.in_error ())) return;
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.add_op (op, env.str_ref);
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
2018-09-01 01:28:47 +02:00
|
|
|
|
|
|
|
private:
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef dict_opset_t SUPER;
|
2018-08-03 01:28:10 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef dict_interpreter_t<cff2_top_dict_opset_t, cff2_top_dict_values_t> cff2_top_dict_interpreter_t;
|
|
|
|
typedef dict_interpreter_t<cff2_font_dict_opset_t, cff2_font_dict_values_t> cff2_font_dict_interpreter_t;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2020-03-03 01:51:19 +01:00
|
|
|
struct CFF2FDArray : FDArray<HBUINT32>
|
|
|
|
{
|
|
|
|
/* FDArray::serialize does not compile without this partial specialization */
|
|
|
|
template <typename ITER, typename OP_SERIALIZER>
|
|
|
|
bool serialize (hb_serialize_context_t *c, ITER it, OP_SERIALIZER& opszr)
|
|
|
|
{ return FDArray<HBUINT32>::serialize<cff2_font_dict_values_t, table_info_t> (c, it, opszr); }
|
|
|
|
};
|
|
|
|
|
2018-12-24 02:19:52 +01:00
|
|
|
} /* namespace CFF */
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
using namespace CFF;
|
|
|
|
|
|
|
|
struct cff2
|
|
|
|
{
|
2019-01-22 12:08:57 +01:00
|
|
|
static constexpr hb_tag_t tableTag = HB_OT_TAG_cff2;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
2018-12-01 05:04:59 +01:00
|
|
|
likely (version.major == 2));
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 01:28:47 +02:00
|
|
|
template <typename PRIVOPSET, typename PRIVDICTVAL>
|
2018-08-03 01:28:10 +02:00
|
|
|
struct accelerator_templ_t
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
void init (hb_face_t *face)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-10 20:07:07 +02:00
|
|
|
topDict.init ();
|
2018-08-01 20:30:38 +02:00
|
|
|
fontDicts.init ();
|
|
|
|
privateDicts.init ();
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
this->blob = sc.reference_table<cff2> (face);
|
|
|
|
|
|
|
|
/* setup for run-time santization */
|
|
|
|
sc.init (this->blob);
|
|
|
|
sc.start_processing ();
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-03 01:28:10 +02:00
|
|
|
const OT::cff2 *cff2 = this->blob->template as<OT::cff2> ();
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2020-04-20 11:42:45 +02:00
|
|
|
if (cff2 == &Null (OT::cff2))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
{ /* parse top dict */
|
2018-12-22 16:47:04 +01:00
|
|
|
byte_str_t topDictStr (cff2 + cff2->topDict, cff2->topDictSize);
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; }
|
2018-12-22 16:47:04 +01:00
|
|
|
cff2_top_dict_interpreter_t top_interp;
|
2018-12-01 05:04:59 +01:00
|
|
|
top_interp.env.init (topDictStr);
|
|
|
|
topDict.init ();
|
|
|
|
if (unlikely (!top_interp.interpret (topDict))) { fini (); return; }
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
globalSubrs = &StructAtOffset<CFF2Subrs> (cff2, cff2->topDict + cff2->topDictSize);
|
|
|
|
varStore = &StructAtOffsetOrNull<CFF2VariationStore> (cff2, topDict.vstoreOffset);
|
|
|
|
charStrings = &StructAtOffsetOrNull<CFF2CharStrings> (cff2, topDict.charStringsOffset);
|
|
|
|
fdArray = &StructAtOffsetOrNull<CFF2FDArray> (cff2, topDict.FDArrayOffset);
|
|
|
|
fdSelect = &StructAtOffsetOrNull<CFF2FDSelect> (cff2, topDict.FDSelectOffset);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2020-04-20 11:42:45 +02:00
|
|
|
if (((varStore != &Null (CFF2VariationStore)) && unlikely (!varStore->sanitize (&sc))) ||
|
|
|
|
(charStrings == &Null (CFF2CharStrings)) || unlikely (!charStrings->sanitize (&sc)) ||
|
|
|
|
(globalSubrs == &Null (CFF2Subrs)) || unlikely (!globalSubrs->sanitize (&sc)) ||
|
|
|
|
(fdArray == &Null (CFF2FDArray)) || unlikely (!fdArray->sanitize (&sc)) ||
|
|
|
|
(((fdSelect != &Null (CFF2FDSelect)) && unlikely (!fdSelect->sanitize (&sc, fdArray->count)))))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
num_glyphs = charStrings->count;
|
2018-08-01 20:30:38 +02:00
|
|
|
if (num_glyphs != sc.get_num_glyphs ())
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-17 22:13:18 +02:00
|
|
|
fdCount = fdArray->count;
|
2020-07-30 22:57:30 +02:00
|
|
|
if (!privateDicts.resize (fdCount))
|
|
|
|
{ fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
/* parse font dicts and gather private dicts */
|
2018-08-17 22:13:18 +02:00
|
|
|
for (unsigned int i = 0; i < fdCount; i++)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t fontDictStr = (*fdArray)[i];
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; }
|
2018-12-22 16:47:04 +01:00
|
|
|
cff2_font_dict_values_t *font;
|
|
|
|
cff2_font_dict_interpreter_t font_interp;
|
2018-12-01 05:04:59 +01:00
|
|
|
font_interp.env.init (fontDictStr);
|
|
|
|
font = fontDicts.push ();
|
2020-04-20 11:42:45 +02:00
|
|
|
if (unlikely (font == &Crap (cff2_font_dict_values_t))) { fini (); return; }
|
2018-12-01 05:04:59 +01:00
|
|
|
font->init ();
|
|
|
|
if (unlikely (!font_interp.interpret (*font))) { fini (); return; }
|
|
|
|
|
2020-03-05 07:31:21 +01:00
|
|
|
const byte_str_t privDictStr (StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset), font->privateDictInfo.size);
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; }
|
2018-12-22 16:47:04 +01:00
|
|
|
dict_interpreter_t<PRIVOPSET, PRIVDICTVAL, cff2_priv_dict_interp_env_t> priv_interp;
|
2018-12-01 05:04:59 +01:00
|
|
|
priv_interp.env.init(privDictStr);
|
|
|
|
privateDicts[i].init ();
|
|
|
|
if (unlikely (!priv_interp.interpret (privateDicts[i]))) { fini (); return; }
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (&privDictStr[0], privateDicts[i].subrsOffset);
|
2020-04-20 11:42:45 +02:00
|
|
|
if (privateDicts[i].localSubrs != &Null (CFF2Subrs) &&
|
2018-12-01 05:04:59 +01:00
|
|
|
unlikely (!privateDicts[i].localSubrs->sanitize (&sc)))
|
|
|
|
{ fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void fini ()
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
sc.end_processing ();
|
2018-12-27 17:33:09 +01:00
|
|
|
topDict.fini ();
|
2018-12-04 19:22:35 +01:00
|
|
|
fontDicts.fini_deep ();
|
2018-10-09 00:05:36 +02:00
|
|
|
privateDicts.fini_deep ();
|
2018-07-18 23:17:52 +02:00
|
|
|
hb_blob_destroy (blob);
|
2018-07-30 23:28:40 +02:00
|
|
|
blob = nullptr;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2020-04-20 21:18:23 +02:00
|
|
|
bool is_valid () const { return blob; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-02 19:18:01 +02:00
|
|
|
protected:
|
2018-12-22 16:47:04 +01:00
|
|
|
hb_blob_t *blob;
|
|
|
|
hb_sanitize_context_t sc;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
public:
|
2018-12-22 16:47:04 +01:00
|
|
|
cff2_top_dict_values_t topDict;
|
|
|
|
const CFF2Subrs *globalSubrs;
|
|
|
|
const CFF2VariationStore *varStore;
|
|
|
|
const CFF2CharStrings *charStrings;
|
|
|
|
const CFF2FDArray *fdArray;
|
|
|
|
const CFF2FDSelect *fdSelect;
|
|
|
|
unsigned int fdCount;
|
|
|
|
|
|
|
|
hb_vector_t<cff2_font_dict_values_t> fontDicts;
|
2018-09-01 01:28:47 +02:00
|
|
|
hb_vector_t<PRIVDICTVAL> privateDicts;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
unsigned int num_glyphs;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct accelerator_t : accelerator_templ_t<cff2_private_dict_opset_t, cff2_private_dict_values_t>
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2018-11-02 00:18:13 +01:00
|
|
|
HB_INTERNAL bool get_extents (hb_font_t *font,
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_glyph_extents_t *extents) const;
|
2020-01-29 19:56:04 +01:00
|
|
|
#ifdef HB_EXPERIMENTAL_API
|
2020-02-26 15:10:44 +01:00
|
|
|
HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, draw_helper_t &draw_helper) const;
|
2020-01-29 19:56:04 +01:00
|
|
|
#endif
|
2018-10-09 00:05:36 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> accelerator_subset_t;
|
2018-08-03 01:28:10 +02:00
|
|
|
|
2020-02-04 21:57:28 +01:00
|
|
|
bool subset (hb_subset_context_t *c) const { return hb_subset_cff2 (c); }
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
public:
|
2019-01-18 00:17:04 +01:00
|
|
|
FixedVersion<HBUINT8> version; /* Version of CFF2 table. set to 0x0200u */
|
|
|
|
NNOffsetTo<TopDict, HBUINT8> topDict; /* headerSize = Offset to Top DICT. */
|
|
|
|
HBUINT16 topDictSize; /* Top DICT size */
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (5);
|
|
|
|
};
|
|
|
|
|
2018-10-09 00:05:36 +02:00
|
|
|
struct cff2_accelerator_t : cff2::accelerator_t {};
|
2018-07-18 23:17:52 +02:00
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
#endif /* HB_OT_CFF2_TABLE_HH */
|