home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_fapi.ps < prev    next >
Text File  |  2003-04-13  |  10KB  |  269 lines

  1. %    Copyright (C) 2000 artofcode LLC.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_fapi.ps,v 1.25 2003/04/12 18:08:18 ray Exp $
  14. % Redefine Font and CIDFont categories with FAPI-handeled fonts.
  15.  
  16. systemdict /.FAPIavailable known { .FAPIavailable } { false } ifelse not {
  17.   (%END FAPI) .skipeof
  18. } if
  19.  
  20. languagelevel 2 .setlanguagelevel
  21.  
  22. %====================================================================
  23. % Redefine Font category with FAPIfontmap and CIDFont with FAPIfontmap :
  24. 15 dict begin    % a temporary dictionary for local binding.
  25.  
  26. /EmbedFontObjectsQuery mark
  27.   /.EmbedFontObjects 0
  28. .dicttomark def
  29.  
  30. /is_device_compatible_to_FAPI    % - is_device_compatible_to_FAPI <bool>
  31. { currentdevice //EmbedFontObjectsQuery .getdeviceparams               % <mark> <name> <value> ...
  32.   dup mark eq {
  33.     pop true
  34.   } {
  35.     exch pop exch pop 0 eq
  36.   } ifelse
  37.   % The code above assumes that only the requested parameter is rendered.
  38.   % The commented-out code below may be useful for general case.
  39.   % Keeping it for a while.
  40.   % counttomark 2 idiv {
  41.   %   exch /.EmbedFontObjects eq {
  42.   %     counttomark 1 add 1 roll cleartomark
  43.   %     0 eq exit
  44.   %   } if
  45.   % } repeat
  46.   % dup mark eq {
  47.   %   pop true
  48.   % } if
  49. } bind def
  50.  
  51. %----------------------------- Process FAPIconfig -----------------------
  52.  
  53. /Config
  54. <<
  55. %% Replace 1 (FAPIconfig)
  56.   (FAPIconfig) .runlibfile
  57. >> def
  58.  
  59. %------------------Copy the FontEmulationProcs here : -------------------
  60.  
  61. /FontEmulationProcs /ProcSet findresource {
  62.   def
  63. } forall
  64.  
  65. currentdict /super.complete_instance currentdict /complete_instance get put
  66.  
  67. %-----------FAPI-specific methods for category redefinition : -----------
  68.  
  69. /RefinePath      % <FontDict> /key RefinePath <FontDict>
  70. { exch begin
  71.   //Config exch get
  72.   /Path exch
  73.   Path false .file_name_combine not {
  74.     exch
  75.     (Can't combine paths ) print print ( and ) print =
  76.     /RefinePath /configurationerror signalerror
  77.   } if
  78.   def
  79.   currentdict end
  80. } bind def
  81.  
  82. /complete_instance  % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  83. { //super.complete_instance exec
  84.   dup /CIDFontName known { /CIDFontPath } { /FontPath } ifelse //RefinePath exec
  85. } bind def
  86.  
  87. /IsMyRecord      % <raw_record> -> <raw_record> bool
  88. { dup type /dicttype eq { dup /FAPI known } { false } ifelse
  89. } bind def
  90.  
  91. /IsActive       % <record> IsActive <bool>
  92. { pop //is_device_compatible_to_FAPI exec
  93. } bind def
  94.  
  95. /FontRecordVirtualMethods //RecordVirtualMethodsStub dup length 2 add dict copy begin
  96.   /IsActive //IsActive def
  97.   /MakeInstance   % <Name> <record> MakeInstance <Name> <Instance> <size>
  98.   { //FontOptions //complete_instance exec
  99.     2 copy //GetSize exec
  100.   } bind def
  101. currentdict end def
  102.  
  103. /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
  104.   /GetCSI //TranslateCSI def
  105.   /IsActive //IsActive def
  106.   /MakeInstance   % <Name> <record> MakeInstance <Name> <Instance> <size>
  107.   { //CIDFontOptions //complete_instance exec
  108.     2 copy //GetSize exec
  109.   } bind def
  110. currentdict end def
  111.  
  112. %----------------------------------The Redefintion---------------------
  113.  
  114. /MappedCategoryRedefiner /ProcSet findresource /Redefine get /Redefine exch def
  115.  
  116. % Redefine the /Font category :
  117. 4 dict begin
  118.   /CategoryName /Font def
  119.   /MapFileName (FAPIfontmap) def
  120.   /VerifyMap  { pop } bind def
  121.   /PreprocessRecord  % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  122.   { //IsMyRecord exec dup {
  123.       pop dup /RecordVirtualMethods //FontRecordVirtualMethods put
  124.       true
  125.     } if
  126.   } bind def
  127. currentdict end Redefine
  128.  
  129. % Redefine the /CIDFont category :
  130. 4 dict begin
  131.   /CategoryName /CIDFont def
  132.   /MapFileName (FAPIcidfmap) def
  133.   /VerifyMap  { pop } bind def
  134.   /PreprocessRecord  % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  135.   { //IsMyRecord exec dup {
  136.       pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
  137.       true
  138.     } if
  139.   } bind def
  140. currentdict end Redefine
  141.  
  142. %==================== A hook for buildfont* operators ====================
  143.  
  144. % The procedure .FAPIhook redirects PS fonts to FAPI on necessity.
  145. % This depends on the following conditions :
  146. %
  147. % 1. If font dictionary has /FAPI entry, it is a font listed in FAPIconfig.FontPath,
  148. %    and must be build with .FAPIrebuildfont, or a copy of a font, which was
  149. %    built with .FAPIrebuildfont .
  150. %
  151. % 2. If the font dictionary has /PathLoad entry, and has no /FAPI entry,
  152. %    it is an installed PS font, which is described in lib/fontmap or
  153. %    in GS_FONTPATH. .loadfont inserts /PathLoad entry for this case
  154. %    (see gs_fonts.ps).
  155. %
  156. %    Installed fonts are being loaded with GS font loader,
  157. %    the they are passed to FAPI is same way as embedded fonts are.
  158. %    We do so because UFST cannot read fonts, which don't
  159. %    follow Type 1/42 file format strongly.
  160. %
  161. % 3. Executing .loadfont, we place /FAPI_hook_disable in the 0th
  162. %    element of some procedure on the execution stack - see gs_fonts.ps .
  163. %    If FAPI_hook finds /FAPI_hook_disable in there, 
  164. %    it knows that it is called for a disk font during 
  165. %    its internal definefont.
  166. %
  167. % 4. If font dictionary has no /FAPI entry, and has no /Path entry,
  168. %    and if we are not in .loadfont context, it is an embedded font.
  169. %
  170. % 5. Two entries to be defined in lib/FAPIconfig to control the hooking of PS fonts :
  171. %    HookDiskFonts and HookEmbeddedFonts .
  172. %    They specify arrays of font types (integers) to be redirected with FAPI.
  173. %    HookDiskFonts controls disk PS fonts (which fall into (2) and (3) ).
  174. %    HookEmbeddedFonts controls fonts being embedded into documents.
  175. %
  176. % 7. We apply the operator .passtoFAPI for checking whether FAPI can handle a font. 
  177. %    If so, we insert /FAPI entry into the font dictionary and convert it
  178. %    with .FAPIrebuildfont . Otherwise the font is handled with the native GS font renderer.
  179.  
  180. /FAPI_hook_debug   % <proc> FAPI_hook_debug -
  181. FAPIDEBUG { {exec} } { {pop} } ifelse
  182. bind def
  183.  
  184. /FAPI_hook_warn   % <proc> FAPI_hook_debug -
  185. QUIET { {pop} } { {exec} } ifelse
  186. bind def
  187.  
  188. /FAPI_is_hook_disabled     % - FAPI_is_hook_disabled <bool>
  189. { % checks whether execution stack contains packedarray started with /FAPI_hook_disable .
  190.   /FAPI_hook_disable /MappedCategoryRedefiner /ProcSet findresource /execstack_lookup get exec
  191.   null ne
  192. } bind def
  193.  
  194. /FAPIhook_aux  %      <string|name> <font_dict> .FAPIhook <string|name> <font>
  195. {                                                     % name <<font>>
  196.   { (FAPIhook ) print 1 index = } //FAPI_hook_debug exec
  197.   dup /FAPI known {
  198.     { //PrintFontRef exec ( is mapped to FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
  199.     true //.FAPIrebuildfont //ChooseDecoding exec
  200.   } {
  201.     dup /PathLoad known dup {
  202.       { (PathLoad known for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
  203.     } {
  204.       pop //FAPI_is_hook_disabled exec dup
  205.       { pop
  206.         { (FAPIhook is in .loadfont context for the font ) print //PrintFontRef exec (.) = } //FAPI_hook_debug exec
  207.         true
  208.       } if
  209.     } ifelse
  210.     { /HookDiskFonts } { /HookEmbeddedFonts } ifelse
  211.     //Config exch get                                  % name <<font>> [types]
  212.     1 index //GetFontType exec //FindInArray exec      % name <<font>> bHook
  213.     { { (Trying to render the font ) print //PrintFontRef exec ( with FAPI...) = } //FAPI_hook_debug exec
  214.       //.FAPIpassfont {
  215.         { //PrintFontRef exec ( is being rendered with FAPI=) print dup /FAPI get = } //FAPI_hook_warn exec
  216.         false //.FAPIrebuildfont //ChooseDecoding exec
  217.       } {
  218.         { (Can't render ) print //PrintFontRef exec ( with FAPI, will do with native GS renderer.) = } //FAPI_hook_warn exec
  219.       } ifelse
  220.     } {
  221.       { (The font ) print //PrintFontRef exec ( doesn't need to render with FAPI.) = } //FAPI_hook_debug exec
  222.     } ifelse
  223.   } ifelse
  224. } bind def
  225.  
  226. /FAPIhook  %      <string|name> <font_dict> .FAPIhook <string|name> <font>
  227. { //is_device_compatible_to_FAPI exec
  228.   { //FAPIhook_aux exec
  229.   } {
  230.     { (FAPIhook is disabled for the current device.) = } //FAPI_hook_debug exec
  231.   } ifelse
  232. } bind def
  233.  
  234. % ------------------ Redefine .buildfont* with FAPI : -----------------------
  235.  
  236. /.buildfont1
  237. { //.buildfont1 exec //FAPIhook exec
  238. } bind % 'odef' is below.
  239.  
  240. /.buildfont2
  241. { //.buildfont2 exec //FAPIhook exec
  242. } bind % 'odef' is below.
  243.  
  244. /.buildfont42
  245. { //.buildfont42 exec //FAPIhook exec
  246. } bind % 'odef' is below.
  247.  
  248. /.buildfont9
  249. { //.buildfont9 exec //FAPIhook exec
  250. } bind % 'odef' is below.
  251.  
  252. /.buildfont10
  253. { //.buildfont10 exec //FAPIhook exec
  254. } bind % 'odef' is below.
  255.  
  256. /.buildfont11
  257. { //.buildfont11 exec //FAPIhook exec
  258. } bind % 'odef' is below.
  259.  
  260. end % the temporary dictionary for local binding.
  261. odef odef odef odef odef odef
  262.  
  263. .setlanguagelevel
  264.  
  265. %END FAPI
  266.