Imported Upstream version 8.2.2
[platform/upstream/harfbuzz.git] / test / api / test-subset.c
index 27bf73c..08c9110 100644 (file)
@@ -155,6 +155,80 @@ test_subset_sets (void)
   hb_subset_input_destroy (input);
 }
 
+static void
+test_subset_plan (void)
+{
+  hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
+  hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
+
+  hb_set_t *codepoints = hb_set_create();
+  hb_set_add (codepoints, 97);
+  hb_set_add (codepoints, 99);
+  hb_subset_input_t* input = hb_subset_test_create_input (codepoints);
+  hb_set_destroy (codepoints);
+
+  hb_subset_plan_t* plan = hb_subset_plan_create_or_fail (face_abc, input);
+  g_assert (plan);
+
+  const hb_map_t* mapping = hb_subset_plan_old_to_new_glyph_mapping (plan);
+  g_assert (hb_map_get (mapping, 1) == 1);
+  g_assert (hb_map_get (mapping, 3) == 2);
+
+  mapping = hb_subset_plan_new_to_old_glyph_mapping (plan);
+  g_assert (hb_map_get (mapping, 1) == 1);
+  g_assert (hb_map_get (mapping, 2) == 3);
+
+  mapping = hb_subset_plan_unicode_to_old_glyph_mapping (plan);
+  g_assert (hb_map_get (mapping, 0x63) == 3);
+
+  hb_face_t* face_abc_subset = hb_subset_plan_execute_or_fail (plan);
+
+  hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a'));
+  hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f'));
+
+  hb_subset_input_destroy (input);
+  hb_subset_plan_destroy (plan);
+  hb_face_destroy (face_abc_subset);
+  hb_face_destroy (face_abc);
+  hb_face_destroy (face_ac);
+}
+
+static hb_blob_t*
+_ref_table (hb_face_t *face, hb_tag_t tag, void *user_data)
+{
+  return hb_face_reference_table ((hb_face_t*) user_data, tag);
+}
+
+static void
+test_subset_create_for_tables_face (void)
+{
+  hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
+  hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
+  hb_face_t *face_create_for_tables = hb_face_create_for_tables (
+      _ref_table,
+      face_abc,
+      NULL);
+
+  hb_set_t *codepoints = hb_set_create();
+  hb_set_add (codepoints, 97);
+  hb_set_add (codepoints, 99);
+
+  hb_subset_input_t* input = hb_subset_test_create_input (codepoints);
+  hb_set_destroy (codepoints);
+
+  hb_face_t* face_abc_subset = hb_subset_or_fail (face_create_for_tables, input);
+
+  hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a'));
+  hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f'));
+  hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','a','s','p'));
+
+  hb_subset_input_destroy (input);
+  hb_face_destroy (face_abc_subset);
+  hb_face_destroy (face_create_for_tables);
+  hb_face_destroy (face_abc);
+  hb_face_destroy (face_ac);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -165,6 +239,8 @@ main (int argc, char **argv)
   hb_test_add (test_subset_crash);
   hb_test_add (test_subset_set_flags);
   hb_test_add (test_subset_sets);
+  hb_test_add (test_subset_plan);
+  hb_test_add (test_subset_create_for_tables_face);
 
   return hb_test_run();
 }