summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-01-11 11:47:01 +0100
committerRicardo Wurmus <rekado@elephly.net>2021-01-11 11:47:01 +0100
commit291a746a1d3b4784d38b05239bdd7b8e796ce761 (patch)
tree44421f956f37abbea3ed73f19d48e9434cb18c71
parent218fb91e0225d2f7f4efa2d3d02cfcbab0c0f581 (diff)
pict: Refactor.
-rw-r--r--pict.scm20
1 files 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))