[kern/kerx] Share Format1 subtable
This commit is contained in:
parent
a244190afa
commit
c808e444da
|
@ -250,12 +250,12 @@ struct KerxSubTableFormat1
|
|||
* from the actual stateTableOffset, use it as the initial state."
|
||||
*/
|
||||
|
||||
inline bool is_actionable (StateTableDriver<MorxTypes, EntryData> *driver HB_UNUSED,
|
||||
inline bool is_actionable (StateTableDriver<Types, EntryData> *driver HB_UNUSED,
|
||||
const Entry<EntryData> *entry)
|
||||
{
|
||||
return Format1EntryT::performAction (entry);
|
||||
}
|
||||
inline bool transition (StateTableDriver<MorxTypes, EntryData> *driver,
|
||||
inline bool transition (StateTableDriver<Types, EntryData> *driver,
|
||||
const Entry<EntryData> *entry)
|
||||
{
|
||||
hb_buffer_t *buffer = driver->buffer;
|
||||
|
@ -376,15 +376,12 @@ struct KerxSubTableFormat1
|
|||
if (!c->plan->requested_kerning)
|
||||
return false;
|
||||
|
||||
if (header.coverage & header.CrossStream)
|
||||
return false;
|
||||
|
||||
if (header.tuple_count ())
|
||||
return_trace (false); /* TODO kerxTupleKern */
|
||||
|
||||
driver_context_t dc (this, c);
|
||||
|
||||
StateTableDriver<MorxTypes, EntryData> driver (machine, c->buffer, c->font->face);
|
||||
StateTableDriver<Types, EntryData> driver (machine, c->buffer, c->font->face);
|
||||
driver.drive (&dc);
|
||||
|
||||
return_trace (true);
|
||||
|
|
|
@ -41,191 +41,6 @@
|
|||
namespace OT {
|
||||
|
||||
|
||||
template <typename KernSubTableHeader>
|
||||
struct KernSubTableFormat1
|
||||
{
|
||||
typedef void EntryData;
|
||||
|
||||
struct driver_context_t
|
||||
{
|
||||
static const bool in_place = true;
|
||||
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. */
|
||||
};
|
||||
|
||||
inline driver_context_t (const KernSubTableFormat1 *table_,
|
||||
AAT::hb_aat_apply_context_t *c_) :
|
||||
c (c_),
|
||||
table (table_),
|
||||
/* 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. */
|
||||
kernAction (&table->machine + table->kernAction),
|
||||
depth (0),
|
||||
crossStream (table->header.coverage & table->header.CrossStream),
|
||||
crossOffset (0) {}
|
||||
|
||||
/* TODO
|
||||
*
|
||||
* "Because the stateTableOffset in the state table header is (strictly
|
||||
* speaking) redundant, some 'kern' tables use it to record an initial
|
||||
* state where that should not be StartOfText. To determine if this is
|
||||
* done, calculate what the stateTableOffset should be. If it's different
|
||||
* from the actual stateTableOffset, use it as the initial state."
|
||||
*/
|
||||
|
||||
inline bool is_actionable (AAT::StateTableDriver<AAT::MortTypes, EntryData> *driver HB_UNUSED,
|
||||
const AAT::Entry<EntryData> *entry)
|
||||
{
|
||||
return entry->flags & Offset;
|
||||
}
|
||||
inline bool transition (AAT::StateTableDriver<AAT::MortTypes, EntryData> *driver,
|
||||
const AAT::Entry<EntryData> *entry)
|
||||
{
|
||||
hb_buffer_t *buffer = driver->buffer;
|
||||
unsigned int flags = entry->flags;
|
||||
|
||||
if (flags & Push)
|
||||
{
|
||||
if (likely (depth < ARRAY_LENGTH (stack)))
|
||||
stack[depth++] = buffer->idx;
|
||||
else
|
||||
depth = 0; /* Probably not what CoreText does, but better? */
|
||||
}
|
||||
|
||||
if (entry->flags & Offset)
|
||||
{
|
||||
unsigned int kernIndex = AAT::MortTypes::offsetToIndex (entry->flags & Offset,
|
||||
&table->machine,
|
||||
kernAction.arrayZ);
|
||||
const FWORD *actions = &kernAction[kernIndex];
|
||||
if (!c->sanitizer.check_array (actions, depth))
|
||||
{
|
||||
depth = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hb_mask_t kern_mask = c->plan->kern_mask;
|
||||
|
||||
/* "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... */
|
||||
unsigned int i;
|
||||
for (i = 0; i < depth; i++)
|
||||
if (actions[i] & 1)
|
||||
{
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
for (; i; i--)
|
||||
{
|
||||
unsigned int idx = stack[depth - i];
|
||||
int v = actions[i - 1];
|
||||
|
||||
/* "The end of the list is marked by an odd value..."
|
||||
* Ignore it. */
|
||||
v &= ~1;
|
||||
|
||||
/* The following flag is undocumented in the spec, but described
|
||||
* in the example. */
|
||||
if (v == -0x8000)
|
||||
{
|
||||
crossOffset = 0;
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (idx < buffer->len && buffer->info[idx].mask & kern_mask)
|
||||
{
|
||||
if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction))
|
||||
{
|
||||
if (crossStream)
|
||||
{
|
||||
crossOffset += v;
|
||||
if (!buffer->pos[idx].y_offset)
|
||||
buffer->pos[idx].y_offset += c->font->em_scale_y (crossOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!buffer->pos[idx].x_offset)
|
||||
{
|
||||
buffer->pos[idx].x_advance += c->font->em_scale_x (v);
|
||||
buffer->pos[idx].x_offset += c->font->em_scale_x (v);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (crossStream)
|
||||
{
|
||||
/* CoreText doesn't do crossStream kerning in vertical. We do. */
|
||||
crossOffset += v;
|
||||
if (!buffer->pos[idx].x_offset)
|
||||
buffer->pos[idx].x_offset = c->font->em_scale_x (crossOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!buffer->pos[idx].y_offset)
|
||||
{
|
||||
buffer->pos[idx].y_advance += c->font->em_scale_y (v);
|
||||
buffer->pos[idx].y_offset += c->font->em_scale_y (v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
depth = 0;
|
||||
}
|
||||
else
|
||||
buffer->pos[buffer->idx].y_offset += c->font->em_scale_y (crossOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
AAT::hb_aat_apply_context_t *c;
|
||||
const KernSubTableFormat1 *table;
|
||||
const UnsizedArrayOf<FWORD> &kernAction;
|
||||
unsigned int stack[8];
|
||||
unsigned int depth;
|
||||
bool crossStream;
|
||||
int crossOffset;
|
||||
};
|
||||
|
||||
inline bool apply (AAT::hb_aat_apply_context_t *c) const
|
||||
{
|
||||
TRACE_APPLY (this);
|
||||
|
||||
if (!c->plan->requested_kerning)
|
||||
return false;
|
||||
|
||||
driver_context_t dc (this, c);
|
||||
|
||||
AAT::StateTableDriver<AAT::MortTypes, EntryData> driver (machine, c->buffer, c->font->face);
|
||||
driver.drive (&dc);
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
/* The rest of array sanitizations are done at run-time. */
|
||||
return_trace (likely (c->check_struct (this) &&
|
||||
machine.sanitize (c)));
|
||||
}
|
||||
|
||||
protected:
|
||||
KernSubTableHeader header;
|
||||
AAT::StateTable<AAT::MortTypes, EntryData> machine;
|
||||
OffsetTo<UnsizedArrayOf<FWORD>, HBUINT16, false> kernAction;
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (KernSubTableHeader::static_size + 10);
|
||||
};
|
||||
|
||||
template <typename KernSubTableHeader>
|
||||
struct KernSubTableFormat2
|
||||
{
|
||||
|
@ -405,7 +220,7 @@ struct KernSubTable
|
|||
union {
|
||||
KernSubTableHeader header;
|
||||
AAT::KerxSubTableFormat0<KernSubTableHeader> format0;
|
||||
KernSubTableFormat1<KernSubTableHeader> format1;
|
||||
AAT::KerxSubTableFormat1<KernSubTableHeader> format1;
|
||||
KernSubTableFormat2<KernSubTableHeader> format2;
|
||||
KernSubTableFormat3<KernSubTableHeader> format3;
|
||||
} u;
|
||||
|
|
Loading…
Reference in New Issue