1 ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print
3 ;; Copyright (C) 2007 Free Software Foundation, Inc.
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
11 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify it under
16 ;; the terms of the GNU General Public License as published by the Free
17 ;; Software Foundation; either version 2, or (at your option) any later
20 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY
21 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
25 ;; You should have received a copy of the GNU General Public License along with
26 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software
27 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 ;; See ps-print.el for documentation.
37 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ((featurep 'xemacs
) ; XEmacs
46 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 (defvar installation-directory nil
)
50 (defvar coding-system-for-read
)
53 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 (defvar leading-code-private-22
157)
58 (or (fboundp 'charset-bytes
)
59 (defun charset-bytes (charset) 1)) ; ascii
61 (or (fboundp 'charset-dimension
)
62 (defun charset-dimension (charset) 1)) ; ascii
64 (or (fboundp 'charset-id
)
65 (defun charset-id (charset) 0)) ; ascii
67 (or (fboundp 'charset-width
)
68 (defun charset-width (charset) 1)) ; ascii
70 (or (fboundp 'find-charset-region
)
71 (defun find-charset-region (beg end
&optional table
)
74 (or (fboundp 'char-width
)
75 (defun char-width (char) 1)) ; ascii
77 (or (fboundp 'chars-in-region
)
78 (defun chars-in-region (beg end
)
79 (- (max beg end
) (min beg end
))))
81 (or (fboundp 'forward-point
)
82 (defun forward-point (arg)
84 (let ((count (abs arg
))
88 (while (and (> count
0)
89 (< (point-min) (point)) (< (point) (point-max)))
91 (setq count
(1- count
)))
92 (+ (point) (* count step
))))))
94 (or (fboundp 'decompose-composite-char
)
95 (defun decompose-composite-char (char &optional type
96 with-composition-rule
)
99 (or (fboundp 'encode-coding-string
)
100 (defun encode-coding-string (string coding-system
&optional nocopy
)
103 (copy-sequence string
))))
105 (or (fboundp 'coding-system-p
)
106 (defun coding-system-p (obj) nil
))
108 (or (fboundp 'ccl-execute-on-string
)
109 (defun ccl-execute-on-string (ccl-prog status str
110 &optional contin unibyte-p
)
113 (or (fboundp 'define-ccl-program
)
114 (defmacro define-ccl-program
(name ccl-program
&optional doc
)
115 `(defconst ,name nil
,doc
)))
117 (or (fboundp 'multibyte-string-p
)
118 (defun multibyte-string-p (str)
119 (let ((len (length str
))
122 (while (and (< i len
) (not (setq multibyte
(> (aref str i
) 255))))
126 (or (fboundp 'string-make-multibyte
)
127 (defalias 'string-make-multibyte
'copy-sequence
))
129 (or (fboundp 'encode-char
)
130 (defun encode-char (ch ccs
)
134 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 (or (fboundp 'line-beginning-position
)
139 (defun line-beginning-position (&optional n
)
141 (and n
(/= n
1) (forward-line (1- n
)))
147 (or (fboundp 'find-composition
)
148 (defalias 'find-composition
'ignore
))
151 (defun ps-xemacs-color-name (color)
152 (if (color-specifier-p color
)
157 (defalias 'ps-mark-active-p
'region-active-p
)
160 (defun ps-face-foreground-name (face)
161 (ps-xemacs-color-name (face-foreground face
)))
164 (defun ps-face-background-name (face)
165 (ps-xemacs-color-name (face-background face
)))
168 (defalias 'ps-frame-parameter
'frame-property
)
171 ;; Return t if the device (which can be changed during an emacs session)
172 ;; can handle colors.
173 ;; XEmacs change: Need to check for emacs-major-version too.
174 (if (or (> emacs-major-version
19)
175 (and (= emacs-major-version
19)
176 (>= emacs-minor-version
12)))
178 (defun ps-color-device ()
179 (eq (device-class) 'color
))
181 (setq ps-print-color-p nil
)
182 (defalias 'ps-color-device
'ignore
))
185 (defun ps-mapper (extent list
)
187 (list (list (extent-start-position extent
) 'push extent
)
188 (list (extent-end-position extent
) 'pull extent
)))
192 (defun ps-extent-sorter (a b
)
193 (< (extent-priority a
) (extent-priority b
)))
196 (defun ps-xemacs-face-kind-p (face kind kind-regex
)
197 (let* ((frame-font (or (face-font-instance face
)
198 (face-font-instance 'default
)))
202 (font-instance-properties frame-font
))))
203 (kind-spec (cdr-safe kind-cons
))
204 (case-fold-search t
))
205 (and kind-spec
(string-match kind-regex kind-spec
))))
208 ;; to avoid XEmacs compilation gripes
209 (defvar coding-system-for-write
)
210 (defvar buffer-file-coding-system
)
213 (and (fboundp 'find-coding-system
)
214 (or (funcall 'find-coding-system
'raw-text-unix
)
215 (funcall 'copy-coding-system
'no-conversion-unix
'raw-text-unix
)))
218 (defun ps-color-values (x-color)
219 (let ((color (ps-xemacs-color-name x-color
)))
221 ((fboundp 'x-color-values
)
222 (funcall 'x-color-values color
))
223 ((and (fboundp 'color-instance-rgb-components
)
225 (funcall 'color-instance-rgb-components
226 (if (color-instance-p x-color
)
228 (make-color-instance color
))))
230 (error "No available function to determine X color values")))))
233 (defun ps-face-bold-p (face)
234 (or (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold")
235 (memq face ps-bold-faces
))) ; Kludge-compatible
238 (defun ps-face-italic-p (face)
239 (or (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o")
240 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o")
241 (memq face ps-italic-faces
))) ; Kludge-compatible
244 ;; XEmacs will have to make do with %s (princ) for floats.
245 (defvar ps-color-format
"%s %s %s")
246 (defvar ps-float-format
"%s ")
249 (defun ps-generate-postscript-with-faces1 (from to
)
250 ;; Generate some PostScript.
251 (let ((face 'default
)
254 ;; Build the list of extents...
255 (a (cons 'dummy nil
))
256 record type extent extent-list
)
257 (map-extents 'ps-mapper nil from to a
)
258 (setq a
(sort (cdr a
) 'car-less-than-car
)
261 ;; Loop through the extents...
264 position
(car record
)
272 ;; Plot up to this record.
273 ;; XEmacs 19.12: for some reason, we're getting into a
274 ;; situation in which some of the records have
275 ;; positions less than 'from'. Since we've narrowed
276 ;; the buffer, this'll generate errors. This is a hack,
277 ;; but don't call ps-plot-with-face unless from > point-min.
278 (and (>= from
(point-min))
279 (ps-plot-with-face from
(min position
(point-max)) face
))
283 (and (extent-face extent
)
284 (setq extent-list
(sort (cons extent extent-list
)
285 'ps-extent-sorter
))))
288 (setq extent-list
(sort (delq extent extent-list
)
289 'ps-extent-sorter
))))
291 (setq face
(if extent-list
292 (extent-face (car extent-list
))
297 (ps-plot-with-face from to face
)))
302 )) ; end cond featurep
306 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
307 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
312 ((featurep 'xemacs
) ; XEmacs
318 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322 (defun ps-mark-active-p ()
326 (defun ps-face-foreground-name (face)
327 (face-foreground face nil t
))
330 (defun ps-face-background-name (face)
331 (face-background face nil t
))
334 (defalias 'ps-frame-parameter
'frame-parameter
)
337 ;; Return t if the device (which can be changed during an emacs session) can
338 ;; handle colors. This function is not yet implemented for GNU emacs.
339 (defun ps-color-device ()
340 (if (fboundp 'color-values
)
341 (funcall 'color-values
"Green")
345 (defun ps-color-values (x-color)
347 ((fboundp 'color-values
)
348 (funcall 'color-values x-color
))
349 ((fboundp 'x-color-values
)
350 (funcall 'x-color-values x-color
))
352 (error "No available function to determine X color values"))))
355 (defun ps-face-bold-p (face)
356 (or (face-bold-p face
)
357 (memq face ps-bold-faces
)))
360 (defun ps-face-italic-p (face)
361 (or (face-italic-p face
)
362 (memq face ps-italic-faces
)))
365 ;; Emacs understands the %f format; we'll use it to limit color RGB values
366 ;; to three decimals to cut down some on the size of the PostScript output.
367 (defvar ps-color-format
"%0.3f %0.3f %0.3f")
368 (defvar ps-float-format
"%0.3f ")
371 (defun ps-generate-postscript-with-faces1 (from to
)
372 ;; Generate some PostScript.
373 (let ((face 'default
)
376 (property-change from
)
377 (overlay-change from
)
378 (save-buffer-invisibility-spec buffer-invisibility-spec
)
379 (buffer-invisibility-spec nil
)
380 before-string after-string
)
382 (and (< property-change to
) ; Don't search for property change
383 ; unless previous search succeeded.
384 (setq property-change
(next-property-change from nil to
)))
385 (and (< overlay-change to
) ; Don't search for overlay change
386 ; unless previous search succeeded.
387 (setq overlay-change
(min (next-overlay-change from
)
389 (setq position
(min property-change overlay-change
)
392 ;; The code below is not quite correct,
393 ;; because a non-nil overlay invisible property
394 ;; which is inactive according to the current value
395 ;; of buffer-invisibility-spec nonetheless overrides
396 ;; a face text property.
398 (cond ((let ((prop (get-text-property from
'invisible
)))
399 ;; Decide whether this invisible property
400 ;; really makes the text invisible.
401 (if (eq save-buffer-invisibility-spec t
)
403 (or (memq prop save-buffer-invisibility-spec
)
404 (assq prop save-buffer-invisibility-spec
))))
405 'emacs--invisible--face
)
406 ((get-text-property from
'face
))
408 (let ((overlays (overlays-at from
))
409 (face-priority -
1)) ; text-property
411 (not (eq face
'emacs--invisible--face
)))
412 (let* ((overlay (car overlays
))
414 (overlay-get overlay
'invisible
))
416 (or (overlay-get overlay
'priority
) 0)))
417 (and (> overlay-priority face-priority
)
419 (or (overlay-get overlay
'before-string
)
422 (or (and (<= (overlay-end overlay
) position
)
423 (overlay-get overlay
'after-string
))
425 face-priority overlay-priority
428 ((if (eq save-buffer-invisibility-spec t
)
429 (not (null overlay-invisible
))
430 (or (memq overlay-invisible
431 save-buffer-invisibility-spec
)
432 (assq overlay-invisible
433 save-buffer-invisibility-spec
)))
434 'emacs--invisible--face
)
435 ((overlay-get overlay
'face
))
438 (setq overlays
(cdr overlays
))))
439 ;; Plot up to this record.
441 (ps-plot-string before-string
))
442 (ps-plot-with-face from position face
)
444 (ps-plot-string after-string
))
445 (setq from position
))
446 (ps-plot-with-face from to face
)))
448 )) ; end cond featurep
451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
455 ;; arch-tag: 4edde45b-af10-4685-b8ee-7cd0f951095a
456 ;;; ps-def.el ends here