[HarfBuzz] harfbuzz: Branch 'master' - 3 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu Nov 2 00:14:14 UTC 2017


 src/hb-ot-kern-table.hh |  137 ++++++++++++++++++++++++++++++++++++++++--------
 src/hb-uniscribe.cc     |    4 -
 2 files changed, 118 insertions(+), 23 deletions(-)

New commits:
commit 2c439210c9734cd21b08beba07d21147a6eb6d8a
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Nov 1 18:13:35 2017 -0600

    [uniscribe] Fix a couple of VS warnings

diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 93e338df..b28e7f04 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -499,7 +499,7 @@ populate_log_font (LOGFONTW  *lf,
 		   unsigned int font_size)
 {
   memset (lf, 0, sizeof (*lf));
-  lf->lfHeight = -font_size;
+  lf->lfHeight = - (int) font_size;
   lf->lfCharSet = DEFAULT_CHARSET;
 
   hb_face_t *face = font->face;
@@ -858,7 +858,7 @@ retry:
   unsigned int glyphs_offset = 0;
   unsigned int glyphs_len;
   bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
-  for (unsigned int i = 0; i < item_count; i++)
+  for (int i = 0; i < item_count; i++)
   {
     unsigned int chars_offset = items[i].iCharPos;
     unsigned int item_chars_len = items[i + 1].iCharPos - chars_offset;
commit 4c43a23bf479b42d42192bab56df6075c8ae0090
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Nov 1 18:12:26 2017 -0600

    [kern] Implement Format0

diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh
index 37658ab2..1d98d33d 100644
--- a/src/hb-ot-kern-table.hh
+++ b/src/hb-ot-kern-table.hh
@@ -38,23 +38,62 @@ namespace OT {
 
 #define HB_OT_TAG_kern HB_TAG('k','e','r','n')
 
+struct hb_glyph_pair_t
+{
+  hb_codepoint_t left;
+  hb_codepoint_t right;
+};
 
-struct KernSubTableFormat0
+struct KernPair
 {
-  inline unsigned int get_size (void) const
+  inline int get_kerning (void) const
+  { return value; }
+
+  inline int cmp (const hb_glyph_pair_t &o) const
   {
-    /* XXX */
-    return 0;
+    int ret = left.cmp (o.left);
+    if (ret) return ret;
+    return right.cmp (o.right);
   }
 
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
+    return_trace (c->check_struct (this));
+  }
 
-    /* XXX */
+  protected:
+  GlyphID	left;
+  GlyphID	right;
+  FWORD		value;
+  public:
+  DEFINE_SIZE_STATIC (6);
+};
 
-    return_trace (true);
+struct KernSubTableFormat0
+{
+  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 unsigned int get_size (void) const
+  { return pairs.get_size (); }
+
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+    return_trace (pairs.sanitize (c));
+  }
+
+  protected:
+  BinSearchArrayOf<KernPair> pairs;	/* Array of kerning pairs. */
+  public:
+  DEFINE_SIZE_ARRAY (8, pairs);
 };
 
 struct KernSubTableFormat2
commit ac3d937c6cb0e2c7e019aa391b02da25aa6970de
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Nov 1 17:54:56 2017 -0600

    [kern] Implement some more

diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh
index b3de99ce..37658ab2 100644
--- a/src/hb-ot-kern-table.hh
+++ b/src/hb-ot-kern-table.hh
@@ -39,29 +39,89 @@ namespace OT {
 #define HB_OT_TAG_kern HB_TAG('k','e','r','n')
 
 
+struct KernSubTableFormat0
+{
+  inline unsigned int get_size (void) const
+  {
+    /* XXX */
+    return 0;
+  }
+
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+
+    /* XXX */
+
+    return_trace (true);
+  }
+};
+
+struct KernSubTableFormat2
+{
+  inline unsigned int get_size (void) const
+  {
+    /* XXX */
+    return 0;
+  }
+
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+
+    /* XXX */
+
+    return_trace (true);
+  }
+};
+
+struct KernSubTable
+{
+  inline unsigned int get_size (unsigned int format) const
+  {
+    switch (format) {
+    case 0: return u.format0.get_size ();
+    case 2: return u.format2.get_size ();
+    default:return 0;
+    }
+  }
+
+  inline bool sanitize (hb_sanitize_context_t *c, unsigned int format) const
+  {
+    TRACE_SANITIZE (this);
+    switch (format) {
+    case 0: return_trace (u.format0.sanitize (c));
+    case 2: return_trace (u.format2.sanitize (c));
+    default:return_trace (true);
+    }
+  }
+
+  protected:
+  union {
+  KernSubTableFormat0	format0;
+  KernSubTableFormat2	format2;
+  } u;
+  public:
+  DEFINE_SIZE_MIN (0);
+};
+
 
 template <typename T>
 struct KernSubTableWrapper
 {
   /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
   inline const T* thiz (void) const { return static_cast<const T *> (this); }
-  inline T* thiz (void) { return static_cast<T *> (this); }
 
   inline unsigned int get_size (void) const { return thiz()->length; }
-  inline const void *get_data (void) const { return thiz()->data; }
-  inline unsigned int get_format (void) const { return thiz()->format; }
 
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
-    if (unlikely (!c->check_struct (thiz()) ||
-		  get_size () < thiz()->min_size ||
-		  !c->check_array (thiz(), 1, get_size ())))
-      return_trace (false);
-
-    /* XXX */
-
-    return_trace (true);
+    return_trace (c->check_struct (thiz()) &&
+		  thiz()->length >= thiz()->min_size &&
+		  c->check_array (thiz(), 1, thiz()->length) &&
+		  thiz()->subtable.sanitize (c, thiz()->format) &&
+		  thiz()->subtable.get_size (thiz()-> format) <= thiz()->length - thiz()->min_size);
   }
 };
 
