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

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Sep 11 08:58:08 UTC 2018


 src/hb-ot-layout-gsub-table.hh              |    5 +----
 src/hb-ot-layout-gsubgpos.hh                |    9 ++++++++-
 test/shaping/data/in-house/tests/rand.tests |    4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)

New commits:
commit cfdea884754ed40ffa5cc00cb1ecaa86cb46a394
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Sep 11 10:57:48 2018 +0200

    [random] Switch to 32bit RNG

diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh
index cb71759e..eae73ce3 100644
--- a/src/hb-ot-layout-gsubgpos.hh
+++ b/src/hb-ot-layout-gsubgpos.hh
@@ -484,7 +484,7 @@ struct hb_ot_apply_context_t :
   bool auto_zwj;
   bool random;
 
-  uint64_t random_state;
+  uint32_t random_state;
 
 
   hb_ot_apply_context_t (unsigned int table_index_,
@@ -523,8 +523,9 @@ struct hb_ot_apply_context_t :
 
   inline uint32_t random_number (void)
   {
-    random_state = (0x5DEECE66Dull * random_state + 11) & (((uint64_t) 1 << 48) - 1);
-    return random_state >> 32;
+    /* http://www.cplusplus.com/reference/random/minstd_rand/ */
+    random_state = random_state * 48271 % 2147483647;
+    return random_state;
   }
 
   inline bool
diff --git a/test/shaping/data/in-house/tests/rand.tests b/test/shaping/data/in-house/tests/rand.tests
index 5ea0fc04..df324b92 100644
--- a/test/shaping/data/in-house/tests/rand.tests
+++ b/test/shaping/data/in-house/tests/rand.tests
@@ -1,3 +1,3 @@
 ../fonts/5bb74492f5e0ffa1fbb72e4c881be035120b6513.ttf:--no-glyph-names --features=-rand:U+0054,U+0055,U+0056:[1=0+560|2=1+602|3=2+602]
-#../fonts/5bb74492f5e0ffa1fbb72e4c881be035120b6513.ttf:--no-glyph-names --features=rand=2:U+0054,U+0055,U+0056:[5=0+560|8=1+602|11=2+602]
-../fonts/5bb74492f5e0ffa1fbb72e4c881be035120b6513.ttf:--no-glyph-names:U+0054,U+0055,U+0056,U+0054,U+0055,U+0056,U+0054,U+0055,U+0056,U+0054,U+0055,U+0056:[6=0+560|9=1+602|10=2+602|6=3+560|9=4+602|12=5+602|5=6+560|8=7+602|11=8+602|6=9+560|8=10+602|10=11+602]
+../fonts/5bb74492f5e0ffa1fbb72e4c881be035120b6513.ttf:--no-glyph-names --features=rand=2:U+0054,U+0055,U+0056:[5=0+560|8=1+602|11=2+602]
+../fonts/5bb74492f5e0ffa1fbb72e4c881be035120b6513.ttf:--no-glyph-names:U+0054,U+0055,U+0056,U+0054,U+0055,U+0056,U+0054,U+0055,U+0056,U+0054,U+0055,U+0056:[5=0+560|7=1+602|10=2+602|4=3+560|7=4+602|10=5+602|6=6+560|9=7+602|10=8+602|5=9+560|8=10+602|12=11+602]
commit 08260c708ae6adc4efa9bde5e9ede01b7e4d42cc
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Sep 11 10:51:19 2018 +0200

    [random] Shuffle

diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh
index dfa50979..4d5db6ae 100644
--- a/src/hb-ot-layout-gsub-table.hh
+++ b/src/hb-ot-layout-gsub-table.hh
@@ -543,10 +543,7 @@ struct AlternateSet
 
     /* If alt_index is MAX, randomize feature if it is the rand feature. */
     if (alt_index == HB_OT_MAP_MAX_VALUE && c->random)
-    {
-      c->random_state = (0x5DEECE66Dull * c->random_state + 11) & (((uint64_t) 1 << 48) - 1);
-      alt_index = (c->random_state >> 32) % count + 1;
-    }
+      alt_index = c->random_number () % count + 1;
 
     if (unlikely (alt_index > count || alt_index == 0)) return_trace (false);
 
diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh
index be1b449c..cb71759e 100644
--- a/src/hb-ot-layout-gsubgpos.hh
+++ b/src/hb-ot-layout-gsubgpos.hh
@@ -521,6 +521,12 @@ struct hb_ot_apply_context_t :
     iter_context.init (this, true);
   }
 
+  inline uint32_t random_number (void)
+  {
+    random_state = (0x5DEECE66Dull * random_state + 11) & (((uint64_t) 1 << 48) - 1);
+    return random_state >> 32;
+  }
+
   inline bool
   match_properties_mark (hb_codepoint_t  glyph,
 			 unsigned int    glyph_props,


More information about the HarfBuzz mailing list