1 #include "benchmark/benchmark.h"
2
3 #include "hb.h"
4 #include "hb-ft.h"
5 #include "hb-ot.h"
6
7 #ifdef HAVE_TTFPARSER
8 #include "ttfparser.h"
9 #endif
10
extents(benchmark::State & state,const char * font_path,bool is_var,backend_t backend)11 static void extents (benchmark::State &state, const char *font_path, bool is_var, backend_t backend)
12 {
13 hb_font_t *font;
14 unsigned num_glyphs;
15 {
16 hb_blob_t *blob = hb_blob_create_from_file (font_path);
17 assert (hb_blob_get_length (blob));
18 hb_face_t *face = hb_face_create (blob, 0);
19 hb_blob_destroy (blob);
20 num_glyphs = hb_face_get_glyph_count (face);
21 font = hb_font_create (face);
22 hb_face_destroy (face);
23 }
24
25 if (is_var)
26 {
27 hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500};
28 hb_font_set_variations (font, &wght, 1);
29 }
30
31 if (backend == HARFBUZZ || backend == FREETYPE)
32 {
33 if (backend == FREETYPE)
34 {
35 hb_ft_font_set_funcs (font);
36 hb_ft_font_set_load_flags (font, FT_LOAD_NO_HINTING | FT_LOAD_NO_SCALE);
37 }
38
39 hb_glyph_extents_t extents;
40 for (auto _ : state)
41 for (unsigned gid = 0; gid < num_glyphs; ++gid)
42 hb_font_get_glyph_extents (font, gid, &extents);
43 }
44 else if (backend == TTF_PARSER)
45 {
46 #ifdef HAVE_TTFPARSER
47 ttfp_face *tp_font = (ttfp_face *) malloc (ttfp_face_size_of ());
48 hb_blob_t *blob = hb_face_reference_blob (hb_font_get_face (font));
49 assert (ttfp_face_init (hb_blob_get_data (blob, nullptr), hb_blob_get_length (blob), 0, tp_font));
50 if (is_var) ttfp_set_variation (tp_font, TTFP_TAG('w','g','h','t'), 500);
51
52 ttfp_rect bbox;
53 for (auto _ : state)
54 for (unsigned gid = 0; gid < num_glyphs; ++gid)
55 ttfp_get_glyph_bbox(tp_font, gid, &bbox);
56
57 hb_blob_destroy (blob);
58 free (tp_font);
59 #endif
60 }
61
62 hb_font_destroy (font);
63 }
64
65 #define FONT_BASE_PATH "test/subset/data/fonts/"
66
67 BENCHMARK_CAPTURE (extents, cff - ot - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, HARFBUZZ);
68 BENCHMARK_CAPTURE (extents, cff - ft - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, FREETYPE);
69 BENCHMARK_CAPTURE (extents, cff - tp - SourceSansPro, FONT_BASE_PATH "SourceSansPro-Regular.otf", false, TTF_PARSER);
70
71 BENCHMARK_CAPTURE (extents, cff2 - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, HARFBUZZ);
72 BENCHMARK_CAPTURE (extents, cff2 - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, FREETYPE);
73 BENCHMARK_CAPTURE (extents, cff2 - tp - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", false, TTF_PARSER);
74
75 BENCHMARK_CAPTURE (extents, cff2/vf - ot - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, HARFBUZZ);
76 BENCHMARK_CAPTURE (extents, cff2/vf - ft - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, FREETYPE);
77 BENCHMARK_CAPTURE (extents, cff2/vf - tp - AdobeVFPrototype, FONT_BASE_PATH "AdobeVFPrototype.otf", true, TTF_PARSER);
78
79 BENCHMARK_CAPTURE (extents, glyf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, HARFBUZZ);
80 BENCHMARK_CAPTURE (extents, glyf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, FREETYPE);
81 BENCHMARK_CAPTURE (extents, glyf - tp - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", false, TTF_PARSER);
82
83 BENCHMARK_CAPTURE (extents, glyf/vf - ot - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, HARFBUZZ);
84 BENCHMARK_CAPTURE (extents, glyf/vf - ft - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, FREETYPE);
85 BENCHMARK_CAPTURE (extents, glyf/vf - tp - SourceSerifVariable, FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", true, TTF_PARSER);
86
87 BENCHMARK_CAPTURE (extents, glyf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, HARFBUZZ);
88 BENCHMARK_CAPTURE (extents, glyf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, FREETYPE);
89 BENCHMARK_CAPTURE (extents, glyf - tp - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", false, TTF_PARSER);
90
91 BENCHMARK_CAPTURE (extents, glyf/vf - ot - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, HARFBUZZ);
92 BENCHMARK_CAPTURE (extents, glyf/vf - ft - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, FREETYPE);
93 BENCHMARK_CAPTURE (extents, glyf/vf - tp - Comfortaa, FONT_BASE_PATH "Comfortaa-Regular-new.ttf", true, TTF_PARSER);
94
95 BENCHMARK_CAPTURE (extents, glyf - ot - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, HARFBUZZ);
96 BENCHMARK_CAPTURE (extents, glyf - ft - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, FREETYPE);
97 BENCHMARK_CAPTURE (extents, glyf - tp - Roboto, FONT_BASE_PATH "Roboto-Regular.ttf", false, TTF_PARSER);
98
99