gnus-article-html: Decode contents by charset.
[emacs.git] / lisp / ps-def.el
blobc27ee251e08ea4771bd10cc42f20d50209a6ea0b
1 ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print
3 ;; Copyright (C) 2007, 2008, 2009, 2010 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
11 ;; Package: ps-print
13 ;; This file is part of GNU Emacs.
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.
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.
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/>.
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 (defun ps-color-device ()
182 (eq (device-class) 'color))
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)
191 (defun ps-extent-sorter (a b)
192 (< (extent-priority a) (extent-priority b)))
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))))
207 ;; to avoid XEmacs compilation gripes
208 (defvar coding-system-for-write)
209 (defvar buffer-file-coding-system)
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)))
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))))
229 (error "No available function to determine X color values")))))
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
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
243 (defalias 'ps-face-strikeout-p 'ignore)
246 (defalias 'ps-face-overline-p 'ignore)
249 (defalias 'ps-face-box-p 'ignore)
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 ")
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)
269 ;; Loop through the extents...
270 (while a
271 (setq record (car a)
272 position (car record)
274 record (cdr record)
275 type (car record)
277 record (cdr record)
278 extent (car record))
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))
289 (cond
290 ((eq type 'push)
291 (and (extent-face extent)
292 (setq extent-list (sort (cons extent extent-list)
293 'ps-extent-sorter))))
295 ((eq type 'pull)
296 (setq extent-list (sort (delq extent extent-list)
297 'ps-extent-sorter))))
299 (setq face (if extent-list
300 (extent-face (car extent-list))
301 'default)
302 from position
303 a (cdr a)))
305 (ps-plot-with-face from to face)))
308 (t ; Emacs
309 ;; Do nothing
310 )) ; end cond featurep
314 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
315 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316 ;; Emacs Definitions
319 (cond
320 ((featurep 'xemacs) ; XEmacs
321 ;; Do nothing
323 (t ; Emacs
326 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327 ;; ps-print
330 (defun ps-mark-active-p ()
331 mark-active)
334 (defun ps-face-foreground-name (face)
335 (face-foreground face nil t))
338 (defun ps-face-background-name (face)
339 (face-background face nil t))
342 (defalias 'ps-frame-parameter 'frame-parameter)
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")
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))
360 (error "No available function to determine X color values"))))
363 (defun ps-face-bold-p (face)
364 (or (face-bold-p face)
365 (memq face ps-bold-faces)))
368 (defun ps-face-italic-p (face)
369 (or (face-italic-p face)
370 (memq face ps-italic-faces)))
373 (defun ps-face-strikeout-p (face)
374 (eq (face-attribute face :strike-through) t))
377 (defun ps-face-overline-p (face)
378 (eq (face-attribute face :overline) t))
381 (defun ps-face-box-p (face)
382 (not (memq (face-attribute face :box) '(nil unspecified))))
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 ")
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)))
468 )) ; end cond featurep
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
473 (provide 'ps-def)
475 ;; arch-tag: 4edde45b-af10-4685-b8ee-7cd0f951095a
476 ;;; ps-def.el ends here