📄 paginate.ps.verbose
字号:
dup % copy token for pass 2 A 0 eq {SH1} % 0 = show string {A 1 eq {SH1} % 1 = show underlined string {A 2 eq {SP1} % 2 = show space character {A 3 eq {SP1} % 3 = show underlined space {A 4 eq {TB1} % 4 = tab {A 5 eq {TB1} % 5 = underlined tab {A 6 eq {B1} % 6 = show subscript string {A 7 eq {B1} % 7 = underlined subscript {A 8 eq {B1} % 8 = show superscript string {A 9 eq {B1} % 9 = underlined superscript {(E1) show} % error ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse} def%% pass 1, calculate length of string% assumes token array is on top of stack/SH1 { aload % unpack array pop pop % discard array copy and action code dup x eq % font changing ? { pop pop} % no - discard "don't cares" {F} % yes - change font ifelse stringwidth pop % get length of string, discard Y coordinate dup LL gt % this string wider than line size ? {pop LL} % yes - truncate if LE % check if end of line reached} def%% pass 1, calculate length of space characters% assumes token array is on top of stack/SP1 { aload % unpack array pop pop % discard array copy and action code dup x eq % font changing ? {pop pop} % no - discard "don't cares" {F} % yes - change font ifelse stringwidth pop % get length of string, discard Y coordinate dup X add % increment X coord, leave copy of length on stack /X exch def dup % copy for division s stringwidth pop % get size of one space div truncate % find how many spaces in string X RM gt % right margin exceeded ? { pop % yes - discard number of spaces X exch sub % reset X coordinate /X exch def pop % discard pass 2 token copy /REM 0 def % no remainder NL % show the line } { TK 1 add % increment token count /TK exch def % update variable SC add % increment count of spaces in line /SC exch def % update variable } ifelse} def%% pass 1, calculate length of tab% if right margin exceeded, the tab is discarded and the line is shown/TB1 { pop % discard token array X 72 add % calculate next 1 inch (72 pt) boundary 72 div truncate 72 mul dup X sub % calculate tab length exch % swap new X coord to top dup /X exch def % update X coord RM gt % right margin exceeded ? { pop pop % yes - discard new X coord and pass 2 token copy /REM 0 def % no remainder NL % show the line } { TK 1 add % increment token count /TK exch def % update variable } ifelse} def%% hard newline encountered, terminate pass 1, start pass 2% a for loop is executed once for each token in the line, TK holds% the number of tokens. the stack is rolled to put the left most token% at the top of the stack, C2 is executed to process the token and pop it% off the stack. the roll moves one less token each time through the loop% since the stack is shrinking by one each iteration. %% paired with each token is the length of the string it contains, so TK% is doubled and the loop iteration count is -2./NL { LS % calculate line starting coordinates TK 2 mul % account for token/length pairs -2 % decrement by this amount each iteration 1 % loop ends when less than 1 pair of items on stack { % loop for each token/length pair -2 roll C2 % - roll leftmost pair to the top } for /TK 0 def % reset token count /LM NLM def % pick up delayed margin change, if any /X LM def % reset X coord to left margin /REM 0 def % reset remainder length /SC 0 def % reset count of spaces /RM NRM def % pick up delayed margin change, if any} def %% soft newline, i.e. building a string and right margin exceeded.% this differs from NL in that one token pair will be left on the% stack, the "remainder" which crossed the margin./SNL { TK 2 mul % account for token/length pairs 2 roll % shove remainder way down TK 1 sub % decrement token count /TK exch def LS % calculate line starting coordinates TK 2 mul % account for token/length pairs -2 % decrement by this amount each iteration 1 % loop ends laving one token pair on stack { % loop for each token/length pair -2 roll C2 % - roll leftmost pair to the top } for /TK 1 def % reset token count (remainder still on stack) /LM NLM def % pick up delayed margin change, if any REM LM add % new X coord = left margin + remainder from prev line /X exch def /REM 0 def % reset remainder length /SC 0 def % reset count of spaces /RM NRM def % pick up delayed margin change, if any} def %% subroutine to process hard new page/NP { NL % do new line processing X LM eq Y TOP eq and not % top of page? { % no - showpage % page eject /X LM def % X coord = left margin /Y TOP def % Y coord = top margin BOX {DB} if % conditionally draw box around page HDR {PH} if % conditionally print running header } if} def%% subroutine to find length of a subscript or superscript string% assumes that host filter determines font size and passes it in the token/B1 { aload % unpack array pop pop % discard array copy and action code F % set font size and style stringwidth pop % get length of string, discard Y coordinate dup LL gt % this string wider than line size ? {pop LL} % yes - truncate if LE % check if end of line reached} def%% draw box around page/DB { PLM PTOP moveto PRM PTOP lineto PRM PBOT lineto PLM PBOT lineto closepath stroke} def%% subroutines: print running header% the header consists of a "3D" representation of the word "MIME," % followed by a title including the date and time the file was generated.% this is printed at the left margin. at the right margin the page number% is printed. the title is hardcoded to 12 pt, using Times-Roman font.%/printMime { % called inside the "3D" loop 0 0 moveto (MIME) true charpath} bind def/printPage { % print page number, right justified (Page ) stringwidth pop % length of literal string "Page " PG 10 string cvs stringwidth pop % length of page number add % total length PRM exch sub % distance to indent from right PTOP 2 add % distance from top of page moveto (Page ) show PG 10 string cvs show PG 1 add /PG exch def % increment page number} def/printHdr { % print left justified header 12 /Times-Roman F2 % set font to 12 pt, default font name PLM 78 add PTOP 2 add moveto % location just past "3D" title MSG show % show date/time message printPage % show page number} def/PH { gsave 24 /Times-Roman F2 % set font for header gsave PLM 20 sub PTOP 12 add translate % set starting point for 3D 1 -.05 0 { % decrement from 1 to 0 by .05 setgray % set gray scale printMime % print character outline fill % fill it in 1 -.5 translate % move for next iteration } for printMime % print outline 1 last time gsave 1 setgray fill % fill it in solid grestore .2 setlinewidth stroke % draw solid line around characters grestore printHdr % print rest of running header grestore} def%% pass 2 case statement% assumes top of stack is stringlength, top-1 is token array/C2 { exch % swap string length and token array A 0 eq {SH2} % 0 = show string {A 1 eq {USH} % 1 = show underlined string {A 2 eq {SP2} % 2 = show space character {A 3 eq {USP} % 3 = show underlined space {A 4 eq {TB2} % 4 = tab {A 5 eq {UTB} % 5 = underlined tab {A 6 eq {B2} % 6 = show subscript string {A 7 eq {UB} % 7 = underlined subscript {A 8 eq {P2} % 8 = show superscript string {A 9 eq {UP} % 9 = underlined superscript {(E2) show} % error ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse} def%% pass 2, display a string/SH2 { aload % unpack token array pop pop % discard array copy and action code dup x eq % font changing ? { pop pop} % no - discard "don't cares" {F2} % yes - change the font ifelse show % show the string pop % discard stringwidth} def%% pass 2, display an underlined string/USH { aload % unpack token array pop pop % discard array copy and action code dup x eq % font changing ? { pop pop} % no - discard "don't cares" {F2} % yes - change the font ifelse currentpoint % get X and Y coordinates /Y1 exch def /X1 exch def X1 Y1 2 sub moveto % move to start of underline, 2 pts below line exch % swap string length to top 0 rlineto stroke % draw the underline X1 Y1 moveto % restore coordinates show % show the string} def%% pass 2, show string while adjusting space/ADJSPC { /STR exch def % save string of space(s) ADJ 0 % put X & Y width adjustment on stack SPACE % put space character literal on stack STR % put the string of space(s) back widthshow % show the string, adjusting the width} def%% pass 2, display space(s)/SP2 { aload % unpack token array pop pop % discard array copy and action code dup x eq % font changing ? {pop pop} % no - discard "don't cares" {F2} % yes - change the font ifelse JU 3 eq % full justification ? {ADJSPC} % yes - adjust the space(s) {show} % else - show the space(s) ifelse pop % discard stringwidth} def%% pass 2, display an underlined space(s)/USP { aload % unpack token array pop pop % discard array copy and action code dup x eq % font changing ? {pop pop} % no - discard "don't cares" {F2} % yes - change the font ifelse currentpoint % save starting point 2 sub /Y1 exch def /X1 exch def JU 3 eq % full justification ? {ADJSPC} % yes - adjust the space(s) {show} % else - show the space(s) ifelse currentpoint 0 -2 rmoveto % move 2 pts below line X1 Y1 lineto % underline to next tab stop stroke % draw the underline (which wipes out X & Y) moveto % restore X & Y pop % discard stringwidth} def%% pass 2, move to next tab stop/TB2 { pop % discard token array, leave length on top 0 rmoveto % move right to next tab stop} def%% pass 2, move to next tab stop, draw underline/UTB { pop % discard token array, leave length on top 0 -2 rmoveto % move 2 pts below line 0 rlineto % underline to next tab stop 0 2 rmoveto % move back up to line currentpoint % remember X & Y coords stroke % draw the underline (which wipes out X & Y) moveto % restore X & Y} def%% pass 2, display a subscript string/B2 { aload % unpack token array pop pop % discard array copy and action code F2 % set font size and style 0 -2 rmoveto % move down from baseline show % show the string 0 2 rmoveto % restore baseline pop % discard stringwidth} def%% pass 2, display an underlined subscript string/UB { aload % unpack token array pop pop % discard array copy and action code F2 % set font size and style currentpoint % get X and Y coordinates /Y1 exch def /X1 exch def X1 Y1 2 sub moveto % move to start of underline, 2 pts below line exch % swap string length to top 0 rlineto stroke % draw the underline X1 Y1 2 sub moveto % restore coordinates, 2 pt below baseline show % show the string 0 2 rmoveto % restore baseline} def%% subroutine to set font for superscript, and remember size in PH variable/FP { findfont exch dup /PH exch def scalefont setfont} def%% pass 2, display a superscript string/P2 { aload % unpack token array pop pop % discard array copy and action code FP % set font size and style 0 PH rmoveto % move up from baseline show % show the string 0 PH neg rmoveto % restore baseline pop % discard stringwidth} def%% pass 2, display an underlined superscript string/UP { aload % unpack token array pop pop % discard array copy and action code FP % set font size and style currentpoint % get X and Y coordinates /Y1 exch def /X1 exch def X1 Y1 2 sub moveto % move to start of underline, 2 pts below line exch % swap string length to top 0 rlineto stroke % draw the underline X1 Y1 PH add moveto % restore coordinates, above baseline show % show the string 0 PH neg rmoveto % restore baseline} def%% subroutine: calculate maximum line length LL/LL {RM LM sub} def%%%EndProlog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -