[HarfBuzz] harfbuzz: Branch 'master'

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Nov 6 20:30:01 UTC 2017


 src/hb-ot-font.cc       |   23 ++++++++++++++++++++++-
 src/hb-ot-kern-table.hh |   41 +++++++++++++++++++++++++++++------------
 2 files changed, 51 insertions(+), 13 deletions(-)

New commits:
commit 82a38d1f7a65537a4ef540af08c489512d6297ac
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Nov 6 15:28:24 2017 -0500

    [kern] Allow subtables longer than 64kb
    
    Apparently calibri.ttf does this:
    https://github.com/fonttools/fonttools/pull/1094#discussion_r148933791

diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index d9896035..72d3c583 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -335,6 +335,27 @@ struct hb_ot_face_post_accelerator_t
   }
 };
 
+struct hb_ot_face_kern_accelerator_t
+{
+  hb_blob_t *kern_blob;
+  OT::kern::accelerator_t accel;
+
+  inline void init (hb_face_t *face)
+  {
+    hb_blob_t *blob = this->kern_blob = OT::Sanitizer<OT::kern>::sanitize (face->reference_table (HB_OT_TAG_kern));
+    accel.init (OT::Sanitizer<OT::kern>::lock_instance (blob), hb_blob_get_length (blob));
+  }
+
+  inline void fini (void)
+  {
+    accel.fini ();
+    hb_blob_destroy (this->kern_blob);
+  }
+
+  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+  { return accel.get_h_kerning (left, right); }
+};
+
 typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
 					  hb_codepoint_t codepoint,
 					  hb_codepoint_t *glyph);
@@ -471,7 +492,7 @@ struct hb_ot_font_t
   OT::hb_lazy_loader_t<hb_ot_face_glyf_accelerator_t> glyf;
   OT::hb_lazy_loader_t<hb_ot_face_cbdt_accelerator_t> cbdt;
   OT::hb_lazy_loader_t<hb_ot_face_post_accelerator_t> post;
-  OT::hb_lazy_table_loader_t<OT::kern> kern;
+  OT::hb_lazy_loader_t<hb_ot_face_kern_accelerator_t> kern;
 };
 
 
diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh
index 2d355914..d074355d 100644
--- a/src/hb-ot-kern-table.hh
+++ b/src/hb-ot-kern-table.hh
@@ -112,7 +112,7 @@ struct KernClassTable
 
 struct KernSubTableFormat2
 {
-  inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, unsigned int length) const
+  inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, const char *end) const
   {
     unsigned int l = (this+leftClassTable).get_class (left);
     unsigned int r = (this+leftClassTable).get_class (left);
@@ -145,11 +145,11 @@ struct KernSubTableFormat2
 
 struct KernSubTable
 {
-  inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, unsigned int length, unsigned int format) const
+  inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, const char *end, unsigned int format) const
   {
     switch (format) {
     case 0: return u.format0.get_kerning (left, right);
-    case 2: return u.format2.get_kerning (left, right, length);
+    case 2: return u.format2.get_kerning (left, right, end);
     default:return 0;
     }
   }
@@ -186,11 +186,11 @@ struct KernSubTableWrapper
   inline bool is_override (void) const
   { return bool (thiz()->coverage & T::COVERAGE_OVERRIDE_FLAG); }
 
-  inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
-  { return thiz()->subtable.get_kerning (left, right, thiz()->length - thiz()->min_size, thiz()->format); }
+  inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, const char *end) const
+  { return thiz()->subtable.get_kerning (left, right, end, thiz()->format); }
 
-  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
-  { return is_horizontal () ? get_kerning (left, right) : 0; }
+  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right, const char *end) const
+  { return is_horizontal () ? get_kerning (left, right, end) : 0; }
 
   inline unsigned int get_size (void) const { return thiz()->length; }
 
@@ -210,7 +210,7 @@ struct KernTable
   /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
   inline const T* thiz (void) const { return static_cast<const T *> (this); }
 
-  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right, unsigned int table_length) const
   {
     int v = 0;
     const typename T::SubTableWrapper *st = CastP<typename T::SubTableWrapper> (thiz()->data);
@@ -219,7 +219,7 @@ struct KernTable
     {
       if (st->is_override ())
         v = 0;
-      v += st->get_h_kerning (left, right);
+      v += st->get_h_kerning (left, right, table_length + (const char *) this);
       st = &StructAfter<typename T::SubTableWrapper> (*st);
     }
     return v;
@@ -329,11 +329,11 @@ struct kern
 {
   static const hb_tag_t tableTag = HB_OT_TAG_kern;
 
-  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+  inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right, unsigned int table_length) const
   {
     switch (u.major) {
-    case 0: return u.ot.get_h_kerning (left, right);
-    case 1: return u.aat.get_h_kerning (left, right);
+    case 0: return u.ot.get_h_kerning (left, right, table_length);
+    case 1: return u.aat.get_h_kerning (left, right, table_length);
     default:return 0;
     }
   }
@@ -349,6 +349,23 @@ struct kern
     }
   }
 
+  struct accelerator_t
+  {
+    inline void init (const kern *table_, unsigned int table_length_)
+    {
+      table = table_;
+      table_length = table_length_;
+    }
+    inline void fini (void) {}
+
+    inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+    { return table->get_h_kerning (left, right, table_length); }
+
+    private:
+    const kern *table;
+    unsigned int table_length;
+  };
+
   protected:
   union {
   USHORT		major;


More information about the HarfBuzz mailing list