pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1391803 - in /pdfbox/trunk/pdfbox/src/main: java/org/apache/pdfbox/pdmodel/font/FontManager.java resources/org/apache/pdfbox/resources/FontMapping.properties
Date Sat, 29 Sep 2012 14:00:22 GMT
Author: lehmi
Date: Sat Sep 29 14:00:22 2012
New Revision: 1391803

URL: http://svn.apache.org/viewvc?rev=1391803&view=rev
Log:
PDFBOX-1418: improved font mapping

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java
    pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/FontMapping.properties

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java?rev=1391803&r1=1391802&r2=1391803&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java Sat
Sep 29 14:00:22 2012
@@ -33,9 +33,9 @@ public class FontManager 
 {
 
     // HashMap with all known fonts
-    private static HashMap envFonts = new HashMap();
+    private static HashMap<String,java.awt.Font> envFonts = new HashMap<String,java.awt.Font>();
     // the standard font
-    private static String standardFont = null;
+    private final static String standardFont = "helvetica";
     private static Properties fontMapping = new Properties(); 
     
     static {
@@ -51,9 +51,8 @@ public class FontManager 
             throw new RuntimeException( "Error loading font mapping" );
         }
         loadFonts();
-        loadFontMapping();
         loadBasefontMapping();
-        setStandardFont();
+        loadFontMapping();
     }
     
     private FontManager() 
