home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / cid2code.ps < prev    next >
Text File  |  2002-02-22  |  5KB  |  161 lines

  1. %    Copyright (C) 1998, 2000 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: cid2code.ps,v 1.5 2002/02/21 21:49:28 giles Exp $
  14. % Construct an inverse map from CIDs to codes.
  15.  
  16. % Create an inverse map from CIDs to code values.
  17. % We only use this for 16-bit Unicode, so it has some limitations.
  18. % After invoking .cmap2code, loading a CMap file prints out the map
  19. % instead of doing what it usually does.  For example:
  20. %
  21. %    gs -dNODISPLAY -dBATCH lib/cid2code.ps -c .cmap2code\
  22. %      -f Resource/CMap/UniJIS-UCS2-H > mapfile
  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.