123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- (defvar gs-program "gs"
- "The name of the Ghostscript interpreter.")
- (defvar gs-device "x11"
- "The Ghostscript device to use to produce images.")
- (defvar gs-options
- '("-q"
-
- "-dSAFER"
- "-dBATCH"
- "-sDEVICE=<device>"
- "<file>")
- "List of command line arguments to pass to Ghostscript.
- Arguments may contain place-holders `<file>' for the name of the
- input file, and `<device>' for the device to use.")
- (put 'gs-options 'risky-local-variable t)
- (defun gs-options (device file)
- "Return a list of command line options with place-holders replaced.
- DEVICE is the value to substitute for the place-holder `<device>',
- FILE is the value to substitute for the place-holder `<file>'."
- (mapcar #'(lambda (option)
- (setq option (replace-regexp-in-string "<device>" device option)
- option (replace-regexp-in-string "<file>" file option)))
- gs-options))
- (declare-function x-display-mm-width "xfns.c" (&optional terminal))
- (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
- (defun gs-width-in-pt (frame pixel-width)
- "Return, on FRAME, pixel width PIXEL-WIDTH translated to pt."
- (let ((mm (* (float pixel-width)
- (/ (float (x-display-mm-width frame))
- (float (x-display-pixel-width frame))))))
- (/ (* 25.4 mm) 72.0)))
- (declare-function x-display-mm-height "xfns.c" (&optional terminal))
- (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
- (defun gs-height-in-pt (frame pixel-height)
- "Return, on FRAME, pixel height PIXEL-HEIGHT translated to pt."
- (let ((mm (* (float pixel-height)
- (/ (float (x-display-mm-height frame))
- (float (x-display-pixel-height frame))))))
- (/ (* 25.4 mm) 72.0)))
- (declare-function x-change-window-property "xfns.c"
- (prop value &optional frame type format outer-p))
- (defun gs-set-ghostview-window-prop (frame spec img-width img-height)
- "Set the `GHOSTVIEW' window property of FRAME.
- SPEC is a GS image specification. IMG-WIDTH is the width of the
- requested image, and IMG-HEIGHT is the height of the requested
- image in pixels."
- (let* ((box (plist-get (cdr spec) :bounding-box))
- (llx (elt box 0))
- (lly (elt box 1))
- (urx (elt box 2))
- (ury (elt box 3))
- (rotation (or (plist-get (cdr spec) :rotate) 0))
-
-
- (in-width (/ (- urx llx) 72.0))
- (in-height (/ (- ury lly) 72.0))
- (xdpi (/ img-width in-width))
- (ydpi (/ img-height in-height)))
- (x-change-window-property "GHOSTVIEW"
- (format "0 %d %d %d %d %d %g %g"
- rotation llx lly urx ury xdpi ydpi)
- frame)))
- (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
- (defun gs-set-ghostview-colors-window-prop (frame pixel-colors)
- "Set the `GHOSTVIEW_COLORS' environment variable depending on FRAME."
- (let ((mode (cond ((x-display-color-p frame) "Color")
- ((x-display-grayscale-p frame) "Grayscale")
- (t "Monochrome"))))
- (x-change-window-property "GHOSTVIEW_COLORS"
- (format "%s %s" mode pixel-colors)
- frame)))
- (declare-function x-window-property "xfns.c"
- (prop &optional frame type source delete-p vector-ret-p))
- (defun gs-load-image (frame spec img-width img-height window-and-pixmap-id
- pixel-colors)
- "Load a PS image for display on FRAME.
- SPEC is an image specification, IMG-HEIGHT and IMG-WIDTH are width
- and height of the image in pixels. WINDOW-AND-PIXMAP-ID is a string of
- the form \"WINDOW-ID PIXMAP-ID\". Value is non-nil if successful."
- (unwind-protect
- (let ((file (plist-get (cdr spec) :file))
- gs
- (timeout 40))
-
-
-
-
-
-
-
- (while (and
-
- (not (zerop (length (x-window-property "GHOSTVIEW"
- frame))))
-
-
-
-
-
- (not (zerop timeout)))
- (unless (sit-for 0.1 t)
- (sleep-for 0.05))
- (setq timeout (1- timeout)))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (gs-set-ghostview-window-prop frame spec img-width img-height)
- (gs-set-ghostview-colors-window-prop frame pixel-colors)
- (setenv "GHOSTVIEW" window-and-pixmap-id)
- (setq gs (apply 'start-process "gs" "*GS*" gs-program
- (gs-options gs-device file)))
- (set-process-query-on-exit-flag gs nil)
- gs)
- nil))
- (provide 'gs)
|