unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andy Wingo <wingo@igalia.com>
To: "Luis Felipe López Acevedo" <felipe.lopez@openmailbox.org>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH] system: grub: Convert grub background using rsvg-convert
Date: Mon, 31 Aug 2015 10:57:17 +0200	[thread overview]
Message-ID: <87zj17vnrm.fsf@igalia.com> (raw)
In-Reply-To: <f73bbdb8d2eddf33ec34c3fc8628c6e8@openmailbox.org> ("Luis Felipe López Acevedo"'s message of "Fri, 28 Aug 2015 12:15:49 -0500")

On Fri 28 Aug 2015 19:15, Luis Felipe López Acevedo <felipe.lopez@openmailbox.org> 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))))))

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

  parent reply	other threads:[~2015-08-31  8:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 18:23 [PATCH] system: grub: Convert grub background using rsvg-convert Mark H Weaver
2015-08-27 21:19 ` 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 [this message]
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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=87zj17vnrm.fsf@igalia.com \
    --to=wingo@igalia.com \
    --cc=felipe.lopez@openmailbox.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).