Re: [PATCH] system: grub: Convert grub background using rsvg-convert
Andy Wingoskribis: > On Fri 28 Aug 2015 19:15, Luis Felipe López Acevedo > writes: > >> Modifying the document background does not affect the design at all, >> because we are using the dark rectangle on top of it as the background >> of the image, so it doesn't matter what the background of the document >> is. >> >> Could it be that rsvg-convert is complaining about transparency in the >> page/document background and not about the transparency of the >> checkerboard pattern in the "Background" layer? Because it is not >> complaining about the transparency in the layer that contains the logo >> (which has transparency as well), is it? > > We could use guile-cairo / guile-rsvg to convert, fwiw. Better to do > that than to cause our graphics people to modify the image. > > (use-modules (rsvg) (cairo)) > > (define (->int x) (inexact->exact (ceiling x))) > > (define (render-to-png in-svg out-png) > (let ((svg (rsvg-handle-new-from-file in-svg))) > (call-with-values (lambda () (rsvg-handle-get-dimensions svg)) > (lambda (width height em ex) > (let* ((surf (cairo-image-surface-create 'argb32 >(->int width) >(->int height))) > (cr (cairo-create surf))) > (rsvg-handle-render-cairo svg cr) > (cairo-surface-flush surf) > (cairo-surface-write-to-png (cairo-get-target cr) out-png)) FWIW I tried this (finally!) and this has the same problem as ‘rsvg-convert’ regarding the checkerboard pattern. So maybe we need to apply Felipe’s changes anyway? Thoughts? Ludo’.
Re: [PATCH] system: grub: Convert grub background using rsvg-convert
Andy Wingoskribis: > We could use guile-cairo / guile-rsvg to convert, fwiw. Better to do > that than to cause our graphics people to modify the image. Indeed, that sounds even better. I had an old stash with Guile-{RSVG,Present}, so I’ve just finished it and pushed. Would you like to rewrite ‘svg->png’ in (gnu system grub) the way you suggested? :-) A helper module, say (gnu build images) would probably be needed. Thanks, Ludo’.
Re: [PATCH] system: grub: Convert grub background using rsvg-convert
On Fri 28 Aug 2015 19:15, Luis Felipe López Acevedowrites: > Modifying the document background does not affect the design at all, > because we are using the dark rectangle on top of it as the background > of the image, so it doesn't matter what the background of the document > is. > > Could it be that rsvg-convert is complaining about transparency in the > page/document background and not about the transparency of the > checkerboard pattern in the "Background" layer? Because it is not > complaining about the transparency in the layer that contains the logo > (which has transparency as well), is it? We could use guile-cairo / guile-rsvg to convert, fwiw. Better to do that than to cause our graphics people to modify the image. (use-modules (rsvg) (cairo)) (define (->int x) (inexact->exact (ceiling x))) (define (render-to-png in-svg out-png) (let ((svg (rsvg-handle-new-from-file in-svg))) (call-with-values (lambda () (rsvg-handle-get-dimensions svg)) (lambda (width height em ex) (let* ((surf (cairo-image-surface-create 'argb32 (->int width) (->int height))) (cr (cairo-create surf))) (rsvg-handle-render-cairo svg cr) (cairo-surface-flush surf) (cairo-surface-write-to-png (cairo-get-target cr) out-png)) That will render a png with the svg's natural pixel dimensions. You can use the png as is, or instead of rendering to a png you could use "surf" as a source surface for other paint operations, for example if you want to down-scale the image nicely. Here's an example, for a suitable definition of create-image-surface and scale-dimensions: (call-with-values (lambda () (create-image-surface filename width height)) (lambda (surface swidth sheight) (if surface (call-with-values (lambda () (scale-dimensions (/ swidth 1.0 sheight))) (lambda (x0 y0 width height) (cairo-save cr) (cairo-translate cr x0 y0) (cairo-scale cr (/ width swidth) (/ height sheight)) (cairo-set-source-surface cr surface 0 0) (cairo-pattern-set-filter (cairo-get-source cr) 'best) (cairo-rectangle cr 0 0 swidth sheight) (cairo-fill cr) (cairo-restore cr) (values width height))) (values 0 0 FWIW :) Cheers, Andy
Re: [PATCH] system: grub: Convert grub background using rsvg-convert
Here are the grub SVGs with vector checkerboard: https://cloud.openmailbox.org/index.php/s/uBM9iQ3oLLjjIZX So no need for Inkscape anymore :) -- Luis Felipe López Acevedo http://sirgazil.bitbucket.org/
Re: [PATCH] system: grub: Convert grub background using rsvg-convert
Hi Luis, thanks for the quick response. Luis Felipe López Acevedo felipe.lo...@openmailbox.org writes: On 2015-08-27 16:19, l...@gnu.org wrote: Mark H Weaver m...@netris.org skribis: 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. Fun. :-) If possible, I would rather remove said layer directly in the guix-artwork repo, or somehow make that layer invisible to rsvg-convert. Luis Felipe: What’s your take on this? If I understand correctly, the problem is transparency, right? I don't understand why transparency would be an issue when exporting PNG images, but I don't know how rsvg works. In any case, the SVG has transparency in several parts: - The logo. - The checkerboard pattern (which is part of the design as in the slim login screen). Ah, okay, so my guesses were incorrect. I guess the problem is actually that rsvg-convert (from librsvg) fails to render these SVG files correctly. Here's how it renders grub/GuixSD-fully-black-4-3.svg on a black background: rsvg-convert --width 640 --height 480 --background-color black \ --format png --output ~/grub-background.png \ grub/GuixSD-fully-black-4-3.svg Modifying the first to be fully opaque is time consuming, but can be done. No need, we should keep the source file in the preferred form for editing. I'll see if I can figure out what librsvg is doing wrong, and in the meantime we can keep using inkscape to do the conversion. Thanks again, Mark
[PATCH] system: grub: Convert grub background using rsvg-convert
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 From 0b3066420f72ecf15b65406bd417768450bfcac7 Mon Sep 17 00:00:00 2001 From: Mark H Weaver m...@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 l...@gnu.org +;;; Copyright © 2015 Mark H Weaver m...@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