Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Google, Inc. |
| 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 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
| 27 | #include "hb-test.h" |
| 28 | |
| 29 | /* Unit tests for hb-font.h */ |
| 30 | |
| 31 | |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 32 | static const char test_data[] = "test\0data"; |
| 33 | |
| 34 | |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 35 | static void |
| 36 | test_face_empty (void) |
| 37 | { |
| 38 | g_assert (hb_face_get_empty ()); |
| 39 | g_assert (hb_face_get_empty () == hb_face_create (hb_blob_get_empty (), 0)); |
| 40 | g_assert (hb_face_get_empty () == hb_face_create (NULL, 0)); |
Behdad Esfahbod | 74d9fa3 | 2011-05-11 23:07:47 -0400 | [diff] [blame] | 41 | |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 42 | g_assert (hb_face_reference_table (hb_face_get_empty (), HB_TAG ('h','e','a','d')) == hb_blob_get_empty ()); |
| 43 | |
| 44 | g_assert_cmpint (hb_face_get_upem (hb_face_get_empty ()), ==, 1000); |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 48 | test_face_create (void) |
| 49 | { |
| 50 | hb_face_t *face; |
| 51 | hb_blob_t *blob; |
| 52 | |
| 53 | blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL); |
| 54 | face = hb_face_create (blob, 0); |
| 55 | hb_blob_destroy (blob); |
| 56 | |
| 57 | g_assert (hb_face_reference_table (face, HB_TAG ('h','e','a','d')) == hb_blob_get_empty ()); |
| 58 | |
| 59 | g_assert_cmpint (hb_face_get_upem (face), ==, 1000); |
| 60 | |
| 61 | hb_face_destroy (face); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | static void |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 66 | free_up (void *user_data) |
| 67 | { |
| 68 | int *freed = (int *) user_data; |
| 69 | |
| 70 | g_assert (!*freed); |
| 71 | |
| 72 | (*freed)++; |
| 73 | } |
| 74 | |
| 75 | static hb_blob_t * |
Behdad Esfahbod | 7033518 | 2011-05-11 23:31:15 -0400 | [diff] [blame] | 76 | get_table (hb_face_t *face, hb_tag_t tag, void *user_data) |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 77 | { |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 78 | if (tag == HB_TAG ('a','b','c','d')) |
| 79 | return hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL); |
| 80 | |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 81 | return hb_blob_get_empty (); |
| 82 | } |
| 83 | |
| 84 | static void |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 85 | test_face_createfortables (void) |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 86 | { |
| 87 | hb_face_t *face; |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 88 | hb_blob_t *blob; |
| 89 | const char *data; |
| 90 | unsigned int len; |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 91 | int freed = 0; |
| 92 | |
| 93 | face = hb_face_create_for_tables (get_table, &freed, free_up); |
| 94 | g_assert (!freed); |
| 95 | |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 96 | g_assert (hb_face_reference_table (face, HB_TAG ('h','e','a','d')) == hb_blob_get_empty ()); |
| 97 | |
| 98 | blob = hb_face_reference_table (face, HB_TAG ('a','b','c','d')); |
| 99 | g_assert (blob != hb_blob_get_empty ()); |
| 100 | |
| 101 | data = hb_blob_get_data (blob, &len); |
| 102 | g_assert_cmpint (len, ==, sizeof (test_data)); |
| 103 | g_assert (0 == memcmp (data, test_data, sizeof (test_data))); |
| 104 | hb_blob_destroy (blob); |
| 105 | |
| 106 | g_assert_cmpint (hb_face_get_upem (face), ==, 1000); |
| 107 | |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 108 | hb_face_destroy (face); |
| 109 | g_assert (freed); |
| 110 | } |
| 111 | |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 112 | static void |
| 113 | _test_font_nil_funcs (hb_font_t *font) |
| 114 | { |
Behdad Esfahbod | 0fd8c2f | 2011-05-12 15:14:13 -0400 | [diff] [blame] | 115 | hb_codepoint_t glyph; |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 116 | hb_position_t x, y; |
| 117 | hb_glyph_extents_t extents; |
| 118 | |
| 119 | x = y = 13; |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 120 | g_assert (!hb_font_get_glyph_contour_point (font, 17, 2, &x, &y)); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 121 | g_assert_cmpint (x, ==, 0); |
| 122 | g_assert_cmpint (y, ==, 0); |
| 123 | |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 124 | x = hb_font_get_glyph_h_advance (font, 17); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 125 | g_assert_cmpint (x, ==, 0); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 126 | |
| 127 | extents.x_bearing = extents.y_bearing = 13; |
| 128 | extents.width = extents.height = 15; |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 129 | hb_font_get_glyph_extents (font, 17, &extents); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 130 | g_assert_cmpint (extents.x_bearing, ==, 0); |
| 131 | g_assert_cmpint (extents.y_bearing, ==, 0); |
| 132 | g_assert_cmpint (extents.width, ==, 0); |
| 133 | g_assert_cmpint (extents.height, ==, 0); |
| 134 | |
Behdad Esfahbod | 0fd8c2f | 2011-05-12 15:14:13 -0400 | [diff] [blame] | 135 | glyph = 3; |
| 136 | g_assert (!hb_font_get_glyph (font, 17, 2, &glyph)); |
| 137 | g_assert_cmpint (glyph, ==, 0); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 138 | |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 139 | x = 13; |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 140 | x = hb_font_get_glyph_h_kerning (font, 17, 19); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 141 | g_assert_cmpint (x, ==, 0); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void |
| 145 | _test_fontfuncs_nil (hb_font_funcs_t *ffuncs) |
| 146 | { |
| 147 | hb_blob_t *blob; |
| 148 | hb_face_t *face; |
| 149 | hb_font_t *font; |
| 150 | hb_font_t *subfont; |
| 151 | int freed = 0; |
| 152 | |
| 153 | blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL); |
| 154 | face = hb_face_create (blob, 0); |
| 155 | hb_blob_destroy (blob); |
Behdad Esfahbod | 7fc5a30 | 2011-05-12 17:48:20 -0400 | [diff] [blame] | 156 | g_assert (!hb_face_is_immutable (face)); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 157 | font = hb_font_create (face); |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 158 | g_assert (font); |
Behdad Esfahbod | 7fc5a30 | 2011-05-12 17:48:20 -0400 | [diff] [blame] | 159 | g_assert (hb_face_is_immutable (face)); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 160 | hb_face_destroy (face); |
| 161 | |
| 162 | |
| 163 | hb_font_set_funcs (font, ffuncs, &freed, free_up); |
| 164 | g_assert_cmpint (freed, ==, 0); |
| 165 | |
| 166 | _test_font_nil_funcs (font); |
| 167 | |
| 168 | subfont = hb_font_create_sub_font (font); |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 169 | g_assert (subfont); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 170 | |
| 171 | g_assert_cmpint (freed, ==, 0); |
| 172 | hb_font_destroy (font); |
| 173 | g_assert_cmpint (freed, ==, 0); |
| 174 | |
| 175 | _test_font_nil_funcs (subfont); |
| 176 | |
| 177 | hb_font_destroy (subfont); |
| 178 | g_assert_cmpint (freed, ==, 1); |
| 179 | } |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 180 | |
| 181 | static void |
| 182 | test_fontfuncs_empty (void) |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 183 | { |
| 184 | g_assert (hb_font_funcs_get_empty ()); |
| 185 | g_assert (hb_font_funcs_is_immutable (hb_font_funcs_get_empty ())); |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 186 | _test_fontfuncs_nil (hb_font_funcs_get_empty ()); |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static void |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 190 | test_fontfuncs_nil (void) |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 191 | { |
Behdad Esfahbod | 14f1e81 | 2011-05-12 00:18:28 -0400 | [diff] [blame] | 192 | hb_font_funcs_t *ffuncs; |
| 193 | |
| 194 | ffuncs = hb_font_funcs_create (); |
| 195 | |
| 196 | g_assert (!hb_font_funcs_is_immutable (ffuncs)); |
| 197 | _test_fontfuncs_nil (hb_font_funcs_get_empty ()); |
| 198 | |
| 199 | hb_font_funcs_destroy (ffuncs); |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 202 | static hb_bool_t |
| 203 | contour_point_func1 (hb_font_t *font, void *font_data, |
| 204 | hb_codepoint_t glyph, unsigned int point_index, |
| 205 | hb_position_t *x, hb_position_t *y, |
| 206 | void *user_data) |
| 207 | { |
| 208 | if (glyph == 1) { |
| 209 | *x = 2; |
| 210 | *y = 3; |
| 211 | return TRUE; |
| 212 | } |
| 213 | if (glyph == 2) { |
| 214 | *x = 4; |
| 215 | *y = 5; |
| 216 | return TRUE; |
| 217 | } |
| 218 | |
| 219 | return FALSE; |
| 220 | } |
| 221 | |
| 222 | static hb_bool_t |
| 223 | contour_point_func2 (hb_font_t *font, void *font_data, |
| 224 | hb_codepoint_t glyph, unsigned int point_index, |
| 225 | hb_position_t *x, hb_position_t *y, |
| 226 | void *user_data) |
| 227 | { |
| 228 | if (glyph == 1) { |
| 229 | *x = 6; |
| 230 | *y = 7; |
| 231 | return TRUE; |
| 232 | } |
| 233 | |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 234 | return hb_font_get_glyph_contour_point (hb_font_get_parent (font), |
| 235 | glyph, point_index, x, y); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 236 | } |
| 237 | |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 238 | static hb_position_t |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 239 | glyph_h_advance_func1 (hb_font_t *font, void *font_data, |
| 240 | hb_codepoint_t glyph, |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 241 | void *user_data) |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 242 | { |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 243 | if (glyph == 1) |
| 244 | return 8; |
| 245 | |
| 246 | return 0; |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void |
| 250 | test_fontfuncs_subclassing (void) |
| 251 | { |
| 252 | hb_blob_t *blob; |
| 253 | hb_face_t *face; |
| 254 | |
| 255 | hb_font_funcs_t *ffuncs1; |
| 256 | hb_font_funcs_t *ffuncs2; |
| 257 | |
| 258 | hb_font_t *font1; |
| 259 | hb_font_t *font2; |
| 260 | hb_font_t *font3; |
| 261 | |
| 262 | hb_position_t x; |
| 263 | hb_position_t y; |
| 264 | |
| 265 | blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL); |
| 266 | face = hb_face_create (blob, 0); |
| 267 | hb_blob_destroy (blob); |
| 268 | font1 = hb_font_create (face); |
| 269 | hb_face_destroy (face); |
| 270 | hb_font_set_scale (font1, 10, 10); |
| 271 | |
| 272 | /* setup font1 */ |
| 273 | ffuncs1 = hb_font_funcs_create (); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 274 | hb_font_funcs_set_glyph_contour_point_func (ffuncs1, contour_point_func1, NULL, NULL); |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 275 | hb_font_funcs_set_glyph_h_advance_func (ffuncs1, glyph_h_advance_func1, NULL, NULL); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 276 | hb_font_set_funcs (font1, ffuncs1, NULL, NULL); |
| 277 | hb_font_funcs_destroy (ffuncs1); |
| 278 | |
| 279 | x = y = 1; |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 280 | g_assert (hb_font_get_glyph_contour_point_for_origin (font1, 1, 2, HB_DIRECTION_LTR, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 281 | g_assert_cmpint (x, ==, 2); |
| 282 | g_assert_cmpint (y, ==, 3); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 283 | g_assert (hb_font_get_glyph_contour_point_for_origin (font1, 2, 5, HB_DIRECTION_LTR, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 284 | g_assert_cmpint (x, ==, 4); |
| 285 | g_assert_cmpint (y, ==, 5); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 286 | g_assert (!hb_font_get_glyph_contour_point_for_origin (font1, 3, 7, HB_DIRECTION_RTL, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 287 | g_assert_cmpint (x, ==, 0); |
| 288 | g_assert_cmpint (y, ==, 0); |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 289 | x = hb_font_get_glyph_h_advance (font1, 1); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 290 | g_assert_cmpint (x, ==, 8); |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 291 | x = hb_font_get_glyph_h_advance (font1, 2); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 292 | g_assert_cmpint (x, ==, 0); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 293 | |
| 294 | |
| 295 | font2 = hb_font_create_sub_font (font1); |
| 296 | g_assert (hb_font_is_immutable (font1)); |
| 297 | hb_font_destroy (font1); |
| 298 | |
| 299 | /* setup font2 to override some funcs */ |
| 300 | ffuncs2 = hb_font_funcs_create (); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 301 | hb_font_funcs_set_glyph_contour_point_func (ffuncs2, contour_point_func2, NULL, NULL); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 302 | hb_font_set_funcs (font2, ffuncs2, NULL, NULL); |
| 303 | hb_font_funcs_destroy (ffuncs2); |
| 304 | |
| 305 | x = y = 1; |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 306 | g_assert (hb_font_get_glyph_contour_point_for_origin (font2, 1, 2, HB_DIRECTION_LTR, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 307 | g_assert_cmpint (x, ==, 6); |
| 308 | g_assert_cmpint (y, ==, 7); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 309 | g_assert (hb_font_get_glyph_contour_point_for_origin (font2, 2, 5, HB_DIRECTION_RTL, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 310 | g_assert_cmpint (x, ==, 4); |
| 311 | g_assert_cmpint (y, ==, 5); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 312 | g_assert (!hb_font_get_glyph_contour_point_for_origin (font2, 3, 7, HB_DIRECTION_LTR, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 313 | g_assert_cmpint (x, ==, 0); |
| 314 | g_assert_cmpint (y, ==, 0); |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 315 | x = hb_font_get_glyph_h_advance (font2, 1); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 316 | g_assert_cmpint (x, ==, 8); |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 317 | x = hb_font_get_glyph_h_advance (font2, 2); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 318 | g_assert_cmpint (x, ==, 0); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 319 | |
| 320 | |
| 321 | font3 = hb_font_create_sub_font (font2); |
| 322 | g_assert (hb_font_is_immutable (font2)); |
| 323 | hb_font_destroy (font2); |
| 324 | |
| 325 | /* setup font3 to override scale */ |
| 326 | hb_font_set_scale (font3, 20, 30); |
| 327 | |
| 328 | x = y = 1; |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 329 | g_assert (hb_font_get_glyph_contour_point_for_origin (font3, 1, 2, HB_DIRECTION_RTL, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 330 | g_assert_cmpint (x, ==, 6*2); |
| 331 | g_assert_cmpint (y, ==, 7*3); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 332 | g_assert (hb_font_get_glyph_contour_point_for_origin (font3, 2, 5, HB_DIRECTION_LTR, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 333 | g_assert_cmpint (x, ==, 4*2); |
| 334 | g_assert_cmpint (y, ==, 5*3); |
Behdad Esfahbod | d316912 | 2011-05-25 11:01:32 -0400 | [diff] [blame] | 335 | g_assert (!hb_font_get_glyph_contour_point_for_origin (font3, 3, 7, HB_DIRECTION_LTR, &x, &y)); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 336 | g_assert_cmpint (x, ==, 0*2); |
| 337 | g_assert_cmpint (y, ==, 0*3); |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 338 | x = hb_font_get_glyph_h_advance (font3, 1); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 339 | g_assert_cmpint (x, ==, 8*2); |
Behdad Esfahbod | 2d8ebcb | 2011-05-25 11:27:33 -0400 | [diff] [blame] | 340 | x = hb_font_get_glyph_h_advance (font3, 2); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 341 | g_assert_cmpint (x, ==, 0*2); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 342 | |
| 343 | |
| 344 | hb_font_destroy (font3); |
| 345 | } |
| 346 | |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 347 | |
| 348 | static void |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 349 | test_font_empty (void) |
| 350 | { |
| 351 | g_assert (hb_font_get_empty ()); |
| 352 | g_assert (hb_font_get_empty () == hb_font_create (hb_face_get_empty ())); |
| 353 | g_assert (hb_font_get_empty () == hb_font_create (NULL)); |
| 354 | g_assert (hb_font_get_empty () == hb_font_create_sub_font (NULL)); |
| 355 | g_assert (hb_font_is_immutable (hb_font_get_empty ())); |
Behdad Esfahbod | 74d9fa3 | 2011-05-11 23:07:47 -0400 | [diff] [blame] | 356 | |
| 357 | g_assert (hb_font_get_face (hb_font_get_empty ()) == hb_face_get_empty ()); |
| 358 | g_assert (hb_font_get_parent (hb_font_get_empty ()) == NULL); |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 359 | } |
| 360 | |
Behdad Esfahbod | 606923b | 2011-05-11 23:05:02 -0400 | [diff] [blame] | 361 | static void |
| 362 | test_font_properties (void) |
| 363 | { |
| 364 | hb_blob_t *blob; |
| 365 | hb_face_t *face; |
| 366 | hb_font_t *font; |
Behdad Esfahbod | cdb1531 | 2011-05-11 23:12:58 -0400 | [diff] [blame] | 367 | hb_font_t *subfont; |
Behdad Esfahbod | 606923b | 2011-05-11 23:05:02 -0400 | [diff] [blame] | 368 | int x_scale, y_scale; |
| 369 | unsigned int x_ppem, y_ppem; |
| 370 | |
| 371 | blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL); |
| 372 | face = hb_face_create (blob, 0); |
| 373 | hb_blob_destroy (blob); |
| 374 | font = hb_font_create (face); |
| 375 | hb_face_destroy (face); |
| 376 | |
| 377 | |
Behdad Esfahbod | db9f4eb | 2011-05-11 23:06:02 -0400 | [diff] [blame] | 378 | g_assert (hb_font_get_face (font) == face); |
| 379 | g_assert (hb_font_get_parent (font) == NULL); |
| 380 | |
| 381 | |
Behdad Esfahbod | 606923b | 2011-05-11 23:05:02 -0400 | [diff] [blame] | 382 | /* Check scale */ |
| 383 | |
| 384 | hb_font_get_scale (font, NULL, NULL); |
| 385 | x_scale = y_scale = 13; |
| 386 | hb_font_get_scale (font, &x_scale, NULL); |
| 387 | g_assert_cmpint (x_scale, ==, 0); |
| 388 | x_scale = y_scale = 13; |
| 389 | hb_font_get_scale (font, NULL, &y_scale); |
| 390 | g_assert_cmpint (y_scale, ==, 0); |
| 391 | x_scale = y_scale = 13; |
| 392 | hb_font_get_scale (font, &x_scale, &y_scale); |
| 393 | g_assert_cmpint (x_scale, ==, 0); |
| 394 | g_assert_cmpint (y_scale, ==, 0); |
| 395 | |
| 396 | hb_font_set_scale (font, 17, 19); |
| 397 | |
| 398 | x_scale = y_scale = 13; |
| 399 | hb_font_get_scale (font, &x_scale, &y_scale); |
| 400 | g_assert_cmpint (x_scale, ==, 17); |
| 401 | g_assert_cmpint (y_scale, ==, 19); |
| 402 | |
| 403 | |
| 404 | /* Check ppem */ |
| 405 | |
| 406 | hb_font_get_ppem (font, NULL, NULL); |
| 407 | x_ppem = y_ppem = 13; |
| 408 | hb_font_get_ppem (font, &x_ppem, NULL); |
| 409 | g_assert_cmpint (x_ppem, ==, 0); |
| 410 | x_ppem = y_ppem = 13; |
| 411 | hb_font_get_ppem (font, NULL, &y_ppem); |
| 412 | g_assert_cmpint (y_ppem, ==, 0); |
| 413 | x_ppem = y_ppem = 13; |
| 414 | hb_font_get_ppem (font, &x_ppem, &y_ppem); |
| 415 | g_assert_cmpint (x_ppem, ==, 0); |
| 416 | g_assert_cmpint (y_ppem, ==, 0); |
| 417 | |
| 418 | hb_font_set_ppem (font, 17, 19); |
| 419 | |
| 420 | x_ppem = y_ppem = 13; |
| 421 | hb_font_get_ppem (font, &x_ppem, &y_ppem); |
| 422 | g_assert_cmpint (x_ppem, ==, 17); |
| 423 | g_assert_cmpint (y_ppem, ==, 19); |
| 424 | |
| 425 | |
| 426 | /* Check immutable */ |
| 427 | |
| 428 | g_assert (!hb_font_is_immutable (font)); |
| 429 | hb_font_make_immutable (font); |
| 430 | g_assert (hb_font_is_immutable (font)); |
| 431 | |
| 432 | hb_font_set_scale (font, 10, 12); |
| 433 | x_scale = y_scale = 13; |
| 434 | hb_font_get_scale (font, &x_scale, &y_scale); |
| 435 | g_assert_cmpint (x_scale, ==, 17); |
| 436 | g_assert_cmpint (y_scale, ==, 19); |
| 437 | |
| 438 | hb_font_set_ppem (font, 10, 12); |
| 439 | x_ppem = y_ppem = 13; |
| 440 | hb_font_get_ppem (font, &x_ppem, &y_ppem); |
| 441 | g_assert_cmpint (x_ppem, ==, 17); |
| 442 | g_assert_cmpint (y_ppem, ==, 19); |
| 443 | |
| 444 | |
Behdad Esfahbod | cdb1531 | 2011-05-11 23:12:58 -0400 | [diff] [blame] | 445 | /* sub_font now */ |
| 446 | subfont = hb_font_create_sub_font (font); |
Behdad Esfahbod | 606923b | 2011-05-11 23:05:02 -0400 | [diff] [blame] | 447 | hb_font_destroy (font); |
Behdad Esfahbod | cdb1531 | 2011-05-11 23:12:58 -0400 | [diff] [blame] | 448 | |
| 449 | g_assert (hb_font_get_parent (subfont) == font); |
| 450 | g_assert (hb_font_get_face (subfont) == face); |
| 451 | |
| 452 | /* scale */ |
| 453 | x_scale = y_scale = 13; |
| 454 | hb_font_get_scale (subfont, &x_scale, &y_scale); |
| 455 | g_assert_cmpint (x_scale, ==, 17); |
| 456 | g_assert_cmpint (y_scale, ==, 19); |
| 457 | hb_font_set_scale (subfont, 10, 12); |
| 458 | x_scale = y_scale = 13; |
| 459 | hb_font_get_scale (subfont, &x_scale, &y_scale); |
| 460 | g_assert_cmpint (x_scale, ==, 10); |
| 461 | g_assert_cmpint (y_scale, ==, 12); |
| 462 | x_scale = y_scale = 13; |
| 463 | hb_font_get_scale (font, &x_scale, &y_scale); |
| 464 | g_assert_cmpint (x_scale, ==, 17); |
| 465 | g_assert_cmpint (y_scale, ==, 19); |
| 466 | |
| 467 | /* ppem */ |
| 468 | x_ppem = y_ppem = 13; |
| 469 | hb_font_get_ppem (subfont, &x_ppem, &y_ppem); |
| 470 | g_assert_cmpint (x_ppem, ==, 17); |
| 471 | g_assert_cmpint (y_ppem, ==, 19); |
| 472 | hb_font_set_ppem (subfont, 10, 12); |
| 473 | x_ppem = y_ppem = 13; |
| 474 | hb_font_get_ppem (subfont, &x_ppem, &y_ppem); |
| 475 | g_assert_cmpint (x_ppem, ==, 10); |
| 476 | g_assert_cmpint (y_ppem, ==, 12); |
| 477 | x_ppem = y_ppem = 13; |
| 478 | hb_font_get_ppem (font, &x_ppem, &y_ppem); |
| 479 | g_assert_cmpint (x_ppem, ==, 17); |
| 480 | g_assert_cmpint (y_ppem, ==, 19); |
| 481 | |
| 482 | hb_font_destroy (subfont); |
Behdad Esfahbod | 606923b | 2011-05-11 23:05:02 -0400 | [diff] [blame] | 483 | } |
| 484 | |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 485 | int |
| 486 | main (int argc, char **argv) |
| 487 | { |
| 488 | hb_test_init (&argc, &argv); |
| 489 | |
| 490 | hb_test_add (test_face_empty); |
Behdad Esfahbod | 2ca0b5a | 2011-05-11 23:57:36 -0400 | [diff] [blame] | 491 | hb_test_add (test_face_create); |
| 492 | hb_test_add (test_face_createfortables); |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 493 | |
Behdad Esfahbod | ea93e7b | 2011-05-11 23:22:55 -0400 | [diff] [blame] | 494 | hb_test_add (test_fontfuncs_empty); |
Behdad Esfahbod | f2c1dd4 | 2011-05-12 00:35:12 -0400 | [diff] [blame] | 495 | hb_test_add (test_fontfuncs_nil); |
| 496 | hb_test_add (test_fontfuncs_subclassing); |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 497 | |
| 498 | hb_test_add (test_font_empty); |
Behdad Esfahbod | 606923b | 2011-05-11 23:05:02 -0400 | [diff] [blame] | 499 | hb_test_add (test_font_properties); |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 500 | |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 501 | return hb_test_run(); |
| 502 | } |