home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / rollconv.ps < prev    next >
Text File  |  2002-05-02  |  12KB  |  373 lines

  1. %!
  2. % Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  3.  
  4. % $Id: rollconv.ps,v 1.4 2002/05/01 23:15:23 igor Exp $
  5. % Utility program for converting Japanese fonts produced by Macromedia's
  6. % Rollup program to Type 0 fonts suitable for use with Ghostscript.
  7. %
  8. % Rollup produces the following files, where xxx is the font name:
  9. %    xxx-H, xxx-SA, xxx-SB, xxx-SK, xxx-SR, xxx-UG
  10. %    JIS83-1_COD
  11. %    JIS83-1_CSA
  12. % The _COD and _CSA files are large files containing the actual
  13. % character outline data; they may theoretically be shared between
  14. % multiple fonts.
  15. %
  16. % rollconv.ps converts the above to files named:
  17. %    fff.ps
  18. %    fff.COD
  19. %    fff.CSA
  20. %    fff.CSR
  21. % where fff is a font file name provided by the user at conversion time.
  22. % The fff.ps file is the actual font file to be loaded with `run'
  23. % or placed in a Fontmap or a directory named by [GS_]FONTPATH;
  24. % the other two files must be present at runtime in a directory that is
  25. % on Ghostscript's search path (-I, GS_LIB, GS_LIB_DEFAULT).
  26. %
  27. % The normal way to invoke this program is
  28. %    gsnd -- rollconv.ps xxx fff InDir CDir OutDir
  29. % (assuming that gsnd is an alias for gs -dNODISPLAY), where:
  30. %    xxx is the font name;
  31. %    fff is the base part of the output file name;
  32. %    InDir is the name of the directory containing the xxx-* input files;
  33. %    CDir is the name of the directory containing the _COD and _CSA
  34. %      input files (typically the same as InDir);
  35. %    OutDir is the name of the directory where the output should be written
  36. %      (OutDir must already exist).
  37. % For example:
  38. %    gsnd -- rollconv.ps HGGothicBPRO gothic /gs/k/rufonts/Gothic \
  39. %      /gs/k/rufonts/Gothic /gs/k/gsfonts
  40. % To suppress output messages, you may insert -q:
  41. %    gsnd -q -- rollconv.ps ...
  42. %
  43. % This program assumes that the files have been FTP'ed from a Macintosh and
  44. % therefore have 128 bytes of garbage at the beginning.  If you have
  45. % transferred them in some manner that avoids this, change true to false
  46. % in the following line.
  47. /fromMac true def
  48. % The FontName of the converted font is xxx-83pv-RKSJ-H.  In order to
  49. % use a converted font with Ghostscript, you may either load it explicitly
  50. % at run time, e.g.,
  51. %    (gothic.ps) run
  52. % or you may add an entry to the Fontmap file, in the form:
  53. %    /HGGothicBPRO-83pv-RKSJ-H  (gothic.ps)  ;
  54. % which will allow the font to be loaded automatically.  After
  55. % loading the font, by either method, you can select it in the usual way:
  56. %    /HGGothicBPRO-83pv-RKSJ-H findfont 36 scalefont setfont
  57. % or
  58. %    /HGGothicBPRO-83pv-RKSJ-H 36 selectfont
  59.  
  60.  
  61. /macrfile        % <filename> macrfile <file>
  62.  { (r) file
  63.    fromMac
  64.     {        % Get rid of the initial Mac garbage (128 characters).
  65.         % The garbage at the end is unpredictable,
  66.         % so we'll just have to hope that it's all nulls.
  67.       dup =string 0 128 getinterval readstring pop pop
  68.     }
  69.    if
  70.  } bind def
  71.  
  72. /convert        % <FName> <OutBase> <InDir> <CDir> <OutDir> convert -
  73.  { /OutDir exch def
  74.    /CDir exch def
  75.    /InDir exch def
  76.    /OutBase exch def
  77.    /FName exch def
  78.  
  79.    /inprefix InDir (/) concatstrings FName concatstrings (-) concatstrings def
  80.    /inh inprefix (H) concatstrings def
  81.  
  82.         % Open the output file.
  83.  
  84. /OutDot OutDir (/) concatstrings OutBase concatstrings (.) concatstrings def
  85. /outname OutDot (ps) concatstrings def
  86. QUIET not { (Writing ) print outname = flush } if
  87. /cdfromstr (\(pgfonts/) FName concatstrings (-JIS83-1_) concatstrings def
  88. /cdstr (\() OutBase concatstrings (.) concatstrings def
  89. /out outname (w) file def
  90. /buffer 65000 string def
  91.  
  92.         % Copy the initial comments from the input file.
  93.  
  94. inh macrfile
  95.  { dup =string readline pop
  96.    out 1 index writestring out (\n) writestring
  97.    (%%EndComments) eq { exit } if
  98.  }
  99. loop
  100.  
  101.         % Write out our preamble.
  102.  
  103. out (
  104. currentpacking true setpacking
  105. userdict /AltsysCFD3 known { (%END) .skipeof } if
  106. userdict /AltsysCFD3 25 dict dup begin
  107. /beint { 0 exch { exch 8 bitshift add } forall } bind def
  108. /rfile { findlibfile { exch pop } { (r) file } ifelse } bind def
  109. /str 500 string def
  110. /AltRO { } def
  111. /BuildCh        % <font> <ccode> <bias> BuildCh -
  112.  { /bias exch def  /ccode exch def  begin % font
  113.    ccode dup 255 and dup bias lt exch 252 gt or { pop 127 } if
  114.    dup -8 bitshift -67 mul add % subfonts have 189 chars, not 256
  115.    bias sub buildch1
  116.  } bind def
  117. /BuildChr        % <font> <ccode> BuildChr -
  118.  { /ccode exch def  begin % font
  119.    ccode buildch1
  120.  } bind def
  121. /buildch1
  122.  { 6 mul PGOffsets add
  123.    FileNames 0 get rfile dup dup 4 -1 roll setfileposition
  124.    (xxxxxx) readstring pop exch closefile
  125.    dup 1 3 getinterval beint % COD offset
  126.    exch 4 2 getinterval beint % length
  127.    dup 0 eq
  128.     { pop pop currentdict end
  129.       1000 0 0 0 1 1 0 -1000 500 1000 setcachedevice2
  130.     }
  131.     { dup str length gt { /str 1 index string store } if
  132.       FileNames 1 get rfile dup dup % offset length file file file
  133.       5 -1 roll setfileposition % length file file
  134.       str 0 5 -1 roll getinterval readstring pop pop closefile
  135.       currentdict end ccode str 1183615869 internaldict /CCRun get exec
  136.     }
  137.    ifelse
  138.  } bind def
  139. /privates 100 dict def
  140. /BuildPr        % <stdhw> <stdvw> BuildPr <dict>
  141.  { 2 copy 1000 mul add privates 1 index known
  142.     { privates exch get 3 1 roll pop pop
  143.     }
  144.     { 7 dict begin
  145.     /MinFeature{16 16}executeonly def
  146.     /BlueValues BlueValues def
  147.     /StdVW 3 -1 roll 1 array astore def
  148.     /StdHW 3 -1 roll 1 array astore def
  149.     /password 5839 def
  150.     /LanguageGroup 1 def
  151.     /Subrs Subrs def
  152.       currentdict readonly end
  153.       privates 2 index 2 index put exch pop
  154.     }
  155.    ifelse
  156.  } bind def
  157. /FullEncoding
  158.   systemdict { pop } forall
  159.   systemdict length 512 sub 1 255 { (x) dup 0 4 -1 roll put cvn } for
  160. 768 packedarray def
  161. /BlueValues[-250 -250 1100 1100]readonly def
  162. /BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def
  163. /CharStrings 1 dict
  164. dup /.notdef (┐1py╩8Åσ) noaccess put
  165. readonly def
  166. /CDevProc
  167.  { pop pop pop pop 0 exch -1000 exch 2 div currentfont /FontBBox get 3 get
  168.  } bind def
  169. /FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]readonly def
  170. /Subrs [
  171. (┐1p|=-ôD\ΓR) noaccess
  172. (┐1py╝÷Uz) noaccess
  173. (┐1py╜─₧i) noaccess
  174. (┐1p∙) noaccess
  175. (┐1p|35r╖I) noaccess
  176. ] noaccess def
  177. end put
  178. %END
  179. ) writestring
  180.  
  181.         % Locate and copy the definition of NotDefFont.
  182.  
  183. out (
  184. FontDirectory /NotDefFont known { (%END) .skipeof } if
  185. ) writestring
  186.  { dup =string readline pop
  187.    dup (/NotDefFont) eq { exit } if pop
  188.  }
  189. loop out exch writestring out (\n) writestring
  190.  { dup =string readline pop
  191.    (definefont) search { pop pop pop exit } if
  192.    out exch writestring out (\n) writestring
  193.  }
  194. loop out (definefont pop
  195. %END
  196. ) writestring
  197.  
  198.         % Copy the definitions of the subfonts, moving the
  199.         % CharStrings of the Roman supplement to an external file.
  200.         % Stack for pattern procedures: infile line
  201.  
  202. /CSRName OutDot (CSR) concatstrings def
  203. /csr CSRName (w) file def
  204. QUIET not { (Writing ) print CSRName = flush } if
  205.  
  206. /encoding 256 array def
  207.  
  208. /patterns [
  209.         % Patterns specific to the Roman supplement, in which
  210.         % the outlines are in an eexec section.
  211.  { (/Encoding 256 array) {
  212.    pop out (/Encoding ) writestring
  213.     { dup buffer readline pop
  214.       dup (dup) search { exit } if pop pop
  215.     }
  216.    loop
  217.     {    % Stack: infile dupline postdup (dup) predup
  218.       pop pop exch pop
  219.     % The top element of the stack is a string beginning with
  220.     % an index and value to put into the Encoding.
  221.       token pop exch token pop exch pop encoding 3 1 roll put
  222.       dup buffer readline pop
  223.       dup (dup) search not { pop exit } if
  224.     }
  225.    loop
  226.    out encoding cvx write== out ( cvlit ) writestring
  227.    out exch writestring out (\n) writestring
  228.  } }
  229.  { (/FontType 1 def) {
  230.    pop out (/FontType 4 def\n) writestring
  231.    out (/BuildChar{AltsysCFD3 begin BuildChr end}bind def\n) writestring
  232.    out (/FileNames[) writestring
  233.    2 { out OutBase (.CSR) concatstrings write==only } repeat
  234.    out (]def\n) writestring
  235.  } }
  236.  { (currentfile eexec) {
  237.    pop out (systemdict begin\n) writestring
  238.    dup //.eexec_param_dict /eexecDecode filter
  239.  } }
  240.  { (dup/CharStrings ) {
  241.     % Copy the individual CharStrings to the CSR file,
  242.     % recording the lengths and offsets.
  243.    pop out (dup/CharStrings AltsysCFD3 /CharStrings get put\n) writestring
  244.    /offsets 256 dict def
  245.     { dup token pop        % char name
  246.       dup dup type /nametype eq exch xcheck not and not { pop exit } if
  247.       1 index token pop        % length of binary data
  248.       2 index token pop pop    % skip RD
  249.       2 index buffer 0 3 index getinterval readstring pop    % charstring
  250.       offsets 3 index csr fileposition 16 bitshift 4 index add put
  251.       csr exch writestring pop pop
  252.       dup buffer readline pop pop    % skip ND
  253.     }
  254.    loop
  255.     % We skipped the 'end'; skip the 'readonly put' as well.
  256.    2 { dup token pop pop } repeat
  257.    out (dup/PGOffsets ) writestring
  258.      out csr fileposition write=only
  259.      out ( put\n) writestring
  260.    encoding
  261.     { offsets exch .knownget not { 0 } if
  262.       2 { csr 0 write } repeat
  263.       4 { dup -24 bitshift csr exch write 8 bitshift } repeat pop
  264.     }
  265.    forall
  266.  } }
  267.  { (/OtherSubrs[) {
  268.    pop
  269.     { dup buffer readline pop
  270.       (]noaccess def) search { pop pop pop exit } if pop
  271.     }
  272.    loop
  273.  } }
  274.  { (/Subrs 5 array) {
  275.    pop out (/Subrs AltsysCFD3 /Subrs get def\n) writestring
  276.    6 { dup buffer readline pop pop } repeat
  277.  } }
  278.  { (currentfile closefile) {
  279.    pop out (end % systemdict\n) writestring
  280.    closefile
  281.  } }
  282.         % Patterns for other supplements.
  283.  { (pgfonts/) {
  284.     { cdfromstr search not { exit } if
  285.       out exch writestring pop out cdstr writestring
  286.     }
  287.    loop out exch writestring out (\n) writestring
  288.  } }
  289.  { (/BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def) {
  290.    pop out (\t/BuildChar AltsysCFD3 /BuildChar get def\n) writestring
  291.  } }
  292.  { (/CDevProc{pop pop pop pop 0 exch -1000 exch 2 div ) {
  293.    pop out (\t/CDevProc AltsysCFD3 /CDevProc get def\n) writestring
  294.  } }
  295.  { (/CharStrings 1 dict dup begin) {
  296.    pop out (\t/CharStrings AltsysCFD3 /CharStrings get def\n) writestring
  297.    2 { dup buffer readline pop pop } repeat
  298.  } }
  299.  { (/FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]def) {
  300.    pop out (\t/FontMatrix AltsysCFD3 /FontMatrix get def\n) writestring
  301.  } }
  302.  { (/Private 14 dict dup begin) {
  303.    pop out (\t/Private) writestring
  304.     { dup buffer readline pop
  305.       (end def) search { pop pop pop exit } if
  306.       (/Std) search
  307.        { pop pop dup length 3 sub 3 exch getinterval
  308.      (]) search pop out ( ) writestring out exch writestring pop
  309.        }
  310.       if pop
  311.     }
  312.    loop out ( AltsysCFD3 begin BuildPr end def\n) writestring
  313.  } }
  314.  { (UniqueID) { pop } }
  315.  { () {
  316.    out exch writestring out (\n) writestring
  317.  } }
  318. ] def
  319. [ (SR) (SA) (SK) (SB) (UG) ]
  320.  { 0 1 255 { encoding exch /.notdef put } for
  321.    inprefix exch concatstrings macrfile
  322.     { dup buffer readline not { pop exit } if
  323.       /patterns load
  324.        { 2 copy 0 get search { pop pop pop 1 get exec exit } if pop pop }
  325.       forall
  326.     }
  327.    loop closefile
  328.  }
  329. forall
  330. csr closefile
  331.  
  332.         % Copy the definition of the root font.
  333.  
  334. dup buffer readstring pop out exch writestring closefile
  335. out (
  336. setpacking
  337. ) writestring
  338. out closefile
  339.  
  340.         % Remove the Mac garbage from the outline files.
  341.  
  342. [ (COD) (CSA) ]
  343.  { CDir (/) concatstrings (JIS83-1_) concatstrings
  344.      1 index concatstrings macrfile
  345.    exch OutDot exch concatstrings
  346.      QUIET not { (Writing ) print dup = flush } if
  347.      (w) file
  348.         % Stack: infile outfile
  349.     { 1 index buffer readstring exch
  350.         % Stack: infile outfile noteof substring
  351.       2 index exch writestring not { exit } if
  352.     }
  353.    loop closefile closefile
  354.  }
  355. forall
  356.  
  357.  } bind def
  358.  
  359. % If the program was invoked from the command line, run it now.
  360. [ shellarguments
  361.  { counttomark 5 eq
  362.     { convert
  363.       QUIET not { (Done.\n) print flush } if
  364.     }
  365.     { cleartomark
  366.       (Usage: gsnd -- rollconv.ps FName OutBase InDir CDir OutDir\n) print
  367.       ( e.g.: gsnd -- rollconv.ps HGMinchoE mincho HGfonts/Mincho HGfonts/Mincho HGfonts/gs\n) print flush
  368.       mark
  369.     }
  370.    ifelse
  371.  }
  372. if pop
  373.