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
|
|
|
|
|
2022-06-16 19:04:13 +02:00
|
|
|
#include "hb-ot-os2-table.hh"
|
|
|
|
#include "hb-ot-shaper-arabic-pua.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
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
2014-05-14 03:47:51 +02:00
|
|
|
{
|
|
|
|
hb_codepoint_t gid = codepoint < 256 ? glyphIdArray[codepoint] : 0;
|
2022-05-03 00:30:22 +02:00
|
|
|
if (unlikely (!gid))
|
2014-05-14 03:47:51 +02:00
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
2018-08-30 01:38:04 +02:00
|
|
|
return true;
|
2014-05-14 03:47:51 +02:00
|
|
|
}
|
2021-08-04 20:38:38 +02:00
|
|
|
|
|
|
|
unsigned get_language () const
|
|
|
|
{
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
2018-08-25 18:35:45 +02:00
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < 256; i++)
|
|
|
|
if (glyphIdArray[i])
|
2018-11-15 20:40:56 +01:00
|
|
|
out->add (i);
|
2018-08-25 18:35:45 +02:00
|
|
|
}
|
2014-05-14 03:47:51 +02:00
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_map_t *mapping /* OUT */) const
|
2020-04-23 00:58:41 +02:00
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 256; i++)
|
|
|
|
if (glyphIdArray[i])
|
|
|
|
{
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_codepoint_t glyph = glyphIdArray[i];
|
|
|
|
unicodes->add (i);
|
|
|
|
mapping->set (i, glyph);
|
2020-04-23 00:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
template<typename Iterator,
|
2021-11-26 03:15:35 +01:00
|
|
|
typename Writer,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2021-11-26 03:15:35 +01:00
|
|
|
void to_ranges (Iterator it, Writer& range_writer)
|
2018-05-03 01:12:04 +02:00
|
|
|
{
|
2021-12-01 19:30:27 +01:00
|
|
|
hb_codepoint_t start_cp = 0, prev_run_start_cp = 0, run_start_cp = 0, end_cp = 0, last_gid = 0;
|
|
|
|
int run_length = 0 , delta = 0, prev_delta = 0;
|
2021-11-26 03:15:35 +01:00
|
|
|
|
|
|
|
enum {
|
2021-11-27 01:18:42 +01:00
|
|
|
FIRST_SUB_RANGE,
|
|
|
|
FOLLOWING_SUB_RANGE,
|
2021-11-26 03:15:35 +01:00
|
|
|
} mode;
|
|
|
|
|
|
|
|
while (it) {
|
|
|
|
// Start a new range
|
2022-04-30 00:49:02 +02:00
|
|
|
{
|
|
|
|
const auto& pair = *it;
|
|
|
|
start_cp = pair.first;
|
|
|
|
prev_run_start_cp = start_cp;
|
|
|
|
run_start_cp = start_cp;
|
|
|
|
end_cp = start_cp;
|
|
|
|
last_gid = pair.second;
|
|
|
|
run_length = 1;
|
|
|
|
prev_delta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
delta = last_gid - start_cp;
|
2021-11-27 01:18:42 +01:00
|
|
|
mode = FIRST_SUB_RANGE;
|
2021-11-26 03:15:35 +01:00
|
|
|
it++;
|
|
|
|
|
|
|
|
while (it) {
|
|
|
|
// Process range
|
2022-04-30 00:49:02 +02:00
|
|
|
const auto& pair = *it;
|
|
|
|
hb_codepoint_t next_cp = pair.first;
|
|
|
|
hb_codepoint_t next_gid = pair.second;
|
2021-11-26 03:15:35 +01:00
|
|
|
if (next_cp != end_cp + 1) {
|
|
|
|
// Current range is over, stop processing.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_gid == last_gid + 1) {
|
|
|
|
// The current run continues.
|
|
|
|
end_cp = next_cp;
|
|
|
|
run_length++;
|
|
|
|
last_gid = next_gid;
|
|
|
|
it++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A new run is starting, decide if we want to commit the current run.
|
2021-11-27 01:18:42 +01:00
|
|
|
int split_cost = (mode == FIRST_SUB_RANGE) ? 8 : 16;
|
2021-11-26 03:15:35 +01:00
|
|
|
int run_cost = run_length * 2;
|
|
|
|
if (run_cost >= split_cost) {
|
2021-11-27 01:18:42 +01:00
|
|
|
commit_current_range(start_cp,
|
|
|
|
prev_run_start_cp,
|
|
|
|
run_start_cp,
|
|
|
|
end_cp,
|
|
|
|
delta,
|
|
|
|
prev_delta,
|
|
|
|
split_cost,
|
|
|
|
range_writer);
|
2021-11-26 03:15:35 +01:00
|
|
|
start_cp = next_cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the new run
|
2021-11-27 01:18:42 +01:00
|
|
|
mode = FOLLOWING_SUB_RANGE;
|
|
|
|
prev_run_start_cp = run_start_cp;
|
2021-11-26 03:15:35 +01:00
|
|
|
run_start_cp = next_cp;
|
|
|
|
end_cp = next_cp;
|
2021-11-27 01:18:42 +01:00
|
|
|
prev_delta = delta;
|
2021-11-26 03:15:35 +01:00
|
|
|
delta = next_gid - run_start_cp;
|
|
|
|
run_length = 1;
|
|
|
|
last_gid = next_gid;
|
|
|
|
it++;
|
2020-03-13 06:03:34 +01:00
|
|
|
}
|
2018-05-03 03:50:56 +02:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
// Finalize range
|
2021-11-27 01:18:42 +01:00
|
|
|
commit_current_range (start_cp,
|
|
|
|
prev_run_start_cp,
|
|
|
|
run_start_cp,
|
|
|
|
end_cp,
|
|
|
|
delta,
|
|
|
|
prev_delta,
|
|
|
|
8,
|
|
|
|
range_writer);
|
2018-05-03 02:11:18 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
if (likely (end_cp != 0xFFFF)) {
|
|
|
|
range_writer (0xFFFF, 0xFFFF, 1);
|
|
|
|
}
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
/*
|
|
|
|
* Writes the current range as either one or two ranges depending on what is most efficient.
|
|
|
|
*/
|
|
|
|
template<typename Writer>
|
|
|
|
void commit_current_range (hb_codepoint_t start,
|
2021-11-27 01:18:42 +01:00
|
|
|
hb_codepoint_t prev_run_start,
|
2021-11-26 03:15:35 +01:00
|
|
|
hb_codepoint_t run_start,
|
|
|
|
hb_codepoint_t end,
|
|
|
|
int run_delta,
|
2021-11-27 01:18:42 +01:00
|
|
|
int previous_run_delta,
|
2021-11-26 03:15:35 +01:00
|
|
|
int split_cost,
|
|
|
|
Writer& range_writer) {
|
|
|
|
bool should_split = false;
|
|
|
|
if (start < run_start && run_start < end) {
|
|
|
|
int run_cost = (end - run_start + 1) * 2;
|
|
|
|
if (run_cost >= split_cost) {
|
|
|
|
should_split = true;
|
2020-03-13 06:03:34 +01:00
|
|
|
}
|
2021-11-26 03:15:35 +01:00
|
|
|
}
|
2020-03-13 06:03:34 +01:00
|
|
|
|
2021-11-27 01:18:42 +01:00
|
|
|
// TODO(grieger): handle case where delta is legitimately 0, mark range offset array instead?
|
2021-11-26 03:15:35 +01:00
|
|
|
if (should_split) {
|
2021-11-27 01:18:42 +01:00
|
|
|
if (start == prev_run_start)
|
|
|
|
range_writer (start, run_start - 1, previous_run_delta);
|
|
|
|
else
|
|
|
|
range_writer (start, run_start - 1, 0);
|
2021-11-26 03:15:35 +01:00
|
|
|
range_writer (run_start, end, run_delta);
|
|
|
|
return;
|
2020-03-13 06:03:34 +01:00
|
|
|
}
|
2019-06-25 22:17:30 +02:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
|
|
|
|
if (start == run_start) {
|
|
|
|
// Range is only a run
|
|
|
|
range_writer (start, end, run_delta);
|
|
|
|
return;
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
// Write only a single non-run range.
|
2021-11-27 01:18:42 +01:00
|
|
|
range_writer (start, end, 0);
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
template<typename Iterator,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2021-11-26 03:15:35 +01:00
|
|
|
unsigned serialize_find_segcount (Iterator it) {
|
|
|
|
struct Counter {
|
|
|
|
unsigned segcount = 0;
|
|
|
|
|
|
|
|
void operator() (hb_codepoint_t start,
|
|
|
|
hb_codepoint_t end,
|
|
|
|
int delta) {
|
|
|
|
segcount++;
|
2020-03-13 06:03:34 +01:00
|
|
|
}
|
2021-11-26 03:15:35 +01:00
|
|
|
} counter;
|
2020-03-13 06:03:34 +01:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
to_ranges (+it, counter);
|
|
|
|
return counter.segcount;
|
|
|
|
}
|
2020-03-13 06:03:34 +01:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
|
|
|
|
template<typename Iterator,
|
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
|
|
|
bool serialize_start_end_delta_arrays (hb_serialize_context_t *c,
|
|
|
|
Iterator it,
|
|
|
|
int segcount)
|
|
|
|
{
|
|
|
|
struct Writer {
|
|
|
|
hb_serialize_context_t *serializer_;
|
|
|
|
HBUINT16* end_code_;
|
|
|
|
HBUINT16* start_code_;
|
|
|
|
HBINT16* id_delta_;
|
|
|
|
int index_;
|
|
|
|
|
|
|
|
Writer(hb_serialize_context_t *serializer)
|
|
|
|
: serializer_(serializer),
|
|
|
|
end_code_(nullptr),
|
|
|
|
start_code_(nullptr),
|
|
|
|
id_delta_(nullptr),
|
|
|
|
index_ (0) {}
|
|
|
|
void operator() (hb_codepoint_t start,
|
|
|
|
hb_codepoint_t end,
|
|
|
|
int delta) {
|
|
|
|
start_code_[index_] = start;
|
|
|
|
end_code_[index_] = end;
|
|
|
|
id_delta_[index_] = delta;
|
|
|
|
index_++;
|
2020-03-13 06:03:34 +01:00
|
|
|
}
|
2021-11-26 03:15:35 +01:00
|
|
|
} writer(c);
|
2020-03-13 06:03:34 +01:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
writer.end_code_ = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount);
|
|
|
|
c->allocate_size<HBUINT16> (2); // padding
|
|
|
|
writer.start_code_ = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount);
|
|
|
|
writer.id_delta_ = c->allocate_size<HBINT16> (HBINT16::static_size * segcount);
|
2018-05-03 01:37:38 +02:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
if (unlikely (!writer.end_code_ || !writer.start_code_ || !writer.id_delta_)) return false;
|
2018-05-03 01:37:38 +02:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
to_ranges (+it, writer);
|
|
|
|
return true;
|
2019-06-25 22:17:30 +02:00
|
|
|
}
|
2018-05-03 01:37:38 +02:00
|
|
|
|
2022-04-30 01:30:32 +02:00
|
|
|
template<typename Iterator,
|
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2019-06-25 22:17:30 +02:00
|
|
|
HBUINT16* serialize_rangeoffset_glyid (hb_serialize_context_t *c,
|
2022-04-30 01:30:32 +02:00
|
|
|
Iterator it,
|
2019-08-24 15:27:14 +02:00
|
|
|
HBUINT16 *endCode,
|
|
|
|
HBUINT16 *startCode,
|
|
|
|
HBINT16 *idDelta,
|
|
|
|
unsigned segcount)
|
2019-06-25 22:17:30 +02:00
|
|
|
{
|
2022-05-18 20:17:43 +02:00
|
|
|
hb_map_t cp_to_gid { it };
|
2021-08-29 18:33:12 +02:00
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
HBUINT16 *idRangeOffset = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount);
|
|
|
|
if (unlikely (!c->check_success (idRangeOffset))) return nullptr;
|
|
|
|
if (unlikely ((char *)idRangeOffset - (char *)idDelta != (int) segcount * (int) HBINT16::static_size)) return nullptr;
|
2019-08-24 15:27:14 +02:00
|
|
|
|
2021-08-29 18:33:12 +02:00
|
|
|
for (unsigned i : + hb_range (segcount)
|
2022-05-18 20:17:43 +02:00
|
|
|
| hb_filter ([&] (const unsigned _) { return idDelta[_] == 0; }))
|
2021-08-29 18:33:12 +02:00
|
|
|
{
|
|
|
|
idRangeOffset[i] = 2 * (c->start_embed<HBUINT16> () - idRangeOffset - i);
|
|
|
|
for (hb_codepoint_t cp = startCode[i]; cp <= endCode[i]; cp++)
|
|
|
|
{
|
|
|
|
HBUINT16 gid;
|
|
|
|
gid = cp_to_gid[cp];
|
|
|
|
c->copy<HBUINT16> (gid);
|
|
|
|
}
|
|
|
|
}
|
2018-05-03 03:50:56 +02:00
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
return idRangeOffset;
|
|
|
|
}
|
2018-05-03 03:50:56 +02:00
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
template<typename Iterator,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2019-06-25 22:17:30 +02:00
|
|
|
void serialize (hb_serialize_context_t *c,
|
|
|
|
Iterator it)
|
|
|
|
{
|
2020-01-07 20:10:40 +01:00
|
|
|
auto format4_iter =
|
|
|
|
+ it
|
|
|
|
| hb_filter ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> _)
|
|
|
|
{ return _.first <= 0xFFFF; })
|
|
|
|
;
|
|
|
|
|
2022-04-30 00:49:02 +02:00
|
|
|
if (!format4_iter) return;
|
2020-01-22 20:36:15 +01:00
|
|
|
|
|
|
|
unsigned table_initpos = c->length ();
|
2021-07-29 01:36:22 +02:00
|
|
|
if (unlikely (!c->extend_min (this))) return;
|
2020-01-22 20:36:15 +01:00
|
|
|
this->format = 4;
|
|
|
|
|
2022-04-30 01:30:32 +02:00
|
|
|
hb_vector_t<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> cp_to_gid {
|
|
|
|
format4_iter
|
|
|
|
};
|
2022-04-30 01:18:53 +02:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
//serialize endCode[], startCode[], idDelta[]
|
|
|
|
HBUINT16* endCode = c->start_embed<HBUINT16> ();
|
2022-04-30 01:18:53 +02:00
|
|
|
unsigned segcount = serialize_find_segcount (cp_to_gid.iter());
|
|
|
|
if (unlikely (!serialize_start_end_delta_arrays (c, cp_to_gid.iter(), segcount)))
|
2021-11-26 03:15:35 +01:00
|
|
|
return;
|
2019-08-24 15:27:14 +02:00
|
|
|
|
2021-11-26 03:15:35 +01:00
|
|
|
HBUINT16 *startCode = endCode + segcount + 1;
|
|
|
|
HBINT16 *idDelta = ((HBINT16*)startCode) + segcount;
|
2019-06-25 22:17:30 +02:00
|
|
|
|
2022-04-30 01:18:53 +02:00
|
|
|
HBUINT16 *idRangeOffset = serialize_rangeoffset_glyid (c,
|
2022-04-30 01:30:32 +02:00
|
|
|
cp_to_gid.iter (),
|
2022-04-30 01:18:53 +02:00
|
|
|
endCode,
|
|
|
|
startCode,
|
|
|
|
idDelta,
|
|
|
|
segcount);
|
2019-06-25 22:17:30 +02:00
|
|
|
if (unlikely (!c->check_success (idRangeOffset))) return;
|
2019-08-24 15:27:14 +02:00
|
|
|
|
2021-08-26 23:32:17 +02:00
|
|
|
this->length = c->length () - table_initpos;
|
|
|
|
if ((long long) this->length != (long long) c->length () - table_initpos)
|
|
|
|
{
|
|
|
|
// Length overflowed. Discard the current object before setting the error condition, otherwise
|
|
|
|
// discard is a noop which prevents the higher level code from reverting the serializer to the
|
|
|
|
// pre-error state in cmap4 overflow handling code.
|
|
|
|
c->pop_discard ();
|
|
|
|
c->err (HB_SERIALIZE_ERROR_INT_OVERFLOW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
this->segCountX2 = segcount * 2;
|
|
|
|
this->entrySelector = hb_max (1u, hb_bit_storage (segcount)) - 1;
|
|
|
|
this->searchRange = 2 * (1u << this->entrySelector);
|
|
|
|
this->rangeShift = segcount * 2 > this->searchRange
|
|
|
|
? 2 * segcount - this->searchRange
|
|
|
|
: 0;
|
2018-05-03 01:12:04 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:38:38 +02:00
|
|
|
unsigned get_language () const
|
|
|
|
{
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2016-02-24 12:27:13 +01:00
|
|
|
struct accelerator_t
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
accelerator_t () {}
|
2022-01-20 19:47:17 +01:00
|
|
|
accelerator_t (const CmapSubtableFormat4 *subtable) { init (subtable); }
|
2018-10-30 06:35:44 +01:00
|
|
|
|
2022-01-20 19:47:17 +01:00
|
|
|
void init (const CmapSubtableFormat4 *subtable)
|
2016-02-24 12:27:13 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2014-05-10 01:55:51 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
2014-05-10 01:55:51 +02:00
|
|
|
{
|
2019-12-10 19:32:37 +01:00
|
|
|
struct CustomRange
|
2016-02-24 12:27:13 +01:00
|
|
|
{
|
2019-12-10 19:32:37 +01:00
|
|
|
int cmp (hb_codepoint_t k,
|
|
|
|
unsigned distance) const
|
2016-02-24 12:27:13 +01:00
|
|
|
{
|
2019-12-10 19:32:37 +01:00
|
|
|
if (k > last) return +1;
|
|
|
|
if (k < (&last)[distance]) return -1;
|
|
|
|
return 0;
|
2016-02-24 12:27:13 +01:00
|
|
|
}
|
2020-04-20 11:42:45 +02:00
|
|
|
HBUINT16 last;
|
2019-12-10 19:32:37 +01:00
|
|
|
};
|
|
|
|
|
2020-07-18 19:44:52 +02:00
|
|
|
const HBUINT16 *found = hb_bsearch (codepoint,
|
|
|
|
this->endCount,
|
|
|
|
this->segCount,
|
|
|
|
2,
|
|
|
|
_hb_cmp_method<hb_codepoint_t, CustomRange, unsigned>,
|
|
|
|
this->segCount + 1);
|
2022-05-03 00:30:22 +02:00
|
|
|
if (unlikely (!found))
|
2020-04-20 11:42:45 +02:00
|
|
|
return false;
|
2019-12-10 19:32:37 +01:00
|
|
|
unsigned int i = found - endCount;
|
2016-02-24 12:27:13 +01:00
|
|
|
|
|
|
|
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;
|
2022-05-03 00:30:22 +02:00
|
|
|
if (unlikely (!gid))
|
2018-08-30 01:38:04 +02:00
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
|
|
|
return true;
|
2014-05-10 01:55:51 +02:00
|
|
|
}
|
2019-12-10 19:32:37 +01:00
|
|
|
|
2019-04-12 23:50:03 +02:00
|
|
|
HB_INTERNAL static bool get_glyph_func (const void *obj, hb_codepoint_t codepoint, hb_codepoint_t *glyph)
|
2019-09-21 12:03:43 +02:00
|
|
|
{ return ((const accelerator_t *) obj)->get_glyph (codepoint, glyph); }
|
2019-12-10 19:32:37 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
2018-08-26 00:25:03 +02:00
|
|
|
{
|
2018-08-26 01:14:32 +02:00
|
|
|
unsigned int count = this->segCount;
|
|
|
|
if (count && this->startCount[count - 1] == 0xFFFFu)
|
2018-11-15 20:40:56 +01:00
|
|
|
count--; /* Skip sentinel segment. */
|
2018-08-26 01:14:32 +02:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2018-08-26 00:25:03 +02:00
|
|
|
{
|
2019-10-29 00:45:49 +01:00
|
|
|
hb_codepoint_t start = this->startCount[i];
|
|
|
|
hb_codepoint_t end = this->endCount[i];
|
2018-08-26 06:23:43 +02:00
|
|
|
unsigned int rangeOffset = this->idRangeOffset[i];
|
2022-04-29 21:21:13 +02:00
|
|
|
out->add_range(start, end);
|
2018-08-26 06:23:43 +02:00
|
|
|
if (rangeOffset == 0)
|
2019-10-29 00:45:49 +01:00
|
|
|
{
|
|
|
|
for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t gid = (codepoint + this->idDelta[i]) & 0xFFFFu;
|
|
|
|
if (unlikely (!gid))
|
2022-04-29 21:21:13 +02:00
|
|
|
out->del(codepoint);
|
2019-10-29 00:45:49 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-26 06:23:43 +02:00
|
|
|
else
|
|
|
|
{
|
2019-10-29 00:45:49 +01:00
|
|
|
for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++)
|
2018-08-26 06:23:43 +02:00
|
|
|
{
|
|
|
|
unsigned int index = rangeOffset / 2 + (codepoint - this->startCount[i]) + i - this->segCount;
|
|
|
|
if (unlikely (index >= this->glyphIdArrayLength))
|
2022-04-29 21:21:13 +02:00
|
|
|
{
|
|
|
|
out->del_range (codepoint, end);
|
2018-08-26 06:23:43 +02:00
|
|
|
break;
|
2022-04-29 21:21:13 +02:00
|
|
|
}
|
2018-08-26 06:23:43 +02:00
|
|
|
hb_codepoint_t gid = this->glyphIdArray[index];
|
|
|
|
if (unlikely (!gid))
|
2022-04-29 21:21:13 +02:00
|
|
|
out->del(codepoint);
|
2018-08-26 06:23:43 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-26 00:25:03 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-10 01:55:51 +02:00
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_map_t *mapping /* OUT */) const
|
2020-04-23 00:58:41 +02:00
|
|
|
{
|
2022-04-30 00:01:06 +02:00
|
|
|
// TODO(grieger): optimize similar to collect_unicodes
|
|
|
|
// (ie. use add_range())
|
2020-04-23 00:58:41 +02:00
|
|
|
unsigned count = this->segCount;
|
|
|
|
if (count && this->startCount[count - 1] == 0xFFFFu)
|
2020-07-29 06:03:32 +02:00
|
|
|
count--; /* Skip sentinel segment. */
|
2020-04-23 00:58:41 +02:00
|
|
|
for (unsigned i = 0; i < count; i++)
|
|
|
|
{
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_codepoint_t start = this->startCount[i];
|
|
|
|
hb_codepoint_t end = this->endCount[i];
|
|
|
|
unsigned rangeOffset = this->idRangeOffset[i];
|
|
|
|
if (rangeOffset == 0)
|
|
|
|
{
|
|
|
|
for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t gid = (codepoint + this->idDelta[i]) & 0xFFFFu;
|
|
|
|
if (unlikely (!gid))
|
|
|
|
continue;
|
|
|
|
unicodes->add (codepoint);
|
|
|
|
mapping->set (codepoint, gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++)
|
|
|
|
{
|
|
|
|
unsigned 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;
|
|
|
|
unicodes->add (codepoint);
|
|
|
|
mapping->set (codepoint, gid);
|
|
|
|
}
|
|
|
|
}
|
2020-04-23 00:58:41 +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;
|
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
2016-02-24 12:27:13 +01:00
|
|
|
{
|
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-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
2018-08-25 18:33:30 +02:00
|
|
|
{
|
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
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_map_t *mapping /* OUT */) const
|
2020-04-23 00:58:41 +02:00
|
|
|
{
|
|
|
|
accelerator_t accel (this);
|
|
|
|
accel.collect_mapping (unicodes, mapping);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
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. */
|
2019-05-08 05:54:31 +02:00
|
|
|
uint16_t new_length = (uint16_t) hb_min ((uintptr_t) 65535,
|
2020-07-18 19:44:52 +02:00
|
|
|
(uintptr_t) (c->end -
|
|
|
|
(char *) this));
|
2014-06-05 00:47:55 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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);
|
|
|
|
};
|
2018-11-24 01:58:49 +01:00
|
|
|
DECLARE_NULL_NAMESPACE_BYTES (OT, CmapSubtableLongGroup);
|
2014-05-12 23:51:15 +02:00
|
|
|
|
2014-05-14 03:17:28 +02:00
|
|
|
template <typename UINT>
|
|
|
|
struct CmapSubtableTrimmed
|
2014-05-13 00:19:29 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
2014-05-13 00:19:29 +02:00
|
|
|
{
|
|
|
|
/* Rely on our implicit array bound-checking. */
|
|
|
|
hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode];
|
2022-05-03 00:30:22 +02:00
|
|
|
if (unlikely (!gid))
|
2014-05-13 00:19:29 +02:00
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
2018-08-30 01:38:04 +02:00
|
|
|
return true;
|
2014-05-13 00:19:29 +02:00
|
|
|
}
|
2021-08-04 20:38:38 +02:00
|
|
|
|
|
|
|
unsigned get_language () const
|
|
|
|
{
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
2018-08-25 18:35:45 +02:00
|
|
|
{
|
|
|
|
hb_codepoint_t start = startCharCode;
|
|
|
|
unsigned int count = glyphIdArray.len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
if (glyphIdArray[i])
|
2018-11-15 20:40:56 +01:00
|
|
|
out->add (start + i);
|
2018-08-25 18:35:45 +02:00
|
|
|
}
|
2014-05-13 00:19:29 +02:00
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_map_t *mapping /* OUT */) const
|
2020-04-23 00:58:41 +02:00
|
|
|
{
|
|
|
|
hb_codepoint_t start_cp = startCharCode;
|
|
|
|
unsigned count = glyphIdArray.len;
|
|
|
|
for (unsigned i = 0; i < count; i++)
|
|
|
|
if (glyphIdArray[i])
|
|
|
|
{
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_codepoint_t unicode = start_cp + i;
|
|
|
|
hb_codepoint_t glyphid = glyphIdArray[i];
|
|
|
|
unicodes->add (unicode);
|
|
|
|
mapping->set (unicode, glyphid);
|
2020-04-23 00:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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. */
|
2021-09-19 22:30:12 +02:00
|
|
|
ArrayOf<HBGlyphID16, 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> {};
|
2022-05-03 00:31:59 +02:00
|
|
|
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;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
|
2014-05-12 23:51:15 +02:00
|
|
|
{
|
2018-11-24 06:35:31 +01:00
|
|
|
hb_codepoint_t gid = T::group_get_glyph (groups.bsearch (codepoint), codepoint);
|
2022-05-03 00:30:22 +02:00
|
|
|
if (unlikely (!gid))
|
2018-08-30 01:38:04 +02:00
|
|
|
return false;
|
|
|
|
*glyph = gid;
|
|
|
|
return true;
|
2014-05-12 23:51:15 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:38:38 +02:00
|
|
|
unsigned get_language () const
|
|
|
|
{
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2020-02-29 10:32:29 +01:00
|
|
|
void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const
|
2018-04-17 15:00:23 +02:00
|
|
|
{
|
2019-10-29 00:45:49 +01:00
|
|
|
for (unsigned int i = 0; i < this->groups.len; i++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t start = this->groups[i].startCharCode;
|
|
|
|
hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode,
|
2020-04-20 11:42:45 +02:00
|
|
|
(hb_codepoint_t) HB_UNICODE_MAX);
|
2020-02-29 10:32:29 +01:00
|
|
|
hb_codepoint_t gid = this->groups[i].glyphID;
|
|
|
|
if (!gid)
|
2019-10-29 00:45:49 +01:00
|
|
|
{
|
2020-02-29 10:32:29 +01:00
|
|
|
/* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */
|
|
|
|
if (! T::group_get_glyph (this->groups[i], end)) continue;
|
|
|
|
start++;
|
|
|
|
gid++;
|
2019-10-29 00:45:49 +01:00
|
|
|
}
|
2020-02-29 10:32:29 +01:00
|
|
|
if (unlikely ((unsigned int) gid >= num_glyphs)) continue;
|
|
|
|
if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs))
|
|
|
|
end = start + (hb_codepoint_t) num_glyphs - gid;
|
|
|
|
|
2022-03-22 01:24:30 +01:00
|
|
|
out->add_range (start, hb_min (end, 0x10FFFFu));
|
2018-04-17 15:00:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
2020-07-29 06:03:32 +02:00
|
|
|
hb_map_t *mapping, /* OUT */
|
|
|
|
unsigned num_glyphs) const
|
2020-04-23 00:58:41 +02:00
|
|
|
{
|
2022-05-10 19:47:08 +02:00
|
|
|
hb_codepoint_t last_end = 0;
|
2020-04-23 00:58:41 +02:00
|
|
|
for (unsigned i = 0; i < this->groups.len; i++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t start = this->groups[i].startCharCode;
|
|
|
|
hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode,
|
2020-07-29 06:03:32 +02:00
|
|
|
(hb_codepoint_t) HB_UNICODE_MAX);
|
2022-05-10 19:47:08 +02:00
|
|
|
if (unlikely (start > end || start < last_end)) {
|
|
|
|
// Range is not in order and is invalid, skip it.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
last_end = end;
|
|
|
|
|
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
hb_codepoint_t gid = this->groups[i].glyphID;
|
|
|
|
if (!gid)
|
|
|
|
{
|
2020-07-29 06:03:32 +02:00
|
|
|
/* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */
|
|
|
|
if (! T::group_get_glyph (this->groups[i], end)) continue;
|
|
|
|
start++;
|
|
|
|
gid++;
|
2020-04-23 00:58:41 +02:00
|
|
|
}
|
|
|
|
if (unlikely ((unsigned int) gid >= num_glyphs)) continue;
|
|
|
|
if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs))
|
2020-07-29 06:03:32 +02:00
|
|
|
end = start + (hb_codepoint_t) num_glyphs - gid;
|
2020-04-23 00:58:41 +02:00
|
|
|
|
|
|
|
for (unsigned cp = start; cp <= end; cp++)
|
|
|
|
{
|
2020-07-29 06:03:32 +02:00
|
|
|
unicodes->add (cp);
|
|
|
|
mapping->set (cp, gid);
|
|
|
|
gid++;
|
2020-04-23 00:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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:
|
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. */
|
2021-04-01 00:09:39 +02:00
|
|
|
SortedArray32Of<CmapSubtableLongGroup>
|
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
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
static hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group,
|
2020-02-28 18:54:27 +01:00
|
|
|
hb_codepoint_t u)
|
|
|
|
{ return likely (group.startCharCode <= group.endCharCode) ?
|
|
|
|
group.glyphID + (u - group.startCharCode) : 0; }
|
2018-05-03 00:42:43 +02:00
|
|
|
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
template<typename Iterator,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2019-06-25 22:17:30 +02:00
|
|
|
void serialize (hb_serialize_context_t *c,
|
|
|
|
Iterator it)
|
2018-05-03 00:42:43 +02:00
|
|
|
{
|
2022-05-05 19:17:23 +02:00
|
|
|
if (!it) return;
|
2019-06-25 22:17:30 +02:00
|
|
|
unsigned table_initpos = c->length ();
|
2021-07-29 01:36:22 +02:00
|
|
|
if (unlikely (!c->extend_min (this))) return;
|
2019-06-25 22:17:30 +02:00
|
|
|
|
2022-05-05 19:21:24 +02:00
|
|
|
hb_codepoint_t startCharCode = (hb_codepoint_t) -1, endCharCode = (hb_codepoint_t) -1;
|
2019-06-25 22:17:30 +02:00
|
|
|
hb_codepoint_t glyphID = 0;
|
|
|
|
|
2021-02-20 01:08:10 +01:00
|
|
|
for (const auto& _ : +it)
|
2020-03-13 06:03:34 +01:00
|
|
|
{
|
2022-05-05 19:21:24 +02:00
|
|
|
if (startCharCode == (hb_codepoint_t) -1)
|
2020-03-13 06:03:34 +01:00
|
|
|
{
|
|
|
|
startCharCode = _.first;
|
|
|
|
endCharCode = _.first;
|
|
|
|
glyphID = _.second;
|
|
|
|
}
|
|
|
|
else if (!_is_gid_consecutive (endCharCode, startCharCode, glyphID, _.first, _.second))
|
|
|
|
{
|
|
|
|
CmapSubtableLongGroup grouprecord;
|
|
|
|
grouprecord.startCharCode = startCharCode;
|
|
|
|
grouprecord.endCharCode = endCharCode;
|
|
|
|
grouprecord.glyphID = glyphID;
|
|
|
|
c->copy<CmapSubtableLongGroup> (grouprecord);
|
|
|
|
|
|
|
|
startCharCode = _.first;
|
|
|
|
endCharCode = _.first;
|
|
|
|
glyphID = _.second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
endCharCode = _.first;
|
|
|
|
}
|
2019-06-25 22:17:30 +02:00
|
|
|
|
|
|
|
CmapSubtableLongGroup record;
|
|
|
|
record.startCharCode = startCharCode;
|
|
|
|
record.endCharCode = endCharCode;
|
|
|
|
record.glyphID = glyphID;
|
|
|
|
c->copy<CmapSubtableLongGroup> (record);
|
2018-05-03 00:42:43 +02:00
|
|
|
|
2019-03-30 04:17:46 +01:00
|
|
|
this->format = 12;
|
|
|
|
this->reserved = 0;
|
2019-06-25 22:17:30 +02:00
|
|
|
this->length = c->length () - table_initpos;
|
2022-05-05 19:17:23 +02:00
|
|
|
this->groups.len = (this->length - min_size) / CmapSubtableLongGroup::static_size;
|
2018-05-03 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-13 23:57:40 +02:00
|
|
|
static size_t get_sub_table_size (const hb_sorted_vector_t<CmapSubtableLongGroup> &groups_data)
|
2019-09-21 12:03:43 +02:00
|
|
|
{ return 16 + 12 * groups_data.length; }
|
2018-05-03 00:42:43 +02:00
|
|
|
|
2019-09-21 12:03:43 +02:00
|
|
|
private:
|
2019-06-25 22:17:30 +02:00
|
|
|
static bool _is_gid_consecutive (hb_codepoint_t endCharCode,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_codepoint_t startCharCode,
|
|
|
|
hb_codepoint_t glyphID,
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_codepoint_t cp,
|
|
|
|
hb_codepoint_t new_gid)
|
2018-05-03 00:42:43 +02:00
|
|
|
{
|
2019-06-25 22:17:30 +02:00
|
|
|
return (cp - 1 == endCharCode) &&
|
|
|
|
new_gid == glyphID + (cp - startCharCode);
|
2018-05-03 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
static hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group,
|
2020-02-28 18:54:27 +01:00
|
|
|
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
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (const hb_codepoint_t &codepoint) const
|
2014-06-27 23:03:22 +02:00
|
|
|
{
|
|
|
|
if (codepoint < startUnicodeValue) return -1;
|
|
|
|
if (codepoint > startUnicodeValue + additionalCount) return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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);
|
|
|
|
};
|
|
|
|
|
2021-04-01 00:09:39 +02:00
|
|
|
struct DefaultUVS : SortedArray32Of<UnicodeValueRange>
|
2018-08-26 01:11:26 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
2018-08-26 01:11:26 +02:00
|
|
|
{
|
|
|
|
unsigned int count = len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t first = arrayZ[i].startUnicodeValue;
|
2019-05-08 05:54:31 +02:00
|
|
|
hb_codepoint_t last = hb_min ((hb_codepoint_t) (first + arrayZ[i].additionalCount),
|
2020-07-18 19:44:52 +02:00
|
|
|
(hb_codepoint_t) HB_UNICODE_MAX);
|
2022-12-03 19:15:06 +01:00
|
|
|
out->add_range (first, last);
|
2018-08-26 01:11:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
DefaultUVS* copy (hb_serialize_context_t *c,
|
2019-09-21 11:49:14 +02:00
|
|
|
const hb_set_t *unicodes) const
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
|
|
|
DefaultUVS *out = c->start_embed<DefaultUVS> ();
|
|
|
|
if (unlikely (!out)) return nullptr;
|
|
|
|
auto snap = c->snapshot ();
|
|
|
|
|
|
|
|
HBUINT32 len;
|
|
|
|
len = 0;
|
|
|
|
if (unlikely (!c->copy<HBUINT32> (len))) return nullptr;
|
|
|
|
unsigned init_len = c->length ();
|
|
|
|
|
2022-12-03 19:18:05 +01:00
|
|
|
if (this->len > unicodes->get_population () * hb_bit_storage ((unsigned) this->len))
|
2019-09-21 12:56:14 +02:00
|
|
|
{
|
2022-12-03 19:18:05 +01:00
|
|
|
hb_codepoint_t start = HB_SET_VALUE_INVALID;
|
|
|
|
hb_codepoint_t end = HB_SET_VALUE_INVALID;
|
2022-12-03 17:46:11 +01:00
|
|
|
|
2022-12-03 19:18:05 +01:00
|
|
|
for (hb_codepoint_t u = HB_SET_VALUE_INVALID;
|
|
|
|
unicodes->next (&u);)
|
2019-09-21 12:56:14 +02:00
|
|
|
{
|
2022-12-03 19:18:05 +01:00
|
|
|
if (!as_array ().bsearch (u))
|
|
|
|
continue;
|
|
|
|
if (start == HB_SET_VALUE_INVALID)
|
2019-09-21 12:56:14 +02:00
|
|
|
{
|
2022-12-03 19:18:05 +01:00
|
|
|
start = u;
|
|
|
|
end = start - 1;
|
|
|
|
}
|
|
|
|
if (end + 1 != u || end - start == 255)
|
|
|
|
{
|
2019-09-21 12:56:14 +02:00
|
|
|
UnicodeValueRange rec;
|
2022-12-03 19:18:05 +01:00
|
|
|
rec.startUnicodeValue = start;
|
|
|
|
rec.additionalCount = end - start;
|
2019-09-21 12:56:14 +02:00
|
|
|
c->copy<UnicodeValueRange> (rec);
|
2022-12-03 19:18:05 +01:00
|
|
|
start = u;
|
2019-09-21 12:56:14 +02:00
|
|
|
}
|
2022-12-03 19:18:05 +01:00
|
|
|
end = u;
|
|
|
|
}
|
|
|
|
if (start != HB_SET_VALUE_INVALID)
|
|
|
|
{
|
|
|
|
UnicodeValueRange rec;
|
|
|
|
rec.startUnicodeValue = start;
|
|
|
|
rec.additionalCount = end - start;
|
|
|
|
c->copy<UnicodeValueRange> (rec);
|
2019-09-21 12:56:14 +02:00
|
|
|
}
|
2019-08-16 22:54:24 +02:00
|
|
|
|
2022-12-03 19:18:05 +01:00
|
|
|
}
|
|
|
|
else
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
2022-12-03 19:18:05 +01:00
|
|
|
hb_codepoint_t lastCode = HB_SET_VALUE_INVALID;
|
|
|
|
int count = -1;
|
|
|
|
|
|
|
|
for (const UnicodeValueRange& _ : *this)
|
|
|
|
{
|
|
|
|
hb_codepoint_t curEntry = (hb_codepoint_t) (_.startUnicodeValue - 1);
|
|
|
|
hb_codepoint_t end = curEntry + _.additionalCount + 2;
|
|
|
|
|
|
|
|
for (; unicodes->next (&curEntry) && curEntry < end;)
|
|
|
|
{
|
|
|
|
count += 1;
|
|
|
|
if (lastCode == HB_SET_VALUE_INVALID)
|
|
|
|
lastCode = curEntry;
|
|
|
|
else if (lastCode + count != curEntry)
|
|
|
|
{
|
|
|
|
UnicodeValueRange rec;
|
|
|
|
rec.startUnicodeValue = lastCode;
|
|
|
|
rec.additionalCount = count - 1;
|
|
|
|
c->copy<UnicodeValueRange> (rec);
|
|
|
|
|
|
|
|
lastCode = curEntry;
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastCode != HB_MAP_VALUE_INVALID)
|
|
|
|
{
|
|
|
|
UnicodeValueRange rec;
|
|
|
|
rec.startUnicodeValue = lastCode;
|
|
|
|
rec.additionalCount = count;
|
|
|
|
c->copy<UnicodeValueRange> (rec);
|
|
|
|
}
|
2019-08-16 22:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c->length () - init_len == 0)
|
|
|
|
{
|
|
|
|
c->revert (snap);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 23:53:10 +01:00
|
|
|
if (unlikely (!c->check_assign (out->len,
|
|
|
|
(c->length () - init_len) / UnicodeValueRange::static_size,
|
2021-03-18 18:51:26 +01:00
|
|
|
HB_SERIALIZE_ERROR_INT_OVERFLOW))) return nullptr;
|
2019-08-16 22:54:24 +02:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 01:11:26 +02:00
|
|
|
public:
|
2018-11-11 01:54:08 +01:00
|
|
|
DEFINE_SIZE_ARRAY (4, *this);
|
2018-08-26 01:11:26 +02:00
|
|
|
};
|
2014-06-27 23:03:22 +02:00
|
|
|
|
|
|
|
struct UVSMapping
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (const hb_codepoint_t &codepoint) const
|
2019-10-01 12:19:55 +02:00
|
|
|
{ return unicodeValue.cmp (codepoint); }
|
2014-06-27 23:03:22 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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 */
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 glyphID; /* Glyph ID of the UVS */
|
2014-06-27 23:03:22 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (5);
|
|
|
|
};
|
|
|
|
|
2021-04-01 00:09:39 +02:00
|
|
|
struct NonDefaultUVS : SortedArray32Of<UVSMapping>
|
2018-08-26 01:11:26 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
2018-08-26 01:11:26 +02:00
|
|
|
{
|
2021-04-01 23:47:21 +02:00
|
|
|
for (const auto& a : as_array ())
|
|
|
|
out->add (a.unicodeValue);
|
2018-08-26 01:11:26 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
|
|
|
hb_map_t *mapping /* OUT */) const
|
|
|
|
{
|
2021-04-01 23:47:21 +02:00
|
|
|
for (const auto& a : as_array ())
|
2020-04-23 00:58:41 +02:00
|
|
|
{
|
2021-04-01 23:47:21 +02:00
|
|
|
hb_codepoint_t unicode = a.unicodeValue;
|
|
|
|
hb_codepoint_t glyphid = a.glyphID;
|
2020-05-15 19:52:49 +02:00
|
|
|
unicodes->add (unicode);
|
|
|
|
mapping->set (unicode, glyphid);
|
2020-04-23 00:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:17:26 +02:00
|
|
|
void closure_glyphs (const hb_set_t *unicodes,
|
2019-09-21 11:49:14 +02:00
|
|
|
hb_set_t *glyphset) const
|
2019-08-07 22:17:26 +02:00
|
|
|
{
|
|
|
|
+ as_array ()
|
2019-08-29 20:17:20 +02:00
|
|
|
| hb_filter (unicodes, &UVSMapping::unicodeValue)
|
2019-08-07 22:17:26 +02:00
|
|
|
| hb_map (&UVSMapping::glyphID)
|
|
|
|
| hb_sink (glyphset)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
NonDefaultUVS* copy (hb_serialize_context_t *c,
|
2019-09-21 11:49:14 +02:00
|
|
|
const hb_set_t *unicodes,
|
2020-04-23 00:58:41 +02:00
|
|
|
const hb_set_t *glyphs_requested,
|
2019-09-21 11:49:14 +02:00
|
|
|
const hb_map_t *glyph_map) const
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
|
|
|
NonDefaultUVS *out = c->start_embed<NonDefaultUVS> ();
|
|
|
|
if (unlikely (!out)) return nullptr;
|
|
|
|
|
|
|
|
auto it =
|
|
|
|
+ as_array ()
|
|
|
|
| hb_filter ([&] (const UVSMapping& _)
|
2019-09-21 11:49:14 +02:00
|
|
|
{
|
2020-04-23 00:58:41 +02:00
|
|
|
return unicodes->has (_.unicodeValue) || glyphs_requested->has (_.glyphID);
|
2019-09-21 11:49:14 +02:00
|
|
|
})
|
2019-08-16 22:54:24 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
if (!it) return nullptr;
|
|
|
|
|
|
|
|
HBUINT32 len;
|
|
|
|
len = it.len ();
|
|
|
|
if (unlikely (!c->copy<HBUINT32> (len))) return nullptr;
|
|
|
|
|
2019-09-21 12:56:14 +02:00
|
|
|
for (const UVSMapping& _ : it)
|
|
|
|
{
|
|
|
|
UVSMapping mapping;
|
|
|
|
mapping.unicodeValue = _.unicodeValue;
|
|
|
|
mapping.glyphID = glyph_map->get (_.glyphID);
|
|
|
|
c->copy<UVSMapping> (mapping);
|
|
|
|
}
|
2019-08-16 22:54:24 +02:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-08-26 01:11:26 +02:00
|
|
|
public:
|
2018-11-11 01:54:08 +01:00
|
|
|
DEFINE_SIZE_ARRAY (4, *this);
|
2018-08-26 01:11:26 +02:00
|
|
|
};
|
2014-06-27 23:03:22 +02:00
|
|
|
|
|
|
|
struct VariationSelectorRecord
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
glyph_variant_t get_glyph (hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph,
|
|
|
|
const void *base) const
|
2014-06-27 23:03:22 +02:00
|
|
|
{
|
2018-11-24 06:35:31 +01:00
|
|
|
if ((base+defaultUVS).bfind (codepoint))
|
2014-06-27 23:03:22 +02:00
|
|
|
return GLYPH_VARIANT_USE_DEFAULT;
|
2018-11-24 06:35:31 +01:00
|
|
|
const UVSMapping &nonDefault = (base+nonDefaultUVS).bsearch (codepoint);
|
|
|
|
if (nonDefault.glyphID)
|
2014-06-27 23:03:22 +02:00
|
|
|
{
|
2018-11-24 06:35:31 +01:00
|
|
|
*glyph = nonDefault.glyphID;
|
2014-06-27 23:03:22 +02:00
|
|
|
return GLYPH_VARIANT_FOUND;
|
|
|
|
}
|
|
|
|
return GLYPH_VARIANT_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2020-02-26 02:39:59 +01:00
|
|
|
VariationSelectorRecord(const VariationSelectorRecord& other)
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator= (const VariationSelectorRecord& other)
|
|
|
|
{
|
|
|
|
varSelector = other.varSelector;
|
|
|
|
HBUINT32 offset = other.defaultUVS;
|
|
|
|
defaultUVS = offset;
|
|
|
|
offset = other.nonDefaultUVS;
|
|
|
|
nonDefaultUVS = offset;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_unicodes (hb_set_t *out, const void *base) const
|
2018-08-26 01:11:26 +02:00
|
|
|
{
|
|
|
|
(base+defaultUVS).collect_unicodes (out);
|
|
|
|
(base+nonDefaultUVS).collect_unicodes (out);
|
|
|
|
}
|
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (const void *base,
|
|
|
|
hb_set_t *unicodes, /* OUT */
|
|
|
|
hb_map_t *mapping /* OUT */) const
|
|
|
|
{
|
|
|
|
(base+defaultUVS).collect_unicodes (unicodes);
|
|
|
|
(base+nonDefaultUVS).collect_mapping (unicodes, mapping);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (const hb_codepoint_t &variation_selector) const
|
2019-09-21 12:03:43 +02:00
|
|
|
{ return varSelector.cmp (variation_selector); }
|
2014-06-27 23:03:22 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-02-10 21:26:40 +01:00
|
|
|
hb_pair_t<unsigned, unsigned>
|
|
|
|
copy (hb_serialize_context_t *c,
|
2020-04-20 11:42:45 +02:00
|
|
|
const hb_set_t *unicodes,
|
2020-04-23 00:58:41 +02:00
|
|
|
const hb_set_t *glyphs_requested,
|
2020-04-20 11:42:45 +02:00
|
|
|
const hb_map_t *glyph_map,
|
|
|
|
const void *base) const
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
|
|
|
auto snap = c->snapshot ();
|
|
|
|
auto *out = c->embed<VariationSelectorRecord> (*this);
|
2020-02-10 21:26:40 +01:00
|
|
|
if (unlikely (!out)) return hb_pair (0, 0);
|
2019-09-21 11:49:14 +02:00
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
out->defaultUVS = 0;
|
|
|
|
out->nonDefaultUVS = 0;
|
|
|
|
|
2020-02-10 21:26:40 +01:00
|
|
|
unsigned non_default_uvs_objidx = 0;
|
|
|
|
if (nonDefaultUVS != 0)
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
|
|
|
c->push ();
|
2020-04-23 00:58:41 +02:00
|
|
|
if (c->copy (base+nonDefaultUVS, unicodes, glyphs_requested, glyph_map))
|
2020-04-20 11:42:45 +02:00
|
|
|
non_default_uvs_objidx = c->pop_pack ();
|
2019-08-16 22:54:24 +02:00
|
|
|
else c->pop_discard ();
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:26:40 +01:00
|
|
|
unsigned default_uvs_objidx = 0;
|
|
|
|
if (defaultUVS != 0)
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
|
|
|
c->push ();
|
2020-03-08 21:09:24 +01:00
|
|
|
if (c->copy (base+defaultUVS, unicodes))
|
2020-04-20 11:42:45 +02:00
|
|
|
default_uvs_objidx = c->pop_pack ();
|
2019-08-16 22:54:24 +02:00
|
|
|
else c->pop_discard ();
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:26:40 +01:00
|
|
|
|
|
|
|
if (!default_uvs_objidx && !non_default_uvs_objidx)
|
2019-08-16 22:54:24 +02:00
|
|
|
c->revert (snap);
|
2020-02-10 21:26:40 +01:00
|
|
|
|
|
|
|
return hb_pair (default_uvs_objidx, non_default_uvs_objidx);
|
2019-08-16 22:54:24 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 18:48:48 +02:00
|
|
|
HBUINT24 varSelector; /* Variation selector. */
|
2021-03-31 20:49:14 +02:00
|
|
|
Offset32To<DefaultUVS>
|
2018-10-13 12:30:05 +02:00
|
|
|
defaultUVS; /* Offset to Default UVS Table. May be 0. */
|
2021-03-31 20:49:14 +02:00
|
|
|
Offset32To<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
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
glyph_variant_t get_glyph_variant (hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t *glyph) const
|
2019-09-21 12:03:43 +02:00
|
|
|
{ return record.bsearch (variation_selector).get_glyph (codepoint, glyph, this); }
|
2014-06-27 23:03:22 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_variation_selectors (hb_set_t *out) const
|
2018-08-26 00:56:07 +02:00
|
|
|
{
|
2021-04-01 23:47:21 +02:00
|
|
|
for (const auto& a : record.as_array ())
|
|
|
|
out->add (a.varSelector);
|
2018-08-26 00:56:07 +02:00
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_variation_unicodes (hb_codepoint_t variation_selector,
|
|
|
|
hb_set_t *out) const
|
2019-09-21 12:03:43 +02:00
|
|
|
{ record.bsearch (variation_selector).collect_unicodes (out, this); }
|
2018-08-26 00:56:07 +02:00
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
void serialize (hb_serialize_context_t *c,
|
2019-09-21 11:49:14 +02:00
|
|
|
const hb_set_t *unicodes,
|
2020-04-23 00:58:41 +02:00
|
|
|
const hb_set_t *glyphs_requested,
|
2019-09-21 11:49:14 +02:00
|
|
|
const hb_map_t *glyph_map,
|
2020-03-08 21:09:24 +01:00
|
|
|
const void *base)
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
|
|
|
auto snap = c->snapshot ();
|
|
|
|
unsigned table_initpos = c->length ();
|
|
|
|
const char* init_tail = c->tail;
|
|
|
|
|
2021-07-29 01:36:22 +02:00
|
|
|
if (unlikely (!c->extend_min (this))) return;
|
2019-08-16 22:54:24 +02:00
|
|
|
this->format = 14;
|
|
|
|
|
2020-03-08 21:09:24 +01:00
|
|
|
auto src_tbl = reinterpret_cast<const CmapSubtableFormat14*> (base);
|
2020-02-10 21:26:40 +01:00
|
|
|
|
2020-02-26 02:20:05 +01:00
|
|
|
/*
|
|
|
|
* Some versions of OTS require that offsets are in order. Due to the use
|
|
|
|
* of push()/pop_pack() serializing the variation records in order results
|
|
|
|
* in the offsets being in reverse order (first record has the largest
|
|
|
|
* offset). While this is perfectly valid, it will cause some versions of
|
|
|
|
* OTS to consider this table bad.
|
|
|
|
*
|
|
|
|
* So to prevent this issue we serialize the variation records in reverse
|
|
|
|
* order, so that the offsets are ordered from small to large. Since
|
|
|
|
* variation records are supposed to be in increasing order of varSelector
|
|
|
|
* we then have to reverse the order of the written variation selector
|
|
|
|
* records after everything is finalized.
|
|
|
|
*/
|
2020-02-10 21:26:40 +01:00
|
|
|
hb_vector_t<hb_pair_t<unsigned, unsigned>> obj_indices;
|
|
|
|
for (int i = src_tbl->record.len - 1; i >= 0; i--)
|
|
|
|
{
|
2020-04-23 00:58:41 +02:00
|
|
|
hb_pair_t<unsigned, unsigned> result = src_tbl->record[i].copy (c, unicodes, glyphs_requested, glyph_map, base);
|
2020-02-10 21:26:40 +01:00
|
|
|
if (result.first || result.second)
|
2020-04-20 11:42:45 +02:00
|
|
|
obj_indices.push (result);
|
2020-02-10 21:26:40 +01:00
|
|
|
}
|
2019-08-16 22:54:24 +02:00
|
|
|
|
2019-09-21 12:56:14 +02:00
|
|
|
if (c->length () - table_initpos == CmapSubtableFormat14::min_size)
|
2020-02-10 21:26:40 +01:00
|
|
|
{
|
2019-08-16 22:54:24 +02:00
|
|
|
c->revert (snap);
|
2020-02-10 21:26:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-31 23:40:49 +02:00
|
|
|
if (unlikely (!c->check_success (!obj_indices.in_error ())))
|
|
|
|
return;
|
|
|
|
|
2020-02-10 21:26:40 +01:00
|
|
|
int tail_len = init_tail - c->tail;
|
2021-03-18 18:51:26 +01:00
|
|
|
c->check_assign (this->length, c->length () - table_initpos + tail_len,
|
|
|
|
HB_SERIALIZE_ERROR_INT_OVERFLOW);
|
2020-02-10 21:26:40 +01:00
|
|
|
c->check_assign (this->record.len,
|
2020-04-20 11:42:45 +02:00
|
|
|
(c->length () - table_initpos - CmapSubtableFormat14::min_size) /
|
2021-03-17 23:53:10 +01:00
|
|
|
VariationSelectorRecord::static_size,
|
2021-03-18 18:51:26 +01:00
|
|
|
HB_SERIALIZE_ERROR_INT_OVERFLOW);
|
2020-02-10 21:26:40 +01:00
|
|
|
|
2020-02-26 02:20:05 +01:00
|
|
|
/* Correct the incorrect write order by reversing the order of the variation
|
|
|
|
records array. */
|
2020-02-10 21:26:40 +01:00
|
|
|
_reverse_variation_records ();
|
|
|
|
|
2020-02-26 02:20:05 +01:00
|
|
|
/* Now that records are in the right order, we can set up the offsets. */
|
2020-02-10 21:26:40 +01:00
|
|
|
_add_links_to_variation_records (c, obj_indices);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _reverse_variation_records ()
|
|
|
|
{
|
2020-02-26 02:39:59 +01:00
|
|
|
record.as_array ().reverse ();
|
2020-02-10 21:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _add_links_to_variation_records (hb_serialize_context_t *c,
|
2020-04-20 11:42:45 +02:00
|
|
|
const hb_vector_t<hb_pair_t<unsigned, unsigned>>& obj_indices)
|
2020-02-10 21:26:40 +01:00
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < obj_indices.length; i++)
|
2019-08-16 22:54:24 +02:00
|
|
|
{
|
2020-02-26 02:20:05 +01:00
|
|
|
/*
|
|
|
|
* Since the record array has been reversed (see comments in copy())
|
|
|
|
* but obj_indices has not been, the indices at obj_indices[i]
|
|
|
|
* are for the variation record at record[j].
|
|
|
|
*/
|
2020-02-10 21:26:40 +01:00
|
|
|
int j = obj_indices.length - 1 - i;
|
2020-03-07 20:02:36 +01:00
|
|
|
c->add_link (record[j].defaultUVS, obj_indices[i].first);
|
|
|
|
c->add_link (record[j].nonDefaultUVS, obj_indices[i].second);
|
2019-08-16 22:54:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:17:26 +02:00
|
|
|
void closure_glyphs (const hb_set_t *unicodes,
|
2019-09-21 11:49:14 +02:00
|
|
|
hb_set_t *glyphset) const
|
2019-08-07 22:17:26 +02:00
|
|
|
{
|
|
|
|
+ hb_iter (record)
|
2019-08-29 20:17:20 +02:00
|
|
|
| hb_filter (hb_bool, &VariationSelectorRecord::nonDefaultUVS)
|
2019-08-07 22:17:26 +02:00
|
|
|
| hb_map (&VariationSelectorRecord::nonDefaultUVS)
|
|
|
|
| hb_map (hb_add (this))
|
|
|
|
| hb_apply ([=] (const NonDefaultUVS& _) { _.closure_glyphs (unicodes, glyphset); })
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2020-01-28 18:30:51 +01:00
|
|
|
void collect_unicodes (hb_set_t *out) const
|
|
|
|
{
|
|
|
|
for (const VariationSelectorRecord& _ : record)
|
|
|
|
_.collect_unicodes (out, this);
|
|
|
|
}
|
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
|
|
|
hb_map_t *mapping /* OUT */) const
|
|
|
|
{
|
|
|
|
for (const VariationSelectorRecord& _ : record)
|
|
|
|
_.collect_mapping (this, unicodes, mapping);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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. */
|
2021-04-01 00:09:39 +02:00
|
|
|
SortedArray32Of<VariationSelectorRecord>
|
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. */
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
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);
|
2019-06-25 22:17:30 +02:00
|
|
|
case 4: return u.format4 .get_glyph (codepoint, glyph);
|
2018-02-15 04:36:33 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-02-29 10:32:29 +01:00
|
|
|
void collect_unicodes (hb_set_t *out, unsigned int num_glyphs = UINT_MAX) const
|
2018-08-25 18:33:30 +02:00
|
|
|
{
|
|
|
|
switch (u.format) {
|
2018-08-25 18:35:45 +02:00
|
|
|
case 0: u.format0 .collect_unicodes (out); return;
|
2019-06-25 22:17: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;
|
2020-02-29 10:32:29 +01:00
|
|
|
case 12: u.format12.collect_unicodes (out, num_glyphs); return;
|
|
|
|
case 13: u.format13.collect_unicodes (out, num_glyphs); return;
|
2018-08-25 18:33:30 +02:00
|
|
|
case 14:
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 23:03:22 +02:00
|
|
|
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, /* OUT */
|
|
|
|
hb_map_t *mapping, /* OUT */
|
|
|
|
unsigned num_glyphs = UINT_MAX) const
|
|
|
|
{
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: u.format0 .collect_mapping (unicodes, mapping); return;
|
|
|
|
case 4: u.format4 .collect_mapping (unicodes, mapping); return;
|
|
|
|
case 6: u.format6 .collect_mapping (unicodes, mapping); return;
|
|
|
|
case 10: u.format10.collect_mapping (unicodes, mapping); return;
|
|
|
|
case 12: u.format12.collect_mapping (unicodes, mapping, num_glyphs); return;
|
|
|
|
case 13: u.format13.collect_mapping (unicodes, mapping, num_glyphs); return;
|
|
|
|
case 14:
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 20:38:38 +02:00
|
|
|
unsigned get_language () const
|
|
|
|
{
|
|
|
|
switch (u.format) {
|
|
|
|
case 0: return u.format0 .get_language ();
|
|
|
|
case 4: return u.format4 .get_language ();
|
|
|
|
case 6: return u.format6 .get_language ();
|
|
|
|
case 10: return u.format10.get_language ();
|
|
|
|
case 12: return u.format12.get_language ();
|
|
|
|
case 13: return u.format13.get_language ();
|
|
|
|
case 14:
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
template<typename Iterator,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2019-06-25 22:17:30 +02:00
|
|
|
void serialize (hb_serialize_context_t *c,
|
|
|
|
Iterator it,
|
2019-09-21 11:49:14 +02:00
|
|
|
unsigned format,
|
|
|
|
const hb_subset_plan_t *plan,
|
2020-03-08 21:09:24 +01:00
|
|
|
const void *base)
|
2019-06-25 22:17:30 +02:00
|
|
|
{
|
|
|
|
switch (format) {
|
2020-03-08 21:09:24 +01:00
|
|
|
case 4: return u.format4.serialize (c, it);
|
|
|
|
case 12: return u.format12.serialize (c, it);
|
2023-01-11 20:27:19 +01:00
|
|
|
case 14: return u.format14.serialize (c, &plan->unicodes, &plan->glyphs_requested, plan->glyph_map, base);
|
2019-06-25 22:17:30 +02:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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));
|
2019-06-25 22:17:30 +02:00
|
|
|
case 4: return_trace (u.format4 .sanitize (c));
|
2015-09-29 15:57:02 +02:00
|
|
|
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;
|
2019-06-25 22:17:30 +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
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *base) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
template<typename Iterator,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2019-06-25 22:17:30 +02:00
|
|
|
EncodingRecord* copy (hb_serialize_context_t *c,
|
2019-09-21 11:49:14 +02:00
|
|
|
Iterator it,
|
|
|
|
unsigned format,
|
2020-03-08 21:09:24 +01:00
|
|
|
const void *base,
|
2019-09-21 11:49:14 +02:00
|
|
|
const hb_subset_plan_t *plan,
|
|
|
|
/* INOUT */ unsigned *objidx) const
|
2019-06-25 22:17:30 +02:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
2019-08-16 22:54:24 +02:00
|
|
|
auto snap = c->snapshot ();
|
2019-06-25 22:17:30 +02:00
|
|
|
auto *out = c->embed (this);
|
|
|
|
if (unlikely (!out)) return_trace (nullptr);
|
|
|
|
out->subtable = 0;
|
|
|
|
|
|
|
|
if (*objidx == 0)
|
|
|
|
{
|
|
|
|
CmapSubtable *cmapsubtable = c->push<CmapSubtable> ();
|
|
|
|
unsigned origin_length = c->length ();
|
2020-03-08 21:09:24 +01:00
|
|
|
cmapsubtable->serialize (c, it, format, plan, &(base+subtable));
|
2019-06-25 22:17:30 +02:00
|
|
|
if (c->length () - origin_length > 0) *objidx = c->pop_pack ();
|
|
|
|
else c->pop_discard ();
|
|
|
|
}
|
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
if (*objidx == 0)
|
|
|
|
{
|
|
|
|
c->revert (snap);
|
|
|
|
return_trace (nullptr);
|
|
|
|
}
|
2019-09-21 11:49:14 +02:00
|
|
|
|
2020-03-07 20:02:36 +01:00
|
|
|
c->add_link (out->subtable, *objidx);
|
2019-08-29 20:17:20 +02:00
|
|
|
return_trace (out);
|
2019-06-25 22:17:30 +02:00
|
|
|
}
|
|
|
|
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 platformID; /* Platform ID. */
|
|
|
|
HBUINT16 encodingID; /* Platform-specific encoding ID. */
|
2021-03-31 20:49:14 +02:00
|
|
|
Offset32To<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);
|
|
|
|
};
|
|
|
|
|
2022-11-29 01:47:55 +01:00
|
|
|
struct cmap;
|
|
|
|
|
2022-04-30 00:01:06 +02:00
|
|
|
struct SubtableUnicodesCache {
|
|
|
|
|
|
|
|
private:
|
2022-11-29 01:47:55 +01:00
|
|
|
hb_blob_ptr_t<cmap> base_blob;
|
2022-11-28 23:53:35 +01:00
|
|
|
const char* base;
|
|
|
|
hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> cached_unicodes;
|
2022-04-30 00:01:06 +02:00
|
|
|
|
|
|
|
public:
|
2022-11-29 01:47:55 +01:00
|
|
|
|
|
|
|
static SubtableUnicodesCache* create (hb_blob_ptr_t<cmap> source_table)
|
|
|
|
{
|
|
|
|
SubtableUnicodesCache* cache =
|
|
|
|
(SubtableUnicodesCache*) hb_malloc (sizeof(SubtableUnicodesCache));
|
|
|
|
new (cache) SubtableUnicodesCache (source_table);
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy (void* value) {
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
SubtableUnicodesCache* cache = (SubtableUnicodesCache*) value;
|
|
|
|
cache->~SubtableUnicodesCache ();
|
|
|
|
hb_free (cache);
|
|
|
|
}
|
|
|
|
|
2022-04-30 00:01:06 +02:00
|
|
|
SubtableUnicodesCache(const void* cmap_base)
|
2022-11-29 01:47:55 +01:00
|
|
|
: base_blob(),
|
|
|
|
base ((const char*) cmap_base),
|
|
|
|
cached_unicodes ()
|
|
|
|
{}
|
|
|
|
|
|
|
|
SubtableUnicodesCache(hb_blob_ptr_t<cmap> base_blob_)
|
|
|
|
: base_blob(base_blob_),
|
|
|
|
base ((const char *) base_blob.get()),
|
|
|
|
cached_unicodes ()
|
|
|
|
{}
|
|
|
|
|
|
|
|
~SubtableUnicodesCache()
|
|
|
|
{
|
|
|
|
base_blob.destroy ();
|
|
|
|
}
|
|
|
|
|
2022-11-30 01:19:10 +01:00
|
|
|
bool same_base(const void* other) const
|
2022-11-29 01:47:55 +01:00
|
|
|
{
|
|
|
|
return other == (const void*) base;
|
|
|
|
}
|
2022-04-30 00:01:06 +02:00
|
|
|
|
2022-11-30 01:19:10 +01:00
|
|
|
const hb_set_t* set_for (const EncodingRecord* record,
|
|
|
|
SubtableUnicodesCache& mutable_cache) const
|
|
|
|
{
|
|
|
|
if (cached_unicodes.has ((unsigned) ((const char *) record - base)))
|
|
|
|
return cached_unicodes.get ((unsigned) ((const char *) record - base));
|
|
|
|
|
|
|
|
return mutable_cache.set_for (record);
|
|
|
|
}
|
|
|
|
|
|
|
|
const hb_set_t* set_for (const EncodingRecord* record)
|
2022-04-30 00:01:06 +02:00
|
|
|
{
|
2022-11-28 23:53:35 +01:00
|
|
|
if (!cached_unicodes.has ((unsigned) ((const char *) record - base)))
|
2022-06-03 09:37:02 +02:00
|
|
|
{
|
|
|
|
hb_set_t *s = hb_set_create ();
|
|
|
|
if (unlikely (s->in_error ()))
|
|
|
|
return hb_set_get_empty ();
|
2022-11-29 01:47:55 +01:00
|
|
|
|
2022-06-03 09:37:02 +02:00
|
|
|
(base+record->subtable).collect_unicodes (s);
|
|
|
|
|
2022-11-28 23:53:35 +01:00
|
|
|
if (unlikely (!cached_unicodes.set ((unsigned) ((const char *) record - base), hb::unique_ptr<hb_set_t> {s})))
|
2022-04-30 00:49:02 +02:00
|
|
|
return hb_set_get_empty ();
|
2022-06-03 09:37:02 +02:00
|
|
|
|
|
|
|
return s;
|
2022-04-30 00:01:06 +02:00
|
|
|
}
|
2022-11-28 23:53:35 +01:00
|
|
|
return cached_unicodes.get ((unsigned) ((const char *) record - base));
|
2022-04-30 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-06-19 19:55:09 +02:00
|
|
|
static inline uint_fast16_t
|
|
|
|
_hb_symbol_pua_map (unsigned codepoint)
|
2022-06-16 19:04:13 +02:00
|
|
|
{
|
|
|
|
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:
|
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/recom
|
|
|
|
* under "Non-Standard (Symbol) Fonts". */
|
|
|
|
return 0xF000u + codepoint;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:35:56 +02:00
|
|
|
struct cmap
|
|
|
|
{
|
2019-01-22 12:08:57 +01:00
|
|
|
static constexpr hb_tag_t tableTag = HB_OT_TAG_cmap;
|
2014-05-09 21:35:56 +02:00
|
|
|
|
2022-11-29 01:47:55 +01:00
|
|
|
|
|
|
|
static SubtableUnicodesCache* create_filled_cache(hb_blob_ptr_t<cmap> source_table) {
|
|
|
|
const cmap* cmap = source_table.get();
|
|
|
|
auto it =
|
|
|
|
+ hb_iter (cmap->encodingRecord)
|
|
|
|
| hb_filter ([&](const EncodingRecord& _) {
|
|
|
|
return cmap::filter_encoding_records_for_subset (cmap, _);
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
SubtableUnicodesCache* cache = SubtableUnicodesCache::create(source_table);
|
|
|
|
for (const EncodingRecord& _ : it)
|
|
|
|
cache->set_for(&_); // populate the cache for this encoding record.
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
template<typename Iterator, typename EncodingRecIter,
|
2020-04-23 00:58:41 +02:00
|
|
|
hb_requires (hb_is_iterator (EncodingRecIter))>
|
2021-08-26 23:32:17 +02:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
2019-09-21 11:49:14 +02:00
|
|
|
Iterator it,
|
|
|
|
EncodingRecIter encodingrec_iter,
|
2020-03-08 21:09:24 +01:00
|
|
|
const void *base,
|
2022-11-29 01:47:55 +01:00
|
|
|
hb_subset_plan_t *plan,
|
2021-08-26 23:32:17 +02:00
|
|
|
bool drop_format_4 = false)
|
2018-08-26 09:21:29 +02:00
|
|
|
{
|
2021-08-26 23:32:17 +02:00
|
|
|
if (unlikely (!c->extend_min ((*this)))) return false;
|
2019-06-25 22:17:30 +02:00
|
|
|
this->version = 0;
|
2018-05-03 00:42:43 +02:00
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
unsigned format4objidx = 0, format12objidx = 0, format14objidx = 0;
|
2021-08-26 23:32:17 +02:00
|
|
|
auto snap = c->snapshot ();
|
2018-05-03 00:42:43 +02:00
|
|
|
|
2022-11-29 01:47:55 +01:00
|
|
|
SubtableUnicodesCache local_unicodes_cache (base);
|
2022-11-30 01:19:10 +01:00
|
|
|
const SubtableUnicodesCache* unicodes_cache = &local_unicodes_cache;
|
2022-11-29 01:47:55 +01:00
|
|
|
|
|
|
|
if (plan->accelerator &&
|
|
|
|
plan->accelerator->cmap_cache &&
|
|
|
|
plan->accelerator->cmap_cache->same_base (base))
|
|
|
|
unicodes_cache = plan->accelerator->cmap_cache;
|
|
|
|
|
2019-09-21 12:56:14 +02:00
|
|
|
for (const EncodingRecord& _ : encodingrec_iter)
|
|
|
|
{
|
2021-08-26 23:32:17 +02:00
|
|
|
if (c->in_error ())
|
|
|
|
return false;
|
|
|
|
|
2020-03-08 21:09:24 +01:00
|
|
|
unsigned format = (base+_.subtable).u.format;
|
2021-07-15 02:27:14 +02:00
|
|
|
if (format != 4 && format != 12 && format != 14) continue;
|
2020-07-16 03:54:52 +02:00
|
|
|
|
2022-11-30 01:19:10 +01:00
|
|
|
const hb_set_t* unicodes_set = unicodes_cache->set_for (&_, local_unicodes_cache);
|
2021-07-15 02:27:14 +02:00
|
|
|
|
2021-08-26 23:32:17 +02:00
|
|
|
if (!drop_format_4 && format == 4)
|
|
|
|
{
|
2022-04-30 00:01:06 +02:00
|
|
|
c->copy (_, + it | hb_filter (*unicodes_set, hb_first), 4u, base, plan, &format4objidx);
|
2021-08-26 23:32:17 +02:00
|
|
|
if (c->in_error () && c->only_overflow ())
|
|
|
|
{
|
|
|
|
// cmap4 overflowed, reset and retry serialization without format 4 subtables.
|
|
|
|
c->revert (snap);
|
|
|
|
return serialize (c, it,
|
|
|
|
encodingrec_iter,
|
|
|
|
base,
|
|
|
|
plan,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 20:38:38 +02:00
|
|
|
else if (format == 12)
|
|
|
|
{
|
2022-11-30 01:19:10 +01:00
|
|
|
if (_can_drop (_,
|
|
|
|
*unicodes_set,
|
|
|
|
base,
|
|
|
|
*unicodes_cache,
|
|
|
|
local_unicodes_cache,
|
|
|
|
+ it | hb_map (hb_first), encodingrec_iter))
|
|
|
|
continue;
|
2022-04-30 00:01:06 +02:00
|
|
|
c->copy (_, + it | hb_filter (*unicodes_set, hb_first), 12u, base, plan, &format12objidx);
|
2021-08-04 20:38:38 +02:00
|
|
|
}
|
2021-07-15 02:27:14 +02:00
|
|
|
else if (format == 14) c->copy (_, it, 14u, base, plan, &format14objidx);
|
2019-09-21 12:56:14 +02:00
|
|
|
}
|
2021-03-17 23:53:10 +01:00
|
|
|
c->check_assign(this->encodingRecord.len,
|
|
|
|
(c->length () - cmap::min_size)/EncodingRecord::static_size,
|
2021-03-18 18:51:26 +01:00
|
|
|
HB_SERIALIZE_ERROR_INT_OVERFLOW);
|
2021-08-26 23:32:17 +02:00
|
|
|
|
|
|
|
// Fail if format 4 was dropped and there is no cmap12.
|
|
|
|
return !drop_format_4 || format12objidx;
|
2018-02-10 02:33:34 +01:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:38:38 +02:00
|
|
|
template<typename Iterator, typename EncodingRecordIterator,
|
|
|
|
hb_requires (hb_is_iterator (Iterator)),
|
|
|
|
hb_requires (hb_is_iterator (EncodingRecordIterator))>
|
|
|
|
bool _can_drop (const EncodingRecord& cmap12,
|
|
|
|
const hb_set_t& cmap12_unicodes,
|
|
|
|
const void* base,
|
2022-11-30 01:19:10 +01:00
|
|
|
const SubtableUnicodesCache& unicodes_cache,
|
|
|
|
SubtableUnicodesCache& local_unicodes_cache,
|
2021-08-04 20:38:38 +02:00
|
|
|
Iterator subset_unicodes,
|
|
|
|
EncodingRecordIterator encoding_records)
|
|
|
|
{
|
|
|
|
for (auto cp : + subset_unicodes | hb_filter (cmap12_unicodes))
|
|
|
|
{
|
|
|
|
if (cp >= 0x10000) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned target_platform;
|
|
|
|
unsigned target_encoding;
|
|
|
|
unsigned target_language = (base+cmap12.subtable).get_language ();
|
|
|
|
|
|
|
|
if (cmap12.platformID == 0 && cmap12.encodingID == 4)
|
|
|
|
{
|
|
|
|
target_platform = 0;
|
|
|
|
target_encoding = 3;
|
|
|
|
} else if (cmap12.platformID == 3 && cmap12.encodingID == 10) {
|
|
|
|
target_platform = 3;
|
|
|
|
target_encoding = 1;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& _ : encoding_records)
|
|
|
|
{
|
|
|
|
if (_.platformID != target_platform
|
|
|
|
|| _.encodingID != target_encoding
|
|
|
|
|| (base+_.subtable).get_language() != target_language)
|
|
|
|
continue;
|
|
|
|
|
2022-11-30 01:19:10 +01:00
|
|
|
const hb_set_t* sibling_unicodes = unicodes_cache.set_for (&_, local_unicodes_cache);
|
2021-08-04 20:38:38 +02:00
|
|
|
|
|
|
|
auto cmap12 = + subset_unicodes | hb_filter (cmap12_unicodes);
|
2022-04-30 00:01:06 +02:00
|
|
|
auto sibling = + subset_unicodes | hb_filter (*sibling_unicodes);
|
2021-08-04 20:38:38 +02:00
|
|
|
for (; cmap12 && sibling; cmap12++, sibling++)
|
|
|
|
{
|
|
|
|
unsigned a = *cmap12;
|
|
|
|
unsigned b = *sibling;
|
|
|
|
if (a != b) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !cmap12 && !sibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:17:26 +02:00
|
|
|
void closure_glyphs (const hb_set_t *unicodes,
|
2019-09-21 11:49:14 +02:00
|
|
|
hb_set_t *glyphset) const
|
2019-08-07 22:17:26 +02:00
|
|
|
{
|
|
|
|
+ hb_iter (encodingRecord)
|
|
|
|
| hb_map (&EncodingRecord::subtable)
|
|
|
|
| hb_map (hb_add (this))
|
|
|
|
| hb_filter ([&] (const CmapSubtable& _) { return _.u.format == 14; })
|
|
|
|
| hb_apply ([=] (const CmapSubtable& _) { _.u.format14.closure_glyphs (unicodes, glyphset); })
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
bool subset (hb_subset_context_t *c) const
|
2018-02-10 02:33:34 +01:00
|
|
|
{
|
2019-06-25 22:17:30 +02:00
|
|
|
TRACE_SUBSET (this);
|
2018-02-12 19:12:11 +01:00
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
cmap *cmap_prime = c->serializer->start_embed<cmap> ();
|
|
|
|
if (unlikely (!c->serializer->check_success (cmap_prime))) return_trace (false);
|
2018-02-10 02:33:34 +01:00
|
|
|
|
2019-08-16 22:54:24 +02:00
|
|
|
auto encodingrec_iter =
|
|
|
|
+ hb_iter (encodingRecord)
|
2022-11-29 01:47:55 +01:00
|
|
|
| hb_filter ([&](const EncodingRecord& _) {
|
|
|
|
return cmap::filter_encoding_records_for_subset (this, _);
|
|
|
|
})
|
2019-08-29 20:17:20 +02:00
|
|
|
;
|
2019-09-21 11:49:14 +02:00
|
|
|
|
2019-08-29 20:17:20 +02:00
|
|
|
if (unlikely (!encodingrec_iter.len ())) return_trace (false);
|
|
|
|
|
2020-02-05 15:26:45 +01:00
|
|
|
const EncodingRecord *unicode_bmp= nullptr, *unicode_ucs4 = nullptr, *ms_bmp = nullptr, *ms_ucs4 = nullptr;
|
2019-09-23 19:21:43 +02:00
|
|
|
bool has_format12 = false;
|
2019-09-21 11:49:14 +02:00
|
|
|
|
2019-09-21 12:56:14 +02:00
|
|
|
for (const EncodingRecord& _ : encodingrec_iter)
|
|
|
|
{
|
|
|
|
unsigned format = (this + _.subtable).u.format;
|
|
|
|
if (format == 12) has_format12 = true;
|
|
|
|
|
2022-01-14 00:17:34 +01:00
|
|
|
const EncodingRecord *table = std::addressof (_);
|
2019-09-23 19:21:43 +02:00
|
|
|
if (_.platformID == 0 && _.encodingID == 3) unicode_bmp = table;
|
|
|
|
else if (_.platformID == 0 && _.encodingID == 4) unicode_ucs4 = table;
|
|
|
|
else if (_.platformID == 3 && _.encodingID == 1) ms_bmp = table;
|
2019-09-21 12:56:14 +02:00
|
|
|
else if (_.platformID == 3 && _.encodingID == 10) ms_ucs4 = table;
|
|
|
|
}
|
2019-09-21 11:49:14 +02:00
|
|
|
|
2020-02-05 14:01:21 +01:00
|
|
|
if (unlikely (!has_format12 && !unicode_bmp && !ms_bmp)) return_trace (false);
|
2019-06-25 22:17:30 +02:00
|
|
|
if (unlikely (has_format12 && (!unicode_ucs4 && !ms_ucs4))) return_trace (false);
|
2018-02-12 19:12:11 +01:00
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
auto it =
|
2022-05-04 00:02:59 +02:00
|
|
|
+ c->plan->unicode_to_new_gid_list.iter ()
|
2019-09-21 12:03:43 +02:00
|
|
|
| hb_filter ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> _)
|
|
|
|
{ return (_.second != HB_MAP_VALUE_INVALID); })
|
2019-06-25 22:17:30 +02:00
|
|
|
;
|
2021-08-26 23:32:17 +02:00
|
|
|
|
2022-11-29 01:47:55 +01:00
|
|
|
return_trace (cmap_prime->serialize (c->serializer,
|
|
|
|
it,
|
|
|
|
encodingrec_iter,
|
|
|
|
this,
|
|
|
|
c->plan));
|
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;
|
|
|
|
|
2019-08-21 21:30:22 +02:00
|
|
|
/* Symbol subtable.
|
|
|
|
* Prefer symbol if available.
|
|
|
|
* https://github.com/harfbuzz/harfbuzz/issues/1918 */
|
|
|
|
if ((subtable = this->find_subtable (3, 0)))
|
|
|
|
{
|
|
|
|
if (symbol) *symbol = true;
|
|
|
|
return subtable;
|
|
|
|
}
|
|
|
|
|
2018-08-26 00:33:05 +02:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* Meh. */
|
2018-11-15 20:40:56 +01:00
|
|
|
return &Null (CmapSubtable);
|
2018-08-26 00:33:05 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
struct accelerator_t
|
|
|
|
{
|
2022-01-20 19:47:17 +01:00
|
|
|
accelerator_t (hb_face_t *face)
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
2018-11-15 20:40:56 +01:00
|
|
|
this->table = hb_sanitize_context_t ().reference_table<cmap> (face);
|
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);
|
2018-11-15 20:40:56 +01:00
|
|
|
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))
|
2022-06-16 19:04:13 +02:00
|
|
|
{
|
|
|
|
switch ((unsigned) face->table.OS2->get_font_page ()) {
|
2022-06-19 18:13:31 +02:00
|
|
|
case OS2::font_page_t::FONT_PAGE_NONE:
|
2022-06-19 18:47:38 +02:00
|
|
|
this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable, _hb_symbol_pua_map>;
|
2022-06-16 19:04:13 +02:00
|
|
|
break;
|
2022-06-19 18:41:45 +02:00
|
|
|
#ifndef HB_NO_OT_SHAPER_ARABIC_FALLBACK
|
2022-06-16 19:04:13 +02:00
|
|
|
case OS2::font_page_t::FONT_PAGE_SIMP_ARABIC:
|
2022-06-19 18:47:38 +02:00
|
|
|
this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable, _hb_arabic_pua_simp_map>;
|
2022-06-16 19:04:13 +02:00
|
|
|
break;
|
|
|
|
case OS2::font_page_t::FONT_PAGE_TRAD_ARABIC:
|
2022-06-19 18:47:38 +02:00
|
|
|
this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable, _hb_arabic_pua_trad_map>;
|
2022-06-16 19:04:13 +02:00
|
|
|
break;
|
2022-06-19 18:41:45 +02:00
|
|
|
#endif
|
2022-06-19 18:13:31 +02:00
|
|
|
default:
|
|
|
|
this->get_glyph_funcZ = get_glyph_from<CmapSubtable>;
|
|
|
|
break;
|
2022-06-16 19:04:13 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-21 12:03:43 +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:
|
2019-09-21 12:03:43 +02:00
|
|
|
{
|
2022-01-20 19:47:17 +01:00
|
|
|
this->format4_accel.init (&subtable->u.format4);
|
2019-09-21 12:03:43 +02:00
|
|
|
this->get_glyph_data = &this->format4_accel;
|
|
|
|
this->get_glyph_funcZ = this->format4_accel.get_glyph_func;
|
2017-11-15 05:06:19 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-09-21 12:03:43 +02:00
|
|
|
}
|
2018-04-11 00:40:24 +02:00
|
|
|
}
|
2017-11-15 05:06:19 +01:00
|
|
|
}
|
2022-01-20 19:47:17 +01:00
|
|
|
~accelerator_t () { this->table.destroy (); }
|
2017-11-15 05:06:19 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_nominal_glyph (hb_codepoint_t unicode,
|
2019-09-21 12:03:43 +02:00
|
|
|
hb_codepoint_t *glyph) const
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
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
|
|
|
}
|
2023-01-28 21:37:43 +01:00
|
|
|
|
|
|
|
template <typename cache_t = void>
|
|
|
|
inline bool _cached_get (hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t *glyph,
|
|
|
|
cache_t *cache) const
|
|
|
|
{
|
|
|
|
unsigned v;
|
|
|
|
if (cache && cache->get (unicode, &v))
|
|
|
|
{
|
|
|
|
*glyph = v;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool ret = this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph);
|
|
|
|
if (cache && ret)
|
|
|
|
cache->set (unicode, *glyph);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename cache_t = void>
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_nominal_glyphs (unsigned int count,
|
|
|
|
const hb_codepoint_t *first_unicode,
|
|
|
|
unsigned int unicode_stride,
|
|
|
|
hb_codepoint_t *first_glyph,
|
2023-01-28 21:37:43 +01:00
|
|
|
unsigned int glyph_stride,
|
|
|
|
cache_t *cache = nullptr) const
|
2018-11-06 01:49:54 +01:00
|
|
|
{
|
|
|
|
if (unlikely (!this->get_glyph_funcZ)) return 0;
|
|
|
|
|
|
|
|
unsigned int done;
|
|
|
|
for (done = 0;
|
2023-01-28 21:37:43 +01:00
|
|
|
done < count && _cached_get (*first_unicode, first_glyph, cache);
|
2018-11-06 01:49:54 +01:00
|
|
|
done++)
|
|
|
|
{
|
2019-01-22 12:45:40 +01:00
|
|
|
first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
|
|
|
|
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
|
2018-11-06 01:49:54 +01:00
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
2017-11-15 05:06:19 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_variation_glyph (hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t *glyph) const
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2020-02-29 10:32:29 +01:00
|
|
|
void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const
|
|
|
|
{ subtable->collect_unicodes (out, num_glyphs); }
|
2020-04-23 00:58:41 +02:00
|
|
|
void collect_mapping (hb_set_t *unicodes, hb_map_t *mapping,
|
|
|
|
unsigned num_glyphs = UINT_MAX) const
|
|
|
|
{ subtable->collect_mapping (unicodes, mapping, num_glyphs); }
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_variation_selectors (hb_set_t *out) const
|
2019-09-21 12:03:43 +02:00
|
|
|
{ subtable_uvs->collect_variation_selectors (out); }
|
2018-12-16 20:08:10 +01:00
|
|
|
void collect_variation_unicodes (hb_codepoint_t variation_selector,
|
|
|
|
hb_set_t *out) const
|
2019-09-21 12:03:43 +02:00
|
|
|
{ subtable_uvs->collect_variation_unicodes (variation_selector, out); }
|
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);
|
2022-06-19 19:55:09 +02:00
|
|
|
typedef uint_fast16_t (*hb_pua_remap_func_t) (unsigned);
|
2018-04-11 00:40:24 +02:00
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
template <typename Type>
|
2019-04-12 23:50:03 +02:00
|
|
|
HB_INTERNAL static bool get_glyph_from (const void *obj,
|
|
|
|
hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph)
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
|
|
|
const Type *typed_obj = (const Type *) obj;
|
|
|
|
return typed_obj->get_glyph (codepoint, glyph);
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:04:13 +02:00
|
|
|
template <typename Type, hb_pua_remap_func_t remap>
|
2019-04-12 23:50:03 +02:00
|
|
|
HB_INTERNAL static bool get_glyph_from_symbol (const void *obj,
|
|
|
|
hb_codepoint_t codepoint,
|
|
|
|
hb_codepoint_t *glyph)
|
2017-11-15 05:06:19 +01:00
|
|
|
{
|
|
|
|
const Type *typed_obj = (const Type *) obj;
|
|
|
|
if (likely (typed_obj->get_glyph (codepoint, glyph)))
|
|
|
|
return true;
|
|
|
|
|
2022-06-16 19:04:13 +02:00
|
|
|
if (hb_codepoint_t c = remap (codepoint))
|
|
|
|
return typed_obj->get_glyph (c, glyph);
|
2017-11-15 05:06:19 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-08-07 22:17:26 +02:00
|
|
|
public:
|
2018-11-11 06:28:47 +01:00
|
|
|
hb_blob_ptr_t<cmap> table;
|
2017-11-15 05:06:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const CmapSubtable *find_subtable (unsigned int platform_id,
|
|
|
|
unsigned int encoding_id) const
|
2014-05-09 21:35:56 +02:00
|
|
|
{
|
|
|
|
EncodingRecord key;
|
2019-03-30 04:17:46 +01:00
|
|
|
key.platformID = platform_id;
|
|
|
|
key.encodingID = encoding_id;
|
2014-05-09 21:35:56 +02:00
|
|
|
|
2018-11-24 06:35:31 +01:00
|
|
|
const EncodingRecord &result = encodingRecord.bsearch (key);
|
|
|
|
if (!result.subtable)
|
2017-10-15 12:11:08 +02:00
|
|
|
return nullptr;
|
2014-05-12 19:46:29 +02:00
|
|
|
|
2018-11-24 06:35:31 +01:00
|
|
|
return &(this+result.subtable);
|
2014-05-09 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 22:17:30 +02:00
|
|
|
const EncodingRecord *find_encodingrec (unsigned int platform_id,
|
2020-04-20 11:42:45 +02:00
|
|
|
unsigned int encoding_id) const
|
2019-06-25 22:17:30 +02:00
|
|
|
{
|
|
|
|
EncodingRecord key;
|
|
|
|
key.platformID = platform_id;
|
|
|
|
key.encodingID = encoding_id;
|
|
|
|
|
|
|
|
return encodingRecord.as_array ().bsearch (key);
|
|
|
|
}
|
|
|
|
|
2019-05-14 22:55:11 +02:00
|
|
|
bool find_subtable (unsigned format) const
|
|
|
|
{
|
|
|
|
auto it =
|
|
|
|
+ hb_iter (encodingRecord)
|
|
|
|
| hb_map (&EncodingRecord::subtable)
|
|
|
|
| hb_map (hb_add (this))
|
|
|
|
| hb_filter ([&] (const CmapSubtable& _) { return _.u.format == format; })
|
|
|
|
;
|
|
|
|
|
|
|
|
return it.len ();
|
|
|
|
}
|
|
|
|
|
2018-11-23 04:17:49 +01:00
|
|
|
public:
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-11-23 04:17:49 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
likely (version == 0) &&
|
|
|
|
encodingRecord.sanitize (c, this));
|
|
|
|
}
|
|
|
|
|
2022-11-29 01:47:55 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
static bool filter_encoding_records_for_subset(const cmap* cmap,
|
|
|
|
const EncodingRecord& _)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
(_.platformID == 0 && _.encodingID == 3) ||
|
|
|
|
(_.platformID == 0 && _.encodingID == 4) ||
|
|
|
|
(_.platformID == 3 && _.encodingID == 1) ||
|
|
|
|
(_.platformID == 3 && _.encodingID == 10) ||
|
|
|
|
(cmap + _.subtable).u.format == 14;
|
|
|
|
}
|
|
|
|
|
2017-11-15 05:06:19 +01:00
|
|
|
protected:
|
2020-04-24 21:15:17 +02:00
|
|
|
HBUINT16 version; /* Table version number (0). */
|
2021-04-01 00:09:39 +02:00
|
|
|
SortedArray16Of<EncodingRecord>
|
2020-04-24 21:15:17 +02:00
|
|
|
encodingRecord; /* Encoding tables. */
|
2014-05-09 21:35:56 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY (4, encodingRecord);
|
|
|
|
};
|
|
|
|
|
2022-01-20 19:47:17 +01:00
|
|
|
struct cmap_accelerator_t : cmap::accelerator_t {
|
|
|
|
cmap_accelerator_t (hb_face_t *face) : cmap::accelerator_t (face) {}
|
|
|
|
};
|
2014-05-09 21:35:56 +02:00
|
|
|
|
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_OT_CMAP_TABLE_HH */
|