2017-08-15 02:24:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2017 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_AAT_LAYOUT_MORX_TABLE_HH
|
|
|
|
#define HB_AAT_LAYOUT_MORX_TABLE_HH
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-open-type.hh"
|
|
|
|
#include "hb-aat-layout-common.hh"
|
|
|
|
#include "hb-ot-layout-common.hh"
|
2021-05-05 12:11:43 +02:00
|
|
|
#include "hb-ot-layout-gdef-table.hh"
|
2018-10-23 23:14:03 +02:00
|
|
|
#include "hb-aat-map.hh"
|
2017-08-15 02:24:36 +02:00
|
|
|
|
2018-04-12 11:08:19 +02:00
|
|
|
/*
|
|
|
|
* morx -- Extended Glyph Metamorphosis
|
|
|
|
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6morx.html
|
2018-10-30 16:11:34 +01:00
|
|
|
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6mort.html
|
2018-04-12 11:08:19 +02:00
|
|
|
*/
|
2018-03-26 09:34:30 +02:00
|
|
|
#define HB_AAT_TAG_morx HB_TAG('m','o','r','x')
|
2018-10-30 16:11:34 +01:00
|
|
|
#define HB_AAT_TAG_mort HB_TAG('m','o','r','t')
|
2017-08-15 02:24:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace AAT {
|
|
|
|
|
|
|
|
using namespace OT;
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types>
|
2017-08-15 02:24:36 +02:00
|
|
|
struct RearrangementSubtable
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2018-02-13 22:59:39 +01:00
|
|
|
typedef void EntryData;
|
|
|
|
|
2018-01-12 00:08:22 +01:00
|
|
|
struct driver_context_t
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool in_place = true;
|
2018-09-15 14:47:18 +02:00
|
|
|
enum Flags
|
|
|
|
{
|
2018-01-12 09:45:42 +01:00
|
|
|
MarkFirst = 0x8000, /* If set, make the current glyph the first
|
|
|
|
* glyph to be rearranged. */
|
2018-01-12 00:08:22 +01:00
|
|
|
DontAdvance = 0x4000, /* If set, don't advance to the next glyph
|
2018-01-12 09:45:42 +01:00
|
|
|
* before going to the new state. This means
|
|
|
|
* that the glyph index doesn't change, even
|
|
|
|
* if the glyph at that index has changed. */
|
|
|
|
MarkLast = 0x2000, /* If set, make the current glyph the last
|
|
|
|
* glyph to be rearranged. */
|
|
|
|
Reserved = 0x1FF0, /* These bits are reserved and should be set to 0. */
|
|
|
|
Verb = 0x000F, /* The type of rearrangement specified. */
|
2018-01-12 00:08:22 +01:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
driver_context_t (const RearrangementSubtable *table HB_UNUSED) :
|
2018-01-12 00:08:22 +01:00
|
|
|
ret (false),
|
2018-02-04 20:58:02 +01:00
|
|
|
start (0), end (0) {}
|
2018-01-12 00:08:22 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool is_actionable (StateTableDriver<Types, EntryData> *driver HB_UNUSED,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-02-04 20:58:02 +01:00
|
|
|
{
|
2019-01-24 17:21:41 +01:00
|
|
|
return (entry.flags & Verb) && start < end;
|
2018-02-04 20:58:02 +01:00
|
|
|
}
|
2019-01-24 18:01:07 +01:00
|
|
|
void transition (StateTableDriver<Types, EntryData> *driver,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
2018-01-12 00:08:22 +01:00
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int flags = entry.flags;
|
2018-01-11 09:15:34 +01:00
|
|
|
|
|
|
|
if (flags & MarkFirst)
|
2018-01-12 00:08:22 +01:00
|
|
|
start = buffer->idx;
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-11 15:23:24 +01:00
|
|
|
if (flags & MarkLast)
|
2019-05-08 05:54:31 +02:00
|
|
|
end = hb_min (buffer->idx + 1, buffer->len);
|
2018-01-11 09:15:34 +01:00
|
|
|
|
|
|
|
if ((flags & Verb) && start < end)
|
|
|
|
{
|
|
|
|
/* The following map has two nibbles, for start-side
|
|
|
|
* and end-side. Values of 0,1,2 mean move that many
|
|
|
|
* to the other side. Value of 3 means move 2 and
|
|
|
|
* flip them. */
|
2018-01-12 11:31:20 +01:00
|
|
|
const unsigned char map[16] =
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
|
|
|
0x00, /* 0 no change */
|
|
|
|
0x10, /* 1 Ax => xA */
|
|
|
|
0x01, /* 2 xD => Dx */
|
|
|
|
0x11, /* 3 AxD => DxA */
|
|
|
|
0x20, /* 4 ABx => xAB */
|
|
|
|
0x30, /* 5 ABx => xBA */
|
|
|
|
0x02, /* 6 xCD => CDx */
|
|
|
|
0x03, /* 7 xCD => DCx */
|
|
|
|
0x12, /* 8 AxCD => CDxA */
|
|
|
|
0x13, /* 9 AxCD => DCxA */
|
|
|
|
0x21, /* 10 ABxD => DxAB */
|
|
|
|
0x31, /* 11 ABxD => DxBA */
|
|
|
|
0x22, /* 12 ABxCD => CDxAB */
|
|
|
|
0x32, /* 13 ABxCD => CDxBA */
|
|
|
|
0x23, /* 14 ABxCD => DCxAB */
|
|
|
|
0x33, /* 15 ABxCD => DCxBA */
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int m = map[flags & Verb];
|
2019-05-08 05:54:31 +02:00
|
|
|
unsigned int l = hb_min (2u, m >> 4);
|
|
|
|
unsigned int r = hb_min (2u, m & 0x0F);
|
2018-01-11 09:15:34 +01:00
|
|
|
bool reverse_l = 3 == (m >> 4);
|
|
|
|
bool reverse_r = 3 == (m & 0x0F);
|
|
|
|
|
2022-06-01 15:54:45 +02:00
|
|
|
if (end - start >= l + r && end-start <= HB_MAX_CONTEXT_LENGTH)
|
2018-01-11 09:15:34 +01:00
|
|
|
{
|
2019-05-08 05:54:31 +02:00
|
|
|
buffer->merge_clusters (start, hb_min (buffer->idx + 1, buffer->len));
|
2018-01-12 00:08:22 +01:00
|
|
|
buffer->merge_clusters (start, end);
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-12 00:08:22 +01:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2018-01-11 09:15:34 +01:00
|
|
|
hb_glyph_info_t buf[4];
|
2018-01-12 00:08:22 +01:00
|
|
|
|
2022-11-22 20:54:50 +01:00
|
|
|
hb_memcpy (buf, info + start, l * sizeof (buf[0]));
|
|
|
|
hb_memcpy (buf + 2, info + end - r, r * sizeof (buf[0]));
|
2018-01-11 09:15:34 +01:00
|
|
|
|
|
|
|
if (l != r)
|
2018-01-11 10:08:25 +01:00
|
|
|
memmove (info + start + r, info + start + l, (end - start - l - r) * sizeof (buf[0]));
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2022-11-22 20:54:50 +01:00
|
|
|
hb_memcpy (info + start, buf + 2, r * sizeof (buf[0]));
|
|
|
|
hb_memcpy (info + end - l, buf, l * sizeof (buf[0]));
|
2018-01-11 09:15:34 +01:00
|
|
|
if (reverse_l)
|
|
|
|
{
|
|
|
|
buf[0] = info[end - 1];
|
|
|
|
info[end - 1] = info[end - 2];
|
|
|
|
info[end - 2] = buf[0];
|
|
|
|
}
|
|
|
|
if (reverse_r)
|
|
|
|
{
|
|
|
|
buf[0] = info[start];
|
|
|
|
info[start] = info[start + 1];
|
|
|
|
info[start + 1] = buf[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-12 00:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool ret;
|
|
|
|
private:
|
2018-01-12 09:38:55 +01:00
|
|
|
unsigned int start;
|
|
|
|
unsigned int end;
|
2018-01-12 00:08:22 +01:00
|
|
|
};
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-01-12 00:08:22 +01:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-12 00:08:22 +01:00
|
|
|
driver_context_t dc (this);
|
|
|
|
|
2018-10-31 03:22:43 +01:00
|
|
|
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->face);
|
2023-01-10 05:32:15 +01:00
|
|
|
driver.drive (&dc, c);
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-12 00:08:22 +01:00
|
|
|
return_trace (dc.ret);
|
2018-01-09 17:55:17 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-11 14:50:47 +01:00
|
|
|
return_trace (machine.sanitize (c));
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
2018-01-11 09:15:34 +01:00
|
|
|
|
|
|
|
protected:
|
2018-10-30 16:11:34 +01:00
|
|
|
StateTable<Types, EntryData> machine;
|
2018-01-11 09:15:34 +01:00
|
|
|
public:
|
2018-01-12 12:04:53 +01:00
|
|
|
DEFINE_SIZE_STATIC (16);
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types>
|
2017-08-15 02:24:36 +02:00
|
|
|
struct ContextualSubtable
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2018-01-11 14:50:47 +01:00
|
|
|
struct EntryData
|
|
|
|
{
|
|
|
|
HBUINT16 markIndex; /* Index of the substitution table for the
|
|
|
|
* marked glyph (use 0xFFFF for none). */
|
|
|
|
HBUINT16 currentIndex; /* Index of the substitution table for the
|
|
|
|
* current glyph (use 0xFFFF for none). */
|
2018-01-11 17:41:34 +01:00
|
|
|
public:
|
2018-01-11 18:01:10 +01:00
|
|
|
DEFINE_SIZE_STATIC (4);
|
2018-01-11 14:50:47 +01:00
|
|
|
};
|
|
|
|
|
2018-01-12 00:01:36 +01:00
|
|
|
struct driver_context_t
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool in_place = true;
|
2018-09-15 14:47:18 +02:00
|
|
|
enum Flags
|
|
|
|
{
|
2018-01-12 00:01:36 +01:00
|
|
|
SetMark = 0x8000, /* If set, make the current glyph the marked glyph. */
|
|
|
|
DontAdvance = 0x4000, /* If set, don't advance to the next glyph before
|
|
|
|
* going to the new state. */
|
|
|
|
Reserved = 0x3FFF, /* These bits are reserved and should be set to 0. */
|
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
driver_context_t (const ContextualSubtable *table_,
|
2018-10-31 07:33:30 +01:00
|
|
|
hb_aat_apply_context_t *c_) :
|
2018-01-12 00:01:36 +01:00
|
|
|
ret (false),
|
2018-10-31 07:33:30 +01:00
|
|
|
c (c_),
|
2021-05-05 12:11:43 +02:00
|
|
|
gdef (*c->gdef_table),
|
2018-02-04 20:45:02 +01:00
|
|
|
mark_set (false),
|
2021-05-05 12:11:43 +02:00
|
|
|
has_glyph_classes (gdef.has_glyph_classes ()),
|
2018-01-12 00:01:36 +01:00
|
|
|
mark (0),
|
2018-10-31 07:33:30 +01:00
|
|
|
table (table_),
|
2018-01-12 00:01:36 +01:00
|
|
|
subs (table+table->substitutionTables) {}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool is_actionable (StateTableDriver<Types, EntryData> *driver,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-02-04 20:58:02 +01:00
|
|
|
{
|
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
|
|
|
|
|
|
|
if (buffer->idx == buffer->len && !mark_set)
|
2019-08-24 15:27:14 +02:00
|
|
|
return false;
|
2018-02-04 20:58:02 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
return entry.data.markIndex != 0xFFFF || entry.data.currentIndex != 0xFFFF;
|
2018-02-04 20:58:02 +01:00
|
|
|
}
|
2019-01-24 18:01:07 +01:00
|
|
|
void transition (StateTableDriver<Types, EntryData> *driver,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-01-11 15:15:07 +01:00
|
|
|
{
|
2018-01-12 00:01:36 +01:00
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
2018-01-11 15:15:07 +01:00
|
|
|
|
2018-02-04 20:45:02 +01:00
|
|
|
/* Looks like CoreText applies neither mark nor current substitution for
|
|
|
|
* end-of-text if mark was not explicitly set. */
|
|
|
|
if (buffer->idx == buffer->len && !mark_set)
|
2019-08-24 15:27:14 +02:00
|
|
|
return;
|
2018-02-04 20:45:02 +01:00
|
|
|
|
2021-09-19 22:30:12 +02:00
|
|
|
const HBGlyphID16 *replacement;
|
2018-10-31 07:33:30 +01:00
|
|
|
|
|
|
|
replacement = nullptr;
|
|
|
|
if (Types::extended)
|
2018-01-11 15:15:07 +01:00
|
|
|
{
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.data.markIndex != 0xFFFF)
|
2018-01-11 15:15:07 +01:00
|
|
|
{
|
2021-09-19 22:30:12 +02:00
|
|
|
const Lookup<HBGlyphID16> &lookup = subs[entry.data.markIndex];
|
2018-10-31 07:33:30 +01:00
|
|
|
replacement = lookup.get_value (buffer->info[mark].codepoint, driver->num_glyphs);
|
2018-01-11 15:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-31 07:33:30 +01:00
|
|
|
else
|
|
|
|
{
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int offset = entry.data.markIndex + buffer->info[mark].codepoint;
|
2021-09-19 22:30:12 +02:00
|
|
|
const UnsizedArrayOf<HBGlyphID16> &subs_old = (const UnsizedArrayOf<HBGlyphID16> &) subs;
|
2018-10-31 23:09:09 +01:00
|
|
|
replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
|
2018-10-31 23:06:12 +01:00
|
|
|
if (!replacement->sanitize (&c->sanitizer) || !*replacement)
|
2018-10-31 07:33:30 +01:00
|
|
|
replacement = nullptr;
|
|
|
|
}
|
|
|
|
if (replacement)
|
|
|
|
{
|
2019-05-08 05:54:31 +02:00
|
|
|
buffer->unsafe_to_break (mark, hb_min (buffer->idx + 1, buffer->len));
|
2018-10-31 07:33:30 +01:00
|
|
|
buffer->info[mark].codepoint = *replacement;
|
2021-05-05 12:11:43 +02:00
|
|
|
if (has_glyph_classes)
|
|
|
|
_hb_glyph_info_set_glyph_props (&buffer->info[mark],
|
|
|
|
gdef.get_glyph_props (*replacement));
|
2018-10-31 07:33:30 +01:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
replacement = nullptr;
|
2019-05-08 05:54:31 +02:00
|
|
|
unsigned int idx = hb_min (buffer->idx, buffer->len - 1);
|
2018-10-31 07:33:30 +01:00
|
|
|
if (Types::extended)
|
2018-01-11 15:15:07 +01:00
|
|
|
{
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.data.currentIndex != 0xFFFF)
|
2018-01-11 15:15:07 +01:00
|
|
|
{
|
2021-09-19 22:30:12 +02:00
|
|
|
const Lookup<HBGlyphID16> &lookup = subs[entry.data.currentIndex];
|
2018-10-31 07:33:30 +01:00
|
|
|
replacement = lookup.get_value (buffer->info[idx].codepoint, driver->num_glyphs);
|
2018-01-11 15:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-31 07:33:30 +01:00
|
|
|
else
|
|
|
|
{
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int offset = entry.data.currentIndex + buffer->info[idx].codepoint;
|
2021-09-19 22:30:12 +02:00
|
|
|
const UnsizedArrayOf<HBGlyphID16> &subs_old = (const UnsizedArrayOf<HBGlyphID16> &) subs;
|
2018-10-31 23:09:09 +01:00
|
|
|
replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
|
2018-10-31 23:06:12 +01:00
|
|
|
if (!replacement->sanitize (&c->sanitizer) || !*replacement)
|
2018-10-31 07:33:30 +01:00
|
|
|
replacement = nullptr;
|
|
|
|
}
|
|
|
|
if (replacement)
|
|
|
|
{
|
|
|
|
buffer->info[idx].codepoint = *replacement;
|
2021-05-05 12:11:43 +02:00
|
|
|
if (has_glyph_classes)
|
|
|
|
_hb_glyph_info_set_glyph_props (&buffer->info[idx],
|
|
|
|
gdef.get_glyph_props (*replacement));
|
2018-10-31 07:33:30 +01:00
|
|
|
ret = true;
|
|
|
|
}
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.flags & SetMark)
|
2018-02-02 22:08:50 +01:00
|
|
|
{
|
2018-02-04 20:45:02 +01:00
|
|
|
mark_set = true;
|
2018-02-02 22:08:50 +01:00
|
|
|
mark = buffer->idx;
|
|
|
|
}
|
2018-01-12 00:01:36 +01:00
|
|
|
}
|
2018-01-11 15:15:07 +01:00
|
|
|
|
2018-01-12 00:01:36 +01:00
|
|
|
public:
|
|
|
|
bool ret;
|
|
|
|
private:
|
2018-10-31 07:33:30 +01:00
|
|
|
hb_aat_apply_context_t *c;
|
2021-05-05 12:11:43 +02:00
|
|
|
const OT::GDEF &gdef;
|
2018-02-04 20:45:02 +01:00
|
|
|
bool mark_set;
|
2021-05-05 12:11:43 +02:00
|
|
|
bool has_glyph_classes;
|
2018-01-12 00:01:36 +01:00
|
|
|
unsigned int mark;
|
2018-10-31 07:33:30 +01:00
|
|
|
const ContextualSubtable *table;
|
2021-09-19 22:30:12 +02:00
|
|
|
const UnsizedListOfOffset16To<Lookup<HBGlyphID16>, HBUINT, false> &subs;
|
2018-01-12 00:01:36 +01:00
|
|
|
};
|
2018-01-11 15:15:07 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-01-12 00:01:36 +01:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
2018-01-11 15:15:07 +01:00
|
|
|
|
2018-10-31 07:33:30 +01:00
|
|
|
driver_context_t dc (this, c);
|
2018-01-12 00:01:36 +01:00
|
|
|
|
2018-10-31 03:22:43 +01:00
|
|
|
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->face);
|
2023-01-10 05:32:15 +01:00
|
|
|
driver.drive (&dc, c);
|
2018-01-12 00:01:36 +01:00
|
|
|
|
|
|
|
return_trace (dc.ret);
|
2018-01-09 17:55:17 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-11 18:54:49 +01:00
|
|
|
|
2018-02-07 18:26:41 +01:00
|
|
|
unsigned int num_entries = 0;
|
2018-02-08 22:11:28 +01:00
|
|
|
if (unlikely (!machine.sanitize (c, &num_entries))) return_trace (false);
|
2018-01-11 18:54:49 +01:00
|
|
|
|
2019-01-14 21:09:14 +01:00
|
|
|
if (!Types::extended)
|
|
|
|
return_trace (substitutionTables.sanitize (c, this, 0));
|
2018-10-31 07:33:30 +01:00
|
|
|
|
2018-01-11 18:54:49 +01:00
|
|
|
unsigned int num_lookups = 0;
|
|
|
|
|
|
|
|
const Entry<EntryData> *entries = machine.get_entries ();
|
|
|
|
for (unsigned int i = 0; i < num_entries; i++)
|
|
|
|
{
|
|
|
|
const EntryData &data = entries[i].data;
|
|
|
|
|
2018-02-02 21:53:25 +01:00
|
|
|
if (data.markIndex != 0xFFFF)
|
Narrow down cast operators on IntType
Say for USHORT, we were implementing casts from and to unsigned.
With this change, we cast from and to uint16_t only. This allows
compiler more opportunities to catch possible narrowing issues in
the code.
It needed a couple of fixes in the codebase though, because
previously, if a USHORT was participating in arithmetic with signed
numbers, eg. "u + 1", the result would have been unsigned. With
this change, it would be signed. The correct fix is to update the
code to read "u + 1u".
That said, I think about conditionally adding back the cast
out to signed/unsigned, to facilitate better type deduction.
But I couldn't think of a real situation where that would help
with anything. So I didn't add. Here's what it was:
template <typename Type2 = hb_conditional<hb_is_signed (Type), signed, unsigned>,
hb_enable_if (sizeof (Type) < sizeof (Type2))>
operator hb_type_identity_t<Type2> () const { return v; }
https://github.com/harfbuzz/harfbuzz/pull/2875
2021-02-23 06:09:15 +01:00
|
|
|
num_lookups = hb_max (num_lookups, 1u + data.markIndex);
|
2018-02-02 21:53:25 +01:00
|
|
|
if (data.currentIndex != 0xFFFF)
|
Narrow down cast operators on IntType
Say for USHORT, we were implementing casts from and to unsigned.
With this change, we cast from and to uint16_t only. This allows
compiler more opportunities to catch possible narrowing issues in
the code.
It needed a couple of fixes in the codebase though, because
previously, if a USHORT was participating in arithmetic with signed
numbers, eg. "u + 1", the result would have been unsigned. With
this change, it would be signed. The correct fix is to update the
code to read "u + 1u".
That said, I think about conditionally adding back the cast
out to signed/unsigned, to facilitate better type deduction.
But I couldn't think of a real situation where that would help
with anything. So I didn't add. Here's what it was:
template <typename Type2 = hb_conditional<hb_is_signed (Type), signed, unsigned>,
hb_enable_if (sizeof (Type) < sizeof (Type2))>
operator hb_type_identity_t<Type2> () const { return v; }
https://github.com/harfbuzz/harfbuzz/pull/2875
2021-02-23 06:09:15 +01:00
|
|
|
num_lookups = hb_max (num_lookups, 1u + data.currentIndex);
|
2018-01-11 18:54:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return_trace (substitutionTables.sanitize (c, this, num_lookups));
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
2018-01-11 14:50:47 +01:00
|
|
|
|
|
|
|
protected:
|
2018-10-30 16:11:34 +01:00
|
|
|
StateTable<Types, EntryData>
|
2018-04-11 16:06:09 +02:00
|
|
|
machine;
|
2021-09-19 22:30:12 +02:00
|
|
|
NNOffsetTo<UnsizedListOfOffset16To<Lookup<HBGlyphID16>, HBUINT, false>, HBUINT>
|
2018-04-11 16:06:09 +02:00
|
|
|
substitutionTables;
|
2018-01-11 14:50:47 +01:00
|
|
|
public:
|
2018-01-12 12:04:53 +01:00
|
|
|
DEFINE_SIZE_STATIC (20);
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
|
2018-10-31 08:15:00 +01:00
|
|
|
template <bool extended>
|
|
|
|
struct LigatureEntry;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct LigatureEntry<true>
|
|
|
|
{
|
2018-10-31 08:36:03 +01:00
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
SetComponent = 0x8000, /* Push this glyph onto the component stack for
|
|
|
|
* eventual processing. */
|
|
|
|
DontAdvance = 0x4000, /* Leave the glyph pointer at this glyph for the
|
|
|
|
next iteration. */
|
|
|
|
PerformAction = 0x2000, /* Use the ligActionIndex to process a ligature
|
|
|
|
* group. */
|
|
|
|
Reserved = 0x1FFF, /* These bits are reserved and should be set to 0. */
|
|
|
|
};
|
|
|
|
|
2018-11-07 16:58:50 +01:00
|
|
|
struct EntryData
|
2018-01-14 21:03:31 +01:00
|
|
|
{
|
|
|
|
HBUINT16 ligActionIndex; /* Index to the first ligActionTable entry
|
|
|
|
* for processing this group, if indicated
|
|
|
|
* by the flags. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (2);
|
2018-11-07 16:58:50 +01:00
|
|
|
};
|
2018-10-31 08:15:00 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static bool performAction (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.flags & PerformAction; }
|
2018-10-31 08:36:03 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static unsigned int ligActionIndex (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.data.ligActionIndex; }
|
2018-10-31 08:15:00 +01:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct LigatureEntry<false>
|
|
|
|
{
|
2018-10-31 08:36:03 +01:00
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
SetComponent = 0x8000, /* Push this glyph onto the component stack for
|
|
|
|
* eventual processing. */
|
|
|
|
DontAdvance = 0x4000, /* Leave the glyph pointer at this glyph for the
|
|
|
|
next iteration. */
|
|
|
|
Offset = 0x3FFF, /* Byte offset from beginning of subtable to the
|
|
|
|
* ligature action list. This value must be a
|
|
|
|
* multiple of 4. */
|
|
|
|
};
|
|
|
|
|
2018-10-31 08:15:00 +01:00
|
|
|
typedef void EntryData;
|
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static bool performAction (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.flags & Offset; }
|
2018-10-31 08:36:03 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static unsigned int ligActionIndex (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.flags & Offset; }
|
2018-10-31 08:15:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Types>
|
|
|
|
struct LigatureSubtable
|
|
|
|
{
|
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2018-10-31 08:36:03 +01:00
|
|
|
typedef LigatureEntry<Types::extended> LigatureEntryT;
|
|
|
|
typedef typename LigatureEntryT::EntryData EntryData;
|
2018-01-14 21:03:31 +01:00
|
|
|
|
|
|
|
struct driver_context_t
|
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool in_place = false;
|
2018-10-31 08:36:03 +01:00
|
|
|
enum
|
2018-09-15 14:47:18 +02:00
|
|
|
{
|
2018-10-31 11:50:14 +01:00
|
|
|
DontAdvance = LigatureEntryT::DontAdvance,
|
2018-01-14 21:03:31 +01:00
|
|
|
};
|
2018-09-15 14:47:18 +02:00
|
|
|
enum LigActionFlags
|
|
|
|
{
|
2018-01-20 03:08:56 +01:00
|
|
|
LigActionLast = 0x80000000, /* This is the last action in the list. This also
|
|
|
|
* implies storage. */
|
|
|
|
LigActionStore = 0x40000000, /* Store the ligature at the current cumulated index
|
|
|
|
* in the ligature table in place of the marked
|
|
|
|
* (i.e. currently-popped) glyph. */
|
|
|
|
LigActionOffset = 0x3FFFFFFF, /* A 30-bit value which is sign-extended to 32-bits
|
|
|
|
* and added to the glyph ID, resulting in an index
|
|
|
|
* into the component table. */
|
|
|
|
};
|
2018-01-14 21:03:31 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
driver_context_t (const LigatureSubtable *table_,
|
|
|
|
hb_aat_apply_context_t *c_) :
|
2018-01-20 03:08:56 +01:00
|
|
|
ret (false),
|
|
|
|
c (c_),
|
2018-10-31 09:16:33 +01:00
|
|
|
table (table_),
|
2018-01-20 03:08:56 +01:00
|
|
|
ligAction (table+table->ligAction),
|
|
|
|
component (table+table->component),
|
|
|
|
ligature (table+table->ligature),
|
|
|
|
match_length (0) {}
|
2018-01-14 21:03:31 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool is_actionable (StateTableDriver<Types, EntryData> *driver HB_UNUSED,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-02-04 20:58:02 +01:00
|
|
|
{
|
2018-11-07 17:05:28 +01:00
|
|
|
return LigatureEntryT::performAction (entry);
|
2018-02-04 20:58:02 +01:00
|
|
|
}
|
2019-01-24 18:01:07 +01:00
|
|
|
void transition (StateTableDriver<Types, EntryData> *driver,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-01-14 21:03:31 +01:00
|
|
|
{
|
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2018-11-07 23:29:37 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Ligature transition at %u", buffer->idx);
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.flags & LigatureEntryT::SetComponent)
|
2018-01-20 03:08:56 +01:00
|
|
|
{
|
|
|
|
/* Never mark same index twice, in case DontAdvance was used... */
|
2019-01-24 18:12:25 +01:00
|
|
|
if (match_length && match_positions[(match_length - 1u) % ARRAY_LENGTH (match_positions)] == buffer->out_len)
|
2018-01-20 03:08:56 +01:00
|
|
|
match_length--;
|
|
|
|
|
2019-01-24 18:12:25 +01:00
|
|
|
match_positions[match_length++ % ARRAY_LENGTH (match_positions)] = buffer->out_len;
|
2018-11-07 23:29:37 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Set component at %u", buffer->out_len);
|
2018-01-20 03:08:56 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 17:05:28 +01:00
|
|
|
if (LigatureEntryT::performAction (entry))
|
2018-01-20 03:08:56 +01:00
|
|
|
{
|
2018-11-07 23:29:37 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Perform action with %u", match_length);
|
2018-01-20 03:08:56 +01:00
|
|
|
unsigned int end = buffer->out_len;
|
2018-10-15 20:04:49 +02:00
|
|
|
|
|
|
|
if (unlikely (!match_length))
|
2019-01-24 18:01:07 +01:00
|
|
|
return;
|
2018-10-15 20:04:49 +02:00
|
|
|
|
2018-10-27 06:59:20 +02:00
|
|
|
if (buffer->idx >= buffer->len)
|
2019-01-24 18:06:17 +01:00
|
|
|
return; /* TODO Work on previous instead? */
|
2018-10-27 06:59:20 +02:00
|
|
|
|
2018-10-16 23:46:07 +02:00
|
|
|
unsigned int cursor = match_length;
|
2018-11-07 17:20:14 +01:00
|
|
|
|
|
|
|
unsigned int action_idx = LigatureEntryT::ligActionIndex (entry);
|
2018-10-31 23:09:09 +01:00
|
|
|
action_idx = Types::offsetToIndex (action_idx, table, ligAction.arrayZ);
|
2018-10-31 22:59:14 +01:00
|
|
|
const HBUINT32 *actionData = &ligAction[action_idx];
|
2018-11-07 17:20:14 +01:00
|
|
|
|
|
|
|
unsigned int ligature_idx = 0;
|
|
|
|
unsigned int action;
|
2019-08-24 15:27:14 +02:00
|
|
|
do
|
2018-01-20 03:08:56 +01:00
|
|
|
{
|
2018-10-16 23:46:07 +02:00
|
|
|
if (unlikely (!cursor))
|
2018-10-23 09:39:44 +02:00
|
|
|
{
|
|
|
|
/* Stack underflow. Clear the stack. */
|
2018-10-23 10:32:08 +02:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Stack underflow");
|
2018-10-23 09:39:44 +02:00
|
|
|
match_length = 0;
|
2018-10-16 23:46:07 +02:00
|
|
|
break;
|
2018-10-23 09:39:44 +02:00
|
|
|
}
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2018-11-07 23:29:37 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Moving to stack position %u", cursor - 1);
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to (match_positions[--cursor % ARRAY_LENGTH (match_positions)]))) return;
|
2018-01-14 21:03:31 +01:00
|
|
|
|
2019-01-24 18:01:07 +01:00
|
|
|
if (unlikely (!actionData->sanitize (&c->sanitizer))) break;
|
2018-10-31 09:16:33 +01:00
|
|
|
action = *actionData;
|
2018-01-20 03:08:56 +01:00
|
|
|
|
|
|
|
uint32_t uoffset = action & LigActionOffset;
|
|
|
|
if (uoffset & 0x20000000)
|
2018-10-16 22:57:35 +02:00
|
|
|
uoffset |= 0xC0000000; /* Sign-extend. */
|
2018-01-20 03:08:56 +01:00
|
|
|
int32_t offset = (int32_t) uoffset;
|
|
|
|
unsigned int component_idx = buffer->cur().codepoint + offset;
|
2018-10-31 23:09:09 +01:00
|
|
|
component_idx = Types::wordOffsetToIndex (component_idx, table, component.arrayZ);
|
2018-10-31 22:59:14 +01:00
|
|
|
const HBUINT16 &componentData = component[component_idx];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (unlikely (!componentData.sanitize (&c->sanitizer))) break;
|
2018-01-20 03:08:56 +01:00
|
|
|
ligature_idx += componentData;
|
|
|
|
|
2023-01-13 01:04:24 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Action store %d last %d",
|
2018-10-23 10:32:08 +02:00
|
|
|
bool (action & LigActionStore),
|
|
|
|
bool (action & LigActionLast));
|
2018-01-20 03:08:56 +01:00
|
|
|
if (action & (LigActionStore | LigActionLast))
|
|
|
|
{
|
2018-10-31 23:09:09 +01:00
|
|
|
ligature_idx = Types::offsetToIndex (ligature_idx, table, ligature.arrayZ);
|
2021-09-19 22:30:12 +02:00
|
|
|
const HBGlyphID16 &ligatureData = ligature[ligature_idx];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (unlikely (!ligatureData.sanitize (&c->sanitizer))) break;
|
2018-01-20 03:08:56 +01:00
|
|
|
hb_codepoint_t lig = ligatureData;
|
|
|
|
|
2018-11-07 23:29:37 +01:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Produced ligature %u", lig);
|
2021-03-15 20:33:44 +01:00
|
|
|
if (unlikely (!buffer->replace_glyph (lig))) return;
|
2018-01-20 03:08:56 +01:00
|
|
|
|
2019-01-24 18:16:17 +01:00
|
|
|
unsigned int lig_end = match_positions[(match_length - 1u) % ARRAY_LENGTH (match_positions)] + 1u;
|
2018-10-16 23:46:07 +02:00
|
|
|
/* Now go and delete all subsequent components. */
|
2019-01-24 18:16:17 +01:00
|
|
|
while (match_length - 1u > cursor)
|
2018-10-16 23:46:07 +02:00
|
|
|
{
|
2018-10-23 10:32:08 +02:00
|
|
|
DEBUG_MSG (APPLY, nullptr, "Skipping ligature component");
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to (match_positions[--match_length % ARRAY_LENGTH (match_positions)]))) return;
|
2021-03-15 20:33:44 +01:00
|
|
|
if (unlikely (!buffer->replace_glyph (DELETED_GLYPH))) return;
|
2018-10-16 23:46:07 +02:00
|
|
|
}
|
2018-10-24 01:46:10 +02:00
|
|
|
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to (lig_end))) return;
|
2019-01-24 18:12:25 +01:00
|
|
|
buffer->merge_out_clusters (match_positions[cursor % ARRAY_LENGTH (match_positions)], buffer->out_len);
|
2018-01-20 03:08:56 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 09:16:33 +01:00
|
|
|
actionData++;
|
2018-01-20 03:08:56 +01:00
|
|
|
}
|
|
|
|
while (!(action & LigActionLast));
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to (end))) return;
|
2018-01-20 03:08:56 +01:00
|
|
|
}
|
2018-01-14 21:03:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool ret;
|
|
|
|
private:
|
2018-01-20 03:08:56 +01:00
|
|
|
hb_aat_apply_context_t *c;
|
2018-10-31 09:16:33 +01:00
|
|
|
const LigatureSubtable *table;
|
2018-01-20 03:08:56 +01:00
|
|
|
const UnsizedArrayOf<HBUINT32> &ligAction;
|
|
|
|
const UnsizedArrayOf<HBUINT16> &component;
|
2021-09-19 22:30:12 +02:00
|
|
|
const UnsizedArrayOf<HBGlyphID16> &ligature;
|
2018-01-20 03:08:56 +01:00
|
|
|
unsigned int match_length;
|
|
|
|
unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
|
2018-01-14 21:03:31 +01:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
2018-01-14 21:03:31 +01:00
|
|
|
|
2018-01-20 03:08:56 +01:00
|
|
|
driver_context_t dc (this, c);
|
2018-01-14 21:03:31 +01:00
|
|
|
|
2018-10-31 03:22:43 +01:00
|
|
|
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->face);
|
2023-01-10 05:32:15 +01:00
|
|
|
driver.drive (&dc, c);
|
2018-01-14 21:03:31 +01:00
|
|
|
|
|
|
|
return_trace (dc.ret);
|
2018-01-09 17:55:17 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-20 03:08:56 +01:00
|
|
|
/* The rest of array sanitizations are done at run-time. */
|
2018-02-08 22:11:28 +01:00
|
|
|
return_trace (c->check_struct (this) && machine.sanitize (c) &&
|
|
|
|
ligAction && component && ligature);
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
2018-01-14 21:03:31 +01:00
|
|
|
|
|
|
|
protected:
|
2018-10-30 16:11:34 +01:00
|
|
|
StateTable<Types, EntryData>
|
2018-04-11 16:06:09 +02:00
|
|
|
machine;
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<UnsizedArrayOf<HBUINT32>, HBUINT>
|
2018-01-14 21:03:31 +01:00
|
|
|
ligAction; /* Offset to the ligature action table. */
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<UnsizedArrayOf<HBUINT16>, HBUINT>
|
2018-01-14 21:03:31 +01:00
|
|
|
component; /* Offset to the component table. */
|
2021-09-19 22:30:12 +02:00
|
|
|
NNOffsetTo<UnsizedArrayOf<HBGlyphID16>, HBUINT>
|
2018-01-14 21:03:31 +01:00
|
|
|
ligature; /* Offset to the actual ligature lists. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (28);
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types>
|
2017-08-15 02:24:36 +02:00
|
|
|
struct NoncontextualSubtable
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2021-05-05 12:11:43 +02:00
|
|
|
const OT::GDEF &gdef (*c->gdef_table);
|
|
|
|
bool has_glyph_classes = gdef.has_glyph_classes ();
|
|
|
|
|
2018-01-09 17:55:17 +01:00
|
|
|
bool ret = false;
|
2018-01-11 09:15:34 +01:00
|
|
|
unsigned int num_glyphs = c->face->get_num_glyphs ();
|
|
|
|
|
|
|
|
hb_glyph_info_t *info = c->buffer->info;
|
|
|
|
unsigned int count = c->buffer->len;
|
2023-01-10 20:16:04 +01:00
|
|
|
// If there's only one range, we already checked the flag.
|
|
|
|
auto *last_range = c->range_flags && (c->range_flags->length > 1) ? &(*c->range_flags)[0] : nullptr;
|
2018-01-09 17:55:17 +01:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2023-01-10 20:17:38 +01:00
|
|
|
/* This block copied from StateTableDriver::drive. Keep in sync. */
|
2023-01-10 18:53:21 +01:00
|
|
|
if (last_range)
|
|
|
|
{
|
|
|
|
auto *range = last_range;
|
|
|
|
{
|
|
|
|
unsigned cluster = info[i].cluster;
|
|
|
|
while (cluster < range->cluster_first)
|
|
|
|
range--;
|
|
|
|
while (cluster > range->cluster_last)
|
|
|
|
range++;
|
|
|
|
|
|
|
|
last_range = range;
|
|
|
|
}
|
|
|
|
if (!(range->flags & c->subtable_flags))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-19 22:30:12 +02:00
|
|
|
const HBGlyphID16 *replacement = substitute.get_value (info[i].codepoint, num_glyphs);
|
2018-01-09 17:55:17 +01:00
|
|
|
if (replacement)
|
|
|
|
{
|
|
|
|
info[i].codepoint = *replacement;
|
2021-05-05 12:11:43 +02:00
|
|
|
if (has_glyph_classes)
|
|
|
|
_hb_glyph_info_set_glyph_props (&info[i],
|
|
|
|
gdef.get_glyph_props (*replacement));
|
2018-01-09 17:55:17 +01:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
2018-01-11 09:15:34 +01:00
|
|
|
|
2018-01-09 17:55:17 +01:00
|
|
|
return_trace (ret);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-01-09 15:48:51 +01:00
|
|
|
return_trace (substitute.sanitize (c));
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
2018-01-09 15:48:51 +01:00
|
|
|
|
|
|
|
protected:
|
2021-09-19 22:30:12 +02:00
|
|
|
Lookup<HBGlyphID16> substitute;
|
2018-01-09 15:48:51 +01:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_MIN (2);
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types>
|
2017-08-15 02:24:36 +02:00
|
|
|
struct InsertionSubtable
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2018-09-15 14:47:18 +02:00
|
|
|
struct EntryData
|
|
|
|
{
|
|
|
|
HBUINT16 currentInsertIndex; /* Zero-based index into the insertion glyph table.
|
|
|
|
* The number of glyphs to be inserted is contained
|
|
|
|
* in the currentInsertCount field in the flags.
|
|
|
|
* A value of 0xFFFF indicates no insertion is to
|
|
|
|
* be done. */
|
|
|
|
HBUINT16 markedInsertIndex; /* Zero-based index into the insertion glyph table.
|
|
|
|
* The number of glyphs to be inserted is contained
|
|
|
|
* in the markedInsertCount field in the flags.
|
|
|
|
* A value of 0xFFFF indicates no insertion is to
|
|
|
|
* be done. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct driver_context_t
|
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool in_place = false;
|
2018-09-15 14:47:18 +02:00
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
SetMark = 0x8000, /* If set, mark the current glyph. */
|
|
|
|
DontAdvance = 0x4000, /* If set, don't advance to the next glyph before
|
|
|
|
* going to the new state. This does not mean
|
|
|
|
* that the glyph pointed to is the same one as
|
|
|
|
* before. If you've made insertions immediately
|
|
|
|
* downstream of the current glyph, the next glyph
|
|
|
|
* processed would in fact be the first one
|
|
|
|
* inserted. */
|
|
|
|
CurrentIsKashidaLike= 0x2000, /* If set, and the currentInsertList is nonzero,
|
|
|
|
* then the specified glyph list will be inserted
|
|
|
|
* as a kashida-like insertion, either before or
|
|
|
|
* after the current glyph (depending on the state
|
|
|
|
* of the currentInsertBefore flag). If clear, and
|
|
|
|
* the currentInsertList is nonzero, then the
|
|
|
|
* specified glyph list will be inserted as a
|
|
|
|
* split-vowel-like insertion, either before or
|
|
|
|
* after the current glyph (depending on the state
|
|
|
|
* of the currentInsertBefore flag). */
|
|
|
|
MarkedIsKashidaLike= 0x1000, /* If set, and the markedInsertList is nonzero,
|
|
|
|
* then the specified glyph list will be inserted
|
|
|
|
* as a kashida-like insertion, either before or
|
|
|
|
* after the marked glyph (depending on the state
|
|
|
|
* of the markedInsertBefore flag). If clear, and
|
|
|
|
* the markedInsertList is nonzero, then the
|
|
|
|
* specified glyph list will be inserted as a
|
|
|
|
* split-vowel-like insertion, either before or
|
|
|
|
* after the marked glyph (depending on the state
|
|
|
|
* of the markedInsertBefore flag). */
|
|
|
|
CurrentInsertBefore= 0x0800, /* If set, specifies that insertions are to be made
|
|
|
|
* to the left of the current glyph. If clear,
|
|
|
|
* they're made to the right of the current glyph. */
|
|
|
|
MarkedInsertBefore= 0x0400, /* If set, specifies that insertions are to be
|
|
|
|
* made to the left of the marked glyph. If clear,
|
|
|
|
* they're made to the right of the marked glyph. */
|
|
|
|
CurrentInsertCount= 0x3E0, /* This 5-bit field is treated as a count of the
|
|
|
|
* number of glyphs to insert at the current
|
|
|
|
* position. Since zero means no insertions, the
|
|
|
|
* largest number of insertions at any given
|
|
|
|
* current location is 31 glyphs. */
|
|
|
|
MarkedInsertCount= 0x001F, /* This 5-bit field is treated as a count of the
|
|
|
|
* number of glyphs to insert at the marked
|
|
|
|
* position. Since zero means no insertions, the
|
|
|
|
* largest number of insertions at any given
|
|
|
|
* marked location is 31 glyphs. */
|
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
driver_context_t (const InsertionSubtable *table,
|
|
|
|
hb_aat_apply_context_t *c_) :
|
2018-09-15 14:47:18 +02:00
|
|
|
ret (false),
|
|
|
|
c (c_),
|
|
|
|
mark (0),
|
|
|
|
insertionAction (table+table->insertionAction) {}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool is_actionable (StateTableDriver<Types, EntryData> *driver HB_UNUSED,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-09-15 14:47:18 +02:00
|
|
|
{
|
2019-01-24 17:21:41 +01:00
|
|
|
return (entry.flags & (CurrentInsertCount | MarkedInsertCount)) &&
|
|
|
|
(entry.data.currentInsertIndex != 0xFFFF ||entry.data.markedInsertIndex != 0xFFFF);
|
2018-09-15 14:47:18 +02:00
|
|
|
}
|
2019-01-24 18:01:07 +01:00
|
|
|
void transition (StateTableDriver<Types, EntryData> *driver,
|
2019-01-24 17:21:41 +01:00
|
|
|
const Entry<EntryData> &entry)
|
2018-09-15 14:47:18 +02:00
|
|
|
{
|
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int flags = entry.flags;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2019-01-23 20:53:57 +01:00
|
|
|
unsigned mark_loc = buffer->out_len;
|
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.data.markedInsertIndex != 0xFFFF)
|
2018-09-15 14:47:18 +02:00
|
|
|
{
|
2018-09-19 22:02:56 +02:00
|
|
|
unsigned int count = (flags & MarkedInsertCount);
|
2020-07-14 12:47:17 +02:00
|
|
|
if (unlikely ((buffer->max_ops -= count) <= 0)) return;
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int start = entry.data.markedInsertIndex;
|
2021-09-19 22:30:12 +02:00
|
|
|
const HBGlyphID16 *glyphs = &insertionAction[start];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (unlikely (!c->sanitizer.check_array (glyphs, count))) count = 0;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2018-09-19 22:02:56 +02:00
|
|
|
bool before = flags & MarkedInsertBefore;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
|
|
|
unsigned int end = buffer->out_len;
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to (mark))) return;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2018-10-15 04:39:31 +02:00
|
|
|
if (buffer->idx < buffer->len && !before)
|
2021-03-15 21:10:39 +01:00
|
|
|
if (unlikely (!buffer->copy_glyph ())) return;
|
2018-09-17 19:29:34 +02:00
|
|
|
/* TODO We ignore KashidaLike setting. */
|
2021-03-15 21:39:06 +01:00
|
|
|
if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return;
|
2018-10-15 04:39:31 +02:00
|
|
|
if (buffer->idx < buffer->len && !before)
|
2018-09-17 19:29:34 +02:00
|
|
|
buffer->skip_glyph ();
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to (end + count))) return;
|
2018-09-28 16:00:07 +02:00
|
|
|
|
2019-05-08 05:54:31 +02:00
|
|
|
buffer->unsafe_to_break_from_outbuffer (mark, hb_min (buffer->idx + 1, buffer->len));
|
2018-09-17 19:29:34 +02:00
|
|
|
}
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2019-01-23 20:53:57 +01:00
|
|
|
if (flags & SetMark)
|
|
|
|
mark = mark_loc;
|
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.data.currentInsertIndex != 0xFFFF)
|
2018-09-17 19:29:34 +02:00
|
|
|
{
|
2018-09-19 22:02:56 +02:00
|
|
|
unsigned int count = (flags & CurrentInsertCount) >> 5;
|
2020-07-14 12:47:17 +02:00
|
|
|
if (unlikely ((buffer->max_ops -= count) <= 0)) return;
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int start = entry.data.currentInsertIndex;
|
2021-09-19 22:30:12 +02:00
|
|
|
const HBGlyphID16 *glyphs = &insertionAction[start];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (unlikely (!c->sanitizer.check_array (glyphs, count))) count = 0;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2018-09-19 22:02:56 +02:00
|
|
|
bool before = flags & CurrentInsertBefore;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2018-09-17 19:29:34 +02:00
|
|
|
unsigned int end = buffer->out_len;
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2018-10-15 04:39:31 +02:00
|
|
|
if (buffer->idx < buffer->len && !before)
|
2021-03-15 21:10:39 +01:00
|
|
|
if (unlikely (!buffer->copy_glyph ())) return;
|
2018-09-17 19:29:34 +02:00
|
|
|
/* TODO We ignore KashidaLike setting. */
|
2021-03-15 21:39:06 +01:00
|
|
|
if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return;
|
2018-10-15 04:39:31 +02:00
|
|
|
if (buffer->idx < buffer->len && !before)
|
2018-09-17 19:29:34 +02:00
|
|
|
buffer->skip_glyph ();
|
2018-09-15 14:47:18 +02:00
|
|
|
|
2018-09-19 22:02:56 +02:00
|
|
|
/* Humm. Not sure where to move to. There's this wording under
|
|
|
|
* DontAdvance flag:
|
|
|
|
*
|
|
|
|
* "If set, don't update the glyph index before going to the new state.
|
|
|
|
* This does not mean that the glyph pointed to is the same one as
|
|
|
|
* before. If you've made insertions immediately downstream of the
|
|
|
|
* current glyph, the next glyph processed would in fact be the first
|
|
|
|
* one inserted."
|
|
|
|
*
|
2018-10-08 02:36:46 +02:00
|
|
|
* This suggests that if DontAdvance is NOT set, we should move to
|
|
|
|
* end+count. If it *was*, then move to end, such that newly inserted
|
|
|
|
* glyphs are now visible.
|
2018-10-08 00:06:53 +02:00
|
|
|
*
|
2018-10-08 02:36:46 +02:00
|
|
|
* https://github.com/harfbuzz/harfbuzz/issues/1224#issuecomment-427691417
|
2018-09-19 22:02:56 +02:00
|
|
|
*/
|
2021-03-15 20:46:54 +01:00
|
|
|
if (unlikely (!buffer->move_to ((flags & DontAdvance) ? end : end + count))) return;
|
2018-09-15 14:47:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool ret;
|
|
|
|
private:
|
|
|
|
hb_aat_apply_context_t *c;
|
|
|
|
unsigned int mark;
|
2021-09-19 22:30:12 +02:00
|
|
|
const UnsizedArrayOf<HBGlyphID16> &insertionAction;
|
2018-09-15 14:47:18 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
2018-09-15 14:47:18 +02:00
|
|
|
|
|
|
|
driver_context_t dc (this, c);
|
|
|
|
|
2018-10-31 03:22:43 +01:00
|
|
|
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->face);
|
2023-01-10 05:32:15 +01:00
|
|
|
driver.drive (&dc, c);
|
2018-09-15 14:47:18 +02:00
|
|
|
|
|
|
|
return_trace (dc.ret);
|
2018-01-09 17:55:17 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-09-15 14:47:18 +02:00
|
|
|
/* The rest of array sanitizations are done at run-time. */
|
|
|
|
return_trace (c->check_struct (this) && machine.sanitize (c) &&
|
|
|
|
insertionAction);
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
2018-09-15 14:47:18 +02:00
|
|
|
|
|
|
|
protected:
|
2018-10-30 16:11:34 +01:00
|
|
|
StateTable<Types, EntryData>
|
2018-09-15 14:47:18 +02:00
|
|
|
machine;
|
2021-09-19 22:30:12 +02:00
|
|
|
NNOffsetTo<UnsizedArrayOf<HBGlyphID16>, HBUINT>
|
2018-09-15 14:47:18 +02:00
|
|
|
insertionAction; /* Byte offset from stateHeader to the start of
|
|
|
|
* the insertion glyph table. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (20);
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Feature
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT16 featureType; /* The type of feature. */
|
|
|
|
HBUINT16 featureSetting; /* The feature's setting (aka selector). */
|
|
|
|
HBUINT32 enableFlags; /* Flags for the settings that this feature
|
2017-08-15 02:24:36 +02:00
|
|
|
* and setting enables. */
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT32 disableFlags; /* Complement of flags for the settings that this
|
2017-08-15 02:24:36 +02:00
|
|
|
* feature and setting disable. */
|
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types>
|
2017-08-15 02:24:36 +02:00
|
|
|
struct ChainSubtable
|
|
|
|
{
|
2018-10-31 03:42:21 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename T>
|
2018-01-11 22:43:57 +01:00
|
|
|
friend struct Chain;
|
2017-08-15 02:24:36 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const { return length; }
|
|
|
|
unsigned int get_type () const { return coverage & 0xFF; }
|
|
|
|
unsigned int get_coverage () const { return coverage >> (sizeof (HBUINT) * 8 - 8); }
|
2017-08-15 02:24:36 +02:00
|
|
|
|
2018-09-19 22:24:34 +02:00
|
|
|
enum Coverage
|
|
|
|
{
|
2018-10-31 03:42:21 +01:00
|
|
|
Vertical = 0x80, /* If set, this subtable will only be applied
|
|
|
|
* to vertical text. If clear, this subtable
|
|
|
|
* will only be applied to horizontal text. */
|
|
|
|
Backwards = 0x40, /* If set, this subtable will process glyphs
|
|
|
|
* in descending order. If clear, it will
|
|
|
|
* process the glyphs in ascending order. */
|
|
|
|
AllDirections = 0x20, /* If set, this subtable will be applied to
|
|
|
|
* both horizontal and vertical text (i.e.
|
|
|
|
* the state of bit 0x80000000 is ignored). */
|
|
|
|
Logical = 0x10, /* If set, this subtable will process glyphs
|
|
|
|
* in logical order (or reverse logical order,
|
|
|
|
* depending on the value of bit 0x80000000). */
|
2018-09-19 22:24:34 +02:00
|
|
|
};
|
2018-09-15 14:47:18 +02:00
|
|
|
enum Type
|
|
|
|
{
|
2017-08-15 02:24:36 +02:00
|
|
|
Rearrangement = 0,
|
|
|
|
Contextual = 1,
|
|
|
|
Ligature = 2,
|
|
|
|
Noncontextual = 4,
|
|
|
|
Insertion = 5
|
|
|
|
};
|
|
|
|
|
2019-05-05 19:14:17 +02:00
|
|
|
template <typename context_t, typename ...Ts>
|
2019-05-08 05:58:43 +02:00
|
|
|
typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
unsigned int subtable_type = get_type ();
|
|
|
|
TRACE_DISPATCH (this, subtable_type);
|
|
|
|
switch (subtable_type) {
|
2021-11-02 07:18:22 +01:00
|
|
|
case Rearrangement: return_trace (c->dispatch (u.rearrangement, std::forward<Ts> (ds)...));
|
|
|
|
case Contextual: return_trace (c->dispatch (u.contextual, std::forward<Ts> (ds)...));
|
|
|
|
case Ligature: return_trace (c->dispatch (u.ligature, std::forward<Ts> (ds)...));
|
|
|
|
case Noncontextual: return_trace (c->dispatch (u.noncontextual, std::forward<Ts> (ds)...));
|
|
|
|
case Insertion: return_trace (c->dispatch (u.insertion, std::forward<Ts> (ds)...));
|
2017-08-15 02:24:36 +02:00
|
|
|
default: return_trace (c->default_return_value ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-11-25 05:46:15 +01:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
|
|
|
hb_sanitize_with_object_t with (&c->sanitizer, this);
|
|
|
|
return_trace (dispatch (c));
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
if (!length.sanitize (c) ||
|
2018-11-23 04:02:19 +01:00
|
|
|
length <= min_size ||
|
2017-08-15 02:24:36 +02:00
|
|
|
!c->check_range (this, length))
|
|
|
|
return_trace (false);
|
|
|
|
|
2018-11-25 05:46:15 +01:00
|
|
|
hb_sanitize_with_object_t with (c, this);
|
2018-01-18 01:59:55 +01:00
|
|
|
return_trace (dispatch (c));
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-31 03:42:21 +01:00
|
|
|
HBUINT length; /* Total subtable length, including this header. */
|
|
|
|
HBUINT coverage; /* Coverage flags and subtable type. */
|
2018-01-11 22:43:57 +01:00
|
|
|
HBUINT32 subFeatureFlags;/* The 32-bit mask identifying which subtable this is. */
|
2017-08-15 02:24:36 +02:00
|
|
|
union {
|
2018-10-30 16:11:34 +01:00
|
|
|
RearrangementSubtable<Types> rearrangement;
|
|
|
|
ContextualSubtable<Types> contextual;
|
|
|
|
LigatureSubtable<Types> ligature;
|
|
|
|
NoncontextualSubtable<Types> noncontextual;
|
|
|
|
InsertionSubtable<Types> insertion;
|
2017-08-15 02:24:36 +02:00
|
|
|
} u;
|
|
|
|
public:
|
2018-10-31 03:42:21 +01:00
|
|
|
DEFINE_SIZE_MIN (2 * sizeof (HBUINT) + 4);
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
template <typename Types>
|
2017-08-15 02:24:36 +02:00
|
|
|
struct Chain
|
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2023-01-10 02:14:40 +01:00
|
|
|
hb_mask_t compile_flags (const hb_aat_map_builder_t *map) const
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
2018-10-23 23:14:03 +02:00
|
|
|
hb_mask_t flags = defaultFlags;
|
2018-09-15 18:31:14 +02:00
|
|
|
{
|
|
|
|
unsigned int count = featureCount;
|
|
|
|
for (unsigned i = 0; i < count; i++)
|
|
|
|
{
|
2018-11-01 10:44:29 +01:00
|
|
|
const Feature &feature = featureZ[i];
|
2018-11-01 19:08:54 +01:00
|
|
|
hb_aat_layout_feature_type_t type = (hb_aat_layout_feature_type_t) (unsigned int) feature.featureType;
|
2018-11-23 09:35:06 +01:00
|
|
|
hb_aat_layout_feature_selector_t setting = (hb_aat_layout_feature_selector_t) (unsigned int) feature.featureSetting;
|
2018-11-01 02:51:45 +01:00
|
|
|
retry:
|
2020-04-20 11:42:45 +02:00
|
|
|
// Check whether this type/setting pair was requested in the map, and if so, apply its flags.
|
|
|
|
// (The search here only looks at the type and setting fields of feature_info_t.)
|
2023-01-10 02:14:40 +01:00
|
|
|
hb_aat_map_builder_t::feature_info_t info = { type, setting, false, 0 };
|
2023-01-10 05:32:15 +01:00
|
|
|
if (map->current_features.bsearch (info))
|
2018-09-15 18:31:14 +02:00
|
|
|
{
|
|
|
|
flags &= feature.disableFlags;
|
|
|
|
flags |= feature.enableFlags;
|
|
|
|
}
|
2018-11-23 18:23:35 +01:00
|
|
|
else if (type == HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE && setting == HB_AAT_LAYOUT_FEATURE_SELECTOR_SMALL_CAPS)
|
2018-11-01 02:51:45 +01:00
|
|
|
{
|
|
|
|
/* Deprecated. https://github.com/harfbuzz/harfbuzz/issues/1342 */
|
2018-11-01 19:08:54 +01:00
|
|
|
type = HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE;
|
2018-11-23 18:23:35 +01:00
|
|
|
setting = HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_SMALL_CAPS;
|
2018-11-01 02:51:45 +01:00
|
|
|
goto retry;
|
|
|
|
}
|
2022-07-18 05:42:04 +02:00
|
|
|
#ifndef HB_NO_AAT
|
2022-07-18 05:32:27 +02:00
|
|
|
else if (type == HB_AAT_LAYOUT_FEATURE_TYPE_LANGUAGE_TAG_TYPE && setting &&
|
|
|
|
/* TODO: Rudimentary language matching. */
|
2022-07-18 06:15:42 +02:00
|
|
|
hb_language_matches (map->face->table.ltag->get_language (setting - 1), map->props.language))
|
2022-07-18 05:32:27 +02:00
|
|
|
{
|
|
|
|
flags &= feature.disableFlags;
|
|
|
|
flags |= feature.enableFlags;
|
|
|
|
}
|
2022-07-18 05:42:04 +02:00
|
|
|
#endif
|
2018-09-15 18:31:14 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-10 02:14:40 +01:00
|
|
|
return flags;
|
2018-10-23 23:14:03 +02:00
|
|
|
}
|
2018-09-15 18:31:14 +02:00
|
|
|
|
2023-01-10 05:32:15 +01:00
|
|
|
void apply (hb_aat_apply_context_t *c) const
|
2018-10-23 23:14:03 +02:00
|
|
|
{
|
2019-04-30 22:05:10 +02:00
|
|
|
const ChainSubtable<Types> *subtable = &StructAfter<ChainSubtable<Types>> (featureZ.as_array (featureCount));
|
2018-01-09 17:55:17 +01:00
|
|
|
unsigned int count = subtableCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2018-09-19 22:46:41 +02:00
|
|
|
bool reverse;
|
|
|
|
|
2023-01-10 21:31:58 +01:00
|
|
|
if (hb_none (hb_iter (c->range_flags) |
|
|
|
|
hb_map ([&subtable] (const hb_aat_map_t::range_flags_t _) -> bool { return subtable->subFeatureFlags & (_.flags); })))
|
2023-01-10 01:28:52 +01:00
|
|
|
goto skip;
|
2023-01-10 05:32:15 +01:00
|
|
|
c->subtable_flags = subtable->subFeatureFlags;
|
2018-09-15 18:31:14 +02:00
|
|
|
|
2018-10-31 03:42:21 +01:00
|
|
|
if (!(subtable->get_coverage() & ChainSubtable<Types>::AllDirections) &&
|
2018-09-19 22:24:34 +02:00
|
|
|
HB_DIRECTION_IS_VERTICAL (c->buffer->props.direction) !=
|
2018-10-31 03:42:21 +01:00
|
|
|
bool (subtable->get_coverage() & ChainSubtable<Types>::Vertical))
|
2019-08-24 15:27:14 +02:00
|
|
|
goto skip;
|
2018-09-19 22:24:34 +02:00
|
|
|
|
2018-09-19 22:46:41 +02:00
|
|
|
/* Buffer contents is always in logical direction. Determine if
|
|
|
|
* we need to reverse before applying this subtable. We reverse
|
|
|
|
* back after if we did reverse indeed.
|
|
|
|
*
|
|
|
|
* Quoting the spac:
|
|
|
|
* """
|
|
|
|
* Bits 28 and 30 of the coverage field control the order in which
|
|
|
|
* glyphs are processed when the subtable is run by the layout engine.
|
|
|
|
* Bit 28 is used to indicate if the glyph processing direction is
|
|
|
|
* the same as logical order or layout order. Bit 30 is used to
|
|
|
|
* indicate whether glyphs are processed forwards or backwards within
|
|
|
|
* that order.
|
|
|
|
|
|
|
|
Bit 30 Bit 28 Interpretation for Horizontal Text
|
|
|
|
0 0 The subtable is processed in layout order
|
|
|
|
(the same order as the glyphs, which is
|
|
|
|
always left-to-right).
|
|
|
|
1 0 The subtable is processed in reverse layout order
|
|
|
|
(the order opposite that of the glyphs, which is
|
|
|
|
always right-to-left).
|
|
|
|
0 1 The subtable is processed in logical order
|
|
|
|
(the same order as the characters, which may be
|
|
|
|
left-to-right or right-to-left).
|
|
|
|
1 1 The subtable is processed in reverse logical order
|
|
|
|
(the order opposite that of the characters, which
|
|
|
|
may be right-to-left or left-to-right).
|
|
|
|
*/
|
2018-10-31 03:42:21 +01:00
|
|
|
reverse = subtable->get_coverage () & ChainSubtable<Types>::Logical ?
|
|
|
|
bool (subtable->get_coverage () & ChainSubtable<Types>::Backwards) :
|
|
|
|
bool (subtable->get_coverage () & ChainSubtable<Types>::Backwards) !=
|
2018-09-19 22:46:41 +02:00
|
|
|
HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction);
|
|
|
|
|
2023-01-13 01:04:24 +01:00
|
|
|
if (!c->buffer->message (c->font, "start chainsubtable %u", c->lookup_index))
|
2019-08-24 15:27:14 +02:00
|
|
|
goto skip;
|
2018-02-10 20:35:17 +01:00
|
|
|
|
2018-09-19 22:46:41 +02:00
|
|
|
if (reverse)
|
2022-04-20 19:35:19 +02:00
|
|
|
c->buffer->reverse ();
|
2018-09-19 22:46:41 +02:00
|
|
|
|
2018-11-25 05:46:15 +01:00
|
|
|
subtable->apply (c);
|
2018-02-07 18:30:18 +01:00
|
|
|
|
2018-09-19 22:46:41 +02:00
|
|
|
if (reverse)
|
2022-04-20 19:35:19 +02:00
|
|
|
c->buffer->reverse ();
|
2018-09-19 22:46:41 +02:00
|
|
|
|
2023-01-13 01:04:24 +01:00
|
|
|
(void) c->buffer->message (c->font, "end chainsubtable %u", c->lookup_index);
|
2018-02-10 20:35:17 +01:00
|
|
|
|
2018-10-01 12:10:00 +02:00
|
|
|
if (unlikely (!c->buffer->successful)) return;
|
|
|
|
|
2018-09-15 18:31:14 +02:00
|
|
|
skip:
|
2019-04-30 22:05:10 +02:00
|
|
|
subtable = &StructAfter<ChainSubtable<Types>> (*subtable);
|
2018-02-07 18:30:18 +01:00
|
|
|
c->set_lookup_index (c->lookup_index + 1);
|
2018-01-09 17:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-15 02:24:36 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const { return length; }
|
2017-08-15 02:24:36 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, unsigned int version HB_UNUSED) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
if (!length.sanitize (c) ||
|
|
|
|
length < min_size ||
|
|
|
|
!c->check_range (this, length))
|
|
|
|
return_trace (false);
|
|
|
|
|
2018-09-10 23:29:26 +02:00
|
|
|
if (!c->check_array (featureZ.arrayZ, featureCount))
|
2017-08-15 02:24:36 +02:00
|
|
|
return_trace (false);
|
|
|
|
|
2019-04-30 22:05:10 +02:00
|
|
|
const ChainSubtable<Types> *subtable = &StructAfter<ChainSubtable<Types>> (featureZ.as_array (featureCount));
|
2017-08-15 02:24:36 +02:00
|
|
|
unsigned int count = subtableCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (!subtable->sanitize (c))
|
|
|
|
return_trace (false);
|
2019-04-30 22:05:10 +02:00
|
|
|
subtable = &StructAfter<ChainSubtable<Types>> (*subtable);
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-31 03:42:21 +01:00
|
|
|
HBUINT32 defaultFlags; /* The default specification for subtables. */
|
|
|
|
HBUINT32 length; /* Total byte count, including this header. */
|
2018-10-30 16:11:34 +01:00
|
|
|
HBUINT featureCount; /* Number of feature subtable entries. */
|
|
|
|
HBUINT subtableCount; /* The number of subtables in the chain. */
|
2017-08-15 02:24:36 +02:00
|
|
|
|
2018-09-10 23:29:26 +02:00
|
|
|
UnsizedArrayOf<Feature> featureZ; /* Features. */
|
|
|
|
/*ChainSubtable firstSubtable;*//* Subtables. */
|
2018-09-15 14:51:50 +02:00
|
|
|
/*subtableGlyphCoverageArray*/ /* Only if version >= 3. We don't use. */
|
2017-08-15 02:24:36 +02:00
|
|
|
|
|
|
|
public:
|
2018-10-31 03:42:21 +01:00
|
|
|
DEFINE_SIZE_MIN (8 + 2 * sizeof (HBUINT));
|
2017-08-15 02:24:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-10-30 16:11:34 +01:00
|
|
|
* The 'mort'/'morx' Table
|
2017-08-15 02:24:36 +02:00
|
|
|
*/
|
|
|
|
|
2019-09-08 22:34:11 +02:00
|
|
|
template <typename Types, hb_tag_t TAG>
|
2018-10-30 16:11:34 +01:00
|
|
|
struct mortmorx
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
2019-09-08 22:34:11 +02:00
|
|
|
static constexpr hb_tag_t tableTag = TAG;
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool has_data () const { return version != 0; }
|
2018-10-04 11:08:15 +02:00
|
|
|
|
2023-01-10 02:14:40 +01:00
|
|
|
void compile_flags (const hb_aat_map_builder_t *mapper,
|
|
|
|
hb_aat_map_t *map) const
|
2018-10-23 23:14:03 +02:00
|
|
|
{
|
2018-10-30 16:11:34 +01:00
|
|
|
const Chain<Types> *chain = &firstChain;
|
2018-10-23 23:14:03 +02:00
|
|
|
unsigned int count = chainCount;
|
2023-01-10 19:29:04 +01:00
|
|
|
if (unlikely (!map->chain_flags.resize (count)))
|
|
|
|
return;
|
2018-10-23 23:14:03 +02:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2023-01-10 05:32:15 +01:00
|
|
|
map->chain_flags[i].push (hb_aat_map_t::range_flags_t {chain->compile_flags (mapper),
|
|
|
|
mapper->range_first,
|
|
|
|
mapper->range_last});
|
2019-04-30 22:05:10 +02:00
|
|
|
chain = &StructAfter<Chain<Types>> (*chain);
|
2018-10-23 23:14:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-10 05:32:15 +01:00
|
|
|
void apply (hb_aat_apply_context_t *c,
|
|
|
|
const hb_aat_map_t &map) const
|
2018-01-09 17:55:17 +01:00
|
|
|
{
|
2018-10-01 12:10:00 +02:00
|
|
|
if (unlikely (!c->buffer->successful)) return;
|
2023-01-10 21:23:19 +01:00
|
|
|
|
|
|
|
c->buffer->unsafe_to_concat ();
|
|
|
|
|
2018-02-07 18:30:18 +01:00
|
|
|
c->set_lookup_index (0);
|
2018-10-30 16:11:34 +01:00
|
|
|
const Chain<Types> *chain = &firstChain;
|
2018-01-09 17:55:17 +01:00
|
|
|
unsigned int count = chainCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2023-01-10 05:32:15 +01:00
|
|
|
c->range_flags = &map.chain_flags[i];
|
|
|
|
chain->apply (c);
|
2018-10-01 12:10:00 +02:00
|
|
|
if (unlikely (!c->buffer->successful)) return;
|
2019-04-30 22:05:10 +02:00
|
|
|
chain = &StructAfter<Chain<Types>> (*chain);
|
2018-01-09 17:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2017-08-15 02:24:36 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-10-31 03:33:31 +01:00
|
|
|
if (!version.sanitize (c) || !version || !chainCount.sanitize (c))
|
2017-08-15 02:24:36 +02:00
|
|
|
return_trace (false);
|
|
|
|
|
2018-10-30 16:11:34 +01:00
|
|
|
const Chain<Types> *chain = &firstChain;
|
2017-08-15 02:24:36 +02:00
|
|
|
unsigned int count = chainCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2018-09-15 14:51:50 +02:00
|
|
|
if (!chain->sanitize (c, version))
|
2017-08-15 02:24:36 +02:00
|
|
|
return_trace (false);
|
2019-04-30 22:05:10 +02:00
|
|
|
chain = &StructAfter<Chain<Types>> (*chain);
|
2017-08-15 02:24:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-09-15 14:51:50 +02:00
|
|
|
HBUINT16 version; /* Version number of the glyph metamorphosis table.
|
2018-10-31 03:33:31 +01:00
|
|
|
* 1, 2, or 3. */
|
2018-09-15 14:51:50 +02:00
|
|
|
HBUINT16 unused; /* Set to 0. */
|
2018-01-10 03:07:30 +01:00
|
|
|
HBUINT32 chainCount; /* Number of metamorphosis chains contained in this
|
2017-08-15 02:24:36 +02:00
|
|
|
* table. */
|
2018-10-30 16:11:34 +01:00
|
|
|
Chain<Types> firstChain; /* Chains. */
|
2017-08-15 02:24:36 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_MIN (8);
|
|
|
|
};
|
|
|
|
|
2019-09-08 22:34:11 +02:00
|
|
|
struct morx : mortmorx<ExtendedTypes, HB_AAT_TAG_morx> {};
|
|
|
|
struct mort : mortmorx<ObsoleteTypes, HB_AAT_TAG_mort> {};
|
2018-10-30 16:11:34 +01:00
|
|
|
|
|
|
|
|
2017-08-15 02:24:36 +02:00
|
|
|
} /* namespace AAT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_AAT_LAYOUT_MORX_TABLE_HH */
|