FileDocCategorySizeDatePackage
FontMetricsDumper.javaAPI DocApache Poi 3.0.13060Mon Jan 01 12:39:34 GMT 2007org.apache.poi.contrib.metrics

FontMetricsDumper

public class FontMetricsDumper extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


        Properties props = new Properties();

        Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
        for ( int i = 0; i < allFonts.length; i++ )
        {
            String fontName = allFonts[i].getFontName();

            Font font = new Font(fontName, Font.BOLD, 10);
            FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
            int fontHeight = fontMetrics.getHeight();

            props.setProperty("font." + fontName + ".height", fontHeight+"");
            StringBuffer characters = new StringBuffer();
            for (char c = 'a"; c <= 'z"; c++)
            {
                characters.append( c + ", " );
            }
            for (char c = 'A"; c <= 'Z"; c++)
            {
                characters.append( c + ", " );
            }
            for (char c = '0"; c <= '9"; c++)
            {
                characters.append( c + ", " );
            }
            StringBuffer widths = new StringBuffer();
            for (char c = 'a"; c <= 'z"; c++)
            {
                widths.append( fontMetrics.getWidths()[c] + ", " );
            }
            for (char c = 'A"; c <= 'Z"; c++)
            {
                widths.append( fontMetrics.getWidths()[c] + ", " );
            }
            for (char c = '0"; c <= '9"; c++)
            {
                widths.append( fontMetrics.getWidths()[c] + ", " );
            }
            props.setProperty("font." + fontName + ".characters", characters.toString());
            props.setProperty("font." + fontName + ".widths", widths.toString());
        }

        FileOutputStream fileOut = new FileOutputStream("font_metrics.properties");
        try
        {
            props.store(fileOut, "Font Metrics");
        }
        finally
        {
            fileOut.close();
        }