1
0

gs_cidtt.ps 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. % Copyright (C) 2000 artofcode LLC. 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_cidtt.ps,v 1.9 2005/04/29 16:58:04 ray Exp $
  16. % Redefine CIDFont category with an emulation with True Type fonts.
  17. languagelevel 2 .setlanguagelevel
  18. 15 dict begin % a temporary dictionary for local binding.
  19. %------------------Copy the FontEmulationProcs here : -------------------
  20. /FontEmulationProcs /ProcSet findresource {
  21. def
  22. } forall
  23. currentdict /super.complete_instance currentdict /complete_instance get put
  24. %-------Auxiliary procedures for building CIDFontType 2 from TT file -----------
  25. /GenerateCIDMap % <font> GenerateCIDMap <font>
  26. { begin
  27. % Obtain the maximal CID :
  28. % This implementation doesn't check whether glyphs really present.
  29. Decoding /CIDCount get /CIDCount exch def
  30. % Prepare the CIDMap structure :
  31. /CIDMap [
  32. CIDCount 22000 le {
  33. CIDCount 2 mul string
  34. } {
  35. 44000 string
  36. CIDCount 44000 gt {
  37. % need three strings
  38. 44000 string % 22000 2 mul string
  39. CIDCount 44000 sub 2 mul string
  40. } {
  41. CIDCount 22000 sub 2 mul string
  42. } ifelse
  43. } ifelse
  44. ] def
  45. % Now fill it :
  46. Decoding TT_cmap SubstNWP GDBytes CIDMap .fillCIDMap
  47. currentdict end
  48. } bind def
  49. /load_sfnts % <FontDict> load_sfnts <FontDict>
  50. { % Read the True Type file from the path /Path, and buld /sfnts,
  51. % skipping glyf and loca.
  52. dup /Path get % <font> (path)
  53. QUIET not {
  54. (Loading a TT font from ) print dup print
  55. ( to emulate a CID font ) print 1 index /CIDFontName get =only ( ... ) print
  56. } if
  57. (r) file dup % <font> file file
  58. 3 1 roll % file <font> file
  59. 1 index /SubfontID .knownget not { 0 } if % file <font> file SubfontID
  60. .load_tt_font_stripped exch copy % file <font>
  61. QUIET not {
  62. (Done.) =
  63. } if
  64. dup 3 1 roll % <font> file <font>
  65. exch /File exch put % <font>
  66. dup dup /CIDSystemInfo get /Ordering get (.) % <font> () ()
  67. 2 index /Decoding get =string cvs % <font> () () ()
  68. concatstrings concatstrings cvn /Decoding exch put % <font>
  69. //ChooseDecoding exec % <font>
  70. //GenerateCIDMap exec % <font>
  71. } bind def
  72. %-----------TrueType-specific methods for category redefinition : -----------
  73. /RefinePath % <FontDict> RefinePath <FontDict>
  74. { dup begin
  75. Path .libfile {
  76. dup .filename {
  77. currentdict exch /Path exch put
  78. } if
  79. closefile
  80. } {
  81. (Can't find the font file ) print =
  82. /findfont cvx /undefinedfilename signalerror
  83. } ifelse
  84. end
  85. } bind def
  86. /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  87. { 1 index /CIDFontType 2 put % Other types are not emulated yet.
  88. //super.complete_instance exec
  89. //RefinePath exec
  90. //load_sfnts exec
  91. } bind def
  92. /IsMyRecord % <raw_record> -> <raw_record> bool
  93. { dup type /dicttype eq { dup /FileType .knownget { /TrueType eq } { false } ifelse } { false } ifelse
  94. } bind def
  95. /IsActive % <record> IsActive <bool>
  96. { pop true
  97. } bind def
  98. /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
  99. /GetCSI //TranslateCSI def
  100. /IsActive //IsActive def
  101. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  102. { //CIDFontOptions //complete_instance exec
  103. 2 copy //GetSize exec
  104. } bind def
  105. currentdict end def
  106. % Redefine the /CIDFont category :
  107. 4 dict begin
  108. /CategoryName /CIDFont def
  109. /IsMapFileOptional true def
  110. /VerifyMap { pop } bind def
  111. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  112. { //IsMyRecord exec dup {
  113. pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
  114. true
  115. } if
  116. } bind def
  117. currentdict end
  118. /MappedCategoryRedefiner /ProcSet findresource /Redefine get exec
  119. end % the temporary dictionary for local binding.
  120. .setlanguagelevel