1 2 17 18 package org.apache.poi.contrib.metrics; 19 20 import java.awt.*; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.util.Properties ; 24 25 public class FontMetricsDumper 26 { 27 public static void main( String [] args ) throws IOException 28 { 29 30 Properties props = new Properties (); 31 32 Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); 33 for ( int i = 0; i < allFonts.length; i++ ) 34 { 35 String fontName = allFonts[i].getFontName(); 36 37 Font font = new Font(fontName, Font.BOLD, 10); 38 FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(font); 39 int fontHeight = fontMetrics.getHeight(); 40 41 props.setProperty("font." + fontName + ".height", fontHeight+""); 42 StringBuffer characters = new StringBuffer (); 43 for (char c = 'a'; c <= 'z'; c++) 44 { 45 characters.append( c + ", " ); 46 } 47 for (char c = 'A'; c <= 'Z'; c++) 48 { 49 characters.append( c + ", " ); 50 } 51 for (char c = '0'; c <= '9'; c++) 52 { 53 characters.append( c + ", " ); 54 } 55 StringBuffer widths = new StringBuffer (); 56 for (char c = 'a'; c <= 'z'; c++) 57 { 58 widths.append( fontMetrics.getWidths()[c] + ", " ); 59 } 60 for (char c = 'A'; c <= 'Z'; c++) 61 { 62 widths.append( fontMetrics.getWidths()[c] + ", " ); 63 } 64 for (char c = '0'; c <= '9'; c++) 65 { 66 widths.append( fontMetrics.getWidths()[c] + ", " ); 67 } 68 props.setProperty("font." + fontName + ".characters", characters.toString()); 69 props.setProperty("font." + fontName + ".widths", widths.toString()); 70 } 71 72 FileOutputStream fileOut = new FileOutputStream ("font_metrics.properties"); 73 try 74 { 75 props.store(fileOut, "Font Metrics"); 76 } 77 finally 78 { 79 fileOut.close(); 80 } 81 } 82 } 83 | Popular Tags |