1*2d1272b8SAndroid Build Coastguard Worker /*
2*2d1272b8SAndroid Build Coastguard Worker * Copyright © 2018 Ebrahim Byagowi
3*2d1272b8SAndroid Build Coastguard Worker *
4*2d1272b8SAndroid Build Coastguard Worker * This is part of HarfBuzz, a text shaping library.
5*2d1272b8SAndroid Build Coastguard Worker *
6*2d1272b8SAndroid Build Coastguard Worker * Permission is hereby granted, without written agreement and without
7*2d1272b8SAndroid Build Coastguard Worker * license or royalty fees, to use, copy, modify, and distribute this
8*2d1272b8SAndroid Build Coastguard Worker * software and its documentation for any purpose, provided that the
9*2d1272b8SAndroid Build Coastguard Worker * above copyright notice and the following two paragraphs appear in
10*2d1272b8SAndroid Build Coastguard Worker * all copies of this software.
11*2d1272b8SAndroid Build Coastguard Worker *
12*2d1272b8SAndroid Build Coastguard Worker * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13*2d1272b8SAndroid Build Coastguard Worker * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14*2d1272b8SAndroid Build Coastguard Worker * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15*2d1272b8SAndroid Build Coastguard Worker * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16*2d1272b8SAndroid Build Coastguard Worker * DAMAGE.
17*2d1272b8SAndroid Build Coastguard Worker *
18*2d1272b8SAndroid Build Coastguard Worker * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19*2d1272b8SAndroid Build Coastguard Worker * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20*2d1272b8SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21*2d1272b8SAndroid Build Coastguard Worker * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22*2d1272b8SAndroid Build Coastguard Worker * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23*2d1272b8SAndroid Build Coastguard Worker */
24*2d1272b8SAndroid Build Coastguard Worker
25*2d1272b8SAndroid Build Coastguard Worker #include "hb-test.h"
26*2d1272b8SAndroid Build Coastguard Worker
27*2d1272b8SAndroid Build Coastguard Worker #include <hb-ot.h>
28*2d1272b8SAndroid Build Coastguard Worker
29*2d1272b8SAndroid Build Coastguard Worker /* Unit tests for hb-ot-layout.h baseline */
30*2d1272b8SAndroid Build Coastguard Worker
31*2d1272b8SAndroid Build Coastguard Worker static void
test_ot_layout_base(void)32*2d1272b8SAndroid Build Coastguard Worker test_ot_layout_base (void)
33*2d1272b8SAndroid Build Coastguard Worker {
34*2d1272b8SAndroid Build Coastguard Worker hb_face_t *face = hb_test_open_font_file ("fonts/base.ttf");
35*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font = hb_font_create (face);
36*2d1272b8SAndroid Build Coastguard Worker
37*2d1272b8SAndroid Build Coastguard Worker hb_position_t position;
38*2d1272b8SAndroid Build Coastguard Worker g_assert (hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB,
39*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('h','a','n','i'),
40*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
41*2d1272b8SAndroid Build Coastguard Worker &position));
42*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (46, ==, position);
43*2d1272b8SAndroid Build Coastguard Worker
44*2d1272b8SAndroid Build Coastguard Worker g_assert (hb_ot_layout_get_baseline2 (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB,
45*2d1272b8SAndroid Build Coastguard Worker HB_SCRIPT_HAN,
46*2d1272b8SAndroid Build Coastguard Worker hb_language_from_string ("en", -1),
47*2d1272b8SAndroid Build Coastguard Worker &position));
48*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (46, ==, position);
49*2d1272b8SAndroid Build Coastguard Worker
50*2d1272b8SAndroid Build Coastguard Worker g_assert (!hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, HB_DIRECTION_TTB,
51*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('h','a','n','i'),
52*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
53*2d1272b8SAndroid Build Coastguard Worker &position));
54*2d1272b8SAndroid Build Coastguard Worker
55*2d1272b8SAndroid Build Coastguard Worker hb_font_destroy (font);
56*2d1272b8SAndroid Build Coastguard Worker hb_face_destroy (face);
57*2d1272b8SAndroid Build Coastguard Worker }
58*2d1272b8SAndroid Build Coastguard Worker
59*2d1272b8SAndroid Build Coastguard Worker static void
test_ot_layout_base_with_fallback(void)60*2d1272b8SAndroid Build Coastguard Worker test_ot_layout_base_with_fallback (void)
61*2d1272b8SAndroid Build Coastguard Worker {
62*2d1272b8SAndroid Build Coastguard Worker hb_face_t *face = hb_test_open_font_file ("fonts/base.ttf");
63*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font = hb_font_create (face);
64*2d1272b8SAndroid Build Coastguard Worker
65*2d1272b8SAndroid Build Coastguard Worker hb_position_t position;
66*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline_with_fallback (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB,
67*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('h','a','n','i'),
68*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
69*2d1272b8SAndroid Build Coastguard Worker &position);
70*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (46, ==, position);
71*2d1272b8SAndroid Build Coastguard Worker
72*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline_with_fallback2 (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB,
73*2d1272b8SAndroid Build Coastguard Worker HB_SCRIPT_HAN,
74*2d1272b8SAndroid Build Coastguard Worker hb_language_from_string ("en", -1),
75*2d1272b8SAndroid Build Coastguard Worker &position);
76*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (46, ==, position);
77*2d1272b8SAndroid Build Coastguard Worker
78*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline_with_fallback (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, HB_DIRECTION_TTB,
79*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('h','a','n','i'),
80*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
81*2d1272b8SAndroid Build Coastguard Worker &position);
82*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (1000, ==, position);
83*2d1272b8SAndroid Build Coastguard Worker
84*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline_with_fallback (font, HB_OT_LAYOUT_BASELINE_TAG_MATH, HB_DIRECTION_LTR,
85*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('h','a','n','i'),
86*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
87*2d1272b8SAndroid Build Coastguard Worker &position);
88*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (271, ==, position);
89*2d1272b8SAndroid Build Coastguard Worker
90*2d1272b8SAndroid Build Coastguard Worker hb_font_destroy (font);
91*2d1272b8SAndroid Build Coastguard Worker hb_face_destroy (face);
92*2d1272b8SAndroid Build Coastguard Worker
93*2d1272b8SAndroid Build Coastguard Worker face = hb_test_open_font_file ("fonts/base2.ttf");
94*2d1272b8SAndroid Build Coastguard Worker font = hb_font_create (face);
95*2d1272b8SAndroid Build Coastguard Worker
96*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline_with_fallback (font, HB_OT_LAYOUT_BASELINE_TAG_HANGING, HB_DIRECTION_LTR,
97*2d1272b8SAndroid Build Coastguard Worker HB_SCRIPT_BENGALI,
98*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
99*2d1272b8SAndroid Build Coastguard Worker &position);
100*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (622, ==, position);
101*2d1272b8SAndroid Build Coastguard Worker
102*2d1272b8SAndroid Build Coastguard Worker hb_ot_layout_get_baseline_with_fallback (font, HB_OT_LAYOUT_BASELINE_TAG_HANGING, HB_DIRECTION_LTR,
103*2d1272b8SAndroid Build Coastguard Worker HB_SCRIPT_TIBETAN,
104*2d1272b8SAndroid Build Coastguard Worker HB_TAG ('E','N','G',' '),
105*2d1272b8SAndroid Build Coastguard Worker &position);
106*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpint (600, ==, position);
107*2d1272b8SAndroid Build Coastguard Worker
108*2d1272b8SAndroid Build Coastguard Worker hb_font_destroy (font);
109*2d1272b8SAndroid Build Coastguard Worker hb_face_destroy (face);
110*2d1272b8SAndroid Build Coastguard Worker }
111*2d1272b8SAndroid Build Coastguard Worker
112*2d1272b8SAndroid Build Coastguard Worker int
main(int argc,char ** argv)113*2d1272b8SAndroid Build Coastguard Worker main (int argc, char **argv)
114*2d1272b8SAndroid Build Coastguard Worker {
115*2d1272b8SAndroid Build Coastguard Worker hb_test_init (&argc, &argv);
116*2d1272b8SAndroid Build Coastguard Worker
117*2d1272b8SAndroid Build Coastguard Worker hb_test_add (test_ot_layout_base);
118*2d1272b8SAndroid Build Coastguard Worker hb_test_add (test_ot_layout_base_with_fallback);
119*2d1272b8SAndroid Build Coastguard Worker
120*2d1272b8SAndroid Build Coastguard Worker return hb_test_run();
121*2d1272b8SAndroid Build Coastguard Worker }
122