comparison lisp/ps-print.el @ 23167:ada869918064

(ps-mule-font-info-database-bdf): The include ASCII entry and change Latin-1 entry in the default value. (ps-mule-font-info-database-ps-bdf): New variable. (ccl-encode-ethio-unicode): Bug of CCL code fixed. (ps-mule-generate-font): Give CHARSET arg to FONT-FUNC function registerd in FONT-SPEC. (ps-mule-bitmap-prologue): Fix PostScript code to realize correct charcter width of bitmap fonts. (ps-mule-generate-bitmap-font): Give COLUMNS arg to PostScript procedure NF. (ps-begin-file): Output PostScript code for setting SpaceWidthRatio. (ps-plot-region): Use line-beginning-position to get a position of the beginning of the current line.
author Kenichi Handa <handa@m17n.org>
date Wed, 02 Sep 1998 04:51:42 +0000
parents 14e74d2a49cb
children 70e635407161
comparison
equal deleted inserted replaced
23166:6072f28afec9 23167:ada869918064
2879 "Sample setting of the `ps-mule-font-info-database' to use builtin PS font. 2879 "Sample setting of the `ps-mule-font-info-database' to use builtin PS font.
2880 2880
2881 Currently, data for Japanese and Korean PostScript printers are listed.") 2881 Currently, data for Japanese and Korean PostScript printers are listed.")
2882 2882
2883 (defconst ps-mule-font-info-database-bdf 2883 (defconst ps-mule-font-info-database-bdf
2884 '(;;(ascii 2884 '((ascii
2885 ;; (normal bdf "etl24-latin1.bdf" nil 1) 2885 (normal bdf "etl24-latin1.bdf" nil 1)
2886 ;; (bold bdf "etl16b-latin1.bdf" iso-latin-1 1) 2886 (bold bdf "etl16b-latin1.bdf" iso-latin-1 1)
2887 ;; (italic bdf "etl16i-latin1.bdf" iso-latin-1 1) 2887 (italic bdf "etl16i-latin1.bdf" iso-latin-1 1)
2888 ;; (bold-italic bdf "etl16bi-latin1.bdf" iso-latin-1 1)) 2888 (bold-italic bdf "etl16bi-latin1.bdf" iso-latin-1 1))
2889 ;;(latin-iso8859-1 2889 (latin-iso8859-1
2890 ;; (normal bdf "etl24-latin1.bdf" iso-latin-1 1) 2890 (normal bdf "etl24-latin1.bdf" iso-latin-1 1)
2891 ;; (bold bdf "etl16b-latin1.bdf" iso-latin-1 1) 2891 (bold bdf "etl16b-latin1.bdf" iso-latin-1 1)
2892 ;; (italic bdf "etl16i-latin1.bdf" iso-latin-1 1) 2892 (italic bdf "etl16i-latin1.bdf" iso-latin-1 1)
2893 ;; (bold-italic bdf "etl16bi-latin1.bdf" iso-latin-1 1)) 2893 (bold-italic bdf "etl16bi-latin1.bdf" iso-latin-1 1))
2894 (latin-iso8859-1 2894 (latin-iso8859-1
2895 (normal nil nil iso-latin-1)) 2895 (normal nil nil iso-latin-1))
2896 (latin-iso8859-2 2896 (latin-iso8859-2
2897 (normal bdf "etl24-latin2.bdf" iso-latin-2 1)) 2897 (normal bdf "etl24-latin2.bdf" iso-latin-2 1))
2898 (latin-iso8859-3 2898 (latin-iso8859-3
2970 (indian-2-column 2970 (indian-2-column
2971 (normal bdf "mule-indian-24.bdf" ps-mule-encode-7bit 2)) 2971 (normal bdf "mule-indian-24.bdf" ps-mule-encode-7bit 2))
2972 (tibetan 2972 (tibetan
2973 (normal bdf "mule-tibmdx-24.bdf" ps-mule-encode-7bit 2))) 2973 (normal bdf "mule-tibmdx-24.bdf" ps-mule-encode-7bit 2)))
2974 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts. 2974 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
2975 BDF (Bitmap Distribution Format) is a format used for distributing
2976 X's font source file.
2975 2977
2976 Current default value lists BDF fonts included in `intlfonts-1.1' 2978 Current default value lists BDF fonts included in `intlfonts-1.1'
2977 which is a collection of X11 fonts for all characters supported by 2979 which is a collection of X11 fonts for all characters supported by
2978 Emacs.") 2980 Emacs.
2981
2982 With the default value, all characters including ASCII and Latin-1 are
2983 printed by BDF fonts. See also `ps-mule-font-info-database-ps-bdf'.")
2984
2985 (defconst ps-mule-font-info-database-ps-bdf
2986 (cons '(latin-iso8859-1
2987 (normal nil nil iso-latin-1))
2988 (cdr (cdr ps-mule-font-info-database-bdf)))
2989 "Sample setting of the `ps-mule-font-info-database to use BDF fonts.
2990
2991 Current default value lists BDF fonts included in `intlfonts-1.1'
2992 which is a collection of X11 fonts for all characters supported by
2993 Emacs.
2994
2995 With the default value, all characters except for ASCII and Latin-1 are
2996 printed by BDF fonts. ASCII and Latin-1 charcaters are printed by
2997 PostScript font specified by `ps-font-family'.
2998
2999 See also `ps-mule-font-info-database-bdf'.")
2979 3000
2980 ;; Two typical encoding functions for PostScript fonts. 3001 ;; Two typical encoding functions for PostScript fonts.
2981 3002
2982 (defun ps-mule-encode-7bit (string) 3003 (defun ps-mule-encode-7bit (string)
2983 (let* ((dim (charset-dimension 3004 (let* ((dim (charset-dimension
3019 str)) 3040 str))
3020 3041
3021 ;; Special encoding function for Ethiopic. 3042 ;; Special encoding function for Ethiopic.
3022 (define-ccl-program ccl-encode-ethio-unicode 3043 (define-ccl-program ccl-encode-ethio-unicode
3023 `(1 3044 `(1
3024 (read r2) 3045 ((read r2)
3025 (loop 3046 (loop
3026 (if (r2 == ,leading-code-private-22) 3047 (if (r2 == ,leading-code-private-22)
3027 ((read r0) 3048 ((read r0)
3028 (if (r0 == ,(charset-id 'ethiopic)) 3049 (if (r0 == ,(charset-id 'ethiopic))
3029 ((read r1 r2) 3050 ((read r1 r2)
3030 (r1 &= 127) (r2 &= 127) 3051 (r1 &= 127) (r2 &= 127)
3031 (call ccl-encode-ethio-font) 3052 (call ccl-encode-ethio-font)
3032 (write r1) 3053 (write r1)
3033 (write-read-repeat r2)) 3054 (write-read-repeat r2))
3034 ((write r2 r0) 3055 ((write r2 r0)
3035 (repeat)))) 3056 (repeat))))
3036 (write-read-repeat r2))))) 3057 (write-read-repeat r2))))))
3037 3058
3038 (defun ps-mule-encode-ethiopic (string) 3059 (defun ps-mule-encode-ethiopic (string)
3039 (ccl-execute-on-string (symbol-value 'ccl-encode-ethio-unicode) 3060 (ccl-execute-on-string (symbol-value 'ccl-encode-ethio-unicode)
3040 (make-vector 9 nil) 3061 (make-vector 9 nil)
3041 string)) 3062 string))
3128 (if (eq charset 'ascii) 3149 (if (eq charset 'ascii)
3129 (format "f%d" ps-current-font) 3150 (format "f%d" ps-current-font)
3130 (format "f%02x-%d" 3151 (format "f%02x-%d"
3131 (charset-id charset) ps-current-font)))) 3152 (charset-id charset) ps-current-font))))
3132 (if (and func (not font-cache)) 3153 (if (and func (not font-cache))
3133 (ps-output-prologue (funcall func font-spec))) 3154 (ps-output-prologue (funcall func charset font-spec)))
3134 (ps-output-prologue 3155 (ps-output-prologue
3135 (list (format "/%s %f /%s Def%sFontMule\n" 3156 (list (format "/%s %f /%s Def%sFontMule\n"
3136 scaled-font-name ps-font-size font-name 3157 scaled-font-name ps-font-size font-name
3137 (if (eq ps-mule-current-charset 'ascii) "Ascii" "")))) 3158 (if (eq ps-mule-current-charset 'ascii) "Ascii" ""))))
3138 (if font-cache 3159 (if font-cache
3582 /FirstCode exch store 3603 /FirstCode exch store
3583 pop 3604 pop
3584 0 0 setcharwidth 3605 0 0 setcharwidth
3585 } { 3606 } {
3586 1 index /FontSize get /size exch def 3607 1 index /FontSize get /size exch def
3608 1 index /FontSpaceWidthRatio get /ratio exch def
3587 1 index /FontIndex get exch FirstCode exch 3609 1 index /FontIndex get exch FirstCode exch
3588 GlobalCharName GetBitmap /bmp exch def 3610 GlobalCharName GetBitmap /bmp exch def
3589 %% bmp == [ DWIDTH BBX-WIDTH BBX-HEIGHT BBX-XOFF BBX-YOFF BITMAP ] 3611 %% bmp == [ DWIDTH BBX-WIDTH BBX-HEIGHT BBX-XOFF BBX-YOFF BITMAP ]
3590 Cmpchar { %ifelse 3612 Cmpchar { %ifelse
3591 /FontMatrix get [ exch { size div } forall ] /mtrx exch def 3613 /FontMatrix get [ exch { size div } forall ] /mtrx exch def
3596 } { 3618 } {
3597 pop 3619 pop
3598 } ifelse 3620 } ifelse
3599 /FirstCode -1 store 3621 /FirstCode -1 store
3600 3622
3601 bmp 0 get size div 0 % wx wy 3623 bmp 0 get SpaceWidthRatio ratio div mul size div 0 % wx wy
3602 setcharwidth % We can't use setcachedevice here. 3624 setcharwidth % We can't use setcachedevice here.
3603 3625
3604 bmp 1 get 0 gt bmp 2 get 0 gt and { 3626 bmp 1 get 0 gt bmp 2 get 0 gt and {
3605 bmp 1 get bmp 2 get % width height 3627 bmp 1 get bmp 2 get % width height
3606 true % polarity 3628 true % polarity
3629 NameIndexDict idxname idx put 3651 NameIndexDict idxname idx put
3630 } for 3652 } for
3631 3653
3632 /GlobalFontIndex 0 def 3654 /GlobalFontIndex 0 def
3633 3655
3634 %% fontname dimension fontsize relative-compose baseline-offset fbbx |- -- 3656 %% fontname dim col fontsize relative-compose baseline-offset fbbx |- --
3635 /BitmapFont { 3657 /BitmapFont {
3636 14 dict begin 3658 15 dict begin
3637 /FontBBox exch def 3659 /FontBBox exch def
3638 /BaselineOffset exch def 3660 /BaselineOffset exch def
3639 /RelativeCompose exch def 3661 /RelativeCompose exch def
3640 /FontSize exch def 3662 /FontSize exch def
3641 /FontBBox [ FontBBox { FontSize div } forall ] def 3663 /FontBBox [ FontBBox { FontSize div } forall ] def
3664 FontBBox 2 get FontBBox 0 get sub exch div
3665 /FontSpaceWidthRatio exch def
3642 /FontDimension exch def 3666 /FontDimension exch def
3643 /FontIndex GlobalFontIndex def 3667 /FontIndex GlobalFontIndex def
3644 /FontType 3 def 3668 /FontType 3 def
3645 /FontMatrix matrix def 3669 /FontMatrix matrix def
3646 /Encoding EncodingCommon def 3670 /Encoding EncodingCommon def
3650 definefont pop 3674 definefont pop
3651 /GlobalFontIndex GlobalFontIndex 1 add def 3675 /GlobalFontIndex GlobalFontIndex 1 add def
3652 } bind def 3676 } bind def
3653 3677
3654 %% Define a new bitmap font. 3678 %% Define a new bitmap font.
3655 %% fontname dimension fontsize relative-compose baseline-offset fbbx |- -- 3679 %% fontname dim col fontsize relative-compose baseline-offset fbbx |- --
3656 /NF { 3680 /NF {
3657 /fbbx exch def 3681 /fbbx exch def
3658 %% Convert BDF's FontBoundingBox to PostScript's FontBBox 3682 %% Convert BDF's FontBoundingBox to PostScript's FontBBox
3659 [ fbbx 2 get fbbx 3 get 3683 [ fbbx 2 get fbbx 3 get
3660 fbbx 2 get fbbx 0 get add fbbx 3 get fbbx 1 get add ] 3684 fbbx 2 get fbbx 0 get add fbbx 3 get fbbx 1 get add ]
3683 (unless ps-mule-bitmap-prologue-generated 3707 (unless ps-mule-bitmap-prologue-generated
3684 (setq ps-mule-bitmap-prologue-generated t) 3708 (setq ps-mule-bitmap-prologue-generated t)
3685 (list ps-mule-bitmap-prologue))) 3709 (list ps-mule-bitmap-prologue)))
3686 3710
3687 (defun ps-mule-generate-bitmap-font (&rest args) 3711 (defun ps-mule-generate-bitmap-font (&rest args)
3688 (list (apply 'format "/%s %d %f %S %d %S NF\n" args))) 3712 (list (apply 'format "/%s %d %d %f %S %d %S NF\n" args)))
3689 3713
3690 (defun ps-mule-generate-bitmap-glyph (font-name code dwidth bbx bitmap) 3714 (defun ps-mule-generate-bitmap-glyph (font-name code dwidth bbx bitmap)
3691 (format "/%s %d [ %d %d %d %d %d <%s> ] NG\n" 3715 (format "/%s %d [ %d %d %d %d %d <%s> ] NG\n"
3692 font-name code 3716 font-name code
3693 dwidth (aref bbx 0) (aref bbx 1) (aref bbx 2) (aref bbx 3) 3717 dwidth (aref bbx 0) (aref bbx 1) (aref bbx 2) (aref bbx 3)
4353 ps-font-size 4377 ps-font-size
4354 (ps-font 'ps-font-for-text (car (car font))))) 4378 (ps-font 'ps-font-for-text (car (car font)))))
4355 (setq font (cdr font) 4379 (setq font (cdr font)
4356 i (1+ i)))) 4380 i (1+ i))))
4357 4381
4382 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database))))
4383 (ps-output (format "/SpaceWidthRatio %f def\n"
4384 (/ (ps-lookup 'space-width) (ps-lookup 'size)))))
4385
4358 (ps-mule-initialize) 4386 (ps-mule-initialize)
4359 4387
4360 (ps-output "\nBeginDoc\n\n" 4388 (ps-output "\nBeginDoc\n\n"
4361 "%%EndPrologue\n")) 4389 "%%EndPrologue\n"))
4362 4390
4601 (ps-set-font ps-current-font) 4629 (ps-set-font ps-current-font)
4602 (setq ps-mule-current-charset 'ascii)) 4630 (setq ps-mule-current-charset 'ascii))
4603 (ps-plot 'ps-basic-plot-string from match-point bg-color)) 4631 (ps-plot 'ps-basic-plot-string from match-point bg-color))
4604 (cond 4632 (cond
4605 ((= match ?\t) ; tab 4633 ((= match ?\t) ; tab
4606 (let ((linestart (save-excursion (beginning-of-line) (point)))) 4634 (let ((linestart (line-beginning-position)))
4607 (forward-char -1) 4635 (forward-char -1)
4608 (setq from (+ linestart (current-column))) 4636 (setq from (+ linestart (current-column)))
4609 (when (re-search-forward "[ \t]+" to t) 4637 (when (re-search-forward "[ \t]+" to t)
4610 (unless (eq ps-mule-current-charset 'ascii) 4638 (unless (eq ps-mule-current-charset 'ascii)
4611 (ps-set-font ps-current-font) 4639 (ps-set-font ps-current-font)