Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -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 | |
Behdad Esfahbod | bce437c | 2018-11-04 02:47:34 -0500 | [diff] [blame] | 27 | #ifndef TEST_OT_FACE_NO_MAIN |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 28 | #include "hb-test.h" |
Behdad Esfahbod | bce437c | 2018-11-04 02:47:34 -0500 | [diff] [blame] | 29 | #endif |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 30 | #include <hb-ot.h> |
| 31 | |
| 32 | /* Unit tests for hb-ot-*.h */ |
| 33 | |
| 34 | |
| 35 | static void |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 36 | test_face (hb_face_t *face, |
| 37 | hb_codepoint_t cp) |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 38 | { |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 39 | hb_font_t *font = hb_font_create (face); |
Chun-wei Fan | 1e09add | 2018-12-12 01:32:01 +0800 | [diff] [blame] | 40 | hb_set_t *set; |
| 41 | hb_codepoint_t g; |
| 42 | hb_position_t x, y; |
| 43 | char buf[5] = {0}; |
| 44 | unsigned int len; |
| 45 | hb_glyph_extents_t extents; |
Behdad Esfahbod | 777c224 | 2018-11-04 02:40:20 -0500 | [diff] [blame] | 46 | hb_ot_font_set_funcs (font); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 47 | |
Chun-wei Fan | 1e09add | 2018-12-12 01:32:01 +0800 | [diff] [blame] | 48 | set = hb_set_create (); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 49 | hb_face_collect_unicodes (face, set); |
| 50 | hb_face_collect_variation_selectors (face, set); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 51 | hb_face_collect_variation_unicodes (face, cp, set); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 52 | |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 53 | hb_font_get_nominal_glyph (font, cp, &g); |
| 54 | hb_font_get_variation_glyph (font, cp, cp, &g); |
| 55 | hb_font_get_glyph_h_advance (font, cp); |
| 56 | hb_font_get_glyph_v_advance (font, cp); |
| 57 | hb_font_get_glyph_h_origin (font, cp, &x, &y); |
| 58 | hb_font_get_glyph_v_origin (font, cp, &x, &y); |
| 59 | hb_font_get_glyph_extents (font, cp, &extents); |
| 60 | hb_font_get_glyph_contour_point (font, cp, 0, &x, &y); |
| 61 | hb_font_get_glyph_name (font, cp, buf, sizeof (buf)); |
Behdad Esfahbod | 777c224 | 2018-11-04 02:40:20 -0500 | [diff] [blame] | 62 | hb_font_get_glyph_from_name (font, buf, strlen (buf), &g); |
| 63 | |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 64 | hb_ot_color_has_palettes (face); |
| 65 | hb_ot_color_palette_get_count (face); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 66 | hb_ot_color_palette_get_name_id (face, cp); |
| 67 | hb_ot_color_palette_color_get_name_id (face, cp); |
| 68 | hb_ot_color_palette_get_flags (face, cp); |
| 69 | hb_ot_color_palette_get_colors (face, cp, 0, NULL, NULL); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 70 | hb_ot_color_has_layers (face); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 71 | hb_ot_color_glyph_get_layers (face, cp, 0, NULL, NULL); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 72 | hb_ot_color_has_svg (face); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 73 | hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, cp)); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 74 | hb_ot_color_has_png (face); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 75 | hb_blob_destroy (hb_ot_color_glyph_reference_png (font, cp)); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 76 | |
| 77 | hb_ot_layout_has_glyph_classes (face); |
| 78 | hb_ot_layout_has_substitution (face); |
| 79 | hb_ot_layout_has_positioning (face); |
| 80 | |
| 81 | hb_ot_math_has_data (face); |
Behdad Esfahbod | bce437c | 2018-11-04 02:47:34 -0500 | [diff] [blame] | 82 | hb_ot_math_get_constant (font, HB_OT_MATH_CONSTANT_MATH_LEADING); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 83 | hb_ot_math_get_glyph_italics_correction (font, cp); |
| 84 | hb_ot_math_get_glyph_top_accent_attachment (font, cp); |
| 85 | hb_ot_math_is_glyph_extended_shape (face, cp); |
| 86 | hb_ot_math_get_glyph_kerning (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0); |
| 87 | hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL); |
Behdad Esfahbod | bce437c | 2018-11-04 02:47:34 -0500 | [diff] [blame] | 88 | hb_ot_math_get_min_connector_overlap (font, HB_DIRECTION_RTL); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 89 | hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_BTT, 0, NULL, NULL, NULL); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 90 | |
Chun-wei Fan | 1e09add | 2018-12-12 01:32:01 +0800 | [diff] [blame] | 91 | len = sizeof (buf); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 92 | hb_ot_name_list_names (face, NULL); |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 93 | hb_ot_name_get_utf8 (face, cp, NULL, &len, buf); |
| 94 | hb_ot_name_get_utf16 (face, cp, NULL, NULL, NULL); |
| 95 | hb_ot_name_get_utf32 (face, cp, NULL, NULL, NULL); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 96 | |
| 97 | hb_ot_var_get_axis_count (face); |
Behdad Esfahbod | f48bb9a | 2018-11-20 20:40:55 -0500 | [diff] [blame] | 98 | hb_ot_var_get_axis_infos (face, 0, NULL, NULL); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 99 | hb_ot_var_normalize_variations (face, NULL, 0, NULL, 0); |
| 100 | hb_ot_var_normalize_coords (face, 0, NULL, NULL); |
| 101 | |
| 102 | hb_set_destroy (set); |
| 103 | hb_font_destroy (font); |
Behdad Esfahbod | bce437c | 2018-11-04 02:47:34 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | #ifndef TEST_OT_FACE_NO_MAIN |
| 107 | static void |
| 108 | test_ot_face_empty (void) |
| 109 | { |
Behdad Esfahbod | 6482fda | 2018-11-05 15:03:18 -0500 | [diff] [blame] | 110 | test_face (hb_face_get_empty (), 0); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Ebrahim Byagowi | 8aaab78 | 2019-03-14 16:49:42 -0700 | [diff] [blame] | 113 | static void |
Behdad Esfahbod | 42f4bd6 | 2019-04-18 19:04:59 -0400 | [diff] [blame] | 114 | test_ot_var_axis_on_zero_named_instance (void) |
Ebrahim Byagowi | 8aaab78 | 2019-03-14 16:49:42 -0700 | [diff] [blame] | 115 | { |
| 116 | hb_face_t *face = hb_test_open_font_file ("fonts/Zycon.ttf"); |
| 117 | g_assert (hb_ot_var_get_axis_count (face)); |
| 118 | hb_face_destroy (face); |
| 119 | } |
| 120 | |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 121 | int |
| 122 | main (int argc, char **argv) |
| 123 | { |
| 124 | hb_test_init (&argc, &argv); |
| 125 | |
| 126 | hb_test_add (test_ot_face_empty); |
Ebrahim Byagowi | 8aaab78 | 2019-03-14 16:49:42 -0700 | [diff] [blame] | 127 | hb_test_add (test_ot_var_axis_on_zero_named_instance); |
Behdad Esfahbod | 9779e60 | 2018-11-03 20:50:56 -0400 | [diff] [blame] | 128 | |
| 129 | return hb_test_run(); |
| 130 | } |
Behdad Esfahbod | bce437c | 2018-11-04 02:47:34 -0500 | [diff] [blame] | 131 | #endif |