2018-07-18 23:17:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Adobe Systems Incorporated.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#include "hb-ot-cff-common-private.hh"
|
|
|
|
#include "hb-subset-cff2.hh"
|
|
|
|
|
|
|
|
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-10 20:07:07 +02:00
|
|
|
typedef Index<HBUINT32> CFF2Index;
|
|
|
|
template <typename Type> struct CFF2IndexOf : IndexOf<HBUINT32, Type> {};
|
|
|
|
|
|
|
|
typedef CFF2Index CFF2CharStrings;
|
|
|
|
typedef FDArray<HBUINT32> CFF2FDArray;
|
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
|
|
|
|
{
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
|
|
|
|
return_trace (likely (c->check_struct (this) && (format == 0 || format == 3 || format == 4) &&
|
|
|
|
(format == 0)?
|
|
|
|
u.format0.sanitize (c, fdcount):
|
|
|
|
((format == 3)?
|
|
|
|
u.format3.sanitize (c, fdcount):
|
|
|
|
u.format4.sanitize (c, fdcount))));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs)
|
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
unsigned int size = src.get_size (num_glyphs);
|
|
|
|
CFF2FDSelect *dest = c->allocate_size<CFF2FDSelect> (size);
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
|
|
|
memcpy (dest, &src, size);
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned int calculate_serialized_size (unsigned int num_glyphs) const
|
|
|
|
{ return get_size (num_glyphs); }
|
|
|
|
|
|
|
|
inline unsigned int get_size (unsigned int num_glyphs) const
|
|
|
|
{
|
|
|
|
unsigned int size = format.static_size;
|
|
|
|
if (format == 0)
|
|
|
|
size += u.format0.get_size (num_glyphs);
|
|
|
|
else if (format == 3)
|
|
|
|
size += u.format3.get_size ();
|
|
|
|
else
|
|
|
|
size += u.format4.get_size ();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline hb_codepoint_t get_fd (hb_codepoint_t glyph) const
|
|
|
|
{
|
2018-08-15 21:00:19 +02:00
|
|
|
if (this == &Null(CFF2FDSelect))
|
|
|
|
return 0;
|
2018-08-06 19:04:53 +02:00
|
|
|
if (format == 0)
|
|
|
|
return u.format0.get_fd (glyph);
|
|
|
|
else if (format == 3)
|
|
|
|
return u.format3.get_fd (glyph);
|
|
|
|
else
|
|
|
|
return u.format4.get_fd (glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
HBUINT8 format;
|
|
|
|
union {
|
|
|
|
FDSelect0 format0;
|
|
|
|
FDSelect3 format3;
|
|
|
|
FDSelect4 format4;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
DEFINE_SIZE_MIN (2);
|
|
|
|
};
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
struct CFF2VariationStore
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (likely (c->check_struct (this)) && varStore.sanitize (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline 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_);
|
2018-08-01 20:30:38 +02:00
|
|
|
if (unlikely (dest == nullptr)) 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-08-02 01:06:52 +02:00
|
|
|
inline unsigned int get_size (void) const { return HBUINT16::static_size + size; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
|
|
|
HBUINT16 size;
|
|
|
|
VariationStore varStore;
|
|
|
|
|
|
|
|
DEFINE_SIZE_MIN (2 + VariationStore::min_size);
|
|
|
|
};
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
struct CFF2TopDictValues : TopDictValues
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
inline void init (void)
|
|
|
|
{
|
2018-08-10 20:07:07 +02:00
|
|
|
TopDictValues::init ();
|
|
|
|
vstoreOffset = 0;
|
|
|
|
FDSelectOffset = 0;
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
2018-08-10 20:07:07 +02:00
|
|
|
TopDictValues::fini ();
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
inline unsigned int calculate_serialized_size (void) const
|
|
|
|
{
|
|
|
|
unsigned int size = 0;
|
2018-08-03 23:35:09 +02:00
|
|
|
for (unsigned int i = 0; i < values.len; i++)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-08-03 23:35:09 +02:00
|
|
|
OpCode op = values[i].op;
|
2018-08-10 20:07:07 +02:00
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case OpCode_vstore:
|
|
|
|
case OpCode_FDSelect:
|
2018-08-15 21:00:19 +02:00
|
|
|
size += OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (op);
|
2018-08-10 20:07:07 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
size += TopDictValues::calculate_serialized_op_size (values[i]);
|
|
|
|
break;
|
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
unsigned int vstoreOffset;
|
|
|
|
unsigned int FDSelectOffset;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
struct CFF2TopDictOpSet : TopDictOpSet
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-15 21:00:19 +02:00
|
|
|
static inline bool process_op (OpCode op, InterpEnv& env, CFF2TopDictValues& 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:
|
|
|
|
{
|
|
|
|
DictVal val;
|
|
|
|
val.init ();
|
2018-08-15 21:00:19 +02:00
|
|
|
dictval.pushVal (op, env.substr);
|
|
|
|
env.argStack.clear ();
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
case OpCode_vstore:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_uint (dictval.vstoreOffset)))
|
2018-07-18 23:17:52 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-07-18 23:17:52 +02:00
|
|
|
break;
|
|
|
|
case OpCode_FDSelect:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_uint (dictval.FDSelectOffset)))
|
2018-07-18 23:17:52 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-07-18 23:17:52 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!TopDictOpSet::process_op (op, env, dictval)))
|
2018-08-10 20:07:07 +02:00
|
|
|
return false;
|
|
|
|
/* Record this operand below if stack is empty, otherwise done */
|
2018-08-15 21:00:19 +02:00
|
|
|
if (!env.argStack.is_empty ()) return true;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
dictval.pushVal (op, env.substr);
|
2018-07-18 23:17:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-03 23:35:09 +02:00
|
|
|
struct CFF2FontDictValues : DictValues<OpStr>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
inline void init (void)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-04 00:00:37 +02:00
|
|
|
DictValues<OpStr>::init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
privateDictInfo.init ();
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
inline void fini (void)
|
|
|
|
{
|
2018-08-04 00:00:37 +02:00
|
|
|
DictValues<OpStr>::fini ();
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
TableInfo privateDictInfo;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
struct CFF2FontDictOpSet : DictOpSet
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-15 21:00:19 +02:00
|
|
|
static inline bool process_op (OpCode op, InterpEnv& env, CFF2FontDictValues& 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:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_uint (dictval.privateDictInfo.offset)))
|
2018-07-18 23:17:52 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_uint (dictval.privateDictInfo.size)))
|
2018-08-01 20:30:38 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-07-18 23:17:52 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!DictOpSet::process_op (op, env)))
|
|
|
|
return false;
|
|
|
|
if (!env.argStack.is_empty ())
|
|
|
|
return true;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
dictval.pushVal (op, env.substr);
|
2018-07-18 23:17:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-03 23:35:09 +02:00
|
|
|
template <typename VAL>
|
|
|
|
struct CFF2PrivateDictValues_Base : DictValues<VAL>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
inline void init (void)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-03 23:35:09 +02:00
|
|
|
DictValues<VAL>::init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
subrsOffset = 0;
|
|
|
|
localSubrs = &Null(CFF2Subrs);
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
2018-08-03 23:35:09 +02:00
|
|
|
DictValues<VAL>::fini ();
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned int calculate_serialized_size (void) const
|
|
|
|
{
|
|
|
|
unsigned int size = 0;
|
2018-08-03 23:35:09 +02:00
|
|
|
for (unsigned int i = 0; i < DictValues<VAL>::values.len; i++)
|
|
|
|
if (DictValues<VAL>::values[i].op == OpCode_Subrs)
|
2018-08-03 01:28:10 +02:00
|
|
|
size += OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs);
|
|
|
|
else
|
2018-08-03 23:35:09 +02:00
|
|
|
size += DictValues<VAL>::values[i].str.len;
|
2018-08-03 01:28:10 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
unsigned int subrsOffset;
|
|
|
|
const CFF2Subrs *localSubrs;
|
2018-08-03 01:28:10 +02:00
|
|
|
};
|
|
|
|
|
2018-08-03 23:35:09 +02:00
|
|
|
typedef CFF2PrivateDictValues_Base<OpStr> CFF2PrivateDictValues_Subset;
|
|
|
|
typedef CFF2PrivateDictValues_Base<DictVal> CFF2PrivateDictValues;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
struct CFF2PrivateDictOpSet : DictOpSet
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-15 21:00:19 +02:00
|
|
|
static inline bool process_op (OpCode op, InterpEnv& env, CFF2PrivateDictValues& dictval)
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-03 23:35:09 +02:00
|
|
|
DictVal val;
|
|
|
|
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-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_num (val.single_val)))
|
2018-07-18 23:17:52 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-07-18 23:17:52 +02:00
|
|
|
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-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_delta (val.multi_val)))
|
2018-07-18 23:17:52 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-07-18 23:17:52 +02:00
|
|
|
break;
|
|
|
|
case OpCode_Subrs:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_uint (dictval.subrsOffset)))
|
2018-07-18 23:17:52 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-07-18 23:17:52 +02:00
|
|
|
break;
|
2018-08-15 21:00:19 +02:00
|
|
|
case OpCode_blenddict:
|
2018-07-18 23:17:52 +02:00
|
|
|
// XXX: TODO
|
2018-08-03 23:35:09 +02:00
|
|
|
return true;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
default:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!DictOpSet::process_op (op, env)))
|
|
|
|
return false;
|
|
|
|
if (!env.argStack.is_empty ()) return true;
|
|
|
|
break;
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
dictval.pushVal (op, env.substr, val);
|
2018-07-18 23:17:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
struct CFF2PrivateDictOpSet_Subset : DictOpSet
|
2018-08-03 01:28:10 +02:00
|
|
|
{
|
2018-08-15 21:00:19 +02:00
|
|
|
static inline bool process_op (OpCode op, InterpEnv& env, CFF2PrivateDictValues_Subset& 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-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-08-03 01:28:10 +02:00
|
|
|
break;
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
case OpCode_blenddict:
|
|
|
|
env.argStack.clear ();
|
2018-08-03 23:35:09 +02:00
|
|
|
return true;
|
|
|
|
|
2018-08-03 01:28:10 +02:00
|
|
|
case OpCode_Subrs:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!env.argStack.check_pop_uint (dictval.subrsOffset)))
|
2018-08-03 01:28:10 +02:00
|
|
|
return false;
|
2018-08-15 21:00:19 +02:00
|
|
|
env.argStack.clear ();
|
2018-08-03 01:28:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!DictOpSet::process_op (op, env)))
|
|
|
|
return false;
|
|
|
|
if (!env.argStack.is_empty ()) return true;
|
|
|
|
break;
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
dictval.pushVal (op, env.substr);
|
2018-08-03 01:28:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
typedef DictInterpreter<CFF2TopDictOpSet, CFF2TopDictValues> CFF2TopDict_Interpreter;
|
|
|
|
typedef DictInterpreter<CFF2FontDictOpSet, CFF2FontDictValues> CFF2FontDict_Interpreter;
|
|
|
|
typedef DictInterpreter<CFF2PrivateDictOpSet, CFF2PrivateDictValues> CFF2PrivateDict_Interpreter;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
}; /* namespace CFF */
|
|
|
|
|
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
using namespace CFF;
|
|
|
|
|
|
|
|
struct cff2
|
|
|
|
{
|
|
|
|
static const hb_tag_t tableTag = HB_OT_TAG_cff2;
|
|
|
|
|
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
likely (version.major == 2));
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:28:10 +02:00
|
|
|
template <typename PrivOpSet, typename PrivDictVal>
|
|
|
|
struct accelerator_templ_t
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
|
|
|
inline void init (hb_face_t *face)
|
|
|
|
{
|
2018-08-10 20:07:07 +02:00
|
|
|
topDict.init ();
|
2018-08-01 20:30:38 +02:00
|
|
|
fontDicts.init ();
|
|
|
|
privateDicts.init ();
|
|
|
|
|
|
|
|
this->blob = sc.reference_table<cff2> (face);
|
|
|
|
|
|
|
|
/* setup for run-time santization */
|
|
|
|
sc.init (this->blob);
|
|
|
|
sc.start_processing ();
|
|
|
|
|
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
|
|
|
|
|
|
|
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 */
|
|
|
|
ByteStr topDictStr (cff2 + cff2->topDict, cff2->topDictSize);
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
CFF2TopDict_Interpreter top_interp;
|
2018-08-15 21:00:19 +02:00
|
|
|
top_interp.env.init (topDictStr);
|
|
|
|
if (unlikely (!top_interp.interpret (topDict))) { fini (); return; }
|
2018-07-18 23:17:52 +02: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-07-18 23:17:52 +02:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
if (((varStore != &Null(CFF2VariationStore)) && unlikely (!varStore->sanitize (&sc))) ||
|
2018-08-10 20:07:07 +02:00
|
|
|
(charStrings == &Null(CFF2CharStrings)) || unlikely (!charStrings->sanitize (&sc)) ||
|
|
|
|
(fdArray == &Null(CFF2FDArray)) || unlikely (!fdArray->sanitize (&sc)) ||
|
|
|
|
(((fdSelect != &Null(CFF2FDSelect)) && unlikely (!fdSelect->sanitize (&sc, fdArray->count)))))
|
|
|
|
{ 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
|
|
|
|
|
|
|
privateDicts.resize (fdArray->count);
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
/* parse font dicts and gather private dicts */
|
2018-08-01 20:30:38 +02:00
|
|
|
for (unsigned int i = 0; i < fdArray->count; i++)
|
|
|
|
{
|
|
|
|
const ByteStr fontDictStr = (*fdArray)[i];
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
CFF2FontDictValues *font;
|
|
|
|
CFF2FontDict_Interpreter font_interp;
|
2018-08-15 21:00:19 +02:00
|
|
|
font_interp.env.init (fontDictStr);
|
2018-08-01 20:30:38 +02:00
|
|
|
font = fontDicts.push ();
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!font_interp.interpret (*font))) { fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
const ByteStr privDictStr (StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset), font->privateDictInfo.size);
|
2018-08-15 21:00:19 +02:00
|
|
|
if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; }
|
|
|
|
DictInterpreter<PrivOpSet, PrivDictVal> priv_interp;
|
|
|
|
priv_interp.env.init(privDictStr);
|
|
|
|
if (unlikely (!priv_interp.interpret (privateDicts[i]))) { fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (privDictStr.str, privateDicts[i].subrsOffset);
|
|
|
|
if (privateDicts[i].localSubrs != &Null(CFF2Subrs) &&
|
2018-08-06 19:04:53 +02:00
|
|
|
unlikely (!privateDicts[i].localSubrs->sanitize (&sc)))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
2018-08-01 20:30:38 +02:00
|
|
|
sc.end_processing ();
|
|
|
|
fontDicts.fini ();
|
|
|
|
privateDicts.fini ();
|
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
|
|
|
}
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
inline bool is_valid (void) const { return blob != nullptr; }
|
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
inline bool get_extents (hb_codepoint_t glyph,
|
|
|
|
hb_glyph_extents_t *extents) const
|
|
|
|
{
|
|
|
|
// XXX: TODO
|
|
|
|
if (glyph >= num_glyphs)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-02 19:18:01 +02:00
|
|
|
protected:
|
2018-07-18 23:17:52 +02:00
|
|
|
hb_blob_t *blob;
|
2018-08-01 20:30:38 +02:00
|
|
|
hb_sanitize_context_t sc;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
public:
|
2018-08-10 20:07:07 +02:00
|
|
|
CFF2TopDictValues topDict;
|
|
|
|
const CFF2Subrs *globalSubrs;
|
2018-08-01 20:30:38 +02:00
|
|
|
const CFF2VariationStore *varStore;
|
2018-08-10 20:07:07 +02:00
|
|
|
const CFF2CharStrings *charStrings;
|
|
|
|
const CFF2FDArray *fdArray;
|
2018-08-06 19:04:53 +02:00
|
|
|
const CFF2FDSelect *fdSelect;
|
2018-08-01 20:30:38 +02:00
|
|
|
|
|
|
|
hb_vector_t<CFF2FontDictValues> fontDicts;
|
2018-08-03 01:28:10 +02:00
|
|
|
hb_vector_t<PrivDictVal> privateDicts;
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
unsigned int num_glyphs;
|
|
|
|
};
|
|
|
|
|
2018-08-03 01:28:10 +02:00
|
|
|
typedef accelerator_templ_t<CFF2PrivateDictOpSet, CFF2PrivateDictValues> accelerator_t;
|
2018-08-03 23:35:09 +02:00
|
|
|
typedef accelerator_templ_t<CFF2PrivateDictOpSet_Subset, CFF2PrivateDictValues_Subset> accelerator_subset_t;
|
2018-08-03 01:28:10 +02:00
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
inline bool subset (hb_subset_plan_t *plan) const
|
|
|
|
{
|
|
|
|
hb_blob_t *cff2_prime = nullptr;
|
|
|
|
|
|
|
|
bool success = true;
|
|
|
|
if (hb_subset_cff2 (plan, &cff2_prime)) {
|
|
|
|
success = success && plan->add_table (HB_OT_TAG_cff2, cff2_prime);
|
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
hb_blob_destroy (cff2_prime);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
public:
|
|
|
|
FixedVersion<HBUINT8> version; /* Version of CFF2 table. set to 0x0200u */
|
|
|
|
OffsetTo<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);
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
#endif /* HB_OT_CFF2_TABLE_HH */
|