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
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-open-type.hh"
|
|
|
|
#include "hb-set.hh"
|
2014-05-09 21:35:56 +02:00
|
|
|
|
|
|
|
/*
|
2018-04-12 11:10:45 +02:00
|
|
|
* cmap -- Character to Glyph Index Mapping
|
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/cmap
|
2014-05-09 21:35:56 +02:00
|
|
|
*/
|
|
|
|
#define HB_OT_TAG_cmap HB_TAG('c','m','a','p')
|
|
|
|
|
2018-04-12 11:10:45 +02:00
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
|
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;
|
2018-08-30 01:38:04 +02:00
|
|
|
return true;
|
2014-05-14 03:47:51 +02:00
|
|
|
}
|
2018-08-25 18:35:45 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < 256; i++)
|
|
|
|
if (glyphIdArray[i])
|
|
|
|
out->add (i);
|
|
|
|
}
|
2014-05-14 03:47:51 +02:00
|
|
|
|
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:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format number is set to 0. */
|
2018-05-02 20:59:14 +02:00
|
|
|
HBUINT16 length; /* Byte length of this subtable. */
|
|
|
|
HBUINT16 language; /* Ignore. */
|
2018-02-12 02:00:42 +01:00
|
|
|
HBUINT8 glyphIdArray[256];/* An array that maps character
|
2014-05-14 03:47:51 +02:00
|
|
|
* code to glyph index values. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (6 + 256);
|
|
|
|
};
|
|
|
|
|
2014-05-09 21:35:56 +02:00
|
|
|
struct CmapSubtableFormat4
|
|
|
|
{
|
2018-05-03 01:12:04 +02:00
|
|
|
struct segment_plan
|
|
|
|
{
|
|
|
|
HBUINT16 start_code;
|
|
|
|
HBUINT16 end_code;
|
|
|
|
bool use_delta;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
const hb_subset_plan_t *plan,
|
|
|
|
const hb_vector_t<segment_plan> &segments)
|
|
|
|
{
|
2018-05-03 02:11:18 +02:00
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
|
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
|
|
|
|
|
|
|
this->format.set (4);
|
|
|
|
this->length.set (get_sub_table_size (segments));
|
|
|
|
|
|
|
|
this->segCountX2.set (segments.len * 2);
|
2018-07-10 14:12:37 +02:00
|
|
|
this->entrySelector.set (MAX (1u, hb_bit_storage (segments.len)) - 1);
|
2018-05-04 20:23:32 +02:00
|
|
|
this->searchRange.set (2 * (1u << this->entrySelector));
|
|
|
|
this->rangeShift.set (segments.len * 2 > this->searchRange
|
|
|
|
? 2 * segments.len - this->searchRange
|
|
|
|
: 0);
|
2018-05-03 02:11:18 +02:00
|
|
|
|
|
|
|
HBUINT16 *end_count = c->allocate_size<HBUINT16> (HBUINT16::static_size * segments.len);
|
|
|
|
c->allocate_size<HBUINT16> (HBUINT16::static_size); // 2 bytes of padding.
|
|
|
|
HBUINT16 *start_count = c->allocate_size<HBUINT16> (HBUINT16::static_size * segments.len);
|
|
|
|
HBINT16 *id_delta = c->allocate_size<HBINT16> (HBUINT16::static_size * segments.len);
|
|
|
|
HBUINT16 *id_range_offset = c->allocate_size<HBUINT16> (HBUINT16::static_size * segments.len);
|
|
|
|
|
2018-05-03 03:50:56 +02:00
|
|
|
if (id_range_offset == nullptr)
|
|
|
|
return_trace (false);
|
|
|
|
|
2018-05-03 02:11:18 +02:00
|
|
|
for (unsigned int i = 0; i < segments.len; i++)
|
|
|
|
{
|
|
|
|
end_count[i].set (segments[i].end_code);
|
|
|
|
start_count[i].set (segments[i].start_code);
|
|
|
|
if (segments[i].use_delta)
|
|
|
|
{
|
2018-05-03 03:50:56 +02:00
|
|
|
hb_codepoint_t cp = segments[i].start_code;
|
|
|
|
hb_codepoint_t start_gid = 0;
|
2018-05-30 21:23:51 +02:00
|
|
|
if (unlikely (!plan->new_gid_for_codepoint (cp, &start_gid) && cp != 0xFFFF))
|
2018-05-03 03:50:56 +02:00
|
|
|
return_trace (false);
|
2018-05-03 02:11:18 +02:00
|
|
|
id_delta[i].set (start_gid - segments[i].start_code);
|
|
|
|
} else {
|
2018-05-03 02:46:30 +02:00
|
|
|
id_delta[i].set (0);
|
|
|
|
unsigned int num_codepoints = segments[i].end_code - segments[i].start_code + 1;
|
|
|
|
HBUINT16 *glyph_id_array = c->allocate_size<HBUINT16> (HBUINT16::static_size * num_codepoints);
|
2018-05-03 03:50:56 +02:00
|
|
|
if (glyph_id_array == nullptr)
|
|
|
|
return_trace (false);
|
2018-05-03 02:46:30 +02:00
|
|
|
// From the cmap spec:
|
|
|
|
//
|
|
|
|
// id_range_offset[i]/2
|
|
|
|
// + (cp - segments[i].start_code)
|
|
|
|
// + (id_range_offset + i)
|
|
|
|
// =
|
|
|
|
// glyph_id_array + (cp - segments[i].start_code)
|
|
|
|
//
|
|
|
|
// So, solve for id_range_offset[i]:
|
|
|
|
//
|
|
|
|
// id_range_offset[i]
|
|
|
|
// =
|
|
|
|
// 2 * (glyph_id_array - id_range_offset - i)
|
|
|
|
id_range_offset[i].set (2 * (
|
|
|
|
glyph_id_array - id_range_offset - i));
|
|
|
|
for (unsigned int j = 0; j < num_codepoints; j++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t cp = segments[i].start_code + j;
|
2018-05-03 03:50:56 +02:00
|
|
|
hb_codepoint_t new_gid;
|
2018-05-30 21:23:51 +02:00
|
|
|
if (unlikely (!plan->new_gid_for_codepoint (cp, &new_gid)))
|
2018-05-03 03:50:56 +02:00
|
|
|
return_trace (false);
|
2018-05-03 02:46:30 +02:00
|
|
|
glyph_id_array[j].set (new_gid);
|
|
|
|
}
|
2018-05-03 02:11:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-03 03:50:56 +02:00
|
|
|
return_trace (true);
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t get_sub_table_size (const hb_vector_t<segment_plan> &segments)
|
|
|
|
{
|
|
|
|
size_t segment_size = 0;
|
|
|
|
for (unsigned int i = 0; i < segments.len; i++)
|
|
|
|
{
|
|
|
|
// Parallel array entries
|
|
|
|
segment_size +=
|
|
|
|
2 // end count
|
|
|
|
+ 2 // start count
|
|
|
|
+ 2 // delta
|
|
|
|
+ 2; // range offset
|
|
|
|
|
|
|
|
if (!segments[i].use_delta)
|
|
|
|
// Add bytes for the glyph index array entries for this segment.
|
|
|
|
segment_size += (segments[i].end_code - segments[i].start_code + 1) * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return min_size
|
|
|
|
+ 2 // Padding
|
|
|
|
+ segment_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool create_sub_table_plan (const hb_subset_plan_t *plan,
|
|
|
|
hb_vector_t<segment_plan> *segments)
|
|
|
|
{
|
2018-05-03 01:37:38 +02:00
|
|
|
segment_plan *segment = nullptr;
|
|
|
|
hb_codepoint_t last_gid = 0;
|
2018-05-30 21:23:51 +02:00
|
|
|
|
|
|
|
hb_codepoint_t cp = HB_SET_VALUE_INVALID;
|
|
|
|
while (plan->unicodes->next (&cp)) {
|
2018-05-03 01:37:38 +02:00
|
|
|
hb_codepoint_t new_gid;
|
2018-05-30 21:23:51 +02:00
|
|
|
if (unlikely (!plan->new_gid_for_codepoint (cp, &new_gid)))
|
2018-05-03 01:37:38 +02:00
|
|
|
{
|
|
|
|
DEBUG_MSG(SUBSET, nullptr, "Unable to find new gid for %04x", cp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp > 0xFFFF) {
|
|
|
|
// We are now outside of unicode BMP, stop adding to this cmap.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!segment
|
2018-05-10 00:28:30 +02:00
|
|
|
|| cp != segment->end_code + 1u)
|
2018-05-03 01:37:38 +02:00
|
|
|
{
|
|
|
|
segment = segments->push ();
|
|
|
|
segment->start_code.set (cp);
|
|
|
|
segment->end_code.set (cp);
|
|
|
|
segment->use_delta = true;
|
|
|
|
} else {
|
|
|
|
segment->end_code.set (cp);
|
2018-05-10 00:28:30 +02:00
|
|
|
if (last_gid + 1u != new_gid)
|
2018-05-03 01:37:38 +02:00
|
|
|
// gid's are not consecutive in this segment so delta
|
|
|
|
// cannot be used.
|
|
|
|
segment->use_delta = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_gid = new_gid;
|
|
|
|
}
|
2018-05-03 03:50:56 +02:00
|
|
|
|
|
|
|
// There must be a final entry with end_code == 0xFFFF. Check if we need to add one.
|
2018-06-02 02:48:37 +02:00
|
|
|
if (segment == nullptr || segment->end_code != 0xFFFF)
|
|
|
|
{
|
2018-05-03 03:50:56 +02:00
|
|
|
segment = segments->push ();
|
|
|
|
segment->start_code.set (0xFFFF);
|
|
|
|
segment->end_code.set (0xFFFF);
|
|
|
|
segment->use_delta = true;
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:37:38 +02:00
|
|
|
return true;
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
|
|
|
|
2016-02-24 12:27:13 +01:00
|
|
|
struct accelerator_t
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
2018-10-30 06:35:44 +01:00
|
|
|
inline accelerator_t (void) {}
|
|
|
|
inline accelerator_t (const CmapSubtableFormat4 *subtable) { init (subtable); }
|
|
|
|
inline ~accelerator_t (void) { fini (); }
|
|
|
|
|
2016-02-24 12:27:13 +01:00
|
|
|
inline void init (const CmapSubtableFormat4 *subtable)
|
|
|
|
{
|
|
|
|
segCount = subtable->segCountX2 / 2;
|
2018-09-10 23:29:26 +02:00
|
|
|
endCount = subtable->values.arrayZ;
|
2016-02-24 12:27:13 +01:00
|
|
|
startCount = endCount + segCount + 1;
|
|
|
|
idDelta = startCount + segCount;
|
|
|
|
idRangeOffset = idDelta + segCount;
|
|
|
|
glyphIdArray = idRangeOffset + segCount;
|
|
|
|
glyphIdArrayLength = (subtable->length - 16 - 8 * segCount) / 2;
|
|
|
|
}
|
2018-08-26 06:08:15 +02:00
|
|
|
inline void fini (void) {}
|
2014-05-10 01:55:51 +02:00
|
|
|
|
2018-08-26 00:25:03 +02:00
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
2014-05-10 01:55:51 +02:00
|
|
|
{
|
2016-02-24 12:27:13 +01:00
|
|
|
/* Custom two-array bsearch. */
|
2018-08-26 00:25:03 +02:00
|
|
|
int min = 0, max = (int) this->segCount - 1;
|
|
|
|
const HBUINT16 *startCount = this->startCount;
|
|
|
|
const HBUINT16 *endCount = this->endCount;
|
2016-02-24 12:27:13 +01:00
|
|
|
unsigned int i;
|
|
|
|
while (min <= max)
|
|
|
|
{
|
2018-10-25 22:19:34 +02:00
|
|
|
int mid = ((unsigned int) min + (unsigned int) max) / 2;
|
2016-02-24 12:27:13 +01:00
|
|
|
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;
|
2018-08-26 00:25:03 +02:00
|
|
|
unsigned int rangeOffset = this->idRangeOffset[i];
|
2016-02-24 12:27:13 +01:00
|
|
|
if (rangeOffset == 0)
|
2018-08-26 00:25:03 +02:00
|
|
|
gid = codepoint + this->idDelta[i];
|
2014-05-10 01:55:51 +02:00
|
|
|
else
|
|
|
|
{
|
2016-02-24 12:27:13 +01:00
|
|
|
/* Somebody has been smoking... */
|
2018-08-26 00:25:03 +02:00
|
|
|
unsigned int index = rangeOffset / 2 + (codepoint - this->startCount[i]) + i - this->segCount;
|
|
|
|
if (unlikely (index >= this->glyphIdArrayLength))
|
2016-02-24 12:27:13 +01:00
|
|
|
return false;
|
2018-08-26 00:25:03 +02:00
|
|
|
gid = this->glyphIdArray[index];
|
2016-02-24 12:27:13 +01:00
|
|
|
if (unlikely (!gid))
|
|
|
|
return false;
|
2018-08-26 00:25:03 +02:00
|
|
|
gid += this->idDelta[i];
|
2014-05-10 01:55:51 +02:00
|
|
|
}
|
2018-08-30 01:38:04 +02:00
|
|
|
gid &= 0xFFFFu;
|
|
|
|
if (!gid)
|
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
|
|
|
return true;
|
2014-05-10 01:55:51 +02:00
|
|
|
}
|
2018-08-26 00:25:03 +02:00
|
|
|
static inline bool get_glyph_func (const void *obj, hb_codepoint_t codepoint, hb_codepoint_t *glyph)
|
|
|
|
{
|
|
|
|
return ((const accelerator_t *) obj)->get_glyph (codepoint, glyph);
|
|
|
|
}
|
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
2018-08-26 01:14:32 +02:00
|
|
|
unsigned int count = this->segCount;
|
|
|
|
if (count && this->startCount[count - 1] == 0xFFFFu)
|
|
|
|
count--; /* Skip sentinel segment. */
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2018-08-26 00:25:03 +02:00
|
|
|
{
|
2018-08-26 06:23:43 +02:00
|
|
|
unsigned int rangeOffset = this->idRangeOffset[i];
|
|
|
|
if (rangeOffset == 0)
|
|
|
|
out->add_range (this->startCount[i], this->endCount[i]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (hb_codepoint_t codepoint = this->startCount[i];
|
|
|
|
codepoint <= this->endCount[i];
|
|
|
|
codepoint++)
|
|
|
|
{
|
|
|
|
unsigned int index = rangeOffset / 2 + (codepoint - this->startCount[i]) + i - this->segCount;
|
|
|
|
if (unlikely (index >= this->glyphIdArrayLength))
|
|
|
|
break;
|
|
|
|
hb_codepoint_t gid = this->glyphIdArray[index];
|
|
|
|
if (unlikely (!gid))
|
|
|
|
continue;
|
|
|
|
out->add (codepoint);
|
|
|
|
}
|
|
|
|
}
|
2018-08-26 00:25:03 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-10 01:55:51 +02:00
|
|
|
|
2018-01-10 03:07:30 +01:00
|
|
|
const HBUINT16 *endCount;
|
|
|
|
const HBUINT16 *startCount;
|
|
|
|
const HBUINT16 *idDelta;
|
|
|
|
const HBUINT16 *idRangeOffset;
|
|
|
|
const HBUINT16 *glyphIdArray;
|
2016-02-24 12:27:13 +01:00
|
|
|
unsigned int segCount;
|
|
|
|
unsigned int glyphIdArrayLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
|
|
|
{
|
2018-10-30 06:35:44 +01:00
|
|
|
accelerator_t accel (this);
|
2016-02-24 12:27:13 +01:00
|
|
|
return accel.get_glyph_func (&accel, codepoint, glyph);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
2018-08-25 18:33:30 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
2018-10-30 06:35:44 +01:00
|
|
|
accelerator_t accel (this);
|
2018-08-26 00:25:03 +02:00
|
|
|
accel.collect_unicodes (out);
|
2018-08-25 18:33:30 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-05-03 01:12:04 +02:00
|
|
|
|
|
|
|
|
2014-05-09 21:35:56 +02:00
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format number is set to 4. */
|
|
|
|
HBUINT16 length; /* This is the length in bytes of the
|
2014-05-09 21:35:56 +02:00
|
|
|
* subtable. */
|
2018-05-02 20:59:14 +02:00
|
|
|
HBUINT16 language; /* Ignore. */
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 segCountX2; /* 2 x segCount. */
|
2018-05-02 20:59:14 +02:00
|
|
|
HBUINT16 searchRange; /* 2 * (2**floor(log2(segCount))) */
|
|
|
|
HBUINT16 entrySelector; /* log2(searchRange/2) */
|
|
|
|
HBUINT16 rangeShift; /* 2 x segCount - searchRange */
|
2014-05-09 21:35:56 +02:00
|
|
|
|
2018-09-10 23:29:26 +02:00
|
|
|
UnsizedArrayOf<HBUINT16>
|
|
|
|
values;
|
2014-05-09 21:35:56 +02:00
|
|
|
#if 0
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 endCount[segCount]; /* End characterCode for each segment,
|
2014-07-11 20:54:42 +02:00
|
|
|
* last=0xFFFFu. */
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 reservedPad; /* Set to 0. */
|
|
|
|
HBUINT16 startCount[segCount]; /* Start character code for each segment. */
|
|
|
|
HBINT16 idDelta[segCount]; /* Delta for all character codes in segment. */
|
|
|
|
HBUINT16 idRangeOffset[segCount];/* Offsets into glyphIdArray or 0 */
|
2018-09-10 23:29:26 +02:00
|
|
|
UnsizedArrayOf<HBUINT16>
|
|
|
|
glyphIdArray; /* Glyph index array (arbitrary length) */
|
2014-05-09 21:35:56 +02:00
|
|
|
#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;
|
2018-04-17 15:00:23 +02:00
|
|
|
template<typename U>
|
|
|
|
friend struct CmapSubtableLongSegmented;
|
2018-02-09 04:39:57 +01:00
|
|
|
friend struct cmap;
|
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:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT32 startCharCode; /* First character code in this group. */
|
|
|
|
HBUINT32 endCharCode; /* Last character code in this group. */
|
|
|
|
HBUINT32 glyphID; /* Glyph index; interpretation depends on
|
2018-08-25 18:35:45 +02:00
|
|
|
* 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;
|
2018-08-30 01:38:04 +02:00
|
|
|
return true;
|
2014-05-13 00:19:29 +02:00
|
|
|
}
|
2018-08-25 18:35:45 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
hb_codepoint_t start = startCharCode;
|
|
|
|
unsigned int count = glyphIdArray.len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
if (glyphIdArray[i])
|
|
|
|
out->add (start + i);
|
|
|
|
}
|
2014-05-13 00:19:29 +02:00
|
|
|
|
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. */
|
2018-05-02 20:59:14 +02:00
|
|
|
UINT length; /* Byte length of this subtable. */
|
|
|
|
UINT language; /* 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
|
|
|
};
|
|
|
|
|
2018-01-10 03:07:30 +01:00
|
|
|
struct CmapSubtableFormat6 : CmapSubtableTrimmed<HBUINT16> {};
|
|
|
|
struct CmapSubtableFormat10 : CmapSubtableTrimmed<HBUINT32 > {};
|
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
|
|
|
{
|
2018-02-10 02:33:34 +01:00
|
|
|
friend struct cmap;
|
|
|
|
|
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;
|
2018-08-30 01:38:04 +02:00
|
|
|
hb_codepoint_t gid = T::group_get_glyph (groups[i], codepoint);
|
|
|
|
if (!gid)
|
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
|
|
|
return true;
|
2014-05-12 23:51:15 +02:00
|
|
|
}
|
|
|
|
|
2018-08-25 17:47:06 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
2018-04-17 15:00:23 +02:00
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < this->groups.len; i++) {
|
2018-08-26 01:11:26 +02:00
|
|
|
out->add_range (this->groups[i].startCharCode,
|
|
|
|
MIN ((hb_codepoint_t) this->groups[i].endCharCode,
|
2018-08-26 07:07:17 +02:00
|
|
|
(hb_codepoint_t) HB_UNICODE_MAX));
|
2018-04-17 15:00:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-02-19 01:27:59 +01:00
|
|
|
inline bool serialize (hb_serialize_context_t *c,
|
2018-05-03 00:42:43 +02:00
|
|
|
const hb_vector_t<CmapSubtableLongGroup> &group_data)
|
2018-02-10 02:33:34 +01:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
2018-02-19 01:27:59 +01:00
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2018-10-26 01:50:38 +02:00
|
|
|
Supplier<CmapSubtableLongGroup> supplier (group_data, group_data.len);
|
2018-02-19 01:27:59 +01:00
|
|
|
if (unlikely (!groups.serialize (c, supplier, group_data.len))) return_trace (false);
|
2018-02-10 02:33:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-12 23:51:15 +02:00
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Subtable format; set to 12. */
|
2018-05-02 20:59:14 +02:00
|
|
|
HBUINT16 reserved; /* Reserved; set to 0. */
|
|
|
|
HBUINT32 length; /* Byte length of this subtable. */
|
|
|
|
HBUINT32 language; /* Ignore. */
|
2018-01-10 03:07:30 +01:00
|
|
|
SortedArrayOf<CmapSubtableLongGroup, HBUINT32>
|
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); }
|
2018-05-03 00:42:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
const hb_vector_t<CmapSubtableLongGroup> &groups)
|
|
|
|
{
|
|
|
|
if (unlikely (!c->extend_min (*this))) return false;
|
|
|
|
|
|
|
|
this->format.set (12);
|
2018-05-04 20:23:32 +02:00
|
|
|
this->reserved.set (0);
|
|
|
|
this->length.set (get_sub_table_size (groups));
|
2018-05-03 00:42:43 +02:00
|
|
|
|
2018-05-03 22:14:28 +02:00
|
|
|
return CmapSubtableLongSegmented<CmapSubtableFormat12>::serialize (c, groups);
|
2018-05-03 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t get_sub_table_size (const hb_vector_t<CmapSubtableLongGroup> &groups)
|
|
|
|
{
|
|
|
|
return 16 + 12 * groups.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool create_sub_table_plan (const hb_subset_plan_t *plan,
|
|
|
|
hb_vector_t<CmapSubtableLongGroup> *groups)
|
|
|
|
{
|
|
|
|
CmapSubtableLongGroup *group = nullptr;
|
|
|
|
|
2018-05-30 21:23:51 +02:00
|
|
|
hb_codepoint_t cp = HB_SET_VALUE_INVALID;
|
|
|
|
while (plan->unicodes->next (&cp)) {
|
2018-05-03 00:42:43 +02:00
|
|
|
hb_codepoint_t new_gid;
|
2018-05-30 21:23:51 +02:00
|
|
|
if (unlikely (!plan->new_gid_for_codepoint (cp, &new_gid)))
|
2018-05-03 00:42:43 +02:00
|
|
|
{
|
|
|
|
DEBUG_MSG(SUBSET, nullptr, "Unable to find new gid for %04x", cp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group || !_is_gid_consecutive (group, cp, new_gid))
|
|
|
|
{
|
|
|
|
group = groups->push ();
|
|
|
|
group->startCharCode.set (cp);
|
|
|
|
group->endCharCode.set (cp);
|
|
|
|
group->glyphID.set (new_gid);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
group->endCharCode.set (cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_MSG(SUBSET, nullptr, "cmap");
|
|
|
|
for (unsigned int i = 0; i < groups->len; i++) {
|
|
|
|
CmapSubtableLongGroup& group = (*groups)[i];
|
|
|
|
DEBUG_MSG(SUBSET, nullptr, " %d: U+%04X-U+%04X, gid %d-%d", i, (uint32_t) group.startCharCode, (uint32_t) group.endCharCode, (uint32_t) group.glyphID, (uint32_t) group.glyphID + ((uint32_t) group.endCharCode - (uint32_t) group.startCharCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static inline bool _is_gid_consecutive (CmapSubtableLongGroup *group,
|
|
|
|
hb_codepoint_t cp,
|
|
|
|
hb_codepoint_t new_gid)
|
|
|
|
{
|
|
|
|
return (cp - 1 == group->endCharCode) &&
|
|
|
|
new_gid == group->glyphID + (cp - group->startCharCode);
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:26:34 +02:00
|
|
|
};
|
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
|
|
|
}
|
|
|
|
|
2018-04-15 18:48:48 +02:00
|
|
|
HBUINT24 startUnicodeValue; /* First value in this range. */
|
2018-08-26 00:56:07 +02:00
|
|
|
HBUINT8 additionalCount; /* Number of additional values in this
|
2014-06-27 23:03:22 +02:00
|
|
|
* range. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
2018-08-26 01:11:26 +02:00
|
|
|
struct DefaultUVS : SortedArrayOf<UnicodeValueRange, HBUINT32>
|
|
|
|
{
|
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
unsigned int count = len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t first = arrayZ[i].startUnicodeValue;
|
|
|
|
hb_codepoint_t last = MIN ((hb_codepoint_t) (first + arrayZ[i].additionalCount),
|
2018-08-26 07:07:17 +02:00
|
|
|
(hb_codepoint_t) HB_UNICODE_MAX);
|
2018-08-26 01:11:26 +02:00
|
|
|
out->add_range (first, last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (4, arrayZ);
|
|
|
|
};
|
2014-06-27 23:03:22 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-15 18:48:48 +02:00
|
|
|
HBUINT24 unicodeValue; /* Base Unicode value of the UVS */
|
2014-06-27 23:03:22 +02:00
|
|
|
GlyphID glyphID; /* Glyph ID of the UVS */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (5);
|
|
|
|
};
|
|
|
|
|
2018-08-26 01:11:26 +02:00
|
|
|
struct NonDefaultUVS : SortedArrayOf<UVSMapping, HBUINT32>
|
|
|
|
{
|
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
unsigned int count = len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
out->add (arrayZ[i].glyphID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (4, arrayZ);
|
|
|
|
};
|
2014-06-27 23:03:22 +02:00
|
|
|
|
|
|
|
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);
|
2018-08-30 01:38:04 +02:00
|
|
|
if (i != -1 && nonDefaults[i].glyphID)
|
2014-06-27 23:03:22 +02:00
|
|
|
{
|
|
|
|
*glyph = nonDefaults[i].glyphID;
|
|
|
|
return GLYPH_VARIANT_FOUND;
|
|
|
|
}
|
|
|
|
return GLYPH_VARIANT_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2018-08-26 01:11:26 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out, const void *base) const
|
|
|
|
{
|
|
|
|
(base+defaultUVS).collect_unicodes (out);
|
|
|
|
(base+nonDefaultUVS).collect_unicodes (out);
|
|
|
|
}
|
|
|
|
|
2014-06-27 23:03:22 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-15 18:48:48 +02:00
|
|
|
HBUINT24 varSelector; /* Variation selector. */
|
2017-01-23 05:28:56 +01:00
|
|
|
LOffsetTo<DefaultUVS>
|
2018-10-13 12:30:05 +02:00
|
|
|
defaultUVS; /* Offset to Default UVS Table. May be 0. */
|
2017-01-23 05:28:56 +01:00
|
|
|
LOffsetTo<NonDefaultUVS>
|
2018-10-13 12:30:05 +02:00
|
|
|
nonDefaultUVS; /* Offset to Non-Default UVS Table. May be 0. */
|
2014-06-27 23:03:22 +02:00
|
|
|
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
|
|
|
|
{
|
2018-08-26 01:11:26 +02:00
|
|
|
return record[record.bsearch (variation_selector)].get_glyph (codepoint, glyph, this);
|
2014-06-27 23:03:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 00:56:07 +02:00
|
|
|
inline void collect_variation_selectors (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
unsigned int count = record.len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
out->add (record.arrayZ[i].varSelector);
|
|
|
|
}
|
2018-08-26 01:11:26 +02:00
|
|
|
inline void collect_variation_unicodes (hb_codepoint_t variation_selector,
|
|
|
|
hb_set_t *out) const
|
|
|
|
{
|
|
|
|
record[record.bsearch (variation_selector)].collect_unicodes (out, this);
|
|
|
|
}
|
2018-08-26 00:56:07 +02:00
|
|
|
|
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:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 format; /* Format number is set to 14. */
|
2018-05-02 20:59:14 +02:00
|
|
|
HBUINT32 length; /* Byte length of this subtable. */
|
2018-01-10 03:07:30 +01:00
|
|
|
SortedArrayOf<VariationSelectorRecord, HBUINT32>
|
2014-06-27 23:03:22 +02:00
|
|
|
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) {
|
2018-02-15 04:36:33 +01:00
|
|
|
case 0: return u.format0 .get_glyph (codepoint, glyph);
|
|
|
|
case 4: return u.format4 .get_glyph (codepoint, glyph);
|
|
|
|
case 6: return u.format6 .get_glyph (codepoint, glyph);
|
|
|
|
case 10: return u.format10.get_glyph (codepoint, glyph);
|
|
|
|
case 12: return u.format12.get_glyph (codepoint, glyph);
|
|
|
|
case 13: return u.format13.get_glyph (codepoint, glyph);
|
2014-06-27 23:03:22 +02:00
|
|
|
case 14:
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-25 18:33:30 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
switch (u.format) {
|
2018-08-25 18:35:45 +02:00
|
|
|
case 0: u.format0 .collect_unicodes (out); return;
|
2018-08-25 18:33:30 +02:00
|
|
|
case 4: u.format4 .collect_unicodes (out); return;
|
2018-08-25 18:35:45 +02:00
|
|
|
case 6: u.format6 .collect_unicodes (out); return;
|
|
|
|
case 10: u.format10.collect_unicodes (out); return;
|
2018-08-25 18:33:30 +02:00
|
|
|
case 12: u.format12.collect_unicodes (out); return;
|
|
|
|
case 13: u.format13.collect_unicodes (out); return;
|
|
|
|
case 14:
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 23:03:22 +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
|
|
|
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 {
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 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
|
|
|
}
|
|
|
|
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 platformID; /* Platform ID. */
|
|
|
|
HBUINT16 encodingID; /* Platform-specific encoding ID. */
|
2017-01-23 05:28:56 +01:00
|
|
|
LOffsetTo<CmapSubtable>
|
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;
|
|
|
|
|
2018-08-26 09:21:29 +02:00
|
|
|
struct subset_plan
|
|
|
|
{
|
2018-05-03 00:42:43 +02:00
|
|
|
inline size_t final_size() const
|
|
|
|
{
|
2018-05-03 03:50:56 +02:00
|
|
|
return 4 // header
|
2018-05-03 19:53:20 +02:00
|
|
|
+ 8 * 3 // 3 EncodingRecord
|
2018-05-03 03:50:56 +02:00
|
|
|
+ CmapSubtableFormat4::get_sub_table_size (this->format4_segments)
|
|
|
|
+ CmapSubtableFormat12::get_sub_table_size (this->format12_groups);
|
2018-05-03 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
2018-10-30 02:05:25 +01:00
|
|
|
hb_vector_t<CmapSubtableFormat4::segment_plan> format4_segments;
|
|
|
|
hb_vector_t<CmapSubtableLongGroup> format12_groups;
|
2018-05-03 00:42:43 +02:00
|
|
|
};
|
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
likely (version == 0) &&
|
|
|
|
encodingRecord.sanitize (c, this));
|
|
|
|
}
|
|
|
|
|
2018-05-03 00:42:43 +02:00
|
|
|
inline bool _create_plan (const hb_subset_plan_t *plan,
|
|
|
|
subset_plan *cmap_plan) const
|
2018-02-08 00:59:36 +01:00
|
|
|
{
|
2018-05-03 01:12:04 +02:00
|
|
|
if (unlikely( !CmapSubtableFormat4::create_sub_table_plan (plan, &cmap_plan->format4_segments)))
|
|
|
|
return false;
|
2018-02-12 23:29:23 +01:00
|
|
|
|
2018-05-03 01:12:04 +02:00
|
|
|
return CmapSubtableFormat12::create_sub_table_plan (plan, &cmap_plan->format12_groups);
|
2018-02-10 02:33:34 +01:00
|
|
|
}
|
|
|
|
|
2018-05-03 01:12:04 +02:00
|
|
|
inline bool _subset (const hb_subset_plan_t *plan,
|
|
|
|
const subset_plan &cmap_subset_plan,
|
2018-02-15 03:50:19 +01:00
|
|
|
size_t dest_sz,
|
|
|
|
void *dest) const
|
2018-02-10 02:33:34 +01:00
|
|
|
{
|
2018-02-19 01:27:59 +01:00
|
|
|
hb_serialize_context_t c (dest, dest_sz);
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-07-23 21:00:02 +02:00
|
|
|
cmap *table = c.start_serialize<cmap> ();
|
|
|
|
if (unlikely (!c.extend_min (*table)))
|
2018-02-10 02:33:34 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:00:02 +02:00
|
|
|
table->version.set (0);
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-07-23 21:00:02 +02:00
|
|
|
if (unlikely (!table->encodingRecord.serialize (&c, /* numTables */ 3)))
|
2018-05-03 03:50:56 +02:00
|
|
|
return false;
|
2018-05-03 01:12:04 +02:00
|
|
|
|
|
|
|
// TODO(grieger): Convert the below to a for loop
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-05-03 19:53:20 +02:00
|
|
|
// Format 4, Plat 0 Encoding Record
|
2018-07-23 21:00:02 +02:00
|
|
|
EncodingRecord &format4_plat0_rec = table->encodingRecord[0];
|
2018-05-03 19:53:20 +02:00
|
|
|
format4_plat0_rec.platformID.set (0); // Unicode
|
|
|
|
format4_plat0_rec.encodingID.set (3);
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-05-03 19:53:20 +02:00
|
|
|
// Format 4, Plat 3 Encoding Record
|
2018-07-23 21:00:02 +02:00
|
|
|
EncodingRecord &format4_plat3_rec = table->encodingRecord[1];
|
2018-05-03 19:53:20 +02:00
|
|
|
format4_plat3_rec.platformID.set (3); // Windows
|
|
|
|
format4_plat3_rec.encodingID.set (1); // Unicode BMP
|
2018-02-12 19:12:11 +01:00
|
|
|
|
2018-05-03 01:12:04 +02:00
|
|
|
// Format 12 Encoding Record
|
2018-07-23 21:00:02 +02:00
|
|
|
EncodingRecord &format12_rec = table->encodingRecord[2];
|
2018-05-03 01:12:04 +02:00
|
|
|
format12_rec.platformID.set (3); // Windows
|
|
|
|
format12_rec.encodingID.set (10); // Unicode UCS-4
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-05-03 19:53:20 +02:00
|
|
|
// Write out format 4 sub table
|
2018-05-03 01:12:04 +02:00
|
|
|
{
|
2018-07-23 21:00:02 +02:00
|
|
|
CmapSubtable &subtable = format4_plat0_rec.subtable.serialize (&c, table);
|
2018-05-03 19:53:20 +02:00
|
|
|
format4_plat3_rec.subtable.set (format4_plat0_rec.subtable);
|
2018-05-03 01:12:04 +02:00
|
|
|
subtable.u.format.set (4);
|
|
|
|
|
|
|
|
CmapSubtableFormat4 &format4 = subtable.u.format4;
|
2018-05-03 03:50:56 +02:00
|
|
|
if (unlikely (!format4.serialize (&c, plan, cmap_subset_plan.format4_segments)))
|
|
|
|
return false;
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
2018-02-12 19:12:11 +01:00
|
|
|
|
2018-05-03 00:42:43 +02:00
|
|
|
// Write out format 12 sub table.
|
2018-05-03 01:12:04 +02:00
|
|
|
{
|
2018-07-23 21:00:02 +02:00
|
|
|
CmapSubtable &subtable = format12_rec.subtable.serialize (&c, table);
|
2018-05-03 01:12:04 +02:00
|
|
|
subtable.u.format.set (12);
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-05-03 01:12:04 +02:00
|
|
|
CmapSubtableFormat12 &format12 = subtable.u.format12;
|
2018-05-03 03:50:56 +02:00
|
|
|
if (unlikely (!format12.serialize (&c, cmap_subset_plan.format12_groups)))
|
|
|
|
return false;
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-02-19 01:27:59 +01:00
|
|
|
c.end_serialize ();
|
2018-02-12 19:12:11 +01:00
|
|
|
|
2018-02-08 00:59:36 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:24:49 +01:00
|
|
|
inline bool subset (hb_subset_plan_t *plan) const
|
2018-02-10 02:33:34 +01:00
|
|
|
{
|
2018-05-03 00:42:43 +02:00
|
|
|
subset_plan cmap_subset_plan;
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2018-05-03 00:42:43 +02:00
|
|
|
if (unlikely (!_create_plan (plan, &cmap_subset_plan)))
|
|
|
|
{
|
|
|
|
DEBUG_MSG(SUBSET, nullptr, "Failed to generate a cmap subsetting plan.");
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-10 02:33:34 +01:00
|
|
|
|
|
|
|
// We now know how big our blob needs to be
|
2018-05-03 00:42:43 +02:00
|
|
|
size_t dest_sz = cmap_subset_plan.final_size();
|
2018-02-24 00:37:43 +01:00
|
|
|
void *dest = malloc (dest_sz);
|
2018-02-15 04:36:33 +01:00
|
|
|
if (unlikely (!dest)) {
|
2018-02-20 19:32:09 +01:00
|
|
|
DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %lu for cmap subset output", (unsigned long) dest_sz);
|
2018-02-14 23:16:25 +01:00
|
|
|
return false;
|
2018-02-10 02:33:34 +01:00
|
|
|
}
|
|
|
|
|
2018-05-03 01:12:04 +02:00
|
|
|
if (unlikely (!_subset (plan, cmap_subset_plan, dest_sz, dest)))
|
2018-02-10 02:33:34 +01:00
|
|
|
{
|
2018-05-03 00:42:43 +02:00
|
|
|
DEBUG_MSG(SUBSET, nullptr, "Failed to perform subsetting of cmap.");
|
2018-02-15 04:36:33 +01:00
|
|
|
free (dest);
|
2018-02-14 23:16:25 +01:00
|
|
|
return false;
|
2018-02-10 02:33:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// all done, write the blob into dest
|
2018-02-14 23:16:25 +01:00
|
|
|
hb_blob_t *cmap_prime = hb_blob_create ((const char *)dest,
|
|
|
|
dest_sz,
|
|
|
|
HB_MEMORY_MODE_READONLY,
|
2018-02-24 00:37:43 +01:00
|
|
|
dest,
|
2018-02-14 23:16:25 +01:00
|
|
|
free);
|
2018-05-30 21:23:51 +02:00
|
|
|
bool result = plan->add_table (HB_OT_TAG_cmap, cmap_prime);
|
2018-02-24 00:37:43 +01:00
|
|
|
hb_blob_destroy (cmap_prime);
|
|
|
|
return result;
|
2018-02-10 02:33:34 +01:00
|
|
|
}
|
|
|
|
|
2018-08-26 00:33:05 +02:00
|
|
|
const CmapSubtable *find_best_subtable (bool *symbol = nullptr) const
|
|
|
|
{
|
|
|
|
if (symbol) *symbol = false;
|
|
|
|
|
|
|
|
const CmapSubtable *subtable;
|
|
|
|
|
|
|
|
/* 32-bit subtables. */
|
|
|
|
if ((subtable = this->find_subtable (3, 10))) return subtable;
|
|
|
|
if ((subtable = this->find_subtable (0, 6))) return subtable;
|
|
|
|
if ((subtable = this->find_subtable (0, 4))) return subtable;
|
|
|
|
|
|
|
|
/* 16-bit subtables. */
|
|
|
|
if ((subtable = this->find_subtable (3, 1))) return subtable;
|
|
|
|
if ((subtable = this->find_subtable (0, 3))) return subtable;
|
|
|
|
if ((subtable = this->find_subtable (0, 2))) return subtable;
|
|
|
|
if ((subtable = this->find_subtable (0, 1))) return subtable;
|
|
|
|
if ((subtable = this->find_subtable (0, 0))) return subtable;
|
|
|
|
|
|
|
|
/* Symbol subtable. */
|
|
|
|
if ((subtable = this->find_subtable (3, 0)))
|
|
|
|
{
|
|
|
|
if (symbol) *symbol = true;
|
|
|
|
return subtable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Meh. */
|
|
|
|
return &Null(CmapSubtable);
|
|
|
|
}
|
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
struct accelerator_t
|
|
|
|
{
|
|
|
|
inline void init (hb_face_t *face)
|
|
|
|
{
|
2018-07-23 20:57:45 +02:00
|
|
|
this->blob = hb_sanitize_context_t().reference_table<cmap> (face);
|
2018-07-23 21:00:02 +02:00
|
|
|
const cmap *table = this->blob->as<cmap> ();
|
2018-08-26 00:33:05 +02:00
|
|
|
bool symbol;
|
2018-11-06 01:46:29 +01:00
|
|
|
this->subtable = table->find_best_subtable (&symbol);
|
|
|
|
this->subtable_uvs = &Null(CmapSubtableFormat14);
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
2018-07-23 21:00:02 +02:00
|
|
|
const CmapSubtable *st = table->find_subtable (0, 5);
|
2017-11-15 05:06:19 +01:00
|
|
|
if (st && st->u.format == 14)
|
2018-11-06 01:46:29 +01:00
|
|
|
subtable_uvs = &st->u.format14;
|
2017-11-15 05:06:19 +01:00
|
|
|
}
|
|
|
|
|
2018-11-06 01:46:29 +01:00
|
|
|
this->get_glyph_data = subtable;
|
2017-11-15 05:06:19 +01:00
|
|
|
if (unlikely (symbol))
|
2018-04-11 00:40:24 +02:00
|
|
|
{
|
2018-11-05 19:45:12 +01:00
|
|
|
this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable>;
|
2018-04-11 00:40:24 +02:00
|
|
|
} else {
|
2018-11-06 01:46:29 +01:00
|
|
|
switch (subtable->u.format) {
|
2017-11-15 05:06:19 +01:00
|
|
|
/* Accelerate format 4 and format 12. */
|
2018-04-11 00:40:24 +02:00
|
|
|
default:
|
2018-11-05 19:45:12 +01:00
|
|
|
this->get_glyph_funcZ = get_glyph_from<CmapSubtable>;
|
2018-04-11 00:40:24 +02:00
|
|
|
break;
|
|
|
|
case 12:
|
2018-11-05 19:45:12 +01:00
|
|
|
this->get_glyph_funcZ = get_glyph_from<CmapSubtableFormat12>;
|
2018-04-11 00:40:24 +02:00
|
|
|
break;
|
2017-11-15 05:06:19 +01:00
|
|
|
case 4:
|
|
|
|
{
|
2018-11-06 01:46:29 +01:00
|
|
|
this->format4_accel.init (&subtable->u.format4);
|
2017-11-15 05:06:19 +01:00
|
|
|
this->get_glyph_data = &this->format4_accel;
|
2018-11-05 19:45:12 +01:00
|
|
|
this->get_glyph_funcZ = this->format4_accel.get_glyph_func;
|
2017-11-15 05:06:19 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-11 00:40:24 +02:00
|
|
|
}
|
2017-11-15 05:06:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
|
|
|
hb_blob_destroy (this->blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool get_nominal_glyph (hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t *glyph) const
|
|
|
|
{
|
2018-11-05 19:45:12 +01:00
|
|
|
if (unlikely (!this->get_glyph_funcZ)) return false;
|
|
|
|
return this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph);
|
2017-11-15 05:06:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool get_variation_glyph (hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t *glyph) const
|
|
|
|
{
|
2018-11-06 01:46:29 +01:00
|
|
|
switch (this->subtable_uvs->get_glyph_variant (unicode,
|
|
|
|
variation_selector,
|
|
|
|
glyph))
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
2018-07-23 20:57:45 +02:00
|
|
|
case GLYPH_VARIANT_NOT_FOUND: return false;
|
|
|
|
case GLYPH_VARIANT_FOUND: return true;
|
|
|
|
case GLYPH_VARIANT_USE_DEFAULT: break;
|
2017-11-15 05:06:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return get_nominal_glyph (unicode, glyph);
|
|
|
|
}
|
|
|
|
|
2018-08-25 17:47:06 +02:00
|
|
|
inline void collect_unicodes (hb_set_t *out) const
|
2018-04-11 00:40:24 +02:00
|
|
|
{
|
2018-11-06 01:46:29 +01:00
|
|
|
subtable->collect_unicodes (out);
|
2018-04-11 00:40:24 +02:00
|
|
|
}
|
2018-08-26 00:56:07 +02:00
|
|
|
inline void collect_variation_selectors (hb_set_t *out) const
|
|
|
|
{
|
2018-11-06 01:46:29 +01:00
|
|
|
subtable_uvs->collect_variation_selectors (out);
|
2018-08-26 00:56:07 +02:00
|
|
|
}
|
2018-08-26 01:11:26 +02:00
|
|
|
inline void collect_variation_unicodes (hb_codepoint_t variation_selector,
|
|
|
|
hb_set_t *out) const
|
|
|
|
{
|
2018-11-06 01:46:29 +01:00
|
|
|
subtable_uvs->collect_variation_unicodes (variation_selector, out);
|
2018-08-26 01:11:26 +02:00
|
|
|
}
|
2018-04-11 00:40:24 +02:00
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
protected:
|
|
|
|
typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
|
|
|
|
hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph);
|
2018-04-11 00:40:24 +02:00
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
template <typename Type>
|
|
|
|
static inline bool get_glyph_from (const void *obj,
|
|
|
|
hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph)
|
|
|
|
{
|
|
|
|
const Type *typed_obj = (const Type *) obj;
|
|
|
|
return typed_obj->get_glyph (codepoint, glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Type>
|
|
|
|
static inline bool get_glyph_from_symbol (const void *obj,
|
|
|
|
hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph)
|
|
|
|
{
|
|
|
|
const Type *typed_obj = (const Type *) obj;
|
|
|
|
if (likely (typed_obj->get_glyph (codepoint, glyph)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (codepoint <= 0x00FFu)
|
|
|
|
{
|
|
|
|
/* For symbol-encoded OpenType fonts, we duplicate the
|
|
|
|
* U+F000..F0FF range at U+0000..U+00FF. That's what
|
|
|
|
* Windows seems to do, and that's hinted about at:
|
2018-04-12 11:10:45 +02:00
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/recom
|
2017-11-15 05:06:19 +01:00
|
|
|
* under "Non-Standard (Symbol) Fonts". */
|
|
|
|
return typed_obj->get_glyph (0xF000u + codepoint, glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-11-06 01:46:29 +01:00
|
|
|
hb_nonnull_ptr_t<const CmapSubtable> subtable;
|
|
|
|
hb_nonnull_ptr_t<const CmapSubtableFormat14> subtable_uvs;
|
2018-08-26 00:56:07 +02:00
|
|
|
|
2018-11-05 19:45:12 +01:00
|
|
|
hb_cmap_get_glyph_func_t get_glyph_funcZ;
|
2017-11-15 05:06:19 +01:00
|
|
|
const void *get_glyph_data;
|
2018-04-11 00:40:24 +02:00
|
|
|
|
2018-07-23 20:57:45 +02:00
|
|
|
CmapSubtableFormat4::accelerator_t format4_accel;
|
2017-11-15 05:06:19 +01:00
|
|
|
|
|
|
|
hb_blob_t *blob;
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
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);
|
|
|
|
|
2018-08-26 00:37:56 +02:00
|
|
|
int result = encodingRecord.bsearch (key);
|
2014-06-05 00:17:29 +02:00
|
|
|
if (result == -1 || !encodingRecord[result].subtable)
|
2017-10-15 12:11:08 +02:00
|
|
|
return nullptr;
|
2014-05-12 19:46:29 +02:00
|
|
|
|
|
|
|
return &(this+encodingRecord[result].subtable);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
protected:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 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);
|
|
|
|
};
|
|
|
|
|
2018-08-27 00:11:24 +02:00
|
|
|
struct cmap_accelerator_t : cmap::accelerator_t {};
|
2014-05-09 21:35:56 +02:00
|
|
|
|
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_OT_CMAP_TABLE_HH */
|