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

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu Aug 30 19:53:53 PDT 2012


 src/hb-open-type-private.hh        |   99 +++++++++++++++++++++++++++++++++++++
 src/hb-ot-layout-common-private.hh |   62 +++++++++++++++++++++++
 src/hb-ot-shape-fallback.cc        |    8 +-
 3 files changed, 165 insertions(+), 4 deletions(-)

New commits:
commit 5a7f18767a87a3f07269d0814f984a98f86ab852
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Aug 30 22:53:29 2012 -0400

    [OT] Better fallback-position Thai / Lao ccc!=0 marks

diff --git a/src/hb-ot-shape-fallback.cc b/src/hb-ot-shape-fallback.cc
index aa6239c..abacfa3 100644
--- a/src/hb-ot-shape-fallback.cc
+++ b/src/hb-ot-shape-fallback.cc
@@ -105,19 +105,19 @@ recategorize_combining_class (unsigned int modified_combining_class)
      * But viramas can be both above and below based on the codepoint / script. */
 
     case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */
-      return HB_UNICODE_COMBINING_CLASS_BELOW;
+      return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
 
     case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */
-      return HB_UNICODE_COMBINING_CLASS_ABOVE;
+      return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
 
 
     /* Lao */
 
     case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */
-      return HB_UNICODE_COMBINING_CLASS_BELOW;
+      return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
 
     case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */
-      return HB_UNICODE_COMBINING_CLASS_ABOVE;
+      return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
 
 
     /* Tibetan */
commit 9f2348de58f0f85593027378169bc03c4dd64e59
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Aug 29 21:08:59 2012 -0400

    [OT] Add serialize() for Coverage

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 7cd8212..10e777e 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -337,7 +337,7 @@ struct Sanitizer
 
 
 #define TRACE_SERIALIZE() \
-	hb_auto_trace_t<HB_DEBUG_SERIALIZE> trace (&c->debug_depth, "SERIALIZE", this, HB_FUNC, "");
+	hb_auto_trace_t<HB_DEBUG_SERIALIZE> trace (&c->debug_depth, "SERIALIZE", c, HB_FUNC, "");
 
 
 struct hb_serialize_context_t
@@ -371,25 +371,43 @@ struct hb_serialize_context_t
   }
 
   template <typename Type>
-  inline Type *allocate (unsigned int size = -1, unsigned int alignment = 2)
+  inline Type *allocate (unsigned int size, unsigned int alignment = 2)
   {
-    if (size == -1)
-      size == Type::static_size;
     unsigned int padding = (alignment - (this->head - this->start) % alignment) % alignment; /* TODO speedup */
     if (unlikely (this->ran_out_of_room || this->end - this->head > padding + size)) {
       this->ran_out_of_room = true;
       return NULL;
     }
     this->head += padding;
-    const char *ret = this->head;
+    char *ret = this->head;
     this->head += size;
     return reinterpret_cast<Type *> (ret);
   }
 
   template <typename Type>
+  inline Type *allocate_min (unsigned int alignment = 2)
+  {
+    return this->allocate<Type> (Type::min_size, alignment);
+  }
+
+  template <typename Type>
   inline Type *embed (const Type &obj, unsigned int alignment = 2)
   {
-    return allocate (obj.size (), alignment);
+    return this->allocate<Type> (obj.get_size (), alignment);
+  }
+
+  template <typename Type>
+  inline Type *extend (Type &obj, unsigned int size, unsigned int alignment = 2)
+  {
+    assert (this->start < (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head);
+    this->allocate<Type> (((char *) &obj) + size - this->head, alignment);
+    return reinterpret_cast<Type *> (&obj);
+  }
+
+  template <typename Type>
+  inline Type *extend (Type &obj)
+  {
+    return this->extend<Type> (obj, obj.get_size ());
   }
 
   inline void truncate (void *head)
@@ -630,6 +648,10 @@ struct GenericArrayOf
     if (unlikely (i >= len)) return Null(Type);
     return array[i];
   }
+  inline Type& operator [] (unsigned int i)
+  {
+    return array[i];
+  }
   inline unsigned int get_size (void) const
   { return len.static_size + len * Type::static_size; }
 
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 48c7e0c..91d5a19 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -355,6 +355,21 @@ struct CoverageFormat1
     return i;
   }
 
+  inline static bool serialize (hb_serialize_context_t *c,
+				const USHORT *glyphs,
+				unsigned int num_glyphs)
+  {
+    TRACE_SERIALIZE ();
+    CoverageFormat1 *t = c->allocate_min<CoverageFormat1> ();
+    if (unlikely (!t)) return TRACE_RETURN (false);
+    t->coverageFormat.set (1);
+    t->glyphArray.len.set (num_glyphs);
+    if (unlikely (!c->extend (t->glyphArray))) return TRACE_RETURN (false);
+    for (unsigned int i = 0; i < num_glyphs; i++)
+      t->glyphArray[i].set (glyphs[i]);
+    return TRACE_RETURN (true);
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
     return TRACE_RETURN (glyphArray.sanitize (c));
@@ -406,6 +421,35 @@ struct CoverageFormat2
     return NOT_COVERED;
   }
 
