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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. % Copyright (C) 2000 Artifex Software, Inc. 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_fapi.ps 8954 2008-08-08 04:22:38Z ray $
  16. % Redefine Font and CIDFont categories with FAPI-handeled fonts.
  17. systemdict /.FAPIavailable known { .FAPIavailable } { false } ifelse not {
  18. (%END FAPI) .skipeof
  19. } if
  20. languagelevel 2 .setlanguagelevel
  21. %====================================================================
  22. % Redefine Font category with FAPIfontmap and CIDFont with FAPIfontmap :
  23. 15 dict begin % a temporary dictionary for local binding.
  24. /EmbedFontObjectsQuery mark
  25. /.EmbedFontObjects 0
  26. .dicttomark def
  27. /is_device_compatible_to_FAPI % - is_device_compatible_to_FAPI <bool>
  28. { currentdevice //EmbedFontObjectsQuery .getdeviceparams % <mark> <name> <value> ...
  29. dup mark eq {
  30. pop true
  31. } {
  32. exch pop exch pop 0 eq
  33. } ifelse
  34. % The code above assumes that only the requested parameter is rendered.
  35. % The commented-out code below may be useful for general case.
  36. % Keeping it for a while.
  37. % counttomark 2 idiv {
  38. % exch /.EmbedFontObjects eq {
  39. % counttomark 1 add 1 roll cleartomark
  40. % 0 eq exit
  41. % } if
  42. % } repeat
  43. % dup mark eq {
  44. % pop true
  45. % } if
  46. } bind def
  47. %----------------------------- Process FAPIconfig -----------------------
  48. /Config
  49. <<
  50. systemdict /FAPIconfig known {/FAPIconfig .systemvar} {(FAPIconfig)} ifelse .runlibfile
  51. /ServerOptions 2 dict
  52. >> def
  53. systemdict /.FAPIconfig //Config put
  54. ()
  55. systemdict /UFST_SSdir .knownget {
  56. (UFST_SSdir=) exch concatstrings concatstrings
  57. } if
  58. systemdict /UFST_PlugIn .knownget {
  59. 1 index length 0 ne {
  60. exch .filenamelistseparator concatstrings exch
  61. } if
  62. (UFST_PlugIn=) exch concatstrings concatstrings
  63. } if
  64. dup length 0 ne {
  65. //Config /ServerOptions get exch /UFST exch put
  66. } {
  67. pop
  68. } ifelse
  69. %------------------Copy the FontEmulationProcs here : -------------------
  70. /FontEmulationProcs /ProcSet findresource {
  71. def
  72. } forall
  73. currentdict /super.complete_instance currentdict /complete_instance get put
  74. %-----------FAPI-specific methods for category redefinition : -----------
  75. /RefinePath % <FontDict> /key RefinePath <FontDict>
  76. { exch begin
  77. //Config exch get
  78. /Path exch
  79. Path false .file_name_combine not {
  80. exch
  81. (Can't combine paths ) print print ( and ) print =
  82. /RefinePath cvx /configurationerror signalerror
  83. } if
  84. def
  85. currentdict end
  86. } bind def
  87. /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  88. { //super.complete_instance exec
  89. dup /CIDFontName known { /CIDFontPath } { /FontPath } ifelse //RefinePath exec
  90. } bind def
  91. /IsMyRecord % <raw_record> -> <raw_record> bool
  92. { dup type /dicttype eq { dup /FAPI known } { false } ifelse
  93. } bind def
  94. /IsActive % <record> IsActive <bool>
  95. { pop //is_device_compatible_to_FAPI exec
  96. } bind def
  97. /FontRecordVirtualMethods //RecordVirtualMethodsStub dup length 2 add dict copy begin
  98. /IsActive //IsActive def
  99. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  100. { currentglobal 3 1 roll true setglobal
  101. //FontOptions //complete_instance exec
  102. 2 copy //GetSize exec
  103. 4 3 roll setglobal
  104. } bind def
  105. currentdict end def
  106. /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
  107. /GetCSI //TranslateCSI def
  108. /IsActive //IsActive def
  109. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  110. { currentglobal 3 1 roll true setglobal
  111. //CIDFontOptions //complete_instance exec
  112. 2 copy //GetSize exec
  113. 4 3 roll setglobal
  114. } bind def
  115. currentdict end def
  116. /ReadFCOfontmap: % <path> ReadFCOfontmap: name dict ...
  117. { /fontfile exch def
  118. {
  119. currentfile =string readline not {
  120. pop exit
  121. } if
  122. dup length 0 ne {
  123. 0 () /SubFileDecode filter
  124. dup token not {
  125. % A comment line
  126. closefile
  127. } {
  128. dup /EndFCOfontmap cvx eq {
  129. pop closefile exit
  130. } if
  131. exch dup token not {
  132. /ReadFCOfontmap: cvx /rangecheck signalerror
  133. } if
  134. exch dup token not {
  135. /StandardEncoding
  136. } {
  137. dup type /nametype ne {
  138. /ReadFCOfontmap: cvx /rangecheck signalerror
  139. } if
  140. } ifelse
  141. findencoding
  142. exch dup token not {
  143. null
  144. } {
  145. dup type /nametype ne {
  146. /ReadFCOfontmap: cvx /rangecheck signalerror
  147. } if
  148. /Decoding findresource
  149. } ifelse
  150. exch closefile % index name enc dec|null
  151. 4 3 roll % name enc dec|null index
  152. << /Path fontfile
  153. /FontType 1
  154. /FAPI /UFST
  155. /SubfontId counttomark 2 add -1 roll
  156. /Decoding counttomark 2 add -1 roll
  157. dup null eq {
  158. pop pop
  159. } if
  160. /Encoding counttomark 2 add -1 roll
  161. >> % dup { exch == = } forall
  162. } ifelse
  163. } {
  164. pop
  165. } ifelse
  166. } loop
  167. currentdict /fontfile undef
  168. } bind def
  169. %----------------------------------The Redefintion---------------------
  170. /MappedCategoryRedefiner /ProcSet findresource /Redefine get /Redefine exch def
  171. % Redefine the /Font category :
  172. 4 dict begin
  173. /CategoryName /Font def
  174. /MapFileName systemdict /FAPIfontmap known {/FAPIfontmap .systemvar} {(FAPIfontmap)} ifelse def
  175. /VerifyMap { pop } bind def
  176. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  177. { //IsMyRecord exec dup {
  178. pop dup /RecordVirtualMethods //FontRecordVirtualMethods put
  179. true
  180. } if
  181. } bind def
  182. currentdict end Redefine
  183. % Redefine the /CIDFont category :
  184. 4 dict begin
  185. /CategoryName /CIDFont def
  186. /MapFileName systemdict /FAPIcidfmap known {/FAPIcidfmap .systemvar} {(FAPIcidfmap)} ifelse def
  187. /VerifyMap { pop } bind def
  188. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  189. { //IsMyRecord exec dup {
  190. pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
  191. true
  192. } if
  193. } bind def
  194. currentdict end Redefine
  195. %==================== A hook for buildfont* operators ====================
  196. % The procedure .FAPIhook redirects PS fonts to FAPI on necessity.
  197. % This depends on the following conditions :
  198. %
  199. % 1. If font dictionary has /FAPI entry, it is a font listed in FAPIconfig.FontPath,
  200. % and must be build with .FAPIrebuildfont, or a copy of a font, which was
  201. % built with .FAPIrebuildfont .
  202. %
  203. % 2. If the font dictionary has /PathLoad entry, and has no /FAPI entry,
  204. % it is an installed PS font, which is described in lib/fontmap or
  205. % in GS_FONTPATH. .loadfont inserts /PathLoad entry for this case
  206. % (see gs_fonts.ps).
  207. %
  208. % Installed fonts are being loaded with GS font loader,
  209. % the they are passed to FAPI is same way as embedded fonts are.
  210. % We do so because UFST cannot read fonts, which don't
  211. % follow Type 1/42 file format strongly.
  212. %
  213. % 3. Executing .loadfont, we place /FAPI_hook_disable in the 0th
  214. % element of some procedure on the execution stack - see gs_fonts.ps .
  215. % If FAPI_hook finds /FAPI_hook_disable in there,
  216. % it knows that it is called for a disk font during
  217. % its internal definefont.
  218. %
  219. % 4. If font dictionary has no /FAPI entry, and has no /Path entry,
  220. % and if we are not in .loadfont context, it is an embedded font.
  221. %
  222. % 5. Two entries to be defined in lib/FAPIconfig to control the hooking of PS fonts :
  223. % HookDiskFonts and HookEmbeddedFonts .
  224. % They specify arrays of font types (integers) to be redirected with FAPI.
  225. % HookDiskFonts controls disk PS fonts (which fall into (2) and (3) ).
  226. % HookEmbeddedFonts controls fonts being embedded into documents.
  227. %
  228. % 7. We apply the operator .passtoFAPI for checking whether FAPI can handle a font.
  229. % If so, we insert /FAPI entry into the font dictionary and convert it
  230. % with .FAPIrebuildfont . Otherwise the font is handled with the native GS font renderer.
  231. /FAPI_hook_debug % <proc> FAPI_hook_debug -
  232. FAPIDEBUG { {exec} } { {pop} } ifelse
  233. bind def
  234. /FAPI_hook_warn % <proc> FAPI_hook_debug -
  235. QUIET { {pop} } { {exec} } ifelse
  236. bind def
  237. /FAPI_is_hook_disabled % - FAPI_is_hook_disabled <bool>
  238. { % checks whether execution stack contains packedarray started with /FAPI_hook_disable .
  239. /FAPI_hook_disable /MappedCategoryRedefiner /ProcSet findresource /execstack_lookup get exec
  240. null ne
  241. } bind def
  242. /FAPIhook_aux % <string|name> <font_dict> .FAPIhook <string|name> <font>
  243. { % name <<font>>
  244. { (FAPIhook ) print 1 index = } //FAPI_hook_debug exec
  245. dup /FAPI known {
  246. { //PrintFontRef exec ( is mapped to FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
  247. true //.FAPIrebuildfont //ChooseDecoding exec
  248. } {
  249. dup /PathLoad known dup {
  250. { (PathLoad known for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
  251. } {
  252. pop //FAPI_is_hook_disabled exec dup
  253. { pop
  254. { (FAPIhook is in .loadfont context for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
  255. true
  256. } if
  257. } ifelse
  258. { /HookDiskFonts } { /HookEmbeddedFonts } ifelse
  259. //Config exch get % name <<font>> [types]
  260. 1 index //GetFontType exec //FindInArray exec % name <<font>> bHook
  261. { { (Trying to render the font ) print //PrintFontRef exec ( with FAPI...) = } //FAPI_hook_debug exec
  262. //.FAPIpassfont {
  263. { //PrintFontRef exec ( is being rendered with FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
  264. false //.FAPIrebuildfont //ChooseDecoding exec
  265. } {
  266. { (Can't render ) print //PrintFontRef exec ( with FAPI, will do with native GS renderer.) = } //FAPI_hook_warn exec
  267. } ifelse
  268. } {
  269. { (The font ) print //PrintFontRef exec ( doesn't need to render with FAPI.) = } //FAPI_hook_debug exec
  270. } ifelse
  271. } ifelse
  272. } bind def
  273. /FAPIhook % <string|name> <font_dict> .FAPIhook <string|name> <font>
  274. { //is_device_compatible_to_FAPI exec
  275. { //FAPIhook_aux exec
  276. } {
  277. { (FAPIhook is disabled for the current device.) = } //FAPI_hook_debug exec
  278. } ifelse
  279. } bind def
  280. % ------------------ Redefine .buildfont* with FAPI : -----------------------
  281. /.buildfont1
  282. { //.buildfont1 exec //FAPIhook exec
  283. } bind % 'odef' is below.
  284. /.buildfont2
  285. { //.buildfont2 exec //FAPIhook exec
  286. } bind % 'odef' is below.
  287. /.buildfont42
  288. { //.buildfont42 exec //FAPIhook exec
  289. } bind % 'odef' is below.
  290. /.buildfont9
  291. { //.buildfont9 exec //FAPIhook exec
  292. } bind % 'odef' is below.
  293. /.buildfont10
  294. { //.buildfont10 exec //FAPIhook exec
  295. } bind % 'odef' is below.
  296. /.buildfont11
  297. { //.buildfont11 exec //FAPIhook exec
  298. } bind % 'odef' is below.
  299. end % the temporary dictionary for local binding.
  300. odef odef odef odef odef odef
  301. .setlanguagelevel
  302. %END FAPI