1 ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print -*- lexical-binding: t -*-
3 ;; Copyright (C) 2007-2016 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
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/>.
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
53 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 (defvar installation-directory nil
)
57 (defvar coding-system-for-read
)
59 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
)
72 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 (or (fboundp 'line-beginning-position
)
77 (defun line-beginning-position (&optional n
)
79 (and n
(/= n
1) (forward-line (1- n
)))
85 (or (fboundp 'find-composition
)
86 (defalias 'find-composition
'ignore
))
89 (defun ps-xemacs-color-name (color)
90 (if (color-specifier-p 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
)
116 (list (list (extent-start-position extent
) 'push extent
)
117 (list (extent-end-position extent
) 'pull extent
)))
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
)))
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
)))
150 ((fboundp 'x-color-values
)
151 (funcall 'x-color-values color
))
152 ((and (fboundp 'color-instance-rgb-components
)
154 (funcall 'color-instance-rgb-components
155 (if (color-instance-p 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
)
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
)
199 ;; Loop through the extents...
202 position
(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
))
221 (and (extent-face extent
)
222 (setq extent-list
(sort (cons extent extent-list
)
223 'ps-extent-sorter
))))
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
))
235 (ps-plot-with-face from to face
)))
240 )) ; end cond featurep
244 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
245 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250 ((featurep 'xemacs
) ; XEmacs
256 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260 (defun ps-mark-active-p ()
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)
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
)
326 (property-change from
)
327 (overlay-change from
)
328 before-string after-string
)
330 (and (< property-change to
) ; Don't search for property change
331 ; unless previous search succeeded.
332 (setq property-change
(next-property-change from nil to
)))
333 (and (< overlay-change to
) ; Don't search for overlay change
334 ; unless previous search succeeded.
335 (setq overlay-change
(min (next-overlay-change from
)
337 (setq position
(min property-change overlay-change
)
341 (cond ((invisible-p from
)
342 'emacs--invisible--face
)
343 ((get-char-property from
'face
))
345 ;; Plot up to this record.
347 (ps-plot-string before-string
))
348 (ps-plot-with-face from position face
)
350 (ps-plot-string after-string
))
351 (setq from position
))
352 (ps-plot-with-face from to face
)))
354 )) ; end cond featurep
357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
361 ;;; ps-def.el ends here