From 49c8708241bc45067382b90d76fdf4a85e5f1cae Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Sun, 17 Aug 2014 18:56:01 +0000 Subject: [PATCH] Add verbose (-v) flag to FontList tool that shows URI of font resource. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1618496 13f79535-47bb-0310-9956-ffa450edef68 --- src/codegen/fonts/font-file.xsl | 12 +++++++ .../org/apache/fop/afp/fonts/AFPFont.java | 7 +++- src/java/org/apache/fop/fonts/CustomFont.java | 11 ++++++ .../org/apache/fop/fonts/FontMetrics.java | 9 +++-- src/java/org/apache/fop/fonts/LazyFont.java | 6 ++++ .../org/apache/fop/fonts/MutableFont.java | 6 ++++ .../fop/fonts/truetype/OFFontLoader.java | 1 + .../java2d/CustomFontMetricsMapper.java | 6 ++++ .../java2d/SystemFontMetricsMapper.java | 17 ++++++++-- .../apache/fop/render/pcl/PCLGraphics2D.java | 2 +- .../fop/tools/fontlist/FontListMain.java | 34 ++++++++++++++++--- 11 files changed, 101 insertions(+), 10 deletions(-) diff --git a/src/codegen/fonts/font-file.xsl b/src/codegen/fonts/font-file.xsl index 8723ed960..42f9281bc 100644 --- a/src/codegen/fonts/font-file.xsl +++ b/src/codegen/fonts/font-file.xsl @@ -36,6 +36,7 @@ package org.apache.fop.fonts.base14; import java.awt.Rectangle; +import java.net.URI; import java.util.Map; @@ -46,6 +47,7 @@ import org.apache.fop.fonts.CodePointMapping; import org.apache.fop.fonts.Typeface; public class extends Base14Font { + private final static URI fontFileURI; private final static String fontName = ""; private final static String fullName = ""; private final static Set familyNames; @@ -69,6 +71,12 @@ public class extends Base14Font { private boolean enableKerning = false; static { + URI uri = null; + try { + uri = new URI("base14:" + fontName.toLowerCase()); + } catch (java.net.URISyntaxException e) { + } + fontFileURI = uri; width = new int[256]; boundingBoxes = new Rectangle[256]; @@ -94,6 +102,10 @@ public class extends Base14Font { return encoding; } + public URI getFontURI() { + return fontFileURI; + } + public String getFontName() { return fontName; } diff --git a/src/java/org/apache/fop/afp/fonts/AFPFont.java b/src/java/org/apache/fop/afp/fonts/AFPFont.java index 99e15a46b..3c84e4aa9 100644 --- a/src/java/org/apache/fop/afp/fonts/AFPFont.java +++ b/src/java/org/apache/fop/afp/fonts/AFPFont.java @@ -20,6 +20,7 @@ package org.apache.fop.afp.fonts; import java.awt.Rectangle; +import java.net.URI; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -27,7 +28,6 @@ import java.util.Set; import org.apache.fop.fonts.FontType; import org.apache.fop.fonts.Typeface; - /** * All implementations of AFP fonts should extend this base class, * the object implements the FontMetrics information. @@ -52,6 +52,11 @@ public abstract class AFPFont extends Typeface { this.embeddable = embeddable; } + /** {@inheritDoc} */ + public URI getFontURI() { + return null; + } + /** {@inheritDoc} */ public String getFontName() { return this.name; diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java index 5c0673b04..fffb429ed 100644 --- a/src/java/org/apache/fop/fonts/CustomFont.java +++ b/src/java/org/apache/fop/fonts/CustomFont.java @@ -42,6 +42,7 @@ public abstract class CustomFont extends Typeface /** Fallback thickness for underline and strikeout when not provided by the font. */ private static final int DEFAULT_LINE_THICKNESS = 50; + private URI fontFileURI; private String fontName; private String fullName; private Set familyNames; @@ -88,6 +89,11 @@ public abstract class CustomFont extends Typeface } + /** {@inheritDoc} */ + public URI getFontURI() { + return fontFileURI; + } + /** {@inheritDoc} */ public String getFontName() { return fontName; @@ -325,6 +331,11 @@ public abstract class CustomFont extends Typeface /* ---- MutableFont interface ---- */ + /** {@inheritDoc} */ + public void setFontURI(URI uri) { + this.fontFileURI = uri; + } + /** {@inheritDoc} */ public void setFontName(String name) { this.fontName = name; diff --git a/src/java/org/apache/fop/fonts/FontMetrics.java b/src/java/org/apache/fop/fonts/FontMetrics.java index 159d321f7..ed59cf5af 100644 --- a/src/java/org/apache/fop/fonts/FontMetrics.java +++ b/src/java/org/apache/fop/fonts/FontMetrics.java @@ -20,16 +20,21 @@ package org.apache.fop.fonts; import java.awt.Rectangle; +import java.net.URI; import java.util.Map; import java.util.Set; - - /** * Main interface for access to font metrics. */ public interface FontMetrics { + /** + * Returns the URI of the font file from which these metrics were loaded. + * @return the font file's URI + */ + URI getFontURI(); + /** * Returns the "PostScript" font name (Example: "Helvetica-BoldOblique"). * @return the font name diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index a392ae6f4..acce1e0f9 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -188,6 +188,12 @@ public class LazyFont extends Typeface implements FontDescriptor, Substitutable, } // ---- FontMetrics interface ---- + /** {@inheritDoc} */ + public URI getFontURI() { + load(true); + return realFont.getFontURI(); + } + /** {@inheritDoc} */ public String getFontName() { load(true); diff --git a/src/java/org/apache/fop/fonts/MutableFont.java b/src/java/org/apache/fop/fonts/MutableFont.java index 9ea323ebf..f02eb2b49 100644 --- a/src/java/org/apache/fop/fonts/MutableFont.java +++ b/src/java/org/apache/fop/fonts/MutableFont.java @@ -30,6 +30,12 @@ import java.util.Set; */ public interface MutableFont { + /** + * Sets the URI from which this font is or will be loaded. + * @param uri URI from which font is or will be loaded + */ + void setFontURI(URI uri); + /** * Sets the "PostScript" font name (Example: "Helvetica-BoldOblique"). * @param name font name diff --git a/src/java/org/apache/fop/fonts/truetype/OFFontLoader.java b/src/java/org/apache/fop/fonts/truetype/OFFontLoader.java index 4216cf290..7c8774933 100644 --- a/src/java/org/apache/fop/fonts/truetype/OFFontLoader.java +++ b/src/java/org/apache/fop/fonts/truetype/OFFontLoader.java @@ -141,6 +141,7 @@ public class OFFontLoader extends FontLoader { returnFont = singleFont; } + returnFont.setFontURI(fontFileURI); returnFont.setFontName(otf.getPostScriptName()); returnFont.setFullName(otf.getFullName()); returnFont.setFamilyNames(otf.getFamilyNames()); diff --git a/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java b/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java index 8a5f4b117..fcb913d53 100644 --- a/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java +++ b/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java @@ -24,6 +24,7 @@ import java.awt.FontFormatException; import java.awt.Rectangle; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.util.List; import java.util.Map; import java.util.Set; @@ -160,6 +161,11 @@ public class CustomFontMetricsMapper extends Typeface implements FontMetricsMapp return typeface.getFontName(); } + /** {@inheritDoc} */ + public final URI getFontURI() { + return typeface.getFontURI(); + } + /** {@inheritDoc} */ public final FontType getFontType() { return typeface.getFontType(); diff --git a/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java b/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java index f922e3f05..9ed323ac4 100644 --- a/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java +++ b/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java @@ -21,6 +21,7 @@ package org.apache.fop.render.java2d; // Java import java.awt.Rectangle; +import java.net.URI; import java.util.Map; import java.util.Set; @@ -44,6 +45,8 @@ public class SystemFontMetricsMapper extends Typeface implements FontMetricsMapp */ private final Java2DFontMetrics java2DFontMetrics; + private final URI fontFileURI; + /** * The java name of the font. * # Make the family name immutable. @@ -63,13 +66,23 @@ public class SystemFontMetricsMapper extends Typeface implements FontMetricsMapp * @param java2DFontMetrics metric calculations delegated to this */ public SystemFontMetricsMapper(String family, int style, Java2DFontMetrics java2DFontMetrics) { + URI uri; + try { + uri = new URI("system:" + family.toLowerCase()); + } catch (java.net.URISyntaxException e) { + uri = null; + } + this.fontFileURI = uri; this.family = family; - this.style = style; - this.java2DFontMetrics = java2DFontMetrics; } + /** {@inheritDoc} */ + public final URI getFontURI() { + return null; + } + /** {@inheritDoc} */ public String getFontName() { return family; diff --git a/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java b/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java index 93648e975..d349394c5 100644 --- a/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java +++ b/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java @@ -120,7 +120,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { * @param msg the error message to be displayed */ protected void handleUnsupportedFeature(String msg) { - if (this.FAIL_ON_UNSUPPORTED_FEATURE) { + if (FAIL_ON_UNSUPPORTED_FEATURE) { throw new UnsupportedOperationException(msg); } } diff --git a/src/java/org/apache/fop/tools/fontlist/FontListMain.java b/src/java/org/apache/fop/tools/fontlist/FontListMain.java index 794f9306f..af9921c4d 100644 --- a/src/java/org/apache/fop/tools/fontlist/FontListMain.java +++ b/src/java/org/apache/fop/tools/fontlist/FontListMain.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.net.URI; import java.net.URL; import java.util.Iterator; import java.util.List; @@ -66,6 +67,7 @@ public final class FontListMain { private FopFactory fopFactory; + private boolean verbose; private File configFile; private File outputFile; private String configMime = MimeConstants.MIME_PDF; @@ -168,22 +170,42 @@ public final class FontListMain { private void writeToConsole(SortedMap fontFamilies) throws TransformerConfigurationException, SAXException, IOException { Iterator iter = fontFamilies.entrySet().iterator(); + StringBuffer sb = new StringBuffer(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry)iter.next(); String firstFamilyName = (String)entry.getKey(); - System.out.println(firstFamilyName + ":"); + sb.append(firstFamilyName); + sb.append(':'); + sb.append('\n'); List list = (List)entry.getValue(); Iterator fonts = list.iterator(); while (fonts.hasNext()) { FontSpec f = (FontSpec)fonts.next(); - System.out.println(" " + f.getKey() + " " + f.getFamilyNames()); + sb.append(" "); + sb.append(f.getKey()); + sb.append(' '); + sb.append(f.getFamilyNames()); + if (verbose) { + URI uri = f.getFontMetrics().getFontURI(); + if (uri != null) { + sb.append(' '); + sb.append('('); + sb.append(uri.toString()); + sb.append(')'); + } + } + sb.append('\n'); Iterator triplets = f.getTriplets().iterator(); while (triplets.hasNext()) { FontTriplet triplet = (FontTriplet)triplets.next(); - System.out.println(" " + triplet.toString()); + sb.append(" "); + sb.append(triplet.toString()); + sb.append('\n'); } } } + System.out.print(sb.toString()); + System.out.flush(); } private void writeOutput(SortedMap fontFamilies) @@ -231,7 +253,7 @@ public final class FontListMain { PrintStream out = System.out; out.println("USAGE"); out.println(" java [vmargs] " + className - + " [-c ] [-f ] [[output-dir|output-file] [font-family]]"); + + "[-v] [-c ] [-f ] [[output-dir|output-file] [font-family]]"); out.println(); out.println("PARAMETERS"); out.println(" config-file: an optional FOP configuration file"); @@ -260,6 +282,10 @@ public final class FontListMain { // @SuppressFBWarnings("DM_EXIT") System.exit(0); } + if ("-v".equals(args[idx])) { + verbose = true; + idx += 1; + } if (idx < args.length - 1 && "-c".equals(args[idx])) { String filename = args[idx + 1]; this.configFile = new File(filename); -- 2.39.5