Commit | Line | Data |
---|---|---|
c97a3f22 VJL |
1 | ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print |
2 | ||
fd7ec851 | 3 | ;; Copyright (C) 2007, 2008 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 VJL |
10 | ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre |
11 | ||
12 | ;; This file is part of GNU Emacs. | |
13 | ||
14 | ;; GNU Emacs is free software; you can redistribute it and/or modify it under | |
15 | ;; the terms of the GNU General Public License as published by the Free | |
269a66ee | 16 | ;; Software Foundation; either version 3, or (at your option) any later |
c97a3f22 VJL |
17 | ;; version. |
18 | ||
19 | ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY | |
20 | ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
21 | ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
22 | ;; details. | |
23 | ||
24 | ;; You should have received a copy of the GNU General Public License along with | |
25 | ;; GNU Emacs; see the file COPYING. If not, write to the Free Software | |
26 | ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
27 | ||
28 | ;;; Commentary: | |
29 | ||
30 | ;; See ps-print.el for documentation. | |
31 | ||
32 | ;;; Code: | |
33 | ||
f6bcd65f GM |
34 | (eval-and-compile |
35 | (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))) | |
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 VJL |
52 | |
53 | ||
54 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
55 | ;; ps-bdf | |
56 | ||
d73d5c1c | 57 | (defvar installation-directory nil) |
9e53076e | 58 | (defvar coding-system-for-read) |
c97a3f22 VJL |
59 | |
60 | ||
61 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
62 | ;; ps-mule | |
63 | ||
64 | (defvar leading-code-private-22 157) | |
65 | ||
66 | (or (fboundp 'charset-bytes) | |
67 | (defun charset-bytes (charset) 1)) ; ascii | |
68 | ||
69 | (or (fboundp 'charset-dimension) | |
70 | (defun charset-dimension (charset) 1)) ; ascii | |
71 | ||
72 | (or (fboundp 'charset-id) | |
73 | (defun charset-id (charset) 0)) ; ascii | |
74 | ||
75 | (or (fboundp 'charset-width) | |
76 | (defun charset-width (charset) 1)) ; ascii | |
77 | ||
78 | (or (fboundp 'find-charset-region) | |
79 | (defun find-charset-region (beg end &optional table) | |
80 | (list 'ascii))) | |
81 | ||
82 | (or (fboundp 'char-width) | |
83 | (defun char-width (char) 1)) ; ascii | |
84 | ||
85 | (or (fboundp 'chars-in-region) | |
86 | (defun chars-in-region (beg end) | |
87 | (- (max beg end) (min beg end)))) | |
88 | ||
89 | (or (fboundp 'forward-point) | |
90 | (defun forward-point (arg) | |
91 | (save-excursion | |
92 | (let ((count (abs arg)) | |
93 | (step (if (zerop arg) | |
94 | 0 | |
95 | (/ arg arg)))) | |
96 | (while (and (> count 0) | |
97 | (< (point-min) (point)) (< (point) (point-max))) | |
98 | (forward-char step) | |
99 | (setq count (1- count))) | |
100 | (+ (point) (* count step)))))) | |
101 | ||
102 | (or (fboundp 'decompose-composite-char) | |
103 | (defun decompose-composite-char (char &optional type | |
104 | with-composition-rule) | |
105 | nil)) | |
106 | ||
107 | (or (fboundp 'encode-coding-string) | |
108 | (defun encode-coding-string (string coding-system &optional nocopy) | |
109 | (if nocopy | |
110 | string | |
111 | (copy-sequence string)))) | |
112 | ||
113 | (or (fboundp 'coding-system-p) | |
114 | (defun coding-system-p (obj) nil)) | |
115 | ||
116 | (or (fboundp 'ccl-execute-on-string) | |
117 | (defun ccl-execute-on-string (ccl-prog status str | |
118 | &optional contin unibyte-p) | |
119 | str)) | |
120 | ||
121 | (or (fboundp 'define-ccl-program) | |
122 | (defmacro define-ccl-program (name ccl-program &optional doc) | |
123 | `(defconst ,name nil ,doc))) | |
124 | ||
125 | (or (fboundp 'multibyte-string-p) | |
126 | (defun multibyte-string-p (str) | |
127 | (let ((len (length str)) | |
128 | (i 0) | |
129 | multibyte) | |
130 | (while (and (< i len) (not (setq multibyte (> (aref str i) 255)))) | |
131 | (setq i (1+ i))) | |
132 | multibyte))) | |
133 | ||
134 | (or (fboundp 'string-make-multibyte) | |
135 | (defalias 'string-make-multibyte 'copy-sequence)) | |
136 | ||
137 | (or (fboundp 'encode-char) | |
138 | (defun encode-char (ch ccs) | |
139 | ch)) | |
140 | ||
141 | ||
142 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
143 | ;; ps-print | |
144 | ||
145 | ;; GNU Emacs | |
146 | (or (fboundp 'line-beginning-position) | |
147 | (defun line-beginning-position (&optional n) | |
148 | (save-excursion | |
149 | (and n (/= n 1) (forward-line (1- n))) | |
150 | (beginning-of-line) | |
151 | (point)))) | |
152 | ||
153 | ||
154 | ;; GNU Emacs | |
155 | (or (fboundp 'find-composition) | |
156 | (defalias 'find-composition 'ignore)) | |
157 | ||
158 | ||
159 | (defun ps-xemacs-color-name (color) | |
160 | (if (color-specifier-p color) | |
161 | (color-name color) | |
162 | color)) | |
163 | ||
164 | ||
165 | (defalias 'ps-mark-active-p 'region-active-p) | |
166 | ||
167 | ||
168 | (defun ps-face-foreground-name (face) | |
169 | (ps-xemacs-color-name (face-foreground face))) | |
170 | ||
171 | ||
172 | (defun ps-face-background-name (face) | |
173 | (ps-xemacs-color-name (face-background face))) | |
174 | ||
175 | ||
9e53076e | 176 | (defalias 'ps-frame-parameter 'frame-property) |
c97a3f22 VJL |
177 | |
178 | ||
179 | ;; Return t if the device (which can be changed during an emacs session) | |
180 | ;; can handle colors. | |
037f214b GM |
181 | (defun ps-color-device () |
182 | (eq (device-class) 'color)) | |
c97a3f22 VJL |
183 | |
184 | (defun ps-mapper (extent list) | |
185 | (nconc list | |
186 | (list (list (extent-start-position extent) 'push extent) | |
187 | (list (extent-end-position extent) 'pull extent))) | |
188 | nil) | |
189 | ||
190 | ||
191 | (defun ps-extent-sorter (a b) | |
192 | (< (extent-priority a) (extent-priority b))) | |
193 | ||
194 | ||
195 | (defun ps-xemacs-face-kind-p (face kind kind-regex) | |
196 | (let* ((frame-font (or (face-font-instance face) | |
197 | (face-font-instance 'default))) | |
198 | (kind-cons | |
199 | (and frame-font | |
200 | (assq kind | |
201 | (font-instance-properties frame-font)))) | |
202 | (kind-spec (cdr-safe kind-cons)) | |
203 | (case-fold-search t)) | |
204 | (and kind-spec (string-match kind-regex kind-spec)))) | |
205 | ||
206 | ||
207 | ;; to avoid XEmacs compilation gripes | |
9e53076e | 208 | (defvar coding-system-for-write) |
9e53076e | 209 | (defvar buffer-file-coding-system) |
c97a3f22 VJL |
210 | |
211 | ||
212 | (and (fboundp 'find-coding-system) | |
213 | (or (funcall 'find-coding-system 'raw-text-unix) | |
214 | (funcall 'copy-coding-system 'no-conversion-unix 'raw-text-unix))) | |
215 | ||
216 | ||
217 | (defun ps-color-values (x-color) | |
218 | (let ((color (ps-xemacs-color-name x-color))) | |
219 | (cond | |
220 | ((fboundp 'x-color-values) | |
221 | (funcall 'x-color-values color)) | |
222 | ((and (fboundp 'color-instance-rgb-components) | |
223 | (ps-color-device)) | |
224 | (funcall 'color-instance-rgb-components | |
225 | (if (color-instance-p x-color) | |
226 | x-color | |
227 | (make-color-instance color)))) | |
228 | (t | |
229 | (error "No available function to determine X color values"))))) | |
230 | ||
231 | ||
232 | (defun ps-face-bold-p (face) | |
233 | (or (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold") | |
234 | (memq face ps-bold-faces))) ; Kludge-compatible | |
235 | ||
236 | ||
237 | (defun ps-face-italic-p (face) | |
238 | (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o") | |
239 | (ps-xemacs-face-kind-p face 'SLANT "i\\|o") | |
240 | (memq face ps-italic-faces))) ; Kludge-compatible | |
241 | ||
242 | ||
fd7ec851 VJL |
243 | (defalias 'ps-face-strikeout-p 'ignore) |
244 | ||
245 | ||
246 | (defalias 'ps-face-overline-p 'ignore) | |
247 | ||
248 | ||
249 | (defalias 'ps-face-box-p 'ignore) | |
250 | ||
251 | ||
c97a3f22 VJL |
252 | ;; XEmacs will have to make do with %s (princ) for floats. |
253 | (defvar ps-color-format "%s %s %s") | |
254 | (defvar ps-float-format "%s ") | |
255 | ||
256 | ||
257 | (defun ps-generate-postscript-with-faces1 (from to) | |
258 | ;; Generate some PostScript. | |
259 | (let ((face 'default) | |
260 | (position to) | |
261 | ;; XEmacs | |
262 | ;; Build the list of extents... | |
263 | (a (cons 'dummy nil)) | |
264 | record type extent extent-list) | |
265 | (map-extents 'ps-mapper nil from to a) | |
266 | (setq a (sort (cdr a) 'car-less-than-car) | |
267 | extent-list nil) | |
268 | ||
269 | ;; Loop through the extents... | |
270 | (while a | |
271 | (setq record (car a) | |
272 | position (car record) | |
273 | ||
274 | record (cdr record) | |
275 | type (car record) | |
276 | ||
277 | record (cdr record) | |
278 | extent (car record)) | |
279 | ||
280 | ;; Plot up to this record. | |
281 | ;; XEmacs 19.12: for some reason, we're getting into a | |
282 | ;; situation in which some of the records have | |
283 | ;; positions less than 'from'. Since we've narrowed | |
284 | ;; the buffer, this'll generate errors. This is a hack, | |
285 | ;; but don't call ps-plot-with-face unless from > point-min. | |
286 | (and (>= from (point-min)) | |
287 | (ps-plot-with-face from (min position (point-max)) face)) | |
288 | ||
289 | (cond | |
290 | ((eq type 'push) | |
291 | (and (extent-face extent) | |
292 | (setq extent-list (sort (cons extent extent-list) | |
293 | 'ps-extent-sorter)))) | |
294 | ||
295 | ((eq type 'pull) | |
296 | (setq extent-list (sort (delq extent extent-list) | |
297 | 'ps-extent-sorter)))) | |
298 | ||
299 | (setq face (if extent-list | |
300 | (extent-face (car extent-list)) | |
301 | 'default) | |
302 | from position | |
303 | a (cdr a))) | |
304 | ||
305 | (ps-plot-with-face from to face))) | |
306 | ||
307 | ) | |
9e53076e | 308 | (t ; Emacs |
c97a3f22 VJL |
309 | ;; Do nothing |
310 | )) ; end cond featurep | |
311 | ||
312 | ||
313 | \f | |
314 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
315 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
316 | ;; Emacs Definitions | |
317 | ||
318 | ||
319 | (cond | |
9e53076e | 320 | ((featurep 'xemacs) ; XEmacs |
c97a3f22 VJL |
321 | ;; Do nothing |
322 | ) | |
9e53076e | 323 | (t ; Emacs |
c97a3f22 VJL |
324 | |
325 | ||
326 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
327 | ;; ps-print | |
328 | ||
c97a3f22 VJL |
329 | |
330 | (defun ps-mark-active-p () | |
331 | mark-active) | |
332 | ||
333 | ||
334 | (defun ps-face-foreground-name (face) | |
335 | (face-foreground face nil t)) | |
336 | ||
337 | ||
338 | (defun ps-face-background-name (face) | |
339 | (face-background face nil t)) | |
340 | ||
341 | ||
9e53076e | 342 | (defalias 'ps-frame-parameter 'frame-parameter) |
c97a3f22 VJL |
343 | |
344 | ||
345 | ;; Return t if the device (which can be changed during an emacs session) can | |
346 | ;; handle colors. This function is not yet implemented for GNU emacs. | |
347 | (defun ps-color-device () | |
348 | (if (fboundp 'color-values) | |
349 | (funcall 'color-values "Green") | |
350 | t)) | |
351 | ||
352 | ||
353 | (defun ps-color-values (x-color) | |
354 | (cond | |
355 | ((fboundp 'color-values) | |
356 | (funcall 'color-values x-color)) | |
357 | ((fboundp 'x-color-values) | |
358 | (funcall 'x-color-values x-color)) | |
359 | (t | |
360 | (error "No available function to determine X color values")))) | |
361 | ||
362 | ||
363 | (defun ps-face-bold-p (face) | |
364 | (or (face-bold-p face) | |
365 | (memq face ps-bold-faces))) | |
366 | ||
367 | ||
368 | (defun ps-face-italic-p (face) | |
369 | (or (face-italic-p face) | |
370 | (memq face ps-italic-faces))) | |
371 | ||
372 | ||
fd7ec851 VJL |
373 | (defun ps-face-strikeout-p (face) |
374 | (eq (face-attribute face :strike-through) t)) | |
375 | ||
376 | ||
377 | (defun ps-face-overline-p (face) | |
378 | (eq (face-attribute face :overline) t)) | |
379 | ||
380 | ||
381 | (defun ps-face-box-p (face) | |
382 | (not (memq (face-attribute face :box) '(nil unspecified)))) | |
383 | ||
384 | ||
c97a3f22 VJL |
385 | ;; Emacs understands the %f format; we'll use it to limit color RGB values |
386 | ;; to three decimals to cut down some on the size of the PostScript output. | |
387 | (defvar ps-color-format "%0.3f %0.3f %0.3f") | |
388 | (defvar ps-float-format "%0.3f ") | |
389 | ||
390 | ||
391 | (defun ps-generate-postscript-with-faces1 (from to) | |
392 | ;; Generate some PostScript. | |
393 | (let ((face 'default) | |
394 | (position to) | |
395 | ;; Emacs | |
396 | (property-change from) | |
397 | (overlay-change from) | |
398 | (save-buffer-invisibility-spec buffer-invisibility-spec) | |
399 | (buffer-invisibility-spec nil) | |
400 | before-string after-string) | |
401 | (while (< from to) | |
402 | (and (< property-change to) ; Don't search for property change | |
403 | ; unless previous search succeeded. | |
404 | (setq property-change (next-property-change from nil to))) | |
405 | (and (< overlay-change to) ; Don't search for overlay change | |
406 | ; unless previous search succeeded. | |
407 | (setq overlay-change (min (next-overlay-change from) | |
408 | to))) | |
409 | (setq position (min property-change overlay-change) | |
410 | before-string nil | |
411 | after-string nil) | |
412 | ;; The code below is not quite correct, | |
413 | ;; because a non-nil overlay invisible property | |
414 | ;; which is inactive according to the current value | |
415 | ;; of buffer-invisibility-spec nonetheless overrides | |
416 | ;; a face text property. | |
417 | (setq face | |
418 | (cond ((let ((prop (get-text-property from 'invisible))) | |
419 | ;; Decide whether this invisible property | |
420 | ;; really makes the text invisible. | |
421 | (if (eq save-buffer-invisibility-spec t) | |
422 | (not (null prop)) | |
423 | (or (memq prop save-buffer-invisibility-spec) | |
424 | (assq prop save-buffer-invisibility-spec)))) | |
425 | 'emacs--invisible--face) | |
426 | ((get-text-property from 'face)) | |
427 | (t 'default))) | |
428 | (let ((overlays (overlays-at from)) | |
429 | (face-priority -1)) ; text-property | |
430 | (while (and overlays | |
431 | (not (eq face 'emacs--invisible--face))) | |
432 | (let* ((overlay (car overlays)) | |
433 | (overlay-invisible | |
434 | (overlay-get overlay 'invisible)) | |
435 | (overlay-priority | |
436 | (or (overlay-get overlay 'priority) 0))) | |
437 | (and (> overlay-priority face-priority) | |
438 | (setq before-string | |
439 | (or (overlay-get overlay 'before-string) | |
440 | before-string) | |
441 | after-string | |
442 | (or (and (<= (overlay-end overlay) position) | |
443 | (overlay-get overlay 'after-string)) | |
444 | after-string) | |
445 | face-priority overlay-priority | |
446 | face | |
447 | (cond | |
448 | ((if (eq save-buffer-invisibility-spec t) | |
449 | (not (null overlay-invisible)) | |
450 | (or (memq overlay-invisible | |
451 | save-buffer-invisibility-spec) | |
452 | (assq overlay-invisible | |
453 | save-buffer-invisibility-spec))) | |
454 | 'emacs--invisible--face) | |
455 | ((overlay-get overlay 'face)) | |
456 | (t face) | |
457 | )))) | |
458 | (setq overlays (cdr overlays)))) | |
459 | ;; Plot up to this record. | |
460 | (and before-string | |
461 | (ps-plot-string before-string)) | |
462 | (ps-plot-with-face from position face) | |
463 | (and after-string | |
464 | (ps-plot-string after-string)) | |
465 | (setq from position)) | |
466 | (ps-plot-with-face from to face))) | |
467 | ||
468 | )) ; end cond featurep | |
469 | ||
470 | \f | |
471 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
472 | ||
473 | (provide 'ps-def) | |
474 | ||
3fb6f73a | 475 | ;; arch-tag: 4edde45b-af10-4685-b8ee-7cd0f951095a |
c97a3f22 | 476 | ;;; ps-def.el ends here |