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

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu May 20 07:41:38 PDT 2010


 src/hb-ot-shape.cc |   69 +++++++++++++++++++++++++++++++++++++++++------------
 src/hb-private.h   |   35 ++++++++++++++++----------
 2 files changed, 76 insertions(+), 28 deletions(-)

New commits:
commit 6774463883978b00b4d8c719ed75edfc4537c77f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 20 15:40:12 2010 +0100

    Apply user features to ranges!

diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 81892a2..509ce7d 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -116,12 +116,33 @@ setup_lookups (hb_face_t    *face,
       add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
   }
 
+  /* Clear buffer masks. */
+  unsigned int count = buffer->len;
+  for (unsigned int i = 0; i < count; i++)
+    buffer->info[i].mask = 1;
+
+  unsigned int last_bit_used = 1;
   for (i = 0; i < num_features; i++)
   {
+    unsigned int bits_needed = _hb_bit_storage (features[i].value);
+    if (!bits_needed)
+      continue;
+    unsigned int mask = (1 << (last_bit_used + bits_needed)) - (1 << last_bit_used);
+    unsigned int value = features[i].value << last_bit_used;
+    last_bit_used += bits_needed;
+
     if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index,
 					    features[i].tag,
 					    &feature_index))
-      add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
+      add_feature (face, table_tag, feature_index, mask, lookups, num_lookups, room_lookups);
+
+    /* Turn mask on in the buffer, the über-slow way! */
+    unsigned int count = buffer->len;
+    for (unsigned int i = 0; i < count; i++) {
+        unsigned int cluster = buffer->info[i].cluster;
+	if (features[i].start <= cluster && cluster < features[i].end)
+	  buffer->info[i].mask |= value;
+    }
   }
 
   qsort (lookups, *num_lookups, sizeof (lookups[0]), cmp_lookups);
commit 9b6023338530a2dbb8214eb4391ef3e8372f3892
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 20 15:31:12 2010 +0100

    Add _hb_bit_storage()

diff --git a/src/hb-private.h b/src/hb-private.h
index f017bf9..78d2bf1 100644
--- a/src/hb-private.h
+++ b/src/hb-private.h
@@ -136,27 +136,36 @@
 #endif
 
 
-/* Return the number of 1 bits in mask.
- *
- * GCC 3.4 supports a "population count" builtin, which on many targets is
- * implemented with a single instruction. There is a fallback definition
- * in libgcc in case a target does not have one, which should be just as
- * good as the open-coded solution below, (which is "HACKMEM 169").
- */
+/* Return the number of 1 bits in mask. */
 static inline HB_CONST_FUNC unsigned int
 _hb_popcount32 (uint32_t mask)
 {
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
-    return __builtin_popcount (mask);
+  return __builtin_popcount (mask);
 #else
-    register uint32_t y;
-
-    y = (mask >> 1) &033333333333;
-    y = mask - y - ((y >>1) & 033333333333);
-    return (((y + (y >> 3)) & 030707070707) % 077);
+  /* "HACKMEM 169" */
+  register uint32_t y;
+  y = (mask >> 1) &033333333333;
+  y = mask - y - ((y >>1) & 033333333333);
+  return (((y + (y >> 3)) & 030707070707) % 077);
 #endif
 }
 
+/* Returns the number of bits needed to store number */
+static inline HB_CONST_FUNC unsigned int
+_hb_bit_storage (unsigned int number)
+{
+#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
+  return likely (number) ? (sizeof (unsigned int) * 8 - __builtin_clzl(number)) : 0;
+#else
+  register unsigned int n_bits = 0;
+  while (number) {
+    n_bits++;
+    number >>= 1;
+  }
+  return n_bits;
+#endif
+}
 
 /* We need external help for these */
 
commit 6b1b957f6d2955cbe4fa97e2659e033b3eaaf4d2
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 20 15:14:44 2010 +0100

    Add lookup_map

diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index c7afdc3..81892a2 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -42,29 +42,45 @@ hb_tag_t default_features[] = {
   HB_TAG('m','k','m','k'),
 };
 
+struct lookup_map {
+  unsigned int index;
+  hb_mask_t mask;
+};
+
 
 static void
 add_feature (hb_face_t    *face,
 	     hb_tag_t      table_tag,
 	     unsigned int  feature_index,
-	     unsigned int *lookups,
+	     hb_mask_t     mask,
+	     lookup_map   *lookups,
 	     unsigned int *num_lookups,
 	     unsigned int  room_lookups)
 {
   unsigned int i = room_lookups - *num_lookups;
+  lookups += *num_lookups;
+
+  unsigned int *lookup_indices = (unsigned int *) lookups;
+
   hb_ot_layout_feature_get_lookup_indexes (face, table_tag, feature_index, 0,
 					   &i,
-					   lookups + *num_lookups);
+					   lookup_indices);
+
   *num_lookups += i;
