diff options
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-ot-var-fvar-table.hh')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/hb-ot-var-fvar-table.hh | 119 |
1 files changed, 91 insertions, 28 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-var-fvar-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-var-fvar-table.hh index a384dfa531..07d7586baa 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-var-fvar-table.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-var-fvar-table.hh @@ -39,6 +39,24 @@ namespace OT { +static bool axis_coord_pinned_or_within_axis_range (const hb_array_t<const F16DOT16> coords, + unsigned axis_index, + Triple axis_limit) +{ + float axis_coord = coords[axis_index].to_float (); + if (axis_limit.is_point ()) + { + if (axis_limit.minimum != axis_coord) + return false; + } + else + { + if (axis_coord < axis_limit.minimum || + axis_coord > axis_limit.maximum) + return false; + } + return true; +} struct InstanceRecord { @@ -47,6 +65,27 @@ struct InstanceRecord hb_array_t<const F16DOT16> get_coordinates (unsigned int axis_count) const { return coordinatesZ.as_array (axis_count); } + bool keep_instance (unsigned axis_count, + const hb_map_t *axes_index_tag_map, + const hb_hashmap_t<hb_tag_t, Triple> *axes_location) const + { + if (axes_location->is_empty ()) return true; + const hb_array_t<const F16DOT16> coords = get_coordinates (axis_count); + for (unsigned i = 0 ; i < axis_count; i++) + { + uint32_t *axis_tag; + if (!axes_index_tag_map->has (i, &axis_tag)) + return false; + if (!axes_location->has (*axis_tag)) + continue; + + Triple axis_limit = axes_location->get (*axis_tag); + if (!axis_coord_pinned_or_within_axis_range (coords, i, axis_limit)) + return false; + } + return true; + } + bool subset (hb_subset_context_t *c, unsigned axis_count, bool has_postscript_nameid) const @@ -56,19 +95,22 @@ struct InstanceRecord if (unlikely (!c->serializer->embed (flags))) return_trace (false); const hb_array_t<const F16DOT16> coords = get_coordinates (axis_count); - const hb_hashmap_t<hb_tag_t, float> *axes_location = &c->plan->user_axes_location; + const hb_hashmap_t<hb_tag_t, Triple> *axes_location = &c->plan->user_axes_location; for (unsigned i = 0 ; i < axis_count; i++) { uint32_t *axis_tag; + Triple *axis_limit; // only keep instances whose coordinates == pinned axis location - if (!c->plan->axes_old_index_tag_map.has (i, &axis_tag)) continue; - - if (axes_location->has (*axis_tag) && - fabsf (axes_location->get (*axis_tag) - coords[i].to_float ()) > 0.001f) - return_trace (false); - - if (!c->plan->axes_index_map.has (i)) - continue; + if (!c->plan->axes_old_index_tag_map.has (i, &axis_tag)) return_trace (false); + if (axes_location->has (*axis_tag, &axis_limit)) + { + if (!axis_coord_pinned_or_within_axis_range (coords, i, *axis_limit)) + return_trace (false); + + //skip pinned axis + if (axis_limit->is_point ()) + continue; + } if (!c->serializer->embed (coords[i])) return_trace (false); @@ -89,6 +131,7 @@ struct InstanceRecord { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && + hb_barrier () && c->check_array (coordinatesZ.arrayZ, axis_count)); } @@ -186,6 +229,30 @@ struct AxisRecord return defaultValue.to_float (); } + TripleDistances get_triple_distances () const + { + float min, default_, max; + get_coordinates (min, default_, max); + return TripleDistances (min, default_, max); + } + + bool subset (hb_subset_context_t *c) const + { + TRACE_SUBSET (this); + auto *out = c->serializer->embed (this); + if (unlikely (!out)) return_trace (false); + + const hb_hashmap_t<hb_tag_t, Triple>& user_axes_location = c->plan->user_axes_location; + Triple *axis_limit; + if (user_axes_location.has (axisTag, &axis_limit)) + { + out->minValue.set_float (axis_limit->minimum); + out->defaultValue.set_float (axis_limit->middle); + out->maxValue.set_float (axis_limit->maximum); + } + return_trace (true); + } + public: Tag axisTag; /* Tag identifying the design variation for the axis. */ protected: @@ -211,12 +278,15 @@ struct fvar { TRACE_SANITIZE (this); return_trace (version.sanitize (c) && + hb_barrier () && likely (version.major == 1) && c->check_struct (this) && + hb_barrier () && axisSize == 20 && /* Assumed in our code. */ instanceSize >= axisCount * 4 + 4 && get_axes ().sanitize (c) && - c->check_range (get_instance (0), instanceCount, instanceSize)); + c->check_range (&StructAfter<InstanceRecord> (get_axes ()), + instanceCount, instanceSize)); } unsigned int get_axis_count () const { return axisCount; } @@ -314,21 +384,19 @@ struct fvar return axisCount; } - void collect_name_ids (hb_hashmap_t<hb_tag_t, float> *user_axes_location, + void collect_name_ids (hb_hashmap_t<hb_tag_t, Triple> *user_axes_location, + hb_map_t *axes_old_index_tag_map, hb_set_t *nameids /* IN/OUT */) const { if (!has_data ()) return; - hb_map_t pinned_axes; auto axis_records = get_axes (); for (unsigned i = 0 ; i < (unsigned)axisCount; i++) { hb_tag_t axis_tag = axis_records[i].get_axis_tag (); - if (user_axes_location->has (axis_tag)) - { - pinned_axes.set (i, axis_tag); + if (user_axes_location->has (axis_tag) && + user_axes_location->get (axis_tag).is_point ()) continue; - } nameids->add (axis_records[i].get_name_id ()); } @@ -337,16 +405,7 @@ struct fvar { const InstanceRecord *instance = get_instance (i); - if (hb_any (+ hb_enumerate (instance->get_coordinates (axisCount)) - | hb_filter (pinned_axes, hb_first) - | hb_map ([&] (const hb_pair_t<unsigned, const F16DOT16&>& _) - { - hb_tag_t axis_tag = pinned_axes.get (_.first); - float location = user_axes_location->get (axis_tag); - if (fabs ((double)location - (double)_.second.to_float ()) > 0.001) return true; - return false; - }) - )) + if (!instance->keep_instance (axisCount, axes_old_index_tag_map, user_axes_location)) continue; nameids->add (instance->subfamilyNameID); @@ -384,21 +443,25 @@ struct fvar for (unsigned i = 0 ; i < (unsigned)axisCount; i++) { if (!c->plan->axes_index_map.has (i)) continue; - if (unlikely (!c->serializer->embed (axes_records[i]))) + if (unlikely (!axes_records[i].subset (c))) return_trace (false); } if (!c->serializer->check_assign (out->firstAxis, get_size (), HB_SERIALIZE_ERROR_INT_OVERFLOW)) return_trace (false); + unsigned num_retained_instances = 0; for (unsigned i = 0 ; i < (unsigned)instanceCount; i++) { const InstanceRecord *instance = get_instance (i); auto snap = c->serializer->snapshot (); if (!instance->subset (c, axisCount, has_postscript_nameid)) c->serializer->revert (snap); + else + num_retained_instances++; } - return_trace (true); + + return_trace (c->serializer->check_assign (out->instanceCount, num_retained_instances, HB_SERIALIZE_ERROR_INT_OVERFLOW)); } public: |