[HarfBuzz] harfbuzz-ng: Branch 'master' - 11 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Sep 28 13:30:41 PDT 2010


 TODO                               |    4 +
 src/Makefile.am                    |    6 +-
 src/hb-font.cc                     |    4 -
 src/hb-font.h                      |    3 -
 src/hb-open-type-private.hh        |    6 +-
 src/hb-ot-layout-common-private.hh |   31 +++++++++---
 src/hb-ot-layout.cc                |   11 ++--
 src/hb-ot-shape.cc                 |    8 +--
 src/test.c                         |   94 +++++++++++++++++++++++++++++++++++++
 9 files changed, 142 insertions(+), 25 deletions(-)

New commits:
commit 4e573715ae5f5ed486ad66382bb44c47a86591ff
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Sep 28 16:23:58 2010 -0400

    Improve cmp function parameter namings and casts
    
    No semantic change.

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index ae01ef9..62a7c88 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -397,7 +397,7 @@ struct IntType
   inline operator Type(void) const { return v; }
   inline bool operator == (const IntType<Type> &o) const { return v == o.v; }
   inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
-  inline int cmp (Type b) const { Type a = v; return b < a ? -1 : b == a ? 0 : +1; }
+  inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; }
   inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
     return likely (c->check_struct (this));
@@ -719,8 +719,8 @@ struct SortedArrayOf : ArrayOf<Type> {
   inline int search (const SearchType &x) const {
     class Cmp {
       public: static int cmp (const void *p1, const void *p2) {
-	const SearchType *a = (const SearchType *) p1;
-	const Type *b = (const Type *) p2;
+	const SearchType *a = reinterpret_cast<const SearchType *>(p1);
+	const Type *b = reinterpret_cast<const Type *>(p2);
 	return b->cmp (*a);
       }
     };
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index ded683d..5db8f67 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -56,9 +56,9 @@ HB_END_DECLS
 template <typename Type>
 struct Record
 {
-  inline int cmp (hb_tag_t b) const {
-    hb_tag_t a = tag;
-    return b < a ? -1 : b == a ? 0 : +1;
+  inline int cmp (hb_tag_t a) const {
+    hb_tag_t b = tag;
+    return a < b ? -1 : a == b ? 0 : +1;
   }
 
   inline bool sanitize (hb_sanitize_context_t *c, void *base) {
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 34ac89b..4173942 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -105,8 +105,8 @@ struct hb_mask_allocator_t {
     static int
     cmp (const void *p1, const void *p2)
     {
-      const feature_info_t *a = (const feature_info_t *) p1;
-      const feature_info_t *b = (const feature_info_t *) p2;
+      const feature_info_t *a = reinterpret_cast<const feature_info_t *>(p1);
+      const feature_info_t *b = reinterpret_cast<const feature_info_t *>(p2);
 
       if (a->tag != b->tag)
         return a->tag < b->tag ? -1 : 1;
@@ -124,8 +124,8 @@ struct hb_mask_allocator_t {
     static int
     cmp (const void *p1, const void *p2)
     {
-      const feature_map_t *a = (const feature_map_t *) p1;
-      const feature_map_t *b = (const feature_map_t *) p2;
+      const feature_map_t *a = reinterpret_cast<const feature_map_t *>(p1);
+      const feature_map_t *b = reinterpret_cast<const feature_map_t *>(p2);
 
       return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0;
     }
commit dca8aff24652c83c53efbb9d06e5e1c7ef1c2fa5
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Sep 28 16:25:23 2010 -0400

    Add comment re DejaVu Sans Mono having 'dflt' script

diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index 17bd37a..5126f37 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -373,7 +373,8 @@ hb_ot_layout_table_find_script (hb_face_t    *face,
   if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
     return FALSE;
 
-  /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
+  /* try with 'dflt'; MS site has had typos and many fonts use it now :(.
+   * including many versions of DejaVu Sans Mono! */
   if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
     return FALSE;
 
commit 9dc45401c07cb40114067cafbe286c63a9598f3b
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Sep 28 16:23:28 2010 -0400

    Fix stupid bug in bsearch cmp function!

diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index edd08c8..ded683d 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -58,7 +58,7 @@ struct Record
 {
   inline int cmp (hb_tag_t b) const {
     hb_tag_t a = tag;
-    return b < a ? -1 : b == a ? 0 : -1;
+    return b < a ? -1 : b == a ? 0 : +1;
   }
 
   inline bool sanitize (hb_sanitize_context_t *c, void *base) {
commit 6fca4c18c42bdcbc67ee8855499c51c7d6311eb2
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Sep 23 10:28:51 2010 -0400

    Add TODO iteam

diff --git a/TODO b/TODO
index eba078c..2537bb6 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+- Rename get_table to reference_table
+
 - head table access cleanup (div by zero now!)
 - cache various expensive scale computation
 
commit f2a30bd605a57b99fce4b78e288c2ca62f7191ad
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Sep 23 10:27:08 2010 -0400

    Remove unimplemented method hb_font_get_funcs()
    
    Got to add a suitable replacement.

diff --git a/src/hb-font.h b/src/hb-font.h
index 19247ef..6f1f3ca 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -174,9 +174,6 @@ hb_font_set_funcs (hb_font_t         *font,
 		   hb_destroy_func_t  destroy,
 		   void              *user_data);
 
-hb_font_funcs_t *
-hb_font_get_funcs (hb_font_t       *font);
-
 
 /*
  * We should add support for full matrices.
commit 7b9a38a112aa2421d97187a9b30619360edeabbe
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Sep 22 17:42:59 2010 -0400

    Add test.c using public API

diff --git a/src/Makefile.am b/src/Makefile.am
index 409c939..ea6fb50 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,12 +106,16 @@ libharfbuzz_la_CPPFLAGS = $(HBCFLAGS)
 libharfbuzz_la_LIBADD = $(HBLIBS)
 pkginclude_HEADERS = $(HBHEADERS)
 
-noinst_PROGRAMS = main
+noinst_PROGRAMS = main test
 
 main_SOURCES = main.cc
 main_CPPFLAGS = $(HBCFLAGS)
 main_LDADD = libharfbuzz.la $(HBLIBS)
 
+test_SOURCES = test.c
+test_CPPFLAGS = $(HBCFLAGS)
+test_LDADD = libharfbuzz.la $(HBLIBS)
+
 TESTS = \
 	check-c-linkage-decls.sh \
 	check-header-guards.sh \
diff --git a/src/test.c b/src/test.c
new file mode 100644
index 0000000..836dd4c
--- /dev/null
+++ b/src/test.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010  Google, Inc.
+ *
+ *  This is part of HarfBuzz, a text shaping library.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and its documentation for any purpose, provided that the
+ * above copyright notice and the following two paragraphs appear in
+ * all copies of this software.
+ *
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+ * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Red Hat Author(s): Behdad Esfahbod
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "hb.h"
+
+#ifdef HAVE_GLIB
+#include <glib.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+
+HB_BEGIN_DECLS
+
+
+int
+main (int argc, char **argv)
+{
+  hb_blob_t *blob = NULL;
+  hb_face_t *face = NULL;
+
+  if (argc != 2) {
+    fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]);
+    exit (1);
+  }
+
+  /* Create the blob */
+  {
+    const char *font_data;
+    unsigned int len;
+    hb_destroy_func_t destroy;
+    void *user_data;
+
+#ifdef HAVE_GLIB
+    GMappedFile *mf = g_mapped_file_new (argv[1], FALSE, NULL);
+    font_data = g_mapped_file_get_contents (mf);
+    len = g_mapped_file_get_length (mf);
+    destroy = (hb_destroy_func_t) g_mapped_file_unref;
+    user_data = (void *) mf;
+#else
+    FILE *f = fopen (argv[1], "rb");
+    fseek (f, 0, SEEK_END);
+    len = ftell (f);
+    fseek (f, 0, SEEK_SET);
+    font_data = (const char *) malloc (len);
+    if (!font_data) len = 0;
+    len = fread ((char *) font_data, 1, len, f);
+    destroy = free;
+    user_data = (void *) font_data;
+    fclose (f);
+#endif
+
+    blob = hb_blob_create (font_data, len,
+			   HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE,
+			   destroy, user_data);
+  }
+
+  /* Create the face */
+  face = hb_face_create_for_data (blob, 0 /* first face */);
+
+  /* So, what now? */
+
+  hb_face_destroy (face);
+  hb_blob_destroy (blob);
+
+  return 0;
+}
commit 9ea7368fce3fa373d8d2925961ad211f5cf6ce70
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Sep 22 17:38:44 2010 -0400

    Fix hb_ot_layout leak

diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index 965a2fb..17bd37a 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -71,6 +71,8 @@ _hb_ot_layout_free (hb_ot_layout_t *layout)
   hb_blob_destroy (layout->gpos_blob);
 
   free (layout->new_gdef.klasses);
+
+  free (layout);
 }
 
 static const GDEF&
commit 8e577acae2e605547b6a1b9b3a941cb9e3c56a4c
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Sep 22 17:37:02 2010 -0400

    Fix blob refcounting with insane SFNT table directories

diff --git a/src/hb-font.cc b/src/hb-font.cc
index a1535f1..8a547a3 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -312,9 +312,7 @@ hb_face_t *
 hb_face_create_for_data (hb_blob_t    *blob,
 			 unsigned int  index)
 {
-  hb_blob_reference (blob);
-  hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer<OpenTypeFontFile>::sanitize (blob), index);
-  hb_blob_destroy (blob);
+  hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index);
 
   if (unlikely (!closure))
     return &_hb_face_nil;
commit 75371bea4fbf50b8604d2698b4935c011648a6b6
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Sep 22 17:12:10 2010 -0400

    Add TODO item

diff --git a/TODO b/TODO
index 98391ab..eba078c 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,8 @@
 - head table access cleanup (div by zero now!)
 - cache various expensive scale computation
 
+- SFNT api?  get_num_faces?
+
 - GNOME Bug 612402 - (hb-arm) HarfBuzz compilation fix for arm
 
 - Make sure LangSys default feature is only applied once...
commit 5bd1e95236320aed60fb29ca1e93b9595d4aeeec
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Sep 22 16:46:18 2010 -0400

    Speedup Device table delta computation for common cases

diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index c4a4055..edd08c8 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007,2008,2009  Red Hat, Inc.
+ * Copyright (C) 2010  Google, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -22,6 +23,7 @@
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  *
  * Red Hat Author(s): Behdad Esfahbod
+ * Google Author(s): Behdad Esfahbod
  */
 
 #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH
@@ -519,15 +521,30 @@ struct ClassDef
 
 struct Device
 {
-  /* XXX speed up */
 
   inline hb_position_t get_x_delta (hb_ot_layout_context_t *c) const
-  { return c->font->x_ppem ? get_delta (c->font->x_ppem) * (uint64_t) c->font->x_scale / c->font->x_ppem : 0; }
+  { return get_delta (c->font->x_ppem, c->font->x_scale); }
 
   inline hb_position_t get_y_delta (hb_ot_layout_context_t *c) const
-  { return c->font->y_ppem ? get_delta (c->font->y_ppem) * (uint64_t) c->font->y_scale / c->font->y_ppem : 0; }
+  { return get_delta (c->font->y_ppem, c->font->y_scale); }
 
-  inline int get_delta (unsigned int ppem_size) const
+  inline int get_delta (unsigned int ppem, unsigned int scale) const
+  {
+    if (!ppem) return 0;
+
+    int pixels = get_delta_pixels (ppem);
+
+    if (!pixels) return 0;
+
+    /* pixels is at most in the -8..7 range.  So 64-bit arithmetic is
+     * not really necessary here.  A simple cast to int may just work
+     * as well.  But since this code is not reached that often and
+     * for the sake of correctness, we do a 64bit operation. */
+    return pixels * (int64_t) scale / ppem;
+  }
+
+
+  inline int get_delta_pixels (unsigned int ppem_size) const
   {
     unsigned int f = deltaFormat;
     if (unlikely (f < 1 || f > 3))
commit ed4acbde9c5e3323cc95037b500d1bf2878ed3ee
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 16 14:36:27 2010 -0400

    Fix NULL dereference
    
    Reported by Jonathan Kew.  Face table handling needs to be redone
    anyway, but fix this for now.

diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index 31451fc..965a2fb 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -76,19 +76,19 @@ _hb_ot_layout_free (hb_ot_layout_t *layout)
 static const GDEF&
 _get_gdef (hb_face_t *face)
 {
-  return likely (face->ot_layout->gdef) ? *face->ot_layout->gdef : Null(GDEF);
+  return likely (face->ot_layout && face->ot_layout->gdef) ? *face->ot_layout->gdef : Null(GDEF);
 }
 
 static const GSUB&
 _get_gsub (hb_face_t *face)
 {
-  return likely (face->ot_layout->gsub) ? *face->ot_layout->gsub : Null(GSUB);
+  return likely (face->ot_layout && face->ot_layout->gsub) ? *face->ot_layout->gsub : Null(GSUB);
 }
 
 static const GPOS&
 _get_gpos (hb_face_t *face)
 {
-  return likely (face->ot_layout->gpos) ? *face->ot_layout->gpos : Null(GPOS);
+  return likely (face->ot_layout && face->ot_layout->gpos) ? *face->ot_layout->gpos : Null(GPOS);
 }
 
 



More information about the HarfBuzz mailing list