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.

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