星火微课系统客户端
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.

gs_ciddc.ps 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 9834 2009-07-03 09:27:02Z ken $
  16. % Define SubstCID, 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. 2 copy get % b [Range] I1 e
  85. dup //null ne {
  86. % We've got char code duplicates for same CID.
  87. dup type /integertype eq {
  88. 4 3 roll % [Range] I1 e b
  89. 2 array astore put %
  90. } {
  91. dup length 1 add dup dup array dup % b [Range] I1 D l l D' D'
  92. 3 2 roll 0 exch getinterval % b [Range] I1 D l D' D''
  93. 4 3 roll exch copy pop % b [Range] I1 l D'
  94. dup 3 2 roll 1 sub % b [Range] I1 D' D' l-1
  95. 6 5 roll % [Range] I1 D' D' l-1 b
  96. put put %
  97. } ifelse
  98. } {
  99. pop 3 2 roll put %
  100. } ifelse
  101. } bind def
  102. /endcidrange
  103. { % Writes the inversed CMap to .Ranges
  104. counttomark 3 idiv { % (b) (e) I
  105. exch .StringToInt % (b) I e
  106. 3 2 roll .StringToInt % I e b
  107. % Note : this code does't handle multidimentional CID ranges.
  108. % fixme : optimize below.
  109. dup 3 2 roll exch sub 1 add % I b d
  110. { 2 copy //.SetCouple exec % I b
  111. 1 add exch 1 add exch
  112. } repeat % I b
  113. pop % I
  114. dup //.Ranges /CIDCount get gt { % I
  115. dup //.Ranges exch /CIDCount exch put
  116. } if % I
  117. pop
  118. } repeat
  119. pop % mark
  120. } bind def
  121. /.GetCIDDecoding % - .GetCIDDEcoding <dict>
  122. { //.Ranges dup length dict copy
  123. //.Ranges //.PurgeDict exec
  124. //.Ranges /CIDCount 0 put
  125. } bind def
  126. currentdict end
  127. exch copy % Merge the dicts - see above.
  128. /ProcSet defineresource pop
  129. %----------------CIDDecoding category----------------------------
  130. % Note that we put all instances in global memory - see FindResource.
  131. /Generic /Category findresource dup length dict copy
  132. begin
  133. /Category /CIDDecoding def
  134. /InstanceType /dicttype def
  135. /.CMapChooser <<
  136. % This lists CMaps to inverse and unite for creating a CIDDecoding.
  137. % Choose by FAPIcidfmap.Registry concatenated with TrueType encoding ID.
  138. % Font renderer must provide the glyph substitution internally.
  139. /CNS1.Big5 [ /ETen-B5-H /ETen-B5-V ]
  140. /CNS1.Unicode [ /UniCNS-UCS2-H /UniCNS-UCS2-V]
  141. /GB1.GB2312 [ /GBK-EUC-H /GBK-EUC-V ]
  142. /GB1.Unicode [ /UniGB-UCS2-H /UniGB-UCS2-V ]
  143. /Japan1.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
  144. /Japan1.Unicode [ /UniJIS-UCS2-H /UniJIS-UCS2-V]
  145. /Japan2.ShiftJIS [ /90ms-RKSJ-H /90ms-RKSJ-V ]
  146. /Japan2.Unicode [ /UniHojo-UCS2-H ]
  147. /Korea1.Johab [ /KSC-Johab-V /KSC-Johab-H ]
  148. /Korea1.Wansung [ /KSCms-UHC-V /KSCms-UHC-H ]
  149. /Korea1.Unicode [ /UniKS-UCS2-H /UniKS-UCS2-V ]
  150. /Identity.Symbol [ /Identity-H /Identity-V ]
  151. /Unicode.Unicode [ /Identity-UTF16-H ]
  152. /Identity.Unicode [ /Identity-UTF16-H ]
  153. >> def
  154. /.MakeInstance % <name> .MakeInstance <inst>
  155. { dup % /Name /Name
  156. //.CMapChooser exch .knownget not {
  157. (Can't build /) print =string cvs print ( /CIDDecoding resource. See gs_ciddc.ps . ) =
  158. /findresource cvx /undefinedresource signalerror
  159. } if % /Name [CMaps]
  160. exch pop % [CMaps]
  161. /CMap /Category findresource % [CMaps] <CMapCategory>
  162. /ParseCMap_Inverse /ProcSet findresource % [CMaps] <CMapCategory> <PCI>
  163. 3 2 roll { % <CMapCategory> <PCI> /CMapName
  164. 3 2 roll begin % <PCI> /CMapName
  165. dup .ResourceFile not {
  166. (Can't find CMap ) print =string cvs print ( building a CIDDecoding resource. ) =
  167. /findresource cvx /undefinedresource signalerror
  168. } if
  169. currentdict end exch % <PCI> /CMapName <CMapCategory> file
  170. 3 index begin
  171. cvx exec % <PCI> /CMapName <CMapCategory>
  172. end
  173. exch pop exch % <CMapCategory> <PCI>
  174. } forall
  175. exch pop begin %
  176. .GetCIDDecoding
  177. end
  178. } bind def
  179. /FindResource % <name> FindResource <dict>
  180. { currentglobal exch % bGlobal /InstName
  181. true setglobal
  182. dup //.MakeInstance exec % bGlobal /InstName <Inst>
  183. DefineResource % bGlobal <Inst>
  184. exch setglobal % <Inst>
  185. } bind def
  186. currentdict end
  187. /CIDDecoding exch /Category defineresource pop
  188. %----------------SubstCID category----------------------------
  189. /Generic /Category findresource dup length dict copy
  190. begin
  191. /Category /SubstCID def
  192. /InstanceType /dicttype def
  193. currentdict end
  194. /SubstCID exch /Category defineresource pop
  195. setglobal
  196. .setlanguagelevel