2004-04-09 13:05:39 +00:00
|
|
|
|
|
|
|
|
/* ====================================================================
|
2006-12-22 19:18:16 +00:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 13:05:39 +00:00
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
==================================================================== */
|
|
|
|
|
|
2010-10-19 15:44:55 +00:00
|
|
|
package org.apache.poi.util;
|
2004-04-09 11:45:38 +00:00
|
|
|
|
2015-09-07 20:19:50 +00:00
|
|
|
import java.awt.Font;
|
|
|
|
|
import java.awt.FontMetrics;
|
|
|
|
|
import java.awt.GraphicsEnvironment;
|
|
|
|
|
import java.awt.Toolkit;
|
2004-04-09 11:45:38 +00:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
2016-12-30 22:12:06 +00:00
|
|
|
import java.io.OutputStream;
|
2004-04-09 11:45:38 +00:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
2010-05-30 06:57:23 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2016-12-30 22:12:06 +00:00
|
|
|
public class FontMetricsDumper {
|
2015-11-08 23:44:24 +00:00
|
|
|
@SuppressForbidden("command line tool")
|
2016-12-30 22:12:06 +00:00
|
|
|
public static void main(String[] args) throws IOException {
|
2004-04-09 11:45:38 +00:00
|
|
|
Properties props = new Properties();
|
|
|
|
|
|
|
|
|
|
Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
2016-10-21 16:31:37 +00:00
|
|
|
for (Font allFont : allFonts) {
|
|
|
|
|
String fontName = allFont.getFontName();
|
2004-04-09 11:45:38 +00:00
|
|
|
|
|
|
|
|
Font font = new Font(fontName, Font.BOLD, 10);
|
|
|
|
|
FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
|
|
|
|
|
int fontHeight = fontMetrics.getHeight();
|
|
|
|
|
|
2016-10-21 16:31:37 +00:00
|
|
|
props.setProperty("font." + fontName + ".height", fontHeight + "");
|
|
|
|
|
StringBuilder characters = new StringBuilder();
|
|
|
|
|
for (char c = 'a'; c <= 'z'; c++) {
|
|
|
|
|
characters.append(c).append(", ");
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
2016-10-21 16:31:37 +00:00
|
|
|
for (char c = 'A'; c <= 'Z'; c++) {
|
|
|
|
|
characters.append(c).append(", ");
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
2016-10-21 16:31:37 +00:00
|
|
|
for (char c = '0'; c <= '9'; c++) {
|
|
|
|
|
characters.append(c).append(", ");
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
2016-10-21 16:31:37 +00:00
|
|
|
StringBuilder widths = new StringBuilder();
|
|
|
|
|
for (char c = 'a'; c <= 'z'; c++) {
|
|
|
|
|
widths.append(fontMetrics.getWidths()[c]).append(", ");
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
2016-10-21 16:31:37 +00:00
|
|
|
for (char c = 'A'; c <= 'Z'; c++) {
|
|
|
|
|
widths.append(fontMetrics.getWidths()[c]).append(", ");
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
2016-10-21 16:31:37 +00:00
|
|
|
for (char c = '0'; c <= '9'; c++) {
|
|
|
|
|
widths.append(fontMetrics.getWidths()[c]).append(", ");
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
props.setProperty("font." + fontName + ".characters", characters.toString());
|
|
|
|
|
props.setProperty("font." + fontName + ".widths", widths.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-15 14:53:11 +00:00
|
|
|
try (OutputStream fileOut = new FileOutputStream("font_metrics.properties")) {
|
2004-04-09 11:45:38 +00:00
|
|
|
props.store(fileOut, "Font Metrics");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|