@@ -70,10 +130,6 @@ struct KernTable
 {
   /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
   inline const T* thiz (void) const { return static_cast<const T *> (this); }
-  inline T* thiz (void) { return static_cast<T *> (this); }
-
-  inline unsigned int get_num_tables (void) const { return thiz()->nTables; }
-  inline const void *get_data (void) const { return thiz()->data; }
 
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
@@ -82,8 +138,8 @@ struct KernTable
 		  thiz()->version != T::VERSION))
       return_trace (false);
 
-    const typename T::SubTableWrapper *st = CastP<typename T::SubTableWrapper> (get_data ());
-    unsigned int count = get_num_tables ();
+    const typename T::SubTableWrapper *st = CastP<typename T::SubTableWrapper> (thiz()->data);
+    unsigned int count = thiz()->nTables;
     for (unsigned int i = 0; i < count; i++)
     {
       if (unlikely (!st->sanitize (c)))
@@ -110,9 +166,9 @@ struct KernOT : KernTable<KernOT>
     USHORT	length;		/* Length of the subtable (including this header). */
     BYTE	format;		/* Subtable format. */
     BYTE	coverage;	/* Coverage bits. */
-    BYTE	data[VAR];	/* Subtable data. */
+    KernSubTable subtable;	/* Subtable data. */
     public:
-    DEFINE_SIZE_ARRAY (6, data);
+    DEFINE_SIZE_MIN (6);
   };
 
   protected:
@@ -139,9 +195,9 @@ struct KernAAT : KernTable<KernAAT>
     BYTE	format;		/* Subtable format. */
     USHORT	tupleIndex;	/* The tuple index (used for variations fonts).
 				 * This value specifies which tuple this subtable covers. */
-    BYTE	data[VAR];	/* Subtable data. */
+    KernSubTable subtable;	/* Subtable data. */
     public:
-    DEFINE_SIZE_ARRAY (8, data);
+    DEFINE_SIZE_MIN (8);
   };
 
   protected:


More information about the HarfBuzz mailing list