-
Notifications
You must be signed in to change notification settings - Fork 33
/
stress.c
83 lines (72 loc) · 1.43 KB
/
stress.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* A stress testing program. Useful for profiling hot spots in libschrift. */
/* See LICENSE file for copyright and license details. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <schrift.h>
#include "util/arg.h"
char *argv0;
static void
die(const char *msg)
{
fprintf(stderr, "%s\n", msg);
exit(1);
}
static void
usage(void)
{
fprintf(stderr,
"usage: %s [-f font file] [-s size in px]\n", argv0);
}
int
main(int argc, char *argv[])
{
SFT sft;
SFT_Font *font;
const char *filename;
double size;
unsigned long cp;
SFT_Glyph gid;
SFT_GMetrics mtx;
SFT_Image image;
int i;
filename = "resources/Ubuntu-Regular.ttf";
size = 20.0;
ARGBEGIN {
case 'f':
filename = EARGF(usage());
break;
case 's':
size = atof(EARGF(usage()));
break;
default:
usage();
exit(1);
} ARGEND
if (argc) {
usage();
exit(1);
}
if (!(font = sft_loadfile(filename)))
die("Can't load font file.");
memset(&sft, 0, sizeof sft);
sft.font = font;
sft.xScale = size;
sft.yScale = size;
sft.flags = SFT_DOWNWARD_Y;
for (i = 0; i < 5000; ++i) {
for (cp = 32; cp < 128; ++cp) {
if (sft_lookup(&sft, cp, &gid) < 0)
continue;
if (sft_gmetrics(&sft, gid, &mtx) < 0)
continue;
image.width = mtx.minWidth;
image.height = mtx.minHeight;
image.pixels = malloc((size_t) image.width * (size_t) image.height);
sft_render(&sft, gid, image);
free(image.pixels);
}
}
sft_freefont(font);
return 0;
}