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.

186 lines
5.8 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. % Redefine CIDFont category with an emulation with True Type fonts.
  16. languagelevel 2 .setlanguagelevel
  17. 15 dict begin % a temporary dictionary for local binding.
  18. %------------------Copy the FontEmulationProcs here : -------------------
  19. /FontEmulationProcs /ProcSet findresource {
  20. def
  21. } forall
  22. currentdict /super.complete_instance currentdict /complete_instance get put
  23. %-------Auxiliary procedures for building CIDFontType 2 from TT file -----------
  24. /GenerateCIDMap % <font> GenerateCIDMap <font>
  25. { begin
  26. % Obtain the maximal CID :
  27. % This implementation doesn't check whether glyphs really present.
  28. Decoding /CIDCount get /CIDCount exch def
  29. % Prepare the CIDMap structure :
  30. /CIDMap [
  31. CIDCount 22000 le {
  32. CIDCount 2 mul string
  33. } {
  34. 44000 string
  35. CIDCount 44000 gt {
  36. % need three strings
  37. 44000 string % 22000 2 mul string
  38. CIDCount 44000 sub 2 mul string
  39. } {
  40. CIDCount 22000 sub 2 mul string
  41. } ifelse
  42. } ifelse
  43. ] def
  44. % Now fill it :
  45. Decoding TT_cmap SubstNWP GDBytes CIDMap .fillCIDMap
  46. currentdict end
  47. } .internalbind def
  48. /GenerateIdentityCIDMap % <font> GenerateCIDMap <font>
  49. { begin
  50. /CIDMap [ 44000 string 44000 string 44000 string] def
  51. CIDMap .fillIdentityCIDMap
  52. currentdict end
  53. } .internalbind def
  54. /load_sfnts % <FontDict> load_sfnts <FontDict>
  55. { % Read the True Type file from the path /Path, and buld /sfnts,
  56. % skipping glyf and loca.
  57. dup /Path get % <font> (path)
  58. QUIET not {
  59. (Loading a TT font from ) print dup print
  60. ( to emulate a CID font ) print 1 index /CIDFontName get =only ( ... ) print
  61. } if
  62. (r) file dup % <font> file file
  63. 3 1 roll % file <font> file
  64. 1 index /SubfontID .knownget not { 0 } if % file <font> file SubfontID
  65. 2 index /FileType .knownget
  66. {/WOFF eq}
  67. {//false} ifelse
  68. % It's not (currently) viable to load WOFF fonts "stripped", so we don't try
  69. {.load_woff_for_cid exch copy exch pop}
  70. {
  71. .load_tt_font_stripped exch
  72. copy % file <font>
  73. QUIET not {
  74. (Done.) =
  75. } if
  76. dup 3 1 roll % <font> file <font>
  77. exch /File exch put % <font>
  78. } ifelse
  79. dup dup /CIDSystemInfo get /Ordering get (.) % <font> () ()
  80. 2 index /Decoding get =string cvs % <font> () () ()
  81. concatstrings concatstrings cvn /Decoding exch put % <font>
  82. dup dup /CIDSystemInfo get /Ordering get (-WMode) % <font> <font> () ()
  83. concatstrings cvn /SubstCID
  84. 2 copy resourcestatus {
  85. pop pop
  86. findresource /subst_CID_on_WMode exch put % <font>
  87. } {
  88. pop pop pop
  89. } ifelse
  90. dup /Decoding get /Identity.Unicode eq {
  91. //ChooseDecoding exec % <font>
  92. //GenerateIdentityCIDMap exec % <font>
  93. } {
  94. //ChooseDecoding exec % <font>
  95. //GenerateCIDMap exec % <font>
  96. } ifelse
  97. } .internalbind def
  98. %-----------TrueType-specific methods for category redefinition : -----------
  99. /RefinePath % <FontDict> RefinePath <FontDict>
  100. { dup begin
  101. Path .libfile {
  102. dup .filename {
  103. currentdict exch /Path exch put
  104. } if
  105. closefile
  106. } {
  107. (r) { file } //.internalstopped exec
  108. {
  109. (Can't find the font file ) print =
  110. /findfont cvx /undefinedfilename signalerror
  111. }
  112. {
  113. dup .filename {
  114. currentdict exch /Path exch put
  115. } if
  116. closefile
  117. } ifelse
  118. } ifelse
  119. end
  120. } .internalbind def
  121. /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  122. { 1 index /CIDFontType 2 put % Other types are not emulated yet.
  123. //super.complete_instance exec
  124. //RefinePath exec
  125. //load_sfnts exec
  126. } .internalbind def
  127. /ValidFileTypes
  128. <<
  129. /TrueType 0
  130. /WOFF 0
  131. >> def
  132. /IsMyRecord % <raw_record> -> <raw_record> bool
  133. {
  134. dup type /dicttype eq { dup /FileType .knownget { //ValidFileTypes exch known } { //false } ifelse } { //false } ifelse
  135. } .internalbind def
  136. currentdict /ValidFileTypes undef
  137. /IsActive % <record> IsActive <bool>
  138. { pop //true
  139. } .internalbind def
  140. /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
  141. /GetCSI //TranslateCSI def
  142. /IsActive //IsActive def
  143. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  144. { currentglobal 3 1 roll //true setglobal
  145. //CIDFontOptions //complete_instance exec
  146. 2 copy //GetSize exec
  147. 4 3 roll setglobal
  148. } .internalbind def
  149. currentdict end def
  150. % Redefine the /CIDFont category :
  151. 4 dict begin
  152. /CategoryName /CIDFont def
  153. /IsMapFileOptional //true def
  154. /VerifyMap { pop } .internalbind def
  155. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  156. { //IsMyRecord exec dup {
  157. pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
  158. //true
  159. } if
  160. } .internalbind def
  161. currentdict end
  162. /MappedCategoryRedefiner /ProcSet findresource /Redefine get exec
  163. end % the temporary dictionary for local binding.
  164. .setlanguagelevel