diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 3fccaf695..fedb2aae4 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -4993,6 +4993,17 @@ Condition::subset_lookup_condition_impl (hb_subset_context_t *c, LOOKUP_CONDITION_SUBSET_TRUE : LOOKUP_CONDITION_SUBSET_FALSE); + if (!c->plan->user_axes_location.is_empty () && + hb_first (*new_varidx_delta) == VarIdx::NO_VARIATION) + { + // Conditions becoming constant depend on the unrounded sign, not + // the integer delta used to instance positioning values. + float value = (int) src.defaultValue + + c->plan->layout_variation_delta (src.varIdx); + return value > 0 ? LOOKUP_CONDITION_SUBSET_TRUE : + LOOKUP_CONDITION_SUBSET_FALSE; + } + int default_value = (int) src.defaultValue + hb_second (*new_varidx_delta); if (unlikely (!c->serializer->check_assign ( @@ -5002,11 +5013,6 @@ Condition::subset_lookup_condition_impl (hb_subset_context_t *c, return LOOKUP_CONDITION_SUBSET_ERROR; out->varIdx = hb_first (*new_varidx_delta); - if (!c->plan->user_axes_location.is_empty () && - out->varIdx == VarIdx::NO_VARIATION) - return default_value > 0 ? - LOOKUP_CONDITION_SUBSET_TRUE : - LOOKUP_CONDITION_SUBSET_FALSE; return LOOKUP_CONDITION_SUBSET_KEEP; } diff --git a/src/hb-subset-plan-layout.cc b/src/hb-subset-plan-layout.cc index 45bd622cb..bd6022b75 100644 --- a/src/hb-subset-plan-layout.cc +++ b/src/hb-subset-plan-layout.cc @@ -35,6 +35,20 @@ using OT::Layout::GPOS; #ifndef HB_NO_SUBSET_LAYOUT +float +hb_subset_plan_t::layout_variation_delta (unsigned var_idx HB_UNUSED) +{ +#ifndef HB_NO_VAR + hb_blob_ptr_t gdef = source_table (); + float delta = gdef->get_var_store ().get_delta (var_idx, + normalized_coords.as_array ()); + gdef.destroy (); + return delta; +#else + return 0.f; +#endif +} + void remap_used_mark_sets (hb_subset_plan_t *plan, hb_map_t& used_mark_sets_map) diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 0111f15e3..9b82eca36 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -215,6 +215,8 @@ struct hb_subset_plan_t bool in_error () const { return !successful; } + HB_INTERNAL float layout_variation_delta (unsigned var_idx); + bool check_success(bool success) { successful = (successful && success); diff --git a/test/api/test-subset.c b/test/api/test-subset.c index d565dfa49..39c71ac3c 100644 --- a/test/api/test-subset.c +++ b/test/api/test-subset.c @@ -266,12 +266,41 @@ test_subset_feature_variation_universal (void) } } +static void +test_subset_lookup_variation_fractional_value (void) +{ + hb_face_t *face = hb_test_open_font_file ( + "../shape/data/in-house/fonts/4e9f0bc6a8f25b5fd3547bbc17423ce8cedb915f.ttf"); + const float locations[] = {0.5f, 0.6f, 0.7f}; + const int normalized[] = {8192, 9830, 11469}; + const int test_coords[] = {4915, 13107}; + + for (unsigned i = 0; i < G_N_ELEMENTS (locations); i++) + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_RETAIN_GIDS); + hb_set_add_range (hb_subset_input_unicode_set (input), 'A', 'F'); + g_assert_true (hb_subset_input_pin_axis_location ( + input, face, HB_TAG ('D', 'U', 'M', 'Y'), locations[i])); + hb_face_t *subset = hb_subset_or_fail (face, input); + g_assert_nonnull (subset); + for (unsigned j = 0; j < G_N_ELEMENTS (test_coords); j++) + { + int coords[] = {test_coords[j], normalized[i]}; + assert_condition_instance_matches (face, subset, coords, &test_coords[j], 1); + } + hb_face_destroy (subset); + hb_subset_input_destroy (input); + } + hb_face_destroy (face); +} + static void test_subset_feature_variation_conditions (void) { hb_face_t *face = hb_test_open_font_file ("fonts/feature-variation-conditions.ttf"); - const float locations[] = {-0.8f, -0.6f, 0.f, 0.3f, 0.8f}; - const int normalized[] = {-13107, -9830, 0, 4915, 13107}; + const float locations[] = {-0.8f, -0.6f, 0.f, 0.3f, 0.6f, 0.8f}; + const int normalized[] = {-13107, -9830, 0, 4915, 9830, 13107}; const hb_tag_t tags[] = {HB_TAG ('T','E','S','T'), HB_TAG ('D','U','M','Y')}; const int original_coords[][2] = {{0, 0}, {4915, 0}, {4915, 13107}, {13107, -13107}, {4915, -9830}}; @@ -869,6 +898,7 @@ main (int argc, char **argv) hb_test_add (test_subset_crash); #ifndef HB_NO_VAR hb_test_add (test_subset_lookup_variations); + hb_test_add (test_subset_lookup_variation_fractional_value); hb_test_add (test_subset_feature_variation_conditions); hb_test_add (test_subset_feature_variation_universal); #endif