home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_fapi.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  11.2 KB  |  345 lines

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