home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / gs403osk.tgz / gs403osk.tar / gs_cmap.ps < prev    next >
Text File  |  1996-09-22  |  7KB  |  231 lines

  1. %    Copyright (C) 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % ProcSet for implementing CMap resource.
  16. % When this is run, systemdict is still writable.
  17.  
  18. %**************** This file is not ready for use:
  19. %   - Rearranged fonts are not implemented.
  20. %   - It has never been tested on a real font.
  21.  
  22. /.setlanguagelevel where { pop 2 .setlanguagelevel } if
  23. .currentglobal true .setglobal
  24.  
  25. /GS_CMapInit_ProcSet 30 dict dup begin
  26.  
  27. % ---------------- CMap operators ---------------- %
  28.  
  29. % We create the following structures for character code mapping.
  30. %   Map - a multi-level array indexed by the successive bytes of
  31. %     the character code.  All of the arrays are read-only.
  32. %   NotdefMap - the same.
  33.  
  34. % ------ Font-level operators ------ %
  35.  
  36. % composefont doesn't appear in CMap files -- it's documented in
  37. % the "PostScript Language Reference Manual Supplement".
  38. /composefont        % <name> <cmap|cmapname> <fonts> composefont <font>
  39.  { exch dup /dicttype ne { /CMap findresource } if
  40.    10 dict
  41.      dup /FontType 0 put
  42.      dup /FMapType 9 put
  43.      dup /CMap 5 -1 roll put
  44.      dup /Encoding [ 0 1 6 index length 1 sub { } for ] put
  45.      dup /FDepVector 4 -1 roll put
  46.    /Font defineresource
  47.  } bind def
  48.  
  49. /begincmap      % - begincmap -
  50.  { /Map 256 array def
  51.    /NotdefMap 256 array def
  52.  } bind def
  53. /endcmap        % - endcmap -
  54.  { /Map Map .endmap def
  55.    /NotdefMap NotdefMap .endmap def
  56.  } bind def
  57.  
  58. /begincodespacerange    % <count> begincodespacerange -
  59.  { pop mark
  60.  } bind def
  61. /endcodespacerange  % <code_lo> <code_hi> ... endcodespacerange -
  62.  { counttomark 2 idiv
  63.     { 2 copy Map .addcodespacerange NotdefMap .addcodespacerange
  64.     } repeat pop
  65.  } bind def
  66.  
  67. /.addcodespacerange % <code_lo> <code_hi> <map> .addcodespacerange -
  68.  { 2 index length 1 eq
  69.     { 2 { 3 -1 roll 0 get } repeat 1 exch
  70.        { 2 copy 0 put pop } for pop
  71.     }
  72.     { 2 index 0 get 1 3 index 0 get
  73.       6 -2 roll
  74.       2 { 1 1 index length 1 sub getinterval 6 1 roll } repeat
  75.         % Stack: lo hi map lo0 1 hi0
  76.        { 2 copy get null eq { 2 copy 256 array put } if
  77.          4 copy get .addcodespacerange pop
  78.        }
  79.       for pop pop pop
  80.     }
  81.    ifelse
  82.  } bind def
  83. /.endmap        % <map> .endmap <map>
  84.  { dup type /arraytype eq { dup { .endmap exch } forall astore readonly } if
  85.  } bind def
  86.  
  87. /usecmap        % <CMap_name> usecmap -
  88.  { /CMap findresource
  89.    dup length dict .copydict
  90.    currentdict end exch .copydict begin
  91.  } bind def
  92.  
  93. % ------ Rearranged font operators ------ %
  94.  
  95. /beginrearrangedfont    % <font_name> <font*> beginrearrangedfont -
  96.  {  (NOT IMPLEMENTED YET.\n) print flush
  97.  } bind def
  98. /endrearrangedfont  % - endrearrangedfont -
  99.  {  (NOT IMPLEMENTED YET.\n) print flush
  100.  } bind def
  101.  
  102. /usefont        % <fontID> usefont -
  103.  {  (NOT IMPLEMENTED YET.\n) print flush
  104.  } bind def
  105.  
  106. /beginusematrix     % <fontID> beginusematrix -
  107.  {  (NOT IMPLEMENTED YET.\n) print flush
  108.  } bind def
  109. /endusematrix       % <matrix> endusematrix -
  110.  {  (NOT IMPLEMENTED YET.\n) print flush
  111.  } bind def
  112.  
  113. % ------ Character name/code selector operators ------ %
  114.  
  115. /beginbfchar        % <count> beginbfchar -
  116.  { pop mark
  117.  } bind def
  118. /endbfchar      % <code> <to_code|charname> ... endbfchar
  119.  { Map .endmapchar /Map exch store pop
  120.  } bind def
  121.  
  122. /beginbfrange       % <count> beginbfrange -
  123.  { pop mark
  124.  } bind def
  125. /endbfrange     % <code_lo> <code_hi> <to_code|(charname*)> ...
  126.             %   endbfrange -
  127.  { Map counttomark 3 idiv { .addbfrange } repeat /Map exch store pop
  128.  } bind def
  129.  
  130. /.addbfrange        % <code_lo> <code_hi> <to_code|(charname*)> <map>
  131.             %   .addbfrange <map>
  132.  { 1 index type /stringtype eq
  133.     {  { dup length string copy dup dup length 1 sub 2 copy get 1 add put }
  134.       exch .addmaprange
  135.     }
  136.     { 2 dict begin exch /codes 1 index def 0 get exch
  137.        { codes dup length 1 sub 1 exch getinterval /codes 1 index def
  138.      dup length 0 gt { 0 get } if
  139.        }
  140.       exch .addmaprange end
  141.     }
  142.    ifelse exch pop
  143.  } bind def
  144.  
  145. % ------ CID selector operators ------ %
  146.  
  147. /begincidchar       % <count> begincidchar -
  148.  { pop mark
  149.  } bind def
  150. /endcidchar     % <code> <cid> ... endcidchar -
  151.  { Map .endmapchar /Map exch store pop
  152.  } bind def
  153.  
  154. /begincidrange      % <count> begincidrange -
  155.  { pop mark
  156.  } bind def
  157. /endcidrange        % <code_lo> <code_hi> <cid_base> ... endcidrange -
  158.  { Map counttomark 3 idiv { { 1 add } exch .addmaprange exch pop } repeat
  159.    /Map exch store pop
  160.  } bind def
  161.  
  162. /.endmapchar        % <code> <value> ... <map> .endmapchar -
  163.  { counttomark 2 idiv
  164.     { 2 index 3 1 roll { } exch .addmaprange exch pop
  165.     } repeat exch pop
  166.  } bind def
  167.  
  168. /.addmaprange       % <code_lo> <code_hi> <value_base> <next_proc> <map>
  169.             %   .addcidrange <value_next> <map>
  170.  {  % We may be updating a (partly) read-only map from another CMap.
  171.     % If so, implement copy-on-write.
  172.    dup wcheck not { dup length array copy } if
  173.    4 index length 1 eq
  174.     { 2 { 5 -1 roll 0 get } repeat 1 exch
  175.        {    % Stack: value proc map code
  176.      2 copy 5 index put pop
  177.      3 -1 roll 2 index exec 3 1 roll
  178.        } for
  179.     }
  180.     { 4 index 0 get 1 5 index 0 get
  181.       8 -2 roll
  182.       2 { 1 1 index length 1 sub getinterval 8 1 roll } repeat
  183.         % Stack: lo hi next proc map lo0 1 hi0
  184.        { 6 copy get .addmaprange
  185.         % Stack: lo hi oldnext proc map i next submap
  186.      exch 6 1 roll 5 -1 roll pop
  187.         % Stack: lo hi next proc map i submap
  188.      3 copy put pop pop
  189.        }
  190.       for 5 -2 roll pop pop
  191.     }
  192.    ifelse exch pop
  193.  } bind def
  194.  
  195. % ------ notdef operators ------ %
  196.  
  197. /beginnotdefchar    % <count> beginnotdefchar -
  198.  { pop mark
  199.  } bind def
  200. /endnotdefchar      % <code> <cid> ... endnotdefchar -
  201.  { counttomark 2 idiv { 1 index exch .addnotdefrange } repeat pop
  202.  } bind def
  203.  
  204. /beginnotdefrange   % <count> beginnotdefrange -
  205.  { pop mark
  206.  } bind def
  207. /endnotdefrange     % <code_lo> <code_hi> <cid> ... endnotdefrange -
  208.  { counttomark 3 idiv { .addnotdefrange } repeat pop
  209.  } bind def
  210.  
  211. /.addnotdefrange    % <code_lo> <code_hi> <cid_base> .addnotdefrange -
  212.  { { } NotdefMap .addmaprange /NotdefMap exch store pop
  213.  } bind def
  214.  
  215. % ---------------- Resource category definition ---------------- %
  216.  
  217. end readonly def
  218.  
  219. /defineresource where
  220.  { pop
  221.    /CMap /Generic /Category findresource dup length dict .copydict
  222.    /Category defineresource pop
  223.    /CMapInit GS_CMapInit_ProcSet /ProcSet defineresource pop
  224.  }
  225. if
  226.  
  227. .setglobal
  228.