home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 September / PCWK996.iso / sharewar / 95 / narzedzi / ambra / ambr32a1.exe / FILE / ARCHIVE.Z / ACROBAT / VIEWER32.EXE / PSPROCSET / 6 < prev    next >
Text File  |  1996-02-22  |  9KB  |  421 lines

  1. %%BeginFile: pdftext.prc
  2. %%Copyright: Copyright 1987-1994 Adobe Systems Incorporated. All Rights Reserved.
  3. % text operators for PDF
  4.  
  5. PDF /PDFText 51 dict dup begin put
  6.  
  7. % initialization
  8. /initialize { /TZ isdefined? not { PDFText begin } if } bd
  9. /terminate { currentdict PDFText eq { end } if } bd
  10.  
  11. % copy all the values but the FID and UniqueID into the font dict
  12. % use this for paint changes but not for encoding (cache issues)
  13. % font must be current dict
  14. /CopyFont {
  15.     { % forall
  16.         1 index /FID ne 2 index /UniqueID ne and
  17.         { def } { pop pop } ifelse
  18.     } forall
  19. } bd
  20.  
  21. % [ number value stream [ array for encoding modification ] modifyEncoding ==> [ modified array ]
  22. /modEnc {
  23.     /_enc xdd                % the encoding dict
  24.     /_icode 0 dd            % next code point
  25.  
  26.     counttomark 1 sub -1 0    % loop over every item above mark
  27.     { % for
  28.         index                % get bottom object
  29.         dup type /nametype eq
  30.             {
  31.                 _enc _icode 3 -1 roll put    % insert name at _icode
  32.                 _icode 1 add                % increment
  33.             }
  34.         if
  35.         /_icode xdd
  36.     } for
  37.     cleartomark
  38.     
  39.     _enc                    % return the modified encoding
  40. } bd
  41.  
  42. % [ 256 glyph-nums translateEncoding ==> new Encoding array
  43. % for each glyph-num, get glyph-name at that code point in Encoding array
  44. % create new Encoding array by replacing number with name
  45. /trEnc {
  46.     /_enc xdd                % the encoding dict
  47.  
  48.     255 -1 0 {
  49.         exch dup -1 eq        % index glyph-num
  50.             { pop /.notdef }
  51.             { Encoding exch get }
  52.         ifelse                % index glyph-name
  53.         _enc 3 1 roll put
  54.     } for
  55.     pop % mark
  56.     
  57.     _enc                    % return the modified encoding
  58. } bd
  59.  
  60. % Define a PDF encoding
  61. % (encoding pairs) enc-num TE -
  62. /TE    {
  63.     /_i xdd
  64.     StandardEncoding 256 array copy modEnc 
  65.     _pdfEncodings exch _i exch put
  66. } bd
  67.  
  68. % re-define font
  69. % expected arguments
  70. % for 'normal fonts : 
  71. % [ /F1/Helvetica-Bold defaultEncoding TZ
  72. % for cartographic, pictographic, and expert fonts :
  73. % [ ... number value stream ... /F1/Symbol defaultEncoding TZ
  74. /TZ        
  75. {
  76.     % platform dependent coding flag
  77.     /_usePDFEncoding xdd
  78.  
  79.     % substitute Helvetica if font not available
  80.     %dup findfont dup /FontName known
  81.     %    {
  82.     %        % substitute if FontName is Courier and original is not
  83.     %        dup /FontName get /Courier eq 3 -1 roll /Courier ne and
  84.     %            { pop /Helvetica findfont }
  85.     %        if
  86.     %    }
  87.     %    { exch pop }
  88.     %ifelse
  89.  
  90.     % never mind (don't substitute) -- too confusing for users
  91.     findfont
  92.     
  93.     % create a new dictionary with length
  94.     % equal to original dictionary length + 2
  95.     % copy all the key/value pairs except FID
  96.     % call makeblended font with the weight values if _wv is an array
  97.     dup length 2 add dict
  98.     
  99.     begin
  100.     
  101.         % copy all the values but the FID into the new dictionary
  102.         {
  103.             1 index /FID ne { def } { pop pop } ifelse
  104.         } forall
  105.         
  106.         % define FontName
  107.         /FontName exch def
  108.         
  109.         % if a known encoding is specified, use that
  110.         % if a modified encoding is needed, apply mods
  111.         % else it's a substitute encoding
  112.         _usePDFEncoding 0 ge
  113.             {    % known encoding
  114.                 /Encoding _pdfEncodings _usePDFEncoding get def
  115.                 pop % mark
  116.             }
  117.             {
  118.                 _usePDFEncoding -1 eq
  119.                     {    % custom or original encoding
  120.                         counttomark 0 eq
  121.                             { pop } % mark
  122.                             {    % custom encoding to be done
  123.                                 Encoding 256 array copy 
  124.                                 modEnc /Encoding exch def
  125.                             }
  126.                         ifelse
  127.                     }
  128.                     {    % translation
  129.                         256 array
  130.                         trEnc /Encoding exch def
  131.                     }
  132.                 ifelse
  133.             }
  134.         ifelse
  135.  
  136.         FontName currentdict
  137.     end
  138.     
  139.     % register the new font
  140.     definefont pop
  141. }
  142. bd
  143.  
  144. % marking operators
  145.  
  146. % like awidthshow but don't draw anything
  147. /swj {                % cx cy fillchar ax ay string swj x y
  148.     dup 4 1 roll
  149.     dup length exch stringwidth 
  150.     exch 5 -1 roll 3 index mul add
  151.     4 1 roll 3 1 roll mul add 
  152.     6 2 roll /_cnt 0 dd
  153.     {1 index eq {/_cnt _cnt 1 add dd} if} forall pop
  154.     exch _cnt mul exch _cnt mul 2 index add 4 1 roll 2 index add 4 1 roll pop pop
  155. } bd
  156.  
  157. % like awidthshow but stroke instead of fill
  158. /jss {                % cx cy fillchar ax ay string matrix jss -
  159.     4 1 roll
  160.     {                % cx cy fillchar matrix ax ay char 0 0 {proc} -   
  161.         2 npop 
  162.         (0) exch 2 copy 0 exch put 
  163.         gsave
  164.         32 eq 
  165.             {
  166.                 exch 6 index 6 index 6 index 5 -1 roll widthshow  
  167.                 currentpoint
  168.             }
  169.             {
  170.                 false charpath currentpoint
  171.                 4 index setmatrix stroke
  172.             }
  173.         ifelse
  174.         grestore
  175.         moveto
  176.         2 copy rmoveto
  177.     } exch cshow
  178.     6 npop
  179. } def
  180.  
  181. % like awidthshow but add char to current path instead of fill
  182. /jsp                    % cx cy fillchar ax ay string jsp -
  183. {
  184.     {                    % cx cy fillchar ax ay char 0 0 {proc} -
  185.     2 npop 
  186.     (0) exch 2 copy 0 exch put 
  187.     32 eq 
  188.         { exch 5 index 5 index 5 index 5 -1 roll widthshow }
  189.         { false charpath }
  190.     ifelse
  191.     2 copy rmoveto
  192.     } exch cshow
  193. 5 npop
  194. } bd
  195.  
  196. % text painting operators
  197.  
  198. % set up for awidthshow
  199. % string trj cx cy fillchar ax ay string
  200. /trj { _cx 0 32 _ax 0 6 5 roll } bd
  201.  
  202. % awidthshow (fill)
  203. % string pjsf -
  204. /pjsf { trj sfc awidthshow } bd
  205.  
  206. % awidthshow (stroke)
  207. % string pjss -
  208. /pjss { trj _ctm ssc jss } bd
  209.  
  210. % awidthshow (clip)
  211. % string pjsc -
  212. /pjsc { trj jsp } bd
  213.  
  214. % define a version of Tj for the 8 Tr modes
  215. % show justified text
  216. % textString Tj -
  217. /_Tjdef [
  218.     % 0 fill
  219.         /pjsf load
  220.     % 1 stroke
  221.         /pjss load
  222.     { % 2 fill and stroke
  223.         dup
  224.         currentpoint 3 2 roll
  225.         pjsf
  226.         newpath moveto
  227.         pjss
  228.     } bind
  229.     { % 3 invisible
  230.         trj swj rmoveto
  231.     } bind
  232.     { % 4 fill and clip
  233.         dup currentpoint 4 2 roll gsave 
  234.         pjsf
  235.         grestore 3 1 roll moveto
  236.         pjsc 
  237.     } bind
  238.     { % 5 stroke and clip
  239.         dup currentpoint 4 2 roll
  240.         currentpoint gsave newpath moveto
  241.         pjss
  242.         grestore 3 1 roll moveto
  243.         pjsc 
  244.     } bind
  245.     { % 6 fill stroke and clip
  246.         dup currentpoint 4 2 roll gsave
  247.         dup currentpoint 3 2 roll
  248.         pjsf
  249.         newpath moveto
  250.         pjss
  251.         grestore 3 1 roll moveto
  252.         pjsc
  253.     } bind
  254.     % 7 clip
  255.         /pjsc load
  256. ] def
  257.  
  258. % begin/end text
  259. /BT % begin text                    % - BT -
  260. {
  261.     /_inT true dd
  262.     _ctm currentmatrix pop matrix _tm copy pop
  263.     0 _rise translate _hs 1 scale
  264.     0 0 moveto
  265. } bd
  266. /ET % end text                        % - ET -
  267. {
  268.     /_inT false dd
  269.     _tr 3 gt {clip} if
  270.     _ctm setmatrix newpath
  271. } bd
  272.  
  273. % Render mode                    % render Tr - 
  274. /Tr    {
  275.     _inT { _tr 3 le {currentpoint newpath moveto} if } if
  276.     dup /_tr xdd
  277.     _Tjdef exch get /Tj xdd
  278. } bd
  279.  
  280. % Text matrix operators
  281.  
  282. % internal set text matrix        % - iTm -    (uses _tm as implicit argument)
  283. /iTm { _ctm setmatrix _tm concat 0 _rise translate _hs 1 scale } bd
  284.  
  285. % set text matrix                % a b c d tx ty Tm -
  286. /Tm { _tm astore pop iTm 0 0 moveto } bd
  287.  
  288. % translate text matrix         % tx ty Td -
  289. /Td { _mtx translate _tm _tm concatmatrix pop iTm 0 0 moveto } bd
  290.  
  291. % translate text matrix, set leading         % tx ty TD -
  292. /TD { dup /_ld xdd Td } bd
  293.  
  294. % Attributes
  295.  
  296. % set font name and size        % fontname size Tf -
  297. /Tf    {
  298.     dup 1000 div /_fScl xdd
  299.     exch findfont exch scalefont setfont
  300. } bd
  301.  
  302. % set leading                    % leading TL -
  303. /TL    { neg /_ld xdd } bd
  304.  
  305. % set computed word spacing        % wordSpace Tw
  306. /Tw    { /_cx xdd } bd
  307.  
  308. % set computed char spacing     % charSpace Tc -
  309. /Tc    { /_ax xdd } bd
  310.  
  311. % set super/subscripting (rise)    % rise Ts -
  312. /Ts { /_rise xdd currentpoint iTm moveto } bd
  313.  
  314. % set horizontal scaling        % scalePercent Tz -
  315. /Tz { 100 div /_hs xdd iTm } bd
  316.  
  317. % Text Bodies
  318.  
  319. % kern    % autoKern kernValue Tk -
  320. % autoKern = 0 -> manual kern, = 1 -> auto kern
  321. % kernValue = kern value in em/1000 space
  322. /Tk { exch pop _fScl mul neg 0 rmoveto } bd
  323.  
  324. % carriage return & line feed    % - T* -
  325. /T* { 0 _ld Td } bd
  326.  
  327. % short-hand for CRLF & show text    % - ' -
  328. /' { 0 0 3 -1 roll " } bd
  329.  
  330. % short-hand for CRLF & show justified text    % wordSpace charSpace string " -
  331. /" { exch Tc exch Tw T* Tj } bd
  332.  
  333. /TJ { % string-based xshow % [ strings & kern offsets ] TJ
  334.     {
  335.         dup type /stringtype eq
  336.             { Tj }
  337.             { 0 exch Tk }
  338.         ifelse
  339.     } forall
  340. } bd
  341.  
  342. % print a discretionary hyphen    % - T- -
  343. /T-    { _hy Tj } bd
  344.  
  345. % Type 3 support
  346. /d0/setcharwidth ld
  347. % Don't allow color changes if setcachedevice
  348. /d1 { setcachedevice /sfc{}dd /ssc{}dd } bd
  349. /nND {{/.notdef} repeat} bd    % int nND -
  350. /T3Defs {            % def shared BuildChar & BuildGlyph
  351.     /BuildChar
  352.     {
  353.         1 index /Encoding get exch get
  354.         1 index /BuildGlyph get exec
  355.     }
  356.     def
  357.     /BuildGlyph {   % fontdict /name BuildGlyph -
  358.         exch begin
  359.         GlyphProcs exch get exec
  360.         end
  361.     } def
  362. } bd
  363.  
  364. /MakeBold {            % newname oldname -
  365.     findfont dup dup length 2 add dict
  366.     begin
  367.         CopyFont
  368.         /PaintType 2 def
  369.         /StrokeWidth .03 0 FontMatrix idtransform pop def
  370.         /dummybold currentdict
  371.     end
  372.     definefont        % newname painttype2font
  373.     8 dict begin
  374.         /_basefont exch def
  375.         /_basefonto exch def
  376.         /FontType 3 def
  377.         /FontMatrix[1 0 0 1 0 0]def
  378.         /FontBBox[0 0 1 1]def
  379.         /Encoding StandardEncoding def
  380.         /BuildChar
  381.         {
  382.             exch begin
  383.                 _basefont setfont
  384.                 ( )dup 0 4 -1 roll put
  385.                 dup stringwidth
  386.                 1 index 0 ne { exch .03 add exch }if
  387.                 setcharwidth
  388.                 0 0 moveto
  389.                 gsave
  390.                 dup show
  391.                 grestore
  392.                 _basefonto setfont
  393.                 show
  394.             end
  395.         }bd
  396.         currentdict
  397.     end
  398.     definefont pop
  399. }bd
  400.  
  401. /MakeItalic {            % newname oldname - 
  402.     findfont _italMtx makefont
  403.     dup length dict
  404.     begin
  405.         CopyFont
  406.                         % newname 
  407.         currentdict
  408.     end
  409.     definefont pop
  410. }bd
  411.  
  412. /MakeBoldItalic {        % newname oldname -
  413.     /dummybold exch
  414.     MakeBold
  415.     /dummybold
  416.     MakeItalic
  417. }bd
  418.  
  419. currentdict readonly pop end
  420. %%EndFile
  421.