📄 ocr.ps
字号:
% Print new "m" directive for currentfont (QM ) print lastMetrics 1 add /lastMetrics 1 index def dup //printInt exec //printMetrics exec () = } bind def/reportEncoding { % stack: -> e % privateDict is open % Print new "e" directive for currentfont (QE ) print lastEncoding 1 add /lastEncoding 1 index def dup //printInt exec //printMap exec } bind def/spaceString (X) def % for space char from current encoding/reportFont { % stack: any -> unchanged % Report currentfont to the user and record its number % //privateDict is open % Sets //privateDict/spaceString to font's encoding's space string, if any, % and sets //privateDict/hasSpace to indicate whether there's a space char. currentfont /UniqueID known not { //reportMetrics exec } { //metrics currentfont /UniqueID get 2 copy known { get } { //reportMetrics exec dup 4 1 roll put % define in /metrics } ifelse } ifelse % stack: m //encodings currentfont /Encoding get 2 copy known { get } { //reportEncoding exec % leaves e on stack dup 4 1 roll put % define in /encodings % Find space character number for the encoding. % Biased towards number 32, so avoid problems with weird encodings //encodingSpace 1 index % dict and key for putting the result currentfont /Encoding get dup length 32 le { false } { dup 32 get dup /space eq exch /G20 eq or } ifelse { pop 32 } { % It's not character number 32: search from 0 0 exch { dup /space eq exch dup /G20 eq exch /suppress eq or or { exit } if 1 add } forall } ifelse put % put in /encodingSpace } ifelse % stack: m e //encodingSpace 1 index get % font's space character (256 if none) /hasSpace 1 index 256 lt def hasSpace { //spaceString exch 0 exch put } { pop } ifelse (QF ) print lastFontNum 1 add /lastFontNum 1 index def //fonts currentfont 2 index put % record fontNum in /fonts dup //printInt exec % print fontNum % stack: m e f 1000 0 //characterToReporting exec 2 copy //showxy exec 0 1000 //characterToReporting exec 2 copy //showxy exec 4 array astore % stack: m e f array //fontsUnit 3 1 roll put % stack: m e //printInt exec % print encoding number //printInt exec % print metrics number () = } bind def/reportFontCreation { % stack: font % Report a newly created font. Called now so that if later uses are % inside a save/restore we don't forget it. % NOTE: this is currently not used, since it actually slows things down //privateDict begin inUse not { /inUse true def dup currentfont exch setfont //reportFont exec setfont /inUse false def } if end } bind def/reportSubString { % stack: args string -> args % Report the rendering of a string, assumed to be a single word. % privateDict is open. /n is font number, /p is call-back dup length 0 eq { p } { (QS ) print n //printInt exec //printCharacterOrigin exec dup length //printInt exec dup print ( ) print /p load end % close privateDict during the call-back exec % render the string; leaves args on stack //privateDict begin //printCharacterOrigin exec () = } ifelse } bind def/report { % stack: args string proc -> args % Report the rendering of a string. % Calls proc for each word and space. The call-back should expect "args" % on the stack followed by a string, and should leave "args" on the stack. //privateDict begin inUse { end exec } { /inUse true def //fonts currentfont 2 copy known not { //reportFont exec } if get % stack: probable font-number % check if points transform as before ... //fontsUnit 1 index get 1000 0 //characterToReporting exec 0 1000 //characterToReporting exec 4 index 3 get ne 4 1 roll 4 index 2 get ne 4 1 roll 4 index 1 get ne 4 1 roll 4 index 0 get ne 5 -1 roll pop or or or { % if transformed points differ //reportFont exec pop //fonts currentfont get } if % stack: args string proc n /n exch def /p exch def % stack: args string hasSpace { { % begin loop //spaceString search { exch pop exch /s exch def //reportSubString exec //spaceString p s } { //reportSubString exec exit } ifelse } loop } { //reportSubString exec } ifelse /inUse false def end } ifelse } bind def/dontReport { % stack: proc % Call "proc" with //privateDict/inUse set to true //privateDict /inUse get { exec } { //privateDict /inUse true put exec //privateDict /inUse false put } ifelse } bind def/kshow.temp (X) def % scratch space for kshow% Output from groff 1.08 sometimes uses ashow to show letters from % two separate words, with the offset being used to add the space.% Implement 'awidthshow' and friends as calls to 'show' to catch this./pstotext_awidthshow { % cx cy char ax ay string -- //kshow.temp 0 1 3 index length 1 sub { 2 index exch get 1 index 0 2 index put 1 index show 4 index 4 index rmoveto 5 index eq { 6 index 6 index rmoveto } if } for pop pop pop pop pop pop pop} def/pstotext_xshow { % string numarray -- //kshow.temp 0 1 4 index length 1 sub { currentpoint 2 index 6 index exch get 4 index 0 2 index put pop 3 index show moveto % set char width from array 2 index exch get 0 rmoveto } for pop pop pop} def/pstotext_yshow { % string numarray -- //kshow.temp 0 1 4 index length 1 sub { currentpoint 2 index 6 index exch get 4 index 0 2 index put pop 3 index show moveto % set char height from array 2 index exch get 0 exch rmoveto } for pop pop pop} def/pstotext_xyshow { % string numarray -- //kshow.temp 0 1 4 index length 1 sub { currentpoint 2 index 6 index exch get 4 index 0 2 index put pop 3 index show moveto % set char width and height from array dup add 2 index 1 index get exch 3 index exch 1 add get rmoveto } for pop pop pop} def% Output inverse of initial currentmatrix, for possible use by postprocessor.(QI ) printmatrix currentmatrix matrix invertmatrix{ 100 mul round cvi //printInt exec } forall() =userdict begin % subsequent definitions are publicly visible% Objects placed in systemdict must be in global memory,% and must not reference local objects./setglobal where { pop currentglobal true setglobal } { }ifelse%% Redefine the character rendering operations to call "report"%/show { { show } //systemdict /pstotextLocalDict get /report get exec } bind redef%/ashow { {3 copy ashow pop}% //systemdict /pstotextLocalDict get /report get% exec pop pop } bind redef% Implement as call to show to catch PostScript that uses% these to show letters from separate words./ashow { 0 0 -1 6 3 roll //systemdict /pstotextLocalDict get /pstotext_awidthshow get exec } bind redef/widthshow { 0 0 3 -1 roll //systemdict /pstotextLocalDict get /pstotext_awidthshow get exec } bind redef/awidthshow { //systemdict /pstotextLocalDict get /pstotext_awidthshow get exec } bind redef/xshow { //systemdict /pstotextLocalDict get /pstotext_xshow get exec } bind redef/yshow { //systemdict /pstotextLocalDict get /pstotext_yshow get exec } bind redef/xyshow { //systemdict /pstotextLocalDict get /pstotext_xyshow get exec } bind redef/kshow { % stack: proc string exch //systemdict /pstotextLocalDict get exch /kshow.proc exch put false exch % stack: false string { % stack: false next | prev true next //systemdict /pstotextLocaldict get /kshow.temp get 0 2 index put exch { //systemdict /pstotextLocalDict get /kshow.proc get exec } { pop } ifelse //systemdict /pstotextLocaldict get /kshow.temp get //show exec //systemdict /pstotextLocaldict get /kshow.temp get 0 get true % stack: this true } forall % stack: false | last true { pop } if } bind redef%% Redefine non-rendering operations so that they don't report%/stringwidth { {stringwidth} //systemdict /pstotextLocalDict get /dontReport get exec } bind redef/charpath { {charpath} //systemdict /pstotextLocalDict get /dontReport get exec } bind redef%% Intercept and report the page operations%/copypage { (QC) = flush copypage } bind redef/erasepage { (QZ) = flush erasepage } bind redef/showpage { (QP) = flush showpage } bind redef%% Intercept font creation so as to record the font inside less save/restore's% NOTE: disabled, because it actually slows things down%% /definefont { definefont //reportFontCreation exec } bind redef% /makefont { makefont //reportFontCreation exec } bind redef% /scalefont { scalefont //reportFontCreation exec } bind redef%% Clean-up%% restore local/global state/setglobal where { pop setglobal } { }ifelseend % close nested userdict beginend % close private dictionary% Bind the operators we just defined, and all the others if we didn't% do it before. Also reenable 'bind' for future files.revision 353 ge {.bindoperatorsNOBIND currentdict systemdict ne and { systemdict begin .bindoperators end }if/DELAYBIND where { pop DELAYBIND { .bindnow } if } if} ifsystemdict readonly pop% Restore the current local/global VM mode.% exec%% Testing%false { 100 dict begin (Times 12, two strings; second one sloping up with ashow:)= /Times-Roman findfont 12 scalefont dup /t12 exch def setfont 72 300 moveto (Hello world) show 72 280 moveto 10 1 (Hello world once more) ashow (Times 10 two strings:)= /Times-Roman findfont 10 scalefont setfont 72 260 moveto (Third) show 72 240 moveto (Fourth) show (Symbol 12, one string:)= /Symbol findfont 12 scalefont setfont 72 220 moveto (symbol string) show (Helvetica 12, two strings:)= /Helvetica findfont 12 scalefont setfont 72 200 moveto (Fifth) show 72 180 moveto (Sixth) show (Times 12 again, two strings; second one with kshow:)= t12 setfont 72 160 moveto (Seventh) show end 72 140 moveto gsave /dx 1.0 def { pop pop dx 1 add /dx 1 index def 0 rmoveto } (Accelerated letter spacing) kshow grestore (Times 12 scaled by 2:)= 72 100 moveto gsave 2 2 scale (Ninth) show grestore count 0 ne { (Left on stack:)= pstack } if flush } if
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -