[librsvg] rsvg-view: Re-implement .svgz support



commit 80391e1019fa1a938aefef61eab27dca94bce2a2
Author: Christian Persch <chpe gnome org>
Date:   Thu Jan 12 23:26:39 2012 +0100

    rsvg-view: Re-implement .svgz support

 test-display.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/test-display.c b/test-display.c
index a71ad0f..1676fa3 100644
--- a/test-display.c
+++ b/test-display.c
@@ -616,6 +616,8 @@ main (int argc, char **argv)
     gboolean keep_aspect_ratio = FALSE;
     char *id = NULL;
     GInputStream *input;
+    GFileInfo *file_info;
+    gboolean compressed;
     GFile *file, *base_file;
     cairo_surface_t *surface;
 
@@ -697,6 +699,8 @@ main (int argc, char **argv)
                              "Reading from stdin not supported");
 #endif
         base_file = NULL;
+
+        compressed = FALSE;
     } else {
         file = g_file_new_for_commandline_arg (args[0]);
         input = (GInputStream *) g_file_read (file, NULL, &err);
@@ -706,6 +710,21 @@ main (int argc, char **argv)
         else
             base_file = g_object_ref (file);
 
+        if ((file_info = g_file_query_info (file,
+                                            G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+                                            G_FILE_QUERY_INFO_NONE,
+                                            NULL,
+                                            NULL))) {
+            const char *content_type;
+            char *gz_content_type;
+
+            content_type = g_file_info_get_content_type (file_info);
+            gz_content_type = g_content_type_from_mime_type ("application/x-gzip");
+            compressed = (content_type != NULL && g_content_type_is_a (content_type, gz_content_type));
+            g_free (gz_content_type);
+            g_object_unref (file_info);
+        }
+
         g_object_unref (file);
     }
 
@@ -717,6 +736,16 @@ main (int argc, char **argv)
         return 1;
     }
 
+    if (compressed) {
+        GZlibDecompressor *decompressor;
+        GInputStream *converter_stream;
+
+        decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
+        converter_stream = g_converter_input_stream_new (input, G_CONVERTER (decompressor));
+        g_object_unref (input);
+        input = converter_stream;
+    }
+
     info.base_uri = base_file ? g_file_get_uri (base_file) : g_strdup ("");
     info.id = id;
     info.x_zoom = x_zoom;
@@ -732,7 +761,6 @@ main (int argc, char **argv)
     if (info.handle == NULL) {
         g_printerr ("Failed to load SVG: %s\n", err->message);
         g_error_free (err);
-        g_object_unref (info.handle);
         return 1;
     }
 



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