| 1 | ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print |
| 2 | |
| 3 | ;; Copyright (C) 2007-2014 Free Software Foundation, Inc. |
| 4 | |
| 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 |
| 12 | |
| 13 | ;; This file is part of GNU Emacs. |
| 14 | |
| 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. |
| 19 | |
| 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. |
| 24 | |
| 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/>. |
| 27 | |
| 28 | ;;; Commentary: |
| 29 | |
| 30 | ;; See ps-print.el for documentation. |
| 31 | |
| 32 | ;;; Code: |
| 33 | |
| 34 | (eval-and-compile |
| 35 | (unless (fboundp 'declare-function) (defmacro declare-function (&rest _r)))) |
| 36 | |
| 37 | (declare-function ps-plot-with-face "ps-print" (from to face)) |
| 38 | (declare-function ps-plot-string "ps-print" (string)) |
| 39 | |
| 40 | (defvar ps-bold-faces) ; in ps-print.el |
| 41 | (defvar ps-italic-faces) |
| 42 | |
| 43 | |
| 44 | \f |
| 45 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 46 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 47 | ;; XEmacs Definitions |
| 48 | |
| 49 | |
| 50 | (cond |
| 51 | ((featurep 'xemacs) ; XEmacs |
| 52 | |
| 53 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 54 | ;; ps-bdf |
| 55 | |
| 56 | (defvar installation-directory nil) |
| 57 | (defvar coding-system-for-read) |
| 58 | |
| 59 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 60 | ;; ps-mule |
| 61 | |
| 62 | (or (fboundp 'charset-dimension) |
| 63 | (defun charset-dimension (_charset) 1)) ; ascii |
| 64 | |
| 65 | (or (fboundp 'char-width) |
| 66 | (defun char-width (_char) 1)) ; ascii |
| 67 | |
| 68 | (or (fboundp 'encode-char) |
| 69 | (defun encode-char (ch _ccs) |
| 70 | ch)) |
| 71 | |
| 72 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 73 | ;; ps-print |
| 74 | |
| 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)))) |
| 82 | |
| 83 | |
| 84 | ;; GNU Emacs |
| 85 | (or (fboundp 'find-composition) |
| 86 | (defalias 'find-composition 'ignore)) |
| 87 | |
| 88 | |
| 89 | (defun ps-xemacs-color-name (color) |
| 90 | (if (color-specifier-p color) |
| 91 | (color-name color) |
| 92 | color)) |
| 93 | |
| 94 | |
| 95 | (defalias 'ps-mark-active-p 'region-active-p) |
| 96 | |
| 97 | |
| 98 | (defun ps-face-foreground-name (face) |
| 99 | (ps-xemacs-color-name (face-foreground face))) |
| 100 | |
| 101 | |
| 102 | (defun ps-face-background-name (face) |
| 103 | (ps-xemacs-color-name (face-background face))) |
| 104 | |
| 105 | |
| 106 | (defalias 'ps-frame-parameter 'frame-property) |
| 107 | |
| 108 | |
| 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)) |
| 113 | |
| 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) |
| 119 | |
| 120 | |
| 121 | (defun ps-extent-sorter (a b) |
| 122 | (< (extent-priority a) (extent-priority b))) |
| 123 | |
| 124 | |
| 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)))) |
| 135 | |
| 136 | |
| 137 | ;; to avoid XEmacs compilation gripes |
| 138 | (defvar coding-system-for-write) |
| 139 | (defvar buffer-file-coding-system) |
| 140 | |
| 141 | |
| 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))) |
| 145 | |
| 146 | |
| 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)))) |
| 158 | (t |
| 159 | (error "No available function to determine X color values"))))) |
| 160 | |
| 161 | |
| 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 |
| 165 | |
| 166 | |
| 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 |
| 171 | |
| 172 | |
| 173 | (defalias 'ps-face-strikeout-p 'ignore) |
| 174 | |
| 175 | |
| 176 | (defalias 'ps-face-overline-p 'ignore) |
| 177 | |
| 178 | |
| 179 | (defalias 'ps-face-box-p 'ignore) |
| 180 | |
| 181 | |
| 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 ") |
| 185 | |
| 186 | |
| 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) |
| 198 | |
| 199 | ;; Loop through the extents... |
| 200 | (while a |
| 201 | (setq record (car a) |
| 202 | position (car record) |
| 203 | |
| 204 | record (cdr record) |
| 205 | type (car record) |
| 206 | |
| 207 | record (cdr record) |
| 208 | extent (car record)) |
| 209 | |
| 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)) |
| 218 | |
| 219 | (cond |
| 220 | ((eq type 'push) |
| 221 | (and (extent-face extent) |
| 222 | (setq extent-list (sort (cons extent extent-list) |
| 223 | 'ps-extent-sorter)))) |
| 224 | |
| 225 | ((eq type 'pull) |
| 226 | (setq extent-list (sort (delq extent extent-list) |
| 227 | 'ps-extent-sorter)))) |
| 228 | |
| 229 | (setq face (if extent-list |
| 230 | (extent-face (car extent-list)) |
| 231 | 'default) |
| 232 | from position |
| 233 | a (cdr a))) |
| 234 | |
| 235 | (ps-plot-with-face from to face))) |
| 236 | |
| 237 | ) |
| 238 | (t ; Emacs |
| 239 | ;; Do nothing |
| 240 | )) ; end cond featurep |
| 241 | |
| 242 | |
| 243 | \f |
| 244 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 245 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 246 | ;; Emacs Definitions |
| 247 | |
| 248 | |
| 249 | (cond |
| 250 | ((featurep 'xemacs) ; XEmacs |
| 251 | ;; Do nothing |
| 252 | ) |
| 253 | (t ; Emacs |
| 254 | |
| 255 | |
| 256 | ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 257 | ;; ps-print |
| 258 | |
| 259 | |
| 260 | (defun ps-mark-active-p () |
| 261 | mark-active) |
| 262 | |
| 263 | |
| 264 | (defun ps-face-foreground-name (face) |
| 265 | (face-foreground face nil t)) |
| 266 | |
| 267 | |
| 268 | (defun ps-face-background-name (face) |
| 269 | (face-background face nil t)) |
| 270 | |
| 271 | |
| 272 | (defalias 'ps-frame-parameter 'frame-parameter) |
| 273 | |
| 274 | |
| 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") |
| 280 | t)) |
| 281 | |
| 282 | |
| 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)) |
| 289 | (t |
| 290 | (error "No available function to determine X color values")))) |
| 291 | |
| 292 | |
| 293 | (defun ps-face-bold-p (face) |
| 294 | (or (face-bold-p face) |
| 295 | (memq face ps-bold-faces))) |
| 296 | |
| 297 | |
| 298 | (defun ps-face-italic-p (face) |
| 299 | (or (face-italic-p face) |
| 300 | (memq face ps-italic-faces))) |
| 301 | |
| 302 | |
| 303 | (defun ps-face-strikeout-p (face) |
| 304 | (eq (face-attribute face :strike-through) t)) |
| 305 | |
| 306 | |
| 307 | (defun ps-face-overline-p (face) |
| 308 | (eq (face-attribute face :overline) t)) |
| 309 | |
| 310 | |
| 311 | (defun ps-face-box-p (face) |
| 312 | (not (memq (face-attribute face :box) '(nil unspecified)))) |
| 313 | |
| 314 | |
| 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 ") |
| 319 | |
| 320 | |
| 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 | (setq face |
| 343 | (cond ((invisible-p from) |
| 344 | 'emacs--invisible--face) |
| 345 | ((get-char-property from 'face)) |
| 346 | (t 'default))) |
| 347 | ;; Plot up to this record. |
| 348 | (and before-string |
| 349 | (ps-plot-string before-string)) |
| 350 | (ps-plot-with-face from position face) |
| 351 | (and after-string |
| 352 | (ps-plot-string after-string)) |
| 353 | (setq from position)) |
| 354 | (ps-plot-with-face from to face))) |
| 355 | |
| 356 | )) ; end cond featurep |
| 357 | |
| 358 | \f |
| 359 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 360 | |
| 361 | (provide 'ps-def) |
| 362 | |
| 363 | ;;; ps-def.el ends here |