indent all the rest of the code, and add some typedefs to indent.pro
[rrdtool.git] / libraries / afm / test-afm.c
1 #include "rrd_afm.h"
2 #include <stdio.h>
3
4 FILE     *fp;
5
6 static void make_tests(
7     void);
8 static void print(
9     const char *s);
10 double    y = 0;
11
12 //static const char *font = "Times-Roman";
13 static const char *font = "Times Bold Italic";
14
15 //static const char *font = "Courier";
16 //static const char *font = "Courier Bold Oblique";
17
18 void make_tests(
19     )
20 {
21 #ifdef __APPLE__
22 #define charset_legend "Macintosh charset"
23 #define AE "\xAE"
24 #define ae "\xBE"
25 #define oe "\xBF"
26 #define aa "\x8C"
27 #define NBSP "\x00CA"
28 #else
29 #define charset_legend "IsoLatin1 charset"
30 #define AE "\xC6"
31 #define ae "\xE6"
32 #define oe "\xF8"
33 #define aa "\xA5"
34 #define NBSP "\x00A0"
35 #endif
36     print(AE);          /* very wide char */
37     print(AE AE AE AE AE AE AE AE AE AE AE AE AE AE AE);
38     print(charset_legend);
39     print("S,");
40     print("sfil");
41     print("Hello, world");
42     print("AVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV");
43     print("AAAAAAAAAAAAAAAAAAVVVVVVVVVVVVVVVVVV");
44     print("fiffififfififfififfififfififfififfi");
45     print("fi");
46     print("fil");
47     print("fifififififififififififififififififififififififififi");
48     print(AE "bleskiver med gl" oe "gg. " NBSP NBSP NBSP NBSP NBSP NBSP NBSP
49           AE " Fywerhus: 'A " ae " u " aa " " ae " " oe " i " ae " fywer'.");
50     print("Ingef" ae "rp" ae "rer med karamelsauce. R" oe "dgr" oe "d med fl"
51           oe "de.");
52     print
53         ("(Optional.) Ligature sequence where successor and ligature are both names.  The current character may join ...");
54 }
55
56 static void vline(
57     double x,
58     double y1,
59     double y2)
60 {
61     fprintf(fp, "<line x1=\"%.2f\" y1=\"%.2f\" x2=\"%.2f\" y2=\"%.2f\""
62             " stroke-width=\"1\" stroke=\"#000\"/>\n", x, y1, x, y2);
63 }
64
65 static void print(
66     const char *s)
67 {
68     double    size = 12;
69     double    x = 10;
70     double    width = afm_get_text_width(0, font, size, 4, s);
71     unsigned char *up = (unsigned char *) s;
72
73     fprintf(stderr, "Width = %f for '%s'\n", width, s);
74     y += 10;
75     vline(x, y, y + 5);
76     fprintf(fp, "<text x=\"%.2f\" y=\"%.2f\" font-size=\"%.2f\">", x, y,
77             size);
78     while (*up) {
79         unsigned char ch = afm_host2unicode(*up);
80
81         if (ch < 127)
82             putc(ch, fp);
83         else
84             fprintf(fp, "&#%d;", ch);
85         up++;
86     }
87     fputs("</text>\n", fp);
88     vline(x + width, y, y + 5);
89     y += 1.1 * size;
90 }
91
92 static void header(
93     )
94 {
95     fprintf(fp,
96             "<?xml version=\"1.0\" standalone=\"no\"?>\n"
97             "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\"\n"
98             "   \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
99             "<svg width=\"650\" height=\"400\" preserveAspectRatio=\"xMidYMid\"\n"
100             "    font-family=\"%s\">\n", font);
101 }
102
103
104 static void footer(
105     )
106 {
107     fputs("</svg>\n", fp);
108 }
109
110 int main(
111     )
112 {
113     fp = fopen("test.svg", "w");
114     if (fp == NULL) {
115         fprintf(stderr, "Can't create output.\n");
116         exit(1);
117     }
118     header();
119     make_tests();
120     footer();
121     fclose(fp);
122     return 0;
123 }