[kern/kerx] Share Format0

This commit is contained in:
Behdad Esfahbod committed 2018-11-07 10:45:25 -05:00
1 parent c97dde5d55
commit 5b17853547
2 files changed
+23 -49

No files matched your search

+16 -6
View File
@@ -93,6 +93,14 @@ struct KernPair
template <typename KernSubTableHeader>
struct KerxSubTableFormat0
{
inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
{
hb_glyph_pair_t pair = {left, right};
int i = pairs.bsearch (pair);
if (i == -1) return 0;
return pairs[i].get_kerning ();
}
inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right,
hb_aat_apply_context_t *c) const
{
@@ -100,7 +108,7 @@ struct KerxSubTableFormat0
int i = pairs.bsearch (pair);
if (i == -1) return 0;
int v = pairs[i].get_kerning ();
return kerxTupleKern (v, header.tupleCount, this, c);
return kerxTupleKern (v, header.tuple_count (), this, c);
}
inline bool apply (hb_aat_apply_context_t *c) const
@@ -310,7 +318,7 @@ struct KerxSubTableFormat1
if (header.coverage & header.CrossStream)
return false;
if (header.tupleCount)
if (header.tuple_count ())
return_trace (false); /* TODO kerxTupleKern */
driver_context_t dc (this, c);
@@ -349,7 +357,7 @@ struct KerxSubTableFormat2
unsigned int offset = l + r;
const FWORD *v = &StructAtOffset<FWORD> (&(this+array), offset);
if (unlikely (!v->sanitize (&c->sanitizer))) return 0;
return kerxTupleKern (*v, header.tupleCount, this, c);
return kerxTupleKern (*v, header.tuple_count (), this, c);
}
inline bool apply (hb_aat_apply_context_t *c) const
@@ -601,7 +609,7 @@ struct KerxSubTableFormat6
if (unlikely (hb_unsigned_mul_overflows (offset, sizeof (FWORD32)))) return 0;
const FWORD32 *v = &StructAtOffset<FWORD32> (&(this+t.array), offset * sizeof (FWORD32));
if (unlikely (!v->sanitize (&c->sanitizer))) return 0;
return kerxTupleKern (*v, header.tupleCount, &(this+vector), c);
return kerxTupleKern (*v, header.tuple_count (), &(this+vector), c);
}
else
{
@@ -611,7 +619,7 @@ struct KerxSubTableFormat6
unsigned int offset = l + r;
const FWORD *v = &StructAtOffset<FWORD> (&(this+t.array), offset * sizeof (FWORD));
if (unlikely (!v->sanitize (&c->sanitizer))) return 0;
return kerxTupleKern (*v, header.tupleCount, &(this+vector), c);
return kerxTupleKern (*v, header.tuple_count (), &(this+vector), c);
}
}
@@ -646,7 +654,7 @@ struct KerxSubTableFormat6
u.s.columnIndexTable.sanitize (c, this) &&
c->check_range (this, u.s.array)
)) &&
(header.tupleCount == 0 ||
(header.tuple_count () == 0 ||
c->check_range (this, vector))));
}
@@ -693,6 +701,8 @@ struct KerxSubTableHeader
{
typedef MorxTypes Types;
unsigned int tuple_count (void) const { return tupleCount; }
enum Coverage
{
Vertical = 0x80000000, /* Set if table has vertical kerning values. */
+7 -43
View File
@@ -41,47 +41,6 @@
namespace OT {
template <typename KernSubTableHeader>
struct KernSubTableFormat0
{
inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
{
AAT::hb_glyph_pair_t pair = {left, right};
int i = pairs.bsearch (pair);
if (i == -1) return 0;
return pairs[i].get_kerning ();
}
inline bool apply (AAT::hb_aat_apply_context_t *c) const
{
TRACE_APPLY (this);
if (!c->plan->requested_kerning)
return false;
if (header.coverage & header.CrossStream)
return false;
hb_kern_machine_t<KernSubTableFormat0> machine (*this);
machine.kern (c->font, c->buffer, c->plan->kern_mask);
return_trace (true);
}
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (pairs.sanitize (c));
}
protected:
KernSubTableHeader header;
BinSearchArrayOf<AAT::KernPair, typename KernSubTableHeader::Types::HBUINT>
pairs; /* Array of kerning pairs. */
public:
DEFINE_SIZE_ARRAY (KernSubTableHeader::static_size + 8, pairs);
};
template <typename KernSubTableHeader>
struct KernSubTableFormat1
{
@@ -445,7 +404,7 @@ struct KernSubTable
public:
union {
KernSubTableHeader header;
KernSubTableFormat0<KernSubTableHeader> format0;
AAT::KerxSubTableFormat0<KernSubTableHeader> format0;
KernSubTableFormat1<KernSubTableHeader> format1;
KernSubTableFormat2<KernSubTableHeader> format2;
KernSubTableFormat3<KernSubTableHeader> format3;
@@ -544,6 +503,8 @@ struct KernOT : KernTable<KernOT>
{
typedef AAT::MortTypes Types;
unsigned int tuple_count (void) const { return 0; }
enum Coverage
{
Direction = 0x01u,
@@ -589,6 +550,8 @@ struct KernAAT : KernTable<KernAAT>
{
typedef AAT::MortTypes Types;
unsigned int tuple_count (void) const { return 0; }
enum Coverage
{
Direction = 0x80u,
@@ -609,7 +572,8 @@ struct KernAAT : KernTable<KernAAT>
HBUINT8 coverage; /* Coverage bits. */
HBUINT8 format; /* Subtable format. */
HBUINT16 tupleIndex; /* The tuple index (used for variations fonts).
* This value specifies which tuple this subtable covers. */
* This value specifies which tuple this subtable covers.
* Note: We don't implement. */
public:
DEFINE_SIZE_STATIC (8);
};