From 291a746a1d3b4784d38b05239bdd7b8e796ce761 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Mon, 11 Jan 2021 11:47:01 +0100 Subject: pict: Refactor. --- pict.scm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pict.scm b/pict.scm index 3e3f11a..b853c47 100644 --- a/pict.scm +++ b/pict.scm @@ -121,15 +121,20 @@ pict? (sxml pict-sxml)) +(define (pict->svg-sxml pict) + "Wrap the PICT's SXML data in a proper SVG wrapper with height, +width, and SVG namespace." + `(svg (@ (width ,(pict-width pict)) + (height ,(pict-height pict)) + (xmlns "http://www.w3.org/2000/svg")) + ,(pict-sxml pict))) + (define (pict->file pict file-name) "Write the PICT to a file with name FILE-NAME. If FILE-NAME is a procedure, it is called with the XML that is supposed to be written to the file to determine the file name. Return the file name." (let* ((xml (with-output-to-string - (lambda _ (sxml->xml `(svg (@ (width ,(pict-width pict)) - (height ,(pict-height pict)) - (xmlns "http://www.w3.org/2000/svg")) - ,(pict-sxml pict)))))) + (lambda _ (sxml->xml (pict->svg-sxml pict))))) (name (if (procedure? file-name) (file-name xml) file-name))) (with-output-to-file name @@ -154,14 +159,9 @@ the file to determine the file name. Return the file name." (define* (pict->pdf pict out #:key page-height page-width) "Read SVG from picture PICT and write a PDF file to OUT." - (define svg - `(svg (@ (width ,(pict-width pict)) - (height ,(pict-height pict)) - (xmlns "http://www.w3.org/2000/svg")) - ,(pict-sxml pict))) (let* ((port (mkstemp! (string-copy "/tmp/pictXXXXXXX"))) (name (port-filename port))) - (sxml->xml svg port) + (sxml->xml (pict->svg-sxml pict) port) (close-port port) (let*-values (((d) (rsvg-set-default-dpi-x-y %dpi %dpi)) ((handle) (rsvg-handle-new-from-file name)) -- cgit v1.2.3