Mercurial > emacs
comparison lisp/ps-print.el @ 11799:4a04c7799790
Miscellaneous fixes for better compatibility with
XEmacs 19.12.
(ps-plot-with-face): Added code to handle Emacs
19.29's new ability for the face attribute to hold a list of
faces.
Rolled in Chuck Thompson's changes to make color
printing work in XEmacs 19.12.
Fix error in comments.
(ps-generate-postscript-with-faces): Add fix to
handle extents without faces.
(ps-faces-list): deleted. Added alias for
list-faces if face-list isn't fbound.
(ps-print-ensure-fontified) added to make sure
ps-print works correctly in conjunction with lazy-lock.
RMS's changes for Emacs.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Fri, 12 May 1995 02:18:47 +0000 |
parents | e7d5b119b583 |
children | 68b1359ecd66 |
comparison
equal
deleted
inserted
replaced
11798:7646040d7383 | 11799:4a04c7799790 |
---|---|
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | 23 |
24 ;; LCD Archive Entry: | 24 ;; LCD Archive Entry: |
25 ;; ps-print|James C. Thompson|thompson@wg2.waii.com| | 25 ;; ps-print|James C. Thompson|thompson@wg2.waii.com| |
26 ;; Jim's Pretty-Good PostScript Generator for Emacs 19 (ps-print)| | 26 ;; Jim's Pretty-Good PostScript Generator for Emacs 19 (ps-print)| |
27 ;; 26-Feb-1994|2.0|~/packages/ps-print.el| | 27 ;; 26-Feb-1994|2.8|~/packages/ps-print.el| |
28 | 28 |
29 ;; Baseline-version: 2.0. (Jim's last change version -- this | 29 ;; Baseline-version: 2.8. (Jim's last change version -- this |
30 ;; file may have been edited as part of Emacs without changes to the | 30 ;; file may have been edited as part of Emacs without changes to the |
31 ;; version number. When reporting bugs, please also report the | 31 ;; version number. When reporting bugs, please also report the |
32 ;; version of Emacs, if any, that ps-print was distributed with.) | 32 ;; version of Emacs, if any, that ps-print was distributed with.) |
33 | 33 |
34 ;;; Commentary: | 34 ;;; Commentary: |
177 ;; contain lists of faces that ps-print should consider bold or | 177 ;; contain lists of faces that ps-print should consider bold or |
178 ;; italic; to set them, put code like the following into your .emacs | 178 ;; italic; to set them, put code like the following into your .emacs |
179 ;; file: | 179 ;; file: |
180 ;; | 180 ;; |
181 ;; (setq ps-bold-faces '(my-blue-face)) | 181 ;; (setq ps-bold-faces '(my-blue-face)) |
182 ;; (setq ps-red-faces '(my-red-face)) | 182 ;; (setq ps-italic-faces '(my-red-face)) |
183 ;; | |
184 ;; Faces like bold-italic that are both bold and italic should go in | |
185 ;; *both* lists. | |
183 ;; | 186 ;; |
184 ;; Ps-print does not attempt to guess the sizes of fonts; all text is | 187 ;; Ps-print does not attempt to guess the sizes of fonts; all text is |
185 ;; rendered using the Courier font family, in 10 point size. To | 188 ;; rendered using the Courier font family, in 10 point size. To |
186 ;; change the font family, change the variables ps-font, ps-font-bold, | 189 ;; change the font family, change the variables ps-font, ps-font-bold, |
187 ;; ps-font-italic, and ps-font-bold-italic; fixed-pitch fonts work | 190 ;; ps-font-italic, and ps-font-bold-italic; fixed-pitch fonts work |
338 ;; Better conformance to PostScript Document Structure Conventions. | 341 ;; Better conformance to PostScript Document Structure Conventions. |
339 ;; | 342 ;; |
340 ;; | 343 ;; |
341 ;; Known bugs and limitations of ps-print: | 344 ;; Known bugs and limitations of ps-print: |
342 ;; -------------------------------------- | 345 ;; -------------------------------------- |
346 ;; Although color printing will work in XEmacs 19.12, it doesn't work | |
347 ;; well; in particular, bold or italic fonts don't print in the right | |
348 ;; background color. | |
349 ;; | |
350 ;; Invisible properties aren't correctly ignored in XEmacs 19.12. | |
351 ;; | |
343 ;; Automatic font-attribute detection doesn't work well, especially | 352 ;; Automatic font-attribute detection doesn't work well, especially |
344 ;; with hilit19 and older versions of get-create-face. Users having | 353 ;; with hilit19 and older versions of get-create-face. Users having |
345 ;; problems with auto-font detection should use the lists ps-italic- | 354 ;; problems with auto-font detection should use the lists ps-italic- |
346 ;; faces and ps-bold-faces and/or turn off automatic detection by | 355 ;; faces and ps-bold-faces and/or turn off automatic detection by |
347 ;; setting ps-auto-font-detect to nil. | 356 ;; setting ps-auto-font-detect to nil. |
348 ;; | 357 ;; |
349 ;; Color output doesn't yet work in XEmacs. | 358 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12 |
359 ;; in tty mode; use the lists ps-italic-faces and ps-bold-faces | |
360 ;; instead. | |
350 ;; | 361 ;; |
351 ;; Still too slow; could use some hand-optimization. | 362 ;; Still too slow; could use some hand-optimization. |
352 ;; | 363 ;; |
353 ;; ASCII Control characters other than tab, linefeed and pagefeed are | 364 ;; ASCII Control characters other than tab, linefeed and pagefeed are |
354 ;; not handled. | 365 ;; not handled. |
394 ;; Jim | 405 ;; Jim |
395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
396 | 407 |
397 ;;; Code: | 408 ;;; Code: |
398 | 409 |
399 (defconst ps-print-version "2.0" | 410 (defconst ps-print-version "2.8" |
400 "ps-print.el,v 2.0 1995/02/12 04:39:48 jct Exp | 411 "ps-print.el,v 2.8 1995/05/04 12:06:10 jct Exp |
401 | 412 |
402 Jim's last change version -- this file may have been edited as part of | 413 Jim's last change version -- this file may have been edited as part of |
403 Emacs without changes to the version number. When reporting bugs, | 414 Emacs without changes to the version number. When reporting bugs, |
404 please also report the version of Emacs, if any, that ps-print was | 415 please also report the version of Emacs, if any, that ps-print was |
405 distributed with. | 416 distributed with. |
442 (defvar ps-show-n-of-n t | 453 (defvar ps-show-n-of-n t |
443 "*Non-nil means show page numbers as N/M, meaning page N of M. | 454 "*Non-nil means show page numbers as N/M, meaning page N of M. |
444 Note: page numbers are displayed as part of headers, see variable | 455 Note: page numbers are displayed as part of headers, see variable |
445 `ps-print-headers'.") | 456 `ps-print-headers'.") |
446 | 457 |
447 (defvar ps-print-color-p (and (fboundp 'x-color-values) | 458 (defvar ps-print-color-p (and (or (fboundp 'x-color-values) ; fsf |
459 (fboundp 'pixel-components)) ; xemacs | |
448 (fboundp 'float)) | 460 (fboundp 'float)) |
449 ; Printing color requires both floating point and x-color-values. | 461 ; Printing color requires both floating point and x-color-values. |
450 "*If non-nil, print the buffer's text in color.") | 462 "*If non-nil, print the buffer's text in color.") |
451 | 463 |
452 (defvar ps-default-fg '(0.0 0.0 0.0) | 464 (defvar ps-default-fg '(0.0 0.0 0.0) |
701 ((string-match "Epoch" emacs-version) 'epoch) | 713 ((string-match "Epoch" emacs-version) 'epoch) |
702 (t 'fsf)))) | 714 (t 'fsf)))) |
703 | 715 |
704 (if (or (eq emacs-type 'lucid) | 716 (if (or (eq emacs-type 'lucid) |
705 (eq emacs-type 'xemacs)) | 717 (eq emacs-type 'xemacs)) |
706 (setq ps-print-color-p nil) | 718 (if (< emacs-minor-version 12) |
719 (setq ps-print-color-p nil)) | |
707 (require 'faces)) ; face-font, face-underline-p, | 720 (require 'faces)) ; face-font, face-underline-p, |
708 ; x-font-regexp | 721 ; x-font-regexp |
709 | 722 |
710 (require 'time-stamp) | 723 (require 'time-stamp) |
711 | 724 |
1470 " true BG\n") | 1483 " true BG\n") |
1471 (ps-output "false BG\n"))) | 1484 (ps-output "false BG\n"))) |
1472 | 1485 |
1473 (defun ps-set-color (color) | 1486 (defun ps-set-color (color) |
1474 (if (setq ps-current-color color) | 1487 (if (setq ps-current-color color) |
1475 (ps-output (format ps-color-format (nth 0 ps-current-color) | 1488 nil |
1476 (nth 1 ps-current-color) (nth 2 ps-current-color)) | 1489 (setq ps-current-color ps-default-fg)) |
1477 " FG\n"))) | 1490 (ps-output (format ps-color-format (nth 0 ps-current-color) |
1491 (nth 1 ps-current-color) (nth 2 ps-current-color)) | |
1492 " FG\n")) | |
1478 | 1493 |
1479 (defun ps-set-underline (underline-p) | 1494 (defun ps-set-underline (underline-p) |
1480 (ps-output (if underline-p "true" "false") " UL\n") | 1495 (ps-output (if underline-p "true" "false") " UL\n") |
1481 (setq ps-current-underline-p underline-p)) | 1496 (setq ps-current-underline-p underline-p)) |
1482 | 1497 |
1535 | 1550 |
1536 (defun ps-color-value (x-color-value) | 1551 (defun ps-color-value (x-color-value) |
1537 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval. | 1552 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval. |
1538 (/ x-color-value ps-print-color-scale)) | 1553 (/ x-color-value ps-print-color-scale)) |
1539 | 1554 |
1555 (defun ps-color-values (x-color) | |
1556 (cond ((fboundp 'x-color-values) | |
1557 (x-color-values x-color)) | |
1558 ((fboundp 'pixel-components) | |
1559 (pixel-components x-color)) | |
1560 (t (error "No available function to determine X color values.")))) | |
1561 | |
1562 (defun ps-face-attributes (face) | |
1563 (let ((differs (face-differs-from-default-p face))) | |
1564 (list (memq face ps-ref-bold-faces) | |
1565 (memq face ps-ref-italic-faces) | |
1566 (memq face ps-ref-underlined-faces) | |
1567 (and differs (face-foreground face)) | |
1568 (and differs (face-background face))))) | |
1569 | |
1570 (defun ps-face-attribute-list (face-or-list) | |
1571 (if (listp face-or-list) | |
1572 (let (bold-p italic-p underline-p foreground background face-attr face) | |
1573 (while face-or-list | |
1574 (setq face (car face-or-list)) | |
1575 (setq face-attr (ps-face-attributes face)) | |
1576 (setq bold-p (or bold-p (nth 0 face-attr))) | |
1577 (setq italic-p (or italic-p (nth 1 face-attr))) | |
1578 (setq underline-p (or underline-p (nth 2 face-attr))) | |
1579 (if foreground | |
1580 nil | |
1581 (setq foreground (nth 3 face-attr))) | |
1582 (if background | |
1583 nil | |
1584 (setq background (nth 4 face-attr))) | |
1585 (setq face-or-list (cdr face-or-list))) | |
1586 (list bold-p italic-p underline-p foreground background)) | |
1587 | |
1588 (ps-face-attributes face-or-list))) | |
1589 | |
1540 (defun ps-plot-with-face (from to face) | 1590 (defun ps-plot-with-face (from to face) |
1541 (if face | 1591 (if face |
1542 (let* ((bold-p (memq face ps-ref-bold-faces)) | 1592 (let* ((face-attr (ps-face-attribute-list face)) |
1543 (italic-p (memq face ps-ref-italic-faces)) | 1593 (bold-p (nth 0 face-attr)) |
1544 (underline-p (memq face ps-ref-underlined-faces)) | 1594 (italic-p (nth 1 face-attr)) |
1545 (foreground (face-foreground face)) | 1595 (underline-p (nth 2 face-attr)) |
1546 (background (face-background face)) | 1596 (foreground (nth 3 face-attr)) |
1597 (background (nth 4 face-attr)) | |
1547 (fg-color (if (and ps-print-color-p foreground) | 1598 (fg-color (if (and ps-print-color-p foreground) |
1548 (mapcar 'ps-color-value | 1599 (mapcar 'ps-color-value |
1549 (x-color-values foreground)) | 1600 (ps-color-values foreground)) |
1550 ps-default-color)) | 1601 ps-default-color)) |
1551 (bg-color (if (and ps-print-color-p background) | 1602 (bg-color (if (and ps-print-color-p background) |
1552 (mapcar 'ps-color-value | 1603 (mapcar 'ps-color-value |
1553 (x-color-values background))))) | 1604 (ps-color-values background))))) |
1554 (ps-plot-region from to | 1605 (ps-plot-region from to |
1555 (cond ((and bold-p italic-p) 3) | 1606 (cond ((and bold-p italic-p) 3) |
1556 (italic-p 2) | 1607 (italic-p 2) |
1557 (bold-p 1) | 1608 (bold-p 1) |
1558 (t 0)) | 1609 (t 0)) |
1599 | 1650 |
1600 (defun ps-face-underlined-p (face) | 1651 (defun ps-face-underlined-p (face) |
1601 (or (face-underline-p face) | 1652 (or (face-underline-p face) |
1602 (memq face ps-underlined-faces))) | 1653 (memq face ps-underlined-faces))) |
1603 | 1654 |
1604 (defun ps-faces-list () | 1655 ;; Ensure that face-list is fbound. |
1605 (if (or (eq emacs-type 'lucid) (eq emacs-type 'xemacs)) | 1656 (or (fboundp 'face-list) (defalias 'face-list 'list-faces)) |
1606 (list-faces) | |
1607 (face-list))) | |
1608 | 1657 |
1609 (defun ps-build-reference-face-lists () | 1658 (defun ps-build-reference-face-lists () |
1610 (if ps-auto-font-detect | 1659 (if ps-auto-font-detect |
1611 (let ((faces (ps-faces-list)) | 1660 (let ((faces (face-list)) |
1612 the-face) | 1661 the-face) |
1613 (setq ps-ref-bold-faces nil | 1662 (setq ps-ref-bold-faces nil |
1614 ps-ref-italic-faces nil | 1663 ps-ref-italic-faces nil |
1615 ps-ref-underlined-faces nil) | 1664 ps-ref-underlined-faces nil) |
1616 (while faces | 1665 (while faces |
1638 (defun ps-sorter (a b) | 1687 (defun ps-sorter (a b) |
1639 (< (car a) (car b))) | 1688 (< (car a) (car b))) |
1640 | 1689 |
1641 (defun ps-extent-sorter (a b) | 1690 (defun ps-extent-sorter (a b) |
1642 (< (extent-priority a) (extent-priority b))) | 1691 (< (extent-priority a) (extent-priority b))) |
1643 | 1692 |
1693 (defun ps-print-ensure-fontified (start end) | |
1694 (if (and (boundp 'lazy-lock-mode) lazy-lock-mode) | |
1695 (if (fboundp 'lazy-lock-fontify-region) | |
1696 (lazy-lock-fontify-region start end) | |
1697 (lazy-lock-fontify-buffer)))) | |
1698 | |
1644 (defun ps-generate-postscript-with-faces (from to) | 1699 (defun ps-generate-postscript-with-faces (from to) |
1645 ;; Build the reference lists of faces if necessary. | 1700 ;; Build the reference lists of faces if necessary. |
1646 (if (or ps-always-build-face-reference | 1701 (if (or ps-always-build-face-reference |
1647 ps-build-face-reference) | 1702 ps-build-face-reference) |
1648 (progn | 1703 (progn |
1651 ;; Set the color scale. We do it here instead of in the defvar so | 1706 ;; Set the color scale. We do it here instead of in the defvar so |
1652 ;; that ps-print can be dumped into emacs. This expression can't be | 1707 ;; that ps-print can be dumped into emacs. This expression can't be |
1653 ;; evaluated at dump-time because X isn't initialized. | 1708 ;; evaluated at dump-time because X isn't initialized. |
1654 (setq ps-print-color-scale | 1709 (setq ps-print-color-scale |
1655 (if ps-print-color-p | 1710 (if ps-print-color-p |
1656 (float (car (x-color-values "white"))) | 1711 (float (car (ps-color-values "white"))) |
1657 1.0)) | 1712 1.0)) |
1658 ;; Generate some PostScript. | 1713 ;; Generate some PostScript. |
1659 (save-restriction | 1714 (save-restriction |
1660 (narrow-to-region from to) | 1715 (narrow-to-region from to) |
1661 (let ((face 'default) | 1716 (let ((face 'default) |
1662 (position to)) | 1717 (position to)) |
1718 (ps-print-ensure-fontified from to) | |
1663 (cond ((or (eq emacs-type 'lucid) (eq emacs-type 'xemacs)) | 1719 (cond ((or (eq emacs-type 'lucid) (eq emacs-type 'xemacs)) |
1664 ;; Build the list of extents... | 1720 ;; Build the list of extents... |
1665 (let ((a (cons 'dummy nil)) | 1721 (let ((a (cons 'dummy nil)) |
1666 record type extent extent-list) | 1722 record type extent extent-list) |
1667 (map-extents 'ps-mapper nil from to a) | 1723 (map-extents 'ps-mapper nil from to a) |
1681 (setq record (cdr record)) | 1737 (setq record (cdr record)) |
1682 | 1738 |
1683 (setq extent (car record)) | 1739 (setq extent (car record)) |
1684 | 1740 |
1685 ;; Plot up to this record. | 1741 ;; Plot up to this record. |
1686 (ps-plot-with-face from position face) | 1742 ;; XEmacs 19.12: for some reason, we're getting into a |
1743 ;; situation in which some of the records have | |
1744 ;; positions less than 'from'. Since we've narrowed | |
1745 ;; the buffer, this'll generate errors. This is a | |
1746 ;; hack, but don't call ps-plot-with-face unless from > | |
1747 ;; point-min. | |
1748 (if (and (>= from (point-min)) | |
1749 (<= position (point-max))) | |
1750 (ps-plot-with-face from position face)) | |
1687 | 1751 |
1688 (cond | 1752 (cond |
1689 ((eq type 'push) | 1753 ((eq type 'push) |
1690 (setq extent-list (sort (cons extent extent-list) | 1754 (if (extent-face extent) |
1691 'ps-extent-sorter))) | 1755 (setq extent-list (sort (cons extent extent-list) |
1756 'ps-extent-sorter)))) | |
1692 | 1757 |
1693 ((eq type 'pull) | 1758 ((eq type 'pull) |
1694 (setq extent-list (sort (delq extent extent-list) | 1759 (setq extent-list (sort (delq extent extent-list) |
1695 'ps-extent-sorter)))) | 1760 'ps-extent-sorter)))) |
1696 | 1761 |
1854 | 1919 |
1855 ;; This stuff is for anybody that's brave enough to look this far, | 1920 ;; This stuff is for anybody that's brave enough to look this far, |
1856 ;; and able to figure out how to use it. It isn't really part of ps- | 1921 ;; and able to figure out how to use it. It isn't really part of ps- |
1857 ;; print, but I'll leave it here in hopes it might be useful: | 1922 ;; print, but I'll leave it here in hopes it might be useful: |
1858 | 1923 |
1924 ;; WARNING!!! The following code is *sample* code only. Don't use it | |
1925 ;; unless you understand what it does! | |
1926 | |
1859 (defmacro ps-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [f22] ''f22)) | 1927 (defmacro ps-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [f22] ''f22)) |
1860 (defmacro ps-c-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [C-f22] | 1928 (defmacro ps-c-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [C-f22] |
1861 ''(control f22))) | 1929 ''(control f22))) |
1862 (defmacro ps-s-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [S-f22] | 1930 (defmacro ps-s-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [S-f22] |
1863 ''(shift f22))) | 1931 ''(shift f22))) |
1965 | 2033 |
1966 (defun ps-info-mode-hook () | 2034 (defun ps-info-mode-hook () |
1967 (setq ps-left-header | 2035 (setq ps-left-header |
1968 ;; The left headers will display the node name and file name. | 2036 ;; The left headers will display the node name and file name. |
1969 (list 'ps-info-node 'ps-info-file))) | 2037 (list 'ps-info-node 'ps-info-file))) |
2038 | |
2039 ;; WARNING! The following function is a *sample* only, and is *not* | |
2040 ;; meant to be used as a whole unless you understand what the effects | |
2041 ;; will be! (In fact, this is a copy if my setup for ps-print -- I'd | |
2042 ;; be very surprised if it was useful to *anybody*, without | |
2043 ;; modification.) | |
1970 | 2044 |
1971 (defun ps-jts-ps-setup () | 2045 (defun ps-jts-ps-setup () |
1972 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc | 2046 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc |
1973 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces) | 2047 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces) |
1974 (global-set-key (ps-c-prsc) 'ps-despool) | 2048 (global-set-key (ps-c-prsc) 'ps-despool) |