diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2018-09-10 22:37:19 +0200 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-09-10 22:37:19 +0200 |
commit | de801b766783919b23e3b05c3d9fbe616bc7e103 (patch) | |
tree | ca878035f9b8b66105a6a84fadd2e929a0b0af18 | |
parent | 3e2daf59ca604688098e5247c3819f509360de60 (diff) |
Make --features rand=1 available to the userrand
Use rand=255 to mean "randomize".
Part of https://github.com/harfbuzz/harfbuzz/pull/803
-rw-r--r-- | src/hb-ot-layout-gsub-table.hh | 11 | ||||
-rw-r--r-- | src/hb-ot-layout-gsubgpos.hh | 1 | ||||
-rw-r--r-- | src/hb-ot-map.cc | 4 | ||||
-rw-r--r-- | src/hb-ot-map.hh | 3 | ||||
-rw-r--r-- | src/hb-ot-shape.cc | 2 |
5 files changed, 11 insertions, 10 deletions
diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 255a2827..dfa50979 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -541,18 +541,15 @@ struct AlternateSet unsigned int shift = hb_ctz (lookup_mask); unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift); - if (unlikely (alt_index > count || alt_index == 0)) return_trace (false); - - /* This is ugly... If alt_index is 1, we take it as "on", and randomize - * feature if it is the rand feature. If it's > 1, it's a user-set value - * for sure, so respect it. So, user cannot set rand=1 and expect it to - * choose the first alternate... */ - if (alt_index == 1 && c->random) + /* 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; } + if (unlikely (alt_index > count || alt_index == 0)) return_trace (false); + c->replace_glyph (alternates[alt_index - 1]); return_trace (true); diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 7e9c0526..fa27b22e 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -33,6 +33,7 @@ #include "hb-buffer.hh" #include "hb-map.hh" #include "hb-set.hh" +#include "hb-ot-map.hh" #include "hb-ot-layout-common.hh" #include "hb-ot-layout-gdef-table.hh" diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 8617f054..cb70583f 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -210,8 +210,8 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, /* Uses the global bit */ bits_needed = 0; else - /* Limit to 8 bits per feature. */ - bits_needed = MIN(8u, hb_bit_storage (info->max_value)); + /* Limit bits per feature. */ + bits_needed = MIN(HB_OT_MAP_MAX_BITS, hb_bit_storage (info->max_value)); if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t)) continue; /* Feature disabled, or not enough bits. */ diff --git a/src/hb-ot-map.hh b/src/hb-ot-map.hh index 091cb3b6..cc36fa27 100644 --- a/src/hb-ot-map.hh +++ b/src/hb-ot-map.hh @@ -32,6 +32,9 @@ #include "hb-buffer.hh" +#define HB_OT_MAP_MAX_BITS 8u +#define HB_OT_MAP_MAX_VALUE ((1u << HB_OT_MAP_MAX_BITS) - 1u) + struct hb_ot_shape_plan_t; static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS}; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 00a8a647..437b0feb 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -96,7 +96,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, map->add_feature (HB_TAG ('d','n','o','m'), 1, F_NONE); /* Random! */ - map->add_feature (HB_TAG ('r','a','n','d'), 1, F_GLOBAL | F_RANDOM); + map->add_feature (HB_TAG ('r','a','n','d'), HB_OT_MAP_MAX_VALUE, F_GLOBAL | F_RANDOM); if (planner->shaper->collect_features) planner->shaper->collect_features (planner); |