gs_typ32.ps 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. % Copyright (C) 1997 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_typ32.ps,v 1.3 2001/08/06 10:19:42 igorm Exp $
  18. % Initialization file for Type 32 fonts.
  19. % ------ Type 32 fonts ------ %
  20. % We need LanguageLevel 2 or higher in order to have defineresource.
  21. languagelevel dup 2 max .setlanguagelevel
  22. /BitmapFontInit mark
  23. /.makeglyph32 systemdict /.makeglyph32 get
  24. systemdict /.makeglyph32 .undef
  25. /addglyph { % ([wx wy llx lly urx ury] |
  26. % [w0x w0y llx lly urx ury w1x w1y vx vy])
  27. % <bitmap> <cid> <type32font> addglyph -
  28. 1 index dup 2 index .removeglyphs
  29. 22 string .makeglyph32
  30. % Stack: metrics bitmap cid font metstr
  31. 3 index () ne {
  32. % Use G4 encoding to compress the bitmap.
  33. % Define a string large enough to hold the metrics,
  34. % an uncompressed bitmap (worst case = 5x expansion),
  35. % and the 2 RTC codes (3 bytes).
  36. dup length 4 index length 5 mul add 10 add string
  37. % Stack: metrics bitmap cid font metstr buffer
  38. dup 0 3 index putinterval
  39. dup 2 index length 1 index length 1 index sub getinterval
  40. % Stack: metrics bitmap cid font metstr buffer bitbuf
  41. mark /Columns 8 index dup 4 get exch 2 get sub
  42. /Rows 10 index dup 5 get exch 3 get sub
  43. /K -1 /EndOfBlock true /BlackIs1 true
  44. .dicttomark /CCITTFaxEncode filter
  45. % Stack: metrics bitmap cid font metstr buffer filter
  46. dup 6 index writestring closefile
  47. % Find the end of the data by scanning backwards for the RTC.
  48. % There are 2 RTCs x 12 bits = 3 bytes to remove.
  49. {
  50. dup dup length 1 sub get 0 ne { exit } if
  51. 0 1 index length 1 sub getinterval
  52. } loop
  53. 0 1 index length 3 sub getinterval
  54. exch pop % metstr
  55. } if
  56. 1 index /CharStrings get 3 index 3 -1 roll put
  57. pop pop pop pop
  58. } obind
  59. /removeall { % <type32font> removeall -
  60. 0 65535 2 index removeglyphs pop
  61. } obind
  62. /.removeglyphs systemdict /.removeglyphs get
  63. systemdict /.removeglyphs .undef
  64. /removeglyphs { % <cid_min> <cid_max> <type32font> .removeglyphs -
  65. 3 copy .removeglyphs
  66. dup /CharStrings get dup {
  67. % Stack: cidmin cidmax font CharStrings cid bitmap
  68. pop dup 5 index ge { dup 4 index le { 2 copy undef } if } if pop
  69. } forall pop pop pop pop
  70. } obind
  71. .dicttomark /ProcSet defineresource pop
  72. /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
  73. .cidfonttypes begin
  74. 4 % CIDFontType 4 = FontType 32
  75. { dup /FontType 32 put
  76. dup /CharStrings 20 dict put
  77. 1 index exch .buildfont32 exch pop
  78. } bind def
  79. end % .cidfonttypes
  80. % Define the BuildGlyph procedure.
  81. % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
  82. % The name %Type32BuildGlyph is known to the interpreter.
  83. (%Type32BuildGlyph) cvn { % <font> <cid> %Type32BuildGlyph -
  84. 1 index /CharStrings get
  85. % Stack: font cid CharStrings
  86. dup 2 index .knownget
  87. { exch pop } { 0 get } ifelse
  88. % Stack: font cid cstr
  89. dup //.getmetrics32 % use // because of .undef below
  90. dup 14 gt {
  91. 8 index 8 index 13 3 roll setcachedevice2
  92. } {
  93. 4 index 4 index 9 3 roll setcachedevice
  94. } ifelse
  95. % Stack: font cid cstr w h nmetrics llx lly
  96. 6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval
  97. % Stack: font cid w h llx lly bitstr
  98. dup () eq {
  99. pop pop pop
  100. } {
  101. mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock false /BlackIs1 true
  102. .dicttomark /CCITTFaxDecode filter 4 index 4 index true
  103. % Stack: font cid w h llx lly filter w h true
  104. [ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask
  105. } ifelse
  106. pop pop pop pop
  107. } bind def
  108. systemdict /.getmetrics32 .undef
  109. buildfontdict 32 /.buildfont32 cvx put
  110. 32 dup /FontType defineresource pop
  111. .setlanguagelevel