-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsvg.c
60 lines (52 loc) · 1015 Bytes
/
svg.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
#include <stdio.h>
#include "svg.h"
void svg_file_begin(FILE *f)
{
fprintf(f, "<svg viewBox=\"%d %d %d %d\" ",
-600, -600, 1200, 1200);
fprintf(f, "xmlns=\"http://www.w3.org/2000/svg\">\n");
}
void svg_file_end(FILE *f)
{
fprintf(f, "</svg>\n");
}
void svg_polyline_begin(FILE *f, int x, int y)
{
fprintf(f, " <polyline points=\"%d,%d", x, y);
}
void svg_polyline_point(FILE *f, int x, int y)
{
fprintf(f, " %d,%d", x, y);
}
void svg_polyline_end(FILE *f)
{
fprintf(f, "\" fill=\"none\" stroke=\"black\" />\n");
}
void svg_text_begin(FILE *f, int x, int y)
{
fprintf(f, " <text x=\"%d\" y=\"%d\">", x, y);
}
void svg_text_character(FILE *f, int c)
{
switch(c) {
case '<':
fprintf(f, "<");
break;
case '>':
fprintf(f, ">");
break;
case '&':
fprintf(f, "&");
break;
default:
if (c <= 31)
fprintf(f, "[^%c]", c + '@');
else
fprintf(f, "%c", c);
break;
}
}
void svg_text_end(FILE *f)
{
fprintf(f, "</text>\n");
}