all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: guix-devel@gnu.org
Subject: [PATCH] system: grub: Convert grub background using rsvg-convert
Date: Sun, 23 Aug 2015 14:23:56 -0400	[thread overview]
Message-ID: <87egitx3r7.fsf@netris.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

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



[-- Attachment #2: [PATCH] system: grub: Convert grub background using rsvg-convert --]
[-- Type: text/x-patch, Size: 4638 bytes --]

From 0b3066420f72ecf15b65406bd417768450bfcac7 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
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 © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
 ;;;
 ;;; 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.
 ;;;
 
-(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=" #$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/convert")
-                                  "-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 bottom
+           ;; "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=\"Background\""
+                                                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)))))
 
 (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."
                         (= (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)))))
 
-- 
2.5.0


             reply	other threads:[~2015-08-23 18:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 18:23 Mark H Weaver [this message]
2015-08-27 21:19 ` [PATCH] system: grub: Convert grub background using rsvg-convert Ludovic Courtès
2015-08-28 17:15   ` Luis Felipe López Acevedo
2015-08-28 18:24     ` Mark H Weaver
2015-08-28 22:38       ` Luis Felipe López Acevedo
2015-08-29 13:55       ` Luis Felipe López Acevedo
2015-08-31  8:57     ` Andy Wingo
2015-08-31 21:05       ` Ludovic Courtès
2015-10-17 13:17       ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87egitx3r7.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.