ps-def.el 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. ;;; ps-def.el --- XEmacs and Emacs definitions for ps-print
  2. ;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
  3. ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
  4. ;; Kenichi Handa <handa@m17n.org> (multi-byte characters)
  5. ;; Maintainer: Kenichi Handa <handa@m17n.org> (multi-byte characters)
  6. ;; Vinicius Jose Latorre <viniciusjl@ig.com.br>
  7. ;; Keywords: wp, print, PostScript
  8. ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
  9. ;; Package: ps-print
  10. ;; This file is part of GNU Emacs.
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;; Commentary:
  22. ;; See ps-print.el for documentation.
  23. ;;; Code:
  24. (eval-and-compile
  25. (unless (fboundp 'declare-function) (defmacro declare-function (&rest _r))))
  26. (declare-function ps-plot-with-face "ps-print" (from to face))
  27. (declare-function ps-plot-string "ps-print" (string))
  28. (defvar ps-bold-faces) ; in ps-print.el
  29. (defvar ps-italic-faces)
  30. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32. ;; XEmacs Definitions
  33. (cond
  34. ((featurep 'xemacs) ; XEmacs
  35. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;; ps-bdf
  37. (defvar installation-directory nil)
  38. (defvar coding-system-for-read)
  39. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  40. ;; ps-mule
  41. (or (fboundp 'charset-dimension)
  42. (defun charset-dimension (_charset) 1)) ; ascii
  43. (or (fboundp 'char-width)
  44. (defun char-width (_char) 1)) ; ascii
  45. (or (fboundp 'encode-char)
  46. (defun encode-char (ch _ccs)
  47. ch))
  48. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49. ;; ps-print
  50. ;; GNU Emacs
  51. (or (fboundp 'line-beginning-position)
  52. (defun line-beginning-position (&optional n)
  53. (save-excursion
  54. (and n (/= n 1) (forward-line (1- n)))
  55. (beginning-of-line)
  56. (point))))
  57. ;; GNU Emacs
  58. (or (fboundp 'find-composition)
  59. (defalias 'find-composition 'ignore))
  60. (defun ps-xemacs-color-name (color)
  61. (if (color-specifier-p color)
  62. (color-name color)
  63. color))
  64. (defalias 'ps-mark-active-p 'region-active-p)
  65. (defun ps-face-foreground-name (face)
  66. (ps-xemacs-color-name (face-foreground face)))
  67. (defun ps-face-background-name (face)
  68. (ps-xemacs-color-name (face-background face)))
  69. (defalias 'ps-frame-parameter 'frame-property)
  70. ;; Return t if the device (which can be changed during an emacs session)
  71. ;; can handle colors.
  72. (defun ps-color-device ()
  73. (eq (device-class) 'color))
  74. (defun ps-mapper (extent list)
  75. (nconc list
  76. (list (list (extent-start-position extent) 'push extent)
  77. (list (extent-end-position extent) 'pull extent)))
  78. nil)
  79. (defun ps-extent-sorter (a b)
  80. (< (extent-priority a) (extent-priority b)))
  81. (defun ps-xemacs-face-kind-p (face kind kind-regex)
  82. (let* ((frame-font (or (face-font-instance face)
  83. (face-font-instance 'default)))
  84. (kind-cons
  85. (and frame-font
  86. (assq kind
  87. (font-instance-properties frame-font))))
  88. (kind-spec (cdr-safe kind-cons))
  89. (case-fold-search t))
  90. (and kind-spec (string-match kind-regex kind-spec))))
  91. ;; to avoid XEmacs compilation gripes
  92. (defvar coding-system-for-write)
  93. (defvar buffer-file-coding-system)
  94. (and (fboundp 'find-coding-system)
  95. (or (funcall 'find-coding-system 'raw-text-unix)
  96. (funcall 'copy-coding-system 'no-conversion-unix 'raw-text-unix)))
  97. (defun ps-color-values (x-color)
  98. (let ((color (ps-xemacs-color-name x-color)))
  99. (cond
  100. ((fboundp 'x-color-values)
  101. (funcall 'x-color-values color))
  102. ((and (fboundp 'color-instance-rgb-components)
  103. (ps-color-device))
  104. (funcall 'color-instance-rgb-components
  105. (if (color-instance-p x-color)
  106. x-color
  107. (make-color-instance color))))
  108. (t
  109. (error "No available function to determine X color values")))))
  110. (defun ps-face-bold-p (face)
  111. (or (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold")
  112. (memq face ps-bold-faces))) ; Kludge-compatible
  113. (defun ps-face-italic-p (face)
  114. (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o")
  115. (ps-xemacs-face-kind-p face 'SLANT "i\\|o")
  116. (memq face ps-italic-faces))) ; Kludge-compatible
  117. (defalias 'ps-face-strikeout-p 'ignore)
  118. (defalias 'ps-face-overline-p 'ignore)
  119. (defalias 'ps-face-box-p 'ignore)
  120. ;; XEmacs will have to make do with %s (princ) for floats.
  121. (defvar ps-color-format "%s %s %s")
  122. (defvar ps-float-format "%s ")
  123. (defun ps-generate-postscript-with-faces1 (from to)
  124. ;; Generate some PostScript.
  125. (let ((face 'default)
  126. (position to)
  127. ;; XEmacs
  128. ;; Build the list of extents...
  129. (a (cons 'dummy nil))
  130. record type extent extent-list)
  131. (map-extents 'ps-mapper nil from to a)
  132. (setq a (sort (cdr a) 'car-less-than-car)
  133. extent-list nil)
  134. ;; Loop through the extents...
  135. (while a
  136. (setq record (car a)
  137. position (car record)
  138. record (cdr record)
  139. type (car record)
  140. record (cdr record)
  141. extent (car record))
  142. ;; Plot up to this record.
  143. ;; XEmacs 19.12: for some reason, we're getting into a
  144. ;; situation in which some of the records have
  145. ;; positions less than 'from'. Since we've narrowed
  146. ;; the buffer, this'll generate errors. This is a hack,
  147. ;; but don't call ps-plot-with-face unless from > point-min.
  148. (and (>= from (point-min))
  149. (ps-plot-with-face from (min position (point-max)) face))
  150. (cond
  151. ((eq type 'push)
  152. (and (extent-face extent)
  153. (setq extent-list (sort (cons extent extent-list)
  154. 'ps-extent-sorter))))
  155. ((eq type 'pull)
  156. (setq extent-list (sort (delq extent extent-list)
  157. 'ps-extent-sorter))))
  158. (setq face (if extent-list
  159. (extent-face (car extent-list))
  160. 'default)
  161. from position
  162. a (cdr a)))
  163. (ps-plot-with-face from to face)))
  164. )
  165. (t ; Emacs
  166. ;; Do nothing
  167. )) ; end cond featurep
  168. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  169. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  170. ;; Emacs Definitions
  171. (cond
  172. ((featurep 'xemacs) ; XEmacs
  173. ;; Do nothing
  174. )
  175. (t ; Emacs
  176. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  177. ;; ps-print
  178. (defun ps-mark-active-p ()
  179. mark-active)
  180. (defun ps-face-foreground-name (face)
  181. (face-foreground face nil t))
  182. (defun ps-face-background-name (face)
  183. (face-background face nil t))
  184. (defalias 'ps-frame-parameter 'frame-parameter)
  185. ;; Return t if the device (which can be changed during an emacs session) can
  186. ;; handle colors. This function is not yet implemented for GNU emacs.
  187. (defun ps-color-device ()
  188. (if (fboundp 'color-values)
  189. (funcall 'color-values "Green")
  190. t))
  191. (defun ps-color-values (x-color)
  192. (cond
  193. ((fboundp 'color-values)
  194. (funcall 'color-values x-color))
  195. ((fboundp 'x-color-values)
  196. (funcall 'x-color-values x-color))
  197. (t
  198. (error "No available function to determine X color values"))))
  199. (defun ps-face-bold-p (face)
  200. (or (face-bold-p face)
  201. (memq face ps-bold-faces)))
  202. (defun ps-face-italic-p (face)
  203. (or (face-italic-p face)
  204. (memq face ps-italic-faces)))
  205. (defun ps-face-strikeout-p (face)
  206. (eq (face-attribute face :strike-through) t))
  207. (defun ps-face-overline-p (face)
  208. (eq (face-attribute face :overline) t))
  209. (defun ps-face-box-p (face)
  210. (not (memq (face-attribute face :box) '(nil unspecified))))
  211. ;; Emacs understands the %f format; we'll use it to limit color RGB values
  212. ;; to three decimals to cut down some on the size of the PostScript output.
  213. (defvar ps-color-format "%0.3f %0.3f %0.3f")
  214. (defvar ps-float-format "%0.3f ")
  215. (defun ps-generate-postscript-with-faces1 (from to)
  216. ;; Generate some PostScript.
  217. (let ((face 'default)
  218. (position to)
  219. ;; Emacs
  220. (property-change from)
  221. (overlay-change from)
  222. (save-buffer-invisibility-spec buffer-invisibility-spec)
  223. (buffer-invisibility-spec nil)
  224. before-string after-string)
  225. (while (< from to)
  226. (and (< property-change to) ; Don't search for property change
  227. ; unless previous search succeeded.
  228. (setq property-change (next-property-change from nil to)))
  229. (and (< overlay-change to) ; Don't search for overlay change
  230. ; unless previous search succeeded.
  231. (setq overlay-change (min (next-overlay-change from)
  232. to)))
  233. (setq position (min property-change overlay-change)
  234. before-string nil
  235. after-string nil)
  236. ;; The code below is not quite correct,
  237. ;; because a non-nil overlay invisible property
  238. ;; which is inactive according to the current value
  239. ;; of buffer-invisibility-spec nonetheless overrides
  240. ;; a face text property.
  241. (setq face
  242. (cond ((let ((prop (get-text-property from 'invisible)))
  243. ;; Decide whether this invisible property
  244. ;; really makes the text invisible.
  245. (if (eq save-buffer-invisibility-spec t)
  246. (not (null prop))
  247. (or (memq prop save-buffer-invisibility-spec)
  248. (assq prop save-buffer-invisibility-spec))))
  249. 'emacs--invisible--face)
  250. ((get-text-property from 'face))
  251. (t 'default)))
  252. (let ((overlays (overlays-at from))
  253. (face-priority -1)) ; text-property
  254. (while (and overlays
  255. (not (eq face 'emacs--invisible--face)))
  256. (let* ((overlay (car overlays))
  257. (overlay-invisible
  258. (overlay-get overlay 'invisible))
  259. (overlay-priority
  260. (or (overlay-get overlay 'priority) 0)))
  261. (and (> overlay-priority face-priority)
  262. (setq before-string
  263. (or (overlay-get overlay 'before-string)
  264. before-string)
  265. after-string
  266. (or (and (<= (overlay-end overlay) position)
  267. (overlay-get overlay 'after-string))
  268. after-string)
  269. face-priority overlay-priority
  270. face
  271. (cond
  272. ((if (eq save-buffer-invisibility-spec t)
  273. (not (null overlay-invisible))
  274. (or (memq overlay-invisible
  275. save-buffer-invisibility-spec)
  276. (assq overlay-invisible
  277. save-buffer-invisibility-spec)))
  278. 'emacs--invisible--face)
  279. ((overlay-get overlay 'face))
  280. (t face)
  281. ))))
  282. (setq overlays (cdr overlays))))
  283. ;; Plot up to this record.
  284. (and before-string
  285. (ps-plot-string before-string))
  286. (ps-plot-with-face from position face)
  287. (and after-string
  288. (ps-plot-string after-string))
  289. (setq from position))
  290. (ps-plot-with-face from to face)))
  291. )) ; end cond featurep
  292. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  293. (provide 'ps-def)
  294. ;;; ps-def.el ends here