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

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon May 2 08:24:44 UTC 2016


 src/Makefile.sources                                                    |    1 
 src/hb-open-type-private.hh                                             |   12 -
 src/hb-ot-font.cc                                                       |   46 +++
 src/hb-ot-post-table.hh                                                 |  119 ++++++++++
 test/shaping/Makefile.am                                                |    1 
 test/shaping/fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf |binary
 test/shaping/tests/fallback-positioning.test                            |    2 
 7 files changed, 178 insertions(+), 3 deletions(-)

New commits:
commit f00ab2a33ab34ba64f38cbbe65830c770a3e071e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon May 2 10:24:00 2016 +0200

    [hb-ot-font] Make 'glyf' table loading lazy
    
    Apparently some clients have reference-table callbacks that copy the table.
    As such, avoid loading 'glyf' table which is only needed if fallback positioning
    happens.

diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 23ac41a..8b62bb1 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -300,13 +300,54 @@ struct hb_ot_face_cmap_accelerator_t
   }
 };
 
+template <typename T>
+struct hb_lazy_loader_t
+{
+  inline void init (hb_face_t *face_)
+  {
+    face = face_;
+    instance = NULL;
+  }
+
+  inline void fini (void)
+  {
+    if (instance && instance != &OT::Null(T))
+    {
+      instance->fini();
+      free (instance);
+    }
+  }
+
+  inline const T* operator-> (void) const
+  {
+  retry:
+    T *p = (T *) hb_atomic_ptr_get (&instance);
+    if (unlikely (!p))
+    {
+      p = (T *) calloc (1, sizeof (T));
+      if (unlikely (!p))
+        return &OT::Null(T);
+      p->init (face);
+      if (unlikely (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), NULL, p)))
+      {
+	p->fini ();
+	goto retry;
+      }
+    }
+    return p;
+  }
+
+  private:
+  hb_face_t *face;
+  T *instance;
+};
 
 struct hb_ot_font_t
 {
   hb_ot_face_cmap_accelerator_t cmap;
   hb_ot_face_metrics_accelerator_t h_metrics;
   hb_ot_face_metrics_accelerator_t v_metrics;
-  hb_ot_face_glyf_accelerator_t glyf;
+  hb_lazy_loader_t<hb_ot_face_glyf_accelerator_t> glyf;
 };
 
 
@@ -390,7 +431,7 @@ hb_ot_get_glyph_extents (hb_font_t *font HB_UNUSED,
 			 void *user_data HB_UNUSED)
 {
   const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
-  bool ret = ot_font->glyf.get_extents (glyph, extents);
+  bool ret = ot_font->glyf->get_extents (glyph, extents);
   extents->x_bearing = font->em_scale_x (extents->x_bearing);
   extents->y_bearing = font->em_scale_y (extents->y_bearing);
   extents->width     = font->em_scale_x (extents->width);
diff --git a/test/shaping/Makefile.am b/test/shaping/Makefile.am
index 6320b02..b3b6300 100644
--- a/test/shaping/Makefile.am
+++ b/test/shaping/Makefile.am
@@ -47,6 +47,7 @@ TESTS = \
 	tests/context-matching.tests \
 	tests/cursive-positioning.tests \
 	tests/default-ignorables.tests \
+	tests/fallback-positioning.test \
 	tests/fuzzed.tests \
 	tests/hangul-jamo.tests \
 	tests/hyphens.tests \
diff --git a/test/shaping/fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf b/test/shaping/fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf
new file mode 100644
index 0000000..fb4534a
Binary files /dev/null and b/test/shaping/fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf differ
diff --git a/test/shaping/tests/fallback-positioning.test b/test/shaping/tests/fallback-positioning.test
new file mode 100644
index 0000000..499db7d
--- /dev/null
+++ b/test/shaping/tests/fallback-positioning.test
@@ -0,0 +1,2 @@
+fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ft:U+0078,U+0301,U+0058,U+0301:[x=0+1030|acutecomb=0 at -45,-32+0|X=2+1295|acutecomb=2 at -171,310+0]
+fonts/sha1sum/7ef276fc886ea502a03b9b0e5c8b547d5dc2b61c.ttf:--font-funcs=ot:U+0078,U+0301,U+0058,U+0301:[gid2=0+1030|gid4=0 at -21,-27+0|gid1=2+1295|gid4=2 at -147,321+0]
commit 587d46227a56940a7f5bb053cbeda6144394acf7
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Apr 30 19:20:56 2016 +0200

    [ot-font] Start implementing 'post' table, for accessing glyph names

diff --git a/src/Makefile.sources b/src/Makefile.sources
index 171c513..ac80683 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -28,6 +28,7 @@ HB_BASE_sources = \
 	hb-ot-maxp-table.hh \
 	hb-ot-name-table.hh \
 	hb-ot-os2-table.hh \
+	hb-ot-post-table.hh \
 	hb-ot-tag.cc \
 	hb-private.hh \
 	hb-set-private.hh \
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 80ad687..df683ca 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -101,7 +101,8 @@ static inline Type& StructAfter(TObject &X)
 #define DEFINE_SIZE_STATIC(size) \
   DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)); \
   static const unsigned int static_size = (size); \
