You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.5 KiB

1 month ago
  1. % Copyright (C) 2001-2023 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % Initialization file for Type 32 fonts.
  16. % ------ Type 32 fonts ------ %
  17. % We need LanguageLevel 2 or higher in order to have defineresource.
  18. languagelevel dup 2 .max .setlanguagelevel
  19. /BitmapFontInit mark
  20. /.makeglyph32 systemdict /.makeglyph32 get
  21. systemdict /.makeglyph32 .undef
  22. /addglyph { % ([wx wy llx lly urx ury] |
  23. % [w0x w0y llx lly urx ury w1x w1y vx vy])
  24. % <bitmap> <cid> <type32font> addglyph -
  25. 1 index dup 2 index .removeglyphs
  26. 22 string .makeglyph32
  27. % Stack: metrics bitmap cid font metstr
  28. 3 index () ne {
  29. % Use G4 encoding to compress the bitmap.
  30. % Define a string large enough to hold the metrics,
  31. % an uncompressed bitmap (worst case = 5x expansion),
  32. % and the 2 RTC codes (3 bytes).
  33. dup length 4 index length 5 mul add 10 add
  34. 65535 .min 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. } executeonly obind
  57. /removeall { % <type32font> removeall -
  58. 0 65535 2 index removeglyphs pop
  59. } executeonly 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. } executeonly obind
  69. .dicttomark /ProcSet defineresource pop
  70. /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
  71. /CIDFontType4
  72. {
  73. dup /FontType 32 .forceput
  74. dup /CharStrings 20 dict .forceput
  75. 1 index exch .buildfont32 exch pop
  76. } .forcebind odef
  77. .cidfonttypes begin
  78. 4 /CIDFontType4 load def % CIDFontType 4 = FontType 32
  79. end % .cidfonttypes
  80. currentdict /CIDFontType4 .forceundef
  81. % Define the BuildGlyph procedure.
  82. % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
  83. % The name %Type32BuildGlyph is known to the interpreter.
  84. (%Type32BuildGlyph) cvn { % <font> <cid> %Type32BuildGlyph -
  85. 1 index /CharStrings get
  86. % Stack: font cid CharStrings
  87. dup 2 index .knownget {
  88. exch pop
  89. } {
  90. 0 .knownget not {
  91. exch pop % Stack: cid
  92. .getshowoperator /invalidfont signalerror
  93. } if
  94. } ifelse
  95. % Stack: font cid cstr
  96. dup //.getmetrics32 % use // because of .undef below
  97. dup 14 gt {
  98. 8 index 8 index 13 3 roll setcachedevice2
  99. } {
  100. 4 index 4 index 9 3 roll setcachedevice
  101. } ifelse
  102. % Stack: font cid cstr w h nmetrics llx lly
  103. 6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval
  104. % Stack: font cid w h llx lly bitstr
  105. dup () eq {
  106. pop pop pop
  107. } {
  108. mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock //false /BlackIs1 //true
  109. .dicttomark /CCITTFaxDecode filter 4 index 4 index //true
  110. % Stack: font cid w h llx lly filter w h //true
  111. [ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask
  112. } ifelse
  113. pop pop pop pop
  114. } .forcebind def
  115. systemdict /.getmetrics32 .undef
  116. buildfontdict 32 /.buildfont32 cvx put
  117. 32 dup /FontType defineresource pop
  118. .setlanguagelevel