gs_cidfm.ps 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_cidfm.ps,v 1.7 2004/10/25 15:11:37 igor Exp $
  16. % Redefine CIDFont category with cidfmap .
  17. languagelevel 2 .setlanguagelevel
  18. 4 dict begin
  19. /CategoryName /CIDFont def
  20. /MapFileName (cidfmap) def
  21. /IsMyRecord % <raw_record> -> <raw_record> bool
  22. { % Only for client's needs.
  23. dup type /nametype eq
  24. } bind def
  25. /RecordVirtualMethods 3 dict begin
  26. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  27. { % We know that currentdict is the category.
  28. /Substitute get FindResource % /Name <<CIDFont>>
  29. dup length dict copy % /Name <<CIDFont>>
  30. 1 index ResourceStatus pop exch pop % /Name <<CIDFont>> size
  31. } bind def
  32. /GetFilePath % <scratch> <Name> <record> GetFilePath <filepath>
  33. { % We know that currentdict is the category.
  34. exch pop
  35. /Substitute get exch ResourceFileName
  36. } bind def
  37. /GetSize % <Name> <record> GetSize <size>
  38. { % We know that currentdict is the category.
  39. /Substitute get ResourceStatus {
  40. exch pop exch pop
  41. } {
  42. /undefinedresource signalerror
  43. } ifelse
  44. } bind def
  45. /GetCSI % <record> GetCSI null
  46. % <record> GetCSI dict
  47. { % We know that currentdict is the category.
  48. RESMPDEBUG { (cidfm GetCSI beg ) = } if
  49. /Substitute get % /Name
  50. GetCIDSystemInfoFromMap
  51. RESMPDEBUG { (cidfm GetCSI end ) print dup = } if
  52. } bind def
  53. /IsActive % <record> IsActive <bool>
  54. { pop true
  55. } bind def
  56. currentdict end def
  57. /VerifyMap % <raw_map> VerifyMap -
  58. { % Checks for vicious substitution cycles.
  59. dup length dict copy % <<map>>
  60. dup length dict % <<map>> <<temp>>
  61. { % Choose a random record :
  62. true 2 index { % <<map>> <<temp>> true /Name /Subs
  63. 3 2 roll pop false exit % <<map>> <<temp>> /Name /Subs false
  64. } forall
  65. { exit % <<map>> <<temp>>
  66. } if % <<map>> <<temp>> /Name /Subs
  67. % Move the substitution chain to <<temp>>, checking for a cycle :
  68. 3 index 2 index undef % <<map>> <<temp>> /Name /Subs
  69. exch 2 index exch 0 put % <<map>> <<temp>> /Subs
  70. { //IsMyRecord exec not {
  71. % Not a substitution, the chain terminates.
  72. pop exit % <<map>> <<temp>>
  73. } if % <<map>> <<temp>> /Subs
  74. 1 index 1 index known {
  75. (Vicious substitution cycle in map file with the entry ) print =string cvs print ( .) =
  76. /VerifyMap cvx /undefinedresource signalerror
  77. } if % <<map>> <<temp>> /Subs
  78. 1 index 1 index 0 put
  79. dup 3 index exch .knownget not { % <<map>> <<temp>> /Subs
  80. % No more substitutions, the chain terminates.
  81. pop exit % <<map>> <<temp>>
  82. } if % <<map>> <<temp>> /Subs /Subs1
  83. exch % <<map>> <<temp>> /Subs1 /Subs
  84. 3 index exch undef % <<map>> <<temp>> /Subs1
  85. } loop
  86. % Not cycled, now purge the <<temp>> :
  87. { % Choose a random record :
  88. true 1 index { % <<map>> <<temp>> true /Name /Subs
  89. 3 2 roll pop false exit % <<map>> <<temp>> /Name /Subs false
  90. } forall
  91. { exit % <<map>> <<temp>>
  92. } if % <<map>> <<temp>> /Name /Subs
  93. % Remove it :
  94. pop 1 index exch undef % <<map>> <<temp>>
  95. } loop
  96. } loop
  97. pop pop %
  98. } bind def
  99. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  100. { //IsMyRecord exec {
  101. 1 dict begin
  102. /Substitute exch def
  103. /RecordVirtualMethods //RecordVirtualMethods def
  104. currentdict end
  105. true
  106. } {
  107. false
  108. } ifelse
  109. } bind def
  110. currentdict end
  111. /MappedCategoryRedefiner /ProcSet findresource /Redefine get exec
  112. .setlanguagelevel