home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 September / PCWorld_2001-09_cd.bin / Software / Vyzkuste / rychlokurz / gs700w32.exe / gs7.00 / lib / cid2code.ps < prev    next >
Text File  |  2000-11-30  |  5KB  |  163 lines

  1. %    Copyright (C) 1998, 2000 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: cid2code.ps,v 1.3 2000/11/30 18:22:11 lpd Exp $
  16. % Construct an inverse map from CIDs to codes.
  17.  
  18. % Create an inverse map from CIDs to code values.
  19. % We only use this for 16-bit Unicode, so it has some limitations.
  20. % After invoking .cmap2code, loading a CMap file prints out the map
  21. % instead of doing what it usually does.  For example:
  22. %
  23. %    gs -dNODISPLAY -dBATCH lib/cid2code.ps -c .cmap2code\
  24. %      -f Resource/CMap/UniJIS-UCS2-H > mapfile
  25.  
  26. /.cmap2codedict 10 dict begin
  27.  
  28. /begincmap {
  29.   mark
  30. } def
  31. /endcmap {
  32.         % Stack: mark code_lo1 code_hi1 cid1 ...
  33.   20 dict begin
  34.     /depth counttomark 3 sub def
  35.         % Do a first pass to determine the maximum CID.
  36.     0 0 3 depth {
  37.       1 add /d exch def
  38.       d index d 2 add index 1 get add d 3 add index 1 get sub .max
  39.     } for
  40.     1 add /ncid exch def
  41.     /map ncid 2 mul string def
  42.         % Now fill in the map.
  43.     0 3 depth {
  44.       /d exch def
  45.       d index 2 mul /cid2 exch def
  46.       d 1 add index /hi exch def
  47.       d 2 add index 2 string copy /lo exch def
  48.       lo 1 get 1 hi 1 get {
  49.     map cid2 lo 0 get put
  50.     map cid2 1 add 3 -1 roll put
  51.     /cid2 cid2 2 add def
  52.       } for
  53.     } for
  54.         % Print the map.
  55.     (%stdout) (w) file
  56.       dup (<) print
  57.       dup /ASCIIHexEncode filter
  58.     dup map writestring
  59.       closefile
  60.       () = flush
  61.     closefile
  62.   end
  63. } def
  64. %/begincodespacerange
  65. /endcodespacerange {cleartomark} def
  66. %/usecmap
  67.  
  68. %/beginbfchar
  69. /endbfchar {cleartomark} def
  70. %/beginbfrange
  71. /endbfrange {cleartomark} def
  72.  
  73. %/begincidchar
  74. /endcidchar {
  75.   counttomark 2 idiv { dup counttomark 1 add 3 roll } repeat pop
  76. } def
  77. %/begincidrange
  78. /endcidrange {
  79.   counttomark 1 add -1 roll pop
  80. } def
  81.  
  82. %/beginnotdefchar
  83. /endnotdefchar {cleartomark} def
  84. %/beginnotdefrange
  85. /endnotdefrange {cleartomark} def
  86.  
  87. currentdict end readonly def
  88.  
  89. /.cmap2code {        % - .cmap2code -
  90.   /CIDInit /ProcSet findresource dup length dict copy
  91.   .cmap2codedict { 3 copy put pop pop } forall
  92.   /CIDInit exch /ProcSet defineresource pop
  93. } def
  94.  
  95. % Extract and print reverse mapping information from a cid2code.txt file.
  96. /.printhex2 {        % <int16> .printhex2 -
  97.   (<) print
  98.   16#10000 add 16 =string cvrs 1 4 getinterval print
  99.   (>) print
  100. } def
  101. /.cid2code {        % <cmaptemplate> <file> <column> .cid2code -
  102.   30 dict begin
  103.   /column exch def
  104.   (r) file /f exch def
  105.   (%!) =
  106.   (/CIDInit /ProcSet findresource begin   12 dict begin   begincmap) =
  107.         % Print the information from the template.
  108.   {
  109.     exch ==only ( ) print
  110.     dup type /dicttype eq {
  111.       dup length =only ( dict dup begin) = {
  112.     (  ) print exch ===only ( ) print ===only ( def) =
  113.       } forall (end def) =
  114.     } {
  115.       ===only
  116.     } ifelse ( def) =
  117.   } forall
  118.         % Read the data from the cid2code.txt file.
  119.   {
  120.     f =string readline pop (CID\t) anchorsearch { pop pop exit } if pop
  121.   } loop
  122.   /map [ {
  123.     f =string readline not { pop exit } if
  124.     column { (\t) search pop pop pop } repeat
  125.     (\t) search { exch pop exch pop } if
  126.     (,) search { exch pop exch pop } if
  127.     dup length 4 ne { pop (*) } if
  128.     dup (*) eq { pop (0000) } if
  129.     (16#) exch concatstrings cvi
  130.   } loop ] def
  131.         % Print the code space range(s).
  132.   /maxcid map length 1 sub def
  133.   mark maxcid
  134.   dup 255 and 255 eq {
  135.     0 exch
  136.   } {
  137.     dup 16#ff00 and exch 0 2 index 1 sub
  138.   } ifelse
  139.   counttomark 2 idiv dup =only ( begincodespacerange) = {
  140.     exch .printhex2 .printhex2 () =
  141.   } repeat (endcodespacerange) =
  142.         % Print the map data.
  143.   0 1 100 maxcid {
  144.     /lo exch def
  145.     /hi lo 99 add maxcid .min def
  146.     0 lo 1 hi { map exch get 0 ne { 1 add } if } for
  147.     dup 0 eq {
  148.       pop
  149.     } {
  150.       =only ( begincidchar) = lo 1 hi {
  151.     map 1 index get dup 0 eq { pop pop } { exch .printhex2 = } ifelse
  152.       } for (endcidchar) =
  153.     } ifelse
  154.   } for
  155.         % Wrap up.
  156.   (endcmap   CMapName currentdict /CMap defineresource pop   end   end) =
  157.   f closefile
  158.   end
  159. } bind def
  160.