From 5b17853547ca6848ee652ef6990a81bb345ac06f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 7 Nov 2018 10:45:25 -0500 Subject: [PATCH] [kern/kerx] Share Format0 --- src/hb-aat-layout-kerx-table.hh | 22 +++++++++++---- src/hb-ot-kern-table.hh | 50 +++++---------------------------- 2 files changed, 23 insertions(+), 49 deletions(-) diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index dcab790d2..9cdba8797 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -93,6 +93,14 @@ struct KernPair template 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 (&(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 (&(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 (&(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. */ diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index c7c15e880..e065b6ff0 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -41,47 +41,6 @@ namespace OT { -template -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 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 - pairs; /* Array of kerning pairs. */ - public: - DEFINE_SIZE_ARRAY (KernSubTableHeader::static_size + 8, pairs); -}; - template struct KernSubTableFormat1 { @@ -445,7 +404,7 @@ struct KernSubTable public: union { KernSubTableHeader header; - KernSubTableFormat0 format0; + AAT::KerxSubTableFormat0 format0; KernSubTableFormat1 format1; KernSubTableFormat2 format2; KernSubTableFormat3 format3; @@ -544,6 +503,8 @@ struct KernOT : KernTable { typedef AAT::MortTypes Types; + unsigned int tuple_count (void) const { return 0; } + enum Coverage { Direction = 0x01u, @@ -589,6 +550,8 @@ struct KernAAT : KernTable { typedef AAT::MortTypes Types; + unsigned int tuple_count (void) const { return 0; } + enum Coverage { Direction = 0x80u, @@ -609,7 +572,8 @@ struct KernAAT : KernTable 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); };