1 ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print
3 ;; Copyright (C) 2007, 2008 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
10 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
12 ;; This file is part of GNU Emacs.
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
16 ;; Software Foundation; either version 3, or (at your option) any later
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
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.
30 ;; See ps-print.el for documentation.
35 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
37 (declare-function ps-plot-with-face
"ps-print" (from to face
))
38 (declare-function ps-plot-string
"ps-print" (string))
40 (defvar ps-bold-faces
) ; in ps-print.el
41 (defvar ps-italic-faces
)
45 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
46 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 ((featurep 'xemacs
) ; XEmacs
54 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 (defvar installation-directory nil
)
58 (defvar coding-system-for-read
)
61 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 (defvar leading-code-private-22
157)
66 (or (fboundp 'charset-bytes
)
67 (defun charset-bytes (charset) 1)) ; ascii
69 (or (fboundp 'charset-dimension
)
70 (defun charset-dimension (charset) 1)) ; ascii
72 (or (fboundp 'charset-id
)
73 (defun charset-id (charset) 0)) ; ascii
75 (or (fboundp 'charset-width
)
76 (defun charset-width (charset) 1)) ; ascii
78 (or (fboundp 'find-charset-region
)
79 (defun find-charset-region (beg end
&optional table
)
82 (or (fboundp 'char-width
)
83 (defun char-width (char) 1)) ; ascii
85 (or (fboundp 'chars-in-region
)
86 (defun chars-in-region (beg end
)
87 (- (max beg end
) (min beg end
))))
89 (or (fboundp 'forward-point
)
90 (defun forward-point (arg)
92 (let ((count (abs arg
))
96 (while (and (> count
0)
97 (< (point-min) (point)) (< (point) (point-max)))
99 (setq count
(1- count
)))
100 (+ (point) (* count step
))))))
102 (or (fboundp 'decompose-composite-char
)
103 (defun decompose-composite-char (char &optional type
104 with-composition-rule
)
107 (or (fboundp 'encode-coding-string
)
108 (defun encode-coding-string (string coding-system
&optional nocopy
)
111 (copy-sequence string
))))
113 (or (fboundp 'coding-system-p
)
114 (defun coding-system-p (obj) nil
))
116 (or (fboundp 'ccl-execute-on-string
)
117 (defun ccl-execute-on-string (ccl-prog status str
118 &optional contin unibyte-p
)
121 (or (fboundp 'define-ccl-program
)
122 (defmacro define-ccl-program
(name ccl-program
&optional doc
)
123 `(defconst ,name nil
,doc
)))
125 (or (fboundp 'multibyte-string-p
)
126 (defun multibyte-string-p (str)
127 (let ((len (length str
))
130 (while (and (< i len
) (not (setq multibyte
(> (aref str i
) 255))))
134 (or (fboundp 'string-make-multibyte
)
135 (defalias 'string-make-multibyte
'copy-sequence
))
137 (or (fboundp 'encode-char
)
138 (defun encode-char (ch ccs
)
142 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146 (or (fboundp 'line-beginning-position
)
147 (defun line-beginning-position (&optional n
)
149 (and n
(/= n
1) (forward-line (1- n
)))
155 (or (fboundp 'find-composition
)
156 (defalias 'find-composition
'ignore
))
159 (defun ps-xemacs-color-name (color)
160 (if (color-specifier-p color
)
165 (defalias 'ps-mark-active-p
'region-active-p
)
168 (defun ps-face-foreground-name (face)
169 (ps-xemacs-color-name (face-foreground face
)))
172 (defun ps-face-background-name (face)
173 (ps-xemacs-color-name (face-background face
)))
176 (defalias 'ps-frame-parameter
'frame-property
)
179 ;; Return t if the device (which can be changed during an emacs session)
180 ;; can handle colors.
181 ;; XEmacs change: Need to check for emacs-major-version too.
182 (if (or (> emacs-major-version
19)
183 (and (= emacs-major-version
19)
184 (>= emacs-minor-version
12)))
186 (defun ps-color-device ()
187 (eq (device-class) 'color
))
189 (setq ps-print-color-p nil
)
190 (defalias 'ps-color-device
'ignore
))
193 (defun ps-mapper (extent list
)
195 (list (list (extent-start-position extent
) 'push extent
)
196 (list (extent-end-position extent
) 'pull extent
)))
200 (defun ps-extent-sorter (a b
)
201 (< (extent-priority a
) (extent-priority b
)))
204 (defun ps-xemacs-face-kind-p (face kind kind-regex
)
205 (let* ((frame-font (or (face-font-instance face
)
206 (face-font-instance 'default
)))
210 (font-instance-properties frame-font
))))
211 (kind-spec (cdr-safe kind-cons
))
212 (case-fold-search t
))
213 (and kind-spec
(string-match kind-regex kind-spec
))))
216 ;; to avoid XEmacs compilation gripes
217 (defvar coding-system-for-write
)
218 (defvar buffer-file-coding-system
)
221 (and (fboundp 'find-coding-system
)
222 (or (funcall 'find-coding-system
'raw-text-unix
)
223 (funcall 'copy-coding-system
'no-conversion-unix
'raw-text-unix
)))
226 (defun ps-color-values (x-color)
227 (let ((color (ps-xemacs-color-name x-color
)))
229 ((fboundp 'x-color-values
)
230 (funcall 'x-color-values color
))
231 ((and (fboundp 'color-instance-rgb-components
)
233 (funcall 'color-instance-rgb-components
234 (if (color-instance-p x-color
)
236 (make-color-instance color
))))
238 (error "No available function to determine X color values")))))
241 (defun ps-face-bold-p (face)
242 (or (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold")
243 (memq face ps-bold-faces
))) ; Kludge-compatible
246 (defun ps-face-italic-p (face)
247 (or (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o")
248 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o")
249 (memq face ps-italic-faces
))) ; Kludge-compatible
252 (defalias 'ps-face-strikeout-p
'ignore
)
255 (defalias 'ps-face-overline-p
'ignore
)
258 (defalias 'ps-face-box-p
'ignore
)
261 ;; XEmacs will have to make do with %s (princ) for floats.
262 (defvar ps-color-format
"%s %s %s")
263 (defvar ps-float-format
"%s ")
266 (defun ps-generate-postscript-with-faces1 (from to
)
267 ;; Generate some PostScript.
268 (let ((face 'default
)
271 ;; Build the list of extents...
272 (a (cons 'dummy nil
))
273 record type extent extent-list
)
274 (map-extents 'ps-mapper nil from to a
)
275 (setq a
(sort (cdr a
) 'car-less-than-car
)
278 ;; Loop through the extents...
281 position
(car record
)
289 ;; Plot up to this record.
290 ;; XEmacs 19.12: for some reason, we're getting into a
291 ;; situation in which some of the records have
292 ;; positions less than 'from'. Since we've narrowed
293 ;; the buffer, this'll generate errors. This is a hack,
294 ;; but don't call ps-plot-with-face unless from > point-min.
295 (and (>= from
(point-min))
296 (ps-plot-with-face from
(min position
(point-max)) face
))
300 (and (extent-face extent
)
301 (setq extent-list
(sort (cons extent extent-list
)
302 'ps-extent-sorter
))))
305 (setq extent-list
(sort (delq extent extent-list
)
306 'ps-extent-sorter
))))
308 (setq face
(if extent-list
309 (extent-face (car extent-list
))
314 (ps-plot-with-face from to face
)))
319 )) ; end cond featurep
323 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
324 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ((featurep 'xemacs
) ; XEmacs
335 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339 (defun ps-mark-active-p ()
343 (defun ps-face-foreground-name (face)
344 (face-foreground face nil t
))
347 (defun ps-face-background-name (face)
348 (face-background face nil t
))
351 (defalias 'ps-frame-parameter
'frame-parameter
)
354 ;; Return t if the device (which can be changed during an emacs session) can
355 ;; handle colors. This function is not yet implemented for GNU emacs.
356 (defun ps-color-device ()
357 (if (fboundp 'color-values
)
358 (funcall 'color-values
"Green")
362 (defun ps-color-values (x-color)
364 ((fboundp 'color-values
)
365 (funcall 'color-values x-color
))
366 ((fboundp 'x-color-values
)
367 (funcall 'x-color-values x-color
))
369 (error "No available function to determine X color values"))))
372 (defun ps-face-bold-p (face)
373 (or (face-bold-p face
)
374 (memq face ps-bold-faces
)))
377 (defun ps-face-italic-p (face)
378 (or (face-italic-p face
)
379 (memq face ps-italic-faces
)))
382 (defun ps-face-strikeout-p (face)
383 (eq (face-attribute face
:strike-through
) t
))
386 (defun ps-face-overline-p (face)
387 (eq (face-attribute face
:overline
) t
))
390 (defun ps-face-box-p (face)
391 (not (memq (face-attribute face
:box
) '(nil unspecified
))))
394 ;; Emacs understands the %f format; we'll use it to limit color RGB values
395 ;; to three decimals to cut down some on the size of the PostScript output.
396 (defvar ps-color-format
"%0.3f %0.3f %0.3f")
397 (defvar ps-float-format
"%0.3f ")
400 (defun ps-generate-postscript-with-faces1 (from to
)
401 ;; Generate some PostScript.
402 (let ((face 'default
)
405 (property-change from
)
406 (overlay-change from
)
407 (save-buffer-invisibility-spec buffer-invisibility-spec
)
408 (buffer-invisibility-spec nil
)
409 before-string after-string
)
411 (and (< property-change to
) ; Don't search for property change
412 ; unless previous search succeeded.
413 (setq property-change
(next-property-change from nil to
)))
414 (and (< overlay-change to
) ; Don't search for overlay change
415 ; unless previous search succeeded.
416 (setq overlay-change
(min (next-overlay-change from
)
418 (setq position
(min property-change overlay-change
)
421 ;; The code below is not quite correct,
422 ;; because a non-nil overlay invisible property
423 ;; which is inactive according to the current value
424 ;; of buffer-invisibility-spec nonetheless overrides
425 ;; a face text property.
427 (cond ((let ((prop (get-text-property from
'invisible
)))
428 ;; Decide whether this invisible property
429 ;; really makes the text invisible.
430 (if (eq save-buffer-invisibility-spec t
)
432 (or (memq prop save-buffer-invisibility-spec
)
433 (assq prop save-buffer-invisibility-spec
))))
434 'emacs--invisible--face
)
435 ((get-text-property from
'face
))
437 (let ((overlays (overlays-at from
))
438 (face-priority -
1)) ; text-property
440 (not (eq face
'emacs--invisible--face
)))
441 (let* ((overlay (car overlays
))
443 (overlay-get overlay
'invisible
))
445 (or (overlay-get overlay
'priority
) 0)))
446 (and (> overlay-priority face-priority
)
448 (or (overlay-get overlay
'before-string
)
451 (or (and (<= (overlay-end overlay
) position
)
452 (overlay-get overlay
'after-string
))
454 face-priority overlay-priority
457 ((if (eq save-buffer-invisibility-spec t
)
458 (not (null overlay-invisible
))
459 (or (memq overlay-invisible
460 save-buffer-invisibility-spec
)
461 (assq overlay-invisible
462 save-buffer-invisibility-spec
)))
463 'emacs--invisible--face
)
464 ((overlay-get overlay
'face
))
467 (setq overlays
(cdr overlays
))))
468 ;; Plot up to this record.
470 (ps-plot-string before-string
))
471 (ps-plot-with-face from position face
)
473 (ps-plot-string after-string
))
474 (setq from position
))
475 (ps-plot-with-face from to face
)))
477 )) ; end cond featurep
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
484 ;; arch-tag: 4edde45b-af10-4685-b8ee-7cd0f951095a
485 ;;; ps-def.el ends here