xref: /aosp_15_r20/external/harfbuzz_ng/test/api/test-be-glyph-advance.c (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 /*
2  * Copyright © 2022  Behdad Esfahbod
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 #include "hb-test.h"
26 
27 #include <hb.h>
28 
29 static void
test_maxp_and_hmtx(void)30 test_maxp_and_hmtx (void)
31 {
32   hb_face_t *face;
33   hb_font_t *font;
34 
35   const char maxp_data[] = "\x00\x00\x50\x00" // version
36 			   "\x00\x05" // numGlyphs
37 			   ;
38   const char loca_data[18] = "";
39   const char hhea_data[36] =
40     "\x00\x01\x00\x00" /* FixedVersion<>version;	 * 0x00010000u for version 1.0. */
41     "\x02\x00" /* FWORD		ascender;	 * Typographic ascent. */
42     "\x00\x10" /* FWORD		descender;	 * Typographic descent. */
43     "\x00\x00" /* FWORD		lineGap;	 * Typographic line gap. */
44     "\x00\x00" /* UFWORD	advanceMax;	 * Maximum advance width/height value in metrics table. */
45     "\x00\x00" /* FWORD		minLeadingBearing;  * Minimum left/top sidebearing value in metrics table. */
46     "\x00\x00" /* FWORD		minTrailingBearing;  * Minimum right/bottom sidebearing value; */
47     "\x01\x00" /* FWORD		maxExtent;	 * horizontal: Max(lsb + (xMax - xMin)), */
48     "\x00\x00" /* HBINT16	caretSlopeRise;	 * Used to calculate the slope of the,*/
49     "\x00\x00" /* HBINT16	caretSlopeRun;	 * 0 for vertical caret, 1 for horizontal. */
50     "\x00\x00" /* HBINT16	caretOffset;	 * The amount by which a slanted */
51     "\x00\x00" /* HBINT16	reserved1;	 * Set to 0. */
52     "\x00\x00" /* HBINT16	reserved2;	 * Set to 0. */
53     "\x00\x00" /* HBINT16	reserved3;	 * Set to 0. */
54     "\x00\x00" /* HBINT16	reserved4;	 * Set to 0. */
55     "\x00\x00" /* HBINT16	metricDataFormat; * 0 for current format. */
56     "\x00\x02" /* HBUINT16	numberOfLongMetrics;  * Number of LongMetric entries in metric table. */
57     ;
58   const char hmtx_data[18] =
59     "\x00\x01\x00\x02"	/* glyph 0 advance lsb */
60     "\x00\x03\x00\x04"	/* glyph 1 advance lsb */
61     "\x00\x05"		/* glyph 2         lsb */
62     "\x00\x06"		/* glyph 3         lsb */
63     "\x00\x07"		/* glyph 4         lsb */
64     "\x00\x08"		/* glyph 5 advance */
65     "\x00\x09"		/* glyph 6 advance */
66     ;
67 
68   face = hb_face_builder_create ();
69   HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
70   HB_FACE_ADD_TABLE (face, "loca", loca_data);
71   HB_FACE_ADD_TABLE (face, "hhea", hhea_data);
72   HB_FACE_ADD_TABLE (face, "hmtx", hmtx_data);
73   font = hb_font_create (face);
74   hb_face_destroy (face);
75   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 0), ==, 1);
76   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 1), ==, 3);
77   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 2), ==, 3);
78   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 3), ==, 3);
79   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 4), ==, 3);
80 #ifndef HB_NO_BEYOND_64K
81   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 5), ==, 8);
82   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 6), ==, 9);
83   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 7), ==, 9);
84 #endif
85   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 8), ==, 0);
86   g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 9), ==, 0);
87   g_assert_cmpuint (hb_font_get_glyph_h_advance (font,10), ==, 0);
88   g_assert_cmpuint (hb_font_get_glyph_h_advance (font,11), ==, 0);
89   hb_font_destroy (font);
90 }
91 
92 
93 int
main(int argc,char ** argv)94 main (int argc, char **argv)
95 {
96   hb_test_init (&argc, &argv);
97 
98   hb_test_add (test_maxp_and_hmtx);
99 
100   return hb_test_run();
101 }
102