From 30c42b644eb33551aa0986287182a46f2d8c32ed Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Sep 2016 03:32:39 -0700 Subject: [PATCH] [GX] Add hb_ot_layout_table_find_feature_variations() --- src/hb-ot-layout-common-private.hh | 18 +++++++++++------- src/hb-ot-layout-gsubgpos-private.hh | 6 +++--- src/hb-ot-layout.cc | 15 +++++++++++++++ src/hb-ot-layout.h | 10 ++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 3c574af70..e67a5145d 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -1342,7 +1342,7 @@ struct ConditionFormat1 friend struct Condition; private: - inline bool evaluate (int *coords, unsigned int coord_len) const + inline bool evaluate (const int *coords, unsigned int coord_len) const { int coord = axisIndex < coord_len ? coords[axisIndex] : 0; return filterRangeMinValue <= coord && coord <= filterRangeMaxValue; @@ -1365,7 +1365,7 @@ struct ConditionFormat1 struct Condition { - inline bool evaluate (int *coords, unsigned int coord_len) const + inline bool evaluate (const int *coords, unsigned int coord_len) const { switch (u.format) { case 1: return u.format1.evaluate (coords, coord_len); @@ -1394,7 +1394,7 @@ struct Condition struct ConditionSet { - inline bool evaluate (int *coords, unsigned int coord_len) const + inline bool evaluate (const int *coords, unsigned int coord_len) const { unsigned int count = conditions.len; for (unsigned int i = 0; i < count; i++) @@ -1470,17 +1470,21 @@ struct FeatureVariationRecord struct FeatureVariations { - inline const FeatureTableSubstitution & - get_substitutions (int *coords, unsigned int coord_len) const + inline bool find_index (const int *coords, unsigned int coord_len, + unsigned int *index) const { unsigned int count = varRecords.len; for (unsigned int i = 0; i < count; i++) { const FeatureVariationRecord &record = varRecords.array[i]; if ((this+record.conditions).evaluate (coords, coord_len)) - return (this+record.substitutions); + { + *index = i; + return true; + } } - return Null(FeatureTableSubstitution); + *index = 0xFFFFFFFF; + return false; } inline bool sanitize (hb_sanitize_context_t *c) const diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 490b91e1b..e20777acb 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -2271,10 +2271,10 @@ struct GSUBGPOS inline const Lookup& get_lookup (unsigned int i) const { return (this+lookupList)[i]; } - inline const FeatureTableSubstitution & - get_feature_substitutions (int *coords, unsigned int coord_len) const + inline bool find_variations_index (const int *coords, unsigned int num_coords, + unsigned int *index) const { return (version.to_int () >= 0x00010001u ? this+featureVars : Null(FeatureVariations)) - .get_substitutions (coords, coord_len); } + .find_index (coords, num_coords, index); } inline bool sanitize (hb_sanitize_context_t *c) const { diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 0501181a3..b352cdb5d 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -836,6 +836,21 @@ hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, } +/* Variations support */ + +hb_bool_t +hb_ot_layout_table_find_feature_variations (hb_face_t *face, + hb_tag_t table_tag, + const int *coords, + unsigned int num_coords, + unsigned int *variations_index /* out */) +{ + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + + return g.find_variations_index (coords, num_coords, variations_index); +} + + /* * OT::GSUB */ diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index eb23d45b6..2e3db8c20 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -95,6 +95,7 @@ hb_ot_layout_get_ligature_carets (hb_font_t *font, #define HB_OT_LAYOUT_NO_SCRIPT_INDEX 0xFFFFu #define HB_OT_LAYOUT_NO_FEATURE_INDEX 0xFFFFu #define HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX 0xFFFFu +#define HB_OT_LAYOUT_NO_VARIATIONS_INDEX 0xFFFFFFFFu HB_EXTERN unsigned int hb_ot_layout_table_get_script_tags (hb_face_t *face, @@ -236,6 +237,15 @@ Xhb_ot_layout_lookup_enumerate_sequences (hb_face_t *face, void *user_data); #endif +/* Variations support */ + +HB_EXTERN hb_bool_t +hb_ot_layout_table_find_feature_variations (hb_face_t *face, + hb_tag_t table_tag, + const int *coords, + unsigned int num_coords, + unsigned int *variations_index /* out */); + /* * GSUB