Mercurial > emacs
annotate lisp/gs.el @ 38720:d2144cf72859
*** empty log message ***
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 07 Aug 2001 13:35:45 +0000 |
parents | 253f761ad37b |
children | a6653fe3cbb9 |
rev | line source |
---|---|
25003 | 1 ;;; gs.el --- interface to Ghostscript |
2 | |
3 ;; Copyright (C) 1998 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: internal | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This code is experimental. Don't use it. | |
28 | |
29 ;;; Code: | |
30 | |
31 (defvar gs-program "gs" | |
32 "The name of the Ghostscript interpreter.") | |
33 | |
34 | |
35 (defvar gs-device "x11" | |
36 "The Ghostscript device to use to produce images.") | |
37 | |
38 | |
35522
9c7789e8882b
use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents:
25651
diff
changeset
|
39 (defvar gs-options |
25003 | 40 '("-q" |
41 ;"-dNOPAUSE" | |
42 "-dBATCH" | |
43 "-sDEVICE=<device>" | |
44 "<file>") | |
45 "List of command line arguments to pass to Ghostscript. | |
46 Arguments may contain place-holders `<file>' for the name of the | |
47 input file, and `<device>' for the device to use.") | |
48 | |
49 (defun gs-options (device file) | |
50 "Return a list of command line options with place-holders replaced. | |
51 DEVICE is the value to substitute for the place-holder `<device>', | |
52 FILE is the value to substitute for the place-holder `<file>'." | |
53 (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
|
54 (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
|
55 option (replace-regexp-in-string "<file>" file option))) |
25003 | 56 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
|
57 |
25003 | 58 |
59 ;; 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
|
60 ;; |
25003 | 61 ;; Type: |
62 ;; | |
63 ;; 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
|
64 ;; |
25003 | 65 ;; 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
|
66 ;; |
25003 | 67 ;; 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
|
68 ;; |
25003 | 69 ;; 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
|
70 ;; |
25003 | 71 ;; 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
|
72 ;; |
25003 | 73 ;; BPIXMAP: pixmap id of the backing pixmap for the window. If no |
74 ;; pixmap is to be used, this parameter should be zero. This | |
75 ;; 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
|
76 ;; |
25003 | 77 ;; ORIENT: orientation of the page. The number represents clockwise |
78 ;; rotation of the paper in degrees. Permitted values are 0, 90, 180, | |
79 ;; 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
|
80 ;; |
25003 | 81 ;; LLX, LLY, URX, URY: Bounding box of the drawable. The bounding box |
82 ;; 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
|
83 ;; |
25003 | 84 ;; XDPI, YDPI: Resolution of window. (This can be derived from the |
85 ;; other parameters, but not without roundoff error. These values are | |
86 ;; 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
|
87 ;; |
25003 | 88 ;; LEFT, BOTTOM, TOP, RIGHT: (optional) Margins around the window. |
89 ;; The margins extend the imageable area beyond the boundaries of the | |
90 ;; window. This is primarily used for popup zoom windows. I have | |
91 ;; encountered several instances of PostScript programs that position | |
92 ;; themselves with respect to the imageable area. The margins are | |
93 ;; specified in PostScript points. If omitted, the margins are | |
94 ;; assumed to be 0. | |
95 | |
96 (defun gs-width-in-pt (frame pixel-width) | |
97 "Return, on FRAME, pixel width PIXEL-WIDTH tranlated to pt." | |
98 (let ((mm (* (float pixel-width) | |
99 (/ (float (x-display-mm-width frame)) | |
100 (float (x-display-pixel-width frame)))))) | |
101 (/ (* 25.4 mm) 72.0))) | |
102 | |
103 | |
104 (defun gs-height-in-pt (frame pixel-height) | |
105 "Return, on FRAME, pixel height PIXEL-HEIGHT tranlated to pt." | |
106 (let ((mm (* (float pixel-height) | |
107 (/ (float (x-display-mm-height frame)) | |
108 (float (x-display-pixel-height frame)))))) | |
109 (/ (* 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
|
110 |
25003 | 111 |
112 (defun gs-set-ghostview-window-prop (frame spec img-width img-height) | |
113 "Set the `GHOSTVIEW' window property of FRAME. | |
114 SPEC is a GS image specification. IMG-WIDTH is the width of the | |
115 requested image, and IMG-HEIGHT is the height of the requested | |
116 image in pixels." | |
117 (let* ((box (plist-get (cdr spec) :bounding-box)) | |
118 (llx (nth 0 box)) | |
119 (lly (nth 1 box)) | |
120 (urx (nth 2 box)) | |
121 (ury (nth 3 box)) | |
122 (rotation (or (plist-get (cdr spec) :rotate) 0)) | |
123 ;; The pixel width IMG-WIDTH of the pixmap gives the | |
124 ;; dots, URX - LLX give the inch. | |
125 (in-width (/ (- urx llx) 72.0)) | |
126 (in-height (/ (- ury lly) 72.0)) | |
127 (xdpi (/ img-width in-width)) | |
128 (ydpi (/ img-height in-height))) | |
129 (x-change-window-property "GHOSTVIEW" | |
130 (format "0 %d %d %d %d %d %g %g" | |
131 rotation llx lly urx ury xdpi ydpi) | |
132 frame))) | |
133 | |
134 | |
135 (defun gs-set-ghostview-colors-window-prop (frame pixel-colors) | |
136 "Set the `GHOSTVIEW_COLORS' environment variable depending on FRAME." | |
137 (let ((mode (cond ((x-display-color-p frame) "Color") | |
138 ((x-display-grayscale-p frame) "Grayscale") | |
139 (t "Monochrome")))) | |
140 (x-change-window-property "GHOSTVIEW_COLORS" | |
141 (format "%s %s" mode pixel-colors)))) | |
35522
9c7789e8882b
use replace-regexps-in-string instead of dired- and gs-replace-in-string
Sam Steingold <sds@gnu.org>
parents:
25651
diff
changeset
|
142 |
25003 | 143 |
144 ; | |
145 ;;;###autoload | |
146 (defun gs-load-image (frame spec img-width img-height window-and-pixmap-id | |
147 pixel-colors) | |
148 "Load a PS image for display on FRAME. | |
149 SPEC is an image specification, IMG-HEIGHT and IMG-WIDTH are width | |
150 and height of the image in pixels. WINDOW-AND-PIXMAP-ID is a string of | |
151 the form \"WINDOW-ID PIXMAP-ID\". Value is non-nil if successful." | |
152 (unwind-protect | |
153 (let ((file (plist-get (cdr spec) :file)) | |
154 gs) | |
155 (gs-set-ghostview-window-prop frame spec img-width img-height) | |
156 (gs-set-ghostview-colors-window-prop frame pixel-colors) | |
157 (setenv "GHOSTVIEW" window-and-pixmap-id) | |
158 (setq gs (apply 'start-process "gs" "*GS*" gs-program | |
159 (gs-options gs-device file))) | |
160 (process-kill-without-query gs) | |
161 gs) | |
162 nil)) | |
163 | |
164 | |
165 ;(defun gs-put-tiger () | |
166 ; (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
|
167 ; (spec `(image :type postscript |
25003 | 168 ; :pt-width 200 :pt-height 200 |
169 ; :bounding-box (22 171 567 738) | |
170 ; :file ,ps-file))) | |
171 ; (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
|
172 ; |
25003 | 173 |
174 (provide 'gs) | |
175 | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
35522
diff
changeset
|
176 ;;; gs.el ends here |