• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2018  Ebrahim Byagowi
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
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.
11  *
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
16  * DAMAGE.
17  *
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.
23  *
24  */
25 
26 #include "hb-test.h"
27 
28 #include <hb-ot.h>
29 
30 static hb_face_t *face;
31 
32 static void
test_ot_layout_feature_get_name_ids_and_characters(void)33 test_ot_layout_feature_get_name_ids_and_characters (void)
34 {
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,
46 					   HB_OT_TAG_GSUB,
47 					   0,
48 					   HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
49 					   cv01,
50 					   &feature_index))
51      g_error ("Failed to find feature index");
52 
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");
57 
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);
63 
64   all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
65 						   0, &char_count, characters);
66 
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);
71 }
72 
73 static void
test_ot_name(void)74 test_ot_name (void)
75 {
76   unsigned int num_entries;
77   const hb_ot_name_entry_t *entries;
78   hb_ot_name_id_t name_id;
79   hb_language_t lang;
80   char text[10];
81   unsigned int text_size = 10;
82   entries = hb_ot_name_list_names (face, &num_entries);
83   g_assert_cmpuint (12, ==, num_entries);
84   name_id = entries[3].name_id;
85   g_assert_cmpuint (3, ==, name_id);
86   lang = entries[3].language;
87   g_assert_cmpstr (hb_language_to_string (lang), ==, "en");
88   g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, lang, &text_size, text));
89   g_assert_cmpuint (9, ==, text_size);
90   g_assert_cmpstr (text, ==, "FontForge");
91 }
92 
93 int
main(int argc,char ** argv)94 main (int argc, char **argv)
95 {
96   unsigned int status;
97   g_test_init (&argc, &argv, NULL);
98 
99   hb_test_add (test_ot_layout_feature_get_name_ids_and_characters);
100   hb_test_add (test_ot_name);
101 
102   face = hb_test_open_font_file ("fonts/cv01.otf");
103   status = hb_test_run ();
104   hb_face_destroy (face);
105   return status;
106 }
107