2 * Copyright © 2018 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
30 static hb_face_t *face;
33 test_ot_layout_feature_get_name_ids_and_characters (void)
35 hb_tag_t cv01 = HB_TAG ('c','v','0','1');
36 unsigned int feature_index;
37 unsigned int num_named_parameters;
38 hb_ot_name_id_t label_id;
39 hb_ot_name_id_t tooltip_id;
40 hb_ot_name_id_t sample_id;
41 hb_ot_name_id_t first_param_id;
42 hb_codepoint_t characters[100];
43 unsigned int char_count = 100;
44 unsigned int all_chars;
45 if (!hb_ot_layout_language_find_feature (face,
48 HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
51 g_error ("Failed to find feature index");
53 if (!hb_ot_layout_feature_get_name_ids (face, HB_OT_TAG_GSUB, feature_index,
54 &label_id, &tooltip_id, &sample_id,
55 &num_named_parameters, &first_param_id))
56 g_error ("Failed to get name ids");
58 g_assert_cmpint (label_id, ==, 256);
59 g_assert_cmpint (tooltip_id, ==, 257);
60 g_assert_cmpint (sample_id, ==, 258);
61 g_assert_cmpint (num_named_parameters, ==, 2);
62 g_assert_cmpint (first_param_id, ==, 259);
64 all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
65 0, &char_count, characters);
67 g_assert_cmpint (all_chars, ==, 2);
68 g_assert_cmpint (char_count, ==, 2);
69 g_assert_cmpint (characters[0], ==, 10);
70 g_assert_cmpint (characters[1], ==, 24030);
74 all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
75 1, &char_count, characters);
76 g_assert_cmpint (all_chars, ==, 2);
77 g_assert_cmpint (char_count, ==, 1);
78 g_assert_cmpint (characters[0], ==, 24030);
79 g_assert_cmpint (characters[1], ==, 1234);
85 unsigned int num_entries;
86 const hb_ot_name_entry_t *entries;
87 hb_ot_name_id_t name_id;
90 unsigned int text_size = 10;
91 entries = hb_ot_name_list_names (face, &num_entries);
92 g_assert_cmpuint (12, ==, num_entries);
93 name_id = entries[3].name_id;
94 g_assert_cmpuint (3, ==, name_id);
95 lang = entries[3].language;
97 g_assert_cmpstr (hb_language_to_string (lang), ==, "en");
98 g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, lang, &text_size, text));
99 g_assert_cmpuint (9, ==, text_size);
100 g_assert_cmpstr (text, ==, "FontForge");
102 g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, hb_language_from_string ("en_US", -1), &text_size, text));
103 g_assert_cmpuint (8, ==, text_size);
104 g_assert_cmpstr (text, ==, "FontForg");
106 g_assert_cmpuint (0, ==, hb_ot_name_get_utf8 (face, name_id, hb_language_from_string ("fa_IR", -1), &text_size, text));
110 main (int argc, char **argv)
113 g_test_init (&argc, &argv, NULL);
115 hb_test_add (test_ot_layout_feature_get_name_ids_and_characters);
116 hb_test_add (test_ot_name);
118 face = hb_test_open_font_file ("fonts/cv01.otf");
119 status = hb_test_run ();
120 hb_face_destroy (face);