@@ -67,11 +66,7 @@ public class FontManager 
      */
     public static java.awt.Font getStandardFont() 
     {
-        if (standardFont != null)
-        {
-            return getAwtFont(standardFont);
-        }
-        return null;
+        return getAwtFont(standardFont);
     }
     
     /**
@@ -87,7 +82,7 @@ public class FontManager 
         String fontname = normalizeFontname(font);
         if (envFonts.containsKey(fontname))
         {
-            return (java.awt.Font)envFonts.get(fontname);
+            return envFonts.get(fontname);
         }
         return null;
     }
@@ -127,19 +122,6 @@ public class FontManager 
         }
     }
 
-    private static void setStandardFont() 
-    {
-        // One of the following fonts will be the standard-font 
-        if (envFonts.containsKey("arial"))
-        {
-            standardFont = "arial";
-        }
-        else if (envFonts.containsKey("timesnewroman"))
-        {
-            standardFont = "timesnewroman";
-        }
-    }
-    
     /**
      * Normalize the fontname.
      *
@@ -215,7 +197,7 @@ public class FontManager 
         while (addedMapping) 
         {
             int counter = 0;
-            Enumeration keys = fontMapping.keys();
+            Enumeration<Object> keys = fontMapping.keys();
             while (keys.hasMoreElements()) 
             {
                 String key = (String)keys.nextElement();
@@ -236,14 +218,61 @@ public class FontManager 
      */
     private static void loadBasefontMapping() 
     {
-        addFontMapping("Times-Roman","TimesNewRoman");
-        addFontMapping("Times-Bold","TimesNewRoman,Bold");
-        addFontMapping("Times-Italic","TimesNewRoman,Italic");
-        addFontMapping("Times-BoldItalic","TimesNewRoman,Bold,Italic");
-        addFontMapping("Helvetica-Oblique","Helvetica,Italic");
-        addFontMapping("Helvetica-BoldOblique","Helvetica,Bold,Italic");
-        addFontMapping("Courier-Oblique","Courier,Italic");
-        addFontMapping("Courier-BoldOblique","Courier,Bold,Italic");
+        // use well known substitutions if the environments doesn't provide native fonts
for the 14 standard fonts
+        // Times-Roman -> Serif
+        if (!addFontMapping("Times-Roman","TimesNewRoman"))
+        {
+            addFontMapping("Times-Roman","Serif");
+        }
+        if (!addFontMapping("Times-Bold","TimesNewRoman,Bold"))
+        {
+            addFontMapping("Times-Bold","Serif.bold");
+        }
+        if (!addFontMapping("Times-Italic","TimesNewRoman,Italic"))
+        {
+            addFontMapping("Times-Italic","Serif.italic");
+        }
+        if (!addFontMapping("Times-BoldItalic","TimesNewRoman,Bold,Italic"))
+        {
+            addFontMapping("Times-BoldItalic","Serif.bolditalic");
+        }
+        // Helvetica -> SansSerif
+        if (!addFontMapping("Helvetica","Helvetica"))
+        {
+            addFontMapping("Helvetica","SansSerif");
+        }
+        if (!addFontMapping("Helvetica-Bold","Helvetica,Bold"))
+        {
+            addFontMapping("Helvetica-Bold","SansSerif.bold");
+        }
+        if (!addFontMapping("Helvetica-Oblique","Helvetica,Italic"))
+        {
+            addFontMapping("Helvetica-Oblique","SansSerif.italic");
+        }
+        if (!addFontMapping("Helvetica-BoldOblique","Helvetica,Bold,Italic"))
+        {
+            addFontMapping("Helvetica-BoldOblique","SansSerif.bolditalic");
+        }
+        // Courier -> Monospaced
+        if (!addFontMapping("Courier","Courier"))
+        {
+            addFontMapping("Courier","Monospaced");
+        }
+        if (!addFontMapping("Courier-Bold","Courier,Bold"))
+        {
+            addFontMapping("Courier-Bold","Monospaced.bold");
+        }
+        if (!addFontMapping("Courier-Oblique","Courier,Italic"))
+        {
+            addFontMapping("Courier-Oblique","Monospaced.italic");
+        }
+        if (!addFontMapping("Courier-BoldOblique","Courier,Bold,Italic"))
+        {
+            addFontMapping("Courier-BoldOblique","Monospaced.bolditalic");
+        }
+        // some well known (??) substitutions found on fedora linux
+        addFontMapping("Symbol","StandardSymbolsL");
+        addFontMapping("ZapfDingbats","Dingbats");
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/FontMapping.properties
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/FontMapping.properties?rev=1391803&r1=1391802&r2=1391803&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/FontMapping.properties
(original)
+++ pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/FontMapping.properties
Sat Sep 29 14:00:22 2012
@@ -17,29 +17,14 @@
 # If a needed font isn't embedded in the pdf and not available in the running environment
 # it will be substituted with an other suitable font, if available
 #
-# These are mappings for a java 1.4.x environment. 
-# Obviously not all fonts in the environment are found, so that we have to work with the
few fonts java delivers
-#
-Arial=Lucida Sans
-Arial,Bold=Lucida Sans,Bold
-Arial,Italic=Lucida Sans,Italic
-Arial,Bold,Italic=Lucida Sans,Bold,Italic
-TimesNewRoman=Lucida Bright
-TimesNewRoman,Bold=Lucida Bright,Bold
-TimesNewRoman,Italic=Lucida Bright,Italic
-TimesNewRoman,Bold,Italic=Lucida Bright,Bold,Italic
-Courier=Lucida Sans Typewriter
-Courier,Bold=Lucida Sans Typewriter,Bold
-Courier,Italic=Lucida Sans Typewriter,Italic
-Courier,Bold,Italic=Lucida Sans Typewriter,Bold,Italic
 #
 # These are some well known mappings for some frequently used fonts
 #
-Helvetica=Arial
-Helvetica,Bold=Arial,Bold
-Helvetica,Italic=Arial,Italic
-Helvetica,Bold,Italic=Arial,Bold,Italic
-SymbolMT=StandardSymbolsL
+Arial=Helvetica 
+Arial,Bold=Helvetica,Bold
+Arial,Italic=Helvetica,Italic
+Arial,Bold,Italic=Helvetica,Bold,Italic
+SymbolMT=Symbol
 ArialMT=Arial
 ArialMT,Bold=Arial,Bold
 ArialMT,Italic=Arial,Italic



Mime
View raw message