* net/ange-ftp.el (ange-ftp-skip-msgs): Add 500 EPSV (tiny change)
[emacs.git] / lisp / ps-def.el
blob468af28240fed8ff929cc18d79ee5cfe0a093207
1 ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print
3 ;; Copyright (C) 2007-2013 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
53 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54 ;; ps-bdf
56 (defvar installation-directory nil)
57 (defvar coding-system-for-read)
59 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 ;; ps-mule
62 (or (fboundp 'charset-dimension)
63 (defun charset-dimension (_charset) 1)) ; ascii
65 (or (fboundp 'char-width)
66 (defun char-width (_char) 1)) ; ascii
68 (or (fboundp 'encode-char)
69 (defun encode-char (ch _ccs)
70 ch))
72 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; ps-print
75 ;; GNU Emacs
76 (or (fboundp 'line-beginning-position)
77 (defun line-beginning-position (&optional n)
78 (save-excursion
79 (and n (/= n 1) (forward-line (1- n)))
80 (beginning-of-line)
81 (point))))
84 ;; GNU Emacs
85 (or (fboundp 'find-composition)
86 (defalias 'find-composition 'ignore))
89 (defun ps-xemacs-color-name (color)
90 (if (color-specifier-p color)
91 (color-name color)
92 color))
95 (defalias 'ps-mark-active-p 'region-active-p)
98 (defun ps-face-foreground-name (face)
99 (ps-xemacs-color-name (face-foreground face)))
102 (defun ps-face-background-name (face)
103 (ps-xemacs-color-name (face-background face)))
106 (defalias 'ps-frame-parameter 'frame-property)
109 ;; Return t if the device (which can be changed during an emacs session)
110 ;; can handle colors.
111 (defun ps-color-device ()
112 (eq (device-class) 'color))
114 (defun ps-mapper (extent list)
115 (nconc list
116 (list (list (extent-start-position extent) 'push extent)
117 (list (extent-end-position extent) 'pull extent)))
118 nil)
121 (defun ps-extent-sorter (a b)
122 (< (extent-priority a) (extent-priority b)))
125 (defun ps-xemacs-face-kind-p (face kind kind-regex)
126 (let* ((frame-font (or (face-font-instance face)
127 (face-font-instance 'default)))
128 (kind-cons
129 (and frame-font
130 (assq kind
131 (font-instance-properties frame-font))))
132 (kind-spec (cdr-safe kind-cons))
133 (case-fold-search t))
134 (and kind-spec (string-match kind-regex kind-spec))))
137 ;; to avoid XEmacs compilation gripes
138 (defvar coding-system-for-write)
139 (defvar buffer-file-coding-system)
142 (and (fboundp 'find-coding-system)
143 (or (funcall 'find-coding-system 'raw-text-unix)
144 (funcall 'copy-coding-system 'no-conversion-unix 'raw-text-unix)))
147 (defun ps-color-values (x-color)
148 (let ((color (ps-xemacs-color-name x-color)))
149 (cond
150 ((fboundp 'x-color-values)
151 (funcall 'x-color-values color))
152 ((and (fboundp 'color-instance-rgb-components)
153 (ps-color-device))
154 (funcall 'color-instance-rgb-components
155 (if (color-instance-p x-color)
156 x-color
157 (make-color-instance color))))
159 (error "No available function to determine X color values")))))
162 (defun ps-face-bold-p (face)
163 (or (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold")
164 (memq face ps-bold-faces))) ; Kludge-compatible
167 (defun ps-face-italic-p (face)
168 (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o")
169 (ps-xemacs-face-kind-p face 'SLANT "i\\|o")
170 (memq face ps-italic-faces))) ; Kludge-compatible
173 (defalias 'ps-face-strikeout-p 'ignore)
176 (defalias 'ps-face-overline-p 'ignore)
179 (defalias 'ps-face-box-p 'ignore)
182 ;; XEmacs will have to make do with %s (princ) for floats.
183 (defvar ps-color-format "%s %s %s")
184 (defvar ps-float-format "%s ")
187 (defun ps-generate-postscript-with-faces1 (from to)
188 ;; Generate some PostScript.
189 (let ((face 'default)
190 (position to)
191 ;; XEmacs
192 ;; Build the list of extents...
193 (a (cons 'dummy nil))
194 record type extent extent-list)
195 (map-extents 'ps-mapper nil from to a)
196 (setq a (sort (cdr a) 'car-less-than-car)
197 extent-list nil)
199 ;; Loop through the extents...
200 (while a
201 (setq record (car a)
202 position (car record)
204 record (cdr record)
205 type (car record)
207 record (cdr record)
208 extent (car record))
210 ;; Plot up to this record.
211 ;; XEmacs 19.12: for some reason, we're getting into a
212 ;; situation in which some of the records have
213 ;; positions less than 'from'. Since we've narrowed
214 ;; the buffer, this'll generate errors. This is a hack,
215 ;; but don't call ps-plot-with-face unless from > point-min.
216 (and (>= from (point-min))
217 (ps-plot-with-face from (min position (point-max)) face))
219 (cond
220 ((eq type 'push)
221 (and (extent-face extent)
222 (setq extent-list (sort (cons extent extent-list)
223 'ps-extent-sorter))))
225 ((eq type 'pull)
226 (setq extent-list (sort (delq extent extent-list)
227 'ps-extent-sorter))))
229 (setq face (if extent-list
230 (extent-face (car extent-list))
231 'default)
232 from position
233 a (cdr a)))
235 (ps-plot-with-face from to face)))
238 (t ; Emacs
239 ;; Do nothing
240 )) ; end cond featurep
244 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
245 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246 ;; Emacs Definitions
249 (cond
250 ((featurep 'xemacs) ; XEmacs
251 ;; Do nothing
253 (t ; Emacs
256 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;; ps-print
260 (defun ps-mark-active-p ()
261 mark-active)
264 (defun ps-face-foreground-name (face)
265 (face-foreground face nil t))
268 (defun ps-face-background-name (face)
269 (face-background face nil t))
272 (defalias 'ps-frame-parameter 'frame-parameter)
275 ;; Return t if the device (which can be changed during an emacs session) can
276 ;; handle colors. This function is not yet implemented for GNU emacs.
277 (defun ps-color-device ()
278 (if (fboundp 'color-values)
279 (funcall 'color-values "Green")
283 (defun ps-color-values (x-color)
284 (cond
285 ((fboundp 'color-values)
286 (funcall 'color-values x-color))
287 ((fboundp 'x-color-values)
288 (funcall 'x-color-values x-color))
290 (error "No available function to determine X color values"))))
293 (defun ps-face-bold-p (face)
294 (or (face-bold-p face)
295 (memq face ps-bold-faces)))
298 (defun ps-face-italic-p (face)
299 (or (face-italic-p face)
300 (memq face ps-italic-faces)))
303 (defun ps-face-strikeout-p (face)
304 (eq (face-attribute face :strike-through) t))
307 (defun ps-face-overline-p (face)
308 (eq (face-attribute face :overline) t))
311 (defun ps-face-box-p (face)
312 (not (memq (face-attribute face :box) '(nil unspecified))))
315 ;; Emacs understands the %f format; we'll use it to limit color RGB values
316 ;; to three decimals to cut down some on the size of the PostScript output.
317 (defvar ps-color-format "%0.3f %0.3f %0.3f")
318 (defvar ps-float-format "%0.3f ")
321 (defun ps-generate-postscript-with-faces1 (from to)
322 ;; Generate some PostScript.
323 (let ((face 'default)
324 (position to)
325 ;; Emacs
326 (property-change from)
327 (overlay-change from)
328 (save-buffer-invisibility-spec buffer-invisibility-spec)
329 (buffer-invisibility-spec nil)
330 before-string after-string)
331 (while (< from to)
332 (and (< property-change to) ; Don't search for property change
333 ; unless previous search succeeded.
334 (setq property-change (next-property-change from nil to)))
335 (and (< overlay-change to) ; Don't search for overlay change
336 ; unless previous search succeeded.
337 (setq overlay-change (min (next-overlay-change from)
338 to)))
339 (setq position (min property-change overlay-change)
340 before-string nil
341 after-string nil)
342 ;; The code below is not quite correct,
343 ;; because a non-nil overlay invisible property
344 ;; which is inactive according to the current value
345 ;; of buffer-invisibility-spec nonetheless overrides
346 ;; a face text property.
347 (setq face
348 (cond ((let ((prop (get-text-property from 'invisible)))
349 ;; Decide whether this invisible property
350 ;; really makes the text invisible.
351 (if (eq save-buffer-invisibility-spec t)
352 (not (null prop))
353 (or (memq prop save-buffer-invisibility-spec)
354 (assq prop save-buffer-invisibility-spec))))
355 'emacs--invisible--face)
356 ((get-text-property from 'face))
357 (t 'default)))
358 (let ((overlays (overlays-at from))
359 (face-priority -1)) ; text-property
360 (while (and overlays
361 (not (eq face 'emacs--invisible--face)))
362 (let* ((overlay (car overlays))
363 (overlay-invisible
364 (overlay-get overlay 'invisible))
365 (overlay-priority
366 (or (overlay-get overlay 'priority) 0)))
367 (and (> overlay-priority face-priority)
368 (setq before-string
369 (or (overlay-get overlay 'before-string)
370 before-string)
371 after-string
372 (or (and (<= (overlay-end overlay) position)
373 (overlay-get overlay 'after-string))
374 after-string)
375 face-priority overlay-priority
376 face
377 (cond
378 ((if (eq save-buffer-invisibility-spec t)
379 (not (null overlay-invisible))
380 (or (memq overlay-invisible
381 save-buffer-invisibility-spec)
382 (assq overlay-invisible
383 save-buffer-invisibility-spec)))
384 'emacs--invisible--face)
385 ((overlay-get overlay 'face))
386 (t face)
387 ))))
388 (setq overlays (cdr overlays))))
389 ;; Plot up to this record.
390 (and before-string
391 (ps-plot-string before-string))
392 (ps-plot-with-face from position face)
393 (and after-string
394 (ps-plot-string after-string))
395 (setq from position))
396 (ps-plot-with-face from to face)))
398 )) ; end cond featurep
401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
403 (provide 'ps-def)
405 ;;; ps-def.el ends here