From cf336f17b2d5aa75ef92d27dd8888320d58d766b Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Mon, 10 Feb 2025 14:15:25 +0200 Subject: [PATCH] [shape-plan] Rename hb_ot_shape_plan_get_features to get_feature_tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify the API by returning only feature tags. The users of this API would be interested only in feature enabled by default and whether the feature is globally or partially enabled wouldn’t be of much interest in that case. For user features, the user of the API already have full access to them. --- docs/harfbuzz-sections.txt | 2 +- src/hb-ot-map.cc | 18 ++--- src/hb-ot-map.hh | 6 +- src/hb-ot-shape.cc | 26 +++---- src/hb-ot-shape.h | 8 +-- test/api/test-shape-plan.c | 144 ++++++++++++++++++------------------- 6 files changed, 98 insertions(+), 106 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 6cd111324..df4e5f8a3 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -674,7 +674,7 @@ hb_ot_layout_table_get_script_tags hb_ot_layout_table_get_lookup_count hb_ot_layout_table_select_script hb_ot_shape_plan_collect_lookups -hb_ot_shape_plan_get_features +hb_ot_shape_plan_get_feature_tags hb_ot_layout_language_get_required_feature_index HB_OT_MAX_TAGS_PER_LANGUAGE HB_OT_MAX_TAGS_PER_SCRIPT diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index eb8d13947..952ab3eb1 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -390,23 +390,15 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, } } -unsigned int hb_ot_map_t::get_features (unsigned int start_offset, unsigned int *feature_count, hb_feature_t *out_features) const +unsigned int hb_ot_map_t::get_feature_tags (unsigned int start_offset, unsigned int *tag_count, hb_tag_t *tags) const { - if (feature_count) + if (tag_count) { - auto sub_features = features.as_array ().sub_array (start_offset, feature_count); - - if (out_features) + auto sub_features = features.as_array ().sub_array (start_offset, tag_count); + if (tags) { for (unsigned int i = 0; i < sub_features.length; i++) - { - out_features[i].tag = sub_features[i].tag; - // FIXME: I should be using the mask to get the proper value, start, and - // end, but I'm not sure how to do that. - out_features[i].value = 1; - out_features[i].start = HB_FEATURE_GLOBAL_START; - out_features[i].end = HB_FEATURE_GLOBAL_END; - } + tags[i] = sub_features[i].tag; } } diff --git a/src/hb-ot-map.hh b/src/hb-ot-map.hh index cdd07edb8..185d133d7 100644 --- a/src/hb-ot-map.hh +++ b/src/hb-ot-map.hh @@ -166,9 +166,9 @@ struct hb_ot_map_t const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; HB_INTERNAL void substitute (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; HB_INTERNAL void position (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; - HB_INTERNAL unsigned int get_features (unsigned int start_offset, - unsigned int *feature_count, /* IN/OUT */ - hb_feature_t *features /* OUT */) const; + HB_INTERNAL unsigned int get_feature_tags (unsigned int start_offset, + unsigned int *tag_count, /* IN/OUT */ + hb_tag_t *tags /* OUT */) const; public: hb_tag_t chosen_script[2]; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index a7be8f48a..2ff337799 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -1261,30 +1261,30 @@ hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, /** - * hb_ot_shape_plan_get_features: + * hb_ot_shape_plan_get_feature_tags: * @shape_plan: A shaping plan * @start_offset: The index of first feature to retrieve - * @feature_count: (inout): Input = the maximum number of features to return; - * Output = the actual number of features returned (may be zero) - * @features: (out) (array length=feature_count): The array of enabled feature + * @tag_count: (inout): Input = the maximum number of features to return; + * Output = the actual number of features returned (may be zero) + * @tags: (out) (array length=tag_count): The array of enabled feature * - * Fetches the list of OpenType features enabled for a shaping plan, if possible. + * Fetches the list of OpenType feature tags enabled for a shaping plan, if possible. * - * Return value: Total number of features. + * Return value: Total number of feature tagss. * * XSince: REPLACEME */ unsigned int -hb_ot_shape_plan_get_features (hb_shape_plan_t *shape_plan, - unsigned int start_offset, - unsigned int *feature_count, /* IN/OUT */ - hb_feature_t *features /* OUT */) +hb_ot_shape_plan_get_feature_tags (hb_shape_plan_t *shape_plan, + unsigned int start_offset, + unsigned int *tag_count, /* IN/OUT */ + hb_tag_t *tags /* OUT */) { #ifndef HB_NO_OT_SHAPE - return shape_plan->ot.map.get_features (start_offset, feature_count, features); + return shape_plan->ot.map.get_feature_tags (start_offset, tag_count, tags); #else - if (feature_count) - *feature_count = 0; + if (tag_count) + *tag_count = 0; return 0; #endif } diff --git a/src/hb-ot-shape.h b/src/hb-ot-shape.h index dd90dc76f..80063f775 100644 --- a/src/hb-ot-shape.h +++ b/src/hb-ot-shape.h @@ -49,10 +49,10 @@ hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, hb_set_t *lookup_indexes /* OUT */); HB_EXTERN unsigned int -hb_ot_shape_plan_get_features (hb_shape_plan_t *shape_plan, - unsigned int start_offset, - unsigned int *feature_count, /* IN/OUT */ - hb_feature_t *features /* OUT */); +hb_ot_shape_plan_get_feature_tags (hb_shape_plan_t *shape_plan, + unsigned int start_offset, + unsigned int *tag_count, /* IN/OUT */ + hb_tag_t *tags /* OUT */); HB_END_DECLS diff --git a/test/api/test-shape-plan.c b/test/api/test-shape-plan.c index 275230149..851dd44b8 100644 --- a/test/api/test-shape-plan.c +++ b/test/api/test-shape-plan.c @@ -29,7 +29,7 @@ /* Unit tests for hb-shape-plan.h */ static void -test_ot_shape_plan_get_features_rtl (void) +test_ot_shape_plan_get_feature_tags_rtl (void) { hb_face_t *face = hb_test_open_font_file ("fonts/NotoSans-Bold.ttf"); hb_font_t *font = hb_font_create (face); @@ -46,28 +46,28 @@ test_ot_shape_plan_get_features_rtl (void) hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, NULL, 0); g_assert_true (ret); - hb_feature_t features[16]; + hb_tag_t features[16]; unsigned int feature_count = sizeof (features) / sizeof (features[0]); - unsigned int count = hb_ot_shape_plan_get_features (shape_plan, 0, &feature_count, features); + unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features); g_assert_cmpuint (count, ==, 16); g_assert_cmpuint (feature_count, ==, count); - g_assert_cmpint (features[0].tag, ==, HB_TAG ('a', 'b', 'v', 'm')); - g_assert_cmpint (features[1].tag, ==, HB_TAG ('c', 'c', 'm', 'p')); - g_assert_cmpint (features[2].tag, ==, HB_TAG ('d', 'i', 's', 't')); - g_assert_cmpint (features[3].tag, ==, HB_TAG ('d', 'n', 'o', 'm')); - g_assert_cmpint (features[4].tag, ==, HB_TAG ('f', 'i', 'n', 'a')); - g_assert_cmpint (features[5].tag, ==, HB_TAG ('f', 'r', 'a', 'c')); - g_assert_cmpint (features[6].tag, ==, HB_TAG ('i', 'n', 'i', 't')); - g_assert_cmpint (features[7].tag, ==, HB_TAG ('i', 's', 'o', 'l')); - g_assert_cmpint (features[8].tag, ==, HB_TAG ('k', 'e', 'r', 'n')); - g_assert_cmpint (features[9].tag, ==, HB_TAG ('l', 'i', 'g', 'a')); - g_assert_cmpint (features[10].tag, ==, HB_TAG ('m', 'a', 'r', 'k')); - g_assert_cmpint (features[11].tag, ==, HB_TAG ('m', 'e', 'd', 'i')); - g_assert_cmpint (features[12].tag, ==, HB_TAG ('m', 'k', 'm', 'k')); - g_assert_cmpint (features[13].tag, ==, HB_TAG ('n', 'u', 'm', 'r')); - g_assert_cmpint (features[14].tag, ==, HB_TAG ('r', 'l', 'i', 'g')); - g_assert_cmpint (features[15].tag, ==, HB_TAG ('r', 't', 'l', 'm')); + g_assert_cmpint (features[0], ==, HB_TAG ('a', 'b', 'v', 'm')); + g_assert_cmpint (features[1], ==, HB_TAG ('c', 'c', 'm', 'p')); + g_assert_cmpint (features[2], ==, HB_TAG ('d', 'i', 's', 't')); + g_assert_cmpint (features[3], ==, HB_TAG ('d', 'n', 'o', 'm')); + g_assert_cmpint (features[4], ==, HB_TAG ('f', 'i', 'n', 'a')); + g_assert_cmpint (features[5], ==, HB_TAG ('f', 'r', 'a', 'c')); + g_assert_cmpint (features[6], ==, HB_TAG ('i', 'n', 'i', 't')); + g_assert_cmpint (features[7], ==, HB_TAG ('i', 's', 'o', 'l')); + g_assert_cmpint (features[8], ==, HB_TAG ('k', 'e', 'r', 'n')); + g_assert_cmpint (features[9], ==, HB_TAG ('l', 'i', 'g', 'a')); + g_assert_cmpint (features[10], ==, HB_TAG ('m', 'a', 'r', 'k')); + g_assert_cmpint (features[11], ==, HB_TAG ('m', 'e', 'd', 'i')); + g_assert_cmpint (features[12], ==, HB_TAG ('m', 'k', 'm', 'k')); + g_assert_cmpint (features[13], ==, HB_TAG ('n', 'u', 'm', 'r')); + g_assert_cmpint (features[14], ==, HB_TAG ('r', 'l', 'i', 'g')); + g_assert_cmpint (features[15], ==, HB_TAG ('r', 't', 'l', 'm')); hb_shape_plan_destroy (shape_plan); hb_buffer_destroy (buffer); @@ -77,7 +77,7 @@ test_ot_shape_plan_get_features_rtl (void) static void -test_ot_shape_plan_get_features_ltr (void) +test_ot_shape_plan_get_feature_tags_ltr (void) { hb_face_t *face = hb_test_open_font_file ("fonts/NotoSans-Bold.ttf"); hb_font_t *font = hb_font_create (face); @@ -94,22 +94,22 @@ test_ot_shape_plan_get_features_ltr (void) hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, NULL, 0); g_assert_true (ret); - hb_feature_t features[10]; + hb_tag_t features[10]; unsigned int feature_count = sizeof (features) / sizeof (features[0]); - unsigned int count = hb_ot_shape_plan_get_features (shape_plan, 0, &feature_count, features); + unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features); g_assert_cmpuint (count, ==, 10); g_assert_cmpuint (feature_count, ==, count); - g_assert_cmpint (features[0].tag, ==, HB_TAG ('a', 'b', 'v', 'm')); - g_assert_cmpint (features[1].tag, ==, HB_TAG ('c', 'c', 'm', 'p')); - g_assert_cmpint (features[2].tag, ==, HB_TAG ('d', 'i', 's', 't')); - g_assert_cmpint (features[3].tag, ==, HB_TAG ('d', 'n', 'o', 'm')); - g_assert_cmpint (features[4].tag, ==, HB_TAG ('f', 'r', 'a', 'c')); - g_assert_cmpint (features[5].tag, ==, HB_TAG ('k', 'e', 'r', 'n')); - g_assert_cmpint (features[6].tag, ==, HB_TAG ('l', 'i', 'g', 'a')); - g_assert_cmpint (features[7].tag, ==, HB_TAG ('m', 'a', 'r', 'k')); - g_assert_cmpint (features[8].tag, ==, HB_TAG ('m', 'k', 'm', 'k')); - g_assert_cmpint (features[9].tag, ==, HB_TAG ('n', 'u', 'm', 'r')); + g_assert_cmpint (features[0], ==, HB_TAG ('a', 'b', 'v', 'm')); + g_assert_cmpint (features[1], ==, HB_TAG ('c', 'c', 'm', 'p')); + g_assert_cmpint (features[2], ==, HB_TAG ('d', 'i', 's', 't')); + g_assert_cmpint (features[3], ==, HB_TAG ('d', 'n', 'o', 'm')); + g_assert_cmpint (features[4], ==, HB_TAG ('f', 'r', 'a', 'c')); + g_assert_cmpint (features[5], ==, HB_TAG ('k', 'e', 'r', 'n')); + g_assert_cmpint (features[6], ==, HB_TAG ('l', 'i', 'g', 'a')); + g_assert_cmpint (features[7], ==, HB_TAG ('m', 'a', 'r', 'k')); + g_assert_cmpint (features[8], ==, HB_TAG ('m', 'k', 'm', 'k')); + g_assert_cmpint (features[9], ==, HB_TAG ('n', 'u', 'm', 'r')); hb_buffer_destroy (buffer); hb_shape_plan_destroy (shape_plan); @@ -118,7 +118,7 @@ test_ot_shape_plan_get_features_ltr (void) } static void -test_ot_shape_plan_get_features_ttb (void) +test_ot_shape_plan_get_feature_tags_ttb (void) { hb_face_t *face = hb_test_open_font_file ("fonts/Mplus1p-Regular.ttf"); hb_font_t *font = hb_font_create (face); @@ -135,16 +135,16 @@ test_ot_shape_plan_get_features_ttb (void) hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, NULL, 0); g_assert_true (ret); - hb_feature_t features[4]; + hb_tag_t features[4]; unsigned int feature_count = sizeof (features) / sizeof (features[0]); - unsigned int count = hb_ot_shape_plan_get_features (shape_plan, 0, &feature_count, features); + unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features); g_assert_cmpuint (count, ==, 4); g_assert_cmpuint (feature_count, ==, count); - g_assert_cmpint (features[0].tag, ==, HB_TAG ('c', 'c', 'm', 'p')); - g_assert_cmpint (features[1].tag, ==, HB_TAG ('m', 'a', 'r', 'k')); - g_assert_cmpint (features[2].tag, ==, HB_TAG ('m', 'k', 'm', 'k')); - g_assert_cmpint (features[3].tag, ==, HB_TAG ('v', 'e', 'r', 't')); + g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p')); + g_assert_cmpint (features[1], ==, HB_TAG ('m', 'a', 'r', 'k')); + g_assert_cmpint (features[2], ==, HB_TAG ('m', 'k', 'm', 'k')); + g_assert_cmpint (features[3], ==, HB_TAG ('v', 'e', 'r', 't')); hb_buffer_destroy (buffer); hb_shape_plan_destroy (shape_plan); @@ -153,7 +153,7 @@ test_ot_shape_plan_get_features_ttb (void) } static void -test_ot_shape_plan_get_features_userfeatures_enable (void) +test_ot_shape_plan_get_feature_tags_userfeatures_enable (void) { hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf"); hb_font_t *font = hb_font_create (face); @@ -172,19 +172,19 @@ test_ot_shape_plan_get_features_userfeatures_enable (void) hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1); g_assert_true (ret); - hb_feature_t features[7]; + hb_tag_t features[7]; unsigned int feature_count = sizeof (features) / sizeof (features[0]); - unsigned int count = hb_ot_shape_plan_get_features (shape_plan, 0, &feature_count, features); + unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features); g_assert_cmpuint (count, ==, 7); g_assert_cmpuint (feature_count, ==, count); - g_assert_cmpint (features[0].tag, ==, HB_TAG ('c', 'c', 'm', 'p')); - g_assert_cmpint (features[1].tag, ==, HB_TAG ('k', 'e', 'r', 'n')); - g_assert_cmpint (features[2].tag, ==, HB_TAG ('m', 'a', 'r', 'k')); - g_assert_cmpint (features[3].tag, ==, HB_TAG ('m', 'k', 'm', 'k')); - g_assert_cmpint (features[4].tag, ==, HB_TAG ('r', 'c', 'l', 't')); - g_assert_cmpint (features[5].tag, ==, HB_TAG ('r', 'l', 'i', 'g')); - g_assert_cmpint (features[6].tag, ==, HB_TAG ('s', 's', '0', '1')); + g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p')); + g_assert_cmpint (features[1], ==, HB_TAG ('k', 'e', 'r', 'n')); + g_assert_cmpint (features[2], ==, HB_TAG ('m', 'a', 'r', 'k')); + g_assert_cmpint (features[3], ==, HB_TAG ('m', 'k', 'm', 'k')); + g_assert_cmpint (features[4], ==, HB_TAG ('r', 'c', 'l', 't')); + g_assert_cmpint (features[5], ==, HB_TAG ('r', 'l', 'i', 'g')); + g_assert_cmpint (features[6], ==, HB_TAG ('s', 's', '0', '1')); hb_buffer_destroy (buffer); hb_shape_plan_destroy (shape_plan); @@ -193,7 +193,7 @@ test_ot_shape_plan_get_features_userfeatures_enable (void) } static void -test_ot_shape_plan_get_features_userfeatures_disable (void) +test_ot_shape_plan_get_feature_tags_userfeatures_disable (void) { hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf"); hb_font_t *font = hb_font_create (face); @@ -212,17 +212,17 @@ test_ot_shape_plan_get_features_userfeatures_disable (void) hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1); g_assert_true (ret); - hb_feature_t features[5]; + hb_tag_t features[5]; unsigned int feature_count = sizeof (features) / sizeof (features[0]); - unsigned int count = hb_ot_shape_plan_get_features (shape_plan, 0, &feature_count, features); + unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features); g_assert_cmpuint (count, ==, 5); g_assert_cmpuint (feature_count, ==, count); - g_assert_cmpint (features[0].tag, ==, HB_TAG ('c', 'c', 'm', 'p')); - g_assert_cmpint (features[1].tag, ==, HB_TAG ('m', 'a', 'r', 'k')); - g_assert_cmpint (features[2].tag, ==, HB_TAG ('m', 'k', 'm', 'k')); - g_assert_cmpint (features[3].tag, ==, HB_TAG ('r', 'c', 'l', 't')); - g_assert_cmpint (features[4].tag, ==, HB_TAG ('r', 'l', 'i', 'g')); + g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p')); + g_assert_cmpint (features[1], ==, HB_TAG ('m', 'a', 'r', 'k')); + g_assert_cmpint (features[2], ==, HB_TAG ('m', 'k', 'm', 'k')); + g_assert_cmpint (features[3], ==, HB_TAG ('r', 'c', 'l', 't')); + g_assert_cmpint (features[4], ==, HB_TAG ('r', 'l', 'i', 'g')); hb_buffer_destroy (buffer); hb_shape_plan_destroy (shape_plan); @@ -231,7 +231,7 @@ test_ot_shape_plan_get_features_userfeatures_disable (void) } static void -test_ot_shape_plan_get_features_userfeatures_disable_range (void) +test_ot_shape_plan_get_feature_tags_userfeatures_disable_range (void) { hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf"); hb_font_t *font = hb_font_create (face); @@ -250,18 +250,18 @@ test_ot_shape_plan_get_features_userfeatures_disable_range (void) hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1); g_assert_true (ret); - hb_feature_t features[6]; + hb_tag_t features[6]; unsigned int feature_count = sizeof (features) / sizeof (features[0]); - unsigned int count = hb_ot_shape_plan_get_features (shape_plan, 0, &feature_count, features); + unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features); g_assert_cmpuint (count, ==, 6); g_assert_cmpuint (feature_count, ==, count); - g_assert_cmpint (features[0].tag, ==, HB_TAG ('c', 'c', 'm', 'p')); - g_assert_cmpint (features[1].tag, ==, HB_TAG ('k', 'e', 'r', 'n')); - g_assert_cmpint (features[2].tag, ==, HB_TAG ('m', 'a', 'r', 'k')); - g_assert_cmpint (features[3].tag, ==, HB_TAG ('m', 'k', 'm', 'k')); - g_assert_cmpint (features[4].tag, ==, HB_TAG ('r', 'c', 'l', 't')); - g_assert_cmpint (features[5].tag, ==, HB_TAG ('r', 'l', 'i', 'g')); + g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p')); + g_assert_cmpint (features[1], ==, HB_TAG ('k', 'e', 'r', 'n')); + g_assert_cmpint (features[2], ==, HB_TAG ('m', 'a', 'r', 'k')); + g_assert_cmpint (features[3], ==, HB_TAG ('m', 'k', 'm', 'k')); + g_assert_cmpint (features[4], ==, HB_TAG ('r', 'c', 'l', 't')); + g_assert_cmpint (features[5], ==, HB_TAG ('r', 'l', 'i', 'g')); hb_buffer_destroy (buffer); hb_shape_plan_destroy (shape_plan); @@ -274,12 +274,12 @@ main (int argc, char **argv) { hb_test_init (&argc, &argv); - hb_test_add (test_ot_shape_plan_get_features_rtl); - hb_test_add (test_ot_shape_plan_get_features_ltr); - hb_test_add (test_ot_shape_plan_get_features_ttb); - hb_test_add (test_ot_shape_plan_get_features_userfeatures_enable); - hb_test_add (test_ot_shape_plan_get_features_userfeatures_disable); - hb_test_add (test_ot_shape_plan_get_features_userfeatures_disable_range); + hb_test_add (test_ot_shape_plan_get_feature_tags_rtl); + hb_test_add (test_ot_shape_plan_get_feature_tags_ltr); + hb_test_add (test_ot_shape_plan_get_feature_tags_ttb); + hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_enable); + hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_disable); + hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_disable_range); return hb_test_run(); }