summaryrefslogtreecommitdiff
path: root/svgtopng
diff options
context:
space:
mode:
authorSean Davis <smd.seandavis@gmail.com>2018-08-15 21:28:20 -0400
committerSimon Steinbeiß <simon.steinbeiss@elfenbeinturm.at>2018-08-27 23:57:09 +0200
commitc4ea261a88e0418949163b4cb8d0df0a0e939627 (patch)
treea57d0e86bcbf2eadac989c2c121db70c5f6a2ca8 /svgtopng
parent52f7c529ee027e87cdc972e17cb7a168bf557715 (diff)
downloadelementary-xfce-c4ea261a88e0418949163b4cb8d0df0a0e939627.tar.gz
Add Makefiles and svgtopng
Diffstat (limited to 'svgtopng')
-rw-r--r--svgtopng/Makefile18
-rwxr-xr-xsvgtopng/pngtheme.sh39
-rw-r--r--svgtopng/svgtopng.c134
3 files changed, 191 insertions, 0 deletions
diff --git a/svgtopng/Makefile b/svgtopng/Makefile
new file mode 100644
index 00000000..0bd90900
--- /dev/null
+++ b/svgtopng/Makefile
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+ICONDIR ?= elementary-xfce
+
+all: svgtopng
+
+svgtopng:
+ gcc -Wall -Werror -O0 -pipe \
+ svgtopng.c -o svgtopng \
+ `pkg-config --libs --cflags gtk+-2.0` \
+ `pkg-config --libs --cflags gdk-pixbuf-2.0`
+
+convert: svgtopng | $(ICONDIR)
+ chmod +x pngtheme.sh
+ ./pngtheme.sh $(ICONDIR)
+
+clean:
+ rm -f svgtopng
diff --git a/svgtopng/pngtheme.sh b/svgtopng/pngtheme.sh
new file mode 100755
index 00000000..83dbf098
--- /dev/null
+++ b/svgtopng/pngtheme.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+icondir="$1"
+
+if test ! -d "$icondir"; then
+ echo "Pass a directory to the theme dir in the argument"
+ exit 1;
+fi
+
+if test ! -f "$icondir/index.theme"; then
+ echo "Not an icontheme directory!"
+ exit 1;
+fi
+
+cmd="svgtopng/svgtopng"
+
+echo "==================================="
+
+echo "Creating png icons from svg files and symlinks"
+#ignore list customized for elementary-xfce
+find "$icondir" -iname "*.svg" -not \( -wholename "*/scalable/*" -o -wholename "*/symbolic/*" -o -wholename "*/animations/*process-*" -o -wholename "*/animations/*gnome-spinner*" -o -wholename "*/animations*pk-action-refresh*" \) -exec $cmd {} +
+
+echo "==================================="
+
+echo "Cleanup icon directory"
+find "$icondir" -name "untitled folder" -type d -exec rm -rf {} +
+
+echo "==================================="
+
+echo "Deleting svg files"
+find "$icondir" -iname '*.svg' -not \( -wholename "*/scalable/*" -o -wholename "*/symbolic/*" -o -wholename "*/animations/*process-*" -o -wholename "*/animations/*gnome-spinner*" -o -wholename "*/animations*pk-action-refresh*" \) -delete
+
+echo "==================================="
+
+#ignore the output if the theme depends on another one (e.g. elementary-xfce-dark needs to be converted before elementary-xfce)
+echo "Checking dangling symlinks"
+find -L "$icondir" -type l -exec /bin/ls -go {} \;
+
+echo "==================================="
diff --git a/svgtopng/svgtopng.c b/svgtopng/svgtopng.c
new file mode 100644
index 00000000..490b5b7c
--- /dev/null
+++ b/svgtopng/svgtopng.c
@@ -0,0 +1,134 @@
+/*-
+ * vi:set et ai sts=2 sw=2 cindent:
+ *
+ * Copyright (c) 2012 Nick Schermer <nick@xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <gtk/gtk.h>
+
+
+static void
+svgtopng (const gchar *src)
+{
+ gchar *dest;
+ gchar *tmp;
+ GdkPixbuf *pix;
+ gchar *link;
+ gchar *newlink;
+ GError *error = NULL;
+ gchar *dirname;
+ gchar *basename;
+ gint icon_size;
+
+ if (!g_str_has_suffix (src, ".svg"))
+ return;
+
+ /* get parent directory name */
+ dirname = g_path_get_dirname (src);
+ basename = g_path_get_basename (dirname);
+ g_free (dirname);
+ if (basename == NULL)
+ return;
+
+ /* to go get an icon size */
+ icon_size = atoi (basename);
+ g_free (basename);
+ if (icon_size == 0)
+ {
+ g_message ("Unable to extract icon size from directory name %s", src);
+ return;
+ }
+
+ tmp = g_strndup (src, strlen (src) - 3);
+ dest = g_strconcat (tmp, "png", NULL);
+ g_free (tmp);
+
+ if (!g_file_test (dest, G_FILE_TEST_EXISTS))
+ {
+ if (g_file_test (src, G_FILE_TEST_IS_SYMLINK))
+ {
+ link = g_file_read_link (src, NULL);
+ if (link
+ && g_str_has_suffix (link, ".svg"))
+ {
+ tmp = g_strndup (link, strlen (link) - 3);
+ newlink = g_strconcat (tmp, "png", NULL);
+ g_free (tmp);
+
+ if (symlink (newlink, dest) == -1)
+ g_message ("failed to create symlink: %s", g_strerror (errno));
+
+ g_free (newlink);
+ }
+ g_free (link);
+ }
+ else
+ {
+ pix = gdk_pixbuf_new_from_file (src, &error);
+ if (pix)
+ {
+ if (gdk_pixbuf_get_width (pix) > icon_size
+ || gdk_pixbuf_get_height (pix) > icon_size)
+ {
+ g_message ("Skipping %s, size too big (%dx%d instead of %dx%d)",
+ dest, gdk_pixbuf_get_width (pix),
+ gdk_pixbuf_get_height (pix),
+ icon_size, icon_size);
+
+ g_object_unref (pix);
+ return;
+ }
+
+ if (!gdk_pixbuf_save (pix, dest, "png", &error, NULL))
+ {
+ g_message ("Failed to save pixmap to %s: %s", dest, error->message);
+ g_error_free (error);
+ }
+ g_object_unref (pix);
+ }
+ else
+ {
+ g_message ("Failed to load svg %s: %s", src, error->message);
+ g_error_free (error);
+ }
+ }
+ }
+
+ g_free (dest);
+}
+
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint i;
+
+ for (i = 1; i < argc; i++)
+ svgtopng (argv[i]);
+
+ return EXIT_SUCCESS;
+}