]>
gitweb.michael.orlitzky.com - libsvgtiny.git/blob - svgtiny_test.c
9bb7e2e30cdd2e9e50348842c4c8ca68f8694729
2 * This file is part of Libsvgtiny
3 * Licensed under the MIT License,
4 * http://opensource.org/licenses/mit-license.php
5 * Copyright 2008 James Bursa <james@semichrome.net>
15 int main(int argc
, char *argv
[])
22 struct svgtiny_diagram
*diagram
;
26 fprintf(stderr
, "Usage: %s FILE\n", argv
[0]);
30 /* load file into memory buffer */
31 fd
= fopen(argv
[1], "rb");
37 if (stat(argv
[1], &sb
)) {
43 fprintf(stderr
, "size: %lld bytes\n", (long long) size
);
45 buffer
= malloc(size
);
47 fprintf(stderr
, "Unable to allocate %lld bytes\n",
52 n
= fread(buffer
, 1, size
, fd
);
60 /* create svgtiny object */
61 diagram
= svgtiny_create();
63 fprintf(stderr
, "svgtiny_create failed\n");
68 code
= svgtiny_parse(diagram
, buffer
, size
, argv
[1], 1000, 1000);
69 if (code
!= svgtiny_OK
)
70 fprintf(stderr
, "svgtiny_parse failed: %i\n", code
);
72 printf("viewbox 0 0 %i %i\n", diagram
->width
, diagram
->height
);
74 for (unsigned int i
= 0; i
!= diagram
->shape_count
; i
++) {
75 if (diagram
->shape
[i
].fill
== svgtiny_TRANSPARENT
)
78 printf("fill #%.6x ", diagram
->shape
[i
].fill
);
79 if (diagram
->shape
[i
].stroke
== svgtiny_TRANSPARENT
)
80 printf("stroke none ");
82 printf("stroke #%.6x ", diagram
->shape
[i
].stroke
);
83 if (diagram
->shape
[i
].path
) {
85 for (unsigned int j
= 0;
86 j
!= diagram
->shape
[i
].path_length
; ) {
87 switch ((int) diagram
->shape
[i
].path
[j
]) {
88 case svgtiny_PATH_MOVE
:
90 diagram
->shape
[i
].path
[j
+ 1],
91 diagram
->shape
[i
].path
[j
+ 2]);
94 case svgtiny_PATH_CLOSE
:
98 case svgtiny_PATH_LINE
:
100 diagram
->shape
[i
].path
[j
+ 1],
101 diagram
->shape
[i
].path
[j
+ 2]);
104 case svgtiny_PATH_BEZIER
:
105 printf("C %g %g %g %g %g %g ",
106 diagram
->shape
[i
].path
[j
+ 1],
107 diagram
->shape
[i
].path
[j
+ 2],
108 diagram
->shape
[i
].path
[j
+ 3],
109 diagram
->shape
[i
].path
[j
+ 4],
110 diagram
->shape
[i
].path
[j
+ 5],
111 diagram
->shape
[i
].path
[j
+ 6]);
120 } else if (diagram
->shape
[i
].text
) {
121 printf("text %g %g '%s' ",
122 diagram
->shape
[i
].text_x
,
123 diagram
->shape
[i
].text_y
,
124 diagram
->shape
[i
].text
);