01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
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: public static void main(String[] args) throws IOException {
27:
28: Properties props = new Properties();
29:
30: Font[] allFonts = GraphicsEnvironment
31: .getLocalGraphicsEnvironment().getAllFonts();
32: for (int i = 0; i < allFonts.length; i++) {
33: String fontName = allFonts[i].getFontName();
34:
35: Font font = new Font(fontName, Font.BOLD, 10);
36: FontMetrics fontMetrics = Toolkit.getDefaultToolkit()
37: .getFontMetrics(font);
38: int fontHeight = fontMetrics.getHeight();
39:
40: props.setProperty("font." + fontName + ".height",
41: fontHeight + "");
42: StringBuffer characters = new StringBuffer();
43: for (char c = 'a'; c <= 'z'; c++) {
44: characters.append(c + ", ");
45: }
46: for (char c = 'A'; c <= 'Z'; c++) {
47: characters.append(c + ", ");
48: }
49: for (char c = '0'; c <= '9'; c++) {
50: characters.append(c + ", ");
51: }
52: StringBuffer widths = new StringBuffer();
53: for (char c = 'a'; c <= 'z'; c++) {
54: widths.append(fontMetrics.getWidths()[c] + ", ");
55: }
56: for (char c = 'A'; c <= 'Z'; c++) {
57: widths.append(fontMetrics.getWidths()[c] + ", ");
58: }
59: for (char c = '0'; c <= '9'; c++) {
60: widths.append(fontMetrics.getWidths()[c] + ", ");
61: }
62: props.setProperty("font." + fontName + ".characters",
63: characters.toString());
64: props.setProperty("font." + fontName + ".widths", widths
65: .toString());
66: }
67:
68: FileOutputStream fileOut = new FileOutputStream(
69: "font_metrics.properties");
70: try {
71: props.store(fileOut, "Font Metrics");
72: } finally {
73: fileOut.close();
74: }
75: }
76: }
|