+  inline static bool serialize (hb_serialize_context_t *c,
+				const USHORT *glyphs,
+				unsigned int num_glyphs)
+  {
+    TRACE_SERIALIZE ();
+    CoverageFormat2 *t = c->allocate_min<CoverageFormat2> ();
+    unsigned int num_ranges = 1;
+    for (unsigned int i = 1; i < num_glyphs; i++)
+      if (glyphs[i - 1] + 1 != glyphs[i])
+        num_ranges++;
+    if (unlikely (!t)) return TRACE_RETURN (false);
+    t->coverageFormat.set (2);
+    t->rangeRecord.len.set (num_ranges);
+    if (unlikely (!c->extend (t->rangeRecord))) return TRACE_RETURN (false);
+    if (unlikely (!num_glyphs)) return TRACE_RETURN (true);
+    unsigned int range = 0;
+    t->rangeRecord[range].start.set (glyphs[0]);
+    t->rangeRecord[range].value.set (0);
+    for (unsigned int i = 1; i < num_glyphs; i++)
+      if (glyphs[i - 1] + 1 != glyphs[i]) {
+	t->rangeRecord[range].start.set (glyphs[i]);
+	t->rangeRecord[range].value.set (i);
+	range++;
+      } else {
+        t->rangeRecord[range].end = glyphs[i];
+      }
+    return TRACE_RETURN (true);
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
     return TRACE_RETURN (rangeRecord.sanitize (c));
@@ -482,6 +526,24 @@ struct Coverage
     }
   }
 
+  inline static bool serialize (hb_serialize_context_t *c,
+				const USHORT *glyphs,
+				unsigned int num_glyphs)
+  {
+    TRACE_SERIALIZE ();
+    unsigned int format;
+    unsigned int num_ranges = 1;
+    for (unsigned int i = 1; i < num_glyphs; i++)
+      if (glyphs[i - 1] + 1 != glyphs[i])
+        num_ranges++;
+    format = num_glyphs * 2 < num_ranges * 3 ? 1 : 2;
+    switch (format) {
+    case 1: return TRACE_RETURN (CoverageFormat1::serialize (c, glyphs, num_glyphs));
+    case 2: return TRACE_RETURN (CoverageFormat2::serialize (c, glyphs, num_glyphs));
+    default:return TRACE_RETURN (false);
+    }
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
     if (!u.format.sanitize (c)) return TRACE_RETURN (false);
commit e901b954c6ec44ac3ae7fb3c326e6e7a40718e4b
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Aug 29 20:26:08 2012 -0400

    [OT] Start adding serialize() API

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 4cbb855..7cd8212 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -327,6 +327,83 @@ struct Sanitizer
 
 
 
+/*
+ * Serialize
+ */
+
+#ifndef HB_DEBUG_SERIALIZE
+#define HB_DEBUG_SERIALIZE (HB_DEBUG+0)
+#endif
+
+
+#define TRACE_SERIALIZE() \
+	hb_auto_trace_t<HB_DEBUG_SERIALIZE> trace (&c->debug_depth, "SERIALIZE", this, HB_FUNC, "");
+
+
+struct hb_serialize_context_t
+{
+  inline void init (void *start, unsigned int size)
+  {
+    this->start = (char *) start;
+    this->end = this->start + size;
+  }
+
+  inline void start_processing (void)
+  {
+    this->ran_out_of_room = false;
+    this->head = this->start;
+    this->debug_depth = 0;
+
+    DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, +1,
+		     "start [%p..%p] (%lu bytes)",
+		     this->start, this->end,
+		     (unsigned long) (this->end - this->start));
+  }
+
+  inline void end_processing (void)
+  {
+    DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, -1,
+		     "end [%p..%p] %s",
+		     this->start, this->end,
+		     this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room");
+
+    this->start = this->end = this->head = NULL;
+  }
+
+  template <typename Type>
+  inline Type *allocate (unsigned int size = -1, unsigned int alignment = 2)
+  {
+    if (size == -1)
+      size == Type::static_size;
+    unsigned int padding = (alignment - (this->head - this->start) % alignment) % alignment; /* TODO speedup */
+    if (unlikely (this->ran_out_of_room || this->end - this->head > padding + size)) {
+      this->ran_out_of_room = true;
+      return NULL;
+    }
+    this->head += padding;
+    const char *ret = this->head;
+    this->head += size;
+    return reinterpret_cast<Type *> (ret);
+  }
+
+  template <typename Type>
+  inline Type *embed (const Type &obj, unsigned int alignment = 2)
+  {
+    return allocate (obj.size (), alignment);
+  }
+
+  inline void truncate (void *head)
+  {
+    assert (this->start < head && head <= this->head);
+    this->head = (char *) head;
+  }
+
+  unsigned int debug_depth;
+  char *start, *end, *head;
+  bool ran_out_of_room;
+};
+
+
 
 /*
  *



More information about the HarfBuzz mailing list