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 void
test_ot_layout_get_ligature_carets_ot_gdef(void)31 test_ot_layout_get_ligature_carets_ot_gdef (void)
32 {
33   hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
34   hb_font_t *font = hb_font_create (face);
35   hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
36 
37   hb_position_t caret_array[16];
38 
39   /* call with no result */
40   {
41     unsigned caret_count = 16;
42     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
43 							       188, 0, &caret_count,
44 							       caret_array));
45 
46     g_assert_cmpuint (0, ==, caret_count);
47   }
48 
49   /* call with no result and some offset */
50   {
51     unsigned caret_count = 16;
52     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
53 							       188, 10, &caret_count,
54 							       caret_array));
55 
56     g_assert_cmpuint (0, ==, caret_count);
57   }
58 
59   /* a glyph with 3 ligature carets */
60   {
61     unsigned caret_count = 16;
62     g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
63 							       1020, 0, &caret_count,
64 							       caret_array));
65 
66     g_assert_cmpuint (3, ==, caret_count);
67     g_assert_cmpuint (2718, ==, caret_array[0]);
68     g_assert_cmpuint (5438, ==, caret_array[1]);
69     g_assert_cmpuint (8156, ==, caret_array[2]);
70   }
71 
72   /* the same glyph as above but with offset */
73   {
74     caret_array[2] = 123;
75 
76     unsigned caret_count = 16;
77     g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
78 							       1020, 1, &caret_count,
79 							       caret_array));
80 
81     g_assert_cmpuint (2, ==, caret_count);
82     g_assert_cmpuint (5438, ==, caret_array[0]);
83     g_assert_cmpuint (8156, ==, caret_array[1]);
84 
85     g_assert_cmpuint (123, ==, caret_array[2]);
86   }
87 
88   /* the same glyph as above but with another offset */
89   {
90     unsigned caret_count = 16;
91     g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
92 							       1020, 2, &caret_count,
93 							       caret_array));
94 
95     g_assert_cmpuint (1, ==, caret_count);
96     g_assert_cmpuint (8156, ==, caret_array[0]);
97   }
98 
99   /* call with no result */
100   {
101     unsigned caret_count = 16;
102     g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
103 							       1021, 0, &caret_count,
104 							       caret_array));
105 
106     g_assert_cmpuint (0, ==, caret_count);
107   }
108 
109   /* a glyph with 1 ligature caret */
110   {
111     unsigned caret_count = 16;
112     g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
113 							       1022, 0, &caret_count,
114 							       caret_array));
115 
116     g_assert_cmpuint (1, ==, caret_count);
117     g_assert_cmpuint (3530, ==, caret_array[0]);
118   }
119 
120   /* the same glyph as above but with offset */
121   {
122     unsigned caret_count = 16;
123     g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
124 							       1022, 1, &caret_count,
125 							       caret_array));
126 
127     g_assert_cmpuint (0, ==, caret_count);
128   }
129 
130   /* a glyph with 2 ligature carets */
131   {
132     unsigned caret_count = 16;
133     g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
134 							       1023, 0, &caret_count,
135 							       caret_array));
136 
137     g_assert_cmpuint (2, ==, caret_count);
138     g_assert_cmpuint (2352, ==, caret_array[0]);
139     g_assert_cmpuint (4706, ==, caret_array[1]);
140   }
141 
142   hb_font_destroy (font);
143   hb_face_destroy (face);
144 }
145 
146 static void
test_ot_layout_get_ligature_carets_empty(void)147 test_ot_layout_get_ligature_carets_empty (void)
148 {
149   hb_face_t *face = hb_face_get_empty ();
150   hb_font_t *font = hb_font_create (face);
151   hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
152 
153   hb_position_t caret_array[3];
154   unsigned int caret_count = 3;
155   g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL,
156 							     1024, 0, &caret_count,
157 							     caret_array));
158 
159   g_assert_cmpuint (0, ==, caret_count);
160 
161   hb_font_destroy (font);
162   hb_face_destroy (face);
163 }
164 
165 int
main(int argc,char ** argv)166 main (int argc, char **argv)
167 {
168   g_test_init (&argc, &argv, NULL);
169 
170   hb_test_add (test_ot_layout_get_ligature_carets_ot_gdef);
171   hb_test_add (test_ot_layout_get_ligature_carets_empty);
172 
173   return hb_test_run ();
174 }
175