fixing merge
[rclg.git] / rcl / devices.lisp
blobc5d6b3d1a11e03040f4318254ac7269839d28f4f
1 ;; Copyright (c) 2006-2007 Carlos Ungil
3 ;; Permission is hereby granted, free of charge, to any person obtaining
4 ;; a copy of this software and associated documentation files (the
5 ;; "Software"), to deal in the Software without restriction, including
6 ;; without limitation the rights to use, copy, modify, merge, publish,
7 ;; distribute, sublicense, and/or sell copies of the Software, and to
8 ;; permit persons to whom the Software is furnished to do so, subject to
9 ;; the following conditions:
11 ;; The above copyright notice and this permission notice shall be
12 ;; included in all copies or substantial portions of the Software.
14 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 (in-package :rcl)
24 (defun device-details (type)
25 "Returns for known types :ps, :pdf, :png, :jp[e]g, :xfig, :pictex
26 a pair function,extension"
27 (values-list (ecase type
28 (:ps '("postscript" "ps"))
29 (:pdf '("pdf" "pdf"))
30 (:png '("png" "png"))
31 ((or :jpeg :jpg) '("jpeg" "jpg"))
32 (:xfig '("xfig" "fig"))
33 (:pictex '("pictex" "tex")))))
35 (defmacro with-device ((filename type &rest options) &body body)
36 "Executes the body after opening a graphical device that is closed at the end;
37 options are passed to R (known types: :ps, :pdf, :png, :jp[e]g, :xfig, :pictex)"
38 `(multiple-value-bind (device-name device-extension) (device-details ,type)
39 (r% device-name (concatenate 'string ,filename "." device-extension) ,@options)
40 (let ((device (r% "dev.cur")))
41 (unwind-protect
42 (progn ,@body)
43 (r% "dev.off" device)))))