pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danielwil...@apache.org
Subject svn commit: r915854 - in /pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font: PDFontFactory.java PDType1CFont.java
Date Wed, 24 Feb 2010 16:25:30 GMT
Author: danielwilson
Date: Wed Feb 24 16:25:30 2010
New Revision: 915854

URL: http://svn.apache.org/viewvc?rev=915854&view=rev
Log:
Incorporate Villu's patch from PDFBOX-635

Modified:
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java?rev=915854&r1=915853&r2=915854&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java Wed Feb 24
16:25:30 2010
@@ -119,7 +119,14 @@
                     String ff3SubType = ff3Stream.getNameAsString(COSName.SUBTYPE);
                     if( ff3SubType.equals("Type1C") )
                     {
-                        retval = new PDType1CFont( dic );
+                        try 
+                        {
+                            retval = new PDType1CFont( dic );
+                        }
+                        catch( Exception e )
+                        {
+                            log.warn("Failed to create Type1C font. Falling back to Type1
font", e);
+                        }
                     }
                 }
             }

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java?rev=915854&r1=915853&r2=915854&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java Wed Feb 24
16:25:30 2010
@@ -96,9 +96,11 @@
      * Constructor.
      * @param fontDictionary the corresponding dictionary
      */
-    public PDType1CFont( COSDictionary fontDictionary )
+    public PDType1CFont( COSDictionary fontDictionary ) throws IOException
     {
         super( fontDictionary );
+
+        load();
     }
 
     /**
@@ -106,8 +108,6 @@
      */
     public String encode( byte[] bytes, int offset, int length ) throws IOException
     {
-        ensureLoaded();
-
         String character = getCharacter(bytes, offset, length);
         if( character == null )
         {
@@ -135,8 +135,6 @@
      */
     public float getFontWidth( byte[] bytes, int offset, int length ) throws IOException
     {
-        ensureLoaded();
-
         String name = getName(bytes, offset, length);
         if( name == null && !Arrays.equals(SPACE_BYTES, bytes) )
         {
@@ -160,8 +158,6 @@
      */
     public float getFontHeight( byte[] bytes, int offset, int length ) throws IOException
     {
-        ensureLoaded();
-
         String name = getName(bytes, offset, length);
         if( name == null )
         {
@@ -197,8 +193,6 @@
      */
     public float getStringWidth( String string ) throws IOException
     {
-        ensureLoaded();
-
         float width = 0;
 
         for( int i = 0; i < string.length(); i++ )
@@ -229,8 +223,6 @@
      */
     public PDFontDescriptor getFontDescriptor() throws IOException
     {
-        ensureLoaded();
-
         return new PDFontDescriptorAFM(this.fontMetric);
     }
 
@@ -239,8 +231,6 @@
      */
     public float getAverageFontWidth() throws IOException
     {
-        ensureLoaded();
-
         if( this.avgWidth == null )
         {
             this.avgWidth = Float.valueOf(this.fontMetric.getAverageCharacterWidth());
@@ -254,8 +244,6 @@
      */
     public PDRectangle getFontBoundingBox() throws IOException
     {
-        ensureLoaded();
-
         if( this.fontBBox == null )
         {
             this.fontBBox = new PDRectangle(this.fontMetric.getFontBBox());
@@ -270,20 +258,13 @@
     public void drawString( String string, Graphics g, float fontSize, AffineTransform at,
float x, float y ) 
         throws IOException
     {
-        ensureLoaded();
-
         Graphics2D g2d = (Graphics2D)g;
         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         writeFont(g2d, at, this.awtFont, fontSize, x, y, string);
     }
 
-    private void ensureLoaded() throws IOException
+    private void load() throws IOException
     {
-        if( this.cffFont != null )
-        {
-            return;
-        }
-
         byte[] cffBytes = loadBytes();
 
         CFFParser cffParser = new CFFParser();
@@ -578,4 +559,4 @@
         }
     }
 
-}
\ No newline at end of file
+}



Mime
View raw message