return cr;
}
-int main(int argc, char** argv) {
- char* svgpath;
- char* pngpath;
- FILE* fp;
-
- diagram_t* diagram;
- cairo_t* cr = 0;
-
- GdkPixbuf* pb;
-
- /* Parse arguments, and maybe print usage */
- if (argc < 3) {
- printf("Usage: %s INPUT OUTPUT\n", argv[0]);
- printf("Convert an SVG file (INPUT) to a PNG file (OUTPUT)\n");
- return 2;
- }
-
- svgpath = argv[1];
- pngpath = argv[2];
-
- fp = fopen(svgpath, "rb");
- if (!fp) {
- perror(svgpath);
- return 1;
- }
-
- diagram = svgtiny_diagram_from_file(fp, VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
- if (!diagram) {
- return 1;
- }
-
- cr = cairo_context_from_diagram(diagram);
- if (!cr) {
- svgtiny_free(diagram);
- return 1;
- }
-
- /* We're using the viewport width and height and not the diagram
- * width/height for the image. The diagram can be of a different
- * size and aspect ratio than the viewport, and our main use case is
- * for icons that are generally square and reasonably sized. If the
- * diagram is "small," then we want to scale it up until it fits
- * nicely in the viewport before rendering it. That's as opposed to
- * rendering the image small, and letting GDK scale it up. Of course
- * this reasoning makes the assumption that the viewport is usually
- * larger than the diagram.
- */
- pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr),
- 0,
- 0,
- VIEWPORT_WIDTH,
- VIEWPORT_HEIGHT);
-
-
- if (pb) {
- gdk_pixbuf_save(pb, pngpath, "png", NULL, NULL);
- g_object_unref(pb);
- }
-
- return 0;
-}
-
-
static GdkPixbuf* gdk_pixbuf_from_svg_file_stream(FILE *fp, GError **error) {
diagram_t* diagram;
cairo_t* cr = 0;
info->license = "AGPL3";
}
+
+int main(int argc, char** argv) {
+ char* svgpath;
+ char* pngpath;
+ FILE* fp;
+ GdkPixbuf* pb;
+
+ /* Parse arguments, and maybe print usage */
+ if (argc < 3) {
+ printf("Usage: %s INPUT OUTPUT\n", argv[0]);
+ printf("Convert an SVG file (INPUT) to a PNG file (OUTPUT)\n");
+ return 2;
+ }
+
+ svgpath = argv[1];
+ pngpath = argv[2];
+
+ fp = fopen(svgpath, "rb");
+ if (!fp) {
+ perror(svgpath);
+ return 1;
+ }
+
+ pb = gdk_pixbuf_from_svg_file_stream(fp, NULL);
+ if (pb) {
+ gdk_pixbuf_save(pb, pngpath, "png", NULL, NULL);
+ g_object_unref(pb);
+ }
+
+ return 0;
+}