home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / gs_typ32.ps < prev    next >
Text File  |  2000-03-09  |  4KB  |  130 lines

  1. %    Copyright (C) 1997 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. % $Id: gs_typ32.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  16. % Initialization file for Type 32 fonts.
  17.  
  18. % ------ Type 32 fonts ------ %
  19.  
  20. % We need LanguageLevel 2 or higher in order to have defineresource.
  21. languagelevel dup 2 max .setlanguagelevel
  22.  
  23. /BitmapFontInit mark
  24.  
  25. /.makeglyph32 systemdict /.makeglyph32 get
  26. systemdict /.makeglyph32 .undef
  27.  
  28. /addglyph {    % ([wx wy llx lly urx ury] |
  29.         %     [w0x w0y llx lly urx ury w1x w1y vx vy])
  30.         %   <bitmap> <cid> <type32font> addglyph -
  31.   1 index dup 2 index .removeglyphs
  32.   22 string .makeglyph32
  33.         % Stack: metrics bitmap cid font metstr
  34.   3 index () ne {
  35.         % Use G4 encoding to compress the bitmap.
  36.         % Define a string large enough to hold the metrics,
  37.         % an uncompressed bitmap (worst case = 5x expansion),
  38.         % and the 2 RTC codes (3 bytes).
  39.     dup length 4 index length 5 mul add 10 add string
  40.         % Stack: metrics bitmap cid font metstr buffer
  41.     dup 0 3 index putinterval
  42.     dup 2 index length 1 index length 1 index sub getinterval
  43.         % Stack: metrics bitmap cid font metstr buffer bitbuf
  44.     mark /Columns 8 index dup 4 get exch 2 get sub
  45.       /Rows 10 index dup 5 get exch 3 get sub
  46.       /K -1 /EndOfBlock true /BlackIs1 true
  47.     .dicttomark /CCITTFaxEncode filter
  48.         % Stack: metrics bitmap cid font metstr buffer filter
  49.     dup 6 index writestring closefile
  50.         % Find the end of the data by scanning backwards for the RTC.
  51.         % There are 2 RTCs x 12 bits = 3 bytes to remove.
  52.     {
  53.       dup dup length 1 sub get 0 ne { exit } if
  54.       0 1 index length 1 sub getinterval
  55.     } loop
  56.     0 1 index length 3 sub getinterval
  57.     exch pop    % metstr
  58.   } if
  59.   1 index /CharStrings get 3 index 3 -1 roll put
  60.   pop pop pop pop
  61. } obind
  62.  
  63. /removeall {        % <type32font> removeall -
  64.   0 65535 2 index removeglyphs pop
  65. } obind
  66.  
  67. /.removeglyphs systemdict /.removeglyphs get
  68. systemdict /.removeglyphs .undef
  69.  
  70. /removeglyphs {        % <cid_min> <cid_max> <type32font> .removeglyphs -
  71.   3 copy .removeglyphs
  72.   dup /CharStrings get dup {
  73.         % Stack: cidmin cidmax font CharStrings cid bitmap
  74.     pop dup 5 index ge { dup 4 index le { 2 copy undef } if } if pop
  75.   } forall pop pop pop pop
  76. } obind
  77.  
  78. .dicttomark /ProcSet defineresource pop
  79.  
  80. /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
  81. .cidfonttypes begin
  82.  
  83. 4    % CIDFontType 4 = FontType 32
  84. { dup /FontType 32 put
  85.   dup /CharStrings 20 dict put
  86.   1 index exch .buildfont32 exch pop
  87. } bind def
  88.  
  89. end        % .cidfonttypes
  90.  
  91. % Define the BuildGlyph procedure.
  92. % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
  93. % The name %Type32BuildGlyph is known to the interpreter.
  94. (%Type32BuildGlyph) cvn {    % <font> <cid> %Type32BuildGlyph -
  95.   1 index /CharStrings get
  96.         % Stack: font cid CharStrings
  97.   dup 2 index .knownget
  98.  { exch pop } { 0 get } ifelse
  99.         % Stack: font cid cstr
  100.   dup .getmetrics32
  101.   dup 14 gt {
  102.     8 index 8 index 13 3 roll setcachedevice2
  103.   } {
  104.     4 index 4 index 9 3 roll setcachedevice
  105.   } ifelse
  106.         % Stack: font cid cstr w h nmetrics llx lly
  107.   6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval
  108.         % Stack: font cid w h llx lly bitstr
  109.   dup () eq {
  110.     pop pop pop
  111.   } {
  112.     mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock false /BlackIs1 true
  113.     .dicttomark /CCITTFaxDecode filter 4 index 4 index true
  114.         % Stack: font cid w h llx lly filter w h true
  115.     [ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask
  116.   } ifelse
  117.   pop pop pop pop
  118. } bind def
  119.  
  120. systemdict /.getmetrics32 .undef
  121.  
  122. buildfontdict 32 /.buildfont32 cvx put
  123.  
  124. 32 dup /FontType defineresource pop
  125.  
  126. .setlanguagelevel
  127.