From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark H Weaver Subject: [PATCH] system: grub: Convert grub background using rsvg-convert Date: Sun, 23 Aug 2015 14:23:56 -0400 Message-ID: <87egitx3r7.fsf@netris.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTZwW-0006Uc-A6 for guix-devel@gnu.org; Sun, 23 Aug 2015 14:24:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTZwS-0007lN-AK for guix-devel@gnu.org; Sun, 23 Aug 2015 14:24:32 -0400 Received: from world.peace.net ([50.252.239.5]:47889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTZwS-0007lJ-5H for guix-devel@gnu.org; Sun, 23 Aug 2015 14:24:28 -0400 List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain This patch modifies 'svg->png' in (gnu system grub) to use rsvg-convert instead of inkscape. Inkscape is a rather heavy dependency to convert an image. This is important for users who choose to avoid binary substitutes. The main difficulty here was that our SVG artwork is partially transparent, and includes a "Background" layer with a checker-board pattern. I guess this layer is for convenience when editing in Inkscape, and apparently Inkscape excludes the "Background" layer when exporting to png. Other tools render all layers. Therefore, avoiding Inkscape required code to remove that layer before conversion to png. Comments and suggestions welcome, Mark --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-system-grub-Convert-grub-background-using-rsvg-conve.patch Content-Transfer-Encoding: quoted-printable Content-Description: [PATCH] system: grub: Convert grub background using rsvg-convert >From 0b3066420f72ecf15b65406bd417768450bfcac7 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 19 Aug 2015 17:26:02 -0400 Subject: [PATCH] system: grub: Convert grub background using rsvg-convert, = not inkscape. * gnu/system/grub.scm (svg->png): Accept additional arguments 'width' and 'height'. Reimplement using rsvg-convert and emacs instead of inkscape. (resize-image): Remove. (grub-background-image): Remove 'resize-image' step. Pass 'width' and 'height' to 'svg->png'. --- gnu/system/grub.scm | 57 +++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm index e49b6db..fe7400a 100644 --- a/gnu/system/grub.scm +++ b/gnu/system/grub.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2013, 2014, 2015 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2015 Mark H Weaver ;;; ;;; This file is part of GNU Guix. ;;; @@ -26,8 +27,8 @@ #:use-module (guix download) #:use-module (gnu artwork) #:autoload (gnu packages grub) (grub) - #:autoload (gnu packages inkscape) (inkscape) - #:autoload (gnu packages imagemagick) (imagemagick) + #:autoload (gnu packages emacs) (emacs) + #:autoload (gnu packages gnome) (librsvg) #:autoload (gnu packages compression) (gzip) #:use-module (ice-9 match) #:use-module (srfi srfi-1) @@ -119,25 +120,40 @@ ;;; Background image & themes. ;;; =20 -(define (svg->png svg) +(define (svg->png svg width height) "Build a PNG from SVG." ;; Don't use #:local-build? so that it's substitutable. - (gexp->derivation "grub-image.png" - #~(zero? - (system* (string-append #$inkscape "/bin/inkscape") - "--without-gui" - (string-append "--export-png=3D" #$output) - #$svg)))) - -(define (resize-image image width height) - "Resize IMAGE to WIDTHxHEIGHT." - ;; Don't use #:local-build? so that it's substitutable. - (let ((size (string-append (number->string width) - "x" (number->string height)))) - (gexp->derivation "grub-image.resized.png" - #~(zero? - (system* (string-append #$imagemagick "/bin/conve= rt") - "-resize" #$size #$image #$output))))) + (let ((width (number->string width)) + (height (number->string height))) + (gexp->derivation + "grub-image.png" + #~(begin + (use-modules (guix build emacs-utils)) + (let ((image-file "/tmp/image.svg")) + ;; The SVG images in the guix-artwork repository contain a bott= om + ;; "Background" layer containing a checkerboard pattern. Here = we + ;; remove that layer. + (copy-file #$svg image-file) + (chmod image-file #o644) + (parameterize ((%emacs (string-append #$emacs "/bin/emacs"))) + (emacs-batch-edit-file image-file + '(progn (goto-char (point-min)) + (when (re-search-forward "inkscape:label=3D\"Backgr= ound\"" + nil nil) + (nxml-backward-up-element) + (set-mark (point)) + (nxml-forward-element) + (kill-region (mark) (point)) + (basic-save-buffer))))) + (zero? + (system* (string-append #$librsvg "/bin/rsvg-convert") + "--width" #$width + "--height" #$height + "--background-color" "black" + "--format" "png" + "--output" #$output + image-file)))) + #:modules '((guix build emacs-utils))))) =20 (define* (grub-background-image config #:key (width 640) (height 480)) "Return the GRUB background image defined in CONFIG with a ratio of @@ -147,8 +163,7 @@ WIDTH/HEIGHT, or #f if none was found." (=3D (grub-image-aspect-ratio image) ratio)) (grub-theme-images (grub-configuration-theme config)= )))) (if image - (mlet %store-monad ((png (svg->png (grub-image-file image)))) - (resize-image png width height)) + (svg->png (grub-image-file image) width height) (with-monad %store-monad (return #f))))) =20 --=20 2.5.0 --=-=-=--