]>
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: %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 printf("stroke-width %i ", diagram
->shape
[i
].stroke_width
);
84 if (diagram
->shape
[i
].path
) {
86 for (unsigned int j
= 0;
87 j
!= diagram
->shape
[i
].path_length
; ) {
88 switch ((int) diagram
->shape
[i
].path
[j
]) {
89 case svgtiny_PATH_MOVE
:
91 diagram
->shape
[i
].path
[j
+ 1],
92 diagram
->shape
[i
].path
[j
+ 2]);
95 case svgtiny_PATH_CLOSE
:
99 case svgtiny_PATH_LINE
:
101 diagram
->shape
[i
].path
[j
+ 1],
102 diagram
->shape
[i
].path
[j
+ 2]);
105 case svgtiny_PATH_BEZIER
:
106 printf("C %g %g %g %g %g %g ",
107 diagram
->shape
[i
].path
[j
+ 1],
108 diagram
->shape
[i
].path
[j
+ 2],
109 diagram
->shape
[i
].path
[j
+ 3],
110 diagram
->shape
[i
].path
[j
+ 4],
111 diagram
->shape
[i
].path
[j
+ 5],
112 diagram
->shape
[i
].path
[j
+ 6]);
121 } else if (diagram
->shape
[i
].text
) {
122 printf("text %g %g '%s' ",
123 diagram
->shape
[i
].text_x
,
124 diagram
->shape
[i
].text_y
,
125 diagram
->shape
[i
].text
);
130 svgtiny_free(diagram
);