]>
gitweb.michael.orlitzky.com - libsvgtiny.git/blob - svgtiny_test.c
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 buffer
= malloc(size
);
45 fprintf(stderr
, "Unable to allocate %lld bytes\n",
50 n
= fread(buffer
, 1, size
, fd
);
58 /* create svgtiny object */
59 diagram
= svgtiny_create();
61 fprintf(stderr
, "svgtiny_create failed\n");
66 code
= svgtiny_parse(diagram
, buffer
, size
, argv
[1], 1000, 1000);
67 if (code
!= svgtiny_OK
) {
68 fprintf(stderr
, "svgtiny_parse failed: ");
70 case svgtiny_OUT_OF_MEMORY
:
71 fprintf(stderr
, "svgtiny_OUT_OF_MEMORY");
73 case svgtiny_LIBXML_ERROR
:
74 fprintf(stderr
, "svgtiny_LIBXML_ERROR");
77 fprintf(stderr
, "svgtiny_NOT_SVG");
79 case svgtiny_SVG_ERROR
:
80 fprintf(stderr
, "svgtiny_SVG_ERROR: line %i: %s",
82 diagram
->error_message
);
85 fprintf(stderr
, "unknown svgtiny_code %i", code
);
88 fprintf(stderr
, "\n");
93 printf("viewbox 0 0 %i %i\n", diagram
->width
, diagram
->height
);
95 for (unsigned int i
= 0; i
!= diagram
->shape_count
; i
++) {
96 if (diagram
->shape
[i
].fill
== svgtiny_TRANSPARENT
)
99 printf("fill #%.6x ", diagram
->shape
[i
].fill
);
100 if (diagram
->shape
[i
].stroke
== svgtiny_TRANSPARENT
)
101 printf("stroke none ");
103 printf("stroke #%.6x ", diagram
->shape
[i
].stroke
);
104 printf("stroke-width %i ", diagram
->shape
[i
].stroke_width
);
105 if (diagram
->shape
[i
].path
) {
107 for (unsigned int j
= 0;
108 j
!= diagram
->shape
[i
].path_length
; ) {
109 switch ((int) diagram
->shape
[i
].path
[j
]) {
110 case svgtiny_PATH_MOVE
:
112 diagram
->shape
[i
].path
[j
+ 1],
113 diagram
->shape
[i
].path
[j
+ 2]);
116 case svgtiny_PATH_CLOSE
:
120 case svgtiny_PATH_LINE
:
122 diagram
->shape
[i
].path
[j
+ 1],
123 diagram
->shape
[i
].path
[j
+ 2]);
126 case svgtiny_PATH_BEZIER
:
127 printf("C %g %g %g %g %g %g ",
128 diagram
->shape
[i
].path
[j
+ 1],
129 diagram
->shape
[i
].path
[j
+ 2],
130 diagram
->shape
[i
].path
[j
+ 3],
131 diagram
->shape
[i
].path
[j
+ 4],
132 diagram
->shape
[i
].path
[j
+ 5],
133 diagram
->shape
[i
].path
[j
+ 6]);
142 } else if (diagram
->shape
[i
].text
) {
143 printf("text %g %g '%s' ",
144 diagram
->shape
[i
].text_x
,
145 diagram
->shape
[i
].text_y
,
146 diagram
->shape
[i
].text
);
151 svgtiny_free(diagram
);