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.
31 test_ot_layout_get_ligature_carets_aat_lcar (void)
33 hb_face_t *face = hb_test_open_font_file ("fonts/lcar.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);
37 hb_position_t caret_array[16];
41 unsigned caret_count = 16;
42 g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
46 g_assert_cmpuint (2, ==, caret_count);
47 g_assert_cmpuint (1130, ==, caret_array[0]);
48 g_assert_cmpuint (2344, ==, caret_array[1]);
51 /* RTL, maybe needs to be tweaked however */
53 unsigned caret_count = 16;
54 g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL,
58 g_assert_cmpuint (2, ==, caret_count);
59 g_assert_cmpuint (1130, ==, caret_array[0]);
60 g_assert_cmpuint (2344, ==, caret_array[1]);
63 /* bottom to top call, bigger caret positions as the specified scaling */
65 unsigned caret_count = 16;
66 g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_BTT,
70 g_assert_cmpuint (2, ==, caret_count);
71 g_assert_cmpuint (2260, ==, caret_array[0]);
72 g_assert_cmpuint (4688, ==, caret_array[1]);
75 /* the same glyph as above but with offset */
79 unsigned caret_count = 16;
80 g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_BTT,
84 g_assert_cmpuint (1, ==, caret_count);
85 g_assert_cmpuint (4688, ==, caret_array[0]);
87 g_assert_cmpuint (123, ==, caret_array[1]);
92 unsigned caret_count = 16;
93 g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
97 g_assert_cmpuint (0, ==, caret_count);
100 hb_font_destroy (font);
101 hb_face_destroy (face);
105 test_ot_layout_get_ligature_carets_ot_gsub (void)
107 hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
108 hb_font_t *font = hb_font_create (face);
109 hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
111 hb_position_t caret_array[16];
113 /* call with no result */
115 unsigned caret_count = 16;
116 g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
117 188, 0, &caret_count,
120 g_assert_cmpuint (0, ==, caret_count);
123 /* call with no result and some offset */
125 unsigned caret_count = 16;
126 g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
127 188, 10, &caret_count,
130 g_assert_cmpuint (0, ==, caret_count);
133 /* a glyph with 3 ligature carets */
135 unsigned caret_count = 16;
136 g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
137 1020, 0, &caret_count,
140 g_assert_cmpuint (3, ==, caret_count);
141 g_assert_cmpuint (2718, ==, caret_array[0]);
142 g_assert_cmpuint (5438, ==, caret_array[1]);
143 g_assert_cmpuint (8156, ==, caret_array[2]);
146 /* the same glyph as above but with offset */
148 caret_array[2] = 123;
150 unsigned caret_count = 16;
151 g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
152 1020, 1, &caret_count,
155 g_assert_cmpuint (2, ==, caret_count);
156 g_assert_cmpuint (5438, ==, caret_array[0]);
157 g_assert_cmpuint (8156, ==, caret_array[1]);
159 g_assert_cmpuint (123, ==, caret_array[2]);
162 /* the same glyph as above but with another offset */
164 unsigned caret_count = 16;
165 g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
166 1020, 2, &caret_count,
169 g_assert_cmpuint (1, ==, caret_count);
170 g_assert_cmpuint (8156, ==, caret_array[0]);
173 /* call with no result */
175 unsigned caret_count = 16;
176 g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
177 1021, 0, &caret_count,
180 g_assert_cmpuint (0, ==, caret_count);
183 /* a glyph with 1 ligature caret */
185 unsigned caret_count = 16;
186 g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
187 1022, 0, &caret_count,
190 g_assert_cmpuint (1, ==, caret_count);
191 g_assert_cmpuint (3530, ==, caret_array[0]);
194 /* the same glyph as above but with offset */
196 unsigned caret_count = 16;
197 g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
198 1022, 1, &caret_count,
201 g_assert_cmpuint (0, ==, caret_count);
204 /* a glyph with 2 ligature carets */
206 unsigned caret_count = 16;
207 g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
208 1023, 0, &caret_count,
211 g_assert_cmpuint (2, ==, caret_count);
212 g_assert_cmpuint (2352, ==, caret_array[0]);
213 g_assert_cmpuint (4706, ==, caret_array[1]);
216 hb_font_destroy (font);
217 hb_face_destroy (face);
221 test_ot_layout_get_ligature_carets_empty (void)
223 hb_face_t *face = hb_face_get_empty ();
224 hb_font_t *font = hb_font_create (face);
225 hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
227 hb_position_t caret_array[3];
228 unsigned int caret_count = 3;
229 g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL,
230 1024, 0, &caret_count,
233 g_assert_cmpuint (0, ==, caret_count);
235 hb_font_destroy (font);
236 hb_face_destroy (face);
240 main (int argc, char **argv)
242 g_test_init (&argc, &argv, NULL);
244 hb_test_add (test_ot_layout_get_ligature_carets_aat_lcar);
245 hb_test_add (test_ot_layout_get_ligature_carets_ot_gsub);
246 hb_test_add (test_ot_layout_get_ligature_carets_empty);
248 return hb_test_run ();