public void process(RandomAccessFileOrArray rf) throws DocumentException, IOException
    {
        String line;
        boolean isMetrics = false;
        while ((line = rf.readLine()) != null)
        {
            StringTokenizer tok = new StringTokenizer(line, " ,\n\r\t\f");
            if (!tok.hasMoreTokens())
                continue;
            String ident = tok.nextToken();
            if (ident.equals("FontName"))
                FontName = tok.nextToken("\u00ff").substring(1);
            else if (ident.equals("FullName"))
                FullName = tok.nextToken("\u00ff").substring(1);
            else if (ident.equals("FamilyName"))
                FamilyName = tok.nextToken("\u00ff").substring(1);
            else if (ident.equals("Weight"))
                Weight = tok.nextToken("\u00ff").substring(1);
            else if (ident.equals("ItalicAngle"))
                ItalicAngle = Float.parseFloat(tok.nextToken());
            else if (ident.equals("IsFixedPitch"))
                IsFixedPitch = tok.nextToken().equals("true");
            else if (ident.equals("CharacterSet"))
                CharacterSet = tok.nextToken("\u00ff").substring(1);
            else if (ident.equals("FontBBox"))
            {
                llx = (int)Float.parseFloat(tok.nextToken());
                lly = (int)Float.parseFloat(tok.nextToken());
                urx = (int)Float.parseFloat(tok.nextToken());
                ury = (int)Float.parseFloat(tok.nextToken());
            }
            else if (ident.equals("UnderlinePosition"))
                UnderlinePosition = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("UnderlineThickness"))
                UnderlineThickness = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("EncodingScheme"))
                EncodingScheme = tok.nextToken("\u00ff").substring(1);
            else if (ident.equals("CapHeight"))
                CapHeight = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("XHeight"))
                XHeight = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("Ascender"))
                Ascender = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("Descender"))
                Descender = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("StdHW"))
                StdHW = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("StdVW"))
                StdVW = (int)Float.parseFloat(tok.nextToken());
            else if (ident.equals("StartCharMetrics"))
            {
                isMetrics = true;
                break;
            }
        }
        if (!isMetrics)
            throw new DocumentException("Missing StartCharMetrics in " + fileName);
        while ((line = rf.readLine()) != null)
        {
            StringTokenizer tok = new StringTokenizer(line);
            if (!tok.hasMoreTokens())
                continue;
            String ident = tok.nextToken();
            if (ident.equals("EndCharMetrics"))
            {
                isMetrics = false;
                break;
            }
            Integer C = Integer.valueOf(-1);
            Integer WX = Integer.valueOf(250);
            String N = "";
            int B[] = null;

            tok = new StringTokenizer(line, ";");
            while (tok.hasMoreTokens())
            {
                StringTokenizer tokc = new StringTokenizer(tok.nextToken());
                if (!tokc.hasMoreTokens())
                    continue;
                ident = tokc.nextToken();
                if (ident.equals("C"))
                    C = Integer.valueOf(tokc.nextToken());
                else if (ident.equals("WX"))
                    WX = Integer.valueOf((int)Float.parseFloat(tokc.nextToken()));
                else if (ident.equals("N"))
                    N = tokc.nextToken();
                else if (ident.equals("B")) {
                    B = new int[]{Integer.parseInt(tokc.nextToken()), 
                                         Integer.parseInt(tokc.nextToken()),
                                         Integer.parseInt(tokc.nextToken()),
                                         Integer.parseInt(tokc.nextToken())};
                }
            }
            Object metrics[] = new Object[]{C, WX, N, B};
            if (C.intValue() >= 0)
                CharMetrics.put(C, metrics);
            CharMetrics.put(N, metrics);
        }
        if (isMetrics)
            throw new DocumentException("Missing EndCharMetrics in " + fileName);
        if (!CharMetrics.containsKey("nonbreakingspace")) {
            Object[] space = (Object[])CharMetrics.get("space");
            if (space != null)
                CharMetrics.put("nonbreakingspace", space);
        }
        while ((line = rf.readLine()) != null)
        {
            StringTokenizer tok = new StringTokenizer(line);
            if (!tok.hasMoreTokens())
                continue;
            String ident = tok.nextToken();
            if (ident.equals("EndFontMetrics"))
                return;
            if (ident.equals("StartKernPairs"))
            {
                isMetrics = true;
                break;
            }
        }
        if (!isMetrics)
            throw new DocumentException("Missing EndFontMetrics in " + fileName);
        while ((line = rf.readLine()) != null)
        {
            StringTokenizer tok = new StringTokenizer(line);
            if (!tok.hasMoreTokens())
                continue;
            String ident = tok.nextToken();
            if (ident.equals("KPX"))
            {
                String first = tok.nextToken();
                String second = tok.nextToken();
                Integer width = Integer.valueOf((int)Float.parseFloat(tok.nextToken()));
                Object relates[] = (Object[])KernPairs.get(first);
                if (relates == null)
                    KernPairs.put(first, new Object[]{second, width});
                else
                {
                    int n = relates.length;
                    Object relates2[] = new Object[n + 2];
                    System.arraycopy(relates, 0, relates2, 0, n);
                    relates2[n] = second;
                    relates2[n + 1] = width;
                    KernPairs.put(first, relates2);
                }
            }
            else if (ident.equals("EndKernPairs"))
            {
                isMetrics = false;
                break;
            }
        }
        if (isMetrics)
            throw new DocumentException("Missing EndKernPairs in " + fileName);
        rf.close();
    }
