X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=io-svg.c;h=cf8864a1eb6a6ed40037bfb161e404da473826ae;hb=83f5680b39a1b77b24bdbce414354625be558bcf;hp=750ea254b22bd945a7e2d707d1f2302987308d96;hpb=ce61daf00d9a18bcbbbff7709d9c59c3c0d2dbbb;p=libsvgtiny-pixbuf.git diff --git a/io-svg.c b/io-svg.c index 750ea25..cf8864a 100644 --- a/io-svg.c +++ b/io-svg.c @@ -1,4 +1,4 @@ -#include /* fopen, fprintf, fread, printf */ +#include /* fprintf, printf */ #include /* memcpy */ #include @@ -300,21 +300,19 @@ static GdkPixbuf* gdk_pixbuf_from_svg_buffer(char* buffer, } - /* 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. - */ + /* I've gone back and forth on this about five times: we use the + * diagram width and height, and not the viewport width and height. + * This can ultimately render an image that's larger than the + * viewport size, but I think GDK will resize the final pixbuf + * anyway. More importantly, rendering small icons at a larger + * (viewport) size seems to make the whole thing go ape-shit. + * So for now I'm back in the diagram camp. + */ pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr), 0, 0, - VIEWPORT_WIDTH, - VIEWPORT_HEIGHT); + diagram->width, + diagram->height); if (!pb) { @@ -328,48 +326,6 @@ static GdkPixbuf* gdk_pixbuf_from_svg_buffer(char* buffer, } -/** - * @brief Create a GdkPixbuf from an SVG filestream. - * - * This is essentially a wrapper around @gdk_pixbuf_from_svg_buffer - * that reads a @c FILE pointer into a buffer. - * - * @param fp - * A pointer to a @c FILE containing the SVG document. - * - * @param error - * The address of a @c GError pointer that we use to return errors. - * - * @return If successful, a valid pointer to a @c GdkPixbuf is - * returned; if not, @c NULL is returned and @c error is populated. - */ -static GdkPixbuf* gdk_pixbuf_from_svg_file_stream(FILE *fp, GError** error) { - size_t bytecount, bytesread; - char* buffer; - - /* Find the size of the file stream */ - fseek(fp, 0L, SEEK_END); - bytecount = ftell(fp); - rewind(fp); - - /* YOLO, no error checking */ - buffer = g_malloc(bytecount); - - bytesread = fread(buffer, 1, bytecount, fp); - if (bytesread != bytecount) { - g_set_error(error, - G_FILE_ERROR, - G_FILE_ERROR_FAILED, - "read only %zd of %zd bytes from stream", - bytesread, - bytecount); - return NULL; - } - - return gdk_pixbuf_from_svg_buffer(buffer, bytecount, error); -} - - static gpointer gdk_pixbuf_begin_load(GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePreparedFunc prep_func, GdkPixbufModuleUpdatedFunc updated_func, @@ -478,7 +434,6 @@ void fill_vtable(GdkPixbufModule* module) { module->begin_load = gdk_pixbuf_begin_load; module->load_increment = gdk_pixbuf_load_increment; module->stop_load = gdk_pixbuf_stop_load; - module->load = gdk_pixbuf_from_svg_file_stream; } G_MODULE_EXPORT void fill_info(GdkPixbufFormat *info); @@ -535,16 +490,10 @@ int main(int argc, char** argv) { svgpath = argv[1]; pngpath = argv[2]; - fp = fopen(svgpath, "rb"); - if (!fp) { - perror(svgpath); - return 1; - } - - pb = gdk_pixbuf_from_svg_file_stream(fp, &err); + pb = gdk_pixbuf_new_from_file(svgpath, &err); if (!pb) { fprintf(stderr, - "Error %d in gdk_pixbuf_from_svg_file_stream: %s\n", + "Error %d in gdk_pixbuf_new_from_file: %s\n", err->code, err->message); g_error_free(err);