+
+  while (i--) {
+    lookups[i].mask = mask;
+    lookups[i].index = lookup_indices[i];
+  }
 }
 
 static int
 cmp_lookups (const void *p1, const void *p2)
 {
-  unsigned int a = * (const unsigned int *) p1;
-  unsigned int b = * (const unsigned int *) p2;
+  const lookup_map *a = (const lookup_map *) p1;
+  const lookup_map *b = (const lookup_map *) p2;
 
-  return a - b;
+  return a->index - b->index;
 }
 
 static void
@@ -73,7 +89,7 @@ setup_lookups (hb_face_t    *face,
 	       hb_feature_t *features,
 	       unsigned int  num_features,
 	       hb_tag_t      table_tag,
-	       unsigned int *lookups,
+	       lookup_map   *lookups,
 	       unsigned int *num_lookups)
 {
   unsigned int i, j, script_index, language_index, feature_index, room_lookups;
@@ -90,14 +106,14 @@ setup_lookups (hb_face_t    *face,
 
   if (hb_ot_layout_language_get_required_feature_index (face, table_tag, script_index, language_index,
 							&feature_index))
-    add_feature (face, table_tag, feature_index, lookups, num_lookups, room_lookups);
+    add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
 
   for (i = 0; i < ARRAY_LENGTH (default_features); i++)
   {
     if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index,
 					    default_features[i],
 					    &feature_index))
-      add_feature (face, table_tag, feature_index, lookups, num_lookups, room_lookups);
+      add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
   }
 
   for (i = 0; i < num_features; i++)
@@ -105,7 +121,7 @@ setup_lookups (hb_face_t    *face,
     if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index,
 					    features[i].tag,
 					    &feature_index))
-      add_feature (face, table_tag, feature_index, lookups, num_lookups, room_lookups);
+      add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
   }
 
   qsort (lookups, *num_lookups, sizeof (lookups[0]), cmp_lookups);
@@ -113,9 +129,11 @@ setup_lookups (hb_face_t    *face,
   if (*num_lookups)
   {
     for (i = 1, j = 0; i < *num_lookups; i++)
-      if (lookups[i] != lookups[j])
+      if (lookups[i].index != lookups[j].index)
 	lookups[++j] = lookups[i];
-    lookups[j++] = lookups[i - 1];
+      else
+        lookups[j].mask |= lookups[i].mask;
+    j++;
     *num_lookups = j;
   }
 }
@@ -128,7 +146,7 @@ _hb_ot_substitute_complex (hb_font_t    *font HB_UNUSED,
 			   hb_feature_t *features,
 			   unsigned int  num_features)
 {
-  unsigned int lookups[1000];
+  lookup_map lookups[1000];
   unsigned int num_lookups = ARRAY_LENGTH (lookups);
   unsigned int i;
 
@@ -140,7 +158,7 @@ _hb_ot_substitute_complex (hb_font_t    *font HB_UNUSED,
 		 lookups, &num_lookups);
 
   for (i = 0; i < num_lookups; i++)
-    hb_ot_layout_substitute_lookup (face, buffer, lookups[i], 1);
+    hb_ot_layout_substitute_lookup (face, buffer, lookups[i].index, lookups[i].mask);
 
   return TRUE;
 }
@@ -152,7 +170,7 @@ _hb_ot_position_complex (hb_font_t    *font,
 			 hb_feature_t *features,
 			 unsigned int  num_features)
 {
-  unsigned int lookups[1000];
+  lookup_map lookups[1000];
   unsigned int num_lookups = ARRAY_LENGTH (lookups);
   unsigned int i;
 
@@ -164,7 +182,7 @@ _hb_ot_position_complex (hb_font_t    *font,
 		 lookups, &num_lookups);
 
   for (i = 0; i < num_lookups; i++)
-    hb_ot_layout_position_lookup (font, face, buffer, lookups[i], 1);
+    hb_ot_layout_position_lookup (font, face, buffer, lookups[i].index, lookups[i].mask);
 
   hb_ot_layout_position_finish (font, face, buffer);
 
commit 60010a0c4d8efae5c61a0c9cf10cfe2c1860f41e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 20 14:05:02 2010 +0100

    Update always-apply mask from 0xFFFF to 1
    
    We plan to use the first bit to be always on.

diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 801d0a3..c7afdc3 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -140,7 +140,7 @@ _hb_ot_substitute_complex (hb_font_t    *font HB_UNUSED,
 		 lookups, &num_lookups);
 
   for (i = 0; i < num_lookups; i++)
-    hb_ot_layout_substitute_lookup (face, buffer, lookups[i], 0xFFFF);
+    hb_ot_layout_substitute_lookup (face, buffer, lookups[i], 1);
 
   return TRUE;
 }
@@ -164,7 +164,7 @@ _hb_ot_position_complex (hb_font_t    *font,
 		 lookups, &num_lookups);
 
   for (i = 0; i < num_lookups; i++)
-    hb_ot_layout_position_lookup (font, face, buffer, lookups[i], 0xFFFF);
+    hb_ot_layout_position_lookup (font, face, buffer, lookups[i], 1);
 
   hb_ot_layout_position_finish (font, face, buffer);
 



More information about the HarfBuzz mailing list