home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / pphs.ps < prev    next >
Text File  |  2003-12-13  |  7KB  |  222 lines

  1. %    Copyright (C) 2001 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: pphs.ps,v 1.5.2.1 2003/12/12 22:07:59 giles Exp $
  14. % Print Linearized PDF hint streams
  15.  
  16. % Utilities
  17. /read1 {    % <file> read1 <value>
  18.   read not {
  19.     (**** Unexpected EOF) = flush quit
  20.   } if
  21. } bind def
  22. /read2 {    % <file> read2 <value>
  23.   dup read1 8 bitshift exch read1 add
  24. } bind def
  25. /read4 {    % <file> read4 <value>
  26.   dup read2 16 bitshift exch read2 add
  27. } bind def
  28. % Free variables: Bits, Bitsleft
  29. /readninit {    % - <readninit> -
  30.   /Bits 0 def
  31.   /Bitsleft 0 def
  32. } bind def
  33.  
  34. /pdftoken {    % <file> pdftoken <token>
  35.   dup token pop
  36.   dup type /nametype eq 1 index xcheck and {
  37.     dup dup (<<) cvn eq exch ([) eq or {
  38.       exec exch {
  39.     dup pdftoken dup dup (>>) cvn eq exch (]) eq or {
  40.       exch pop exec exit
  41.     } if exch
  42.       } loop
  43.     } {
  44.       exch pop
  45.     } ifelse
  46.   } {
  47.     exch pop
  48.   } ifelse
  49. } bind def
  50. /makemask {    % <nbits> makemask <mask>
  51.   1 exch bitshift 1 sub
  52. } bind def
  53. /readn {    % <file> <nbits> readn <value>
  54.   dup Bitsleft le {
  55.     exch pop
  56.     /Bitsleft Bitsleft 2 index sub def
  57.     makemask Bits Bitsleft neg bitshift and
  58.   } {
  59.     Bitsleft makemask Bits and
  60.     exch Bitsleft sub exch 1 index bitshift 3 1 roll
  61.     /Bits 2 index read1 def /Bitsleft 8 def
  62.     readn add
  63.   } ifelse
  64. } bind def
  65. /sread {    % <string> sread <file>
  66.   0 () /SubFileDecode filter
  67. } bind def
  68.  
  69. /ptag {        % <pre-tag> <proc> <post-tag> ptag -
  70.   3 -1 roll print (: ) print
  71.   exch exec
  72.   (        % ) print =
  73. } bind def
  74.  
  75. % Print the linearization parameters dictionary.
  76. /plpkeys <<
  77.   /E (end of p. 1 objects)
  78.   /L (total file length)
  79.   /H (PHS start + length)
  80.   /N (# of pages)
  81.   /O (p. 1 object #)
  82.   /T (offset of first main xref entry)
  83. >> def
  84. /plpdict {    % <dict> plpdict -
  85.   (<<) = plpkeys {
  86.     2 index 2 index .knownget {
  87.     % Stack: dict key label value
  88.       (  ) print 3 -1 roll ===only ( ) print ===only
  89.       (        % ) print =
  90.     } {
  91.       pop pop
  92.     } ifelse
  93.   } forall {
  94.     plpkeys 2 index known {
  95.       pop pop
  96.     } {
  97.       (  ) print exch ===only ( ) print ===
  98.     } ifelse
  99.   } forall (>>) =
  100. } bind def
  101.  
  102. % Print the Page Offset Hint Table.
  103. /ppoht {    % <npages> <file> ppoht -
  104.  
  105.   20 dict begin
  106.   /f exch def
  107.   /npages exch def
  108.   readninit
  109.  
  110.   (1) { f read4 =only } (least # objs/page) ptag
  111.   (2) { f read4 =only } (offset of p. 1 object (+PHS length if beyond PHS)) ptag
  112.   (3) { f read2 dup =only /nb3 exch def } (# bits for # objs/page delta) ptag
  113.   (4) { f read4 =only } (least # bytes/page) ptag
  114.   (5) { f read2 dup =only /nb5 exch def } (# bits for # bytes/page delta) ptag
  115.   (6) { f read4 =only } (least content stream offset-in-page) ptag
  116.   (7) { f read2 dup =only /nb7 exch def } (# bits for content stream offset delta) ptag
  117.   (8) { f read4 =only } (least content stream length) ptag
  118.   (9) { f read2 dup =only /nb9 exch def } (# bits for content stream length delta) ptag
  119.   (10) { f read2 dup =only /nb10 exch def } (# bits for # of shared obj refs) ptag
  120.   (11) { f read2 dup =only /nb11 exch def } (# bits for shared obj indices) ptag
  121.   (12) { f read2 dup =only /nb12 exch def } (# bits for shared obj ref pos numerators) ptag
  122.   (13) { f read2 =only } (shared obj ref pos denominator) ptag
  123.  
  124.   (*1) { [ npages { f nb3 readn } repeat ] ==only } (# objs/page deltas (see 1,3)) ptag
  125.   (*2) { [ npages { f nb5 readn } repeat ] ==only } (# bytes/page deltas (see 4,5)) ptag
  126.   (*3) { [ npages { f nb10 readn } repeat ] dup ==only /nso exch def } (# of shared obj refs (see 10)) ptag
  127.   (*4) { [ nso { [ exch { f nb11 readn } repeat ] } forall ] ==only } (shared obj indices (see 11)) ptag
  128.   (*5) { [ nso { [ exch { f nb12 readn } repeat ] } forall ] ==only } (shared obj ref pos numerators (see 12)) ptag
  129.   (*6) { [ npages { f nb7 readn } repeat ] ==only } (content stream offset-in-page deltas (see 6,7)) ptag
  130.   (*7) { [ npages { f nb9 readn } repeat ] ==only } (content stream length deltas (see 8,9)) ptag
  131.  
  132.   end        % temp dict
  133.  
  134. } bind def
  135.  
  136. % Print the Shared Objects Hint Table.
  137. /psoht {    % <file> psoht -
  138.  
  139.   20 dict begin
  140.   /f exch def
  141.   readninit
  142.  
  143.   (1) { f read4 =only } (first shared obj #) ptag
  144.   (2) { f read4 =only } (first shared obj offset (+PHS length if beyond PHS)) ptag
  145.   (3) { f read4 dup =only /n3 exch def } (# of p. 1 shared objs) ptag
  146.   (4) { f read4 dup =only /n4 exch def } (total # of shared objs) ptag
  147.   (5) { f read2 dup =only /nb5 exch def } (# bits for # of shared objs/group) ptag
  148.   (6) { f read4 =only } (least shared obj group length) ptag
  149.   (7) { f read2 dup =only /nb7 exch def } (# bits for shared obj group length delta) ptag
  150.  
  151.   /nse n4 def
  152.   (*1) { [ nse { f nb7 readn } repeat ] ==only } (shared obj group length deltas (see 6,7)) ptag
  153.   (*2) { [ nse { f 1 readn } repeat ] dup ==only /md5s exch def } (MD5 present?) ptag
  154.   (*3:) = md5s {
  155.     0 ne {
  156.       (  ) print f 16 string readstring pop
  157.       (%stdout) (w) file dup 3 -1 roll writehexstring closefile () =
  158.     } if
  159.   } forall
  160.   (*4) { [ nse { f nb5 readn } repeat ] ==only } (# objs/group (see 5)) ptag
  161.  
  162.   end        % temp dict
  163.  
  164. } bind def
  165.  
  166. % Print the Primary Hint Stream of a PDF file.
  167. /pphs {        % <file> pphs -
  168.   /pdf exch def
  169.  
  170.     % Read the linearization parameter dictionary.
  171.   { pdf pdftoken /obj eq { exit } if } loop
  172.   pdf pdftoken /lpdict exch def
  173.   /lpdict type /dicttype eq { lpdict /Linearized known } { false } ifelse {
  174.     (Not a linearized PDF file.) = stop
  175.   } if
  176.  
  177.   lpdict plpdict flush
  178.  
  179.     % Read the primary hint stream.
  180.   null {
  181.     pdf pdftoken dup /stream eq { pop exit } if
  182.     exch pop
  183.   } loop
  184.   /phsdict exch def
  185.     % Remove Length if indirect reference.
  186.   phsdict 0 known {
  187.     phsdict 0 undef  phsdict /Length undef
  188.   } if
  189.   (PHS: ) print phsdict === flush
  190.   pdf 0 (endstream) /SubFileDecode filter
  191.   dup 64000 string readstring pop exch closefile
  192.   sread /phsdata exch def
  193.  
  194.     % Decode the hint stream data if necessary.
  195.   phsdict /Filter .knownget {
  196.     phsdata exch filter
  197.     dup 5000 string readstring pop exch closefile
  198.     sread /phsdata exch def
  199.   } if
  200.  
  201.     % Adobe says we can assume /P = 0.
  202.   (Page Offset Hint Table:) =
  203.   lpdict /N get
  204.   phsdata phsdict /S get string readstring pop sread
  205.   ppoht
  206.   (Shared Objects Hint Table:) =
  207.   phsdata psoht
  208. } bind def
  209.  
  210. % Check for command line arguments.
  211. [ shellarguments
  212.  { ] dup length 1 eq
  213.     { 0 get (r) file dup pphs closefile }
  214.     { (Usage: pphs filename.pdf\n) print flush }
  215.    ifelse
  216.  }
  217.  { pop }
  218. ifelse
  219.