You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/06/10 21:49:59 UTC
svn commit: r953431 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font:
PDSimpleFont.java PDType1CFont.java PDType1Font.java
Author: lehmi
Date: Thu Jun 10 19:49:59 2010
New Revision: 953431
URL: http://svn.apache.org/viewvc?rev=953431&view=rev
Log:
PDFBOX-739: use the DescendantFont of a base font, enabled the fontfile3 usage
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=953431&r1=953430&r2=953431&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java Thu Jun 10 19:49:59 2010
@@ -268,6 +268,23 @@ public abstract class PDSimpleFont exten
{
fontDescriptor = new PDFontDescriptorAFM( afm );
}
+ else
+ {
+ COSArray descendantFontArray =
+ (COSArray)font.getDictionaryObject( COSName.DESCENDANT_FONTS );
+ if (descendantFontArray != null)
+ {
+ fd = (COSDictionary)descendantFontArray.getObject( 0 );
+ if (fd != null)
+ {
+ fd = (COSDictionary)fd.getDictionaryObject( COSName.FONT_DESC );
+ if (fd != null)
+ {
+ fontDescriptor = new PDFontDescriptorDictionary( fd );
+ }
+ }
+ }
+ }
}
else
{
@@ -303,7 +320,7 @@ public abstract class PDSimpleFont exten
*/
public PDStream getToUnicode() throws IOException
{
- return PDStream.createFromCOS( font.getDictionaryObject( "ToUnicode" ) );
+ return PDStream.createFromCOS( font.getDictionaryObject( COSName.TO_UNICODE ) );
}
/**
@@ -313,7 +330,7 @@ public abstract class PDSimpleFont exten
*/
public void setToUnicode( PDStream unicode )
{
- font.setItem( "ToUnicode", unicode );
+ font.setItem( COSName.TO_UNICODE, unicode );
}
/**
@@ -364,7 +381,7 @@ public abstract class PDSimpleFont exten
}
catch (NoninvertibleTransformException e)
{
- System.err.println( "Error in "+getClass().getName()+".writeFont:"+e);
+ log.error("Error in "+getClass().getName()+".writeFont",e);
}
}
else
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java?rev=953431&r1=953430&r2=953431&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java Thu Jun 10 19:49:59 2010
@@ -19,9 +19,6 @@ package org.apache.pdfbox.pdmodel.font;
import java.awt.Font;
import java.awt.FontFormatException;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -96,6 +93,10 @@ public class PDType1CFont extends PDSimp
private static final byte[] SPACE_BYTES = {(byte)32};
+ private COSDictionary descendantDescriptor = null;
+ private COSDictionary fontDescriptor = null;
+ private COSDictionary fontDict = null;
+
/**
* Constructor.
* @param fontDictionary the corresponding dictionary
@@ -103,7 +104,22 @@ public class PDType1CFont extends PDSimp
public PDType1CFont( COSDictionary fontDictionary ) throws IOException
{
super( fontDictionary );
-
+ fontDict = fontDictionary;
+ fontDescriptor = (COSDictionary)fontDict.getDictionaryObject(COSName.FONT_DESC);
+ if (fontDescriptor == null)
+ {
+ fontDescriptor = fontDict;
+ }
+ COSArray descendantFontArray =
+ (COSArray)fontDescriptor.getDictionaryObject( COSName.DESCENDANT_FONTS );
+ if (descendantFontArray != null)
+ {
+ descendantDescriptor = (COSDictionary)descendantFontArray.getObject( 0 );
+ if (descendantDescriptor != null)
+ {
+ descendantDescriptor = (COSDictionary)descendantDescriptor.getDictionaryObject( COSName.FONT_DESC );
+ }
+ }
load();
}
@@ -387,10 +403,13 @@ public class PDType1CFont extends PDSimp
private byte[] loadBytes() throws IOException
{
- COSDictionary fontDic = (COSDictionary)super.font.getDictionaryObject(COSName.FONT_DESC);
- if( fontDic != null )
+ if( fontDescriptor != null )
{
- COSStream ff3Stream = (COSStream)fontDic.getDictionaryObject("FontFile3");
+ COSStream ff3Stream = (COSStream)fontDescriptor.getDictionaryObject(COSName.FONT_FILE3);
+ if( ff3Stream == null )
+ {
+ ff3Stream = (COSStream)descendantDescriptor.getDictionaryObject(COSName.FONT_FILE3);
+ }
if( ff3Stream != null )
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -424,7 +443,7 @@ public class PDType1CFont extends PDSimp
private Map<Integer,String> loadOverride() throws IOException
{
Map<Integer,String> result = new LinkedHashMap<Integer,String>();
- COSBase encoding = super.font.getDictionaryObject(COSName.ENCODING);
+ COSBase encoding = descendantDescriptor != null ? descendantDescriptor.getDictionaryObject(COSName.ENCODING) : fontDict.getDictionaryObject(COSName.ENCODING);
if( encoding instanceof COSName )
{
COSName name = (COSName)encoding;
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=953431&r1=953430&r2=953431&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Thu Jun 10 19:49:59 2010
@@ -102,17 +102,7 @@ public class PDType1Font extends PDSimpl
*/
public static final PDType1Font ZAPF_DINGBATS = new PDType1Font( "ZapfDingbats" );
- /**
- * Hardcoded copy of the Font.TYPE1_FONT constant in Java 5. PDFBox should
- * compile and work also with Java 1.4, so we can't rely on Java 5 features
- * being always available. The code that uses this constant will fail
- * gracefully if support for Type 1 fonts are not available.
- *
- * @see <a href="https://issues.apache.org/jira/browse/PDFBOX-379">PDFBOX-379</a>
- */
- private static final int TYPE1_FONT = 1;
-
- private static final Map STANDARD_14 = new HashMap();
+ private static final Map<String, PDType1Font> STANDARD_14 = new HashMap<String, PDType1Font>();
static
{
STANDARD_14.put( TIMES_ROMAN.getBaseFont(), TIMES_ROMAN );
@@ -197,25 +187,37 @@ public class PDType1Font extends PDSimpl
if (fd != null && fd instanceof PDFontDescriptorDictionary)
{
PDFontDescriptorDictionary fdDictionary = (PDFontDescriptorDictionary)fd;
- PDStream ffStream = fdDictionary.getFontFile();
- if( ffStream == null && fdDictionary.getFontFile3() != null)
+ if( fdDictionary.getFontFile() != null )
{
- // TODO FontFile3-streams containing CIDFontType0C or OpenType fonts aren't yet supported
- log.info("Embedded font-type is not supported " + fd.getFontName() );
+ try
+ {
+ // create a type1 font with the embedded data
+ awtFont = Font.createFont( Font.TYPE1_FONT, fdDictionary.getFontFile().createInputStream() );
+ }
+ catch (FontFormatException e)
+ {
+ log.info("Can't read the embedded type1 font " + fd.getFontName() );
+ }
}
- if( ffStream != null )
+ else if ( fdDictionary.getFontFile2() != null)
{
try
{
- // create a font with the embedded data
- awtFont = Font.createFont( TYPE1_FONT, ffStream.createInputStream() );
+ // create a true type font with the embedded data
+ awtFont = Font.createFont( Font.TRUETYPE_FONT, fdDictionary.getFontFile2().createInputStream() );
}
catch (FontFormatException e)
{
- log.info("Can't read the embedded font " + fd.getFontName() );
+ log.info("Can't read the embedded true type font " + fd.getFontName() );
}
}
- else
+ else if( fdDictionary.getFontFile3() != null)
+ {
+ PDType1CFont type1CFont = new PDType1CFont( super.font );
+ awtFont = type1CFont.getawtFont();
+ }
+
+ if (awtFont == null)
{
// check if the font is part of our environment
awtFont = FontManager.getAwtFont(fd.getFontName());
@@ -243,5 +245,5 @@ public class PDType1Font extends PDSimpl
}
return awtFont;
}
-
+
}