gs_typ32.ps 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. % Copyright (C) 1997 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_typ32.ps,v 1.6 2002/06/02 12:03:28 mpsuzuki Exp $
  16. % Initialization file for Type 32 fonts.
  17. % ------ Type 32 fonts ------ %
  18. % We need LanguageLevel 2 or higher in order to have defineresource.
  19. languagelevel dup 2 .max .setlanguagelevel
  20. /BitmapFontInit mark
  21. /.makeglyph32 systemdict /.makeglyph32 get
  22. systemdict /.makeglyph32 .undef
  23. /addglyph { % ([wx wy llx lly urx ury] |
  24. % [w0x w0y llx lly urx ury w1x w1y vx vy])
  25. % <bitmap> <cid> <type32font> addglyph -
  26. 1 index dup 2 index .removeglyphs
  27. 22 string .makeglyph32
  28. % Stack: metrics bitmap cid font metstr
  29. 3 index () ne {
  30. % Use G4 encoding to compress the bitmap.
  31. % Define a string large enough to hold the metrics,
  32. % an uncompressed bitmap (worst case = 5x expansion),
  33. % and the 2 RTC codes (3 bytes).
  34. dup length 4 index length 5 mul add 10 add string
  35. % Stack: metrics bitmap cid font metstr buffer
  36. dup 0 3 index putinterval
  37. dup 2 index length 1 index length 1 index sub getinterval
  38. % Stack: metrics bitmap cid font metstr buffer bitbuf
  39. mark /Columns 8 index dup 4 get exch 2 get sub
  40. /Rows 10 index dup 5 get exch 3 get sub
  41. /K -1 /EndOfBlock true /BlackIs1 true
  42. .dicttomark /CCITTFaxEncode filter
  43. % Stack: metrics bitmap cid font metstr buffer filter
  44. dup 6 index writestring closefile
  45. % Find the end of the data by scanning backwards for the RTC.
  46. % There are 2 RTCs x 12 bits = 3 bytes to remove.
  47. {
  48. dup dup length 1 sub get 0 ne { exit } if
  49. 0 1 index length 1 sub getinterval
  50. } loop
  51. 0 1 index length 3 sub getinterval
  52. exch pop % metstr
  53. } if
  54. 1 index /CharStrings get 3 index 3 -1 roll put
  55. pop pop pop pop
  56. } obind
  57. /removeall { % <type32font> removeall -
  58. 0 65535 2 index removeglyphs pop
  59. } obind
  60. /.removeglyphs systemdict /.removeglyphs get
  61. systemdict /.removeglyphs .undef
  62. /removeglyphs { % <cid_min> <cid_max> <type32font> .removeglyphs -
  63. 3 copy .removeglyphs
  64. dup /CharStrings get dup {
  65. % Stack: cidmin cidmax font CharStrings cid bitmap
  66. pop dup 5 index ge { dup 4 index le { 2 copy undef } if } if pop
  67. } forall pop pop pop pop
  68. } obind
  69. .dicttomark /ProcSet defineresource pop
  70. /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
  71. .cidfonttypes begin
  72. 4 % CIDFontType 4 = FontType 32
  73. { dup /FontType 32 put
  74. dup /CharStrings 20 dict put
  75. 1 index exch .buildfont32 exch pop
  76. } bind def
  77. end % .cidfonttypes
  78. % Define the BuildGlyph procedure.
  79. % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
  80. % The name %Type32BuildGlyph is known to the interpreter.
  81. (%Type32BuildGlyph) cvn { % <font> <cid> %Type32BuildGlyph -
  82. 1 index /CharStrings get
  83. % Stack: font cid CharStrings
  84. dup 2 index .knownget
  85. { exch pop } { 0 get } ifelse
  86. % Stack: font cid cstr
  87. dup //.getmetrics32 % use // because of .undef below
  88. dup 14 gt {
  89. 8 index 8 index 13 3 roll setcachedevice2
  90. } {
  91. 4 index 4 index 9 3 roll setcachedevice
  92. } ifelse
  93. % Stack: font cid cstr w h nmetrics llx lly
  94. 6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval
  95. % Stack: font cid w h llx lly bitstr
  96. dup () eq {
  97. pop pop pop
  98. } {
  99. mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock false /BlackIs1 true
  100. .dicttomark /CCITTFaxDecode filter 4 index 4 index true
  101. % Stack: font cid w h llx lly filter w h true
  102. [ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask
  103. } ifelse
  104. pop pop pop pop
  105. } bind def
  106. systemdict /.getmetrics32 .undef
  107. buildfontdict 32 /.buildfont32 cvx put
  108. 32 dup /FontType defineresource pop
  109. .setlanguagelevel