Fix #188: Support preview of .svgz files
authorColin Clark <colin.clark@cclark.uk>
Sat, 17 Aug 2019 10:03:36 +0000 (11:03 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sat, 17 Aug 2019 10:03:36 +0000 (11:03 +0100)
https://github.com/BestImageViewer/geeqie/issues/188

src/Makefile.am
src/image-load.c
src/image_load_svgz.c [new file with mode: 0644]
src/image_load_svgz.h [new file with mode: 0644]

index a477118..aa8695b 100644 (file)
@@ -203,6 +203,8 @@ geeqie_SOURCES = \
        image_load_psd.h\
        image_load_j2k.c\
        image_load_j2k.h\
+       image_load_svgz.c\
+       image_load_svgz.h\
        image_load_ffmpegthumbnailer.c\
        image_load_ffmpegthumbnailer.h\
        image-overlay.c \
index 2504ff8..6c9a305 100644 (file)
@@ -33,6 +33,7 @@
 #include "image_load_collection.h"
 #include "image_load_webp.h"
 #include "image_load_j2k.h"
+#include "image_load_svgz.h"
 
 #include "exif.h"
 #include "filedata.h"
@@ -711,6 +712,12 @@ static void image_loader_setup_loader(ImageLoader *il)
                DEBUG_1("Using custom collection loader");
                image_loader_backend_set_collection(&il->backend);
                }
+       else
+       if (g_strcmp0(strrchr(il->fd->path, '.'), ".svgz") == 0)
+               {
+               DEBUG_1("Using custom svgz loader");
+               image_loader_backend_set_svgz(&il->backend);
+               }
        else
                image_loader_backend_set_default(&il->backend);
 
diff --git a/src/image_load_svgz.c b/src/image_load_svgz.c
new file mode 100644 (file)
index 0000000..39981d2
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2019 The Geeqie Team
+ *
+ * Author: Colin Clark
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "main.h"
+#include "image-load.h"
+#include "image_load_svgz.h"
+
+
+static gchar* image_loader_svgz_get_format_name(gpointer loader)
+{
+       return g_strdup("svg");
+
+}
+static gchar** image_loader_svgz_get_format_mime_types(gpointer loader)
+{
+       static gchar *mime[] = {"image/svg", NULL};
+       return g_strdupv(mime);
+}
+
+static gpointer image_loader_svgz_new(ImageLoaderBackendCbAreaUpdated area_updated_cb, ImageLoaderBackendCbSize size_cb, ImageLoaderBackendCbAreaPrepared area_prepared_cb, gpointer data)
+{
+       GError *error = NULL;
+
+       GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_mime_type("image/svg", &error);
+       if (error)
+               {
+               g_error_free(error);
+               return NULL;
+               }
+
+       g_signal_connect(G_OBJECT(loader), "area_updated", G_CALLBACK(area_updated_cb), data);
+       g_signal_connect(G_OBJECT(loader), "size_prepared", G_CALLBACK(size_cb), data);
+       g_signal_connect(G_OBJECT(loader), "area_prepared", G_CALLBACK(area_prepared_cb), data);
+       return (gpointer) loader;
+}
+
+static void image_loader_svgz_abort(gpointer loader)
+{
+}
+
+static void image_loader_svgz_free(gpointer loader)
+{
+       g_object_unref(G_OBJECT(loader));
+}
+
+void image_loader_backend_set_svgz(ImageLoaderBackend *funcs)
+{
+       funcs->loader_new = image_loader_svgz_new;
+       funcs->set_size = (ImageLoaderBackendFuncSetSize) gdk_pixbuf_loader_set_size;
+       funcs->load = NULL;
+       funcs->write = (ImageLoaderBackendFuncWrite) gdk_pixbuf_loader_write;
+       funcs->get_pixbuf = (ImageLoaderBackendFuncGetPixbuf) gdk_pixbuf_loader_get_pixbuf;
+       funcs->close = (ImageLoaderBackendFuncClose) gdk_pixbuf_loader_close;
+       funcs->abort = image_loader_svgz_abort;
+       funcs->free = image_loader_svgz_free;
+
+       funcs->get_format_name = image_loader_svgz_get_format_name;
+       funcs->get_format_mime_types = image_loader_svgz_get_format_mime_types;
+}
+
+
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff --git a/src/image_load_svgz.h b/src/image_load_svgz.h
new file mode 100644 (file)
index 0000000..e1a47ed
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2019 The Geeqie Team
+ *
+ * Author: Colin Clark
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef IMAGE_LOAD_SVGZ_H
+#define IMAGE_LOAD_SVGZ_H
+
+void image_loader_backend_set_svgz(ImageLoaderBackend *funcs);
+
+#endif
+
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */