home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / PSUTILS / GETAFM.CMD < prev    next >
OS/2 REXX Batch file  |  1994-01-13  |  6KB  |  362 lines

  1. extproc sh d:/bin/getafm.cmd 
  2. #!/bin/sh
  3.  
  4. shift 
  5.  
  6. if [ $# -ne 1 ]; then
  7.   echo "usage: $0 font-name | gsnd - >font-name.afm" >&2
  8.   exit 1
  9. fi
  10.  
  11. cat << EOF
  12. %!
  13. % produce .afm for $1
  14. % (c) 1993 by Robert Joop <rj@rainbow.in-berlin.de>
  15. % inspired by two other versions of this theme which are
  16. %    getafm 1.00 (c) AJCD
  17. % and getafm.ps by an unknown author,
  18. %    modified by J. Daniel Smith <dsmith@mailhost.aa.cad.slb.com>
  19.  
  20. % Metrics dictionary code added by AJCD, 7/6/93
  21.  
  22. /getafmdict 100 dict dup begin
  23.  
  24.   /buf 256 string def
  25.   /buf2 16 string def
  26.  
  27.   /prany    % dict dictname printname -> dict
  28.   {
  29.     2 index 2 index cvn known
  30.     {
  31.       print % printname
  32.       ( ) print
  33.       1 index exch cvn get =
  34.     }
  35.     {
  36.       (Comment /FontInfo contains no /) print
  37.       2 copy eq
  38.       {
  39.         = % printname
  40.     pop % dictname
  41.       }
  42.       {
  43.     exch
  44.     print % dictname
  45.     (, therefore no ) print
  46.     = % printname
  47.       }
  48.       ifelse
  49.     }
  50.     ifelse
  51.   }
  52.   bind def
  53.  
  54.   /printfontname
  55.   {
  56.     (FontName)dup prany
  57.   }
  58.   bind def
  59.  
  60.   /printfontinfo
  61.   {
  62.     dup /FontInfo known
  63.     {
  64.       dup /FontInfo get
  65.     (FullName)dup prany
  66.     (FamilyName)dup prany
  67.     (Weight)dup prany
  68.     (ItalicAngle)dup prany
  69.     (isFixedPitch)(IsFixedPitch) prany
  70.     (UnderlinePosition)dup prany
  71.     (UnderlineThickness)dup prany
  72.     (Version)(version) prany
  73.     (Notice)dup prany
  74.       pop
  75.     }
  76.     {
  77.       (Comment Font lacks a /FontInfo!)=
  78.     }
  79.     ifelse
  80.   }
  81.   bind def
  82.  
  83.   /prbbox % llx lly urx ury -> -
  84.   {
  85.     4 1 roll 3 1 roll exch % swap top 4 elements
  86.     4 { ( ) print buf cvs print } repeat
  87.   }
  88.   bind def
  89.  
  90.   /getbbox % fontdict chardict character -> fontdict chardict llx lly urx ury
  91.   {
  92.     gsave
  93.       2 index setfont 0 0 moveto
  94.       false charpath flattenpath pathbbox
  95.     grestore
  96.   }
  97.   bind def
  98.  
  99.   /printmiscinfo
  100.   {
  101.     dup /FontBBox known
  102.     {
  103.       (FontBBox) print
  104.       dup /FontBBox get aload pop prbbox ()=
  105.     }
  106.     {
  107.       (Comment missing required /FontBBox)=
  108.       quit
  109.     }
  110.     ifelse
  111.     2 copy exch get
  112.       dup /H known
  113.       1 index /x known and
  114.       1 index /d known and
  115.       1 index /p known and
  116.       dup /looksRoman exch def
  117.       {
  118.     (CapHeight ) print
  119.     (H) getbbox
  120.     ceiling cvi = pop pop pop
  121.     (XHeight ) print
  122.     (x) getbbox
  123.     ceiling cvi = pop pop pop
  124.     (Ascender ) print
  125.     (d) getbbox
  126.     ceiling cvi = pop pop pop
  127.     (Descender ) print
  128.     (p) getbbox
  129.     pop pop floor cvi = pop
  130.       }
  131.       {
  132.     (Comment font doesn't contain H, x, d and p; therefore no CapHeight, XHeight, Ascender and Descender)=
  133.       }
  134.       ifelse
  135.     pop
  136.     dup /Encoding get
  137.       [
  138.     [ (ISOLatin1Encoding) /ISOLatin1Encoding ]
  139.     [ (AdobeStandardEncoding) /StandardEncoding ]
  140.       ]
  141.       {
  142.     aload pop dup where
  143.     {
  144.       exch get 2 index eq
  145.       {
  146.         (EncodingScheme ) print
  147.         buf cvs =
  148.       }
  149.       {
  150.         pop
  151.       }
  152.       ifelse
  153.     }
  154.     {
  155.       pop pop
  156.     }
  157.     ifelse
  158.       }
  159.       forall
  160.     pop
  161.   }
  162.   bind def
  163.  
  164.   /printcharmetric
  165.   {
  166.     % chardictname fontdict charnamedict encoding charindex charname
  167.  
  168.     4 index dup length dict dup begin exch
  169.       {
  170.     1 index /FID ne
  171.     2 index /UniqueID ne
  172.     and
  173.     {
  174.       1 index /Encoding eq { 256 array copy } if
  175.       def
  176.     }
  177.     { pop pop }
  178.     ifelse
  179.       }
  180.       forall
  181.     end
  182.     dup /Encoding get 32 3 index put
  183.     /f2 exch definefont
  184.     setfont
  185.  
  186.     (C ) print
  187.     1 index buf cvs print
  188.  
  189.     ( ; WX ) print
  190. % Metrics entries are:
  191. %       1 number:               which is the character width
  192. %       an array of 2 numbers:  which are the left sidebearing and width
  193. %       an array of 4 numbers:  x & y left sidebearing, width and height
  194.     dup 5 index         % /charname fontdict
  195.     dup /Metrics known {
  196.        /Metrics get exch 2 copy known {
  197.           get dup type /arraytype eq {
  198.              dup length 2 eq
  199.              {1 get} {2 get} ifelse
  200.           } if
  201.           round cvi buf cvs print
  202.        } {
  203.           pop pop ( ) stringwidth pop round cvi buf cvs print
  204.        } ifelse
  205.     } {
  206.        pop pop ( ) stringwidth pop round cvi buf cvs print
  207.     } ifelse
  208.  
  209.     ( ; N ) print
  210.     dup buf cvs print
  211.  
  212.     ( ; B) print
  213.     gsave
  214.       newpath 0 0 moveto
  215.       ( ) true charpath flattenpath pathbbox
  216.     grestore
  217.     2 { ceiling cvi 4 1 roll } repeat
  218.     2 { floor cvi 4 1 roll } repeat
  219.     prbbox
  220.  
  221.     looksRoman
  222.     {
  223.       [
  224.     [ /f [ /i /f /l ] ]
  225.     [ /ff [ /i /l ] ]
  226.       ]
  227.       {
  228.     aload pop 1 index 3 index eq
  229.     {
  230.       { 
  231.         1 index buf cvs
  232.         length
  233.         1 index buf2 cvs dup length
  234.         2 index add
  235.         buf
  236.         4 2 roll putinterval
  237.         buf 0
  238.         3 -1 roll getinterval
  239.         dup cvn
  240.         7 index
  241.         exch known
  242.         {
  243.           exch
  244.           ( ; L ) print
  245.           buf2 cvs print
  246.           ( ) print
  247.           print
  248.         }
  249.         {
  250.           pop pop
  251.         }
  252.         ifelse
  253.       }
  254.       forall
  255.       pop 
  256.     }
  257.     {
  258.       pop pop
  259.     }
  260.     ifelse
  261.       }
  262.       forall
  263.     }
  264.     if
  265.     pop
  266.  
  267.     ( ;)=
  268.   }
  269.   bind def
  270.  
  271.   /printcharmetrics
  272.   {
  273.     (StartCharMetrics ) print
  274.     2 copy exch get length 1 sub buf cvs =
  275.  
  276.     256 dict dup begin
  277.       1 index /Encoding get
  278.       { null def }
  279.       forall
  280.     end
  281.     % chardictname fontdict charnamedict
  282.     1 index /Encoding get
  283.     0 1 255
  284.     {
  285.       % encoding index
  286.       2 copy get
  287.       dup /.notdef eq { pop } { printcharmetric } ifelse
  288.       pop % index
  289.     } for
  290.  
  291.     -1
  292.     3 index 5 index get
  293.     {
  294.       pop
  295.       dup /.notdef eq
  296.       { pop }
  297.       {
  298.     % chardictname fontdict charnamedict encoding charindex charname
  299.     dup 4 index exch known
  300.     { pop }
  301.     { printcharmetric }
  302.     ifelse
  303.       }
  304.       ifelse
  305.     }
  306.     forall
  307.     % charnamedict encoding index
  308.     pop pop pop
  309.  
  310.     (EndCharMetrics)=
  311.   }
  312.   bind def
  313.  
  314.   /printfontmetrics
  315.   {
  316.     (StartFontMetrics 3.0)=
  317.     (Comment Produced by getafm 3.0 (which is by rj@rainbow.in-berlin.de))=
  318.  
  319.     printfontname
  320.     printfontinfo
  321.     printmiscinfo
  322.     printcharmetrics
  323.  
  324.     (EndFontMetrics)=
  325.   }
  326.   bind def
  327.  
  328. end def
  329.  
  330. /getafm
  331. {
  332.   getafmdict begin
  333.     save exch
  334.       findfont 1000 scalefont 
  335.  
  336.       null
  337.       [ /CharDefs /CharData /CharProcs /CharStrings ]
  338.       {
  339.     2 index 1 index known { exch } if
  340.     pop
  341.       }
  342.       forall
  343.       dup null eq
  344.       {
  345.     (can't find dictionary with character data!)=
  346.     quit
  347.       }
  348.       if
  349.       exch % dictname fontdict
  350.  
  351.       printfontmetrics
  352.  
  353.       pop pop
  354.     restore
  355.   end
  356. }
  357. bind def
  358.  
  359. /$1 getafm
  360.  
  361. EOF
  362.