2018-02-19 00:47:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Ebrahim Byagowi
|
2018-03-01 21:37:26 +01:00
|
|
|
* Copyright © 2018 Google, Inc.
|
2018-02-19 00:47:44 +01:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_AAT_LAYOUT_KERX_TABLE_HH
|
|
|
|
#define HB_AAT_LAYOUT_KERX_TABLE_HH
|
|
|
|
|
2018-11-07 16:25:25 +01:00
|
|
|
#include "hb-kern.hh"
|
2018-11-07 16:39:39 +01:00
|
|
|
#include "hb-aat-layout-ankr-table.hh"
|
2018-02-19 00:47:44 +01:00
|
|
|
|
2018-04-12 11:08:19 +02:00
|
|
|
/*
|
|
|
|
* kerx -- Extended Kerning
|
|
|
|
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kerx.html
|
|
|
|
*/
|
2018-03-26 09:34:30 +02:00
|
|
|
#define HB_AAT_TAG_kerx HB_TAG('k','e','r','x')
|
2018-02-19 00:47:44 +01:00
|
|
|
|
|
|
|
|
2018-03-01 21:37:26 +01:00
|
|
|
namespace AAT {
|
2018-02-19 00:47:44 +01:00
|
|
|
|
2018-03-01 21:37:26 +01:00
|
|
|
using namespace OT;
|
2018-02-19 00:47:44 +01:00
|
|
|
|
|
|
|
|
2018-10-20 01:06:54 +02:00
|
|
|
static inline int
|
|
|
|
kerxTupleKern (int value,
|
|
|
|
unsigned int tupleCount,
|
|
|
|
const void *base,
|
|
|
|
hb_aat_apply_context_t *c)
|
|
|
|
{
|
2018-11-24 06:35:31 +01:00
|
|
|
if (likely (!tupleCount || !c)) return value;
|
2018-10-20 01:06:54 +02:00
|
|
|
|
|
|
|
unsigned int offset = value;
|
|
|
|
const FWORD *pv = &StructAtOffset<FWORD> (base, offset);
|
2018-11-07 19:48:45 +01:00
|
|
|
if (unlikely (!c->sanitizer.check_array (pv, tupleCount))) return 0;
|
2018-10-20 01:06:54 +02:00
|
|
|
return *pv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-07 16:39:39 +01:00
|
|
|
struct hb_glyph_pair_t
|
2018-10-11 00:14:41 +02:00
|
|
|
{
|
2018-11-07 16:39:39 +01:00
|
|
|
hb_codepoint_t left;
|
|
|
|
hb_codepoint_t right;
|
|
|
|
};
|
2018-11-07 16:33:46 +01:00
|
|
|
|
2018-11-07 16:39:39 +01:00
|
|
|
struct KernPair
|
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
int get_kerning () const { return value; }
|
2018-11-07 16:39:39 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (const hb_glyph_pair_t &o) const
|
2018-11-06 20:48:42 +01:00
|
|
|
{
|
2018-11-07 16:39:39 +01:00
|
|
|
int ret = left.cmp (o.left);
|
|
|
|
if (ret) return ret;
|
|
|
|
return right.cmp (o.right);
|
|
|
|
}
|
2018-11-06 20:48:42 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-11 00:14:41 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-11-07 16:39:39 +01:00
|
|
|
return_trace (c->check_struct (this));
|
2018-10-11 00:14:41 +02:00
|
|
|
}
|
|
|
|
|
2018-11-07 16:39:39 +01:00
|
|
|
protected:
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 left;
|
|
|
|
HBGlyphID16 right;
|
2018-11-07 16:39:39 +01:00
|
|
|
FWORD value;
|
2018-10-11 00:14:41 +02:00
|
|
|
public:
|
2018-11-07 16:39:39 +01:00
|
|
|
DEFINE_SIZE_STATIC (6);
|
2018-10-11 00:14:41 +02:00
|
|
|
};
|
|
|
|
|
2018-11-07 16:19:46 +01:00
|
|
|
template <typename KernSubTableHeader>
|
2018-10-08 04:33:41 +02:00
|
|
|
struct KerxSubTableFormat0
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_kerning (hb_codepoint_t left, hb_codepoint_t right,
|
|
|
|
hb_aat_apply_context_t *c = nullptr) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-10-08 04:33:41 +02:00
|
|
|
hb_glyph_pair_t pair = {left, right};
|
2018-11-24 06:35:31 +01:00
|
|
|
int v = pairs.bsearch (pair).get_kerning ();
|
2018-11-07 16:45:25 +01:00
|
|
|
return kerxTupleKern (v, header.tuple_count (), this, c);
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-10-07 20:01:33 +02:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
|
|
|
|
2018-10-11 00:10:05 +02:00
|
|
|
if (!c->plan->requested_kerning)
|
|
|
|
return false;
|
|
|
|
|
2018-11-07 20:52:36 +01:00
|
|
|
if (header.coverage & header.Backwards)
|
2018-11-06 20:48:42 +01:00
|
|
|
return false;
|
|
|
|
|
2018-10-20 23:56:28 +02:00
|
|
|
accelerator_t accel (*this, c);
|
2018-11-07 20:52:36 +01:00
|
|
|
hb_kern_machine_t<accelerator_t> machine (accel, header.coverage & header.CrossStream);
|
2018-10-10 04:35:22 +02:00
|
|
|
machine.kern (c->font, c->buffer, c->plan->kern_mask);
|
2018-10-07 20:01:33 +02:00
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
2018-02-19 00:47:44 +01:00
|
|
|
|
2018-10-20 23:56:28 +02:00
|
|
|
struct accelerator_t
|
|
|
|
{
|
|
|
|
const KerxSubTableFormat0 &table;
|
|
|
|
hb_aat_apply_context_t *c;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
accelerator_t (const KerxSubTableFormat0 &table_,
|
|
|
|
hb_aat_apply_context_t *c_) :
|
|
|
|
table (table_), c (c_) {}
|
2018-10-20 23:56:28 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
|
2018-10-20 23:56:28 +02:00
|
|
|
{ return table.get_kerning (left, right, c); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-11-07 16:33:46 +01:00
|
|
|
return_trace (likely (pairs.sanitize (c)));
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-11-07 16:19:46 +01:00
|
|
|
KernSubTableHeader header;
|
2018-11-07 16:33:46 +01:00
|
|
|
BinSearchArrayOf<KernPair, typename KernSubTableHeader::Types::HBUINT>
|
2018-10-11 00:14:41 +02:00
|
|
|
pairs; /* Sorted kern records. */
|
2018-02-19 00:47:44 +01:00
|
|
|
public:
|
2018-11-07 16:19:46 +01:00
|
|
|
DEFINE_SIZE_ARRAY (KernSubTableHeader::static_size + 16, pairs);
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 17:02:04 +01:00
|
|
|
|
|
|
|
template <bool extended>
|
|
|
|
struct Format1Entry;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Format1Entry<true>
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-11-07 17:02:04 +01:00
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
Push = 0x8000, /* If set, push this glyph on the kerning stack. */
|
|
|
|
DontAdvance = 0x4000, /* If set, don't advance to the next glyph
|
|
|
|
* before going to the new state. */
|
|
|
|
Reset = 0x2000, /* If set, reset the kerning data (clear the stack) */
|
|
|
|
Reserved = 0x1FFF, /* Not used; set to 0. */
|
|
|
|
};
|
|
|
|
|
2018-10-11 02:37:22 +02:00
|
|
|
struct EntryData
|
|
|
|
{
|
2018-10-11 03:18:37 +02:00
|
|
|
HBUINT16 kernActionIndex;/* Index into the kerning value array. If
|
|
|
|
* this index is 0xFFFF, then no kerning
|
|
|
|
* is to be performed. */
|
2018-10-11 02:37:22 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (2);
|
|
|
|
};
|
2018-11-07 17:20:14 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static bool performAction (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.data.kernActionIndex != 0xFFFF; }
|
2018-11-07 17:20:14 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static unsigned int kernActionIndex (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.data.kernActionIndex; }
|
2018-11-07 17:02:04 +01:00
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct Format1Entry<false>
|
|
|
|
{
|
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
Push = 0x8000, /* If set, push this glyph on the kerning stack. */
|
|
|
|
DontAdvance = 0x4000, /* If set, don't advance to the next glyph
|
|
|
|
* before going to the new state. */
|
|
|
|
Offset = 0x3FFF, /* Byte offset from beginning of subtable to the
|
|
|
|
* value table for the glyphs on the kerning stack. */
|
|
|
|
|
|
|
|
Reset = 0x0000, /* Not supported? */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void EntryData;
|
2018-11-07 17:20:14 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static bool performAction (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.flags & Offset; }
|
2018-11-07 17:20:14 +01:00
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
static unsigned int kernActionIndex (const Entry<EntryData> &entry)
|
|
|
|
{ return entry.flags & Offset; }
|
2018-11-07 17:02:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename KernSubTableHeader>
|
|
|
|
struct KerxSubTableFormat1
|
|
|
|
{
|
|
|
|
typedef typename KernSubTableHeader::Types Types;
|
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
|
|
|
typedef Format1Entry<Types::extended> Format1EntryT;
|
|
|
|
typedef typename Format1EntryT::EntryData EntryData;
|
2018-10-11 02:37:22 +02:00
|
|
|
|
|
|
|
struct driver_context_t
|
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool in_place = true;
|
2018-11-07 17:02:04 +01:00
|
|
|
enum
|
2018-10-11 02:37:22 +02:00
|
|
|
{
|
2018-11-07 17:02:04 +01:00
|
|
|
DontAdvance = Format1EntryT::DontAdvance,
|
2018-10-11 02:37:22 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
driver_context_t (const KerxSubTableFormat1 *table_,
|
|
|
|
hb_aat_apply_context_t *c_) :
|
2018-10-11 03:18:37 +02:00
|
|
|
c (c_),
|
2018-11-07 17:20:14 +01:00
|
|
|
table (table_),
|
2018-10-11 03:53:14 +02:00
|
|
|
/* Apparently the offset kernAction is from the beginning of the state-machine,
|
|
|
|
* similar to offsets in morx table, NOT from beginning of this table, like
|
|
|
|
* other subtables in kerx. Discovered via testing. */
|
2018-10-11 03:46:58 +02:00
|
|
|
kernAction (&table->machine + table->kernAction),
|
2018-11-06 20:48:42 +01:00
|
|
|
depth (0),
|
2018-11-07 20:38:29 +01:00
|
|
|
crossStream (table->header.coverage & table->header.CrossStream) {}
|
2018-11-07 17:20:14 +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)
|
2020-07-22 15:00:48 +02:00
|
|
|
{ return Format1EntryT::performAction (entry); }
|
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-10-11 02:37:22 +02:00
|
|
|
{
|
2018-10-11 03:18:37 +02:00
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
2019-01-24 17:21:41 +01:00
|
|
|
unsigned int flags = entry.flags;
|
2018-10-11 03:18:37 +02:00
|
|
|
|
2018-11-07 17:02:04 +01:00
|
|
|
if (flags & Format1EntryT::Reset)
|
2018-10-19 18:58:45 +02:00
|
|
|
depth = 0;
|
2018-10-11 03:18:37 +02:00
|
|
|
|
2018-11-07 17:02:04 +01:00
|
|
|
if (flags & Format1EntryT::Push)
|
2018-10-11 03:18:37 +02:00
|
|
|
{
|
2018-10-19 18:58:45 +02:00
|
|
|
if (likely (depth < ARRAY_LENGTH (stack)))
|
2018-10-11 03:18:37 +02:00
|
|
|
stack[depth++] = buffer->idx;
|
|
|
|
else
|
|
|
|
depth = 0; /* Probably not what CoreText does, but better? */
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:56:48 +01:00
|
|
|
if (Format1EntryT::performAction (entry) && depth)
|
2018-10-11 03:18:37 +02:00
|
|
|
{
|
2019-05-08 05:54:31 +02:00
|
|
|
unsigned int tuple_count = hb_max (1u, table->header.tuple_count ());
|
2018-11-11 03:13:13 +01:00
|
|
|
|
2018-11-07 17:20:14 +01:00
|
|
|
unsigned int kern_idx = Format1EntryT::kernActionIndex (entry);
|
2018-11-28 21:24:30 +01:00
|
|
|
kern_idx = Types::byteOffsetToIndex (kern_idx, &table->machine, kernAction.arrayZ);
|
2018-11-07 17:20:14 +01:00
|
|
|
const FWORD *actions = &kernAction[kern_idx];
|
2018-11-12 20:24:36 +01:00
|
|
|
if (!c->sanitizer.check_array (actions, depth, tuple_count))
|
2018-10-11 03:18:37 +02:00
|
|
|
{
|
|
|
|
depth = 0;
|
2019-01-24 18:01:07 +01:00
|
|
|
return;
|
2018-10-11 03:18:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 04:15:13 +02:00
|
|
|
hb_mask_t kern_mask = c->plan->kern_mask;
|
2018-11-07 03:45:40 +01:00
|
|
|
|
|
|
|
/* From Apple 'kern' spec:
|
|
|
|
* "Each pops one glyph from the kerning stack and applies the kerning value to it.
|
|
|
|
* The end of the list is marked by an odd value... */
|
2018-11-07 21:44:40 +01:00
|
|
|
bool last = false;
|
2018-11-12 19:56:48 +01:00
|
|
|
while (!last && depth)
|
2018-10-11 03:18:37 +02:00
|
|
|
{
|
2018-11-12 19:56:48 +01:00
|
|
|
unsigned int idx = stack[--depth];
|
2018-11-07 21:44:40 +01:00
|
|
|
int v = *actions;
|
|
|
|
actions += tuple_count;
|
2018-11-07 20:11:48 +01:00
|
|
|
if (idx >= buffer->len) continue;
|
|
|
|
|
2018-11-07 21:44:40 +01:00
|
|
|
/* "The end of the list is marked by an odd value..." */
|
|
|
|
last = v & 1;
|
2018-11-07 03:45:40 +01:00
|
|
|
v &= ~1;
|
|
|
|
|
2018-11-07 20:38:29 +01:00
|
|
|
hb_glyph_position_t &o = buffer->pos[idx];
|
|
|
|
|
2020-05-06 02:48:24 +02:00
|
|
|
if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction))
|
2018-10-11 04:15:13 +02:00
|
|
|
{
|
2018-11-07 20:11:48 +01:00
|
|
|
if (crossStream)
|
2018-11-02 19:47:42 +01:00
|
|
|
{
|
2020-05-06 02:48:24 +02:00
|
|
|
/* The following flag is undocumented in the spec, but described
|
|
|
|
* in the 'kern' table example. */
|
|
|
|
if (v == -0x8000)
|
2018-11-07 20:38:29 +01:00
|
|
|
{
|
2022-06-29 02:52:27 +02:00
|
|
|
o.attach_type() = OT::Layout::GPOS_impl::ATTACH_TYPE_NONE;
|
2020-05-06 02:48:24 +02:00
|
|
|
o.attach_chain() = 0;
|
|
|
|
o.y_offset = 0;
|
|
|
|
}
|
|
|
|
else if (o.attach_type())
|
|
|
|
{
|
|
|
|
o.y_offset += c->font->em_scale_y (v);
|
2018-11-07 20:38:29 +01:00
|
|
|
buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
|
|
|
|
}
|
2018-11-02 19:47:42 +01:00
|
|
|
}
|
2018-11-07 20:11:48 +01:00
|
|
|
else if (buffer->info[idx].mask & kern_mask)
|
2018-11-02 19:47:42 +01:00
|
|
|
{
|
2020-05-06 02:48:24 +02:00
|
|
|
o.x_advance += c->font->em_scale_x (v);
|
|
|
|
o.x_offset += c->font->em_scale_x (v);
|
2018-11-07 20:11:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (crossStream)
|
|
|
|
{
|
|
|
|
/* CoreText doesn't do crossStream kerning in vertical. We do. */
|
2020-05-06 02:48:24 +02:00
|
|
|
if (v == -0x8000)
|
|
|
|
{
|
2022-06-29 02:52:27 +02:00
|
|
|
o.attach_type() = OT::Layout::GPOS_impl::ATTACH_TYPE_NONE;
|
2020-05-06 02:48:24 +02:00
|
|
|
o.attach_chain() = 0;
|
|
|
|
o.x_offset = 0;
|
|
|
|
}
|
|
|
|
else if (o.attach_type())
|
2018-11-07 20:38:29 +01:00
|
|
|
{
|
2020-05-06 02:48:24 +02:00
|
|
|
o.x_offset += c->font->em_scale_x (v);
|
2018-11-07 20:38:29 +01:00
|
|
|
buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
|
|
|
|
}
|
2018-11-07 20:11:48 +01:00
|
|
|
}
|
|
|
|
else if (buffer->info[idx].mask & kern_mask)
|
|
|
|
{
|
2020-05-06 02:48:24 +02:00
|
|
|
o.y_advance += c->font->em_scale_y (v);
|
|
|
|
o.y_offset += c->font->em_scale_y (v);
|
2018-11-02 19:47:42 +01:00
|
|
|
}
|
2018-10-11 04:15:13 +02:00
|
|
|
}
|
2018-10-11 03:18:37 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-11 02:37:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-10-11 03:18:37 +02:00
|
|
|
hb_aat_apply_context_t *c;
|
2018-11-07 17:20:14 +01:00
|
|
|
const KerxSubTableFormat1 *table;
|
2018-10-11 03:18:37 +02:00
|
|
|
const UnsizedArrayOf<FWORD> &kernAction;
|
|
|
|
unsigned int stack[8];
|
|
|
|
unsigned int depth;
|
2018-11-06 20:48:42 +01:00
|
|
|
bool crossStream;
|
2018-10-11 02:37:22 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-10-07 20:01:33 +02:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
|
|
|
|
2018-11-07 20:04:04 +01:00
|
|
|
if (!c->plan->requested_kerning &&
|
|
|
|
!(header.coverage & header.CrossStream))
|
2018-10-11 00:10:05 +02:00
|
|
|
return false;
|
|
|
|
|
2018-10-11 03:18:37 +02:00
|
|
|
driver_context_t dc (this, c);
|
2018-10-11 02:37:22 +02:00
|
|
|
|
2018-11-07 17:28:36 +01:00
|
|
|
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->font->face);
|
2023-01-10 05:32:15 +01:00
|
|
|
driver.drive (&dc, c);
|
2018-10-07 20:01:33 +02:00
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-03-01 21:37:26 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2018-10-14 23:56:32 +02:00
|
|
|
/* The rest of array sanitizations are done at run-time. */
|
|
|
|
return_trace (likely (c->check_struct (this) &&
|
|
|
|
machine.sanitize (c)));
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-11-07 16:19:46 +01:00
|
|
|
KernSubTableHeader header;
|
2018-11-07 17:02:04 +01:00
|
|
|
StateTable<Types, EntryData> machine;
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<UnsizedArrayOf<FWORD>, HBUINT> kernAction;
|
2018-02-19 00:47:44 +01:00
|
|
|
public:
|
2018-11-07 17:25:55 +01:00
|
|
|
DEFINE_SIZE_STATIC (KernSubTableHeader::static_size + 5 * sizeof (HBUINT));
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 16:19:46 +01:00
|
|
|
template <typename KernSubTableHeader>
|
2018-02-19 00:47:44 +01:00
|
|
|
struct KerxSubTableFormat2
|
|
|
|
{
|
2018-11-07 18:16:38 +01:00
|
|
|
typedef typename KernSubTableHeader::Types Types;
|
|
|
|
typedef typename Types::HBUINT HBUINT;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_kerning (hb_codepoint_t left, hb_codepoint_t right,
|
|
|
|
hb_aat_apply_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-10-13 18:16:12 +02:00
|
|
|
unsigned int num_glyphs = c->sanitizer.get_num_glyphs ();
|
2018-11-07 18:16:38 +01:00
|
|
|
unsigned int l = (this+leftClassTable).get_class (left, num_glyphs, 0);
|
|
|
|
unsigned int r = (this+rightClassTable).get_class (right, num_glyphs, 0);
|
2018-11-28 21:06:01 +01:00
|
|
|
|
|
|
|
const UnsizedArrayOf<FWORD> &arrayZ = this+array;
|
|
|
|
unsigned int kern_idx = l + r;
|
2019-09-07 03:36:31 +02:00
|
|
|
kern_idx = Types::offsetToIndex (kern_idx, this, arrayZ.arrayZ);
|
2018-11-28 21:06:01 +01:00
|
|
|
const FWORD *v = &arrayZ[kern_idx];
|
2018-10-13 19:36:27 +02:00
|
|
|
if (unlikely (!v->sanitize (&c->sanitizer))) return 0;
|
2018-11-28 21:06:01 +01:00
|
|
|
|
2018-11-07 16:45:25 +01:00
|
|
|
return kerxTupleKern (*v, header.tuple_count (), this, c);
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-10-07 20:01:33 +02:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
|
|
|
|
2018-10-11 00:10:05 +02:00
|
|
|
if (!c->plan->requested_kerning)
|
|
|
|
return false;
|
|
|
|
|
2018-11-07 20:52:36 +01:00
|
|
|
if (header.coverage & header.Backwards)
|
2018-11-06 20:48:42 +01:00
|
|
|
return false;
|
|
|
|
|
2018-10-13 18:16:12 +02:00
|
|
|
accelerator_t accel (*this, c);
|
2018-11-07 20:52:36 +01:00
|
|
|
hb_kern_machine_t<accelerator_t> machine (accel, header.coverage & header.CrossStream);
|
2018-10-10 04:35:22 +02:00
|
|
|
machine.kern (c->font, c->buffer, c->plan->kern_mask);
|
2018-10-07 20:01:33 +02:00
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-10-10 04:35:22 +02:00
|
|
|
struct accelerator_t
|
|
|
|
{
|
|
|
|
const KerxSubTableFormat2 &table;
|
2018-10-13 18:16:12 +02:00
|
|
|
hb_aat_apply_context_t *c;
|
2018-10-10 04:35:22 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
accelerator_t (const KerxSubTableFormat2 &table_,
|
|
|
|
hb_aat_apply_context_t *c_) :
|
|
|
|
table (table_), c (c_) {}
|
2018-10-10 04:35:22 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
|
2018-10-13 18:16:12 +02:00
|
|
|
{ return table.get_kerning (left, right, c); }
|
2018-10-10 04:35:22 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-20 23:56:28 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (likely (c->check_struct (this) &&
|
|
|
|
leftClassTable.sanitize (c, this) &&
|
|
|
|
rightClassTable.sanitize (c, this) &&
|
|
|
|
c->check_range (this, array)));
|
|
|
|
}
|
|
|
|
|
2018-02-19 00:47:44 +01:00
|
|
|
protected:
|
2018-11-07 16:19:46 +01:00
|
|
|
KernSubTableHeader header;
|
2018-11-07 18:16:38 +01:00
|
|
|
HBUINT rowWidth; /* The width, in bytes, of a row in the table. */
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<typename Types::ClassTypeWide, HBUINT>
|
2018-10-11 00:14:41 +02:00
|
|
|
leftClassTable; /* Offset from beginning of this subtable to
|
|
|
|
* left-hand class table. */
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<typename Types::ClassTypeWide, HBUINT>
|
2018-10-11 00:14:41 +02:00
|
|
|
rightClassTable;/* Offset from beginning of this subtable to
|
|
|
|
* right-hand class table. */
|
2019-01-18 00:24:18 +01:00
|
|
|
NNOffsetTo<UnsizedArrayOf<FWORD>, HBUINT>
|
2018-10-11 02:43:21 +02:00
|
|
|
array; /* Offset from beginning of this subtable to
|
2018-10-11 00:14:41 +02:00
|
|
|
* the start of the kerning array. */
|
2018-02-19 00:47:44 +01:00
|
|
|
public:
|
2018-11-07 18:16:38 +01:00
|
|
|
DEFINE_SIZE_STATIC (KernSubTableHeader::static_size + 4 * sizeof (HBUINT));
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 16:19:46 +01:00
|
|
|
template <typename KernSubTableHeader>
|
2018-02-19 00:47:44 +01:00
|
|
|
struct KerxSubTableFormat4
|
|
|
|
{
|
2018-11-07 17:51:40 +01:00
|
|
|
typedef ExtendedTypes Types;
|
|
|
|
|
2018-10-11 06:12:49 +02:00
|
|
|
struct EntryData
|
|
|
|
{
|
|
|
|
HBUINT16 ankrActionIndex;/* Either 0xFFFF (for no action) or the index of
|
|
|
|
* the action to perform. */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (2);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct driver_context_t
|
|
|
|
{
|
2019-01-22 12:07:43 +01:00
|
|
|
static constexpr bool in_place = true;
|
2018-10-11 06:12:49 +02:00
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
Mark = 0x8000, /* If set, remember this glyph as the marked glyph. */
|
|
|
|
DontAdvance = 0x4000, /* If set, don't advance to the next glyph before
|
|
|
|
* going to the new state. */
|
|
|
|
Reserved = 0x3FFF, /* Not used; set to 0. */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SubTableFlags
|
|
|
|
{
|
|
|
|
ActionType = 0xC0000000, /* A two-bit field containing the action type. */
|
|
|
|
Unused = 0x3F000000, /* Unused - must be zero. */
|
|
|
|
Offset = 0x00FFFFFF, /* Masks the offset in bytes from the beginning
|
|
|
|
* of the subtable to the beginning of the control
|
|
|
|
* point table. */
|
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
driver_context_t (const KerxSubTableFormat4 *table,
|
2020-07-18 19:44:52 +02:00
|
|
|
hb_aat_apply_context_t *c_) :
|
2018-10-11 06:12:49 +02:00
|
|
|
c (c_),
|
|
|
|
action_type ((table->flags & ActionType) >> 30),
|
|
|
|
ankrData ((HBUINT16 *) ((const char *) &table->machine + (table->flags & Offset))),
|
|
|
|
mark_set (false),
|
|
|
|
mark (0) {}
|
|
|
|
|
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)
|
2020-07-18 19:44:52 +02:00
|
|
|
{ return entry.data.ankrActionIndex != 0xFFFF; }
|
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-10-11 06:12:49 +02:00
|
|
|
{
|
|
|
|
hb_buffer_t *buffer = driver->buffer;
|
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
if (mark_set && entry.data.ankrActionIndex != 0xFFFF && buffer->idx < buffer->len)
|
2018-10-11 06:12:49 +02:00
|
|
|
{
|
2018-10-11 07:17:57 +02:00
|
|
|
hb_glyph_position_t &o = buffer->cur_pos();
|
2018-10-11 06:12:49 +02:00
|
|
|
switch (action_type)
|
|
|
|
{
|
|
|
|
case 0: /* Control Point Actions.*/
|
|
|
|
{
|
2020-07-05 23:44:10 +02:00
|
|
|
/* Indexed into glyph outline. */
|
|
|
|
/* Each action (record in ankrData) contains two 16-bit fields, so we must
|
|
|
|
double the ankrActionIndex to get the correct offset here. */
|
|
|
|
const HBUINT16 *data = &ankrData[entry.data.ankrActionIndex * 2];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (!c->sanitizer.check_array (data, 2)) return;
|
2020-07-05 23:44:10 +02:00
|
|
|
unsigned int markControlPoint = *data++;
|
|
|
|
unsigned int currControlPoint = *data++;
|
2018-10-11 07:22:29 +02:00
|
|
|
hb_position_t markX = 0;
|
|
|
|
hb_position_t markY = 0;
|
|
|
|
hb_position_t currX = 0;
|
|
|
|
hb_position_t currY = 0;
|
|
|
|
if (!c->font->get_glyph_contour_point_for_origin (c->buffer->info[mark].codepoint,
|
|
|
|
markControlPoint,
|
|
|
|
HB_DIRECTION_LTR /*XXX*/,
|
|
|
|
&markX, &markY) ||
|
|
|
|
!c->font->get_glyph_contour_point_for_origin (c->buffer->cur ().codepoint,
|
|
|
|
currControlPoint,
|
|
|
|
HB_DIRECTION_LTR /*XXX*/,
|
|
|
|
&currX, &currY))
|
2019-01-24 18:01:07 +01:00
|
|
|
return;
|
2018-10-11 07:22:29 +02:00
|
|
|
|
|
|
|
o.x_offset = markX - currX;
|
|
|
|
o.y_offset = markY - currY;
|
2018-10-11 06:12:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Anchor Point Actions. */
|
|
|
|
{
|
2020-07-05 23:44:10 +02:00
|
|
|
/* Indexed into 'ankr' table. */
|
|
|
|
/* Each action (record in ankrData) contains two 16-bit fields, so we must
|
|
|
|
double the ankrActionIndex to get the correct offset here. */
|
|
|
|
const HBUINT16 *data = &ankrData[entry.data.ankrActionIndex * 2];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (!c->sanitizer.check_array (data, 2)) return;
|
2018-10-11 07:14:18 +02:00
|
|
|
unsigned int markAnchorPoint = *data++;
|
|
|
|
unsigned int currAnchorPoint = *data++;
|
2019-01-17 20:06:32 +01:00
|
|
|
const Anchor &markAnchor = c->ankr_table->get_anchor (c->buffer->info[mark].codepoint,
|
|
|
|
markAnchorPoint,
|
2019-01-17 23:47:29 +01:00
|
|
|
c->sanitizer.get_num_glyphs ());
|
2019-01-17 20:06:32 +01:00
|
|
|
const Anchor &currAnchor = c->ankr_table->get_anchor (c->buffer->cur ().codepoint,
|
|
|
|
currAnchorPoint,
|
2019-01-17 23:47:29 +01:00
|
|
|
c->sanitizer.get_num_glyphs ());
|
2018-10-11 07:17:57 +02:00
|
|
|
|
2018-10-11 07:14:18 +02:00
|
|
|
o.x_offset = c->font->em_scale_x (markAnchor.xCoordinate) - c->font->em_scale_x (currAnchor.xCoordinate);
|
|
|
|
o.y_offset = c->font->em_scale_y (markAnchor.yCoordinate) - c->font->em_scale_y (currAnchor.yCoordinate);
|
2018-10-11 06:12:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Control Point Coordinate Actions. */
|
|
|
|
{
|
2020-07-05 23:44:10 +02:00
|
|
|
/* Each action contains four 16-bit fields, so we multiply the ankrActionIndex
|
|
|
|
by 4 to get the correct offset for the given action. */
|
|
|
|
const FWORD *data = (const FWORD *) &ankrData[entry.data.ankrActionIndex * 4];
|
2019-01-24 18:01:07 +01:00
|
|
|
if (!c->sanitizer.check_array (data, 4)) return;
|
2018-10-11 07:17:57 +02:00
|
|
|
int markX = *data++;
|
|
|
|
int markY = *data++;
|
|
|
|
int currX = *data++;
|
|
|
|
int currY = *data++;
|
|
|
|
|
|
|
|
o.x_offset = c->font->em_scale_x (markX) - c->font->em_scale_x (currX);
|
|
|
|
o.y_offset = c->font->em_scale_y (markY) - c->font->em_scale_y (currY);
|
2018-10-11 06:12:49 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-06-29 02:52:27 +02:00
|
|
|
o.attach_type() = OT::Layout::GPOS_impl::ATTACH_TYPE_MARK;
|
2018-10-11 07:17:57 +02:00
|
|
|
o.attach_chain() = (int) mark - (int) buffer->idx;
|
|
|
|
buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
|
2018-10-11 06:12:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 17:21:41 +01:00
|
|
|
if (entry.flags & Mark)
|
2018-10-11 06:12:49 +02:00
|
|
|
{
|
|
|
|
mark_set = true;
|
|
|
|
mark = buffer->idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
hb_aat_apply_context_t *c;
|
|
|
|
unsigned int action_type;
|
|
|
|
const HBUINT16 *ankrData;
|
|
|
|
bool mark_set;
|
|
|
|
unsigned int mark;
|
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-10-07 20:01:33 +02:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
|
|
|
|
2018-10-11 06:12:49 +02:00
|
|
|
driver_context_t dc (this, c);
|
|
|
|
|
2018-11-07 17:51:40 +01:00
|
|
|
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->font->face);
|
2023-01-10 05:32:15 +01:00
|
|
|
driver.drive (&dc, c);
|
2018-10-07 20:01:33 +02:00
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-10-11 06:12:49 +02:00
|
|
|
/* The rest of array sanitizations are done at run-time. */
|
2018-10-14 23:56:32 +02:00
|
|
|
return_trace (likely (c->check_struct (this) &&
|
|
|
|
machine.sanitize (c)));
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-11-07 17:51:40 +01:00
|
|
|
KernSubTableHeader header;
|
|
|
|
StateTable<Types, EntryData> machine;
|
|
|
|
HBUINT32 flags;
|
2018-02-19 00:47:44 +01:00
|
|
|
public:
|
2018-11-07 16:19:46 +01:00
|
|
|
DEFINE_SIZE_STATIC (KernSubTableHeader::static_size + 20);
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 16:19:46 +01:00
|
|
|
template <typename KernSubTableHeader>
|
2018-02-19 00:47:44 +01:00
|
|
|
struct KerxSubTableFormat6
|
|
|
|
{
|
2018-10-11 01:58:20 +02:00
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
ValuesAreLong = 0x00000001,
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_long () const { return flags & ValuesAreLong; }
|
2018-10-11 01:58:20 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_kerning (hb_codepoint_t left, hb_codepoint_t right,
|
2020-07-18 19:44:52 +02:00
|
|
|
hb_aat_apply_context_t *c) const
|
2018-10-11 02:10:20 +02:00
|
|
|
{
|
2018-10-13 18:16:12 +02:00
|
|
|
unsigned int num_glyphs = c->sanitizer.get_num_glyphs ();
|
2018-10-11 02:10:20 +02:00
|
|
|
if (is_long ())
|
|
|
|
{
|
2018-11-07 16:19:46 +01:00
|
|
|
const typename U::Long &t = u.l;
|
2018-10-11 02:10:20 +02:00
|
|
|
unsigned int l = (this+t.rowIndexTable).get_value_or_null (left, num_glyphs);
|
|
|
|
unsigned int r = (this+t.columnIndexTable).get_value_or_null (right, num_glyphs);
|
|
|
|
unsigned int offset = l + r;
|
2018-10-13 17:39:12 +02:00
|
|
|
if (unlikely (offset < l)) return 0; /* Addition overflow. */
|
|
|
|
if (unlikely (hb_unsigned_mul_overflows (offset, sizeof (FWORD32)))) return 0;
|
2018-10-13 19:36:27 +02:00
|
|
|
const FWORD32 *v = &StructAtOffset<FWORD32> (&(this+t.array), offset * sizeof (FWORD32));
|
|
|
|
if (unlikely (!v->sanitize (&c->sanitizer))) return 0;
|
2018-11-07 16:45:25 +01:00
|
|
|
return kerxTupleKern (*v, header.tuple_count (), &(this+vector), c);
|
2018-10-11 02:10:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-07 16:19:46 +01:00
|
|
|
const typename U::Short &t = u.s;
|
2018-10-11 02:10:20 +02:00
|
|
|
unsigned int l = (this+t.rowIndexTable).get_value_or_null (left, num_glyphs);
|
|
|
|
unsigned int r = (this+t.columnIndexTable).get_value_or_null (right, num_glyphs);
|
|
|
|
unsigned int offset = l + r;
|
2018-10-13 19:36:27 +02:00
|
|
|
const FWORD *v = &StructAtOffset<FWORD> (&(this+t.array), offset * sizeof (FWORD));
|
|
|
|
if (unlikely (!v->sanitize (&c->sanitizer))) return 0;
|
2018-11-07 16:45:25 +01:00
|
|
|
return kerxTupleKern (*v, header.tuple_count (), &(this+vector), c);
|
2018-10-11 02:10:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (hb_aat_apply_context_t *c) const
|
2018-10-07 20:01:33 +02:00
|
|
|
{
|
|
|
|
TRACE_APPLY (this);
|
|
|
|
|
2018-10-11 00:10:05 +02:00
|
|
|
if (!c->plan->requested_kerning)
|
|
|
|
return false;
|
|
|
|
|
2018-11-07 20:52:36 +01:00
|
|
|
if (header.coverage & header.Backwards)
|
2018-11-06 20:48:42 +01:00
|
|
|
return false;
|
|
|
|
|
2018-10-13 18:16:12 +02:00
|
|
|
accelerator_t accel (*this, c);
|
2018-11-07 20:52:36 +01:00
|
|
|
hb_kern_machine_t<accelerator_t> machine (accel, header.coverage & header.CrossStream);
|
2018-10-11 02:10:20 +02:00
|
|
|
machine.kern (c->font, c->buffer, c->plan->kern_mask);
|
2018-10-07 20:01:33 +02:00
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-03-01 21:37:26 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2018-04-20 18:42:58 +02:00
|
|
|
return_trace (likely (c->check_struct (this) &&
|
2018-10-16 06:16:58 +02:00
|
|
|
(is_long () ?
|
|
|
|
(
|
|
|
|
u.l.rowIndexTable.sanitize (c, this) &&
|
|
|
|
u.l.columnIndexTable.sanitize (c, this) &&
|
|
|
|
c->check_range (this, u.l.array)
|
|
|
|
) : (
|
|
|
|
u.s.rowIndexTable.sanitize (c, this) &&
|
|
|
|
u.s.columnIndexTable.sanitize (c, this) &&
|
|
|
|
c->check_range (this, u.s.array)
|
2018-10-20 01:06:54 +02:00
|
|
|
)) &&
|
2018-11-07 16:45:25 +01:00
|
|
|
(header.tuple_count () == 0 ||
|
2018-10-20 01:06:54 +02:00
|
|
|
c->check_range (this, vector))));
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-11 02:10:20 +02:00
|
|
|
struct accelerator_t
|
|
|
|
{
|
|
|
|
const KerxSubTableFormat6 &table;
|
2018-10-13 18:16:12 +02:00
|
|
|
hb_aat_apply_context_t *c;
|
2018-10-11 02:10:20 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
accelerator_t (const KerxSubTableFormat6 &table_,
|
|
|
|
hb_aat_apply_context_t *c_) :
|
|
|
|
table (table_), c (c_) {}
|
2018-10-11 02:10:20 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
|
2018-10-13 18:16:12 +02:00
|
|
|
{ return table.get_kerning (left, right, c); }
|
2018-10-11 02:10:20 +02:00
|
|
|
};
|
|
|
|
|
2018-02-19 00:47:44 +01:00
|
|
|
protected:
|
2018-11-07 16:19:46 +01:00
|
|
|
KernSubTableHeader header;
|
2018-10-11 00:14:41 +02:00
|
|
|
HBUINT32 flags;
|
|
|
|
HBUINT16 rowCount;
|
|
|
|
HBUINT16 columnCount;
|
2018-10-11 02:10:20 +02:00
|
|
|
union U
|
2018-10-11 01:58:20 +02:00
|
|
|
{
|
2018-10-11 02:10:20 +02:00
|
|
|
struct Long
|
2018-10-11 01:58:20 +02:00
|
|
|
{
|
2021-03-31 20:49:14 +02:00
|
|
|
NNOffset32To<Lookup<HBUINT32>> rowIndexTable;
|
|
|
|
NNOffset32To<Lookup<HBUINT32>> columnIndexTable;
|
|
|
|
NNOffset32To<UnsizedArrayOf<FWORD32>> array;
|
2018-10-11 01:58:20 +02:00
|
|
|
} l;
|
2018-10-11 02:10:20 +02:00
|
|
|
struct Short
|
|
|
|
{
|
2021-03-31 20:49:14 +02:00
|
|
|
NNOffset32To<Lookup<HBUINT16>> rowIndexTable;
|
|
|
|
NNOffset32To<Lookup<HBUINT16>> columnIndexTable;
|
|
|
|
NNOffset32To<UnsizedArrayOf<FWORD>> array;
|
2018-10-11 02:10:20 +02:00
|
|
|
} s;
|
2018-10-11 01:58:20 +02:00
|
|
|
} u;
|
2021-03-31 20:49:14 +02:00
|
|
|
NNOffset32To<UnsizedArrayOf<FWORD>> vector;
|
2018-02-19 00:47:44 +01:00
|
|
|
public:
|
2018-11-07 16:19:46 +01:00
|
|
|
DEFINE_SIZE_STATIC (KernSubTableHeader::static_size + 24);
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 16:39:39 +01:00
|
|
|
|
|
|
|
struct KerxSubTableHeader
|
|
|
|
{
|
2018-11-07 17:51:40 +01:00
|
|
|
typedef ExtendedTypes Types;
|
2018-11-07 16:39:39 +01:00
|
|
|
|
2019-10-01 12:19:55 +02:00
|
|
|
unsigned tuple_count () const { return tupleCount; }
|
|
|
|
bool is_horizontal () const { return !(coverage & Vertical); }
|
2018-11-07 16:45:25 +01:00
|
|
|
|
2018-11-07 16:39:39 +01:00
|
|
|
enum Coverage
|
|
|
|
{
|
2018-11-07 19:33:23 +01:00
|
|
|
Vertical = 0x80000000u, /* Set if table has vertical kerning values. */
|
|
|
|
CrossStream = 0x40000000u, /* Set if table has cross-stream kerning values. */
|
|
|
|
Variation = 0x20000000u, /* Set if table has variation kerning values. */
|
|
|
|
Backwards = 0x10000000u, /* If clear, process the glyphs forwards, that
|
|
|
|
* is, from first to last in the glyph stream.
|
|
|
|
* If we, process them from last to first.
|
|
|
|
* This flag only applies to state-table based
|
|
|
|
* 'kerx' subtables (types 1 and 4). */
|
|
|
|
Reserved = 0x0FFFFF00u, /* Reserved, set to zero. */
|
|
|
|
SubtableType= 0x000000FFu, /* Subtable type. */
|
2018-11-07 16:39:39 +01:00
|
|
|
};
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-11-07 16:39:39 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2022-07-11 22:01:52 +02:00
|
|
|
return_trace (c->check_struct (this));
|
2018-11-07 16:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
HBUINT32 length;
|
|
|
|
HBUINT32 coverage;
|
|
|
|
HBUINT32 tupleCount;
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
|
|
|
};
|
|
|
|
|
2018-11-07 17:56:36 +01:00
|
|
|
struct KerxSubTable
|
2018-03-01 21:37:26 +01:00
|
|
|
{
|
2018-10-09 14:28:07 +02:00
|
|
|
friend struct kerx;
|
2018-10-09 04:41:08 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_size () const { return u.header.length; }
|
|
|
|
unsigned int get_type () const { return u.header.coverage & u.header.SubtableType; }
|
2018-10-07 20:01:33 +02:00
|
|
|
|
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
|
2018-10-07 20:01:33 +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 0: return_trace (c->dispatch (u.format0, std::forward<Ts> (ds)...));
|
|
|
|
case 1: return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...));
|
|
|
|
case 2: return_trace (c->dispatch (u.format2, std::forward<Ts> (ds)...));
|
|
|
|
case 4: return_trace (c->dispatch (u.format4, std::forward<Ts> (ds)...));
|
|
|
|
case 6: return_trace (c->dispatch (u.format6, std::forward<Ts> (ds)...));
|
2018-11-06 18:11:45 +01:00
|
|
|
default: return_trace (c->default_return_value ());
|
2018-10-07 20:01:33 +02:00
|
|
|
}
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-10-11 00:14:41 +02:00
|
|
|
if (!u.header.sanitize (c) ||
|
2018-11-23 04:02:19 +01:00
|
|
|
u.header.length <= u.header.static_size ||
|
2018-10-11 00:14:41 +02:00
|
|
|
!c->check_range (this, u.header.length))
|
2018-03-01 21:37:26 +01:00
|
|
|
return_trace (false);
|
|
|
|
|
2018-10-07 20:01:33 +02:00
|
|
|
return_trace (dispatch (c));
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
public:
|
2018-02-19 00:47:44 +01:00
|
|
|
union {
|
2018-11-07 16:19:46 +01:00
|
|
|
KerxSubTableHeader header;
|
|
|
|
KerxSubTableFormat0<KerxSubTableHeader> format0;
|
|
|
|
KerxSubTableFormat1<KerxSubTableHeader> format1;
|
|
|
|
KerxSubTableFormat2<KerxSubTableHeader> format2;
|
|
|
|
KerxSubTableFormat4<KerxSubTableHeader> format4;
|
|
|
|
KerxSubTableFormat6<KerxSubTableHeader> format6;
|
2018-02-19 00:47:44 +01:00
|
|
|
} u;
|
2018-11-07 19:40:22 +01:00
|
|
|
public:
|
2018-03-01 21:37:26 +01:00
|
|
|
DEFINE_SIZE_MIN (12);
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-10-07 20:01:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The 'kerx' Table
|
|
|
|
*/
|
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
template <typename T>
|
|
|
|
struct KerxTable
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-11-07 19:40:22 +01:00
|
|
|
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
|
2018-12-17 19:01:01 +01:00
|
|
|
const T* thiz () const { return static_cast<const T *> (this); }
|
2018-02-19 00:47:44 +01:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool has_state_machine () const
|
2018-11-23 17:10:17 +01:00
|
|
|
{
|
|
|
|
typedef typename T::SubTable SubTable;
|
|
|
|
|
|
|
|
const SubTable *st = &thiz()->firstSubTable;
|
|
|
|
unsigned int count = thiz()->tableCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (st->get_type () == 1)
|
2019-08-24 15:27:14 +02:00
|
|
|
return true;
|
2018-11-23 17:10:17 +01:00
|
|
|
st = &StructAfter<SubTable> (*st);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool has_cross_stream () const
|
2018-11-07 22:02:40 +01:00
|
|
|
{
|
|
|
|
typedef typename T::SubTable SubTable;
|
|
|
|
|
|
|
|
const SubTable *st = &thiz()->firstSubTable;
|
|
|
|
unsigned int count = thiz()->tableCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (st->u.header.coverage & st->u.header.CrossStream)
|
2019-08-24 15:27:14 +02:00
|
|
|
return true;
|
2018-11-07 22:02:40 +01:00
|
|
|
st = &StructAfter<SubTable> (*st);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
|
2018-11-07 19:40:22 +01:00
|
|
|
{
|
|
|
|
typedef typename T::SubTable SubTable;
|
2018-11-07 19:33:23 +01:00
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
int v = 0;
|
|
|
|
const SubTable *st = &thiz()->firstSubTable;
|
|
|
|
unsigned int count = thiz()->tableCount;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if ((st->u.header.coverage & (st->u.header.Variation | st->u.header.CrossStream)) ||
|
|
|
|
!st->u.header.is_horizontal ())
|
2019-08-24 15:27:14 +02:00
|
|
|
continue;
|
2018-11-07 19:40:22 +01:00
|
|
|
v += st->get_kerning (left, right);
|
|
|
|
st = &StructAfter<SubTable> (*st);
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2018-10-07 20:01:33 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool apply (AAT::hb_aat_apply_context_t *c) const
|
2018-02-24 10:19:42 +01:00
|
|
|
{
|
2023-01-10 21:23:19 +01:00
|
|
|
c->buffer->unsafe_to_concat ();
|
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
typedef typename T::SubTable SubTable;
|
|
|
|
|
2018-11-07 22:03:09 +01:00
|
|
|
bool ret = false;
|
2018-11-07 20:38:29 +01:00
|
|
|
bool seenCrossStream = false;
|
2018-10-07 20:01:33 +02:00
|
|
|
c->set_lookup_index (0);
|
2018-11-07 19:40:22 +01:00
|
|
|
const SubTable *st = &thiz()->firstSubTable;
|
|
|
|
unsigned int count = thiz()->tableCount;
|
2018-10-07 20:01:33 +02:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2018-10-09 04:41:08 +02:00
|
|
|
bool reverse;
|
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
if (!T::Types::extended && (st->u.header.coverage & st->u.header.Variation))
|
2019-08-24 15:27:14 +02:00
|
|
|
goto skip;
|
2018-11-07 19:40:22 +01:00
|
|
|
|
2018-11-07 18:32:39 +01:00
|
|
|
if (HB_DIRECTION_IS_HORIZONTAL (c->buffer->props.direction) != st->u.header.is_horizontal ())
|
2018-10-10 23:32:32 +02:00
|
|
|
goto skip;
|
2018-10-09 04:41:08 +02:00
|
|
|
|
2018-11-07 19:58:41 +01:00
|
|
|
reverse = bool (st->u.header.coverage & st->u.header.Backwards) !=
|
2018-10-09 04:41:08 +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 subtable %u", c->lookup_index))
|
2018-10-10 23:32:32 +02:00
|
|
|
goto skip;
|
2018-10-09 04:41:08 +02:00
|
|
|
|
2018-11-07 20:38:29 +01:00
|
|
|
if (!seenCrossStream &&
|
|
|
|
(st->u.header.coverage & st->u.header.CrossStream))
|
|
|
|
{
|
2019-08-24 15:27:14 +02:00
|
|
|
/* Attach all glyphs into a chain. */
|
|
|
|
seenCrossStream = true;
|
2018-11-07 20:38:29 +01:00
|
|
|
hb_glyph_position_t *pos = c->buffer->pos;
|
|
|
|
unsigned int count = c->buffer->len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2022-06-29 02:52:27 +02:00
|
|
|
pos[i].attach_type() = OT::Layout::GPOS_impl::ATTACH_TYPE_CURSIVE;
|
2018-11-07 20:38:29 +01:00
|
|
|
pos[i].attach_chain() = HB_DIRECTION_IS_FORWARD (c->buffer->props.direction) ? -1 : +1;
|
|
|
|
/* We intentionally don't set HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT,
|
|
|
|
* since there needs to be a non-zero attachment for post-positioning to
|
|
|
|
* be needed. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 04:41:08 +02:00
|
|
|
if (reverse)
|
2018-10-10 23:32:32 +02:00
|
|
|
c->buffer->reverse ();
|
2018-10-09 04:41:08 +02:00
|
|
|
|
2018-11-25 05:49:23 +01:00
|
|
|
{
|
|
|
|
/* See comment in sanitize() for conditional here. */
|
|
|
|
hb_sanitize_with_object_t with (&c->sanitizer, i < count - 1 ? st : (const SubTable *) nullptr);
|
|
|
|
ret |= st->dispatch (c);
|
|
|
|
}
|
2018-10-09 04:41:08 +02:00
|
|
|
|
|
|
|
if (reverse)
|
2018-10-10 23:32:32 +02:00
|
|
|
c->buffer->reverse ();
|
2018-10-09 04:41:08 +02:00
|
|
|
|
2023-01-13 01:04:24 +01:00
|
|
|
(void) c->buffer->message (c->font, "end subtable %u", c->lookup_index);
|
2018-10-09 04:41:08 +02:00
|
|
|
|
|
|
|
skip:
|
2018-11-07 19:33:23 +01:00
|
|
|
st = &StructAfter<SubTable> (*st);
|
2018-11-06 19:51:39 +01:00
|
|
|
c->set_lookup_index (c->lookup_index + 1);
|
2018-10-07 20:01:33 +02:00
|
|
|
}
|
2018-11-07 22:03:09 +01:00
|
|
|
|
|
|
|
return ret;
|
2018-02-24 10:19:42 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-03-01 21:37:26 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2018-11-07 19:40:22 +01:00
|
|
|
if (unlikely (!thiz()->version.sanitize (c) ||
|
2018-11-29 21:01:10 +01:00
|
|
|
(unsigned) thiz()->version < (unsigned) T::minVersion ||
|
2018-11-07 19:40:22 +01:00
|
|
|
!thiz()->tableCount.sanitize (c)))
|
2018-03-01 21:37:26 +01:00
|
|
|
return_trace (false);
|
2018-02-19 00:47:44 +01:00
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
typedef typename T::SubTable SubTable;
|
|
|
|
|
|
|
|
const SubTable *st = &thiz()->firstSubTable;
|
|
|
|
unsigned int count = thiz()->tableCount;
|
2018-10-07 20:01:33 +02:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2018-02-19 00:47:44 +01:00
|
|
|
{
|
2018-11-25 04:16:53 +01:00
|
|
|
if (unlikely (!st->u.header.sanitize (c)))
|
|
|
|
return_trace (false);
|
|
|
|
/* OpenType kern table has 2-byte subtable lengths. That's limiting.
|
|
|
|
* MS implementation also only supports one subtable, of format 0,
|
|
|
|
* anyway. Certain versions of some fonts, like Calibry, contain
|
|
|
|
* kern subtable that exceeds 64kb. Looks like, the subtable length
|
|
|
|
* is simply ignored. Which makes sense. It's only needed if you
|
|
|
|
* have multiple subtables. To handle such fonts, we just ignore
|
|
|
|
* the length for the last subtable. */
|
2018-11-25 05:49:23 +01:00
|
|
|
hb_sanitize_with_object_t with (c, i < count - 1 ? st : (const SubTable *) nullptr);
|
2018-11-25 04:16:53 +01:00
|
|
|
|
2018-11-07 19:40:22 +01:00
|
|
|
if (unlikely (!st->sanitize (c)))
|
2018-10-07 20:01:33 +02:00
|
|
|
return_trace (false);
|
2018-11-25 05:49:23 +01:00
|
|
|
|
2018-11-07 19:33:23 +01:00
|
|
|
st = &StructAfter<SubTable> (*st);
|
2018-02-19 00:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
}
|
2018-11-07 19:40:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct kerx : KerxTable<kerx>
|
|
|
|
{
|
|
|
|
friend struct KerxTable<kerx>;
|
|
|
|
|
2019-01-22 12:08:57 +01:00
|
|
|
static constexpr hb_tag_t tableTag = HB_AAT_TAG_kerx;
|
2019-01-22 12:11:24 +01:00
|
|
|
static constexpr unsigned minVersion = 2u;
|
2018-11-07 19:40:22 +01:00
|
|
|
|
|
|
|
typedef KerxSubTableHeader SubTableHeader;
|
|
|
|
typedef SubTableHeader::Types Types;
|
|
|
|
typedef KerxSubTable SubTable;
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool has_data () const { return version; }
|
2018-02-19 00:47:44 +01:00
|
|
|
|
|
|
|
protected:
|
2018-10-07 20:01:33 +02:00
|
|
|
HBUINT16 version; /* The version number of the extended kerning table
|
|
|
|
* (currently 2, 3, or 4). */
|
|
|
|
HBUINT16 unused; /* Set to 0. */
|
|
|
|
HBUINT32 tableCount; /* The number of subtables included in the extended kerning
|
|
|
|
* table. */
|
2018-11-07 19:33:23 +01:00
|
|
|
SubTable firstSubTable; /* Subtables. */
|
2018-10-07 20:01:33 +02:00
|
|
|
/*subtableGlyphCoverageArray*/ /* Only if version >= 3. We don't use. */
|
|
|
|
|
2018-02-19 00:47:44 +01:00
|
|
|
public:
|
2018-10-07 20:01:33 +02:00
|
|
|
DEFINE_SIZE_MIN (8);
|
2018-02-19 00:47:44 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 16:39:39 +01:00
|
|
|
|
2018-02-19 00:47:44 +01:00
|
|
|
} /* namespace AAT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_AAT_LAYOUT_KERX_TABLE_HH */
|