test-subset-repacker.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright © 2022 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. */
  25. #include "hb-test.h"
  26. #include "hb-subset-test.h"
  27. #ifdef HB_EXPERIMENTAL_API
  28. #include "hb-subset-repacker.h"
  29. char test_gsub_data[106] = "\x0\x1\x0\x0\x0\xa\x0\x1e\x0\x2c\x0\x1\x6c\x61\x74\x6e\x0\x8\x0\x4\x0\x0\x0\x0\xff\xff\x0\x1\x0\x0\x0\x1\x74\x65\x73\x74\x0\x8\x0\x0\x0\x1\x0\x1\x0\x2\x0\x2a\x0\x6\x0\x5\x0\x0\x0\x1\x0\x8\x0\x1\x0\x8\x0\x1\x0\xe\x0\x1\x0\x1\x0\x1\x0\x1\x0\x4\x0\x2\x0\x1\x0\x2\x0\x1\x0\x0\x0\x1\x0\x0\x0\x1\x0\x8\x0\x1\x0\x6\x0\x1\x0\x1\x0\x1\x0\x2";
  30. static void
  31. test_hb_repack_with_cy_struct (void)
  32. {
  33. hb_object_t *hb_objs = calloc (15, sizeof (hb_object_t));
  34. hb_objs[0].head = &(test_gsub_data[100]);
  35. hb_objs[0].tail = &(test_gsub_data[105]) + 1;
  36. hb_objs[0].num_real_links = 0;
  37. hb_objs[0].num_virtual_links = 0;
  38. hb_objs[0].real_links = NULL;
  39. hb_objs[0].virtual_links = NULL;
  40. hb_objs[1].head = &(test_gsub_data[94]);
  41. hb_objs[1].tail = &(test_gsub_data[100]);
  42. hb_objs[1].num_real_links = 1;
  43. hb_objs[1].num_virtual_links = 0;
  44. hb_objs[1].real_links = malloc (sizeof (hb_link_t));
  45. hb_objs[1].real_links[0].width = 2;
  46. hb_objs[1].real_links[0].position = 2;
  47. hb_objs[1].real_links[0].objidx = 1;
  48. hb_objs[1].virtual_links = NULL;
  49. hb_objs[2].head = &(test_gsub_data[86]);
  50. hb_objs[2].tail = &(test_gsub_data[94]);
  51. hb_objs[2].num_real_links = 1;
  52. hb_objs[2].num_virtual_links = 0;
  53. hb_objs[2].real_links = malloc (sizeof (hb_link_t));
  54. hb_objs[2].real_links[0].width = 2;
  55. hb_objs[2].real_links[0].position = 6;
  56. hb_objs[2].real_links[0].objidx = 2;
  57. hb_objs[2].virtual_links = NULL;
  58. hb_objs[3].head = &(test_gsub_data[76]);
  59. hb_objs[3].tail = &(test_gsub_data[86]);
  60. hb_objs[3].num_real_links = 0;
  61. hb_objs[3].num_virtual_links = 0;
  62. hb_objs[3].real_links = NULL;
  63. hb_objs[3].virtual_links = NULL;
  64. hb_objs[4].head = &(test_gsub_data[72]);
  65. hb_objs[4].tail = &(test_gsub_data[76]);
  66. hb_objs[4].num_real_links = 1;
  67. hb_objs[4].num_virtual_links = 0;
  68. hb_objs[4].real_links = malloc (sizeof (hb_link_t));
  69. hb_objs[4].real_links[0].width = 2;
  70. hb_objs[4].real_links[0].position = 2;
  71. hb_objs[4].real_links[0].objidx = 4;
  72. hb_objs[4].virtual_links = NULL;
  73. hb_objs[5].head = &(test_gsub_data[66]);
  74. hb_objs[5].tail = &(test_gsub_data[72]);
  75. hb_objs[5].num_real_links = 0;
  76. hb_objs[5].num_virtual_links = 0;
  77. hb_objs[5].real_links = NULL;
  78. hb_objs[5].virtual_links = NULL;
  79. hb_objs[6].head = &(test_gsub_data[58]);
  80. hb_objs[6].tail = &(test_gsub_data[66]);
  81. hb_objs[6].num_real_links = 2;
  82. hb_objs[6].num_virtual_links = 0;
  83. hb_objs[6].real_links = calloc (2, sizeof (hb_link_t));
  84. hb_objs[6].real_links[0].width = 2;
  85. hb_objs[6].real_links[0].position = 6;
  86. hb_objs[6].real_links[0].objidx = 5;
  87. hb_objs[6].real_links[1].width = 2;
  88. hb_objs[6].real_links[1].position = 2;
  89. hb_objs[6].real_links[1].objidx = 6;
  90. hb_objs[6].virtual_links = NULL;
  91. hb_objs[7].head = &(test_gsub_data[50]);
  92. hb_objs[7].tail = &(test_gsub_data[58]);
  93. hb_objs[7].num_real_links = 1;
  94. hb_objs[7].num_virtual_links = 0;
  95. hb_objs[7].real_links = malloc (sizeof (hb_link_t));
  96. hb_objs[7].real_links[0].width = 2;
  97. hb_objs[7].real_links[0].position = 6;
  98. hb_objs[7].real_links[0].objidx = 7;
  99. hb_objs[7].virtual_links = NULL;
  100. hb_objs[8].head = &(test_gsub_data[44]);
  101. hb_objs[8].tail = &(test_gsub_data[50]);
  102. hb_objs[8].num_real_links = 2;
  103. hb_objs[8].num_virtual_links = 0;
  104. hb_objs[8].real_links = calloc (2, sizeof (hb_link_t));
  105. hb_objs[8].real_links[0].width = 2;
  106. hb_objs[8].real_links[0].position = 2;
  107. hb_objs[8].real_links[0].objidx = 3;
  108. hb_objs[8].real_links[1].width = 2;
  109. hb_objs[8].real_links[1].position = 4;
  110. hb_objs[8].real_links[1].objidx = 8;
  111. hb_objs[8].virtual_links = NULL;
  112. hb_objs[9].head = &(test_gsub_data[38]);
  113. hb_objs[9].tail = &(test_gsub_data[44]);
  114. hb_objs[9].num_real_links = 0;
  115. hb_objs[9].num_virtual_links = 0;
  116. hb_objs[9].real_links = NULL;
  117. hb_objs[9].virtual_links = NULL;
  118. hb_objs[10].head = &(test_gsub_data[30]);
  119. hb_objs[10].tail = &(test_gsub_data[38]);
  120. hb_objs[10].num_real_links = 1;
  121. hb_objs[10].num_virtual_links = 0;
  122. hb_objs[10].real_links = malloc (sizeof (hb_link_t));
  123. hb_objs[10].real_links[0].width = 2;
  124. hb_objs[10].real_links[0].position = 6;
  125. hb_objs[10].real_links[0].objidx = 10;
  126. hb_objs[10].virtual_links = NULL;
  127. hb_objs[11].head = &(test_gsub_data[22]);
  128. hb_objs[11].tail = &(test_gsub_data[30]);
  129. hb_objs[11].num_real_links = 0;
  130. hb_objs[11].num_virtual_links = 0;
  131. hb_objs[11].real_links = NULL;
  132. hb_objs[11].virtual_links = NULL;
  133. hb_objs[12].head = &(test_gsub_data[18]);
  134. hb_objs[12].tail = &(test_gsub_data[22]);
  135. hb_objs[12].num_real_links = 1;
  136. hb_objs[12].num_virtual_links = 0;
  137. hb_objs[12].real_links = malloc (sizeof (hb_link_t));
  138. hb_objs[12].real_links[0].width = 2;
  139. hb_objs[12].real_links[0].position = 0;
  140. hb_objs[12].real_links[0].objidx = 12;
  141. hb_objs[12].virtual_links = NULL;
  142. hb_objs[13].head = &(test_gsub_data[10]);
  143. hb_objs[13].tail = &(test_gsub_data[18]);
  144. hb_objs[13].num_real_links = 1;
  145. hb_objs[13].num_virtual_links = 0;
  146. hb_objs[13].real_links = malloc (sizeof (hb_link_t));
  147. hb_objs[13].real_links[0].width = 2;
  148. hb_objs[13].real_links[0].position = 6;
  149. hb_objs[13].real_links[0].objidx = 13;
  150. hb_objs[13].virtual_links = NULL;
  151. hb_objs[14].head = &(test_gsub_data[0]);
  152. hb_objs[14].tail = &(test_gsub_data[10]);
  153. hb_objs[14].num_real_links = 3;
  154. hb_objs[14].num_virtual_links = 0;
  155. hb_objs[14].real_links = calloc (3, sizeof (hb_link_t));
  156. hb_objs[14].real_links[0].width = 2;
  157. hb_objs[14].real_links[0].position = 8;
  158. hb_objs[14].real_links[0].objidx = 9;
  159. hb_objs[14].real_links[1].width = 2;
  160. hb_objs[14].real_links[1].position = 6;
  161. hb_objs[14].real_links[1].objidx = 11;
  162. hb_objs[14].real_links[2].width = 2;
  163. hb_objs[14].real_links[2].position = 4;
  164. hb_objs[14].real_links[2].objidx = 14;
  165. hb_objs[14].virtual_links = NULL;
  166. hb_blob_t *result = hb_subset_repack_or_fail (HB_TAG_NONE, hb_objs, 15);
  167. hb_face_t *face_expected = hb_test_open_font_file ("fonts/repacker_expected.otf");
  168. hb_blob_t *expected_blob = hb_face_reference_table (face_expected, HB_TAG ('G','S','U','B'));
  169. fprintf(stderr, "expected %d bytes, actual %d bytes\n", hb_blob_get_length(expected_blob), hb_blob_get_length (result));
  170. if (hb_blob_get_length (expected_blob) != 0 ||
  171. hb_blob_get_length (result) != 0)
  172. hb_test_assert_blobs_equal (expected_blob, result);
  173. hb_face_destroy (face_expected);
  174. hb_blob_destroy (expected_blob);
  175. hb_blob_destroy (result);
  176. for (unsigned i = 0 ; i < 15; i++)
  177. {
  178. if (hb_objs[i].real_links != NULL)
  179. free (hb_objs[i].real_links);
  180. }
  181. free (hb_objs);
  182. }
  183. int
  184. main (int argc, char **argv)
  185. {
  186. hb_test_init (&argc, &argv);
  187. hb_test_add (test_hb_repack_with_cy_struct);
  188. return hb_test_run();
  189. }
  190. #else
  191. int main (int argc HB_UNUSED, char **argv HB_UNUSED)
  192. {
  193. return 0;
  194. }
  195. #endif