From: Ben Pfaff Date: Wed, 3 Aug 2022 23:53:53 +0000 (-0700) Subject: Use rsvg-convert instead of GIMP for converting SVG to PNG. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=6d7eed1c12693a3688a3c16f634a5b816660085b Use rsvg-convert instead of GIMP for converting SVG to PNG. rsvg-convert is much faster and more commonly installed. --- diff --git a/NEWS b/NEWS index 7ca413f4e9..13ab59c643 100644 --- 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. diff --git a/README.Git b/README.Git index 26ec65ddac..b666c06d81 100644 --- a/README.Git +++ b/README.Git @@ -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 72c1d34f0b..8061b698f7 100644 --- 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 diff --git a/build-aux/automake.mk b/build-aux/automake.mk index af4d6e98f9..22c17555e6 100644 --- a/build-aux/automake.mk +++ b/build-aux/automake.mk @@ -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 index 0000000000..c9cff8ba3e --- /dev/null +++ b/build-aux/png-add-comment @@ -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 diff --git a/build-aux/svg2png b/build-aux/svg2png index 3587c26167..3ba9d6ac9e 100755 --- a/build-aux/svg2png +++ b/build-aux/svg2png @@ -14,29 +14,9 @@ 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"