2018-08-10 20:07:07 +02:00
|
|
|
/*
|
2018-11-12 17:47:07 +01:00
|
|
|
* Copyright © 2018 Adobe Inc.
|
2018-08-10 20:07:07 +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-16 09:13:09 +02:00
|
|
|
#ifndef HB_OT_CFF1_TABLE_HH
|
|
|
|
#define HB_OT_CFF1_TABLE_HH
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-09-13 19:55:56 +02:00
|
|
|
#include "hb-ot-head-table.hh"
|
2018-08-29 22:26:17 +02:00
|
|
|
#include "hb-ot-cff-common.hh"
|
2018-08-16 09:13:09 +02:00
|
|
|
#include "hb-subset-cff1.hh"
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
namespace CFF {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CFF -- Compact Font Format (CFF)
|
|
|
|
* http://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5176.CFF.pdf
|
|
|
|
*/
|
2018-08-16 09:25:57 +02:00
|
|
|
#define HB_OT_TAG_cff1 HB_TAG('C','F','F',' ')
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
#define CFF_UNDEF_SID CFF_UNDEF_CODE
|
2018-09-07 02:28:15 +02:00
|
|
|
|
|
|
|
enum EncodingID { StandardEncoding = 0, ExpertEncoding = 1 };
|
|
|
|
enum CharsetID { ISOAdobeCharset = 0, ExpertCharset = 1, ExpertSubsetCharset = 2 };
|
|
|
|
|
2018-08-16 17:03:46 +02:00
|
|
|
typedef CFFIndex<HBUINT16> CFF1Index;
|
2018-09-07 02:28:15 +02:00
|
|
|
template <typename Type> struct CFF1IndexOf : CFFIndexOf<HBUINT16, Type> {};
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-01 05:04:59 +01:00
|
|
|
typedef CFFIndex<HBUINT16> CFF1Index;
|
|
|
|
typedef CFF1Index CFF1CharStrings;
|
|
|
|
typedef FDArray<HBUINT16> CFF1FDArray;
|
|
|
|
typedef Subrs<HBUINT16> CFF1Subrs;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
struct CFF1FDSelect : FDSelect {};
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
/* Encoding */
|
|
|
|
struct Encoding0 {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2019-01-23 23:04:29 +01:00
|
|
|
return_trace (codes.sanitize (c));
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_code (hb_codepoint_t glyph) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-11-07 18:09:13 +01:00
|
|
|
assert (glyph > 0);
|
|
|
|
glyph--;
|
2019-01-23 23:04:29 +01:00
|
|
|
if (glyph < nCodes ())
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-07 02:28:15 +02:00
|
|
|
return (hb_codepoint_t)codes[glyph];
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
else
|
2018-09-07 02:28:15 +02:00
|
|
|
return CFF_UNDEF_CODE;
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
HBUINT8 &nCodes () { return codes.len; }
|
|
|
|
HBUINT8 nCodes () const { return codes.len; }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
ArrayOf<HBUINT8, HBUINT8> codes;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
DEFINE_SIZE_ARRAY_SIZED (1, codes);
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Encoding1_Range {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
HBUINT8 first;
|
|
|
|
HBUINT8 nLeft;
|
|
|
|
|
|
|
|
DEFINE_SIZE_STATIC (2);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Encoding1 {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2019-01-23 23:04:29 +01:00
|
|
|
return_trace (ranges.sanitize (c));
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_code (hb_codepoint_t glyph) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-11-07 18:09:13 +01:00
|
|
|
assert (glyph > 0);
|
|
|
|
glyph--;
|
2019-01-23 23:04:29 +01:00
|
|
|
for (unsigned int i = 0; i < nRanges (); i++)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
if (glyph <= ranges[i].nLeft)
|
|
|
|
{
|
2019-04-19 00:17:10 +02:00
|
|
|
hb_codepoint_t code = (hb_codepoint_t) ranges[i].first + glyph;
|
|
|
|
return (likely (code < 0x100) ? code: CFF_UNDEF_CODE);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
glyph -= (ranges[i].nLeft + 1);
|
|
|
|
}
|
2018-09-07 02:28:15 +02:00
|
|
|
return CFF_UNDEF_CODE;
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
HBUINT8 &nRanges () { return ranges.len; }
|
|
|
|
HBUINT8 nRanges () const { return ranges.len; }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
ArrayOf<Encoding1_Range, HBUINT8> ranges;
|
|
|
|
|
|
|
|
DEFINE_SIZE_ARRAY_SIZED (1, ranges);
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
struct SuppEncoding {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
HBUINT8 code;
|
|
|
|
HBUINT16 glyph;
|
|
|
|
|
|
|
|
DEFINE_SIZE_STATIC (3);
|
|
|
|
};
|
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
struct CFF1SuppEncData {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2019-01-23 23:04:29 +01:00
|
|
|
return_trace (supps.sanitize (c));
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void get_codes (hb_codepoint_t sid, hb_vector_t<hb_codepoint_t> &codes) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2019-01-23 23:04:29 +01:00
|
|
|
for (unsigned int i = 0; i < nSups (); i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
if (sid == supps[i].glyph)
|
2018-12-01 05:04:59 +01:00
|
|
|
codes.push (supps[i].code);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
HBUINT8 &nSups () { return supps.len; }
|
|
|
|
HBUINT8 nSups () const { return supps.len; }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
ArrayOf<SuppEncoding, HBUINT8> supps;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2019-01-23 23:04:29 +01:00
|
|
|
DEFINE_SIZE_ARRAY_SIZED (1, supps);
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Encoding {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
|
|
|
|
if (unlikely (!c->check_struct (this)))
|
|
|
|
return_trace (false);
|
|
|
|
unsigned int fmt = format & 0x7F;
|
|
|
|
if (unlikely (fmt > 1))
|
|
|
|
return_trace (false);
|
|
|
|
if (unlikely (!((fmt == 0)? u.format0.sanitize (c): u.format1.sanitize (c))))
|
|
|
|
return_trace (false);
|
|
|
|
return_trace (((format & 0x80) == 0) || suppEncData ().sanitize (c));
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
/* serialize a fullset Encoding */
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const Encoding &src)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
unsigned int size = src.get_size ();
|
|
|
|
Encoding *dest = c->allocate_size<Encoding> (size);
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
|
|
|
memcpy (dest, &src, size);
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
/* serialize a subset Encoding */
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
uint8_t format,
|
|
|
|
unsigned int enc_count,
|
2018-12-22 16:47:04 +01:00
|
|
|
const hb_vector_t<code_pair_t>& code_ranges,
|
|
|
|
const hb_vector_t<code_pair_t>& supp_codes)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
Encoding *dest = c->extend_min (*this);
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
dest->format = format | ((supp_codes.length > 0)? 0x80: 0);
|
2018-09-07 02:28:15 +02:00
|
|
|
if (format == 0)
|
|
|
|
{
|
|
|
|
Encoding0 *fmt0 = c->allocate_size<Encoding0> (Encoding0::min_size + HBUINT8::static_size * enc_count);
|
|
|
|
if (unlikely (fmt0 == nullptr)) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt0->nCodes () = enc_count;
|
2018-09-07 02:28:15 +02:00
|
|
|
unsigned int glyph = 0;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < code_ranges.length; i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_codepoint_t code = code_ranges[i].code;
|
|
|
|
for (int left = (int)code_ranges[i].glyph; left >= 0; left--)
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt0->codes[glyph++] = code++;
|
2018-12-11 21:20:20 +01:00
|
|
|
if (unlikely (!((glyph <= 0x100) && (code <= 0x100))))
|
|
|
|
return_trace (false);
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-22 00:46:51 +01:00
|
|
|
Encoding1 *fmt1 = c->allocate_size<Encoding1> (Encoding1::min_size + Encoding1_Range::static_size * code_ranges.length);
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (fmt1 == nullptr)) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt1->nRanges () = code_ranges.length;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < code_ranges.length; i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-11 21:20:20 +01:00
|
|
|
if (unlikely (!((code_ranges[i].code <= 0xFF) && (code_ranges[i].glyph <= 0xFF))))
|
|
|
|
return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt1->ranges[i].first = code_ranges[i].code;
|
|
|
|
fmt1->ranges[i].nLeft = code_ranges[i].glyph;
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-22 00:46:51 +01:00
|
|
|
if (supp_codes.length > 0)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-22 00:46:51 +01:00
|
|
|
CFF1SuppEncData *suppData = c->allocate_size<CFF1SuppEncData> (CFF1SuppEncData::min_size + SuppEncoding::static_size * supp_codes.length);
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (suppData == nullptr)) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
suppData->nSups () = supp_codes.length;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < supp_codes.length; i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2019-03-30 04:17:46 +01:00
|
|
|
suppData->supps[i].code = supp_codes[i].code;
|
|
|
|
suppData->supps[i].glyph = supp_codes[i].glyph; /* actually SID */
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parallel to above: calculate the size of a subset Encoding */
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_serialized_size (uint8_t format,
|
|
|
|
unsigned int enc_count,
|
|
|
|
unsigned int supp_count)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
unsigned int size = min_size;
|
|
|
|
if (format == 0)
|
|
|
|
size += Encoding0::min_size + HBUINT8::static_size * enc_count;
|
|
|
|
else
|
|
|
|
size += Encoding1::min_size + Encoding1_Range::static_size * enc_count;
|
|
|
|
if (supp_count > 0)
|
|
|
|
size += CFF1SuppEncData::min_size + SuppEncoding::static_size * supp_count;
|
|
|
|
return size;
|
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
unsigned int size = min_size;
|
2018-09-07 02:28:15 +02:00
|
|
|
if (table_format () == 0)
|
2018-08-10 20:07:07 +02:00
|
|
|
size += u.format0.get_size ();
|
|
|
|
else
|
|
|
|
size += u.format1.get_size ();
|
2018-09-07 02:28:15 +02:00
|
|
|
if (has_supplement ())
|
2018-08-10 20:07:07 +02:00
|
|
|
size += suppEncData ().get_size ();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_code (hb_codepoint_t glyph) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-07 02:28:15 +02:00
|
|
|
if (table_format () == 0)
|
|
|
|
return u.format0.get_code (glyph);
|
|
|
|
else
|
|
|
|
return u.format1.get_code (glyph);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
uint8_t table_format () const { return (format & 0x7F); }
|
|
|
|
bool has_supplement () const { return (format & 0x80) != 0; }
|
2018-09-07 02:28:15 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void get_supplement_codes (hb_codepoint_t sid, hb_vector_t<hb_codepoint_t> &codes) const
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
codes.resize (0);
|
|
|
|
if (has_supplement ())
|
|
|
|
suppEncData().get_codes (sid, codes);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-12-17 19:01:01 +01:00
|
|
|
const CFF1SuppEncData &suppEncData () const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
if ((format & 0x7F) == 0)
|
2019-01-23 23:04:29 +01:00
|
|
|
return StructAfter<CFF1SuppEncData> (u.format0.codes[u.format0.nCodes ()-1]);
|
2018-08-10 20:07:07 +02:00
|
|
|
else
|
2019-01-23 23:04:29 +01:00
|
|
|
return StructAfter<CFF1SuppEncData> (u.format1.ranges[u.format1.nRanges ()-1]);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
public:
|
2018-08-10 20:07:07 +02:00
|
|
|
HBUINT8 format;
|
2018-09-07 02:28:15 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
union {
|
|
|
|
Encoding0 format0;
|
|
|
|
Encoding1 format1;
|
|
|
|
} u;
|
2018-08-16 09:13:09 +02:00
|
|
|
/* CFF1SuppEncData suppEncData; */
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
DEFINE_SIZE_MIN (1);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Charset */
|
|
|
|
struct Charset0 {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int num_glyphs) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) && sids[num_glyphs - 1].sanitize (c));
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_sid (hb_codepoint_t glyph) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
if (glyph == 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return sids[glyph - 1];
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_glyph (hb_codepoint_t sid, unsigned int num_glyphs) const
|
2018-11-14 22:38:03 +01:00
|
|
|
{
|
|
|
|
if (sid == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (unsigned int glyph = 1; glyph < num_glyphs; glyph++)
|
|
|
|
{
|
|
|
|
if (sids[glyph-1] == sid)
|
2018-12-01 05:04:59 +01:00
|
|
|
return glyph;
|
2018-11-14 22:38:03 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_size (unsigned int num_glyphs) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
assert (num_glyphs > 0);
|
|
|
|
return HBUINT16::static_size * (num_glyphs - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
HBUINT16 sids[VAR];
|
|
|
|
|
|
|
|
DEFINE_SIZE_ARRAY(0, sids);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename TYPE>
|
|
|
|
struct Charset_Range {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
HBUINT16 first;
|
2018-08-10 20:07:07 +02:00
|
|
|
TYPE nLeft;
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
DEFINE_SIZE_STATIC (HBUINT16::static_size + TYPE::static_size);
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename TYPE>
|
|
|
|
struct Charset1_2 {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int num_glyphs) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (!c->check_struct (this)))
|
|
|
|
return_trace (false);
|
|
|
|
num_glyphs--;
|
|
|
|
for (unsigned int i = 0; num_glyphs > 0; i++)
|
|
|
|
{
|
|
|
|
if (unlikely (!ranges[i].sanitize (c) || (num_glyphs < ranges[i].nLeft + 1)))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2018-09-07 02:28:15 +02:00
|
|
|
num_glyphs -= (ranges[i].nLeft + 1);
|
|
|
|
}
|
|
|
|
return_trace (true);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_sid (hb_codepoint_t glyph) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-07 02:28:15 +02:00
|
|
|
if (glyph == 0) return 0;
|
|
|
|
glyph--;
|
|
|
|
for (unsigned int i = 0;; i++)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
if (glyph <= ranges[i].nLeft)
|
2018-12-01 05:04:59 +01:00
|
|
|
return (hb_codepoint_t)ranges[i].first + glyph;
|
2018-08-10 20:07:07 +02:00
|
|
|
glyph -= (ranges[i].nLeft + 1);
|
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
return 0;
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_glyph (hb_codepoint_t sid, unsigned int num_glyphs) const
|
2018-11-14 22:38:03 +01:00
|
|
|
{
|
|
|
|
if (sid == 0) return 0;
|
|
|
|
hb_codepoint_t glyph = 1;
|
|
|
|
for (unsigned int i = 0;; i++)
|
|
|
|
{
|
2018-12-04 22:51:26 +01:00
|
|
|
if (glyph >= num_glyphs)
|
|
|
|
return 0;
|
|
|
|
if ((ranges[i].first <= sid) && (sid <= ranges[i].first + ranges[i].nLeft))
|
2018-12-01 05:04:59 +01:00
|
|
|
return glyph + (sid - ranges[i].first);
|
2018-11-14 22:38:03 +01:00
|
|
|
glyph += (ranges[i].nLeft + 1);
|
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-14 22:38:03 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_size (unsigned int num_glyphs) const
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
unsigned int size = HBUINT8::static_size;
|
|
|
|
int glyph = (int)num_glyphs;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
assert (glyph > 0);
|
|
|
|
glyph--;
|
|
|
|
for (unsigned int i = 0; glyph > 0; i++)
|
|
|
|
{
|
|
|
|
glyph -= (ranges[i].nLeft + 1);
|
|
|
|
size += Charset_Range<TYPE>::static_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
Charset_Range<TYPE> ranges[VAR];
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
DEFINE_SIZE_ARRAY (0, ranges);
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
typedef Charset1_2<HBUINT8> Charset1;
|
|
|
|
typedef Charset1_2<HBUINT16> Charset2;
|
|
|
|
typedef Charset_Range<HBUINT8> Charset1_Range;
|
|
|
|
typedef Charset_Range<HBUINT16> Charset2_Range;
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
struct Charset {
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
|
|
|
|
if (unlikely (!c->check_struct (this)))
|
|
|
|
return_trace (false);
|
|
|
|
if (format == 0)
|
|
|
|
return_trace (u.format0.sanitize (c, c->get_num_glyphs ()));
|
|
|
|
else if (format == 1)
|
2018-09-07 02:28:15 +02:00
|
|
|
return_trace (u.format1.sanitize (c, c->get_num_glyphs ()));
|
2018-08-10 20:07:07 +02:00
|
|
|
else if (likely (format == 2))
|
2018-09-07 02:28:15 +02:00
|
|
|
return_trace (u.format2.sanitize (c, c->get_num_glyphs ()));
|
2018-08-10 20:07:07 +02:00
|
|
|
else
|
|
|
|
return_trace (false);
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
/* serialize a fullset Charset */
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const Charset &src, unsigned int num_glyphs)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
unsigned int size = src.get_size (num_glyphs);
|
|
|
|
Charset *dest = c->allocate_size<Charset> (size);
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
|
|
|
memcpy (dest, &src, size);
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
/* serialize a subset Charset */
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
uint8_t format,
|
|
|
|
unsigned int num_glyphs,
|
2018-12-22 16:47:04 +01:00
|
|
|
const hb_vector_t<code_pair_t>& sid_ranges)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
Charset *dest = c->extend_min (*this);
|
|
|
|
if (unlikely (dest == nullptr)) return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
dest->format = format;
|
2018-09-07 02:28:15 +02:00
|
|
|
if (format == 0)
|
|
|
|
{
|
2018-09-12 22:22:19 +02:00
|
|
|
Charset0 *fmt0 = c->allocate_size<Charset0> (Charset0::min_size + HBUINT16::static_size * (num_glyphs - 1));
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (fmt0 == nullptr)) return_trace (false);
|
|
|
|
unsigned int glyph = 0;
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < sid_ranges.length; i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_codepoint_t sid = sid_ranges[i].code;
|
|
|
|
for (int left = (int)sid_ranges[i].glyph; left >= 0; left--)
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt0->sids[glyph++] = sid++;
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (format == 1)
|
|
|
|
{
|
2018-12-22 00:46:51 +01:00
|
|
|
Charset1 *fmt1 = c->allocate_size<Charset1> (Charset1::min_size + Charset1_Range::static_size * sid_ranges.length);
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (fmt1 == nullptr)) return_trace (false);
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < sid_ranges.length; i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-11 21:20:20 +01:00
|
|
|
if (unlikely (!(sid_ranges[i].glyph <= 0xFF)))
|
|
|
|
return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt1->ranges[i].first = sid_ranges[i].code;
|
|
|
|
fmt1->ranges[i].nLeft = sid_ranges[i].glyph;
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* format 2 */
|
|
|
|
{
|
2018-12-22 00:46:51 +01:00
|
|
|
Charset2 *fmt2 = c->allocate_size<Charset2> (Charset2::min_size + Charset2_Range::static_size * sid_ranges.length);
|
2018-09-07 02:28:15 +02:00
|
|
|
if (unlikely (fmt2 == nullptr)) return_trace (false);
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < sid_ranges.length; i++)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-11 21:20:20 +01:00
|
|
|
if (unlikely (!(sid_ranges[i].glyph <= 0xFFFF)))
|
|
|
|
return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
fmt2->ranges[i].first = sid_ranges[i].code;
|
|
|
|
fmt2->ranges[i].nLeft = sid_ranges[i].glyph;
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parallel to above: calculate the size of a subset Charset */
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int calculate_serialized_size (
|
2018-12-01 05:04:59 +01:00
|
|
|
uint8_t format,
|
|
|
|
unsigned int count)
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
unsigned int size = min_size;
|
|
|
|
if (format == 0)
|
2018-09-12 22:22:19 +02:00
|
|
|
size += Charset0::min_size + HBUINT16::static_size * (count - 1);
|
2018-09-07 02:28:15 +02:00
|
|
|
else if (format == 1)
|
|
|
|
size += Charset1::min_size + Charset1_Range::static_size * count;
|
|
|
|
else
|
|
|
|
size += Charset2::min_size + Charset2_Range::static_size * count;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_size (unsigned int num_glyphs) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
unsigned int size = min_size;
|
|
|
|
if (format == 0)
|
|
|
|
size += u.format0.get_size (num_glyphs);
|
|
|
|
else if (format == 1)
|
2018-09-07 02:28:15 +02:00
|
|
|
size += u.format1.get_size (num_glyphs);
|
2018-08-10 20:07:07 +02:00
|
|
|
else
|
2018-09-07 02:28:15 +02:00
|
|
|
size += u.format2.get_size (num_glyphs);
|
2018-08-10 20:07:07 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_sid (hb_codepoint_t glyph) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-07 02:28:15 +02:00
|
|
|
if (format == 0)
|
|
|
|
return u.format0.get_sid (glyph);
|
|
|
|
else if (format == 1)
|
|
|
|
return u.format1.get_sid (glyph);
|
|
|
|
else
|
|
|
|
return u.format2.get_sid (glyph);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t get_glyph (hb_codepoint_t sid, unsigned int num_glyphs) const
|
2018-11-14 22:38:03 +01:00
|
|
|
{
|
|
|
|
if (format == 0)
|
|
|
|
return u.format0.get_glyph (sid, num_glyphs);
|
|
|
|
else if (format == 1)
|
2018-12-04 22:51:26 +01:00
|
|
|
return u.format1.get_glyph (sid, num_glyphs);
|
2018-11-14 22:38:03 +01:00
|
|
|
else
|
2018-12-04 22:51:26 +01:00
|
|
|
return u.format2.get_glyph (sid, num_glyphs);
|
2018-11-14 22:38:03 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
HBUINT8 format;
|
|
|
|
union {
|
2018-09-07 02:28:15 +02:00
|
|
|
Charset0 format0;
|
|
|
|
Charset1 format1;
|
|
|
|
Charset2 format2;
|
2018-08-10 20:07:07 +02:00
|
|
|
} u;
|
|
|
|
|
|
|
|
DEFINE_SIZE_MIN (1);
|
|
|
|
};
|
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
struct CFF1StringIndex : CFF1Index
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c, const CFF1StringIndex &strings,
|
2018-12-22 16:47:04 +01:00
|
|
|
unsigned int offSize_, const remap_t &sidmap)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-11 01:00:20 +02:00
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
if (unlikely ((strings.count == 0) || (sidmap.get_count () == 0)))
|
|
|
|
{
|
2018-10-12 11:16:07 +02:00
|
|
|
if (!unlikely (c->extend_min (this->count)))
|
2018-12-01 05:04:59 +01:00
|
|
|
return_trace (false);
|
2019-03-30 04:17:46 +01:00
|
|
|
count = 0;
|
2018-09-11 01:00:20 +02:00
|
|
|
return_trace (true);
|
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
byte_str_array_t bytesArray;
|
2018-09-11 01:00:20 +02:00
|
|
|
bytesArray.init ();
|
|
|
|
if (!bytesArray.resize (sidmap.get_count ()))
|
|
|
|
return_trace (false);
|
|
|
|
for (unsigned int i = 0; i < strings.count; i++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t j = sidmap[i];
|
|
|
|
if (j != CFF_UNDEF_CODE)
|
2018-12-01 05:04:59 +01:00
|
|
|
bytesArray[j] = strings[i];
|
2018-09-11 01:00:20 +02:00
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
bool result = CFF1Index::serialize (c, offSize_, bytesArray);
|
|
|
|
bytesArray.fini ();
|
|
|
|
return_trace (result);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
/* in parallel to above */
|
2018-12-22 16:47:04 +01:00
|
|
|
unsigned int calculate_serialized_size (unsigned int &offSize /*OUT*/, const remap_t &sidmap) const
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
offSize = 0;
|
|
|
|
if ((count == 0) || (sidmap.get_count () == 0))
|
|
|
|
return count.static_size;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
unsigned int dataSize = 0;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
if (sidmap[i] != CFF_UNDEF_CODE)
|
2018-12-01 05:04:59 +01:00
|
|
|
dataSize += length_at (i);
|
2018-09-11 01:00:20 +02:00
|
|
|
|
|
|
|
offSize = calcOffSize(dataSize);
|
|
|
|
return CFF1Index::calculate_serialized_size (offSize, sidmap.get_count (), dataSize);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_top_dict_interp_env_t : num_interp_env_t
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
cff1_top_dict_interp_env_t ()
|
|
|
|
: num_interp_env_t(), prev_offset(0), last_offset(0) {}
|
2018-09-11 01:00:20 +02:00
|
|
|
|
|
|
|
unsigned int prev_offset;
|
|
|
|
unsigned int last_offset;
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct name_dict_values_t
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
enum name_dict_val_index_t
|
2018-09-11 02:02:31 +02:00
|
|
|
{
|
|
|
|
version,
|
|
|
|
notice,
|
|
|
|
copyright,
|
|
|
|
fullName,
|
|
|
|
familyName,
|
|
|
|
weight,
|
|
|
|
postscript,
|
|
|
|
fontName,
|
|
|
|
baseFontName,
|
|
|
|
registry,
|
|
|
|
ordering,
|
|
|
|
|
|
|
|
ValCount
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-11 02:02:31 +02:00
|
|
|
for (unsigned int i = 0; i < ValCount; i++)
|
2018-09-11 01:00:20 +02:00
|
|
|
values[i] = CFF_UNDEF_SID;
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int& operator[] (unsigned int i)
|
2018-09-11 02:02:31 +02:00
|
|
|
{ assert (i < ValCount); return values[i]; }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int operator[] (unsigned int i) const
|
2018-09-11 02:02:31 +02:00
|
|
|
{ assert (i < ValCount); return values[i]; }
|
2018-09-11 01:00:20 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
static enum name_dict_val_index_t name_op_to_index (op_code_t op)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-11 01:00:20 +02:00
|
|
|
switch (op) {
|
2018-12-08 05:49:39 +01:00
|
|
|
default: // can't happen - just make some compiler happy
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_version:
|
2018-12-01 05:04:59 +01:00
|
|
|
return version;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_Notice:
|
2018-12-01 05:04:59 +01:00
|
|
|
return notice;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_Copyright:
|
2018-12-01 05:04:59 +01:00
|
|
|
return copyright;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_FullName:
|
2018-12-01 05:04:59 +01:00
|
|
|
return fullName;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_FamilyName:
|
2018-12-01 05:04:59 +01:00
|
|
|
return familyName;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_Weight:
|
2018-12-01 05:04:59 +01:00
|
|
|
return weight;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_PostScript:
|
2018-12-01 05:04:59 +01:00
|
|
|
return postscript;
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_FontName:
|
2018-12-01 05:04:59 +01:00
|
|
|
return fontName;
|
2018-12-08 05:49:39 +01:00
|
|
|
case OpCode_BaseFontName:
|
|
|
|
return baseFontName;
|
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-11 02:02:31 +02:00
|
|
|
unsigned int values[ValCount];
|
2018-09-11 01:00:20 +02:00
|
|
|
};
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_top_dict_val_t : op_str_t
|
2018-09-11 01:00:20 +02:00
|
|
|
{
|
|
|
|
unsigned int last_arg_offset;
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_top_dict_values_t : top_dict_values_t<cff1_top_dict_val_t>
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
top_dict_values_t<cff1_top_dict_val_t>::init ();
|
2018-09-11 01:00:20 +02:00
|
|
|
|
|
|
|
nameSIDs.init ();
|
|
|
|
ros_supplement = 0;
|
|
|
|
cidCount = 8720;
|
|
|
|
EncodingOffset = 0;
|
|
|
|
CharsetOffset = 0;
|
|
|
|
FDSelectOffset = 0;
|
|
|
|
privateDictInfo.init ();
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
2018-12-22 16:47:04 +01:00
|
|
|
void fini () { top_dict_values_t<cff1_top_dict_val_t>::fini (); }
|
2018-09-07 02:28:15 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_CID () const
|
2018-12-22 16:47:04 +01:00
|
|
|
{ return nameSIDs[name_dict_values_t::registry] != CFF_UNDEF_SID; }
|
2018-09-07 02:28:15 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
name_dict_values_t nameSIDs;
|
2018-09-11 01:00:20 +02:00
|
|
|
unsigned int ros_supplement_offset;
|
|
|
|
unsigned int ros_supplement;
|
|
|
|
unsigned int cidCount;
|
|
|
|
|
|
|
|
unsigned int EncodingOffset;
|
|
|
|
unsigned int CharsetOffset;
|
|
|
|
unsigned int FDSelectOffset;
|
2018-12-22 16:47:04 +01:00
|
|
|
table_info_t privateDictInfo;
|
2018-09-07 02:28:15 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_top_dict_opset_t : top_dict_opset_t<cff1_top_dict_val_t>
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, cff1_top_dict_interp_env_t& env, cff1_top_dict_values_t& dictval)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
cff1_top_dict_val_t val;
|
2018-09-11 01:00:20 +02:00
|
|
|
val.last_arg_offset = (env.last_offset-1) - dictval.opStart; /* offset to the last argument */
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
switch (op) {
|
|
|
|
case OpCode_version:
|
|
|
|
case OpCode_Notice:
|
|
|
|
case OpCode_Copyright:
|
|
|
|
case OpCode_FullName:
|
|
|
|
case OpCode_FamilyName:
|
|
|
|
case OpCode_Weight:
|
2018-09-11 01:00:20 +02:00
|
|
|
case OpCode_PostScript:
|
|
|
|
case OpCode_BaseFontName:
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.nameSIDs[name_dict_values_t::name_op_to_index (op)] = env.argStack.pop_uint ();
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_isFixedPitch:
|
|
|
|
case OpCode_ItalicAngle:
|
|
|
|
case OpCode_UnderlinePosition:
|
|
|
|
case OpCode_UnderlineThickness:
|
|
|
|
case OpCode_PaintType:
|
|
|
|
case OpCode_CharstringType:
|
|
|
|
case OpCode_UniqueID:
|
|
|
|
case OpCode_StrokeWidth:
|
|
|
|
case OpCode_SyntheticBase:
|
|
|
|
case OpCode_CIDFontVersion:
|
|
|
|
case OpCode_CIDFontRevision:
|
|
|
|
case OpCode_CIDFontType:
|
|
|
|
case OpCode_UIDBase:
|
|
|
|
case OpCode_FontBBox:
|
|
|
|
case OpCode_XUID:
|
|
|
|
case OpCode_BaseFontBlend:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_CIDCount:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.cidCount = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
case OpCode_ROS:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.ros_supplement = env.argStack.pop_uint ();
|
2018-12-22 16:47:04 +01:00
|
|
|
dictval.nameSIDs[name_dict_values_t::ordering] = env.argStack.pop_uint ();
|
|
|
|
dictval.nameSIDs[name_dict_values_t::registry] = env.argStack.pop_uint ();
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
case OpCode_Encoding:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.EncodingOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
if (unlikely (dictval.EncodingOffset == 0)) return;
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
case OpCode_charset:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.CharsetOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
if (unlikely (dictval.CharsetOffset == 0)) return;
|
|
|
|
break;
|
2018-08-10 20:07:07 +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-08-10 20:07:07 +02:00
|
|
|
case OpCode_Private:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.privateDictInfo.offset = env.argStack.pop_uint ();
|
|
|
|
dictval.privateDictInfo.size = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
default:
|
2018-12-22 16:47:04 +01:00
|
|
|
env.last_offset = env.str_ref.offset;
|
|
|
|
top_dict_opset_t<cff1_top_dict_val_t>::process_op (op, env, dictval);
|
2018-12-01 05:04:59 +01:00
|
|
|
/* Record this operand below if stack is empty, otherwise done */
|
|
|
|
if (!env.argStack.is_empty ()) return;
|
|
|
|
break;
|
2018-08-10 20:07:07 +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-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_font_dict_values_t : dict_values_t<op_str_t>
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
dict_values_t<op_str_t>::init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
privateDictInfo.init ();
|
2018-09-11 01:00:20 +02:00
|
|
|
fontName = CFF_UNDEF_SID;
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
2018-12-22 16:47:04 +01:00
|
|
|
void fini () { dict_values_t<op_str_t>::fini (); }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
table_info_t privateDictInfo;
|
2018-09-11 01:00:20 +02:00
|
|
|
unsigned int fontName;
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_font_dict_opset_t : dict_opset_t
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, num_interp_env_t& env, cff1_font_dict_values_t& dictval)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case OpCode_FontName:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.fontName = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_FontMatrix:
|
|
|
|
case OpCode_PaintType:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +02:00
|
|
|
case OpCode_Private:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.privateDictInfo.offset = env.argStack.pop_uint ();
|
|
|
|
dictval.privateDictInfo.size = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-10 20:07:07 +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-08-10 20:07:07 +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-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename VAL>
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_private_dict_values_base_t : dict_values_t<VAL>
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-08-10 20:07:07 +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;
|
2018-08-16 09:13:09 +02:00
|
|
|
localSubrs = &Null(CFF1Subrs);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
2018-12-22 16:47:04 +01:00
|
|
|
void fini () { dict_values_t<VAL>::fini (); }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int calculate_serialized_size () const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
unsigned int size = 0;
|
2018-12-22 16:47:04 +01:00
|
|
|
for (unsigned int i = 0; i < dict_values_t<VAL>::get_count; i++)
|
|
|
|
if (dict_values_t<VAL>::get_value (i).op == OpCode_Subrs)
|
2018-12-01 05:04:59 +01:00
|
|
|
size += OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs);
|
2018-08-10 20:07:07 +02:00
|
|
|
else
|
2018-12-22 16:47:04 +01:00
|
|
|
size += dict_values_t<VAL>::get_value (i).str.length;
|
2018-08-10 20:07:07 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int subrsOffset;
|
2018-08-16 09:13:09 +02:00
|
|
|
const CFF1Subrs *localSubrs;
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef cff1_private_dict_values_base_t<op_str_t> cff1_private_dict_values_subset_t;
|
|
|
|
typedef cff1_private_dict_values_base_t<num_dict_val_t> cff1_private_dict_values_t;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_private_dict_opset_t : dict_opset_t
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, num_interp_env_t& env, cff1_private_dict_values_t& dictval)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
num_dict_val_t val;
|
2018-08-10 20:07:07 +02:00
|
|
|
val.init ();
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
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-08-10 20:07:07 +02:00
|
|
|
case OpCode_StdHW:
|
|
|
|
case OpCode_StdVW:
|
|
|
|
case OpCode_BlueScale:
|
|
|
|
case OpCode_BlueShift:
|
|
|
|
case OpCode_BlueFuzz:
|
|
|
|
case OpCode_ForceBold:
|
|
|
|
case OpCode_LanguageGroup:
|
|
|
|
case OpCode_ExpansionFactor:
|
|
|
|
case OpCode_initialRandomSeed:
|
|
|
|
case OpCode_defaultWidthX:
|
|
|
|
case OpCode_nominalWidthX:
|
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_Subrs:
|
2018-12-01 05:04:59 +01:00
|
|
|
dictval.subrsOffset = env.argStack.pop_uint ();
|
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +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-08-10 20:07:07 +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-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct cff1_private_dict_opset_subset : dict_opset_t
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
static void process_op (op_code_t op, num_interp_env_t& env, cff1_private_dict_values_subset_t& dictval)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case OpCode_BlueValues:
|
|
|
|
case OpCode_OtherBlues:
|
|
|
|
case OpCode_FamilyBlues:
|
|
|
|
case OpCode_FamilyOtherBlues:
|
|
|
|
case OpCode_StemSnapH:
|
|
|
|
case OpCode_StemSnapV:
|
|
|
|
case OpCode_StdHW:
|
|
|
|
case OpCode_StdVW:
|
|
|
|
case OpCode_BlueScale:
|
|
|
|
case OpCode_BlueShift:
|
|
|
|
case OpCode_BlueFuzz:
|
|
|
|
case OpCode_ForceBold:
|
|
|
|
case OpCode_LanguageGroup:
|
|
|
|
case OpCode_ExpansionFactor:
|
|
|
|
case OpCode_initialRandomSeed:
|
|
|
|
case OpCode_defaultWidthX:
|
|
|
|
case OpCode_nominalWidthX:
|
2018-12-01 05:04:59 +01:00
|
|
|
env.clear_args ();
|
|
|
|
break;
|
2018-08-10 20:07:07 +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-10 20:07:07 +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-08-10 20:07:07 +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-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef dict_interpreter_t<cff1_top_dict_opset_t, cff1_top_dict_values_t, cff1_top_dict_interp_env_t> cff1_top_dict_interpreter_t;
|
|
|
|
typedef dict_interpreter_t<cff1_font_dict_opset_t, cff1_font_dict_values_t> cff1_font_dict_interpreter_t;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
typedef CFF1Index CFF1NameIndex;
|
|
|
|
typedef CFF1IndexOf<TopDict> CFF1TopDictIndex;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-24 02:19:52 +01:00
|
|
|
} /* namespace CFF */
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
using namespace CFF;
|
|
|
|
|
2018-08-16 09:25:57 +02:00
|
|
|
struct cff1
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2019-01-22 12:08:57 +01:00
|
|
|
static constexpr hb_tag_t tableTag = HB_OT_TAG_cff1;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
2018-12-01 05:04:59 +01:00
|
|
|
likely (version.major == 1));
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 01:28:47 +02:00
|
|
|
template <typename PRIVOPSET, typename PRIVDICTVAL>
|
2018-08-10 20:07:07 +02:00
|
|
|
struct accelerator_templ_t
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
void init (hb_face_t *face)
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
2018-09-11 01:00:20 +02:00
|
|
|
topDict.init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
fontDicts.init ();
|
|
|
|
privateDicts.init ();
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-16 09:25:57 +02:00
|
|
|
this->blob = sc.reference_table<cff1> (face);
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
/* setup for run-time santization */
|
|
|
|
sc.init (this->blob);
|
|
|
|
sc.start_processing ();
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-08-16 09:25:57 +02:00
|
|
|
const OT::cff1 *cff = this->blob->template as<OT::cff1> ();
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-08-16 09:25:57 +02:00
|
|
|
if (cff == &Null(OT::cff1))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
|
|
|
|
|
|
|
nameIndex = &cff->nameIndex (cff);
|
2018-08-16 09:13:09 +02:00
|
|
|
if ((nameIndex == &Null (CFF1NameIndex)) || !nameIndex->sanitize (&sc))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
topDictIndex = &StructAtOffset<CFF1TopDictIndex> (nameIndex, nameIndex->get_size ());
|
|
|
|
if ((topDictIndex == &Null (CFF1TopDictIndex)) || !topDictIndex->sanitize (&sc) || (topDictIndex->count == 0))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
|
|
|
|
|
|
|
{ /* parse top dict */
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t topDictStr = (*topDictIndex)[0];
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; }
|
2018-12-22 16:47:04 +01:00
|
|
|
cff1_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-08-10 20:07:07 +02:00
|
|
|
}
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-14 22:38:03 +01:00
|
|
|
if (is_predef_charset ())
|
2018-12-01 05:04:59 +01:00
|
|
|
charset = &Null(Charset);
|
2018-11-14 22:38:03 +01:00
|
|
|
else
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
charset = &StructAtOffsetOrNull<Charset> (cff, topDict.CharsetOffset);
|
|
|
|
if (unlikely ((charset == &Null (Charset)) || !charset->sanitize (&sc))) { fini (); return; }
|
2018-11-14 22:38:03 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
fdCount = 1;
|
|
|
|
if (is_CID ())
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
fdArray = &StructAtOffsetOrNull<CFF1FDArray> (cff, topDict.FDArrayOffset);
|
|
|
|
fdSelect = &StructAtOffsetOrNull<CFF1FDSelect> (cff, topDict.FDSelectOffset);
|
|
|
|
if (unlikely ((fdArray == &Null(CFF1FDArray)) || !fdArray->sanitize (&sc) ||
|
|
|
|
(fdSelect == &Null(CFF1FDSelect)) || !fdSelect->sanitize (&sc, fdArray->count)))
|
|
|
|
{ fini (); return; }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-01 05:04:59 +01:00
|
|
|
fdCount = fdArray->count;
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
fdArray = &Null(CFF1FDArray);
|
|
|
|
fdSelect = &Null(CFF1FDSelect);
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
stringIndex = &StructAtOffset<CFF1StringIndex> (topDictIndex, topDictIndex->get_size ());
|
|
|
|
if ((stringIndex == &Null (CFF1StringIndex)) || !stringIndex->sanitize (&sc))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
globalSubrs = &StructAtOffset<CFF1Subrs> (stringIndex, stringIndex->get_size ());
|
2018-12-06 00:07:46 +01:00
|
|
|
if ((globalSubrs != &Null (CFF1Subrs)) && !globalSubrs->sanitize (&sc))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
|
|
|
|
2018-09-11 01:00:20 +02:00
|
|
|
charStrings = &StructAtOffsetOrNull<CFF1CharStrings> (cff, topDict.charStringsOffset);
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
if ((charStrings == &Null(CFF1CharStrings)) || unlikely (!charStrings->sanitize (&sc)))
|
2018-08-10 20:07:07 +02:00
|
|
|
{ fini (); return; }
|
|
|
|
|
|
|
|
num_glyphs = charStrings->count;
|
|
|
|
if (num_glyphs != sc.get_num_glyphs ())
|
|
|
|
{ fini (); return; }
|
|
|
|
|
|
|
|
privateDicts.resize (fdCount);
|
|
|
|
for (unsigned int i = 0; i < fdCount; i++)
|
2018-12-01 05:04:59 +01:00
|
|
|
privateDicts[i].init ();
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
// parse CID font dicts and gather private dicts
|
|
|
|
if (is_CID ())
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
for (unsigned int i = 0; i < fdCount; i++)
|
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
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
|
|
|
cff1_font_dict_values_t *font;
|
|
|
|
cff1_font_dict_interpreter_t font_interp;
|
2018-12-01 05:04:59 +01:00
|
|
|
font_interp.env.init (fontDictStr);
|
|
|
|
font = fontDicts.push ();
|
2018-12-22 16:47:04 +01:00
|
|
|
if (unlikely (font == &Crap(cff1_font_dict_values_t))) { fini (); return; }
|
2018-12-01 05:04:59 +01:00
|
|
|
font->init ();
|
|
|
|
if (unlikely (!font_interp.interpret (*font))) { fini (); return; }
|
|
|
|
PRIVDICTVAL *priv = &privateDicts[i];
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t privDictStr (StructAtOffset<UnsizedByteStr> (cff, 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> priv_interp;
|
2018-12-01 05:04:59 +01:00
|
|
|
priv_interp.env.init (privDictStr);
|
|
|
|
priv->init ();
|
|
|
|
if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; }
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
priv->localSubrs = &StructAtOffsetOrNull<CFF1Subrs> (&privDictStr, priv->subrsOffset);
|
2018-12-01 05:04:59 +01:00
|
|
|
if (priv->localSubrs != &Null(CFF1Subrs) &&
|
|
|
|
unlikely (!priv->localSubrs->sanitize (&sc)))
|
|
|
|
{ fini (); return; }
|
|
|
|
}
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
else /* non-CID */
|
|
|
|
{
|
2018-12-22 16:47:04 +01:00
|
|
|
cff1_top_dict_values_t *font = &topDict;
|
2018-12-01 05:04:59 +01:00
|
|
|
PRIVDICTVAL *priv = &privateDicts[0];
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t privDictStr (StructAtOffset<UnsizedByteStr> (cff, 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> priv_interp;
|
2018-12-01 05:04:59 +01:00
|
|
|
priv_interp.env.init (privDictStr);
|
|
|
|
priv->init ();
|
|
|
|
if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; }
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
priv->localSubrs = &StructAtOffsetOrNull<CFF1Subrs> (&privDictStr, priv->subrsOffset);
|
2018-12-01 05:04:59 +01:00
|
|
|
if (priv->localSubrs != &Null(CFF1Subrs) &&
|
|
|
|
unlikely (!priv->localSubrs->sanitize (&sc)))
|
|
|
|
{ fini (); return; }
|
2018-08-10 20:07:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void fini ()
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
sc.end_processing ();
|
2018-09-11 01:00:20 +02: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-08-10 20:07:07 +02:00
|
|
|
hb_blob_destroy (blob);
|
|
|
|
blob = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_valid () const { return blob != nullptr; }
|
|
|
|
bool is_CID () const { return topDict.is_CID (); }
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_predef_charset () const { return topDict.CharsetOffset <= ExpertSubsetCharset; }
|
2018-11-14 22:38:03 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int std_code_to_glyph (hb_codepoint_t code) const
|
2018-11-14 22:38:03 +01:00
|
|
|
{
|
|
|
|
hb_codepoint_t sid = lookup_standard_encoding_for_sid (code);
|
|
|
|
if (unlikely (sid == CFF_UNDEF_SID))
|
2018-12-01 05:04:59 +01:00
|
|
|
return 0;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-11-14 22:38:03 +01:00
|
|
|
if (charset != &Null(Charset))
|
2018-12-01 05:04:59 +01:00
|
|
|
return charset->get_glyph (sid, num_glyphs);
|
2018-11-14 22:38:03 +01:00
|
|
|
else if ((topDict.CharsetOffset == ISOAdobeCharset)
|
2018-12-01 05:04:59 +01:00
|
|
|
&& (code <= 228 /*zcaron*/)) return sid;
|
2018-11-14 22:38:03 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-17 20:14:56 +02:00
|
|
|
protected:
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_blob_t *blob;
|
2018-09-17 20:14:56 +02:00
|
|
|
hb_sanitize_context_t sc;
|
|
|
|
|
|
|
|
public:
|
2018-12-01 05:04:59 +01:00
|
|
|
const Charset *charset;
|
2018-09-17 20:14:56 +02:00
|
|
|
const CFF1NameIndex *nameIndex;
|
|
|
|
const CFF1TopDictIndex *topDictIndex;
|
|
|
|
const CFF1StringIndex *stringIndex;
|
2018-12-01 05:04:59 +01:00
|
|
|
const CFF1Subrs *globalSubrs;
|
2018-09-17 20:14:56 +02:00
|
|
|
const CFF1CharStrings *charStrings;
|
|
|
|
const CFF1FDArray *fdArray;
|
|
|
|
const CFF1FDSelect *fdSelect;
|
2018-12-01 05:04:59 +01:00
|
|
|
unsigned int fdCount;
|
2018-09-17 20:14:56 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
cff1_top_dict_values_t topDict;
|
|
|
|
hb_vector_t<cff1_font_dict_values_t> fontDicts;
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_vector_t<PRIVDICTVAL> privateDicts;
|
2018-09-17 20:14:56 +02:00
|
|
|
|
2018-12-01 05:04:59 +01:00
|
|
|
unsigned int num_glyphs;
|
2018-09-17 20:14:56 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct accelerator_t : accelerator_templ_t<cff1_private_dict_opset_t, cff1_private_dict_values_t>
|
2018-09-17 20:14:56 +02:00
|
|
|
{
|
2018-09-17 20:28:33 +02:00
|
|
|
HB_INTERNAL bool get_extents (hb_codepoint_t glyph, hb_glyph_extents_t *extents) const;
|
2018-11-14 22:38:03 +01:00
|
|
|
HB_INTERNAL bool get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const;
|
2018-09-17 20:14:56 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
struct accelerator_subset_t : accelerator_templ_t<cff1_private_dict_opset_subset, cff1_private_dict_values_subset_t>
|
2018-09-17 20:14:56 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
void init (hb_face_t *face)
|
2018-09-17 20:14:56 +02:00
|
|
|
{
|
|
|
|
SUPER::init (face);
|
|
|
|
if (blob == nullptr) return;
|
2018-12-01 04:54:57 +01:00
|
|
|
|
2018-09-17 21:11:56 +02:00
|
|
|
const OT::cff1 *cff = this->blob->as<OT::cff1> ();
|
2018-09-17 20:14:56 +02:00
|
|
|
encoding = &Null(Encoding);
|
|
|
|
if (is_CID ())
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
if (unlikely (charset == &Null(Charset))) { fini (); return; }
|
2018-09-17 20:14:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
if (!is_predef_encoding ())
|
|
|
|
{
|
|
|
|
encoding = &StructAtOffsetOrNull<Encoding> (cff, topDict.EncodingOffset);
|
|
|
|
if (unlikely ((encoding == &Null (Encoding)) || !encoding->sanitize (&sc))) { fini (); return; }
|
|
|
|
}
|
2018-09-17 20:14:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_predef_encoding () const { return topDict.EncodingOffset <= ExpertEncoding; }
|
2018-09-07 02:28:15 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t glyph_to_code (hb_codepoint_t glyph) const
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
if (encoding != &Null(Encoding))
|
2018-12-01 05:04:59 +01:00
|
|
|
return encoding->get_code (glyph);
|
2018-09-07 02:28:15 +02:00
|
|
|
else
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_codepoint_t sid = glyph_to_sid (glyph);
|
|
|
|
if (sid == 0) return 0;
|
|
|
|
hb_codepoint_t code = 0;
|
|
|
|
switch (topDict.EncodingOffset)
|
|
|
|
{
|
|
|
|
case StandardEncoding:
|
|
|
|
code = lookup_standard_encoding_for_code (sid);
|
|
|
|
break;
|
|
|
|
case ExpertEncoding:
|
|
|
|
code = lookup_expert_encoding_for_code (sid);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return code;
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t glyph_to_sid (hb_codepoint_t glyph) const
|
2018-09-07 02:28:15 +02:00
|
|
|
{
|
|
|
|
if (charset != &Null(Charset))
|
2018-12-01 05:04:59 +01:00
|
|
|
return charset->get_sid (glyph);
|
2018-09-07 02:28:15 +02:00
|
|
|
else
|
|
|
|
{
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_codepoint_t sid = 0;
|
|
|
|
switch (topDict.CharsetOffset)
|
|
|
|
{
|
|
|
|
case ISOAdobeCharset:
|
|
|
|
if (glyph <= 228 /*zcaron*/) sid = glyph;
|
|
|
|
break;
|
|
|
|
case ExpertCharset:
|
|
|
|
sid = lookup_expert_charset_for_sid (glyph);
|
|
|
|
break;
|
|
|
|
case ExpertSubsetCharset:
|
|
|
|
sid = lookup_expert_subset_charset_for_sid (glyph);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return sid;
|
2018-09-07 02:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 05:04:59 +01:00
|
|
|
const Encoding *encoding;
|
2018-08-10 20:07:07 +02:00
|
|
|
|
2018-09-17 20:14:56 +02:00
|
|
|
private:
|
2018-12-22 16:47:04 +01:00
|
|
|
typedef accelerator_templ_t<cff1_private_dict_opset_subset, cff1_private_dict_values_subset_t> SUPER;
|
2018-08-10 20:07:07 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool subset (hb_subset_plan_t *plan) const
|
2018-08-10 20:07:07 +02:00
|
|
|
{
|
|
|
|
hb_blob_t *cff_prime = nullptr;
|
|
|
|
|
|
|
|
bool success = true;
|
2018-08-16 09:13:09 +02:00
|
|
|
if (hb_subset_cff1 (plan, &cff_prime)) {
|
2018-08-16 09:25:57 +02:00
|
|
|
success = success && plan->add_table (HB_OT_TAG_cff1, cff_prime);
|
2018-09-13 19:55:56 +02:00
|
|
|
hb_blob_t *head_blob = hb_sanitize_context_t().reference_table<head> (plan->source);
|
|
|
|
success = success && head_blob && plan->add_table (HB_OT_TAG_head, head_blob);
|
|
|
|
hb_blob_destroy (head_blob);
|
2018-08-10 20:07:07 +02:00
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
hb_blob_destroy (cff_prime);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:28:15 +02:00
|
|
|
protected:
|
2018-11-14 22:38:03 +01:00
|
|
|
HB_INTERNAL static hb_codepoint_t lookup_standard_encoding_for_code (hb_codepoint_t sid);
|
|
|
|
HB_INTERNAL static hb_codepoint_t lookup_expert_encoding_for_code (hb_codepoint_t sid);
|
|
|
|
HB_INTERNAL static hb_codepoint_t lookup_expert_charset_for_sid (hb_codepoint_t glyph);
|
|
|
|
HB_INTERNAL static hb_codepoint_t lookup_expert_subset_charset_for_sid (hb_codepoint_t glyph);
|
|
|
|
HB_INTERNAL static hb_codepoint_t lookup_standard_encoding_for_sid (hb_codepoint_t code);
|
2018-09-07 02:28:15 +02:00
|
|
|
|
2018-08-10 20:07:07 +02:00
|
|
|
public:
|
2018-12-01 05:04:59 +01:00
|
|
|
FixedVersion<HBUINT8> version; /* Version of CFF table. set to 0x0100u */
|
2018-08-16 09:13:09 +02:00
|
|
|
OffsetTo<CFF1NameIndex, HBUINT8> nameIndex; /* headerSize = Offset to Name INDEX. */
|
2018-12-01 05:04:59 +01:00
|
|
|
HBUINT8 offSize; /* offset size (unused?) */
|
2018-08-10 20:07:07 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
2018-09-17 20:14:56 +02:00
|
|
|
struct cff1_accelerator_t : cff1::accelerator_t {};
|
2018-08-10 20:07:07 +02:00
|
|
|
} /* namespace OT */
|
|
|
|
|
2018-08-16 09:13:09 +02:00
|
|
|
#endif /* HB_OT_CFF1_TABLE_HH */
|