int main(int argc, char *argv[])
{
FILE *fd;
+ float scale = 1.0;
struct stat sb;
char *buffer;
size_t size;
struct svgtiny_diagram *diagram;
svgtiny_code code;
- if (argc != 2) {
- fprintf(stderr, "Usage: %s FILE\n", argv[0]);
+ if (argc != 2 && argc != 3) {
+ fprintf(stderr, "Usage: %s FILE [SCALE]\n", argv[0]);
return 1;
}
}
size = sb.st_size;
- fprintf(stderr, "size: %lld bytes\n", (long long) size);
-
buffer = malloc(size);
if (!buffer) {
fprintf(stderr, "Unable to allocate %lld bytes\n",
fclose(fd);
+ /* read scale argument */
+ if (argc == 3) {
+ scale = atof(argv[2]);
+ if (scale == 0)
+ scale = 1.0;
+ }
+
/* create svgtiny object */
diagram = svgtiny_create();
if (!diagram) {
/* parse */
code = svgtiny_parse(diagram, buffer, size, argv[1], 1000, 1000);
- if (code != svgtiny_OK)
- fprintf(stderr, "svgtiny_parse failed: %i\n", code);
+ if (code != svgtiny_OK) {
+ fprintf(stderr, "svgtiny_parse failed: ");
+ switch (code) {
+ case svgtiny_OUT_OF_MEMORY:
+ fprintf(stderr, "svgtiny_OUT_OF_MEMORY");
+ break;
+ case svgtiny_LIBXML_ERROR:
+ fprintf(stderr, "svgtiny_LIBXML_ERROR");
+ break;
+ case svgtiny_NOT_SVG:
+ fprintf(stderr, "svgtiny_NOT_SVG");
+ break;
+ case svgtiny_SVG_ERROR:
+ fprintf(stderr, "svgtiny_SVG_ERROR: line %i: %s",
+ diagram->error_line,
+ diagram->error_message);
+ break;
+ default:
+ fprintf(stderr, "unknown svgtiny_code %i", code);
+ break;
+ }
+ fprintf(stderr, "\n");
+ }
+
+ free(buffer);
- printf("viewbox 0 0 %i %i\n", diagram->width, diagram->height);
+ printf("viewbox 0 0 %g %g\n",
+ scale * diagram->width, scale * diagram->height);
for (unsigned int i = 0; i != diagram->shape_count; i++) {
if (diagram->shape[i].fill == svgtiny_TRANSPARENT)
printf("stroke none ");
else
printf("stroke #%.6x ", diagram->shape[i].stroke);
+ printf("stroke-width %g ",
+ scale * diagram->shape[i].stroke_width);
if (diagram->shape[i].path) {
printf("path '");
for (unsigned int j = 0;
switch ((int) diagram->shape[i].path[j]) {
case svgtiny_PATH_MOVE:
printf("M %g %g ",
- diagram->shape[i].path[j + 1],
- diagram->shape[i].path[j + 2]);
+ scale * diagram->shape[i].path[j + 1],
+ scale * diagram->shape[i].path[j + 2]);
j += 3;
break;
case svgtiny_PATH_CLOSE:
break;
case svgtiny_PATH_LINE:
printf("L %g %g ",
- diagram->shape[i].path[j + 1],
- diagram->shape[i].path[j + 2]);
+ scale * diagram->shape[i].path[j + 1],
+ scale * diagram->shape[i].path[j + 2]);
j += 3;
break;
case svgtiny_PATH_BEZIER:
printf("C %g %g %g %g %g %g ",
- diagram->shape[i].path[j + 1],
- diagram->shape[i].path[j + 2],
- diagram->shape[i].path[j + 3],
- diagram->shape[i].path[j + 4],
- diagram->shape[i].path[j + 5],
- diagram->shape[i].path[j + 6]);
+ scale * diagram->shape[i].path[j + 1],
+ scale * diagram->shape[i].path[j + 2],
+ scale * diagram->shape[i].path[j + 3],
+ scale * diagram->shape[i].path[j + 4],
+ scale * diagram->shape[i].path[j + 5],
+ scale * diagram->shape[i].path[j + 6]);
j += 7;
break;
default:
printf("' ");
} else if (diagram->shape[i].text) {
printf("text %g %g '%s' ",
- diagram->shape[i].text_x,
- diagram->shape[i].text_y,
+ scale * diagram->shape[i].text_x,
+ scale * diagram->shape[i].text_y,
diagram->shape[i].text);
}
printf("\n");
}
+ svgtiny_free(diagram);
+
return 0;
}