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
|
|
|
|
*/
|
2018-08-29 22:36:39 +02:00
|
|
|
#ifndef HB_OT_CFF_COMMON_HH
|
|
|
|
#define HB_OT_CFF_COMMON_HH
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-08-29 22:26:17 +02:00
|
|
|
#include "hb-open-type.hh"
|
|
|
|
#include "hb-ot-layout-common.hh"
|
|
|
|
#include "hb-cff-interp-dict-common.hh"
|
2018-08-01 20:30:38 +02:00
|
|
|
#include "hb-subset-plan.hh"
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
namespace CFF {
|
|
|
|
|
|
|
|
using namespace OT;
|
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
#define CFF_UNDEF_CODE 0xFFFFFFFF
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
/* utility macro */
|
|
|
|
template<typename Type>
|
|
|
|
static inline const Type& StructAtOffsetOrNull(const void *P, unsigned int offset)
|
|
|
|
{ return offset? (* reinterpret_cast<const Type*> ((const char *) P + offset)): Null(Type); }
|
|
|
|
|
2018-09-12 01:20:39 +02:00
|
|
|
inline unsigned int calcOffSize(unsigned int dataSize)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
unsigned int size = 1;
|
2018-09-12 01:20:39 +02:00
|
|
|
unsigned int offset = dataSize + 1;
|
2018-08-01 20:30:38 +02:00
|
|
|
while ((offset & ~0xFF) != 0)
|
|
|
|
{
|
|
|
|
size++;
|
|
|
|
offset >>= 8;
|
|
|
|
}
|
2018-12-11 21:20:20 +01:00
|
|
|
/* format does not support size > 4; caller should handle it as an error */
|
2018-08-01 20:30:38 +02:00
|
|
|
return size;
|
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct code_pair_t
|
2018-09-13 01:08:54 +02:00
|
|
|
{
|
|
|
|
hb_codepoint_t code;
|
|
|
|
hb_codepoint_t glyph;
|
|
|
|
};
|
|
|
|
|
2018-12-27 23:56:22 +01:00
|
|
|
typedef hb_vector_t<unsigned char> str_buff_t;
|
2018-12-22 16:47:04 +01:00
|
|
|
struct str_buff_vec_t : hb_vector_t<str_buff_t>
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void fini () { SUPER::fini_deep (); }
|
2018-11-05 01:19:15 +01:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int total_size () const
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
|
|
|
unsigned int size = 0;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < length; i++)
|
|
|
|
size += (*this)[i].length;
|
2018-11-01 06:30:34 +01:00
|
|
|
return size;
|
|
|
|
}
|
2018-11-05 01:19:15 +01:00
|
|
|
|
|
|
|
private:
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef hb_vector_t<str_buff_t> SUPER;
|
2018-11-01 06:30:34 +01:00
|
|
|
};
|
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
/* CFF INDEX */
|
2018-08-10 20:07:07 +02:00
|
|
|
template <typename COUNT>
|
2018-08-16 17:03:46 +02:00
|
|
|
struct CFFIndex
|
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);
|
2018-08-20 23:04:46 +02:00
|
|
|
return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */
|
2018-12-01 05:04:59 +01:00
|
|
|
(c->check_struct (this) && offSize >= 1 && offSize <= 4 &&
|
|
|
|
c->check_array (offsets, offSize, count + 1) &&
|
|
|
|
c->check_array ((const HBUINT8*)data_base (), 1, max_offset () - 1))));
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_offset_array_size (unsigned int offSize, unsigned int count)
|
2018-07-18 23:17:52 +02:00
|
|
|
{ return offSize * (count + 1); }
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int offset_array_size () const
|
2018-08-01 20:30:38 +02:00
|
|
|
{ return calculate_offset_array_size (offSize, count); }
|
|
|
|
|
2019-05-14 03:04:09 +02:00
|
|
|
static unsigned int calculate_serialized_size (unsigned int offSize_, unsigned int count, unsigned int dataSize)
|
2018-11-02 23:28:01 +01:00
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
return COUNT::static_size;
|
|
|
|
else
|
2019-05-14 03:04:09 +02:00
|
|
|
return min_size + calculate_offset_array_size (offSize_, count) + dataSize;
|
2018-11-02 23:28:01 +01:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const CFFIndex &src)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-08-02 19:52:08 +02:00
|
|
|
TRACE_SERIALIZE (this);
|
2018-08-01 20:30:38 +02:00
|
|
|
unsigned int size = src.get_size ();
|
2018-08-16 17:03:46 +02:00
|
|
|
CFFIndex *dest = c->allocate_size<CFFIndex> (size);
|
2018-08-01 20:30:38 +02:00
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
|
|
|
memcpy (dest, &src, size);
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
unsigned int offSize_,
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_array_t &byteArray)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
2018-12-22 00:46:51 +01:00
|
|
|
if (byteArray.length == 0)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-11-02 23:28:01 +01:00
|
|
|
COUNT *dest = c->allocate_min<COUNT> ();
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
*dest = 0;
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
2018-11-02 23:28:01 +01:00
|
|
|
else
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-11-02 23:28:01 +01:00
|
|
|
/* serialize CFFIndex header */
|
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
this->count = byteArray.length;
|
|
|
|
this->offSize = offSize_;
|
2018-12-22 00:46:51 +01:00
|
|
|
if (!unlikely (c->allocate_size<HBUINT8> (offSize_ * (byteArray.length + 1))))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-02 23:28:01 +01:00
|
|
|
/* serialize indices */
|
|
|
|
unsigned int offset = 1;
|
|
|
|
unsigned int i = 0;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (; i < byteArray.length; i++)
|
2018-11-02 23:28:01 +01:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
set_offset_at (i, offset);
|
|
|
|
offset += byteArray[i].get_size ();
|
2018-11-02 23:28:01 +01:00
|
|
|
}
|
|
|
|
set_offset_at (i, offset);
|
|
|
|
|
|
|
|
/* serialize data */
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < byteArray.length; i++)
|
2018-11-02 23:28:01 +01:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t &bs = byteArray[i];
|
|
|
|
unsigned char *dest = c->allocate_size<unsigned char> (bs.length);
|
|
|
|
if (unlikely (dest == nullptr))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2018-12-22 16:47:04 +01:00
|
|
|
memcpy (dest, &bs[0], bs.length);
|
2018-11-02 23:28:01 +01:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
unsigned int offSize_,
|
2018-12-22 16:47:04 +01:00
|
|
|
const str_buff_vec_t &buffArray)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
byte_str_array_t byteArray;
|
2018-11-01 06:30:34 +01:00
|
|
|
byteArray.init ();
|
2018-12-22 00:46:51 +01:00
|
|
|
byteArray.resize (buffArray.length);
|
|
|
|
for (unsigned int i = 0; i < byteArray.length; i++)
|
2018-11-01 06:30:34 +01:00
|
|
|
{
|
2019-05-11 03:40:29 +02:00
|
|
|
byteArray[i] = byte_str_t (buffArray[i].arrayZ, buffArray[i].length);
|
2018-11-01 06:30:34 +01:00
|
|
|
}
|
|
|
|
bool result = this->serialize (c, offSize_, byteArray);
|
|
|
|
byteArray.fini ();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void set_offset_at (unsigned int index, unsigned int offset)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
HBUINT8 *p = offsets + offSize * index + offSize;
|
|
|
|
unsigned int size = offSize;
|
|
|
|
for (; size; size--)
|
|
|
|
{
|
|
|
|
--p;
|
2019-03-30 04:17:46 +01:00
|
|
|
*p = offset & 0xFF;
|
2018-08-01 20:30:38 +02:00
|
|
|
offset >>= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int offset_at (unsigned int index) const
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-03 01:28:10 +02:00
|
|
|
assert (index <= count);
|
2018-07-18 23:17:52 +02:00
|
|
|
const HBUINT8 *p = offsets + offSize * index;
|
|
|
|
unsigned int size = offSize;
|
|
|
|
unsigned int offset = 0;
|
|
|
|
for (; size; size--)
|
|
|
|
offset = (offset << 8) + *p++;
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int length_at (unsigned int index) const
|
2018-12-13 03:08:15 +01:00
|
|
|
{
|
2018-12-15 19:02:13 +01:00
|
|
|
if (likely ((offset_at (index + 1) >= offset_at (index)) &&
|
2018-12-13 03:08:15 +01:00
|
|
|
(offset_at (index + 1) <= offset_at (count))))
|
|
|
|
return offset_at (index + 1) - offset_at (index);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
const unsigned char *data_base () const
|
|
|
|
{ return (const unsigned char *)this + min_size + offset_array_size (); }
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int data_size () const { return HBINT8::static_size; }
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
byte_str_t operator [] (unsigned int index) const
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
|
|
|
if (likely (index < count))
|
2018-12-22 16:47:04 +01:00
|
|
|
return byte_str_t (data_base () + offset_at (index) - 1, length_at (index));
|
2018-08-01 20:30:38 +02:00
|
|
|
else
|
2018-12-22 16:47:04 +01:00
|
|
|
return Null(byte_str_t);
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-08-16 17:03:46 +02:00
|
|
|
if (this != &Null(CFFIndex))
|
2018-08-03 01:28:10 +02:00
|
|
|
{
|
|
|
|
if (count > 0)
|
2018-12-01 05:04:59 +01:00
|
|
|
return min_size + offset_array_size () + (offset_at (count) - 1);
|
2018-08-03 01:28:10 +02:00
|
|
|
else
|
2018-12-01 05:04:59 +01:00
|
|
|
return count.static_size; /* empty CFFIndex contains count only */
|
2018-08-03 01:28:10 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-07-30 23:28:40 +02:00
|
|
|
protected:
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int max_offset () const
|
2018-07-30 23:28:40 +02:00
|
|
|
{
|
|
|
|
unsigned int max = 0;
|
2018-12-01 05:38:24 +01:00
|
|
|
for (unsigned int i = 0; i < count + 1u; i++)
|
2018-07-30 23:28:40 +02:00
|
|
|
{
|
|
|
|
unsigned int off = offset_at (i);
|
|
|
|
if (off > max) max = off;
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2018-12-01 05:04:59 +01:00
|
|
|
COUNT count; /* Number of object data. Note there are (count+1) offsets */
|
2018-07-18 23:17:52 +02:00
|
|
|
HBUINT8 offSize; /* The byte size of each offset in the offsets array. */
|
|
|
|
HBUINT8 offsets[VAR]; /* The array of (count + 1) offsets into objects array (1-base). */
|
|
|
|
/* HBUINT8 data[VAR]; Object data */
|
|
|
|
public:
|
2018-08-10 20:07:07 +02:00
|
|
|
DEFINE_SIZE_ARRAY (COUNT::static_size + HBUINT8::static_size, offsets);
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
template <typename COUNT, typename TYPE>
|
2018-09-07 02:28:15 +02:00
|
|
|
struct CFFIndexOf : CFFIndex<COUNT>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t operator [] (unsigned int index) const
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-08-16 17:03:46 +02:00
|
|
|
if (likely (index < CFFIndex<COUNT>::count))
|
2018-12-22 16:47:04 +01:00
|
|
|
return byte_str_t (CFFIndex<COUNT>::data_base () + CFFIndex<COUNT>::offset_at (index) - 1, CFFIndex<COUNT>::length_at (index));
|
|
|
|
return Null(byte_str_t);
|
2018-07-18 23:17:52 +02:00
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
template <typename DATA, typename PARAM1, typename PARAM2>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
unsigned int offSize_,
|
|
|
|
const DATA *dataArray,
|
|
|
|
unsigned int dataArrayLen,
|
|
|
|
const hb_vector_t<unsigned int> &dataSizeArray,
|
|
|
|
const PARAM1 ¶m1,
|
|
|
|
const PARAM2 ¶m2)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
2018-08-16 17:03:46 +02:00
|
|
|
/* serialize CFFIndex header */
|
2018-08-10 20:07:07 +02:00
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
this->count = dataArrayLen;
|
|
|
|
this->offSize = offSize_;
|
2018-09-07 02:28:15 +02:00
|
|
|
if (!unlikely (c->allocate_size<HBUINT8> (offSize_ * (dataArrayLen + 1))))
|
2018-08-10 20:07:07 +02:00
|
|
|
return_trace (false);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
/* serialize indices */
|
|
|
|
unsigned int offset = 1;
|
|
|
|
unsigned int i = 0;
|
2018-09-07 02:28:15 +02:00
|
|
|
for (; i < dataArrayLen; i++)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-08-16 17:03:46 +02:00
|
|
|
CFFIndex<COUNT>::set_offset_at (i, offset);
|
2018-08-10 20:07:07 +02:00
|
|
|
offset += dataSizeArray[i];
|
|
|
|
}
|
2018-08-16 17:03:46 +02:00
|
|
|
CFFIndex<COUNT>::set_offset_at (i, offset);
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
/* serialize data */
|
2018-09-07 02:28:15 +02:00
|
|
|
for (unsigned int i = 0; i < dataArrayLen; i++)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TYPE *dest = c->start_embed<TYPE> ();
|
|
|
|
if (unlikely (dest == nullptr ||
|
2018-12-01 05:04:59 +01:00
|
|
|
!dest->serialize (c, dataArray[i], param1, param2)))
|
|
|
|
return_trace (false);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* in parallel to above */
|
|
|
|
template <typename DATA, typename PARAM>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_serialized_size (unsigned int &offSize_ /* OUT */,
|
|
|
|
const DATA *dataArray,
|
|
|
|
unsigned int dataArrayLen,
|
|
|
|
hb_vector_t<unsigned int> &dataSizeArray, /* OUT */
|
|
|
|
const PARAM ¶m)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
/* determine offset size */
|
|
|
|
unsigned int totalDataSize = 0;
|
2018-09-07 02:28:15 +02:00
|
|
|
for (unsigned int i = 0; i < dataArrayLen; i++)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
unsigned int dataSize = TYPE::calculate_serialized_size (dataArray[i], param);
|
|
|
|
dataSizeArray[i] = dataSize;
|
|
|
|
totalDataSize += dataSize;
|
|
|
|
}
|
|
|
|
offSize_ = calcOffSize (totalDataSize);
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
return CFFIndex<COUNT>::calculate_serialized_size (offSize_, dataArrayLen, totalDataSize);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
/* Top Dict, Font Dict, Private Dict */
|
2018-08-01 20:30:38 +02:00
|
|
|
struct Dict : UnsizedByteStr
|
|
|
|
{
|
2018-08-03 23:35:09 +02:00
|
|
|
template <typename DICTVAL, typename OP_SERIALIZER, typename PARAM>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
const DICTVAL &dictval,
|
|
|
|
OP_SERIALIZER& opszr,
|
|
|
|
PARAM& param)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
2018-11-01 06:30:34 +01:00
|
|
|
for (unsigned int i = 0; i < dictval.get_count (); i++)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (!opszr.serialize (c, dictval[i], param)))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
2018-07-18 23:17:52 +02:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
/* in parallel to above */
|
2018-11-04 06:42:22 +01:00
|
|
|
template <typename DICTVAL, typename OP_SERIALIZER, typename PARAM>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_serialized_size (const DICTVAL &dictval,
|
|
|
|
OP_SERIALIZER& opszr,
|
|
|
|
PARAM& param)
|
2018-11-04 06:42:22 +01:00
|
|
|
{
|
|
|
|
unsigned int size = 0;
|
|
|
|
for (unsigned int i = 0; i < dictval.get_count (); i++)
|
|
|
|
size += opszr.calculate_serialized_size (dictval[i], param);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-08-03 23:35:09 +02:00
|
|
|
template <typename DICTVAL, typename OP_SERIALIZER>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_serialized_size (const DICTVAL &dictval,
|
|
|
|
OP_SERIALIZER& opszr)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
unsigned int size = 0;
|
2018-11-01 06:30:34 +01:00
|
|
|
for (unsigned int i = 0; i < dictval.get_count (); i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
size += opszr.calculate_serialized_size (dictval[i]);
|
2018-08-01 20:30:38 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename INTTYPE, int minVal, int maxVal>
|
2018-12-22 16:47:04 +01:00
|
|
|
static bool serialize_int_op (hb_serialize_context_t *c, op_code_t op, int value, op_code_t intOp)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
// XXX: not sure why but LLVM fails to compile the following 'unlikely' macro invocation
|
|
|
|
if (/*unlikely*/ (!serialize_int<INTTYPE, minVal, maxVal> (c, intOp, value)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
/* serialize the opcode */
|
2018-08-29 21:14:30 +02:00
|
|
|
HBUINT8 *p = c->allocate_size<HBUINT8> (OpCode_Size (op));
|
2018-08-01 20:30:38 +02:00
|
|
|
if (unlikely (p == nullptr)) return_trace (false);
|
2018-08-29 21:14:30 +02:00
|
|
|
if (Is_OpCode_ESC (op))
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2019-03-30 04:17:46 +01:00
|
|
|
*p = OpCode_escape;
|
2018-08-29 21:14:30 +02:00
|
|
|
op = Unmake_OpCode_ESC (op);
|
2018-08-01 20:30:38 +02:00
|
|
|
p++;
|
|
|
|
}
|
2019-03-30 04:17:46 +01:00
|
|
|
*p = op;
|
2018-08-01 20:30:38 +02:00
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
static bool serialize_uint4_op (hb_serialize_context_t *c, op_code_t op, int value)
|
2018-09-11 01:00:20 +02:00
|
|
|
{ return serialize_int_op<HBUINT32, 0, 0x7FFFFFFF> (c, op, value, OpCode_longintdict); }
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
static bool serialize_uint2_op (hb_serialize_context_t *c, op_code_t op, int value)
|
2018-09-11 01:00:20 +02:00
|
|
|
{ return serialize_int_op<HBUINT16, 0, 0x7FFF> (c, op, value, OpCode_shortint); }
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
static bool serialize_offset4_op (hb_serialize_context_t *c, op_code_t op, int value)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
return serialize_uint4_op (c, op, value);
|
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
static bool serialize_offset2_op (hb_serialize_context_t *c, op_code_t op, int value)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
return serialize_uint2_op (c, op, value);
|
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TopDict : Dict {};
|
|
|
|
struct FontDict : Dict {};
|
|
|
|
struct PrivateDict : Dict {};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct table_info_t
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init () { offSize = offset = size = 0; }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
unsigned int offset;
|
|
|
|
unsigned int size;
|
2018-08-15 21:00:19 +02:00
|
|
|
unsigned int offSize;
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
/* used to remap font index or SID from fullset to subset.
|
|
|
|
* set to CFF_UNDEF_CODE if excluded from subset */
|
2018-12-22 16:47:04 +01:00
|
|
|
struct remap_t : hb_vector_t<hb_codepoint_t>
|
2018-08-10 21:55:22 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init () { SUPER::init (); }
|
2018-08-10 21:55:22 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void fini () { SUPER::fini (); }
|
2018-08-10 21:55:22 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool reset (unsigned int size)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
2018-11-07 23:48:37 +01:00
|
|
|
if (unlikely (!SUPER::resize (size)))
|
2018-09-11 01:00:20 +02:00
|
|
|
return false;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < length; i++)
|
2018-09-11 01:00:20 +02:00
|
|
|
(*this)[i] = CFF_UNDEF_CODE;
|
|
|
|
count = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool identity (unsigned int size)
|
2018-11-16 00:39:43 +01:00
|
|
|
{
|
|
|
|
if (unlikely (!SUPER::resize (size)))
|
|
|
|
return false;
|
|
|
|
unsigned int i;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (i = 0; i < length; i++)
|
2018-11-16 00:39:43 +01:00
|
|
|
(*this)[i] = i;
|
|
|
|
count = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool excludes (hb_codepoint_t id) const
|
2018-12-22 00:46:51 +01:00
|
|
|
{ return (id < length) && ((*this)[id] == CFF_UNDEF_CODE); }
|
2018-08-20 23:04:46 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool includes (hb_codepoint_t id) const
|
2018-11-01 06:30:34 +01:00
|
|
|
{ return !excludes (id); }
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int add (unsigned int i)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
if ((*this)[i] == CFF_UNDEF_CODE)
|
|
|
|
(*this)[i] = count++;
|
|
|
|
return (*this)[i];
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
hb_codepoint_t get_count () const { return count; }
|
2018-09-11 01:00:20 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
hb_codepoint_t count;
|
2018-11-07 23:48:37 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef hb_vector_t<hb_codepoint_t> SUPER;
|
2018-08-10 21:55:22 +02:00
|
|
|
};
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
template <typename COUNT>
|
2018-09-07 02:28:15 +02:00
|
|
|
struct FDArray : CFFIndexOf<COUNT, FontDict>
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-09-11 01:00:20 +02:00
|
|
|
/* used by CFF1 */
|
|
|
|
template <typename DICTVAL, typename OP_SERIALIZER>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
unsigned int offSize_,
|
|
|
|
const hb_vector_t<DICTVAL> &fontDicts,
|
|
|
|
OP_SERIALIZER& opszr)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
this->count = fontDicts.length;
|
|
|
|
this->offSize = offSize_;
|
2018-12-22 00:46:51 +01:00
|
|
|
if (!unlikely (c->allocate_size<HBUINT8> (offSize_ * (fontDicts.length + 1))))
|
2018-09-11 01:00:20 +02:00
|
|
|
return_trace (false);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
/* serialize font dict offsets */
|
|
|
|
unsigned int offset = 1;
|
|
|
|
unsigned int fid = 0;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (; fid < fontDicts.length; fid++)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
CFFIndexOf<COUNT, FontDict>::set_offset_at (fid, offset);
|
|
|
|
offset += FontDict::calculate_serialized_size (fontDicts[fid], opszr);
|
|
|
|
}
|
|
|
|
CFFIndexOf<COUNT, FontDict>::set_offset_at (fid, offset);
|
|
|
|
|
|
|
|
/* serialize font dicts */
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < fontDicts.length; i++)
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
FontDict *dict = c->start_embed<FontDict> ();
|
|
|
|
if (unlikely (!dict->serialize (c, fontDicts[i], opszr, fontDicts[i])))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2018-09-11 01:00:20 +02:00
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
/* used by CFF2 */
|
2018-08-01 20:30:38 +02:00
|
|
|
template <typename DICTVAL, typename OP_SERIALIZER>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
unsigned int offSize_,
|
|
|
|
const hb_vector_t<DICTVAL> &fontDicts,
|
|
|
|
unsigned int fdCount,
|
2018-12-22 16:47:04 +01:00
|
|
|
const remap_t &fdmap,
|
2018-12-16 20:08:10 +01:00
|
|
|
OP_SERIALIZER& opszr,
|
2018-12-22 16:47:04 +01:00
|
|
|
const hb_vector_t<table_info_t> &privateInfos)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
this->count = fdCount;
|
|
|
|
this->offSize = offSize_;
|
2018-08-10 20:07:07 +02:00
|
|
|
if (!unlikely (c->allocate_size<HBUINT8> (offSize_ * (fdCount + 1))))
|
2018-08-01 20:30:38 +02:00
|
|
|
return_trace (false);
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
/* serialize font dict offsets */
|
|
|
|
unsigned int offset = 1;
|
2018-08-06 19:04:53 +02:00
|
|
|
unsigned int fid = 0;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned i = 0; i < fontDicts.length; i++)
|
2018-11-07 23:48:37 +01:00
|
|
|
if (fdmap.includes (i))
|
2018-08-06 19:04:53 +02:00
|
|
|
{
|
2019-03-15 21:46:25 +01:00
|
|
|
if (unlikely (fid >= fdCount)) return_trace (false);
|
2018-12-01 05:04:59 +01:00
|
|
|
CFFIndexOf<COUNT, FontDict>::set_offset_at (fid++, offset);
|
|
|
|
offset += FontDict::calculate_serialized_size (fontDicts[i], opszr);
|
2018-08-06 19:04:53 +02:00
|
|
|
}
|
2018-09-07 02:28:15 +02:00
|
|
|
CFFIndexOf<COUNT, FontDict>::set_offset_at (fid, offset);
|
2018-08-01 20:30:38 +02:00
|
|
|
|
|
|
|
/* serialize font dicts */
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < fontDicts.length; i++)
|
2018-11-07 23:48:37 +01:00
|
|
|
if (fdmap.includes (i))
|
2018-08-06 19:04:53 +02:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
FontDict *dict = c->start_embed<FontDict> ();
|
|
|
|
if (unlikely (!dict->serialize (c, fontDicts[i], opszr, privateInfos[fdmap[i]])))
|
|
|
|
return_trace (false);
|
2018-08-06 19:04:53 +02:00
|
|
|
}
|
2018-08-01 20:30:38 +02:00
|
|
|
return_trace (true);
|
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-01 20:30:38 +02:00
|
|
|
/* in parallel to above */
|
|
|
|
template <typename OP_SERIALIZER, typename DICTVAL>
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_serialized_size (unsigned int &offSize_ /* OUT */,
|
|
|
|
const hb_vector_t<DICTVAL> &fontDicts,
|
|
|
|
unsigned int fdCount,
|
2018-12-22 16:47:04 +01:00
|
|
|
const remap_t &fdmap,
|
2018-12-16 20:08:10 +01:00
|
|
|
OP_SERIALIZER& opszr)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
unsigned int dictsSize = 0;
|
|
|
|
for (unsigned int i = 0; i < fontDicts.len; i++)
|
2018-11-07 23:48:37 +01:00
|
|
|
if (fdmap.includes (i))
|
2018-12-01 05:04:59 +01:00
|
|
|
dictsSize += FontDict::calculate_serialized_size (fontDicts[i], opszr);
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-09-12 01:20:39 +02:00
|
|
|
offSize_ = calcOffSize (dictsSize);
|
2018-08-16 17:03:46 +02:00
|
|
|
return CFFIndex<COUNT>::calculate_serialized_size (offSize_, fdCount, dictsSize);
|
2018-08-01 20:30:38 +02:00
|
|
|
}
|
|
|
|
};
|
2018-07-18 23:17:52 +02:00
|
|
|
|
|
|
|
/* FDSelect */
|
|
|
|
struct FDSelect0 {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
|
2018-07-30 23:28:40 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-08-06 19:04:53 +02:00
|
|
|
if (unlikely (!(c->check_struct (this))))
|
|
|
|
return_trace (false);
|
|
|
|
for (unsigned int i = 0; i < c->get_num_glyphs (); i++)
|
|
|
|
if (unlikely (!fds[i].sanitize (c)))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2018-08-06 19:04:53 +02:00
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return (hb_codepoint_t)fds[glyph];
|
2018-07-30 23:28:40 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_size (unsigned int num_glyphs) const
|
2018-08-01 20:30:38 +02:00
|
|
|
{ return HBUINT8::static_size * num_glyphs; }
|
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
HBUINT8 fds[VAR];
|
2018-07-30 23:28:40 +02:00
|
|
|
|
|
|
|
DEFINE_SIZE_MIN (1);
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
template <typename GID_TYPE, typename FD_TYPE>
|
|
|
|
struct FDSelect3_4_Range {
|
2019-04-05 11:29:56 +02:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void * /*nullptr*/, unsigned int fdcount) const
|
2018-07-30 23:28:40 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2019-01-15 03:23:17 +01:00
|
|
|
return_trace (first < c->get_num_glyphs () && (fd < fdcount));
|
2018-07-30 23:28:40 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
GID_TYPE first;
|
|
|
|
FD_TYPE fd;
|
2018-07-30 23:28:40 +02:00
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
DEFINE_SIZE_STATIC (GID_TYPE::static_size + FD_TYPE::static_size);
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
template <typename GID_TYPE, typename FD_TYPE>
|
|
|
|
struct FDSelect3_4 {
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const
|
2019-01-15 03:23:17 +01:00
|
|
|
{ return GID_TYPE::static_size * 2 + ranges.get_size (); }
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
|
2018-07-30 23:28:40 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2019-01-15 03:23:17 +01:00
|
|
|
if (unlikely (!c->check_struct (this) || !ranges.sanitize (c, nullptr, fdcount) ||
|
|
|
|
(nRanges () == 0) || ranges[0].first != 0))
|
2018-08-06 19:04:53 +02:00
|
|
|
return_trace (false);
|
|
|
|
|
2019-01-15 03:23:17 +01:00
|
|
|
for (unsigned int i = 1; i < nRanges (); i++)
|
2018-08-06 19:04:53 +02:00
|
|
|
{
|
2019-01-15 03:23:17 +01:00
|
|
|
if (unlikely (ranges[i - 1].first >= ranges[i].first))
|
|
|
|
return_trace (false);
|
2018-08-06 19:04:53 +02:00
|
|
|
}
|
2019-01-15 03:23:17 +01:00
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
if (unlikely (!sentinel().sanitize (c) || (sentinel() != c->get_num_glyphs ())))
|
|
|
|
return_trace (false);
|
|
|
|
|
|
|
|
return_trace (true);
|
2018-07-30 23:28:40 +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
|
|
|
{
|
2018-09-27 03:51:36 +02:00
|
|
|
unsigned int i;
|
2019-01-15 03:23:17 +01:00
|
|
|
for (i = 1; i < nRanges (); i++)
|
2018-08-10 20:07:07 +02:00
|
|
|
if (glyph < ranges[i].first)
|
2018-12-01 05:04:59 +01:00
|
|
|
break;
|
2018-08-06 19:04:53 +02:00
|
|
|
|
2018-09-27 03:51:36 +02:00
|
|
|
return (hb_codepoint_t)ranges[i - 1].fd;
|
2018-08-06 19:04:53 +02:00
|
|
|
}
|
2018-07-30 23:28:40 +02:00
|
|
|
|
2019-01-15 03:23:17 +01:00
|
|
|
GID_TYPE &nRanges () { return ranges.len; }
|
|
|
|
GID_TYPE nRanges () const { return ranges.len; }
|
|
|
|
GID_TYPE &sentinel () { return StructAfter<GID_TYPE> (ranges[nRanges () - 1]); }
|
|
|
|
const GID_TYPE &sentinel () const { return StructAfter<GID_TYPE> (ranges[nRanges () - 1]); }
|
2018-08-06 19:04:53 +02:00
|
|
|
|
2019-01-15 03:23:17 +01:00
|
|
|
ArrayOf<FDSelect3_4_Range<GID_TYPE, FD_TYPE>, GID_TYPE> ranges;
|
2018-08-06 19:04:53 +02:00
|
|
|
/* GID_TYPE sentinel */
|
|
|
|
|
2018-11-03 00:40:20 +01:00
|
|
|
DEFINE_SIZE_ARRAY (GID_TYPE::static_size, ranges);
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-06 19:04:53 +02:00
|
|
|
typedef FDSelect3_4<HBUINT16, HBUINT8> FDSelect3;
|
|
|
|
typedef FDSelect3_4_Range<HBUINT16, HBUINT8> FDSelect3_Range;
|
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
struct FDSelect {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
|
2018-07-30 23:28:40 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-08-01 20:30:38 +02:00
|
|
|
|
2018-07-30 23:28:40 +02:00
|
|
|
return_trace (likely (c->check_struct (this) && (format == 0 || format == 3) &&
|
2018-12-01 05:04:59 +01:00
|
|
|
(format == 0)?
|
|
|
|
u.format0.sanitize (c, fdcount):
|
|
|
|
u.format3.sanitize (c, fdcount)));
|
2018-07-30 23:28:40 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const FDSelect &src, unsigned int num_glyphs)
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
2018-08-02 19:52:08 +02:00
|
|
|
TRACE_SERIALIZE (this);
|
2018-08-01 20:30:38 +02:00
|
|
|
unsigned int size = src.get_size (num_glyphs);
|
|
|
|
FDSelect *dest = c->allocate_size<FDSelect> (size);
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
|
|
|
memcpy (dest, &src, size);
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int calculate_serialized_size (unsigned int num_glyphs) const
|
2018-08-01 20:30:38 +02:00
|
|
|
{ return get_size (num_glyphs); }
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_size (unsigned int num_glyphs) const
|
2018-08-01 20:30:38 +02:00
|
|
|
{
|
|
|
|
unsigned int size = format.static_size;
|
|
|
|
if (format == 0)
|
|
|
|
size += u.format0.get_size (num_glyphs);
|
2018-08-06 19:04:53 +02:00
|
|
|
else
|
2018-08-01 20:30:38 +02:00
|
|
|
size += u.format3.get_size ();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-08-15 21:00:19 +02:00
|
|
|
if (this == &Null(FDSelect))
|
|
|
|
return 0;
|
2018-08-06 19:04:53 +02:00
|
|
|
if (format == 0)
|
|
|
|
return u.format0.get_fd (glyph);
|
|
|
|
else
|
|
|
|
return u.format3.get_fd (glyph);
|
|
|
|
}
|
|
|
|
|
2018-07-18 23:17:52 +02:00
|
|
|
HBUINT8 format;
|
|
|
|
union {
|
|
|
|
FDSelect0 format0;
|
|
|
|
FDSelect3 format3;
|
|
|
|
} u;
|
2018-07-30 23:28:40 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
DEFINE_SIZE_MIN (1);
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
2018-08-15 21:00:19 +02:00
|
|
|
template <typename COUNT>
|
2018-08-16 17:03:46 +02:00
|
|
|
struct Subrs : CFFIndex<COUNT>
|
2018-07-18 23:17:52 +02:00
|
|
|
{
|
2018-11-01 06:30:34 +01:00
|
|
|
typedef COUNT count_type;
|
|
|
|
typedef CFFIndex<COUNT> SUPER;
|
2018-07-18 23:17:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace CFF */
|
|
|
|
|
2018-08-29 22:36:39 +02:00
|
|
|
#endif /* HB_OT_CFF_COMMON_HH */
|