public void process ( RandomAccessFileOrArray rf ) throws DocumentException , IOException { String line ; boolean isMetrics = false ; while ( ( line = rf . readLine ( ) ) != null ) { StringTokenizer tok = new StringTokenizer ( line , " ,\n\r\t\f" ) ; if ( ! tok . hasMoreTokens ( ) ) continue ; String ident = tok . nextToken ( ) ; if ( ident . equals ( "FontName" ) ) FontName = tok . nextToken ( "ÿ" ) . substring ( 1 ) ; else if ( ident . equals ( "FullName" ) ) FullName = tok . nextToken ( "ÿ" ) . substring ( 1 ) ; else if ( ident . equals ( "FamilyName" ) ) FamilyName = tok . nextToken ( "ÿ" ) . substring ( 1 ) ; else if ( ident . equals ( "Weight" ) ) Weight = tok . nextToken ( "ÿ" ) . substring ( 1 ) ; else if ( ident . equals ( "ItalicAngle" ) ) ItalicAngle = Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "IsFixedPitch" ) ) IsFixedPitch = tok . nextToken ( ) . equals ( "true" ) ; else if ( ident . equals ( "CharacterSet" ) ) CharacterSet = tok . nextToken ( "ÿ" ) . substring ( 1 ) ; else if ( ident . equals ( "FontBBox" ) ) { llx = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; lly = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; urx = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; ury = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; } else if ( ident . equals ( "UnderlinePosition" ) ) UnderlinePosition = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "UnderlineThickness" ) ) UnderlineThickness = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "EncodingScheme" ) ) EncodingScheme = tok . nextToken ( "ÿ" ) . substring ( 1 ) ; else if ( ident . equals ( "CapHeight" ) ) CapHeight = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "XHeight" ) ) XHeight = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "Ascender" ) ) Ascender = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "Descender" ) ) Descender = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "StdHW" ) ) StdHW = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "StdVW" ) ) StdVW = ( int ) Float . parseFloat ( tok . nextToken ( ) ) ; else if ( ident . equals ( "StartCharMetrics" ) ) { isMetrics = true ; break ; } } if ( ! isMetrics ) throw new DocumentException ( "Missing StartCharMetrics in " + fileName ) ; while ( ( line = rf . readLine ( ) ) != null ) { StringTokenizer tok = new StringTokenizer ( line ) ; if ( ! tok . hasMoreTokens ( ) ) continue ; String ident = tok . nextToken ( ) ; if ( ident . equals ( "EndCharMetrics" ) ) { isMetrics = false ; break ; } Integer C = Integer . valueOf ( - 1 ) ; Integer WX = Integer . valueOf ( 250 ) ; String N = "" ; int B [ ] = null ; tok = new StringTokenizer ( line , ";" ) ; while ( tok . hasMoreTokens ( ) ) { StringTokenizer tokc = new StringTokenizer ( tok . nextToken ( ) ) ; if ( ! tokc . hasMoreTokens ( ) ) continue ; ident = tokc . nextToken ( ) ; if ( ident . equals ( "C" ) ) C = Integer . valueOf ( tokc . nextToken ( ) ) ; else if ( ident . equals ( "WX" ) ) WX = Integer . valueOf ( ( int ) Float . parseFloat ( tokc . nextToken ( ) ) ) ; else if ( ident . equals ( "N" ) ) N = tokc . nextToken ( ) ; else if ( ident . equals ( "B" ) ) { B = new int [ ] { Integer . parseInt ( tokc . nextToken ( ) ) , Integer . parseInt ( tokc . nextToken ( ) ) , Integer . parseInt ( tokc . nextToken ( ) ) , Integer . parseInt ( tokc . nextToken ( ) ) } ; } } Object metrics [ ] = new Object [ ] { C , WX , N , B } ; if ( C . intValue ( ) >= 0 ) CharMetrics . put ( C , metrics ) ; CharMetrics . put ( N , metrics ) ; } if ( isMetrics ) throw new DocumentException ( "Missing EndCharMetrics in " + fileName ) ; if ( ! CharMetrics . containsKey ( "nonbreakingspace" ) ) { Object [ ] space = ( Object [ ] ) CharMetrics . get ( "space" ) ; if ( space != null ) CharMetrics . put ( "nonbreakingspace" , space ) ; } while ( ( line = rf . readLine ( ) ) != null ) { StringTokenizer tok = new StringTokenizer ( line ) ; if ( ! tok . hasMoreTokens ( ) ) continue ; String ident = tok . nextToken ( ) ; if ( ident . equals ( "EndFontMetrics" ) ) return ; if ( ident . equals ( "StartKernPairs" ) ) { isMetrics = true ; break ; } } if ( ! isMetrics ) throw new DocumentException ( "Missing EndFontMetrics in " + fileName ) ; while ( ( line = rf . readLine ( ) ) != null ) { StringTokenizer tok = new StringTokenizer ( line ) ; if ( ! tok . hasMoreTokens ( ) ) continue ; String ident = tok . nextToken ( ) ; if ( ident . equals ( "KPX" ) ) { String first = tok . nextToken ( ) ; String second = tok . nextToken ( ) ; Integer width = Integer . valueOf ( ( int ) Float . parseFloat ( tok . nextToken ( ) ) ) ; Object relates [ ] = ( Object [ ] ) KernPairs . get ( first ) ; if ( relates == null ) KernPairs . put ( first , new Object [ ] { second , width } ) ; else { int n = relates . length ; Object relates2 [ ] = new Object [ n + 2 ] ; System . arraycopy ( relates , 0 , relates2 , 0 , n ) ; relates2 [ n ] = second ; relates2 [ n + 1 ] = width ; KernPairs . put ( first , relates2 ) ; } } else if ( ident . equals ( "EndKernPairs" ) ) { isMetrics = false ; break ; } } if ( isMetrics ) throw new DocumentException ( "Missing EndKernPairs in " + fileName ) ; rf . close ( ) ; }
Reads the font metrics
@param rf the AFM file
@throws DocumentException the AFM file is invalid
@throws IOException the AFM file could not be read