]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Add verbose (-v) flag to FontList tool that shows URI of font resource.
authorGlenn Adams <gadams@apache.org>
Sun, 17 Aug 2014 18:56:01 +0000 (18:56 +0000)
committerGlenn Adams <gadams@apache.org>
Sun, 17 Aug 2014 18:56:01 +0000 (18:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1618496 13f79535-47bb-0310-9956-ffa450edef68

src/codegen/fonts/font-file.xsl
src/java/org/apache/fop/afp/fonts/AFPFont.java
src/java/org/apache/fop/fonts/CustomFont.java
src/java/org/apache/fop/fonts/FontMetrics.java
src/java/org/apache/fop/fonts/LazyFont.java
src/java/org/apache/fop/fonts/MutableFont.java
src/java/org/apache/fop/fonts/truetype/OFFontLoader.java
src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java
src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java
src/java/org/apache/fop/render/pcl/PCLGraphics2D.java
src/java/org/apache/fop/tools/fontlist/FontListMain.java

index 8723ed960ca4036323839ab8c0757fb970162ce5..42f9281bcbad757b56f4575636519031608d4495 100644 (file)
@@ -36,6 +36,7 @@
 package org.apache.fop.fonts.base14;
 
 import java.awt.Rectangle;
+import java.net.URI;
 <xsl:if test="count(kerning) &gt; 0">
 import java.util.Map;
 </xsl:if>
@@ -46,6 +47,7 @@ import org.apache.fop.fonts.CodePointMapping;
 import org.apache.fop.fonts.Typeface;
 
 public class <xsl:value-of select="class-name"/> extends Base14Font {
+    private final static URI fontFileURI;
     private final static String fontName = "<xsl:value-of select="font-name"/>";
     private final static String fullName = "<xsl:value-of select="full-name"/>";
     private final static Set familyNames;
@@ -69,6 +71,12 @@ public class <xsl:value-of select="class-name"/> 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];
         <xsl:apply-templates select="char-metrics"/>
@@ -94,6 +102,10 @@ public class <xsl:value-of select="class-name"/> extends Base14Font {
         return encoding;
     }
 
+    public URI getFontURI() {
+        return fontFileURI;
+    }
+
     public String getFontName() {
         return fontName;
     }
index 99e15a46b415fa5f4f5f5891b301c402e130954e..3c84e4aa93a28ad1240f08031e1aa313f9ccbf3e 100644 (file)
@@ -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;
index 5c0673b04c9a0b8e758fb5d35978aece6229c8b1..fffb429ed2a4db5cf198d290f9b683d2f107457b 100644 (file)
@@ -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<String> 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;
index 159d321f7e59eb7c40888f7bab4818bd18d2c871..ed59cf5af7006bf73848eaf0e165a3afd181a6e9 100644 (file)
 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
index a392ae6f49ac90206cebdb9d26047962619c6b88..acce1e0f9c874ad9be226db2f312203f2d95351b 100644 (file)
@@ -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);
index 9ea323ebfebf9f162acdc6191ce15ab7a49e8e6e..f02eb2b49575cb34a5b4a242549e1a12309b487d 100644 (file)
@@ -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
index 4216cf29048a0fab59b72b582b9c9e199fd04f57..7c87749338c735490cd9dd7aeba7e566b4650cf9 100644 (file)
@@ -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());
index 8a5f4b117f04488545ff92d1bb93a46eea7ccf7a..fcb913d533f0b2b4feeb2f32e5ec9e49e9ff176d 100644 (file)
@@ -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();
index f922e3f05c857ee5a096710faa3f53f64d5ea924..9ed323ac439c211841ee197745bdfeb99154b52a 100644 (file)
@@ -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;
index 93648e9757df7c23589ef4a92318602a48f4d321..d349394c522a1d85a4f2c9747315cc68cca9ff1a 100644 (file)
@@ -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);
         }
     }
index 794f9306f33e479008e70c81faff4d902a58af7d..af9921c4da44a8717ef0e3d470cfeda316eae9bb 100644 (file)
@@ -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 <config-file>] [-f <mime>] [[output-dir|output-file] [font-family]]");
+                + "[-v] [-c <config-file>] [-f <mime>] [[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);