home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_fntem.ps < prev    next >
Text File  |  2003-12-13  |  11KB  |  398 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_fntem.ps,v 1.4.2.1 2003/12/12 22:07:58 giles Exp $
  14. % A procset for Postscript font emulation
  15.  
  16. % The procedures must not depend on the presence of the
  17. % procset dictionary on the dictionary stack.
  18.  
  19. languagelevel 2 .setlanguagelevel
  20.  
  21. %========================= Process xlatmap ====================
  22. mark
  23. %% Replace 1 (xlatmap)
  24. (xlatmap) .runlibfile
  25. .dicttomark dup systemdict exch /.xlatmap_dict exch put
  26.  
  27. % Convert it into a plain text to simplify the processing in C :
  28. % *(fontkind\0\0\ *(charmap\0decoding\0) ) \0
  29.  
  30. () exch {
  31.   3 1 roll =string cvs concatstrings (\0\0) concatstrings
  32.   exch
  33.   { =string cvs concatstrings (\0) concatstrings
  34.   } forall
  35. } forall
  36. (\0) concatstrings
  37. systemdict exch /.xlatmap exch put
  38.  
  39. /FontEmulationProcs 10 dict begin
  40.  
  41. %-------------------------------Font--------------------------------
  42.  
  43.  
  44. /FontCommon  % - font_common -
  45. { currentdict /PaintType known not {
  46.     /PaintType 0 def
  47.   } if
  48.   currentdict /Encoding .knownget not {
  49.     //StandardEncoding
  50.   } if
  51.   dup type /nametype eq {
  52.     /Encoding findresource
  53.   } if
  54.   /Encoding exch def
  55. } bind def
  56.  
  57. /FontOptions 5 dict begin
  58.   /make_procs currentdict def
  59.   /NameKey /FontName def
  60.   /TypeKey /FontType def
  61.  
  62.   1
  63.   { /FontMatrix [0.001 0 0 0.001 0 0] def
  64.     /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  65.     /Private 0 dict def
  66.     /CharStrings << /.notdef () >> def
  67.     //FontCommon exec
  68.   } bind def
  69.  
  70.   42
  71.   { /FontMatrix [1 0 0 1 0 0] def
  72.     /FontBBox [0 0 1 1] def % zfapi.ps refines it.
  73.     /CharStrings <<>> def
  74.     /sfnts [<00010000 0000 0000 0000 0000 0000>] def
  75.     /GlyphDirectory [] def
  76.     //FontCommon exec
  77.   } bind def
  78.  
  79.   %fixme : more font types.
  80.  
  81. currentdict end def
  82.  
  83. %---------------------------CIDFont---------------------------
  84.  
  85. /TranslateCSI   % <record> TranslateCSI <CSI>
  86. { begin
  87.   << /Registry (Adobe) 
  88.      /Ordering CSI aload pop 
  89.      /Supplement exch 
  90.   >>
  91.   end
  92. } bind def
  93.  
  94. /CIDFontCommon
  95. { /CIDSystemInfo currentdict //TranslateCSI exec def
  96.   currentdict /CSI undef
  97.   /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  98.   /CIDCount 1 def % ChooseDecoding will set a reasonable value.
  99. } bind def
  100.  
  101. % GFlyph substitution table for narrow, wide, proportional glyphs - 
  102. % used with TrueTypes.
  103.  
  104. currentpacking false setpacking
  105. /SubstNWP << 
  106.  
  107.   % Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type
  108.   % type = (n==narrow, w==wide, p==proportional).
  109.  
  110.   /Japan1
  111.   { p 1 94 231 n    
  112.  
  113.     p 17 26 780 w
  114.     p 34 59 790 w
  115.     p 66 91 816 w
  116.     w 842 842 7918 w  % fixme: These substitutions require to shift the glyph origin.
  117.     w 844 844 7919 w
  118.     w 846 846 7920 w
  119.     w 848 848 7921 w
  120.     w 850 850 7922 w
  121.     w 876 876 7923 w
  122.     w 908 908 7924 w
  123.     w 910 910 7925 w
  124.     w 912 912 7926 w
  125.     w 914 914 7927 w
  126.     w 925 925 7928 w
  127.     w 927 927 7929 w
  128.     w 929 929 7930 w
  129.     w 931 931 7931 w
  130.     w 933 933 7932 w
  131.     w 959 959 7933 w
  132.     w 991 991 7934 w
  133.     w 993 993 7935 w
  134.     w 995 995 7936 w
  135.     w 1002 1002 7937 w
  136.     w 1009 1009 7938 w
  137.     w 1010 1010 7939 w
  138.   } cvlit
  139.  
  140.   /Japan2 1 index
  141.  
  142.   /CNS1
  143.   { p 1 94 13648 n
  144.  
  145.     p 17 26 333 w
  146.     p 34 59 365 w
  147.     p 66 91 391 w
  148.   } cvlit
  149.  
  150.   /GB1
  151.   { p 2 94 814 n
  152.   
  153.     p 2 94 262 w
  154.  
  155.     p 1 1 7716 n
  156.   } cvlit
  157.  
  158.   /Korea1
  159.   { p  1 60 8094 n
  160.     p 62 94 8155 n
  161.  
  162.     p  2 59 264 w
  163.     p 63 94 325 w
  164.   } cvlit
  165.  
  166.   /Identity []
  167.  
  168. >> def
  169. setpacking
  170.  
  171. /CIDFontOptions 5 dict begin
  172.   /make_procs currentdict def
  173.   /NameKey /CIDFontName def
  174.   /TypeKey /CIDFontType def
  175.  
  176.   0
  177.   { //CIDFontCommon exec
  178.     /FDArray [
  179.       14 dict begin
  180.         /FontName CIDFontName =string cvs (%) concatstrings cvn def
  181.         /FontType 1 def
  182.         /FontMatrix [0.001 0 0 0.001 0 0 ] def
  183.         /PaintType 0 def
  184.         /Private 0 dict def
  185.         currentdict
  186.       end
  187.     ] def
  188.     /GlyphDirectory [] def
  189.     /GDBytes 1 def
  190.     /FDBytes 0 def
  191.   } bind def
  192.  
  193.   1
  194.   { //CIDFontCommon exec
  195.     /FontMatrix [1 0 0 1 0 0] def
  196.     /BuildGlyph {} def
  197.   } bind def
  198.  
  199.   2
  200.   { //CIDFontCommon exec
  201.     /FontMatrix [1 0 0 1 0 0] def
  202.     /GDBytes 2 def
  203.     /CIDMap <0000> def
  204.     /sfnts [<00010000 0000 0000 0000 0000 0000>] def
  205.     /Encoding [] def
  206.     /CharStrings << /.notdef 0 >> def
  207.   } bind def
  208.  
  209. currentdict end def
  210.  
  211. /complete_instance  % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  212. { begin
  213.   dup length dict copy
  214.   begin
  215.   1 index NameKey exch def
  216.   currentglobal true setglobal
  217.   make_procs TypeKey load .knownget {
  218.     exec
  219.   } { setglobal
  220.       /complete_instance cvx /invalidfont signalerror
  221.   } ifelse
  222.   setglobal
  223.   currentdict end
  224.   end
  225. } bind def
  226.  
  227. /GetFilePath    % <scratch> <Name> <record> GetFilePath <filepath>
  228. { exch pop                       % (scratch) <record>
  229.   /Path get                      % (scratch) (path)
  230.   exch copy
  231.   % What we make here it is not a complete PS resource.
  232.   % Unable to provide full conformity :
  233.   % the attempt to run this file may fail.
  234. } bind def
  235.  
  236. /GetSize        % <Name> <record> GetSize <size>
  237. { pop pop -1 % Unknown size.
  238.   % fixme: probably we could provide an estimation size for some fonts.
  239. } bind def
  240.  
  241. /RecordVirtualMethodsStub 3 dict begin
  242.   /GetFilePath //GetFilePath def
  243.   /GetSize //GetSize def
  244. currentdict end def
  245.  
  246. % ---------------------- Decoding helpers ----------------------------
  247.  
  248. /encodingnames mark
  249.  StandardEncoding /StandardEncoding
  250.  ISOLatin1Encoding /ISOLatin1Encoding
  251.  SymbolEncoding /SymbolEncoding
  252.  DingbatsEncoding /DingbatsEncoding
  253.  /resourceforall where
  254.   { pop (*) { cvn dup findencoding exch } 1024 string /Encoding resourceforall }
  255.  if
  256. .dicttomark def
  257.  
  258. /ChooseDecoding  % <font> ChooseDecoding <font>
  259. { { % A loop for 'exit' context.
  260.     dup /Decoding .knownget {
  261.       dup type /nametype eq {
  262.         1 index /CIDFontType known { /CIDDecoding } { /Decoding } ifelse
  263.         findresource 1 index exch /Decoding exch put
  264.       } {
  265.         pop
  266.       } ifelse
  267.       dup /CIDFontType known {
  268.         dup dup /Decoding get /CIDCount get /CIDCount exch put
  269.       } if
  270.       exit
  271.     } if
  272.     dup /CIDFontType known {
  273.       % This is a hooked CID font, no need for Decoding.
  274.       exit
  275.     } if
  276.     % This works when the renderer can't choose character by name,
  277.     % and we cannot determine the charset.
  278.     % Probably this branch is to be removed after UFST problem is fixed.
  279.     dup /Encoding get                                    % <<font>> encoding
  280.     dup type /nametype eq {
  281.       /Decoding findresource 1 index exch /Decoding exch put
  282.     } {
  283.       dup //encodingnames
  284.       exch .knownget {
  285.         exch pop
  286.         /Decoding findresource 1 index exch /Decoding exch put
  287.       } {
  288.         % unknown encoding, convert it to decoding :
  289.         dup length dict begin
  290.         /.notdef 0 def
  291.         0 1 currentdict length 1 sub
  292.         { dup 2 index exch get 
  293.           dup /.notdef ne {
  294.             exch def
  295.           } {
  296.             pop pop
  297.           } ifelse
  298.         } for
  299.         pop
  300.         currentdict end
  301.         1 index exch /Decoding exch put
  302.       } ifelse
  303.     } ifelse
  304.     exit
  305.   } loop
  306.   dup /CIDFontType known {
  307.     dup /SubstNWP .knownget not {
  308.       dup /CIDSystemInfo get /Ordering get cvn
  309.     } if
  310.     dup type /nametype eq {
  311.       //SubstNWP exch get                              % <<font>> [SubstNWP]
  312.     } if
  313.     1 index exch /SubstNWP exch put
  314.   } if
  315. } bind def
  316.  
  317. /PrintFontRef      % <string|name> <font> PrintFontRef <string|name> <font>
  318. { dup /FontName known { (Font ) } { (CIDFont ) } ifelse print
  319.   1 index =string cvs print
  320.   dup /FontName .knownget not {
  321.     dup /CIDFontName get
  322.   } if                               % <string|name> <font> <fontname>
  323.   dup 3 index ne {
  324.     ( \( aliased from ) print
  325.     =string cvs print ( \)) print
  326.   } {
  327.     pop
  328.   } ifelse
  329. } bind def
  330.  
  331. /GetFontType       % <font> GetFontType int
  332. { dup /CIDFontType .knownget {
  333.     exch pop 9 add
  334.   } {
  335.     /FontType get
  336.   } ifelse
  337. } bind def
  338.  
  339. /FindInArray    % <array> <elem> .array_find <bool>
  340. { false 3 1 roll
  341.   exch {                      % false elem elem_i
  342.     1 index eq {              % false elem
  343.        pop true exch
  344.     } if
  345.   } forall
  346.   pop
  347. } bind def
  348.  
  349. /ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font>
  350. {
  351.   % If the font is maintained by FAPI, or if it is TT-emulated CID font,
  352.   % it already has /Decoding. But its value isn't guaranteeed to
  353.   % be an Unicode decoding. Since we can't determine whether 
  354.   % it is an Unicode decoding, we unconditionally load an appropriate Unicode decoding
  355.   % and attach it with /GlyphNames2Unicode entry.
  356.   %
  357.   % Another interesting case is when the font already has /GlyphNames2Unicode.
  358.   % The latter to be used instead. Note that /GlyphNames2Unicode
  359.   % appears only when type 32 fonts are disable (see .pdf_hook_DSC_Creator),
  360.   % but an automatic disabling is not implemented yet.
  361.  
  362.   currentglobal true setglobal exch
  363.   dup /FontInfo known not {
  364.     dup /FontInfo 1 dict put
  365.   } if
  366.   { % A loop just for 'exit' context.
  367.     dup /FontInfo get /GlyphNames2Unicode known {
  368.       exit
  369.     } if
  370.     dup /CIDFontType known {
  371.       dup mark exch                                              % bool <font> [ <font>
  372.       dup /CIDSystemInfo get /Ordering get (.Unicode)            % bool <font> [ <font> () ()
  373.       concatstrings cvn                                          % bool <font> [ <font> /Name
  374.       /CIDDecoding { findresource } stopped {
  375.         % Can't provide a decoding, giving up without creating /GlyphNames2Unicode.
  376.         cleartomark exit
  377.       } if                                                       % bool <font> [ <font> <D>
  378.       exch /FontInfo get exch                                    % bool <font> [ <FI> <D>
  379.       /GlyphNames2Unicode exch
  380.       .forceput % FontInfo can be read-only.
  381.       pop                                                        % bool <font>
  382.       exit
  383.     } if
  384.     dup /FontInfo get                                            % bool <font> <FI>
  385.     /GlyphNames2Unicode /Unicode /Decoding findresource
  386.     .forceput % FontInfo can be read-only.
  387.     exit
  388.   } loop
  389.   exch setglobal
  390. } bind def
  391.  
  392. currentdict end /ProcSet defineresource pop
  393.  
  394. .setlanguagelevel
  395.