pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1611905 - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox: pdmodel/font/PDFontFactory.java util/operator/SetTextFont.java
Date Sat, 19 Jul 2014 12:28:09 GMT
Author: tilman
Date: Sat Jul 19 12:28:09 2014
New Revision: 1611905

URL: http://svn.apache.org/r1611905
Log:
PDFBOX-2222: create a default font if font doesn't exist

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetTextFont.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java?rev=1611905&r1=1611904&r2=1611905&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
Sat Jul 19 12:28:09 2014
@@ -124,4 +124,19 @@ public class PDFontFactory
         }
         return retval;
     }
+
+    /**
+     * Create a default font
+     * 
+     * @return a default font
+     * @throws IOException if something goes wrong
+     */
+    public static PDFont createDefaultFont() throws IOException
+    {
+        COSDictionary dict = new COSDictionary();
+        dict.setItem(COSName.TYPE, COSName.FONT);
+        dict.setItem (COSName.SUBTYPE, COSName.TYPE1);
+        dict.setString(COSName.BASE_FONT, "Arial");
+        return createFont(dict);
+    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetTextFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetTextFont.java?rev=1611905&r1=1611904&r2=1611905&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetTextFont.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetTextFont.java
Sat Jul 19 12:28:09 2014
@@ -25,6 +25,9 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.util.PDFOperator;
 
 import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.pdmodel.font.PDFontFactory;
 
 /**
  * @author Huault : huault@free.fr
@@ -33,6 +36,8 @@ import java.io.IOException;
 
 public class SetTextFont extends OperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(SetTextFont.class);
+    
     /**
      * Tf selectfont Set text font and size.
      * @param operator The operator that is being executed.
@@ -51,11 +56,13 @@ public class SetTextFont extends Operato
             float fontSize = ((COSNumber)arguments.get( 1 ) ).floatValue();
             context.getGraphicsState().getTextState().setFontSize( fontSize );
 
-            context.getGraphicsState().getTextState().setFont( (PDFont)context.getFonts().get(
fontName.getName() ) );
-            if( context.getGraphicsState().getTextState().getFont() == null )
+            PDFont font = (PDFont) context.getFonts().get(fontName.getName());
+            if( font == null )
             {
-                throw new IOException( "Error: Could not find font(" + fontName + ") in map="
+ context.getFonts() );
+                LOG.error("Could not find font(" + fontName + ") in map=" + context.getFonts()
+ ", creating default font");
+                font = PDFontFactory.createDefaultFont();
             }
+            context.getGraphicsState().getTextState().setFont(font);
         }
     }
 



Mime
View raw message