home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / Chip_2002-10_cd1.bin / zkuste / pdf / download / gs704w32.exe / gs7.04 / lib / pphs.ps < prev    next >
Encoding:
Text File  |  2002-01-31  |  7.2 KB  |  224 lines

  1. %    Copyright (C) 2001 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of AFPL Ghostscript.
  3. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  4. % distributor accepts any responsibility for the consequences of using it, or
  5. % for whether it serves any particular purpose or works at all, unless he or
  6. % she says so in writing.  Refer to the Aladdin Free Public License (the
  7. % "License") for full details.
  8. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. % in a plain ASCII text file named PUBLIC.  The License grants you the right
  10. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. % conditions described in the License.  Among other things, the License
  12. % requires that the copyright notice and this notice be preserved on all
  13. % copies.
  14.  
  15. % $Id: pphs.ps,v 1.3 2001/07/24 22:24:28 lpd Exp $
  16. % Print Linearized PDF hint streams
  17.  
  18. % Utilities
  19. /read1 {    % <file> read1 <value>
  20.   read not {
  21.     (**** Unexpected EOF) = flush quit
  22.   } if
  23. } bind def
  24. /read2 {    % <file> read2 <value>
  25.   dup read1 8 bitshift exch read1 add
  26. } bind def
  27. /read4 {    % <file> read4 <value>
  28.   dup read2 16 bitshift exch read2 add
  29. } bind def
  30. % Free variables: Bits, Bitsleft
  31. /readninit {    % - <readninit> -
  32.   /Bits 0 def
  33.   /Bitsleft 0 def
  34. } bind def
  35.  
  36. /pdftoken {    % <file> pdftoken <token>
  37.   dup token pop
  38.   dup type /nametype eq 1 index xcheck and {
  39.     dup dup (<<) cvn eq exch ([) eq or {
  40.       exec exch {
  41.     dup pdftoken dup dup (>>) cvn eq exch (]) eq or {
  42.       exch pop exec exit
  43.     } if exch
  44.       } loop
  45.     } {
  46.       exch pop
  47.     } ifelse
  48.   } {
  49.     exch pop
  50.   } ifelse
  51. } bind def
  52. /makemask {    % <nbits> makemask <mask>
  53.   1 exch bitshift 1 sub
  54. } bind def
  55. /readn {    % <file> <nbits> readn <value>
  56.   dup Bitsleft le {
  57.     exch pop
  58.     /Bitsleft Bitsleft 2 index sub def
  59.     makemask Bits Bitsleft neg bitshift and
  60.   } {
  61.     Bitsleft makemask Bits and
  62.     exch Bitsleft sub exch 1 index bitshift 3 1 roll
  63.     /Bits 2 index read1 def /Bitsleft 8 def
  64.     readn add
  65.   } ifelse
  66. } bind def
  67. /sread {    % <string> sread <file>
  68.   0 () /SubFileDecode filter
  69. } bind def
  70.  
  71. /ptag {        % <pre-tag> <proc> <post-tag> ptag -
  72.   3 -1 roll print (: ) print
  73.   exch exec
  74.   (        % ) print =
  75. } bind def
  76.  
  77. % Print the linearization parameters dictionary.
  78. /plpkeys <<
  79.   /E (end of p. 1 objects)
  80.   /L (total file length)
  81.   /H (PHS start + length)
  82.   /N (# of pages)
  83.   /O (p. 1 object #)
  84.   /T (offset of first main xref entry)
  85. >> def
  86. /plpdict {    % <dict> plpdict -
  87.   (<<) = plpkeys {
  88.     2 index 2 index .knownget {
  89.     % Stack: dict key label value
  90.       (  ) print 3 -1 roll ===only ( ) print ===only
  91.       (        % ) print =
  92.     } {
  93.       pop pop
  94.     } ifelse
  95.   } forall {
  96.     plpkeys 2 index known {
  97.       pop pop
  98.     } {
  99.       (  ) print exch ===only ( ) print ===
  100.     } ifelse
  101.   } forall (>>) =
  102. } bind def
  103.  
  104. % Print the Page Offset Hint Table.
  105. /ppoht {    % <npages> <file> ppoht -
  106.  
  107.   20 dict begin
  108.   /f exch def
  109.   /npages exch def
  110.   readninit
  111.  
  112.   (1) { f read4 =only } (least # objs/page) ptag
  113.   (2) { f read4 =only } (offset of p. 1 object (+PHS length if beyond PHS)) ptag
  114.   (3) { f read2 dup =only /nb3 exch def } (# bits for # objs/page delta) ptag
  115.   (4) { f read4 =only } (least # bytes/page) ptag
  116.   (5) { f read2 dup =only /nb5 exch def } (# bits for # bytes/page delta) ptag
  117.   (6) { f read4 =only } (least content stream offset-in-page) ptag
  118.   (7) { f read2 dup =only /nb7 exch def } (# bits for content stream offset delta) ptag
  119.   (8) { f read4 =only } (least content stream length) ptag
  120.   (9) { f read2 dup =only /nb9 exch def } (# bits for content stream length delta) ptag
  121.   (10) { f read2 dup =only /nb10 exch def } (# bits for # of shared obj refs) ptag
  122.   (11) { f read2 dup =only /nb11 exch def } (# bits for shared obj indices) ptag
  123.   (12) { f read2 dup =only /nb12 exch def } (# bits for shared obj ref pos numerators) ptag
  124.   (13) { f read2 =only } (shared obj ref pos denominator) ptag
  125.  
  126.   (*1) { [ npages { f nb3 readn } repeat ] ==only } (# objs/page deltas (see 1,3)) ptag
  127.   (*2) { [ npages { f nb5 readn } repeat ] ==only } (# bytes/page deltas (see 4,5)) ptag
  128.   (*3) { [ npages { f nb10 readn } repeat ] dup ==only /nso exch def } (# of shared obj refs (see 10)) ptag
  129.   (*4) { [ nso { [ exch { f nb11 readn } repeat ] } forall ] ==only } (shared obj indices (see 11)) ptag
  130.   (*5) { [ nso { [ exch { f nb12 readn } repeat ] } forall ] ==only } (shared obj ref pos numerators (see 12)) ptag
  131.   (*6) { [ npages { f nb7 readn } repeat ] ==only } (content stream offset-in-page deltas (see 6,7)) ptag
  132.   (*7) { [ npages { f nb9 readn } repeat ] ==only } (content stream length deltas (see 8,9)) ptag
  133.  
  134.   end        % temp dict
  135.  
  136. } bind def
  137.  
  138. % Print the Shared Objects Hint Table.
  139. /psoht {    % <file> psoht -
  140.  
  141.   20 dict begin
  142.   /f exch def
  143.   readninit
  144.  
  145.   (1) { f read4 =only } (first shared obj #) ptag
  146.   (2) { f read4 =only } (first shared obj offset (+PHS length if beyond PHS)) ptag
  147.   (3) { f read4 dup =only /n3 exch def } (# of p. 1 shared objs) ptag
  148.   (4) { f read4 dup =only /n4 exch def } (total # of shared objs) ptag
  149.   (5) { f read2 dup =only /nb5 exch def } (# bits for # of shared objs/group) ptag
  150.   (6) { f read4 =only } (least shared obj group length) ptag
  151.   (7) { f read2 dup =only /nb7 exch def } (# bits for shared obj group length delta) ptag
  152.  
  153.   /nse n4 def
  154.   (*1) { [ nse { f nb7 readn } repeat ] ==only } (shared obj group length deltas (see 6,7)) ptag
  155.   (*2) { [ nse { f 1 readn } repeat ] dup ==only /md5s exch def } (MD5 present?) ptag
  156.   (*3:) = md5s {
  157.     0 ne {
  158.       (  ) print f 16 string readstring pop
  159.       (%stdout) (w) file dup 3 -1 roll writehexstring closefile () =
  160.     } if
  161.   } forall
  162.   (*4) { [ nse { f nb5 readn } repeat ] ==only } (# objs/group (see 5)) ptag
  163.  
  164.   end        % temp dict
  165.  
  166. } bind def
  167.  
  168. % Print the Primary Hint Stream of a PDF file.
  169. /pphs {        % <file> pphs -
  170.   /pdf exch def
  171.  
  172.     % Read the linearization parameter dictionary.
  173.   { pdf pdftoken /obj eq { exit } if } loop
  174.   pdf pdftoken /lpdict exch def
  175.   /lpdict type /dicttype eq { lpdict /Linearized known } { false } ifelse {
  176.     (Not a linearized PDF file.) = stop
  177.   } if
  178.  
  179.   lpdict plpdict flush
  180.  
  181.     % Read the primary hint stream.
  182.   null {
  183.     pdf pdftoken dup /stream eq { pop exit } if
  184.     exch pop
  185.   } loop
  186.   /phsdict exch def
  187.     % Remove Length if indirect reference.
  188.   phsdict 0 known {
  189.     phsdict 0 undef  phsdict /Length undef
  190.   } if
  191.   (PHS: ) print phsdict === flush
  192.   pdf 0 (endstream) /SubFileDecode filter
  193.   dup 5000 string readstring pop exch closefile
  194.   sread /phsdata exch def
  195.  
  196.     % Decode the hint stream data if necessary.
  197.   phsdict /Filter .knownget {
  198.     phsdata exch filter
  199.     dup 5000 string readstring pop exch closefile
  200.     sread /phsdata exch def
  201.   } if
  202.  
  203.     % Adobe says we can assume /P = 0.
  204.   (Page Offset Hint Table:) =
  205.   lpdict /N get
  206.   phsdata phsdict /S get string readstring pop sread
  207.   ppoht
  208.   (Shared Objects Hint Table:) =
  209.   phsdata psoht
  210. } bind def
  211.  
  212. % Check for command line arguments.
  213. [ shellarguments
  214.  { ] dup length 1 eq
  215.     { 0 get (r) file dup pphs closefile }
  216.     { (Usage: pphs filename.pdf\n) print flush }
  217.    ifelse
  218.  }
  219.  { pop }
  220. ifelse
  221.