Use rsvg-convert instead of GIMP for converting SVG to PNG.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 3 Aug 2022 23:53:53 +0000 (16:53 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Aug 2022 16:53:13 +0000 (09:53 -0700)
rsvg-convert is much faster and more commonly installed.

NEWS
README.Git
Smake
build-aux/automake.mk
build-aux/png-add-comment [new file with mode: 0644]
build-aux/svg2png

diff --git a/NEWS b/NEWS
index 7ca413f4e94770f933aa3aae6a0fa7981ec56a10..13ab59c6430130820e8ddc0ffd18dd1cd93663aa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,11 @@ See the end for copying conditions.
 
 Please send PSPP bug reports to bug-gnu-pspp@gnu.org.
 
+Changes after 1.6.2:
+
+ * Building from a Git repository, which previously required GIMP, now
+   requires rsvg-convert from librsvg2 instead.
+
 Changes from 1.6.1 to 1.6.2:
 
  * Bug fixes.
index 26ec65ddacc95d7e87dca9c3bad4c401d68501af..b666c06d816c1cd0150779d68245204278b9a4b6 100644 (file)
@@ -2,7 +2,7 @@ Prerequisites for Building PSPP from Git
 ----------------------------------------
 
 To build this project from the sources direct from the Git archive,
-you must install the prerequisites listed in README, plus the
+you must install the prerequisites listed in INSTALL, plus the
 following:
 
        * Autoconf 2.64 (or later).
@@ -23,7 +23,7 @@ following:
 
        * Texinfo 5.2 or later, to build the documentation.
 
-       * Gimp --  2.8.2 is known to work
+       * rsvg-convert from librsvg2.
 
 After you install PSPP's prerequisites, you must obtain a copy of
 Gnulib, then bootstrap the tree, as described in the sections below.
diff --git a/Smake b/Smake
index 72c1d34f0b5a6cbc14e6875325fba62c25e68611..8061b698f7ed4996909a370d02a43b2c6ea38fbe 100644 (file)
--- a/Smake
+++ b/Smake
@@ -24,6 +24,8 @@ all: everything
 GNULIB = ../gnulib
 GNULIB_TOOL = $(GNULIB)/gnulib-tool
 
+PYTHON3 = python3
+
 GNULIB_MODULES = \
        assert \
        byteswap \
@@ -419,12 +421,6 @@ clean: clean-icons
 .PHONY: all gettextize clean
 
 
-# The "convert" program from imagemagick can be used to create png from svg but doesn't properly deal
-# with the alpha channels.  Therefore, it is not recommended for production pspp builds, but might
-# be useful to get something working on a platform which doesn't have a working gimp.
-
-#svg2png=convert -background transparent $1 $3
-
 # Graphical layout of icons and our portfolio
 # ===========================================
 #
@@ -456,33 +452,35 @@ clean: clean-icons
 #  => all others are in scaled (just one design svg)
 #
 
+SVG2PNG = PYTHON3='$(PYTHON3)' build-aux/svg2png
+
 # Rule for icons with size dependent graphical design
 src/ui/gui/icons/%.png: src/ui/gui/artwork/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 
 # Rules for icons which are simply scaled - Attention multitarget would trigger only once...
 src/ui/gui/icons/16x16/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 src/ui/gui/icons/22x22/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 src/ui/gui/icons/24x24/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 src/ui/gui/icons/32x32/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 src/ui/gui/icons/48x48/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 src/ui/gui/icons/96x96/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 src/ui/gui/icons/256x256/%.png : src/ui/gui/artwork/scalable/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
        mkdir -p $(dir $@)
-       build-aux/svg2png "$<" "$(lastword $^)" "$@"
+       $(SVG2PNG) "$<" "$(lastword $^)" "$@"
 
 # Copy svg
 src/ui/gui/icons/%.svg: src/ui/gui/artwork/%.svg
index af4d6e98f9b746f3dc70e89f490755251377fdd1..22c17555e606b1b907786b4fe13bf5c255014d32 100644 (file)
@@ -16,4 +16,4 @@
 #
 ## Process this file with automake to produce Makefile.in  -*- makefile -*-
 
-EXTRA_DIST += build-aux/svg2png build-aux/icon-list
+EXTRA_DIST += build-aux/png-add-comment build-aux/svg2png build-aux/icon-list
diff --git a/build-aux/png-add-comment b/build-aux/png-add-comment
new file mode 100644 (file)
index 0000000..c9cff8b
--- /dev/null
@@ -0,0 +1,72 @@
+#! /usr/bin/python3
+
+import codecs
+import os
+import struct
+import sys
+import zlib
+
+if len(sys.argv) != 3 or '--help' in sys.argv:
+    sys.stdout.write("""\
+%s: adds a comment to a PNG file
+usage: png-add-comment KEYWORD TEXT < INPUT.PNG > OUTPUT.PNG
+where KEYWORD is the comment type, e.g. "Comment" or "Copyright"
+  and TEXT is the comment's content (encoded in Latin-1).
+""" % sys.argv[0])
+    sys.exit(0)
+
+if os.isatty(1):
+    sys.stderr.write("%s: not writing binary data to a terminal "
+                     "(use --help for help)\n")
+    sys.exit(1)
+
+infile = sys.stdin.buffer
+outfile = sys.stdout.buffer
+
+encoded_keyword = codecs.encode(sys.argv[1], "ASCII")
+if len(encoded_keyword) > 79:
+    sys.stderr.write("%s: keyword must be 79 bytes or less\n" % sys.argv[0])
+
+encoded_comment = codecs.encode(sys.argv[2], "Latin-1")
+comment_data = encoded_keyword + bytes([0]) + encoded_comment
+comment_crc = zlib.crc32(b'tEXt' + comment_data, 0)
+comment_chunk = struct.pack('!L', len(comment_data)) + b'tEXt' + comment_data + struct.pack('!L', comment_crc)
+
+def read_fully(stream, n):
+    data = stream.read(n)
+    if len(data) != n:
+        sys.stderr.write("%s: unexpected end of input\n" % sys.argv[0])
+        sys.exit(1)
+    return data
+
+# Copy signature and verify that we're working with a PNG file.
+signature = read_fully(infile, 8)
+if signature != bytes([137, 80, 78, 71, 13, 10, 26, 10]):
+    sys.stderr.write("%s: input is not a PNG file\n" % sys.argv[0])
+    sys.exit(1)
+outfile.write(signature)
+
+comment_written = False
+while True:
+    header = read_fully(infile, 8)
+    chunk_len, chunk_type = struct.unpack('!L 4s', header)
+    chunk_data = read_fully(infile, chunk_len)
+    chunk_crc = read_fully(infile, 4)
+
+    if (chunk_type in (b'iCCP', b'sRGB', b'sBIT', b'gAMA', b'cHRM',
+                       b'PLTE', b'tRNS', b'hIST', b'bKGD', b'IDAT',
+                       b'IEND')) and not comment_written:
+        outfile.write(comment_chunk)
+        comment_written = True
+
+    outfile.write(header)
+    outfile.write(chunk_data)
+    outfile.write(chunk_crc)
+    crc = struct.unpack('!L', chunk_crc)[0]
+    expected_crc = zlib.crc32(header[4:8] + chunk_data, 0)
+    if crc != expected_crc:
+        sys.stderr.write("%s: bad crc reading PNG chunk\n"
+                         % sys.argv[0])
+    if chunk_type == b'IEND':
+        break
+assert comment_written
index 3587c26167274d234076f9fc08eca3124d3ae2de..3ba9d6ac9ee0fb82291795e4005d2298ebe23853 100755 (executable)
 stripprefix=${3#src*icons\/}
 width=${stripprefix%%x*}
 
-if (gimp --version) >/dev/null 2>&1; then
-    echo "Converting $1 to $3 size $widthx$width with GIMP"
-    comment=`cat $2`
-    # If no width can be extracted from the destination path
-    # then take the natural width by setting width to 0
-    case "$width" in
-       [0-9][0-9] | [0-9][0-9][0-9])  ;;
-       *)                 width="0";;
-    esac
-    gimp -i -d -b "\
-(let* ((image (car (file-svg-load 1 \"$1\" \"$1\" 90 $width $width 0 ))))
-      (gimp-image-attach-parasite image '(\"gimp-comment\" 0 \"$comment\"))
-      (gimp-file-save 1 image (car (gimp-image-get-active-drawable image))
-                     \"$3\" \"$3\"))
-    (gimp-quit 1)"
-elif (rsvg-convert --version) >/dev/null 2>&1; then
-    echo "Converting $1 to $3 size $widthx$width with rsvg-convert"
-    case $width in
-       [0-9][0-9] | [0-9][0-9][0-9]) widthoption="--width=$width --height=$width" ;;
-       *) widthoption= ;;
-    esac
-    rsvg-convert $widthoption "$1" > "$3"
-else
-    echo "$0: can't find gimp or rsvg-convert" >&2
-    exit 1
-fi
+comment=`cat $2`
+case $width in
+    [0-9][0-9] | [0-9][0-9][0-9]) widthoption="--width=$width --height=$width" ;;
+    *) widthoption= ;;
+esac
+rsvg-convert $widthoption "$1" | ${PYTHON3:-python3} build-aux/png-add-comment Comment "$comment" > "$3"