test-hb-subset-parsing.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include "glib.h"
  4. #include "hb-subset.h"
  5. #include "helper-subset.hh"
  6. static
  7. hb_face_t* open_font(const char* path)
  8. {
  9. hb_face_t *face = hb_face_create_from_file_or_fail (path, 0);
  10. g_assert (face);
  11. return face;
  12. }
  13. static
  14. gboolean check_parsing(hb_face_t* face, const char* spec, hb_tag_t axis, float exp_min, float exp_def, float exp_max)
  15. {
  16. printf(">> testing spec: %s\n", spec);
  17. hb_subset_input_t* input = hb_subset_input_create_or_fail();
  18. g_assert(input);
  19. {
  20. GError* error;
  21. char *spec_copy = g_strdup (spec);
  22. gboolean res = parse_instancing_spec(spec_copy, face, input, &error);
  23. g_free(spec_copy);
  24. if (!res) {
  25. hb_subset_input_destroy(input);
  26. return res;
  27. }
  28. }
  29. float act_min = 0.0, act_def = 0.0, act_max = 0.0;
  30. hb_bool_t res = hb_subset_input_get_axis_range(input, axis, &act_min, &act_max, &act_def);
  31. if (!res) {
  32. hb_subset_input_destroy(input);
  33. return false;
  34. }
  35. g_assert_cmpuint(exp_min, ==, act_min);
  36. g_assert_cmpuint(exp_def, ==, act_def);
  37. g_assert_cmpuint(exp_max, ==, act_max);
  38. hb_subset_input_destroy(input);
  39. return true;
  40. }
  41. static hb_tag_t wght = HB_TAG('w', 'g', 'h', 't');
  42. static hb_tag_t xxxx = HB_TAG('x', 'x', 'x', 'x');
  43. static void
  44. test_parse_instancing_spec (void)
  45. {
  46. hb_face_t* face = open_font("../test/api/fonts/AdobeVFPrototype-Subset.otf");
  47. hb_face_t* roboto = open_font("../test/api/fonts/Roboto-Variable.abc.ttf");
  48. g_assert(check_parsing(face, "wght=300", wght, 300, 300, 300));
  49. g_assert(check_parsing(face, "wght=100:200:300", wght, 100, 200, 300));
  50. g_assert(check_parsing(face, "wght=:500:", wght, 0, 500, 1000));
  51. g_assert(check_parsing(face, "wght=::700", wght, 0, 700, 700));
  52. g_assert(check_parsing(face, "wght=200::", wght, 200, 1000, 1000));
  53. g_assert(check_parsing(face, "wght=200:300:", wght, 200, 300, 1000));
  54. g_assert(check_parsing(face, "wght=:300:500", wght, 0, 300, 500));
  55. g_assert(check_parsing(face, "wght=300::700", wght, 300, 700, 700));
  56. g_assert(check_parsing(face, "wght=300:700", wght, 300, 700, 700));
  57. g_assert(check_parsing(face, "wght=:700", wght, 0, 700, 700));
  58. g_assert(check_parsing(face, "wght=200:", wght, 200, 1000, 1000));
  59. g_assert(check_parsing(face, "wght=200: xxxx=50", wght, 200, 1000, 1000));
  60. g_assert(check_parsing(face, "wght=200: xxxx=50", xxxx, 50, 50, 50));
  61. g_assert(check_parsing(face, "wght=200:,xxxx=50", wght, 200, 1000, 1000));
  62. g_assert(check_parsing(face, "wght=200:,xxxx=50", xxxx, 50, 50, 50));
  63. g_assert(check_parsing(face, "wght=200,*=drop", wght, 1000, 1000, 1000));
  64. g_assert(check_parsing(face, "wght=200,*=drop", xxxx, 0, 0, 0));
  65. g_assert(check_parsing(face, "*=drop,wght=200", wght, 200, 200, 200));
  66. g_assert(check_parsing(face, "*=drop,wght=200", xxxx, 0, 0, 0));
  67. g_assert(check_parsing(face, "*=drop,wght=200,xxxx=50", wght, 200, 200, 200));
  68. g_assert(check_parsing(face, "*=drop,wght=200,xxxx=50", xxxx, 50, 50, 50));
  69. g_assert(check_parsing(face, "xxxx=50,*=drop,wght=200", wght, 200, 200, 200));
  70. g_assert(check_parsing(face, "xxxx=50,*=drop,wght=200", xxxx, 0, 0, 0));
  71. g_assert(check_parsing(face, "*=drop", wght, 1000, 1000, 1000));
  72. g_assert(check_parsing(face, "*=drop", xxxx, 0, 0, 0));
  73. g_assert(check_parsing(roboto, "wght=300", wght, 300, 300, 300));
  74. g_assert(check_parsing(roboto, "wght=100:200:300", wght, 100, 200, 300));
  75. g_assert(check_parsing(roboto, "wght=:500:", wght, 100, 500, 900));
  76. g_assert(check_parsing(roboto, "wght=::850", wght, 100, 400, 850));
  77. g_assert(check_parsing(roboto, "wght=200::", wght, 200, 400, 900));
  78. g_assert(check_parsing(roboto, "wght=200:300:", wght, 200, 300, 900));
  79. g_assert(check_parsing(roboto, "wght=:300:500", wght, 100, 300, 500));
  80. g_assert(check_parsing(roboto, "wght=300::700", wght, 300, 400, 700));
  81. g_assert(check_parsing(roboto, "wght=300:700", wght, 300, 400, 700));
  82. g_assert(check_parsing(roboto, "wght=:700", wght, 100, 400, 700));
  83. g_assert(check_parsing(roboto, "wght=200:", wght, 200, 400, 900));
  84. hb_face_destroy(face);
  85. hb_face_destroy(roboto);
  86. }
  87. int
  88. main (int argc, char **argv)
  89. {
  90. test_parse_instancing_spec();
  91. return 0;
  92. }