1
0

gs_ciddc.ps 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. % Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000 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_ciddc.ps,v 1.14 2005/01/20 00:26:06 ray Exp $
  16. % Define Decoding and CIDDecoding resource categories and related procsets.
  17. languagelevel 2 .setlanguagelevel
  18. currentglobal true setglobal
  19. %----------------ParseDecoding procset----------------------------
  20. /ParseDecoding <<
  21. /Parse % <resource_name> <num_tokens> Parse -
  22. { dict begin % /ResName
  23. 0 % /ResName nCode
  24. { currentfile token not {
  25. exit
  26. } if % /ResName nCode token
  27. dup type /integertype eq { % /ResName nCode
  28. exch pop
  29. } {
  30. 1 index def % /ResName nCode
  31. } ifelse
  32. } loop % /ResName nCode
  33. pop % /ResName
  34. currentdict end /Decoding % /ResName <<inst>> /Decoding
  35. defineresource pop
  36. } bind
  37. >> /ProcSet defineresource pop
  38. %----------------Decoding category----------------------------
  39. /Generic /Category findresource dup length dict copy
  40. dup /InstanceType /dicttype put
  41. /Decoding exch /Category defineresource pop
  42. %----------------ParseCMap_Inverse procset----------------------------
  43. /ParseCMap_Inverse <<
  44. /findresource { pop } bind
  45. /defineresource { pop pop } bind
  46. /dict {}
  47. /def { pop pop } bind
  48. /dup null
  49. /begin { pop } bind
  50. /end {}
  51. /currentdict null
  52. /CMapName null
  53. /usecmap { pop } bind
  54. /begincmap {}
  55. /endcmap {}
  56. /begincodespacerange { pop mark } bind
  57. /endcodespacerange { cleartomark } bind
  58. /beginnotdefrange { pop mark } bind
  59. /endnotdefrange { cleartomark } bind
  60. /beginbfchar { pop mark } bind
  61. /endbfchar { pop mark } bind
  62. /beginbfrange { begincidrange }
  63. /endbfrange { endcidrange }
  64. /begincidchar { beginbfchar }
  65. /endcidchar { endbfchar }
  66. /begincidrange { pop mark } bind
  67. /endcidrange { cleartomark } bind
  68. >> % Just keep it on stack for a while.
  69. % Now we define another dict for local binding, than merge it with the previous one :
  70. dup length 5 add dict begin
  71. /.Ranges 40 dict def % Key = CID/256, value = array of 256 integer codes.
  72. //.Ranges /CIDCount 0 put
  73. /.StringToInt % <string> .StringToInt <integer>
  74. { 0 exch { exch 8 bitshift add } forall
  75. } bind def
  76. /.SetCouple % <I> <b> .SetCouple -
  77. { exch % b I
  78. dup 256 idiv % b I I0
  79. dup //.Ranges exch known not {
  80. dup //.Ranges exch 256 array put
  81. } if % b I I0
  82. //.Ranges exch get % b I [Range]
  83. exch 256 mod % b [Range] I1
  84. 3 2 roll put %
  85. } bind def
  86. /endcidrange
  87. { % Writes the inversed CMap to .Ranges
  88. counttomark 3 idiv { % (b) (e) I
  89. exch .StringToInt % (b) I e
  90. 3 2 roll .StringToInt % I e b
  91. % Note : this code does't handle multidimentional CID ranges.
  92. % fixme : optimize below.
  93. dup 3 2 roll exch sub 1 add % I b d
  94. { 2 copy //.SetCouple exec % I b
  95. 1 add exch 1 add exch
  96. } repeat % I b
  97. pop % I
  98. dup //.Ranges /CIDCount get gt { % I
  99. dup //.Ranges exch /CIDCount exch put
  100. } if % I
  101. pop
  102. } repeat
  103. pop % mark
  104. } bind def
  105. /.GetCIDDecoding % - .GetCIDDEcoding <dict>
  106. { //.Ranges dup length dict copy
  107. //.Ranges //.PurgeDict exec
  108. //.Ranges /CIDCount 0 put
  109. } bind def
  110. currentdict end
  111. exch copy % Merge the dicts - see above.
  112. /ProcSet defineresource pop
  113. %----------------CIDDecoding category----------------------------
  114. % Note that we put all instances in global memory - see FindResource.
  115. /Generic /Category findresource dup length dict copy
  116. begin
  117. /Category /CIDDecoding def
  118. /InstanceType /dicttype def
  119. /.CMapChooser <<
  120. % This lists CMaps to inverse and unite for creating a CIDDecoding.
  121. % Choose by FAPIcidfmap.Registry concatenated with TrueType encoding ID.
  122. % Font renderer must provide the glyph substitution internally.
  123. /CNS1.Big5 [ /ETen-B5-H /ETen-B5-V ]
  124. /CNS1.Unicode [ /UniCNS-UCS2-H /UniCNS-UCS2-V]
  125. /GB1.GB2312 [ /GBK-EUC-H /GBK-EUC-V ]
  126. /GB1.Unicode [ /UniGB-UCS2-H /UniGB-UCS2-V ]
  127. /Japan1.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
  128. /Japan1.Unicode [ /UniJIS-UCS2-H /UniJIS-UCS2-V]
  129. /Japan2.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
  130. /Japan2.Unicode [ /UniHojo-UCS2-H ]
  131. /Korea1.Johab [ /KSC-Johab-V /KSC-Johab-H ]
  132. /Korea1.Wansung [ /KSCms-UHC-V /KSCms-UHC-H ]
  133. /Korea1.Unicode [ /UniKS-UCS2-H /UniKS-UCS2-V ]
  134. /Identity.Symbol [ /Identity-H /Identity-V ]
  135. >> def
  136. /.MakeInstance % <name> .MakeInstance <inst>
  137. { dup % /Name /Name
  138. //.CMapChooser exch .knownget not {
  139. (Can't build /) print =string cvs print ( /CIDDecoding resource. See gs_ciddc.ps . ) =
  140. /findresource cvx /undefinedresource signalerror
  141. } if % /Name [CMaps]
  142. exch pop % [CMaps]
  143. /CMap /Category findresource % [CMaps] <CMapCategory>
  144. /ParseCMap_Inverse /ProcSet findresource % [CMaps] <CMapCategory> <PCI>
  145. 3 2 roll { % <CMapCategory> <PCI> /CMapName
  146. 3 2 roll begin % <PCI> /CMapName
  147. dup .ResourceFile not {
  148. (Can't find CMap ) print =string cvs print ( building a CIDDecoding resource. ) =
  149. /findresource cvx /undefinedresource signalerror
  150. } if
  151. currentdict end exch % <PCI> /CMapName <CMapCategory> file
  152. 3 index begin
  153. cvx exec % <PCI> /CMapName <CMapCategory>
  154. end
  155. exch pop exch % <CMapCategory> <PCI>
  156. } forall
  157. exch pop begin %
  158. .GetCIDDecoding
  159. end
  160. } bind def
  161. /FindResource % <name> FindResource <dict>
  162. { currentglobal exch % bGlobal /InstName
  163. true setglobal
  164. dup //.MakeInstance exec % bGlobal /InstName <Inst>
  165. DefineResource % bGlobal <Inst>
  166. exch setglobal % <Inst>
  167. } bind def
  168. currentdict end
  169. /CIDDecoding exch /Category defineresource pop
  170. setglobal
  171. .setlanguagelevel