[eog] Use the result of librsvg's parser to generate pixel data out of SVGs



commit d57936817e1738aaa6d359de45aeab7a48a280c8
Author: Felix Riemann <friemann gnome org>
Date:   Fri May 27 19:30:01 2011 +0200

    Use the result of librsvg's parser to generate pixel data out of SVGs
    
    Resolves problems with converting SVGs that use relative paths.
    Also avoids the duplicate SVG parsing by gdk-pixbuf's SVG loader.
    It's not the nicest code, but we need to split EogImage in
    format-specific variants anyway. So, this can stay like this until then.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642725

 src/eog-image.c |   81 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 54 insertions(+), 27 deletions(-)
---
diff --git a/src/eog-image.c b/src/eog-image.c
index de5b105..6a755dd 100644
--- a/src/eog-image.c
+++ b/src/eog-image.c
@@ -897,6 +897,7 @@ eog_image_real_load (EogImage *img,
 	gboolean failed = FALSE;
 	gboolean first_run = TRUE;
 	gboolean set_metadata = TRUE;
+	gboolean use_rsvg = FALSE;
 	gboolean read_image_data = (data2read & EOG_IMAGE_DATA_IMAGE);
 	gboolean read_only_dimension = (data2read & EOG_IMAGE_DATA_DIMENSION) &&
 				  ((data2read ^ EOG_IMAGE_DATA_DIMENSION) == 0);
@@ -967,39 +968,43 @@ eog_image_real_load (EogImage *img,
 			gchar *file_path;
 			/* Keep the object for rendering */
 			priv->svg = rsvg_handle_new ();
+			use_rsvg = (priv->svg != NULL);
 			file_path = g_file_get_path (priv->file);
 			rsvg_handle_set_base_uri (priv->svg, file_path);
 			g_free (file_path);
 		}
 #endif
-		loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, error);
 
-		if (error && *error) {
-			g_error_free (*error);
-			*error = NULL;
+		if (!use_rsvg) {
+			loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, error);
 
-			loader = gdk_pixbuf_loader_new ();
-		} else {
-			/* The mimetype-based loader should know the
-			 * format here already. */
-			checked_threadsafety = check_loader_threadsafety (loader, &priv->threadsafe_format);
-		}
+			if (error && *error) {
+				g_error_free (*error);
+				*error = NULL;
+
+				loader = gdk_pixbuf_loader_new ();
+			} else {
+				/* The mimetype-based loader should know the
+				 * format here already. */
+				checked_threadsafety = check_loader_threadsafety (loader, &priv->threadsafe_format);
+			}
 
 		/* This is used to detect non-threadsafe loaders and disable
  		 * any possible asyncronous task that could bring deadlocks
  		 * to image loading process. */
-		if (!checked_threadsafety)
-			g_signal_connect (loader,
+			if (!checked_threadsafety)
+				g_signal_connect (loader,
 					  "size-prepared",
 					  G_CALLBACK (eog_image_pre_size_prepared),
 					  img);
 
-		g_signal_connect_object (G_OBJECT (loader),
+			g_signal_connect_object (G_OBJECT (loader),
 					 "size-prepared",
 					 G_CALLBACK (eog_image_size_prepared),
 					 img,
 					 0);
-        }
+		}
+	}
 	g_free (mime_type);
 
 	while (!priv->cancel_loading) {
@@ -1024,17 +1029,23 @@ eog_image_real_load (EogImage *img,
 		}
 
 		if ((read_image_data || read_only_dimension)) {
-			if (!gdk_pixbuf_loader_write (loader, buffer, bytes_read, error)) {
-				failed = TRUE;
-				break;
-			}
 #ifdef HAVE_RSVG
-			if (eog_image_is_svg (img) &&
-			    !rsvg_handle_write (priv->svg, buffer, bytes_read, error)) {
+			if (use_rsvg) {
+				gboolean res;
+
+				res = rsvg_handle_write (priv->svg, buffer,
+							 bytes_read, error);
+
+				if (G_UNLIKELY (!res)) {
+					failed = TRUE;
+					break;
+				}
+			} else
+#endif
+			if (!gdk_pixbuf_loader_write (loader, buffer, bytes_read, error)) {
 				failed = TRUE;
 				break;
 			}
-#endif
 		}
 
 		bytes_read_total += bytes_read;
@@ -1095,6 +1106,11 @@ eog_image_real_load (EogImage *img,
 	}
 
 	if (read_image_data || read_only_dimension) {
+#ifdef HAVE_RSVG
+		if (use_rsvg) {
+			rsvg_handle_close (priv->svg, error);
+		} else
+#endif
 		if (failed) {
 			gdk_pixbuf_loader_close (loader, NULL);
 		} else if (!gdk_pixbuf_loader_close (loader, error)) {
@@ -1104,10 +1120,6 @@ eog_image_real_load (EogImage *img,
 				g_clear_error (error);
 			}
 	        }
-#ifdef HAVE_RSVG
-		if (eog_image_is_svg (img))
-			rsvg_handle_close (priv->svg, error);
-#endif
         }
 
 	g_free (buffer);
@@ -1131,6 +1143,13 @@ eog_image_real_load (EogImage *img,
 			g_object_unref (priv->image);
 		}
 
+#ifdef HAVE_RSVG
+		if (use_rsvg) {
+			priv->image = rsvg_handle_get_pixbuf (priv->svg);
+		} else
+#endif
+		{
+
 		priv->anim = gdk_pixbuf_loader_get_animation (loader);
 
 		if (gdk_pixbuf_animation_is_static_image (priv->anim)) {
@@ -1141,13 +1160,21 @@ eog_image_real_load (EogImage *img,
 			priv->image = gdk_pixbuf_animation_iter_get_pixbuf (priv->anim_iter);
 		}
 
+		}
+
 		if (G_LIKELY (priv->image != NULL)) {
-			g_object_ref (priv->image);
+			if (!use_rsvg)
+				g_object_ref (priv->image);
 
 			priv->width = gdk_pixbuf_get_width (priv->image);
 			priv->height = gdk_pixbuf_get_height (priv->image);
 
-			format = gdk_pixbuf_loader_get_format (loader);
+			if (use_rsvg) {
+				format = NULL;
+				priv->file_type = g_strdup ("svg");
+			} else {
+				format = gdk_pixbuf_loader_get_format (loader);
+			}
 
 			if (format != NULL) {
 				priv->file_type = gdk_pixbuf_format_get_name (format);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]