2014-05-09 21:35:56 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Google, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_OT_CMAP_TABLE_HH
|
|
|
|
#define HB_OT_CMAP_TABLE_HH
|
|
|
|
|
|
|
|
#include "hb-open-type-private.hh"
|
|
|
|
|
|
|
|
|
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cmap -- Character To Glyph Index Mapping Table
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define HB_OT_TAG_cmap HB_TAG('c','m','a','p')
|
|
|
|
|
|
|
|
|
2014-05-14 03:47:51 +02:00
|
|
|
struct CmapSubtableFormat0
|
|
|
|
{
|
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
|
|
|
{
|
|
|
|
hb_codepoint_t gid = codepoint < 256 ? glyphIdArray[codepoint] : 0;
|
|
|
|
if (!gid)
|
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-05-14 03:47:51 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this));
|
2014-05-14 03:47:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
USHORT format; /* Format number is set to 0. */
|
2014-06-27 23:30:59 +02:00
|
|
|
USHORT lengthZ; /* Byte length of this subtable. */
|
|
|
|
USHORT languageZ; /* Ignore. */
|
2014-05-14 03:47:51 +02:00
|
|
|
BYTE glyphIdArray[256];/* An array that maps character
|
|
|
|
* code to glyph index values. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (6 + 256);
|
|
|
|
};
|
|
|
|
|
2014-05-09 21:35:56 +02:00
|
|
|
struct CmapSubtableFormat4
|
|
|
|
{
|
2016-02-24 12:27:13 +01:00
|
|
|
struct accelerator_t
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
2016-02-24 12:27:13 +01:00
|
|
|
inline void init (const CmapSubtableFormat4 *subtable)
|
|
|
|
{
|
|
|
|
segCount = subtable->segCountX2 / 2;
|
|
|
|
endCount = subtable->values;
|
|
|
|
startCount = endCount + segCount + 1;
|
|
|
|
idDelta = startCount + segCount;
|
|
|
|
idRangeOffset = idDelta + segCount;
|
|
|
|
glyphIdArray = idRangeOffset + segCount;
|
|
|
|
glyphIdArrayLength = (subtable->length - 16 - 8 * segCount) / 2;
|
|
|
|
}
|
2014-05-10 01:55:51 +02:00
|
|
|
|
2016-02-24 12:27:13 +01:00
|
|
|
static inline bool get_glyph_func (const void *obj, hb_codepoint_t codepoint, hb_codepoint_t *glyph)
|
2014-05-10 01:55:51 +02:00
|
|
|
{
|
2016-02-24 12:27:13 +01:00
|
|
|
const accelerator_t *thiz = (const accelerator_t *) obj;
|
|
|
|
|
|
|
|
/* Custom two-array bsearch. */
|
|
|
|
int min = 0, max = (int) thiz->segCount - 1;
|
|
|
|
const USHORT *startCount = thiz->startCount;
|
|
|
|
const USHORT *endCount = thiz->endCount;
|
|
|
|
unsigned int i;
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
int mid = (min + max) / 2;
|
|
|
|
if (codepoint < startCount[mid])
|
|
|
|
max = mid - 1;
|
|
|
|
else if (codepoint > endCount[mid])
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = mid;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
found:
|
|
|
|
hb_codepoint_t gid;
|
|
|
|
unsigned int rangeOffset = thiz->idRangeOffset[i];
|
|
|
|
if (rangeOffset == 0)
|
|
|
|
gid = codepoint + thiz->idDelta[i];
|
2014-05-10 01:55:51 +02:00
|
|
|
else
|
|
|
|
{
|
2016-02-24 12:27:13 +01:00
|
|
|
/* Somebody has been smoking... */
|
|
|
|
unsigned int index = rangeOffset / 2 + (codepoint - thiz->startCount[i]) + i - thiz->segCount;
|
|
|
|
if (unlikely (index >= thiz->glyphIdArrayLength))
|
|
|
|
return false;
|
|
|
|
gid = thiz->glyphIdArray[index];
|
|
|
|
if (unlikely (!gid))
|
|
|
|
return false;
|
|
|
|
gid += thiz->idDelta[i];
|
2014-05-10 01:55:51 +02:00
|
|
|
}
|
2016-02-24 12:27:13 +01:00
|
|
|
|
|
|
|
*glyph = gid & 0xFFFFu;
|
|
|
|
return true;
|
2014-05-10 01:55:51 +02:00
|
|
|
}
|
|
|
|
|
2016-02-24 12:27:13 +01:00
|
|
|
const USHORT *endCount;
|
|
|
|
const USHORT *startCount;
|
|
|
|
const USHORT *idDelta;
|
|
|
|
const USHORT *idRangeOffset;
|
|
|
|
const USHORT *glyphIdArray;
|
|
|
|
unsigned int segCount;
|
|
|
|
unsigned int glyphIdArrayLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
|
|
|
{
|
|
|
|
accelerator_t accel;
|
|
|
|
accel.init (this);
|
|
|
|
return accel.get_glyph_func (&accel, codepoint, glyph);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
2014-06-05 00:47:55 +02:00
|
|
|
{
|
2014-05-09 21:35:56 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2014-06-05 00:47:55 +02:00
|
|
|
if (unlikely (!c->check_struct (this)))
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (false);
|
2014-06-05 00:47:55 +02:00
|
|
|
|
|
|
|
if (unlikely (!c->check_range (this, length)))
|
|
|
|
{
|
|
|
|
/* Some broken fonts have too long of a "length" value.
|
|
|
|
* If that is the case, just change the value to truncate
|
|
|
|
* the subtable at the end of the blob. */
|
|
|
|
uint16_t new_length = (uint16_t) MIN ((uintptr_t) 65535,
|
|
|
|
(uintptr_t) (c->end -
|
|
|
|
(char *) this));
|
|
|
|
if (!c->try_set (&length, new_length))
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (false);
|
2014-06-05 00:47:55 +02:00
|
|
|
}
|
|
|
|
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (16 + 4 * (unsigned int) segCountX2 <= length);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
USHORT format; /* Format number is set to 4. */
|
|
|
|
USHORT length; /* This is the length in bytes of the
|
|
|
|
* subtable. */
|
2014-06-27 23:30:59 +02:00
|
|
|
USHORT languageZ; /* Ignore. */
|
2014-05-09 21:35:56 +02:00
|
|
|
USHORT segCountX2; /* 2 x segCount. */
|
2014-06-27 23:30:59 +02:00
|
|
|
USHORT searchRangeZ; /* 2 * (2**floor(log2(segCount))) */
|
|
|
|
USHORT entrySelectorZ; /* log2(searchRange/2) */
|
|
|
|
USHORT rangeShiftZ; /* 2 x segCount - searchRange */
|
2014-05-09 21:35:56 +02:00
|
|
|
|
|
|
|
USHORT values[VAR];
|
|
|
|
#if 0
|
|
|
|
USHORT endCount[segCount]; /* End characterCode for each segment,
|
2014-07-11 20:54:42 +02:00
|
|
|
* last=0xFFFFu. */
|
2014-05-09 21:35:56 +02:00
|
|
|
USHORT reservedPad; /* Set to 0. */
|
|
|
|
USHORT startCount[segCount]; /* Start character code for each segment. */
|
|
|
|
SHORT idDelta[segCount]; /* Delta for all character codes in segment. */
|
|
|
|
USHORT idRangeOffset[segCount];/* Offsets into glyphIdArray or 0 */
|
|
|
|
USHORT glyphIdArray[VAR]; /* Glyph index array (arbitrary length) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (14, values);
|
|
|
|
};
|
|
|
|
|
2014-05-12 23:58:31 +02:00
|
|
|
struct CmapSubtableLongGroup
|
2014-05-12 23:51:15 +02:00
|
|
|
{
|
|
|
|
friend struct CmapSubtableFormat12;
|
2014-05-12 23:58:31 +02:00
|
|
|
friend struct CmapSubtableFormat13;
|
2014-05-12 23:51:15 +02:00
|
|
|
|
|
|
|
int cmp (hb_codepoint_t codepoint) const
|
|
|
|
{
|
|
|
|
if (codepoint < startCharCode) return -1;
|
|
|
|
if (codepoint > endCharCode) return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-05-12 23:51:15 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this));
|
2014-05-12 23:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ULONG startCharCode; /* First character code in this group. */
|
|
|
|
ULONG endCharCode; /* Last character code in this group. */
|
2014-05-12 23:58:31 +02:00
|
|
|
ULONG glyphID; /* Glyph index; interpretation depends on
|
|
|
|
* subtable format. */
|
2014-05-12 23:51:15 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
|
|
|
};
|
|
|
|
|
2014-05-14 03:17:28 +02:00
|
|
|
template <typename UINT>
|
|
|
|
struct CmapSubtableTrimmed
|
2014-05-13 00:19:29 +02:00
|
|
|
{
|
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
|
|
|
{
|
|
|
|
/* Rely on our implicit array bound-checking. */
|
|
|
|
hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode];
|
|
|
|
if (!gid)
|
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-05-13 00:19:29 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this) && glyphIdArray.sanitize (c));
|
2014-05-13 00:19:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-05-14 03:17:28 +02:00
|
|
|
UINT formatReserved; /* Subtable format and (maybe) padding. */
|
2014-06-27 23:30:59 +02:00
|
|
|
UINT lengthZ; /* Byte length of this subtable. */
|
|
|
|
UINT languageZ; /* Ignore. */
|
2014-05-14 03:17:28 +02:00
|
|
|
UINT startCharCode; /* First character code covered. */
|
2014-06-27 21:09:42 +02:00
|
|
|
ArrayOf<GlyphID, UINT>
|
2014-05-13 00:19:29 +02:00
|
|
|
glyphIdArray; /* Array of glyph index values for character
|
|
|
|
* codes in the range. */
|
|
|
|
public:
|
2014-05-14 03:17:28 +02:00
|
|
|
DEFINE_SIZE_ARRAY (5 * sizeof (UINT), glyphIdArray);
|
2014-05-13 00:19:29 +02:00
|
|
|
};
|
|
|
|
|
2014-05-14 03:17:28 +02:00
|
|
|
struct CmapSubtableFormat6 : CmapSubtableTrimmed<USHORT> {};
|
|
|
|
struct CmapSubtableFormat10 : CmapSubtableTrimmed<ULONG > {};
|
2014-05-13 00:19:29 +02:00
|
|
|
|
2014-05-14 03:26:34 +02:00
|
|
|
template <typename T>
|
|
|
|
struct CmapSubtableLongSegmented
|
2014-05-12 23:51:15 +02:00
|
|
|
{
|
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
|
|
|
{
|
2014-06-19 21:39:18 +02:00
|
|
|
int i = groups.bsearch (codepoint);
|
2014-05-12 23:51:15 +02:00
|
|
|
if (i == -1)
|
|
|
|
return false;
|
2014-05-14 03:26:34 +02:00
|
|
|
*glyph = T::group_get_glyph (groups[i], codepoint);
|
2014-05-12 23:51:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-05-12 23:51:15 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this) && groups.sanitize (c));
|
2014-05-12 23:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
USHORT format; /* Subtable format; set to 12. */
|
2014-06-27 23:30:59 +02:00
|
|
|
USHORT reservedZ; /* Reserved; set to 0. */
|
|
|
|
ULONG lengthZ; /* Byte length of this subtable. */
|
|
|
|
ULONG languageZ; /* Ignore. */
|
2014-06-27 21:23:18 +02:00
|
|
|
SortedArrayOf<CmapSubtableLongGroup, ULONG>
|
2014-05-12 23:58:31 +02:00
|
|
|
groups; /* Groupings. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (16, groups);
|
|
|
|
};
|
|
|
|
|
2014-05-14 03:26:34 +02:00
|
|
|
struct CmapSubtableFormat12 : CmapSubtableLongSegmented<CmapSubtableFormat12>
|
2014-05-12 23:58:31 +02:00
|
|
|
{
|
2014-05-14 03:26:34 +02:00
|
|
|
static inline hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group,
|
|
|
|
hb_codepoint_t u)
|
|
|
|
{ return group.glyphID + (u - group.startCharCode); }
|
|
|
|
};
|
2014-05-12 23:58:31 +02:00
|
|
|
|
2014-05-14 03:26:34 +02:00
|
|
|
struct CmapSubtableFormat13 : CmapSubtableLongSegmented<CmapSubtableFormat13>
|
|
|
|
{
|
|
|
|
static inline hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group,
|
|
|
|
hb_codepoint_t u HB_UNUSED)
|
|
|
|
{ return group.glyphID; }
|
2014-05-12 23:51:15 +02:00
|
|
|
};
|
|
|
|
|
2014-06-27 23:03:22 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GLYPH_VARIANT_NOT_FOUND = 0,
|
|
|
|
GLYPH_VARIANT_FOUND = 1,
|
|
|
|
GLYPH_VARIANT_USE_DEFAULT = 2
|
|
|
|
} glyph_variant_t;
|
|
|
|
|
|
|
|
struct UnicodeValueRange
|
|
|
|
{
|
|
|
|
inline int cmp (const hb_codepoint_t &codepoint) const
|
|
|
|
{
|
|
|
|
if (codepoint < startUnicodeValue) return -1;
|
|
|
|
if (codepoint > startUnicodeValue + additionalCount) return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-06-27 23:03:22 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this));
|
2014-06-27 23:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT24 startUnicodeValue; /* First value in this range. */
|
|
|
|
BYTE additionalCount; /* Number of additional values in this
|
|
|
|
* range. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SortedArrayOf<UnicodeValueRange, ULONG> DefaultUVS;
|
|
|
|
|
|
|
|
struct UVSMapping
|
|
|
|
{
|
|
|
|
inline int cmp (const hb_codepoint_t &codepoint) const
|
|
|
|
{
|
|
|
|
return unicodeValue.cmp (codepoint);
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-06-27 23:03:22 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this));
|
2014-06-27 23:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT24 unicodeValue; /* Base Unicode value of the UVS */
|
|
|
|
GlyphID glyphID; /* Glyph ID of the UVS */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (5);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SortedArrayOf<UVSMapping, ULONG> NonDefaultUVS;
|
|
|
|
|
|
|
|
struct VariationSelectorRecord
|
|
|
|
{
|
|
|
|
inline glyph_variant_t get_glyph (hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph,
|
|
|
|
const void *base) const
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const DefaultUVS &defaults = base+defaultUVS;
|
|
|
|
i = defaults.bsearch (codepoint);
|
|
|
|
if (i != -1)
|
|
|
|
return GLYPH_VARIANT_USE_DEFAULT;
|
|
|
|
const NonDefaultUVS &nonDefaults = base+nonDefaultUVS;
|
|
|
|
i = nonDefaults.bsearch (codepoint);
|
|
|
|
if (i != -1)
|
|
|
|
{
|
|
|
|
*glyph = nonDefaults[i].glyphID;
|
|
|
|
return GLYPH_VARIANT_FOUND;
|
|
|
|
}
|
|
|
|
return GLYPH_VARIANT_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int cmp (const hb_codepoint_t &variation_selector) const
|
|
|
|
{
|
|
|
|
return varSelector.cmp (variation_selector);
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
|
|
|
{
|
2014-06-27 23:03:22 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
defaultUVS.sanitize (c, base) &&
|
|
|
|
nonDefaultUVS.sanitize (c, base));
|
2014-06-27 23:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT24 varSelector; /* Variation selector. */
|
|
|
|
OffsetTo<DefaultUVS, ULONG>
|
|
|
|
defaultUVS; /* Offset to Default UVS Table. May be 0. */
|
|
|
|
OffsetTo<NonDefaultUVS, ULONG>
|
|
|
|
nonDefaultUVS; /* Offset to Non-Default UVS Table. May be 0. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (11);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CmapSubtableFormat14
|
|
|
|
{
|
|
|
|
inline glyph_variant_t get_glyph_variant (hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t *glyph) const
|
|
|
|
{
|
|
|
|
return record[record.bsearch(variation_selector)].get_glyph (codepoint, glyph, this);
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-06-27 23:03:22 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
record.sanitize (c, this));
|
2014-06-27 23:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-02-24 11:32:43 +01:00
|
|
|
USHORT format; /* Format number is set to 14. */
|
2014-06-27 23:30:59 +02:00
|
|
|
ULONG lengthZ; /* Byte length of this subtable. */
|
2014-06-27 23:03:22 +02:00
|
|
|
SortedArrayOf<VariationSelectorRecord, ULONG>
|
|
|
|
record; /* Variation selector records; sorted
|
|
|
|
* in increasing order of `varSelector'. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (10, record);
|
|
|
|
};
|
|
|
|
|
2014-05-09 21:35:56 +02:00
|
|
|
struct CmapSubtable
|
|
|
|
{
|
2014-05-14 06:42:18 +02:00
|
|
|
/* Note: We intentionally do NOT implement subtable formats 2 and 8. */
|
|
|
|
|
2014-06-27 23:03:22 +02:00
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph) const
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
|
|
|
switch (u.format) {
|
2014-05-14 03:47:51 +02:00
|
|
|
case 0: return u.format0 .get_glyph(codepoint, glyph);
|
2014-05-12 23:51:15 +02:00
|
|
|
case 4: return u.format4 .get_glyph(codepoint, glyph);
|
2014-05-13 00:19:29 +02:00
|
|
|
case 6: return u.format6 .get_glyph(codepoint, glyph);
|
|
|
|
case 10: return u.format10.get_glyph(codepoint, glyph);
|
2014-05-12 23:51:15 +02:00
|
|
|
case 12: return u.format12.get_glyph(codepoint, glyph);
|
2014-05-12 23:58:31 +02:00
|
|
|
case 13: return u.format13.get_glyph(codepoint, glyph);
|
2014-06-27 23:03:22 +02:00
|
|
|
case 14:
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-05-09 21:35:56 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
if (!u.format.sanitize (c)) return_trace (false);
|
2014-05-09 21:35:56 +02:00
|
|
|
switch (u.format) {
|
2015-09-29 15:57:02 +02:00
|
|
|
case 0: return_trace (u.format0 .sanitize (c));
|
|
|
|
case 4: return_trace (u.format4 .sanitize (c));
|
|
|
|
case 6: return_trace (u.format6 .sanitize (c));
|
|
|
|
case 10: return_trace (u.format10.sanitize (c));
|
|
|
|
case 12: return_trace (u.format12.sanitize (c));
|
|
|
|
case 13: return_trace (u.format13.sanitize (c));
|
|
|
|
case 14: return_trace (u.format14.sanitize (c));
|
|
|
|
default:return_trace (true);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 11:32:43 +01:00
|
|
|
public:
|
2014-05-09 21:35:56 +02:00
|
|
|
union {
|
|
|
|
USHORT format; /* Format identifier */
|
2014-05-14 03:47:51 +02:00
|
|
|
CmapSubtableFormat0 format0;
|
2014-05-09 21:35:56 +02:00
|
|
|
CmapSubtableFormat4 format4;
|
2014-05-13 00:19:29 +02:00
|
|
|
CmapSubtableFormat6 format6;
|
|
|
|
CmapSubtableFormat10 format10;
|
2014-05-12 23:51:15 +02:00
|
|
|
CmapSubtableFormat12 format12;
|
2014-05-12 23:58:31 +02:00
|
|
|
CmapSubtableFormat13 format13;
|
2014-06-27 23:03:22 +02:00
|
|
|
CmapSubtableFormat14 format14;
|
2014-05-09 21:35:56 +02:00
|
|
|
} u;
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_UNION (2, format);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct EncodingRecord
|
|
|
|
{
|
2014-06-05 01:00:29 +02:00
|
|
|
inline int cmp (const EncodingRecord &other) const
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2014-06-05 01:00:29 +02:00
|
|
|
ret = platformID.cmp (other.platformID);
|
2014-05-09 21:35:56 +02:00
|
|
|
if (ret) return ret;
|
2014-06-05 01:00:29 +02:00
|
|
|
ret = encodingID.cmp (other.encodingID);
|
2014-05-09 21:35:56 +02:00
|
|
|
if (ret) return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
|
|
|
{
|
2014-05-09 21:35:56 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
subtable.sanitize (c, base));
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
USHORT platformID; /* Platform ID. */
|
|
|
|
USHORT encodingID; /* Platform-specific encoding ID. */
|
2014-06-27 21:09:42 +02:00
|
|
|
OffsetTo<CmapSubtable, ULONG>
|
2014-05-09 21:35:56 +02:00
|
|
|
subtable; /* Byte offset from beginning of table to the subtable for this encoding. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (8);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cmap
|
|
|
|
{
|
|
|
|
static const hb_tag_t tableTag = HB_OT_TAG_cmap;
|
|
|
|
|
2014-05-12 19:46:29 +02:00
|
|
|
inline const CmapSubtable *find_subtable (unsigned int platform_id,
|
|
|
|
unsigned int encoding_id) const
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
|
|
|
EncodingRecord key;
|
|
|
|
key.platformID.set (platform_id);
|
|
|
|
key.encodingID.set (encoding_id);
|
|
|
|
|
2014-06-19 21:39:18 +02:00
|
|
|
/* Note: We can use bsearch, but since it has no performance
|
|
|
|
* implications, we use lsearch and as such accept fonts with
|
|
|
|
* unsorted subtable list. */
|
|
|
|
int result = encodingRecord./*bsearch*/lsearch (key);
|
2014-06-05 00:17:29 +02:00
|
|
|
if (result == -1 || !encodingRecord[result].subtable)
|
2014-05-12 19:46:29 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &(this+encodingRecord[result].subtable);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:27:44 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
2014-05-09 21:35:56 +02:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
likely (version == 0) &&
|
|
|
|
encodingRecord.sanitize (c, this));
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2014-06-05 01:00:29 +02:00
|
|
|
USHORT version; /* Table version number (0). */
|
2014-06-19 21:39:18 +02:00
|
|
|
SortedArrayOf<EncodingRecord>
|
2014-06-05 01:00:29 +02:00
|
|
|
encodingRecord; /* Encoding tables. */
|
2014-05-09 21:35:56 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (4, encodingRecord);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_OT_CMAP_TABLE_HH */
|