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