]>
gitweb.michael.orlitzky.com - libsvgtiny.git/blob - test/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>
16 int main(int argc
, char *argv
[])
24 struct svgtiny_diagram
*diagram
;
27 if (argc
!= 2 && argc
!= 3) {
28 fprintf(stderr
, "Usage: %s FILE [SCALE]\n", argv
[0]);
32 /* load file into memory buffer */
33 fd
= fopen(argv
[1], "rb");
39 if (stat(argv
[1], &sb
)) {
45 buffer
= malloc(size
);
47 fprintf(stderr
, "Unable to allocate %lld bytes\n",
52 n
= fread(buffer
, 1, size
, fd
);
60 /* read scale argument */
62 scale
= atof(argv
[2]);
67 /* create svgtiny object */
68 diagram
= svgtiny_create();
70 fprintf(stderr
, "svgtiny_create failed\n");
75 code
= svgtiny_parse(diagram
, buffer
, size
, argv
[1], 1000, 1000);
76 if (code
!= svgtiny_OK
) {
77 fprintf(stderr
, "svgtiny_parse failed: ");
79 case svgtiny_OUT_OF_MEMORY
:
80 fprintf(stderr
, "svgtiny_OUT_OF_MEMORY");
82 case svgtiny_LIBDOM_ERROR
:
83 fprintf(stderr
, "svgtiny_LIBDOM_ERROR");
86 fprintf(stderr
, "svgtiny_NOT_SVG");
88 case svgtiny_SVG_ERROR
:
89 fprintf(stderr
, "svgtiny_SVG_ERROR: line %i: %s",
91 diagram
->error_message
);
94 fprintf(stderr
, "unknown svgtiny_code %i", code
);
97 fprintf(stderr
, "\n");
102 printf("viewbox 0 0 %g %g\n",
103 scale
* diagram
->width
, scale
* diagram
->height
);
105 for (unsigned int i
= 0; i
!= diagram
->shape_count
; i
++) {
106 if (diagram
->shape
[i
].fill
== svgtiny_TRANSPARENT
)
107 printf("fill none ");
109 printf("fill #%.6x ", diagram
->shape
[i
].fill
);
110 if (diagram
->shape
[i
].stroke
== svgtiny_TRANSPARENT
)
111 printf("stroke none ");
113 printf("stroke #%.6x ", diagram
->shape
[i
].stroke
);
114 printf("stroke-width %g ",
115 scale
* diagram
->shape
[i
].stroke_width
);
116 if (diagram
->shape
[i
].path
) {
118 for (unsigned int j
= 0;
119 j
!= diagram
->shape
[i
].path_length
; ) {
120 switch ((int) diagram
->shape
[i
].path
[j
]) {
121 case svgtiny_PATH_MOVE
:
123 scale
* diagram
->shape
[i
].path
[j
+ 1],
124 scale
* diagram
->shape
[i
].path
[j
+ 2]);
127 case svgtiny_PATH_CLOSE
:
131 case svgtiny_PATH_LINE
:
133 scale
* diagram
->shape
[i
].path
[j
+ 1],
134 scale
* diagram
->shape
[i
].path
[j
+ 2]);
137 case svgtiny_PATH_BEZIER
:
138 printf("C %g %g %g %g %g %g ",
139 scale
* diagram
->shape
[i
].path
[j
+ 1],
140 scale
* diagram
->shape
[i
].path
[j
+ 2],
141 scale
* diagram
->shape
[i
].path
[j
+ 3],
142 scale
* diagram
->shape
[i
].path
[j
+ 4],
143 scale
* diagram
->shape
[i
].path
[j
+ 5],
144 scale
* diagram
->shape
[i
].path
[j
+ 6]);
153 } else if (diagram
->shape
[i
].text
) {
154 printf("text %g %g '%s' ",
155 scale
* diagram
->shape
[i
].text_x
,
156 scale
* diagram
->shape
[i
].text_y
,
157 diagram
->shape
[i
].text
);
162 svgtiny_free(diagram
);