comparison lisp/ps-print.el @ 89531:f035500271d2

(ps-generate-string-list): Function deleted. (ps-rh-cache, ps-lf-cache, ps-rf-cache): Variables deleted. (ps-header-footer-string): Function deleted. (ps-encode-header-string-function): New variable (ps-generate-header-line): Call ps-encode-header-string-function. (ps-basic-plot-string-function): New variable (ps-begin-job): Set ps-basic-plot-string-function and ps-encode-header-string-function. For setting up headers and footers, don't use caches such as ps-rh-cache. Don't call ps-mule-begin-page. (ps-basic-plot-str): Don't call ps-mule-prepare-ascii-font. (ps-basic-plot-string): Likewise. (ps-control-character): Likewise. (ps-plot-region): Don't pay attention to composition and non-ASCII characters. (ps-generate): Call ps-mule-end-job. (ps-mule-prepare-ascii-font): Delete autoload. (ps-mule-set-ascii-font): Likewise. (ps-mule-plot-string): Likewise. (ps-mule-begin-page): Likewise. (ps-mule-end-job): Declare autoload.
author Kenichi Handa <handa@m17n.org>
date Fri, 26 Sep 2003 11:59:31 +0000
parents 375f2633d815
children 68c22ea6027c
comparison
equal deleted inserted replaced
89530:498e5353548a 89531:f035500271d2
4664 (save-excursion 4664 (save-excursion
4665 (set-buffer ps-spool-buffer) 4665 (set-buffer ps-spool-buffer)
4666 (goto-char (point-max)) 4666 (goto-char (point-max))
4667 (insert-file fname))) 4667 (insert-file fname)))
4668 4668
4669 ;; These functions are used in `ps-mule' to get charset of header and footer.
4670 ;; To avoid unnecessary calls to functions in `ps-left-header',
4671 ;; `ps-right-header', `ps-left-footer' and `ps-right-footer'.
4672
4673 (defun ps-generate-string-list (content)
4674 (let (str)
4675 (while content
4676 (setq str (cons (cond
4677 ((stringp (car content))
4678 (car content))
4679 ((and (symbolp (car content)) (fboundp (car content)))
4680 (concat "(" (funcall (car content)) ")"))
4681 ((and (symbolp (car content)) (boundp (car content)))
4682 (concat "(" (symbol-value (car content)) ")"))
4683 (t
4684 ""))
4685 str)
4686 content (cdr content)))
4687 (nreverse str)))
4688
4689 (defvar ps-lh-cache nil)
4690 (defvar ps-rh-cache nil)
4691 (defvar ps-lf-cache nil)
4692 (defvar ps-rf-cache nil)
4693
4694 (defun ps-header-footer-string ()
4695 (and ps-print-header
4696 (setq ps-lh-cache (ps-generate-string-list ps-left-header)
4697 ps-rh-cache (ps-generate-string-list ps-right-header)))
4698 (and ps-print-footer
4699 (setq ps-lf-cache (ps-generate-string-list ps-left-footer)
4700 ps-rf-cache (ps-generate-string-list ps-right-footer)))
4701 (mapconcat 'identity
4702 (append ps-lh-cache ps-rh-cache ps-lf-cache ps-rf-cache)
4703 ""))
4704
4705 ;; These functions insert the arrays that define the contents of the headers. 4669 ;; These functions insert the arrays that define the contents of the headers.
4670
4671 (defvar ps-encode-header-string-function nil)
4706 4672
4707 (defun ps-generate-header-line (fonttag &optional content) 4673 (defun ps-generate-header-line (fonttag &optional content)
4708 (ps-output " [" fonttag " ") 4674 (ps-output " [" fonttag " ")
4709 (cond 4675 (cond
4710 ;; Literal strings should be output as is -- the string must contain its own 4676 ;; Literal strings should be output as is -- the string must contain its own
4711 ;; PS string delimiters, '(' and ')', if necessary. 4677 ;; PS string delimiters, '(' and ')', if necessary.
4712 ((stringp content) 4678 ((stringp content)
4713 (ps-output (ps-mule-encode-header-string content fonttag))) 4679 (ps-output content))
4714 4680
4715 ;; Functions are called -- they should return strings; they will be inserted 4681 ;; Functions are called -- they should return strings; they will be inserted
4716 ;; as strings and the PS string delimiters added. 4682 ;; as strings and the PS string delimiters added.
4717 ((and (symbolp content) (fboundp content)) 4683 ((and (symbolp content) (fboundp content))
4718 (ps-output-string (ps-mule-encode-header-string (funcall content) 4684 (if (fboundp ps-encode-header-string-function)
4719 fonttag))) 4685 (dolist (l (funcall ps-encode-header-string-function
4686 (funcall content) fonttag))
4687 (ps-output-string l))
4688 (ps-output-string (funcall content))))
4720 4689
4721 ;; Variables will have their contents inserted. They should contain 4690 ;; Variables will have their contents inserted. They should contain
4722 ;; strings, and will be inserted as strings. 4691 ;; strings, and will be inserted as strings.
4723 ((and (symbolp content) (boundp content)) 4692 ((and (symbolp content) (boundp content))
4724 (ps-output-string (ps-mule-encode-header-string (symbol-value content) 4693 (if (fboundp ps-encode-header-string-function)
4725 fonttag))) 4694 (dolist (l (funcall ps-encode-header-string-function
4695 (symbol-value content) fonttag))
4696 (ps-output-string l))
4697 (ps-output-string (symbol-value content))))
4726 4698
4727 ;; Anything else will get turned into an empty string. 4699 ;; Anything else will get turned into an empty string.
4728 (t 4700 (t
4729 (ps-output-string ""))) 4701 (ps-output-string "")))
4730 (ps-output "]\n")) 4702 (ps-output "]\n"))
5674 (list color color color)) 5646 (list color color color))
5675 ((stringp color) (ps-color-scale color)) 5647 ((stringp color) (ps-color-scale color))
5676 (t (list default default default)) 5648 (t (list default default default))
5677 )) 5649 ))
5678 5650
5651 (defvar ps-basic-plot-string-function 'ps-basic-plot-string)
5679 5652
5680 (defun ps-begin-job () 5653 (defun ps-begin-job ()
5681 ;; prologue files 5654 ;; prologue files
5682 (or (equal ps-mark-code-directory ps-postscript-code-directory) 5655 (or (equal ps-mark-code-directory ps-postscript-code-directory)
5683 (setq ps-print-prologue-0 (ps-prologue-file 0) 5656 (setq ps-print-prologue-0 (ps-prologue-file 0)
5762 ;; that ps-print can be dumped into emacs. This expression can't be 5735 ;; that ps-print can be dumped into emacs. This expression can't be
5763 ;; evaluated at dump-time because X isn't initialized. 5736 ;; evaluated at dump-time because X isn't initialized.
5764 ps-color-p (and ps-print-color-p (ps-color-device)) 5737 ps-color-p (and ps-print-color-p (ps-color-device))
5765 ps-print-color-scale (if ps-color-p 5738 ps-print-color-scale (if ps-color-p
5766 (float (car (ps-color-values "white"))) 5739 (float (car (ps-color-values "white")))
5767 1.0)) 5740 1.0)
5741 ;; Set up default functions. They may be overridden by
5742 ;; ps-mule-begin-job.
5743 ps-basic-plot-string-function 'ps-basic-plot-string
5744 ps-encode-header-string-function nil)
5768 ;; initialize page dimensions 5745 ;; initialize page dimensions
5769 (ps-get-page-dimensions) 5746 (ps-get-page-dimensions)
5770 ;; final check 5747 ;; final check
5771 (and ps-color-p 5748 (and ps-color-p
5772 (equal ps-default-background ps-default-foreground) 5749 (equal ps-default-background ps-default-foreground)
5843 5820
5844 (ps-output (format "/LineNumber %d def\n" ps-showline-count) 5821 (ps-output (format "/LineNumber %d def\n" ps-showline-count)
5845 (format "/PageNumber %d def\n" (ps-page-number))) 5822 (format "/PageNumber %d def\n" (ps-page-number)))
5846 5823
5847 (when ps-print-header 5824 (when ps-print-header
5848 (ps-generate-header "HeaderLinesLeft" "/h0" "/h1" 5825 (ps-generate-header "HeaderLinesLeft" "/h0" "/h1" ps-left-header)
5849 (or ps-lh-cache ps-left-header)) 5826 (ps-generate-header "HeaderLinesRight" "/h0" "/h1" ps-right-header)
5850 (ps-generate-header "HeaderLinesRight" "/h0" "/h1" 5827 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
5851 (or ps-rh-cache ps-right-header))
5852 (ps-output (format "%d SetHeaderLines\n" ps-header-lines))
5853 (setq ps-lh-cache nil
5854 ps-rh-cache nil))
5855 5828
5856 (when ps-print-footer 5829 (when ps-print-footer
5857 (ps-generate-header "FooterLinesLeft" "/H0" "/H0" 5830 (ps-generate-header "FooterLinesLeft" "/H0" "/H0" ps-left-footer)
5858 (or ps-lf-cache ps-left-footer)) 5831 (ps-generate-header "FooterLinesRight" "/H0" "/H0" ps-right-footer)
5859 (ps-generate-header "FooterLinesRight" "/H0" "/H0" 5832 (ps-output (format "%d SetFooterLines\n" ps-footer-lines)))
5860 (or ps-rf-cache ps-right-footer))
5861 (ps-output (format "%d SetFooterLines\n" ps-footer-lines))
5862 (setq ps-lf-cache nil
5863 ps-rf-cache nil))
5864 5833
5865 (ps-output (number-to-string ps-lines-printed) " BeginPage\n") 5834 (ps-output (number-to-string ps-lines-printed) " BeginPage\n")
5866 (ps-set-font ps-current-font) 5835 (ps-set-font ps-current-font)
5867 (ps-set-bg ps-current-bg) 5836 (ps-set-bg ps-current-bg)
5868 (ps-set-color ps-current-color) 5837 (ps-set-color ps-current-color))
5869 (ps-mule-begin-page))
5870 5838
5871 (defsubst ps-skip-newline (limit) 5839 (defsubst ps-skip-newline (limit)
5872 (setq ps-showline-count (1+ ps-showline-count) 5840 (setq ps-showline-count (1+ ps-showline-count)
5873 ps-lines-printed (1+ ps-lines-printed)) 5841 ps-lines-printed (1+ ps-lines-printed))
5874 (and (< (point) limit) 5842 (and (< (point) limit)
5908 (defun ps-basic-plot-str (from to string) 5876 (defun ps-basic-plot-str (from to string)
5909 (let* ((wrappoint (ps-find-wrappoint from to 5877 (let* ((wrappoint (ps-find-wrappoint from to
5910 (ps-avg-char-width 'ps-font-for-text))) 5878 (ps-avg-char-width 'ps-font-for-text)))
5911 (to (car wrappoint)) 5879 (to (car wrappoint))
5912 (str (substring string from to))) 5880 (str (substring string from to)))
5913 (ps-mule-prepare-ascii-font str)
5914 (ps-output-string str) 5881 (ps-output-string str)
5915 (ps-output " S\n") 5882 (ps-output " S\n")
5916 wrappoint)) 5883 wrappoint))
5917 5884
5918 (defun ps-basic-plot-string (from to &optional bg-color) 5885 (defun ps-basic-plot-string (from to &optional bg-color)
5919 (let* ((wrappoint (ps-find-wrappoint from to 5886 (let* ((wrappoint (ps-find-wrappoint from to
5920 (ps-avg-char-width 'ps-font-for-text))) 5887 (ps-avg-char-width 'ps-font-for-text)))
5921 (to (car wrappoint)) 5888 (to (car wrappoint))
5922 (string (buffer-substring-no-properties from to))) 5889 (string (buffer-substring-no-properties from to)))
5923 (ps-mule-prepare-ascii-font string)
5924 (ps-output-string string) 5890 (ps-output-string string)
5925 (ps-output " S\n") 5891 (ps-output " S\n")
5926 wrappoint)) 5892 wrappoint))
5927 5893
5928 (defun ps-basic-plot-whitespace (from to &optional bg-color) 5894 (defun ps-basic-plot-whitespace (from to &optional bg-color)
6022 (forward-char 1)) 5988 (forward-char 1))
6023 (setq from (point)))) 5989 (setq from (point))))
6024 (if (re-search-forward ps-control-or-escape-regexp to t) 5990 (if (re-search-forward ps-control-or-escape-regexp to t)
6025 ;; region with some control characters or some multi-byte characters 5991 ;; region with some control characters or some multi-byte characters
6026 (let* ((match-point (match-beginning 0)) 5992 (let* ((match-point (match-beginning 0))
6027 (match (char-after match-point)) 5993 (match (char-after match-point)))
6028 (composition (ps-e-find-composition from (1+ match-point))))
6029 (if composition
6030 (if (and (nth 2 composition)
6031 (<= (car composition) match-point))
6032 (progn
6033 (setq match-point (car composition)
6034 match 0)
6035 (goto-char (nth 1 composition)))
6036 (setq composition nil)))
6037 (when (< from match-point) 5994 (when (< from match-point)
6038 (ps-mule-set-ascii-font) 5995 (ps-plot ps-basic-plot-string-function
6039 (ps-plot 'ps-basic-plot-string from match-point bg-color)) 5996 from match-point bg-color))
6040 (cond 5997 (cond
6041 ((= match ?\t) ; tab 5998 ((= match ?\t) ; tab
6042 (let ((linestart (line-beginning-position))) 5999 (let ((linestart (line-beginning-position)))
6043 (forward-char -1) 6000 (forward-char -1)
6044 (setq from (+ linestart (current-column))) 6001 (setq from (+ linestart (current-column)))
6045 (when (re-search-forward "[ \t]+" to t) 6002 (when (re-search-forward "[ \t]+" to t)
6046 (ps-mule-set-ascii-font)
6047 (ps-plot 'ps-basic-plot-whitespace 6003 (ps-plot 'ps-basic-plot-whitespace
6048 from (+ linestart (current-column)) 6004 from (+ linestart (current-column))
6049 bg-color)))) 6005 bg-color))))
6050 6006
6051 ((= match ?\n) ; newline 6007 ((= match ?\n) ; newline
6066 ;; \f\n ==>> skip \n, but keep line counting!! 6022 ;; \f\n ==>> skip \n, but keep line counting!!
6067 (and (equal (following-char) ?\n) 6023 (and (equal (following-char) ?\n)
6068 (ps-skip-newline to)) 6024 (ps-skip-newline to))
6069 (ps-next-page))) 6025 (ps-next-page)))
6070 6026
6071 (composition ; a composite sequence
6072 (ps-plot 'ps-mule-plot-composition match-point (point) bg-color))
6073
6074 ((> match 255) ; a multi-byte character
6075 (let* ((charset (char-charset match))
6076 (composition (ps-e-find-composition match-point to))
6077 (stop (if (nth 2 composition) (car composition) to)))
6078 (or (eq charset 'composition)
6079 (while (and (< (point) stop) (eq (charset-after) charset))
6080 (forward-char 1)))
6081 (ps-plot 'ps-mule-plot-string match-point (point) bg-color)))
6082 ; characters from ^@ to ^_ and
6083 (t ; characters from 127 to 255 6027 (t ; characters from 127 to 255
6084 (ps-control-character match))) 6028 (ps-control-character match)))
6085 (setq from (point))) 6029 (setq from (point)))
6086 ;; region without control characters nor multi-byte characters 6030 ;; region without control characters
6087 (ps-mule-set-ascii-font) 6031 (ps-plot ps-basic-plot-string-function from to bg-color)
6088 (ps-plot 'ps-basic-plot-string from to bg-color)
6089 (setq from to))))) 6032 (setq from to)))))
6090 6033
6091 (defvar ps-string-control-codes 6034 (defvar ps-string-control-codes
6092 (let ((table (make-vector 256 nil)) 6035 (let ((table (make-vector 256 nil))
6093 (char ?\000)) 6036 (char ?\000))
6115 (char-width (ps-avg-char-width 'ps-font-for-text)) 6058 (char-width (ps-avg-char-width 'ps-font-for-text))
6116 (wrappoint (ps-find-wrappoint from to char-width))) 6059 (wrappoint (ps-find-wrappoint from to char-width)))
6117 (if (< (car wrappoint) to) 6060 (if (< (car wrappoint) to)
6118 (ps-continue-line)) 6061 (ps-continue-line))
6119 (setq ps-width-remaining (- ps-width-remaining (* len char-width))) 6062 (setq ps-width-remaining (- ps-width-remaining (* len char-width)))
6120 (ps-mule-prepare-ascii-font str)
6121 (ps-output-string str) 6063 (ps-output-string str)
6122 (ps-output " S\n"))) 6064 (ps-output " S\n")))
6123 6065
6124 6066
6125 (defun ps-face-attributes (face) 6067 (defun ps-face-attributes (face)
6478 (ps-mule-begin-job from to) 6420 (ps-mule-begin-job from to)
6479 (ps-selected-pages))) 6421 (ps-selected-pages)))
6480 (ps-begin-page) 6422 (ps-begin-page)
6481 (funcall genfunc from to) 6423 (funcall genfunc from to)
6482 (ps-end-page) 6424 (ps-end-page)
6425 (ps-mule-end-job)
6483 (ps-end-job needs-begin-file) 6426 (ps-end-job needs-begin-file)
6484 6427
6485 ;; Setting this variable tells the unwind form that the 6428 ;; Setting this variable tells the unwind form that the
6486 ;; the PostScript was generated without error. 6429 ;; the PostScript was generated without error.
6487 (setq completed-safely t)) 6430 (setq completed-safely t))
6829 6772
6830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 6773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6831 ;; To make this file smaller, some commands go in a separate file. 6774 ;; To make this file smaller, some commands go in a separate file.
6832 ;; But autoload them here to make the separation invisible. 6775 ;; But autoload them here to make the separation invisible.
6833 6776
6834 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
6835 "Setup special ASCII font for STRING.
6836 STRING should contain only ASCII characters.")
6837
6838 (autoload 'ps-mule-set-ascii-font "ps-mule"
6839 "Adjust current font if current charset is not ASCII.")
6840
6841 (autoload 'ps-mule-plot-string "ps-mule"
6842 "Generate PostScript code for plotting characters in the region FROM and TO.
6843
6844 It is assumed that all characters in this region belong to the same charset.
6845
6846 Optional argument BG-COLOR specifies background color.
6847
6848 Returns the value:
6849
6850 (ENDPOS . RUN-WIDTH)
6851
6852 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
6853 the sequence.")
6854
6855 (autoload 'ps-mule-initialize "ps-mule" 6777 (autoload 'ps-mule-initialize "ps-mule"
6856 "Initialize global data for printing multi-byte characters.") 6778 "Initialize global data for printing multi-byte characters.")
6857 6779
6858 (autoload 'ps-mule-begin-job "ps-mule" 6780 (autoload 'ps-mule-begin-job "ps-mule"
6859 "Start printing job for multi-byte chars between FROM and TO. 6781 "Start printing job for multi-byte chars between FROM and TO.
6860 This checks if all multi-byte characters in the region are printable or not.") 6782 This checks if all multi-byte characters in the region are printable or not.")
6861 6783
6862 (autoload 'ps-mule-begin-page "ps-mule" 6784 (autoload 'ps-mule-begin-page "ps-mule"
6863 "Initialize multi-byte charset for printing current page.") 6785 "Initialize multi-byte charset for printing current page.")
6864 6786
6865 (autoload 'ps-mule-encode-header-string "ps-mule" 6787 (autoload 'ps-mule-end-job "ps-mule"
6866 "Generate PostScript code for plotting characters in header STRING. 6788 "Finish printing job for multi-byte chars.")
6867
6868 It is assumed that the length of STRING is not zero.")
6869 6789
6870 6790
6871 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 6791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6872 6792
6873 (provide 'ps-print) 6793 (provide 'ps-print)