aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu build svg)
  #:use-module (rsvg)
  #:use-module (cairo)
  #:use-module (srfi srfi-11)
  #:export (svg->png))

(define* (downscaled-surface surface
                             #:key
                             source-width source-height
                             width height)
  "Return a new rendering context where SURFACE is scaled to WIDTH x HEIGHT."
  (let ((cr (cairo-create (cairo-image-surface-create 'argb32
                                                      width height))))
    (cairo-scale cr (/ width source-width) (/ height source-height))
    (cairo-set-source-surface cr surface 0 0)
    (cairo-pattern-set-filter (cairo-get-source cr) 'best)
    (cairo-rectangle cr 0 0 source-width source-height)
    (cairo-fill cr)
    cr))

(define* (svg->png in-svg out-png
                   #:key width height)
  "Render the file at IN-SVG as a PNG file in OUT-PNG.  When WIDTH and HEIGHT
are provided, use them as the dimensions of OUT-PNG; otherwise preserve the
dimensions of IN-SVG."
  (define svg
    (rsvg-handle-new-from-file in-svg))

  (let-values (((origin-width origin-height em ex)
                (rsvg-handle-get-dimensions svg)))
    (let* ((surf (cairo-image-surface-create 'argb32
                                             origin-width origin-height))
           (cr   (cairo-create surf)))
      (rsvg-handle-render-cairo svg cr)
      (cairo-surface-flush surf)
      (let ((cr (if (and width height
                         (not (= width origin-width))
                         (not (= height origin-height)))
                    (downscaled-surface surf
                                        #:source-width origin-width
                                        #:source-height origin-height
                                        #:width width
                                        #:height height)
                    cr)))
        (cairo-surface-write-to-png (cairo-get-target cr) out-png)))))

;;; svg.scm ends here
le='2017-05-28 09:56:14 -0400'>2017-05-28gnu: flex: Use the gzip-compressed tarball....This reverts commit 77e2538eda8a2721aef8336103c94fe31e12870c and fetches the gzip-compressed tarball. We do this so that flex-boot0 will not require lzip. * gnu/packages/flex.scm (flex)[source]: Fetch the '.tar.gz' tarball. [native-inputs]: Remove lzip. Leo Famulari 2017-05-27gnu: packages: flex: Add missing 'lzip' input....* gnu/packages/flex.scm (flex)[native-inputs]: Add lzip. Signed-off-by: Leo Famulari <leo@famulari.name> Sergei Trofimovich 2017-05-15gnu: flex-2.6.1: Remove variable....* gnu/packages/flex.scm (flex-2.6.1): Remove variable. * gnu/packages/bootloaders.scm (grub, dtc): Use flex instead of flex-2.6.1. * gnu/packages/embedded.scm (propeller-binutils, binutils-vc4): Likewise. * gnu/packages/maths.scm (scotch): Likewise. * gnu/packages/wine.scm (wine): Likewise. Leo Famulari 2017-05-15gnu: flex: Update to 2.6.4....* gnu/packages/flex.scm (flex): Update to 2.6.4. Leo Famulari 2017-03-08gnu: Add flex-2.6.1....* gnu/packages/flex.scm (flex-2.6.1): New variable. Leo Famulari 2017-02-28gnu: flex: Update to 2.6.3....* gnu/packages/flex.scm (flex): Update to 2.6.3. Leo Famulari 2016-12-02gnu: flex: Update to 2.6.2....* gnu/packages/flex.scm (flex): Update to 2.6.2. [native-inputs]: Add help2man. [origin]: Update uri to github. Remove CVE-2016-6354 patch. (flex-2.6.1): Remove variable. * gnu/packages/patches/flex-CVE-2016-6354.patch: Delete file. * gnu/local.mk (dist_patch_DATA): Update. * gnu/packages/kde-frameworks.scm (solid, kservice)[native-inputs]: Use flex. David Craven 2016-10-29Merge branch 'master' into core-updatesLeo Famulari 2016-10-29gnu: Add flex-2.6.1....* gnu/packages/flex.scm (flex-2.6.1): New variable. David Craven 2016-08-27gnu: flex: Fix CVE-2016-6354....* gnu/packages/flex.scm (flex)[source]: Add patch. * gnu/packages/patches/flex-CVE-2016-6354.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. Leo Famulari 2016-07-29gnu: Use define-public to export packages....* gnu/packages/bison.scm (bison): Define public. * gnu/packages/flex.scm (flex): Define public. * gnu/packages/pulseaudio.scm (libsndfile, libsamplerate, pulseaudio): Define public. * gnu/packages/sdl.scm (sdl, sdl2, libmikmod, sdl-gfx, sdl-image, sdl-mixer, sdl-net, sdl-ttf): Define public. * gnu/packages/search.scm (xapian): Remove unnecessary #:export. * gnu/packages/swig.scm (swig): Define public. Signed-off-by: Ludovic Courtès <ludo@gnu.org> David Craven