1
0

gs_fapi.ps 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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_fapi.ps,v 1.25 2003/04/12 18:08:18 ray Exp $
  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. %% Replace 1 (FAPIconfig)
  51. (FAPIconfig) .runlibfile
  52. >> def
  53. %------------------Copy the FontEmulationProcs here : -------------------
  54. /FontEmulationProcs /ProcSet findresource {
  55. def
  56. } forall
  57. currentdict /super.complete_instance currentdict /complete_instance get put
  58. %-----------FAPI-specific methods for category redefinition : -----------
  59. /RefinePath % <FontDict> /key RefinePath <FontDict>
  60. { exch begin
  61. //Config exch get
  62. /Path exch
  63. Path false .file_name_combine not {
  64. exch
  65. (Can't combine paths ) print print ( and ) print =
  66. /RefinePath /configurationerror signalerror
  67. } if
  68. def
  69. currentdict end
  70. } bind def
  71. /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  72. { //super.complete_instance exec
  73. dup /CIDFontName known { /CIDFontPath } { /FontPath } ifelse //RefinePath exec
  74. } bind def
  75. /IsMyRecord % <raw_record> -> <raw_record> bool
  76. { dup type /dicttype eq { dup /FAPI known } { false } ifelse
  77. } bind def
  78. /IsActive % <record> IsActive <bool>
  79. { pop //is_device_compatible_to_FAPI exec
  80. } bind def
  81. /FontRecordVirtualMethods //RecordVirtualMethodsStub dup length 2 add dict copy begin
  82. /IsActive //IsActive def
  83. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  84. { //FontOptions //complete_instance exec
  85. 2 copy //GetSize exec
  86. } bind def
  87. currentdict end def
  88. /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
  89. /GetCSI //TranslateCSI def
  90. /IsActive //IsActive def
  91. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  92. { //CIDFontOptions //complete_instance exec
  93. 2 copy //GetSize exec
  94. } bind def
  95. currentdict end def
  96. %----------------------------------The Redefintion---------------------
  97. /MappedCategoryRedefiner /ProcSet findresource /Redefine get /Redefine exch def
  98. % Redefine the /Font category :
  99. 4 dict begin
  100. /CategoryName /Font def
  101. /MapFileName (FAPIfontmap) def
  102. /VerifyMap { pop } bind def
  103. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  104. { //IsMyRecord exec dup {
  105. pop dup /RecordVirtualMethods //FontRecordVirtualMethods put
  106. true
  107. } if
  108. } bind def
  109. currentdict end Redefine
  110. % Redefine the /CIDFont category :
  111. 4 dict begin
  112. /CategoryName /CIDFont def
  113. /MapFileName (FAPIcidfmap) def
  114. /VerifyMap { pop } bind def
  115. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  116. { //IsMyRecord exec dup {
  117. pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
  118. true
  119. } if
  120. } bind def
  121. currentdict end Redefine
  122. %==================== A hook for buildfont* operators ====================
  123. % The procedure .FAPIhook redirects PS fonts to FAPI on necessity.
  124. % This depends on the following conditions :
  125. %
  126. % 1. If font dictionary has /FAPI entry, it is a font listed in FAPIconfig.FontPath,
  127. % and must be build with .FAPIrebuildfont, or a copy of a font, which was
  128. % built with .FAPIrebuildfont .
  129. %
  130. % 2. If the font dictionary has /PathLoad entry, and has no /FAPI entry,
  131. % it is an installed PS font, which is described in lib/fontmap or
  132. % in GS_FONTPATH. .loadfont inserts /PathLoad entry for this case
  133. % (see gs_fonts.ps).
  134. %
  135. % Installed fonts are being loaded with GS font loader,
  136. % the they are passed to FAPI is same way as embedded fonts are.
  137. % We do so because UFST cannot read fonts, which don't
  138. % follow Type 1/42 file format strongly.
  139. %
  140. % 3. Executing .loadfont, we place /FAPI_hook_disable in the 0th
  141. % element of some procedure on the execution stack - see gs_fonts.ps .
  142. % If FAPI_hook finds /FAPI_hook_disable in there,
  143. % it knows that it is called for a disk font during
  144. % its internal definefont.
  145. %
  146. % 4. If font dictionary has no /FAPI entry, and has no /Path entry,
  147. % and if we are not in .loadfont context, it is an embedded font.
  148. %
  149. % 5. Two entries to be defined in lib/FAPIconfig to control the hooking of PS fonts :
  150. % HookDiskFonts and HookEmbeddedFonts .
  151. % They specify arrays of font types (integers) to be redirected with FAPI.
  152. % HookDiskFonts controls disk PS fonts (which fall into (2) and (3) ).
  153. % HookEmbeddedFonts controls fonts being embedded into documents.
  154. %
  155. % 7. We apply the operator .passtoFAPI for checking whether FAPI can handle a font.
  156. % If so, we insert /FAPI entry into the font dictionary and convert it
  157. % with .FAPIrebuildfont . Otherwise the font is handled with the native GS font renderer.
  158. /FAPI_hook_debug % <proc> FAPI_hook_debug -
  159. FAPIDEBUG { {exec} } { {pop} } ifelse
  160. bind def
  161. /FAPI_hook_warn % <proc> FAPI_hook_debug -
  162. QUIET { {pop} } { {exec} } ifelse
  163. bind def
  164. /FAPI_is_hook_disabled % - FAPI_is_hook_disabled <bool>
  165. { % checks whether execution stack contains packedarray started with /FAPI_hook_disable .
  166. /FAPI_hook_disable /MappedCategoryRedefiner /ProcSet findresource /execstack_lookup get exec
  167. null ne
  168. } bind def
  169. /FAPIhook_aux % <string|name> <font_dict> .FAPIhook <string|name> <font>
  170. { % name <<font>>
  171. { (FAPIhook ) print 1 index = } //FAPI_hook_debug exec
  172. dup /FAPI known {
  173. { //PrintFontRef exec ( is mapped to FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
  174. true //.FAPIrebuildfont //ChooseDecoding exec
  175. } {
  176. dup /PathLoad known dup {
  177. { (PathLoad known for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
  178. } {
  179. pop //FAPI_is_hook_disabled exec dup
  180. { pop
  181. { (FAPIhook is in .loadfont context for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
  182. true
  183. } if
  184. } ifelse
  185. { /HookDiskFonts } { /HookEmbeddedFonts } ifelse
  186. //Config exch get % name <<font>> [types]
  187. 1 index //GetFontType exec //FindInArray exec % name <<font>> bHook
  188. { { (Trying to render the font ) print //PrintFontRef exec ( with FAPI...) = } //FAPI_hook_debug exec
  189. //.FAPIpassfont {
  190. { //PrintFontRef exec ( is being rendered with FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
  191. false //.FAPIrebuildfont //ChooseDecoding exec
  192. } {
  193. { (Can't render ) print //PrintFontRef exec ( with FAPI, will do with native GS renderer.) = } //FAPI_hook_warn exec
  194. } ifelse
  195. } {
  196. { (The font ) print //PrintFontRef exec ( doesn't need to render with FAPI.) = } //FAPI_hook_debug exec
  197. } ifelse
  198. } ifelse
  199. } bind def
  200. /FAPIhook % <string|name> <font_dict> .FAPIhook <string|name> <font>
  201. { //is_device_compatible_to_FAPI exec
  202. { //FAPIhook_aux exec
  203. } {
  204. { (FAPIhook is disabled for the current device.) = } //FAPI_hook_debug exec
  205. } ifelse
  206. } bind def
  207. % ------------------ Redefine .buildfont* with FAPI : -----------------------
  208. /.buildfont1
  209. { //.buildfont1 exec //FAPIhook exec
  210. } bind % 'odef' is below.
  211. /.buildfont2
  212. { //.buildfont2 exec //FAPIhook exec
  213. } bind % 'odef' is below.
  214. /.buildfont42
  215. { //.buildfont42 exec //FAPIhook exec
  216. } bind % 'odef' is below.
  217. /.buildfont9
  218. { //.buildfont9 exec //FAPIhook exec
  219. } bind % 'odef' is below.
  220. /.buildfont10
  221. { //.buildfont10 exec //FAPIhook exec
  222. } bind % 'odef' is below.
  223. /.buildfont11
  224. { //.buildfont11 exec //FAPIhook exec
  225. } bind % 'odef' is below.
  226. end % the temporary dictionary for local binding.
  227. odef odef odef odef odef odef
  228. .setlanguagelevel
  229. %END FAPI