Commit | Line | Data |
---|---|---|
c97a3f22 VJL |
1 | ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2007-2014 Free Software Foundation, Inc. |
c97a3f22 VJL |
4 | |
5 | ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> | |
6 | ;; Kenichi Handa <handa@m17n.org> (multi-byte characters) | |
7 | ;; Maintainer: Kenichi Handa <handa@m17n.org> (multi-byte characters) | |
8 | ;; Vinicius Jose Latorre <viniciusjl@ig.com.br> | |
9 | ;; Keywords: wp, print, PostScript | |
c97a3f22 | 10 | ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre |
bd78fa1d | 11 | ;; Package: ps-print |
c97a3f22 VJL |
12 | |
13 | ;; This file is part of GNU Emacs. | |
14 | ||
eb3fa2cf GM |
15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
16 | ;; it under the terms of the GNU General Public License as published by | |
17 | ;; the Free Software Foundation, either version 3 of the License, or | |
18 | ;; (at your option) any later version. | |
19 | ||
20 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
c97a3f22 VJL |
27 | |
28 | ;;; Commentary: | |
29 | ||
30 | ;; See ps-print.el for documentation. | |
31 | ||
32 | ;;; Code: | |
33 | ||
f6bcd65f | 34 | (eval-and-compile |
06b60517 | 35 | (unless (fboundp 'declare-function) (defmacro declare-function (&rest _r)))) |
f6bcd65f GM |
36 | |
37 | (declare-function ps-plot-with-face "ps-print" (from to face)) | |
38 | (declare-function ps-plot-string "ps-print" (string)) | |
39 | ||
40 | (defvar ps-bold-faces) ; in ps-print.el | |
41 | (defvar ps-italic-faces) | |
42 | ||
c97a3f22 VJL |
43 | |
44 | \f | |
45 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
46 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
47 | ;; XEmacs Definitions | |
48 | ||
49 | ||
50 | (cond | |
9e53076e | 51 | ((featurep 'xemacs) ; XEmacs |
c97a3f22 | 52 | |
c97a3f22 VJL |
53 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
54 | ;; ps-bdf | |
55 | ||
d73d5c1c | 56 | (defvar installation-directory nil) |
9e53076e | 57 | (defvar coding-system-for-read) |
c97a3f22 | 58 | |
c97a3f22 VJL |
59 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
60 | ;; ps-mule | |
61 | ||
c97a3f22 | 62 | (or (fboundp 'charset-dimension) |
06b60517 | 63 | (defun charset-dimension (_charset) 1)) ; ascii |
c97a3f22 | 64 | |
c97a3f22 | 65 | (or (fboundp 'char-width) |
06b60517 | 66 | (defun char-width (_char) 1)) ; ascii |
c97a3f22 | 67 | |
c97a3f22 | 68 | (or (fboundp 'encode-char) |
06b60517 | 69 | (defun encode-char (ch _ccs) |
c97a3f22 VJL |
70 | ch)) |
71 | ||
c97a3f22 VJL |
72 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
73 | ;; ps-print | |
74 | ||
75 | ;; GNU Emacs | |
76 | (or (fboundp 'line-beginning-position) | |
77 | (defun line-beginning-position (&optional n) | |
78 | (save-excursion | |
79 | (and n (/= n 1) (forward-line (1- n))) | |
80 | (beginning-of-line) | |
81 | (point)))) | |
82 | ||
83 | ||
84 | ;; GNU Emacs | |
85 | (or (fboundp 'find-composition) | |
86 | (defalias 'find-composition 'ignore)) | |
87 | ||
88 | ||
89 | (defun ps-xemacs-color-name (color) | |
90 | (if (color-specifier-p color) | |
91 | (color-name color) | |
92 | color)) | |
93 | ||
94 | ||
95 | (defalias 'ps-mark-active-p 'region-active-p) | |
96 | ||
97 | ||
98 | (defun ps-face-foreground-name (face) | |
99 | (ps-xemacs-color-name (face-foreground face))) | |
100 | ||
101 | ||
102 | (defun ps-face-background-name (face) | |
103 | (ps-xemacs-color-name (face-background face))) | |
104 | ||
105 | ||
9e53076e | 106 | (defalias 'ps-frame-parameter 'frame-property) |
c97a3f22 VJL |
107 | |
108 | ||
109 | ;; Return t if the device (which can be changed during an emacs session) | |
110 | ;; can handle colors. | |
037f214b GM |
111 | (defun ps-color-device () |
112 | (eq (device-class) 'color)) | |
c97a3f22 VJL |
113 | |
114 | (defun ps-mapper (extent list) | |
115 | (nconc list | |
116 | (list (list (extent-start-position extent) 'push extent) | |
117 | (list (extent-end-position extent) 'pull extent))) | |
118 | nil) | |
119 | ||
120 | ||
121 | (defun ps-extent-sorter (a b) | |
122 | (< (extent-priority a) (extent-priority b))) | |
123 | ||
124 | ||
125 | (defun ps-xemacs-face-kind-p (face kind kind-regex) | |
126 | (let* ((frame-font (or (face-font-instance face) | |
127 | (face-font-instance 'default))) | |
128 | (kind-cons | |
129 | (and frame-font | |
130 | (assq kind | |
131 | (font-instance-properties frame-font)))) | |
132 | (kind-spec (cdr-safe kind-cons)) | |
133 | (case-fold-search t)) | |
134 | (and kind-spec (string-match kind-regex kind-spec)))) | |
135 | ||
136 | ||
137 | ;; to avoid XEmacs compilation gripes | |
9e53076e | 138 | (defvar coding-system-for-write) |
9e53076e | 139 | (defvar buffer-file-coding-system) |
c97a3f22 VJL |
140 | |
141 | ||
142 | (and (fboundp 'find-coding-system) | |
143 | (or (funcall 'find-coding-system 'raw-text-unix) | |
144 | (funcall 'copy-coding-system 'no-conversion-unix 'raw-text-unix))) | |
145 | ||
146 | ||
147 | (defun ps-color-values (x-color) | |
148 | (let ((color (ps-xemacs-color-name x-color))) | |
149 | (cond | |
150 | ((fboundp 'x-color-values) | |
151 | (funcall 'x-color-values color)) | |
152 | ((and (fboundp 'color-instance-rgb-components) | |
153 | (ps-color-device)) | |
154 | (funcall 'color-instance-rgb-components | |
155 | (if (color-instance-p x-color) | |
156 | x-color | |
157 | (make-color-instance color)))) | |
158 | (t | |
159 | (error "No available function to determine X color values"))))) | |
160 | ||
161 | ||
162 | (defun ps-face-bold-p (face) | |
163 | (or (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold") | |
164 | (memq face ps-bold-faces))) ; Kludge-compatible | |
165 | ||
166 | ||
167 | (defun ps-face-italic-p (face) | |
168 | (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o") | |
169 | (ps-xemacs-face-kind-p face 'SLANT "i\\|o") | |
170 | (memq face ps-italic-faces))) ; Kludge-compatible | |
171 | ||
172 | ||
fd7ec851 VJL |
173 | (defalias 'ps-face-strikeout-p 'ignore) |
174 | ||
175 | ||
176 | (defalias 'ps-face-overline-p 'ignore) | |
177 | ||
178 | ||
179 | (defalias 'ps-face-box-p 'ignore) | |
180 | ||
181 | ||
c97a3f22 VJL |
182 | ;; XEmacs will have to make do with %s (princ) for floats. |
183 | (defvar ps-color-format "%s %s %s") | |
184 | (defvar ps-float-format "%s ") | |
185 | ||
186 | ||
187 | (defun ps-generate-postscript-with-faces1 (from to) | |
188 | ;; Generate some PostScript. | |
189 | (let ((face 'default) | |
190 | (position to) | |
191 | ;; XEmacs | |
192 | ;; Build the list of extents... | |
193 | (a (cons 'dummy nil)) | |
194 | record type extent extent-list) | |
195 | (map-extents 'ps-mapper nil from to a) | |
196 | (setq a (sort (cdr a) 'car-less-than-car) | |
197 | extent-list nil) | |
198 | ||
199 | ;; Loop through the extents... | |
200 | (while a | |
201 | (setq record (car a) | |
202 | position (car record) | |
203 | ||
204 | record (cdr record) | |
205 | type (car record) | |
206 | ||
207 | record (cdr record) | |
208 | extent (car record)) | |
209 | ||
210 | ;; Plot up to this record. | |
211 | ;; XEmacs 19.12: for some reason, we're getting into a | |
212 | ;; situation in which some of the records have | |
213 | ;; positions less than 'from'. Since we've narrowed | |
214 | ;; the buffer, this'll generate errors. This is a hack, | |
215 | ;; but don't call ps-plot-with-face unless from > point-min. | |
216 | (and (>= from (point-min)) | |
217 | (ps-plot-with-face from (min position (point-max)) face)) | |
218 | ||
219 | (cond | |
220 | ((eq type 'push) | |
221 | (and (extent-face extent) | |
222 | (setq extent-list (sort (cons extent extent-list) | |
223 | 'ps-extent-sorter)))) | |
224 | ||
225 | ((eq type 'pull) | |
226 | (setq extent-list (sort (delq extent extent-list) | |
227 | 'ps-extent-sorter)))) | |
228 | ||
229 | (setq face (if extent-list | |
230 | (extent-face (car extent-list)) | |
231 | 'default) | |
232 | from position | |
233 | a (cdr a))) | |
234 | ||
235 | (ps-plot-with-face from to face))) | |
236 | ||
237 | ) | |
9e53076e | 238 | (t ; Emacs |
c97a3f22 VJL |
239 | ;; Do nothing |
240 | )) ; end cond featurep | |
241 | ||
242 | ||
243 | \f | |
244 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
245 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
246 | ;; Emacs Definitions | |
247 | ||
248 | ||
249 | (cond | |
9e53076e | 250 | ((featurep 'xemacs) ; XEmacs |
c97a3f22 VJL |
251 | ;; Do nothing |
252 | ) | |
9e53076e | 253 | (t ; Emacs |
c97a3f22 VJL |
254 | |
255 | ||
256 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
257 | ;; ps-print | |
258 | ||
c97a3f22 VJL |
259 | |
260 | (defun ps-mark-active-p () | |
261 | mark-active) | |
262 | ||
263 | ||
264 | (defun ps-face-foreground-name (face) | |
265 | (face-foreground face nil t)) | |
266 | ||
267 | ||
268 | (defun ps-face-background-name (face) | |
269 | (face-background face nil t)) | |
270 | ||
271 | ||
9e53076e | 272 | (defalias 'ps-frame-parameter 'frame-parameter) |
c97a3f22 VJL |
273 | |
274 | ||
275 | ;; Return t if the device (which can be changed during an emacs session) can | |
276 | ;; handle colors. This function is not yet implemented for GNU emacs. | |
277 | (defun ps-color-device () | |
278 | (if (fboundp 'color-values) | |
279 | (funcall 'color-values "Green") | |
280 | t)) | |
281 | ||
282 | ||
283 | (defun ps-color-values (x-color) | |
284 | (cond | |
285 | ((fboundp 'color-values) | |
286 | (funcall 'color-values x-color)) | |
287 | ((fboundp 'x-color-values) | |
288 | (funcall 'x-color-values x-color)) | |
289 | (t | |
290 | (error "No available function to determine X color values")))) | |
291 | ||
292 | ||
293 | (defun ps-face-bold-p (face) | |
294 | (or (face-bold-p face) | |
295 | (memq face ps-bold-faces))) | |
296 | ||
297 | ||
298 | (defun ps-face-italic-p (face) | |
299 | (or (face-italic-p face) | |
300 | (memq face ps-italic-faces))) | |
301 | ||
302 | ||
fd7ec851 VJL |
303 | (defun ps-face-strikeout-p (face) |
304 | (eq (face-attribute face :strike-through) t)) | |
305 | ||
306 | ||
307 | (defun ps-face-overline-p (face) | |
308 | (eq (face-attribute face :overline) t)) | |
309 | ||
310 | ||
311 | (defun ps-face-box-p (face) | |
312 | (not (memq (face-attribute face :box) '(nil unspecified)))) | |
313 | ||
314 | ||
c97a3f22 VJL |
315 | ;; Emacs understands the %f format; we'll use it to limit color RGB values |
316 | ;; to three decimals to cut down some on the size of the PostScript output. | |
317 | (defvar ps-color-format "%0.3f %0.3f %0.3f") | |
318 | (defvar ps-float-format "%0.3f ") | |
319 | ||
320 | ||
321 | (defun ps-generate-postscript-with-faces1 (from to) | |
322 | ;; Generate some PostScript. | |
323 | (let ((face 'default) | |
324 | (position to) | |
325 | ;; Emacs | |
326 | (property-change from) | |
327 | (overlay-change from) | |
328 | (save-buffer-invisibility-spec buffer-invisibility-spec) | |
329 | (buffer-invisibility-spec nil) | |
330 | before-string after-string) | |
331 | (while (< from to) | |
332 | (and (< property-change to) ; Don't search for property change | |
333 | ; unless previous search succeeded. | |
334 | (setq property-change (next-property-change from nil to))) | |
335 | (and (< overlay-change to) ; Don't search for overlay change | |
336 | ; unless previous search succeeded. | |
337 | (setq overlay-change (min (next-overlay-change from) | |
338 | to))) | |
339 | (setq position (min property-change overlay-change) | |
340 | before-string nil | |
341 | after-string nil) | |
c97a3f22 | 342 | (setq face |
20fa59a0 | 343 | (cond ((invisible-p from) |
c97a3f22 | 344 | 'emacs--invisible--face) |
20fa59a0 | 345 | ((get-char-property from 'face)) |
c97a3f22 | 346 | (t 'default))) |
c97a3f22 VJL |
347 | ;; Plot up to this record. |
348 | (and before-string | |
349 | (ps-plot-string before-string)) | |
350 | (ps-plot-with-face from position face) | |
351 | (and after-string | |
352 | (ps-plot-string after-string)) | |
353 | (setq from position)) | |
354 | (ps-plot-with-face from to face))) | |
355 | ||
356 | )) ; end cond featurep | |
357 | ||
358 | \f | |
359 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
360 | ||
361 | (provide 'ps-def) | |
362 | ||
c97a3f22 | 363 | ;;; ps-def.el ends here |