home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / wftopfa.ps < prev    next >
Text File  |  2000-03-09  |  9KB  |  306 lines

  1. %    Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % $Id: wftopfa.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  16. % wftopfa.ps
  17. % Convert a Wadalab base font to .PFA (or .PFB) format.
  18.  
  19. (gs_ksb_e.ps) runlibfile
  20. (wrfont.ps) runlibfile
  21.  
  22. /wftopfa_dict 100 dict def
  23. wftopfa_dict begin
  24.  
  25. /KanjiSubEncoding dup .findencoding def
  26.  
  27. % Initialize parameters.
  28. /init            % - init -
  29.  { /chars 256 dict def
  30.    /version (001.001) def
  31.    /highcode 0 def
  32.    /StdHW [32] def
  33.    /StdVW [32] def
  34.    /UniqueID 20000000 def
  35.    /FontBase (Wadalab) def
  36.    /StdEncMode false def
  37.    /CustomEncMode false def
  38.    /Binary false def
  39.    /Encrypt true def
  40.  } bind def
  41.  
  42. % Read definitions.
  43. /rdstring 5000 string def
  44. /readdefs        % <filename> readdefs -
  45.  { (r) file
  46.     { dup rdstring readline not { pop exit } if
  47.       dup length 15 ge
  48.        { dup dup length 7 sub 7 getinterval (> CompD) eq
  49.       { token pop exch token pop exch pop
  50.         dup 0 get /highcode exch def
  51.         exch chars 3 1 roll put
  52.       }
  53.       { pop
  54.       }
  55.      ifelse
  56.        }
  57.        { pop
  58.        }
  59.       ifelse
  60.     }
  61.    loop closefile
  62.  } bind def
  63.  
  64. % Write out the final font.
  65. /writepfa
  66.  { 4 string highcode 16#1000 add 16 2 index cvrs 0 (.r) putinterval
  67.      FontBase exch concatstrings /fullname exch def
  68.    UniqueID 20000000 eq { /UniqueID 4990000 highcode add def } if
  69.    /encoding CustomEncMode
  70.     { KanjiSubEncoding }
  71.     { StdEncMode { StandardEncoding } { ISOLatin1Encoding } ifelse }
  72.    ifelse def
  73.  
  74.    /Font 30 dict def
  75.    Font begin
  76.    /FontInfo 20 dict def
  77.    FontInfo begin
  78.  
  79.         % Write the clear text part.
  80.  
  81.    /CreationDate (%Calendar%) currentdevparams
  82.      dup /Weekday get {(Sun )(Mon )(Tue )(Wed )(Thu )(Fri )(Sat )} exch get
  83.      1 index /Month get 1 sub
  84.        {(Jan)(Feb)(Mar)(Apr)(May)(Jun)(Jul)(Aug)(Sep)(Oct)(Nov)(Dec)} exch get
  85.      concatstrings
  86.       {{/Day ( )} {/Hour ( )} {/Minute (:)} {/Second (:)} {/Year ( )}}
  87.       { dup 1 get 3 -1 roll exch concatstrings exch
  88.         0 get 2 index exch get
  89.         dup 10 lt { =string cvs (0) exch concatstrings } { =string cvs } ifelse
  90.         concatstrings
  91.       }
  92.      forall exch pop readonly def
  93.    /VMusage 100000 def
  94.    /version version readonly def
  95.    /Notice (No copyright on this font. Original available from moe.ipl.t.u-tokyo.ac.jp:/Font. Converted by wftopfa.ps (Aladdin Enterprises).) readonly def
  96.    /FullName fullname readonly def
  97.    /FamilyName FontBase readonly def
  98.    /Weight (Regular) readonly def
  99.    /ItalicAngle 0 def
  100.    /isFixedPitch true def
  101.    /UnderlinePosition 0 def
  102.    /UnderlineThickness 0 def
  103.  
  104.    end            % FontInfo
  105.  
  106.    /FontName fullname cvn def
  107.    /Encoding encoding def
  108.    /PaintType 0 def
  109.    /FontType 1 def
  110.    /FontMatrix [.001 0 0 .001 0 -0.16] readonly def
  111.    /UniqueID UniqueID def
  112.    /FontBBox [0 0 1000 1000] readonly def
  113.  
  114.    /Private 20 dict def
  115.    Private begin
  116.  
  117.    /-| {string currentfile exch readstring pop} readonly def
  118.    /|- {readonly def} readonly def
  119.    /| {readonly put} readonly def
  120.    /BlueValues [] readonly def
  121.    /OtherBlues [] readonly def
  122.    /MinFeature {16 16} readonly def
  123.    /StdHW StdHW def
  124.    /StdVW StdVW def
  125.    /ForceBold false def
  126.    /password 5839 def
  127.    /UniqueID UniqueID def
  128.    /OtherSubrs [] readonly def
  129.    /Subrs [
  130.      (\020\2771p|\020\024\020=-\223D\\\342R) readonly
  131.      (\020\2771py\274\366Uz) readonly
  132.      (\020\2771py\275\304\236i) readonly
  133.      (\020\2771p\371) readonly
  134.      (\020\2771p~\266+6\034\3446z) readonly
  135.    ] readonly def
  136.  
  137.    end            % Private
  138.  
  139.    /CharStrings 256 dict def
  140.    chars
  141.     { exch =string cvs
  142.       dup 0 get highcode eq
  143.        { 1 get encoding exch get exch CharStrings 3 1 roll put }
  144.        { pop pop }
  145.       ifelse
  146.     }
  147.    forall
  148.  
  149.    end            % Font
  150.  
  151.    Font /FontName get Font definefont setfont
  152.    (%stdout) (w) file writefont
  153.  } bind def
  154.  
  155. % Scan the command line and process files.
  156. /options mark
  157.   /version { 2 copy get /version exch def 1 add } bind
  158.   /StdHW { 2 copy get cvx exec /StdHW exch def 1 add } bind
  159.   /StdVW { 2 copy get cvx exec /StdVW exch def 1 add } bind
  160.   /UniqueId { 2 copy get cvi /UniqueID exch def 1 add } bind
  161.   /UniqueID 1 index
  162.   /FontBase { 2 copy get /FontBase exch def 1 add } bind
  163.   /StdEnc { /StdEncMode true def } bind
  164.   /CustomEnc { /CustomEncMode true def } bind
  165.   /Binary { /Binary true def } bind
  166.   /noEncrypt { /Encrypt false def } bind
  167. .dicttomark def
  168. /wftopfa        % [(arg1) ...] wftopfa -
  169.  { init dup 0
  170.     { dup 2 index length ge { exit } if
  171.       2 copy get exch 1 add exch
  172.       options 1 index .knownget { exch pop exec } { readdefs } ifelse
  173.     }
  174.    loop pop pop
  175.    wrfont_dict /binary_CharStrings Binary put
  176.    wrfont_dict /eexec_encrypt Encrypt put
  177.    wrfont_dict /name_all_Encodings CustomEncMode put
  178.    writepfa
  179.  } bind def
  180.  
  181. end                % wftopfa_dict
  182.  
  183. /wftopfa
  184.  { mark exch wftopfa_dict begin /saved save def { wftopfa } exec false%stopped
  185.     { cleartomark true } { cleartomark false } ifelse
  186.    saved end restore { stop } if
  187.  } bind def
  188.  
  189. [ shellarguments
  190.  { ] wftopfa }
  191.  { pop }
  192. ifelse
  193.  
  194. % ---------------- Root font ---------------- %
  195.  
  196. % Define the Encoding for the root font.
  197. /wfrootencoding
  198. % \x00-\x3F
  199.   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  200.   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  201.   0  1  2  3  4  5  6  7  8  0  0  0  0  0  0  0
  202.   9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  203. % \x40-\x7F
  204.  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  205.  41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  206.  57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  207.  73 74 75 76 77  0  0  0  0  0  0  0  0  0  0  0
  208. % \x80-\xFF
  209. 128 copy
  210. 256 packedarray def
  211.  
  212. % Define the template for the root font dictionary.
  213. /wfrootfontdict mark
  214.   /FontType 0
  215.   /FontMatrix [1 0 0 1 0 0]
  216.   /FMapType 2
  217.   /Encoding wfrootencoding
  218. .dicttomark def
  219.  
  220. % Define a dummy (placeholder) Type 1 font for the FDepVector.
  221. /type1dummyfont        % <fontname> type1dummyfont <font>
  222.  { mark /FontName 3 -1 roll
  223.    /FontType 1
  224.    /FontMatrix [.001 0 0 .001 0 0]
  225.    /FontBBox [0 0 1000 1000]
  226.    /Encoding /KanjiSubEncoding findencoding
  227.    /CharStrings 0 dict
  228.    /Private mark /BlueValues [] /password 5839 .dicttomark
  229.    .dicttomark dup /FontName get exch definefont
  230.  } bind def
  231.  
  232. % Write a root font.  Again, wrfont.ps does most of the work.
  233. /makerootfont        % <rootname> makerootfont <font>
  234.  { wfrootfontdict dup length 4 add    % FontName, FDepVector, PrefEnc, FID
  235.    dict copy begin
  236.    cvlit /FontName exch def
  237.    4 dict begin
  238.    /len FontName length def
  239.    /str len 4 add string def
  240.    FontName str cvs pop
  241.    str len (.r) putinterval
  242.    /FDepVector [ 16#21 1 16#74
  243.     { dup wfrootencoding exch get 0 eq
  244.        { pop
  245.        }
  246.        { 16 str len 2 add 2 getinterval cvrs pop
  247.          str cvn type1dummyfont
  248.        }
  249.       ifelse
  250.     }
  251.    for end counttomark -1 roll dup counttomark 2 roll
  252.    ] def
  253.    FontName currentdict end definefont
  254.  } bind def
  255. /writerootfont        % <rootname> writerootfont -
  256.  { save exch makerootfont setfont (%stdout) (w) file writefont restore
  257.  } bind def
  258.  
  259. % ---------------- Converting entire fonts ---------------- %
  260.  
  261. % Define the directory where the Wadalab fonts are stored.
  262. /wfdir (/home/ghost/kanji/w) def
  263.  
  264. % Convert an entire Wadalab font.
  265. /writeentirefont    % <fontname> <template*> writeentirefont -
  266.  { 2 dict begin
  267.    /templates exch def
  268.    /fontname exch def
  269.    [ templates
  270.       { wfdir (/) concatstrings exch concatstrings { copystring }
  271.     100 string filenameforall
  272.       }
  273.      forall
  274.      wfdir (/wadalab-sym/*.ps) concatstrings { copystring }
  275.        100 string filenameforall
  276.    ]
  277.    (%!\n) print
  278.     { /currentuserparams where
  279.        { pop currentuserparams /VMReclaim get -2 vmreclaim { vmreclaim } }
  280.        { { } }
  281.       ifelse
  282.     } == (exec\n) print
  283.    (/KanjiSubEncoding ) print /KanjiSubEncoding findencoding ==
  284.      (readonly def\n) print
  285.     { (%stderr) (w) file dup 2 index write== flushfile
  286.        mark exch (CustomEnc) (Binary) (noEncrypt)
  287.        (FontBase) fontname counttomark -1 roll ] wftopfa
  288.     }
  289.    forall
  290.    fontname cvn writerootfont
  291.    (exec\n) print
  292.    end
  293.  } def            % don't bind, so we can print the procedure
  294.  
  295. % Convert the Wadalab JIS 1&2 SaiMincho font.
  296. % To invoke this from the command line,
  297. %    gs -dNODISPLAY -q wftopfa.ps -c writeSaiMincho0 flush quit >wmin0.ps
  298. % To make the resulting font loadable on demand, add to the Fontmap file:
  299. %    /Wadalab-SaiMincho (wmin0.ps) ;
  300. /writeSaiMincho0
  301.  { (Wadalab-SaiMincho) [ (wadalab-mincho-0-8/*.ps) ] writeentirefont
  302.  } bind def
  303.