-  static const unsigned int min_size = (size)
+  static const unsigned int min_size = (size); \
+  inline unsigned int get_size (void) const { return (size); }
 
 #define DEFINE_SIZE_UNION(size, _member) \
   DEFINE_INSTANCE_ASSERTION (this->u._member.static_size == (size)); \
@@ -671,6 +672,15 @@ struct F2DOT14 : SHORT
   DEFINE_SIZE_STATIC (2);
 };
 
+/* 32-bit signed fixed-point number (16.16). */
+struct Fixed: LONG
+{
+  //inline float to_float (void) const { return ???; }
+  //inline void set_float (float f) { v.set (f * ???); }
+  public:
+  DEFINE_SIZE_STATIC (4);
+};
+
 /* Date represented in number of seconds since 12:00 midnight, January 1,
  * 1904. The value is represented as a signed 64-bit integer. */
 struct LONGDATETIME
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 61c7036..23ac41a 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -36,6 +36,7 @@
 #include "hb-ot-hhea-table.hh"
 #include "hb-ot-hmtx-table.hh"
 #include "hb-ot-os2-table.hh"
+#include "hb-ot-post-table.hh"
 
 
 struct hb_ot_face_metrics_accelerator_t
diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh
new file mode 100644
index 0000000..82ab388
--- /dev/null
+++ b/src/hb-ot-post-table.hh
@@ -0,0 +1,119 @@
+/*
+ * Copyright © 2016  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.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#ifndef HB_OT_POST_TABLE_HH
+#define HB_OT_POST_TABLE_HH
+
+#include "hb-open-type-private.hh"
+
+
+namespace OT {
+
+
+/*
+ * post -- PostScript
+ */
+
+#define HB_OT_TAG_post HB_TAG('p','o','s','t')
+
+
+struct postV2Tail
+{
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+    return_trace (numberOfGlyphs.sanitize (c) &&
+		  c->check_array (glyphNameIndex, sizeof (USHORT), numberOfGlyphs));
+  }
+
+  USHORT	numberOfGlyphs;		/* Number of glyphs (this should be the
+					 * same as numGlyphs in 'maxp' table). */
+  USHORT	glyphNameIndex[VAR];	/* This is not an offset, but is the
+					 * ordinal number of the glyph in 'post'
+					 * string tables. */
+  BYTE		namesX[VAR];		/* Glyph names with length bytes [variable]
+					 * (a Pascal string). */
+
+  DEFINE_SIZE_ARRAY2 (2, glyphNameIndex, namesX);
+};
+
+struct post
+{
+  static const hb_tag_t tableTag = HB_OT_TAG_post;
+
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+    if (unlikely (!c->check_struct (this)))
+      return_trace (false);
+    if (version.to_int () == 0x00020000)
+    {
+      const postV2Tail &v2 = StructAfter<postV2Tail>(*this);
+      return_trace (v2.sanitize (c));
+    }
+    return_trace (true);
+  }
+
+  public:
+  FixedVersion<>version;		/* 0x00010000 for version 1.0
+					 * 0x00020000 for version 2.0
+					 * 0x00025000 for version 2.5 (deprecated)
+					 * 0x00030000 for version 3.0 */
+  Fixed		italicAngle;		/* Italic angle in counter-clockwise degrees
+					 * from the vertical. Zero for upright text,
+					 * negative for text that leans to the right
+					 * (forward). */
+  FWORD		underlinePosition;	/* This is the suggested distance of the top
+					 * of the underline from the baseline
+					 * (negative values indicate below baseline).
+					 * The PostScript definition of this FontInfo
+					 * dictionary key (the y coordinate of the
+					 * center of the stroke) is not used for
+					 * historical reasons. The value of the
+					 * PostScript key may be calculated by
+					 * subtracting half the underlineThickness
+					 * from the value of this field. */
+  FWORD		underlineThickness;	/* Suggested values for the underline
+					   thickness. */
+  ULONG		isFixedPitch;		/* Set to 0 if the font is proportionally
+					 * spaced, non-zero if the font is not
+					 * proportionally spaced (i.e. monospaced). */
+  ULONG		minMemType42;		/* Minimum memory usage when an OpenType font
+					 * is downloaded. */
+  ULONG		maxMemType42;		/* Maximum memory usage when an OpenType font
+					 * is downloaded. */
+  ULONG		minMemType1;		/* Minimum memory usage when an OpenType font
+					 * is downloaded as a Type 1 font. */
+  ULONG		maxMemType1;		/* Maximum memory usage when an OpenType font
+					 * is downloaded as a Type 1 font. */
+/*postV2Tail	v2[VAR];*/
+  DEFINE_SIZE_STATIC (32);
+};
+
+} /* namespace OT */
+
+
+#endif /* HB_OT_POST_TABLE_HH */


More information about the HarfBuzz mailing list