home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 February / INTERNET88.ISO / pc / software / windows / bits / pdf995 / data1.cab / Program_Executable_Files / res / cid2code.ps < prev    next >
Encoding:
Text File  |  2001-12-08  |  4.6 KB  |  161 lines

  1. %    Copyright (C) 1998 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of GNU Ghostscript.
  3. % GNU Ghostscript is distributed in the hope that it will be useful, but
  4. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  5. % to anyone for the consequences of using it or for whether it serves any
  6. % particular purpose or works at all, unless he says so in writing.  Refer
  7. % to the GNU General Public License for full details.
  8. % Everyone is granted permission to copy, modify and redistribute GNU
  9. % Ghostscript, but only under the conditions described in the GNU General
  10. % Public License.  A copy of this license is supposed to have been given
  11. % to you along with GNU Ghostscript so you can know your rights and
  12. % responsibilities.  It should be in a file named COPYING.  Among other
  13. % things, the copyright notice and this notice must be preserved on all
  14. % copies.
  15.  
  16. % $RCSfile: cid2code.ps,v $ $Revision: 1.2.2.1 $
  17. % Construct an inverse map from CIDs to codes.
  18.  
  19. % Create an inverse map from CIDs to code values.
  20. % We only use this for 16-bit Unicode, so it has some limitations.
  21. % After invoking .cmap2code, loading a CMap file prints out the map
  22. % instead of doing what it usually does.
  23.  
  24. /.cmap2codedict 10 dict begin
  25.  
  26. /begincmap {
  27.   mark
  28. } def
  29. /endcmap {
  30.         % Stack: mark code_lo1 code_hi1 cid1 ...
  31.   20 dict begin
  32.     /depth counttomark 3 sub def
  33.         % Do a first pass to determine the maximum CID.
  34.     0 0 3 depth {
  35.       1 add /d exch def
  36.       d index d 2 add index 1 get add d 3 add index 1 get sub .max
  37.     } for
  38.     1 add /ncid exch def
  39.     /map ncid 2 mul string def
  40.         % Now fill in the map.
  41.     0 3 depth {
  42.       /d exch def
  43.       d index 2 mul /cid2 exch def
  44.       d 1 add index /hi exch def
  45.       d 2 add index 2 string copy /lo exch def
  46.       lo 1 get 1 hi 1 get {
  47.     map cid2 lo 0 get put
  48.     map cid2 1 add 3 -1 roll put
  49.     /cid2 cid2 2 add def
  50.       } for
  51.     } for
  52.         % Print the map.
  53.     (%stdout) (w) file
  54.       dup (<) print
  55.       dup /ASCIIHexEncode filter
  56.     dup map writestring
  57.       closefile
  58.       () = flush
  59.     closefile
  60.   end
  61. } def
  62. %/begincodespacerange
  63. /endcodespacerange {cleartomark} def
  64. %/usecmap
  65.  
  66. %/beginbfchar
  67. /endbfchar {cleartomark} def
  68. %/beginbfrange
  69. /endbfrange {cleartomark} def
  70.  
  71. %/begincidchar
  72. /endcidchar {
  73.   counttomark 2 idiv { dup counttomark 1 add 3 roll } repeat pop
  74. } def
  75. %/begincidrange
  76. /endcidrange {
  77.   counttomark 1 add -1 roll pop
  78. } def
  79.  
  80. %/beginnotdefchar
  81. /endnotdefchar {cleartomark} def
  82. %/beginnotdefrange
  83. /endnotdefrange {cleartomark} def
  84.  
  85. currentdict end readonly def
  86.  
  87. /.cmap2code {        % - .cmap2code -
  88.   /CIDInit /ProcSet findresource dup length dict copy
  89.   .cmap2codedict { 3 copy put pop pop } forall
  90.   /CIDInit exch /ProcSet defineresource pop
  91. } def
  92.  
  93. % Extract and print reverse mapping information from a cid2code.txt file.
  94. /.printhex2 {        % <int16> .printhex2 -
  95.   (<) print
  96.   16#10000 add 16 =string cvrs 1 4 getinterval print
  97.   (>) print
  98. } def
  99. /.cid2code {        % <cmaptemplate> <file> <column> .cid2code -
  100.   30 dict begin
  101.   /column exch def
  102.   (r) file /f exch def
  103.   (%!) =
  104.   (/CIDInit /ProcSet findresource begin   12 dict begin   begincmap) =
  105.         % Print the information from the template.
  106.   {
  107.     exch ==only ( ) print
  108.     dup type /dicttype eq {
  109.       dup length =only ( dict dup begin) = {
  110.     (  ) print exch ===only ( ) print ===only ( def) =
  111.       } forall (end def) =
  112.     } {
  113.       ===only
  114.     } ifelse ( def) =
  115.   } forall
  116.         % Read the data from the cid2code.txt file.
  117.   {
  118.     f =string readline pop (CID\t) anchorsearch { pop pop exit } if pop
  119.   } loop
  120.   /map [ {
  121.     f =string readline not { pop exit } if
  122.     column { (\t) search pop pop pop } repeat
  123.     (\t) search { exch pop exch pop } if
  124.     (,) search { exch pop exch pop } if
  125.     dup length 4 ne { pop (*) } if
  126.     dup (*) eq { pop (0000) } if
  127.     (16#) exch concatstrings cvi
  128.   } loop ] def
  129.         % Print the code space range(s).
  130.   /maxcid map length 1 sub def
  131.   mark maxcid
  132.   dup 255 and 255 eq {
  133.     0 exch
  134.   } {
  135.     dup 16#ff00 and exch 0 2 index 1 sub
  136.   } ifelse
  137.   counttomark 2 idiv dup =only ( begincodespacerange) = {
  138.     exch .printhex2 .printhex2 () =
  139.   } repeat (endcodespacerange) =
  140.         % Print the map data.
  141.   0 1 100 maxcid {
  142.     /lo exch def
  143.     /hi lo 99 add maxcid .min def
  144.     0 lo 1 hi { map exch get 0 ne { 1 add } if } for
  145.     dup 0 eq {
  146.       pop
  147.     } {
  148.       =only ( begincidchar) = lo 1 hi {
  149.     map 1 index get dup 0 eq { pop pop } { exch .printhex2 = } ifelse
  150.       } for (endcidchar) =
  151.     } ifelse
  152.   } for
  153.         % Wrap up.
  154.   (endcmap   CMapName currentdict /CMap defineresource pop   end   end) =
  155.   f closefile
  156.   end
  157. } bind def
  158.