aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/ruby.scm
blob: 540aab23aff68f2f26c7d1e5764735cadef9661a (about) (plain)
blob size (490KB) exceeds display size limit (100KB).
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