(number, original-date, add-to-diary-list)
[emacs.git] / lisp / ps-def.el
blob72a8bbf3e2310cf0d34c8f0581404103b7c29099
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
17 ;; version.
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.
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.
28 ;;; Commentary:
30 ;; See ps-print.el for documentation.
32 ;;; Code:
34 (eval-and-compile
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 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 ;; XEmacs Definitions
50 (cond
51 ((featurep 'xemacs) ; XEmacs
54 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;; ps-bdf
57 (defvar installation-directory nil)
58 (defvar coding-system-for-read)
61 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 ;; ps-mule
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)
80 (list 'ascii)))
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)
91 (save-excursion
92 (let ((count (abs arg))
93 (step (if (zerop arg)
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))))))
102 (or (fboundp 'decompose-composite-char)
103 (defun decompose-composite-char (char &optional type
104 with-composition-rule)
105 nil))
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))))
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)
119 str))
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))
128 (i 0)
129 multibyte)
130 (while (and (< i len) (not (setq multibyte (> (aref str i) 255))))
131 (setq i (1+ i)))
132 multibyte)))
134 (or (fboundp 'string-make-multibyte)
135 (defalias 'string-make-multibyte 'copy-sequence))
137 (or (fboundp 'encode-char)
138 (defun encode-char (ch ccs)
139 ch))
142 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 ;; ps-print
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))))
154 ;; GNU Emacs
155 (or (fboundp 'find-composition)
156 (defalias 'find-composition 'ignore))
159 (defun ps-xemacs-color-name (color)
160 (if (color-specifier-p color)
161 (color-name color)
162 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)))
185 ;; xemacs >= 19.12
186 (defun ps-color-device ()
187 (eq (device-class) 'color))
188 ;; xemacs < 19.12
189 (setq ps-print-color-p nil)
190 (defalias 'ps-color-device 'ignore))
193 (defun ps-mapper (extent list)
194 (nconc list
195 (list (list (extent-start-position extent) 'push extent)
196 (list (extent-end-position extent) 'pull extent)))
197 nil)
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)))
207 (kind-cons
208 (and frame-font
209 (assq kind
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)))
228 (cond
229 ((fboundp 'x-color-values)
230 (funcall 'x-color-values color))
231 ((and (fboundp 'color-instance-rgb-components)
232 (ps-color-device))
233 (funcall 'color-instance-rgb-components
234 (if (color-instance-p x-color)
235 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)
269 (position to)
270 ;; XEmacs
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)
276 extent-list nil)
278 ;; Loop through the extents...
279 (while a
280 (setq record (car a)
281 position (car record)
283 record (cdr record)
284 type (car record)
286 record (cdr record)
287 extent (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))
298 (cond
299 ((eq type 'push)
300 (and (extent-face extent)
301 (setq extent-list (sort (cons extent extent-list)
302 'ps-extent-sorter))))
304 ((eq type 'pull)
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))
310 'default)
311 from position
312 a (cdr a)))
314 (ps-plot-with-face from to face)))
317 (t ; Emacs
318 ;; Do nothing
319 )) ; end cond featurep
323 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
324 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325 ;; Emacs Definitions
328 (cond
329 ((featurep 'xemacs) ; XEmacs
330 ;; Do nothing
332 (t ; Emacs
335 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
336 ;; ps-print
339 (defun ps-mark-active-p ()
340 mark-active)
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)
363 (cond
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)
403 (position to)
404 ;; Emacs
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)
410 (while (< from to)
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)
417 to)))
418 (setq position (min property-change overlay-change)
419 before-string nil
420 after-string nil)
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.
426 (setq face
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)
431 (not (null prop))
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))
436 (t 'default)))
437 (let ((overlays (overlays-at from))
438 (face-priority -1)) ; text-property
439 (while (and overlays
440 (not (eq face 'emacs--invisible--face)))
441 (let* ((overlay (car overlays))
442 (overlay-invisible
443 (overlay-get overlay 'invisible))
444 (overlay-priority
445 (or (overlay-get overlay 'priority) 0)))
446 (and (> overlay-priority face-priority)
447 (setq before-string
448 (or (overlay-get overlay 'before-string)
449 before-string)
450 after-string
451 (or (and (<= (overlay-end overlay) position)
452 (overlay-get overlay 'after-string))
453 after-string)
454 face-priority overlay-priority
455 face
456 (cond
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))
465 (t face)
466 ))))
467 (setq overlays (cdr overlays))))
468 ;; Plot up to this record.
469 (and before-string
470 (ps-plot-string before-string))
471 (ps-plot-with-face from position face)
472 (and after-string
473 (ps-plot-string after-string))
474 (setq from position))
475 (ps-plot-with-face from to face)))
477 )) ; end cond featurep
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
482 (provide 'ps-def)
484 ;; arch-tag: 4edde45b-af10-4685-b8ee-7cd0f951095a
485 ;;; ps-def.el ends here