annotate lisp/gs.el @ 87229:e4e336c0677e

Add declare-function compatibility definition. (mail-header-parse-content-type, message-narrow-to-head): Autoload. (message-fetch-field): Declare as a function.
author Glenn Morris <rgm@gnu.org>
date Tue, 11 Dec 2007 05:22:04 +0000
parents 9355f9b7bbff
children 73661ddc7ac7 f55f9811f5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; gs.el --- interface to Ghostscript
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1998, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Maintainer: FSF
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Keywords: internal
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; any later version.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 55771
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 55771
diff changeset
24 ;; Boston, MA 02110-1301, USA.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; This code is experimental. Don't use it.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;;; Code:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 (defvar gs-program "gs"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 "The name of the Ghostscript interpreter.")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 (defvar gs-device "x11"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 "The Ghostscript device to use to produce images.")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
40 (defvar gs-options
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 '("-q"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;"-dNOPAUSE"
55725
00841464e6d8 (gs-options): Add -dSAFER. Mark it risky.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
43 "-dSAFER"
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 "-dBATCH"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 "-sDEVICE=<device>"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 "<file>")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 "List of command line arguments to pass to Ghostscript.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 Arguments may contain place-holders `<file>' for the name of the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 input file, and `<device>' for the device to use.")
55725
00841464e6d8 (gs-options): Add -dSAFER. Mark it risky.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
50 (put 'gs-options 'risky-local-variable t)
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (defun gs-options (device file)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 "Return a list of command line options with place-holders replaced.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 DEVICE is the value to substitute for the place-holder `<device>',
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 FILE is the value to substitute for the place-holder `<file>'."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (mapcar #'(lambda (option)
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
57 (setq option (replace-regexp-in-string "<device>" device option)
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
58 option (replace-regexp-in-string "<file>" file option)))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 gs-options))
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
60
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; The GHOSTVIEW property (taken from gv 3.5.8).
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
62 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; Type:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;;
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; STRING
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
66 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; Parameters:
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
68 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; BPIXMAP ORIENT LLX LLY URX URY XDPI YDPI [LEFT BOTTOM TOP RIGHT]
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
70 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; Scanf format: "%d %d %d %d %d %d %f %f %d %d %d %d"
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
72 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; Explanation of parameters:
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
74 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; BPIXMAP: pixmap id of the backing pixmap for the window. If no
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;; pixmap is to be used, this parameter should be zero. This
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; parameter must be zero when drawing on a pixmap.
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
78 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; ORIENT: orientation of the page. The number represents clockwise
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; rotation of the paper in degrees. Permitted values are 0, 90, 180,
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;; 270.
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
82 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;; LLX, LLY, URX, URY: Bounding box of the drawable. The bounding box
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; is specified in PostScript points in default user coordinates.
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
85 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;; XDPI, YDPI: Resolution of window. (This can be derived from the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;; other parameters, but not without roundoff error. These values are
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; included to avoid this error.)
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
89 ;;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; LEFT, BOTTOM, TOP, RIGHT: (optional) Margins around the window.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;; The margins extend the imageable area beyond the boundaries of the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; window. This is primarily used for popup zoom windows. I have
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; encountered several instances of PostScript programs that position
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; themselves with respect to the imageable area. The margins are
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; specified in PostScript points. If omitted, the margins are
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 ;; assumed to be 0.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (defun gs-width-in-pt (frame pixel-width)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 "Return, on FRAME, pixel width PIXEL-WIDTH tranlated to pt."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (let ((mm (* (float pixel-width)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (/ (float (x-display-mm-width frame))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (float (x-display-pixel-width frame))))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (/ (* 25.4 mm) 72.0)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (defun gs-height-in-pt (frame pixel-height)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 "Return, on FRAME, pixel height PIXEL-HEIGHT tranlated to pt."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (let ((mm (* (float pixel-height)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (/ (float (x-display-mm-height frame))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (float (x-display-pixel-height frame))))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (/ (* 25.4 mm) 72.0)))
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
112
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 (defun gs-set-ghostview-window-prop (frame spec img-width img-height)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 "Set the `GHOSTVIEW' window property of FRAME.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 SPEC is a GS image specification. IMG-WIDTH is the width of the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 requested image, and IMG-HEIGHT is the height of the requested
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 image in pixels."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (let* ((box (plist-get (cdr spec) :bounding-box))
39518
db80e2ff68e8 (gs-set-ghostview-window-prop): Fix args of `elt'.
Gerd Moellmann <gerd@gnu.org>
parents: 39313
diff changeset
120 (llx (elt box 0))
db80e2ff68e8 (gs-set-ghostview-window-prop): Fix args of `elt'.
Gerd Moellmann <gerd@gnu.org>
parents: 39313
diff changeset
121 (lly (elt box 1))
db80e2ff68e8 (gs-set-ghostview-window-prop): Fix args of `elt'.
Gerd Moellmann <gerd@gnu.org>
parents: 39313
diff changeset
122 (urx (elt box 2))
db80e2ff68e8 (gs-set-ghostview-window-prop): Fix args of `elt'.
Gerd Moellmann <gerd@gnu.org>
parents: 39313
diff changeset
123 (ury (elt box 3))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (rotation (or (plist-get (cdr spec) :rotate) 0))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 ;; The pixel width IMG-WIDTH of the pixmap gives the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 ;; dots, URX - LLX give the inch.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (in-width (/ (- urx llx) 72.0))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (in-height (/ (- ury lly) 72.0))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (xdpi (/ img-width in-width))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (ydpi (/ img-height in-height)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (x-change-window-property "GHOSTVIEW"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (format "0 %d %d %d %d %d %g %g"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 rotation llx lly urx ury xdpi ydpi)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 frame)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (defun gs-set-ghostview-colors-window-prop (frame pixel-colors)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 "Set the `GHOSTVIEW_COLORS' environment variable depending on FRAME."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (let ((mode (cond ((x-display-color-p frame) "Color")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 ((x-display-grayscale-p frame) "Grayscale")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (t "Monochrome"))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (x-change-window-property "GHOSTVIEW_COLORS"
38890
a6653fe3cbb9 (gs-set-ghostview-colors-window-prop): Call
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
143 (format "%s %s" mode pixel-colors)
a6653fe3cbb9 (gs-set-ghostview-colors-window-prop): Call
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
144 frame)))
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
145
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 ;
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (defun gs-load-image (frame spec img-width img-height window-and-pixmap-id
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 pixel-colors)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 "Load a PS image for display on FRAME.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 SPEC is an image specification, IMG-HEIGHT and IMG-WIDTH are width
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 and height of the image in pixels. WINDOW-AND-PIXMAP-ID is a string of
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 the form \"WINDOW-ID PIXMAP-ID\". Value is non-nil if successful."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (unwind-protect
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (let ((file (plist-get (cdr spec) :file))
38890
a6653fe3cbb9 (gs-set-ghostview-colors-window-prop): Call
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
157 gs
38997
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
158 (timeout 40))
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
159 ;; Wait while property gets freed from a previous ghostscript process
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
160 ;; sit-for returns nil as soon as input starts being
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
161 ;; available, so if we want to give GhostScript a reasonable
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
162 ;; chance of starting up, we better use sleep-for. We let
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
163 ;; sleep-for wait only half the time because if input is
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
164 ;; available, it is more likely that we don't care that much
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
165 ;; about garbled redisplay and are in a hurry.
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
166 (while (and
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
167 ;; Wait while the property is not yet available
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
168 (not (zerop (length (x-window-property "GHOSTVIEW"
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
169 frame))))
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
170 ;; The following was an alternative condition: wait
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
171 ;; while there is still a process running. The idea
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
172 ;; was to avoid contention between processes. Turned
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
173 ;; out even more sluggish.
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
174 ;; (get-buffer-process "*GS*")
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
175 (not (zerop timeout)))
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
176 (unless (sit-for 0 100 t)
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
177 (sleep-for 0 50))
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
178 (setq timeout (1- timeout)))
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
179
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
180 ;; No use waiting longer. We might want to try killing off
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
181 ;; stuck processes, but there is no point in doing so: either
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
182 ;; they are stuck for good, in which case the user would
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
183 ;; probably be responsible for that, and killing them off will
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
184 ;; make debugging harder, or they are not. In that case, they
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
185 ;; will cause incomplete displays. But the same will happen
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
186 ;; if they are killed, anyway. The whole is rather
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
187 ;; disconcerting, and fast scrolling through a dozen images
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
188 ;; will make Emacs freeze for a while. The alternatives are a)
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
189 ;; proper implementation not waiting at all but creating
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
190 ;; appropriate queues, or b) permanently bad display due to
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
191 ;; bad cached images. So remember that this
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
192 ;; is just a hack and if people don't like the behaviour, they
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
193 ;; will most likely like the easy alternatives even less.
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
194 ;; And at least the image cache will make the delay apparent
751bf57c84a1 (gs-load-image): Use sleep-for.
Gerd Moellmann <gerd@gnu.org>
parents: 38935
diff changeset
195 ;; just once.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (gs-set-ghostview-window-prop frame spec img-width img-height)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (gs-set-ghostview-colors-window-prop frame pixel-colors)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (setenv "GHOSTVIEW" window-and-pixmap-id)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (setq gs (apply 'start-process "gs" "*GS*" gs-program
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (gs-options gs-device file)))
55771
4b9c2c0fbfe1 (gs-load-image): Use `set-process-query-on-exit-flag' instead of
John Paul Wallington <jpw@pobox.com>
parents: 55725
diff changeset
201 (set-process-query-on-exit-flag gs nil)
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 gs)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 nil))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 ;(defun gs-put-tiger ()
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 ; (let* ((ps-file "/usr/local/share/ghostscript/5.10/examples/tiger.ps")
25651
e65a0e39a0a9 Change `ghostscript' to `postscript' in comment.
Gerd Moellmann <gerd@gnu.org>
parents: 25003
diff changeset
208 ; (spec `(image :type postscript
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 ; :pt-width 200 :pt-height 200
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 ; :bounding-box (22 171 567 738)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 ; :file ,ps-file)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 ; (put-text-property 1 2 'display spec)))
35522
9c7789e8882b use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents: 25651
diff changeset
213 ;
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 (provide 'gs)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 39518
diff changeset
217 ;;; arch-tag: 06ab51b8-4932-4cfe-9f60-b924a8edb3f0
38412
253f761ad37b Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents: 35522
diff changeset
218 ;;; gs.el ends here