pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r737638 - in /incubator/pdfbox/trunk/src/main: java/org/apache/pdfbox/pdmodel/font/FontManager.java resources/Resources/FontMapping.properties
Date Mon, 26 Jan 2009 06:19:58 GMT
Author: lehmi
Date: Mon Jan 26 06:19:57 2009
New Revision: 737638

URL: http://svn.apache.org/viewvc?rev=737638&view=rev
Log:
PDFBOX-302: Adding some additional font-mapping espacially for java 1.4.x

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

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java?rev=737638&r1=737637&r2=737638&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/FontManager.java Mon
Jan 26 06:19:57 2009
@@ -34,11 +34,25 @@
     private static HashMap envFonts = new HashMap();
 	// the standard font
     private static String standardFont = null;
+	private static Properties fontMapping = new Properties(); 
     
     static {
+        try
+        {
+            ResourceLoader.loadProperties( "Resources/FontMapping.properties", fontMapping
);
+        }
+        catch( IOException io )
+        {
+            io.printStackTrace();
+            throw new RuntimeException( "Error loading font mapping" );
+        }
     	loadFonts();
-    	loadFontMapping();
+    	// There could be some recursive mappings in the fontmapping, so that we have to 
+    	// read the list until no more additional mapping is added to it 
+    	while (loadFontMapping() > 0) 
+    		; 
     	loadBasefontMapping();
+    	setStandardFont();
     }
     
     /**
@@ -91,6 +105,9 @@
 				envFonts.put(family, font);
 			}
 		}
+    }
+
+    private static void setStandardFont() {
 		// One of the following fonts will be the standard-font 
 		if (envFonts.containsKey("arial"))
 			standardFont = "arial";
@@ -135,38 +152,32 @@
      * @param mappedName The name of the mapped font.
      * 
      */
-    private static void addFontMapping(String font, String mappedName) {
+    private static boolean addFontMapping(String font, String mappedName) {
     	String fontname = normalizeFontname(font);
     	// is there already a font mapping ?
     	if (envFonts.containsKey(fontname))
-    		return;
+    		return false;
     	String mappedFontname = normalizeFontname(mappedName);
     	// is the mapped font available ?
     	if (!envFonts.containsKey(mappedFontname))
-    		return;
+    		return false;
     	envFonts.put(fontname, envFonts.get(mappedFontname));
+    	return true;
     }
     
     /**
      * Load the mapping for the well knwon font-substitutions
      *
      */
-    private static void loadFontMapping() {
-    	Properties fontMapping = new Properties();; 
-        try
-        {
-            ResourceLoader.loadProperties( "Resources/FontMapping.properties", fontMapping
);
-        }
-        catch( IOException io )
-        {
-            io.printStackTrace();
-            throw new RuntimeException( "Error loading font mapping" );
-        }
+    private static int loadFontMapping() {
         Enumeration keys = fontMapping.keys();
+        int counter = 0;
         while (keys.hasMoreElements()) {
         	String key = (String)keys.nextElement();
-        	addFontMapping(key,(String)fontMapping.get(key));
+        	if (addFontMapping(key,(String)fontMapping.get(key)))
+        		counter++;
         }
+        return counter;
     }
 
     /**

Modified: incubator/pdfbox/trunk/src/main/resources/Resources/FontMapping.properties
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/resources/Resources/FontMapping.properties?rev=737638&r1=737637&r2=737638&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/resources/Resources/FontMapping.properties (original)
+++ incubator/pdfbox/trunk/src/main/resources/Resources/FontMapping.properties Mon Jan 26
06:19:57 2009
@@ -1,7 +1,25 @@
-# This file contaions well known font substitutions. 
+# This file contains well known font substitutions. 
 # 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
@@ -12,4 +30,4 @@
 ArialMT,Italic=Arial,Italic
 ArialMT,Bold,Italic=Arial,Bold,Italic
 TimesNewRomanPSMT=Verdana
-TimesNewRomanPSMT,Bold=Verdana,Bold
\ No newline at end of file
+TimesNewRomanPSMT,Bold=Verdana,Bold



Mime
View raw message