enscript.pro - enscript - GNU Enscript
 (HTM) git clone git://thinkerwim.org/enscript.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       enscript.pro (6930B)
       ---
            1 %
            2 % PostScript prolog.
            3 % Copyright (c) 1995-1998 Markku Rossi.
            4 %
            5 % Author: Markku Rossi <mtr@iki.fi>
            6 %
            7 %
            8 % This file is part of GNU Enscript.
            9 %
           10 % Enscript is free software: you can redistribute it and/or modify
           11 % it under the terms of the GNU General Public License as published by
           12 % the Free Software Foundation, either version 3 of the License, or
           13 % (at your option) any later version.
           14 %
           15 % Enscript 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 %
           20 % You should have received a copy of the GNU General Public License
           21 % along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
           22 %
           23 
           24 % -- code follows this line --
           25 %
           26 % Procedures.
           27 %
           28 
           29 /_S {        % save current state
           30   /_s save def
           31 } def
           32 /_R {        % restore from saved state
           33   _s restore
           34 } def
           35 
           36 /S {        % showpage protecting gstate
           37   gsave
           38   showpage
           39   grestore
           40 } bind def
           41 
           42 /MF {        % fontname newfontname -> -        make a new encoded font
           43   /newfontname exch def
           44   /fontname exch def
           45 
           46   /fontdict fontname findfont def
           47   /newfont fontdict maxlength dict def
           48 
           49   fontdict {
           50     exch
           51     dup /FID eq {
           52       % skip FID pair
           53       pop pop
           54     } {
           55       % copy to the new font dictionary
           56       exch newfont 3 1 roll put
           57     } ifelse
           58   } forall
           59 
           60   newfont /FontName newfontname put
           61 
           62   % insert only valid encoding vectors
           63   encoding_vector length 256 eq {
           64     newfont /Encoding encoding_vector put
           65   } if
           66 
           67   newfontname newfont definefont pop
           68 } def
           69 
           70 /MF_PS { % fontname newfontname -> -        make a new font preserving its enc
           71   /newfontname exch def
           72   /fontname exch def
           73 
           74   /fontdict fontname findfont def
           75   /newfont fontdict maxlength dict def
           76 
           77   fontdict {
           78     exch
           79     dup /FID eq {
           80       % skip FID pair
           81       pop pop
           82     } {
           83       % copy to the new font dictionary
           84       exch newfont 3 1 roll put
           85     } ifelse
           86   } forall
           87 
           88   newfont /FontName newfontname put
           89 
           90   newfontname newfont definefont pop
           91 } def
           92 
           93 /SF { % fontname width height -> -        set a new font
           94   /height exch def
           95   /width exch def
           96 
           97   findfont
           98   [width 0 0 height 0 0] makefont setfont
           99 } def
          100 
          101 /SUF { % fontname width height -> -        set a new user font
          102   /height exch def
          103   /width exch def
          104 
          105   /F-gs-user-font MF
          106   /F-gs-user-font width height SF
          107 } def
          108 
          109 /SUF_PS { % fontname width height -> -        set a new user font preserving its enc
          110   /height exch def
          111   /width exch def
          112 
          113   /F-gs-user-font MF_PS
          114   /F-gs-user-font width height SF
          115 } def
          116 
          117 /M {moveto} bind def
          118 /s {show} bind def
          119 
          120 /Box {        % x y w h -> -                        define box path
          121   /d_h exch def /d_w exch def /d_y exch def /d_x exch def
          122   d_x d_y  moveto
          123   d_w 0 rlineto
          124   0 d_h rlineto
          125   d_w neg 0 rlineto
          126   closepath
          127 } def
          128 
          129 /bgs {        % x y height blskip gray str -> -        show string with bg color
          130   /str exch def
          131   /gray exch def
          132   /blskip exch def
          133   /height exch def
          134   /y exch def
          135   /x exch def
          136 
          137   gsave
          138     x y blskip sub str stringwidth pop height Box
          139     gray setgray
          140     fill
          141   grestore
          142   x y M str s
          143 } def
          144 
          145 /bgcs { % x y height blskip red green blue str -> -  show string with bg color
          146   /str exch def
          147   /blue exch def
          148   /green exch def
          149   /red exch def
          150   /blskip exch def
          151   /height exch def
          152   /y exch def
          153   /x exch def
          154 
          155   gsave
          156     x y blskip sub str stringwidth pop height Box
          157     red green blue setrgbcolor
          158     fill
          159   grestore
          160   x y M str s
          161 } def
          162 
          163 % Highlight bars.
          164 /highlight_bars {        % nlines lineheight output_y_margin gray -> -
          165   gsave
          166     setgray
          167     /ymarg exch def
          168     /lineheight exch def
          169     /nlines exch def
          170 
          171     % This 2 is just a magic number to sync highlight lines to text.
          172     0 d_header_y ymarg sub 2 sub translate
          173 
          174     /cw d_output_w cols div def
          175     /nrows d_output_h ymarg 2 mul sub lineheight div cvi def
          176 
          177     % for each column
          178     0 1 cols 1 sub {
          179       cw mul /xp exch def
          180 
          181       % for each rows
          182       0 1 nrows 1 sub {
          183         /rn exch def
          184         rn lineheight mul neg /yp exch def
          185         rn nlines idiv 2 mod 0 eq {
          186           % Draw highlight bar.  4 is just a magic indentation.
          187           xp 4 add yp cw 8 sub lineheight neg Box fill
          188         } if
          189       } for
          190     } for
          191 
          192   grestore
          193 } def
          194 
          195 % Line highlight bar.
          196 /line_highlight {        % x y width height gray -> -
          197   gsave
          198     /gray exch def
          199     Box gray setgray fill
          200   grestore
          201 } def
          202 
          203 % Column separator lines.
          204 /column_lines {
          205   gsave
          206     .1 setlinewidth
          207     0 d_footer_h translate
          208     /cw d_output_w cols div def
          209     1 1 cols 1 sub {
          210       cw mul 0 moveto
          211       0 d_output_h rlineto stroke
          212     } for
          213   grestore
          214 } def
          215 
          216 % Column borders.
          217 /column_borders {
          218   gsave
          219     .1 setlinewidth
          220     0 d_footer_h moveto
          221     0 d_output_h rlineto
          222     d_output_w 0 rlineto
          223     0 d_output_h neg rlineto
          224     closepath stroke
          225   grestore
          226 } def
          227 
          228 % Do the actual underlay drawing
          229 /draw_underlay {
          230   ul_style 0 eq {
          231     ul_str true charpath stroke
          232   } {
          233     ul_str show
          234   } ifelse
          235 } def
          236 
          237 % Underlay
          238 /underlay {        % - -> -
          239   gsave
          240     0 d_page_h translate
          241     d_page_h neg d_page_w atan rotate
          242 
          243     ul_gray setgray
          244     ul_font setfont
          245     /dw d_page_h dup mul d_page_w dup mul add sqrt def
          246     ul_str stringwidth pop dw exch sub 2 div ul_h_ptsize -2 div moveto
          247     draw_underlay
          248   grestore
          249 } def
          250 
          251 /user_underlay {        % - -> -
          252   gsave
          253     ul_x ul_y translate
          254     ul_angle rotate
          255     ul_gray setgray
          256     ul_font setfont
          257     0 0 ul_h_ptsize 2 div sub moveto
          258     draw_underlay
          259   grestore
          260 } def
          261 
          262 % Page prefeed
          263 /page_prefeed {                % bool -> -
          264   statusdict /prefeed known {
          265     statusdict exch /prefeed exch put
          266   } {
          267     pop
          268   } ifelse
          269 } def
          270 
          271 % Wrapped line markers
          272 /wrapped_line_mark {        % x y charwith charheight type -> -
          273   /type exch def
          274   /h exch def
          275   /w exch def
          276   /y exch def
          277   /x exch def
          278 
          279   type 2 eq {
          280     % Black boxes (like TeX does)
          281     gsave
          282       0 setlinewidth
          283       x w 4 div add y M
          284       0 h rlineto w 2 div 0 rlineto 0 h neg rlineto
          285       closepath fill
          286     grestore
          287   } {
          288     type 3 eq {
          289       % Small arrows
          290       gsave
          291         .2 setlinewidth
          292         x w 2 div add y h 2 div add M
          293         w 4 div 0 rlineto
          294         x w 4 div add y lineto stroke
          295 
          296         x w 4 div add w 8 div add y h 4 div add M
          297         x w 4 div add y lineto
          298         w 4 div h 8 div rlineto stroke
          299       grestore
          300     } {
          301       % do nothing
          302     } ifelse
          303   } ifelse
          304 } def
          305 
          306 % EPSF import.
          307 
          308 /BeginEPSF {
          309   /b4_Inc_state save def                    % Save state for cleanup
          310   /dict_count countdictstack def        % Count objects on dict stack
          311   /op_count count 1 sub def                % Count objects on operand stack
          312   userdict begin
          313   /showpage { } def
          314   0 setgray 0 setlinecap
          315   1 setlinewidth 0 setlinejoin
          316   10 setmiterlimit [ ] 0 setdash newpath
          317   /languagelevel where {
          318     pop languagelevel
          319     1 ne {
          320       false setstrokeadjust false setoverprint
          321     } if
          322   } if
          323 } bind def
          324 
          325 /EndEPSF {
          326   count op_count sub { pos } repeat        % Clean up stacks
          327   countdictstack dict_count sub { end } repeat
          328   b4_Inc_state restore
          329 } bind def
          330 
          331 % Check PostScript language level.
          332 /languagelevel where {
          333   pop /gs_languagelevel languagelevel def
          334 } {
          335   /gs_languagelevel 1 def
          336 } ifelse