home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 8 / AU_CD8.iso / Utilities / !PSUtils / ps / getafmhd next >
Text File  |  1997-01-24  |  6KB  |  345 lines

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