test-font.c 17 KB

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