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 2012/03/04 15:44:39 UTC
svn commit: r1296818 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdfviewer/
pdmodel/font/ util/
Author: lehmi
Date: Sun Mar 4 14:44:39 2012
New Revision: 1296818
URL: http://svn.apache.org/viewvc?rev=1296818&view=rev
Log:
PDFBOX-1216: use glyphs and the correct encoding to draw the text
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/TextPosition.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java Sun Mar 4 14:44:39 2012
@@ -218,7 +218,7 @@ public class PageDrawer extends PDFStrea
graphics.setClip(graphicsState.getCurrentClippingPath());
// the fontSize is no longer needed as it is already part of the transformation
// we should remove it from the parameter list in the long run
- font.drawString( text.getCharacter(), graphics, 1, at, x, y );
+ font.drawString( text.getCharacter(), text.getCodePoints(), graphics, 1, at, x, y );
}
catch( IOException io )
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java Sun Mar 4 14:44:39 2012
@@ -91,6 +91,7 @@ public class PDCIDFontType2Font extends
{
LOG.info("Using font "+awtFont.getName()+ " instead");
}
+ setIsFontSubstituted(true);
}
}
// TODO FontFile3
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Sun Mar 4 14:44:39 2012
@@ -70,12 +70,12 @@ public abstract class PDFont implements
private Encoding fontEncoding = null;
/**
- * The descriptor of the font
+ * The descriptor of the font.
*/
private PDFontDescriptor fontDescriptor = null;
/**
- * The font matrix
+ * The font matrix.
*/
protected PDMatrix fontMatrix = null;
@@ -91,7 +91,7 @@ public abstract class PDFont implements
Collections.synchronizedMap( new HashMap<String, CMap>() );
/**
- * A list a floats representing the widths
+ * A list a floats representing the widths.
*/
private List<Float> widths = null;
@@ -206,7 +206,7 @@ public abstract class PDFont implements
}
else
{
- FontMetric afm = getAFM();
+ getAFM();
if( afm != null )
{
fontDescriptor = new PDFontDescriptorAFM( afm );
@@ -219,17 +219,17 @@ public abstract class PDFont implements
/**
* This will set the font descriptor.
*
- * @param fontDescriptor The font descriptor.
+ * @param fdDictionary The font descriptor.
*/
- public void setFontDescriptor( PDFontDescriptorDictionary fontDescriptor )
+ public void setFontDescriptor( PDFontDescriptorDictionary fdDictionary )
{
COSDictionary dic = null;
- if( fontDescriptor != null )
+ if( fdDictionary != null )
{
- dic = fontDescriptor.getCOSDictionary();
+ dic = fdDictionary.getCOSDictionary();
}
font.setItem( COSName.FONT_DESC, dic );
- this.fontDescriptor = fontDescriptor;
+ fontDescriptor = fdDictionary;
}
/**
@@ -308,16 +308,36 @@ public abstract class PDFont implements
* @param string The string to draw.
* @param g The graphics to draw onto.
* @param fontSize The size of the font to draw.
- * @param at The transformation matrix with all infos for scaling and shearing of the font.
+ * @param at The transformation matrix with all information for scaling and shearing of the font.
* @param x The x coordinate to draw at.
* @param y The y coordinate to draw at.
*
* @throws IOException If there is an error drawing the specific string.
+ * @deprecated use {@link PDFont#drawString(String, int[], Graphics, float, AffineTransform, float, float)} instead
*/
- public abstract void drawString( String string, Graphics g, float fontSize,
- AffineTransform at, float x, float y ) throws IOException;
+ public void drawString( String string, Graphics g, float fontSize, AffineTransform at, float x, float y )
+ throws IOException
+ {
+ drawString(string, null, g, fontSize, at, x, y);
+ }
/**
+ * This will draw a string on a canvas using the font.
+ *
+ * @param string The string to draw.
+ * @param codePoints The codePoints of the given string.
+ * @param g The graphics to draw onto.
+ * @param fontSize The size of the font to draw.
+ * @param at The transformation matrix with all information for scaling and shearing of the font.
+ * @param x The x coordinate to draw at.
+ * @param y The y coordinate to draw at.
+ *
+ * @throws IOException If there is an error drawing the specific string.
+ */
+ public abstract void drawString( String string, int[] codePoints, Graphics g, float fontSize,
+ AffineTransform at, float x, float y ) throws IOException;
+
+ /**
* Used for multibyte encodings.
*
* @param data The array of data.
@@ -326,7 +346,7 @@ public abstract class PDFont implements
*
* @return The int value of data from the array.
*/
- protected int getCodeFromArray( byte[] data, int offset, int length )
+ public int getCodeFromArray( byte[] data, int offset, int length )
{
int code = 0;
for( int i=0; i<length; i++ )
@@ -352,8 +372,7 @@ public abstract class PDFont implements
FontMetric metric = getAFM();
if( metric != null )
{
- Encoding encoding = getFontEncoding();
- String characterName = encoding.getName( code );
+ String characterName = fontEncoding.getName( code );
retval = metric.getCharacterWidth( characterName );
}
return retval;
@@ -422,7 +441,7 @@ public abstract class PDFont implements
* <pre>
* font.getDictionaryObject(COSName.ENCODING);
* </pre>
- * @return
+ * @return the encoding
*/
protected COSBase getEncoding()
{
@@ -437,10 +456,10 @@ public abstract class PDFont implements
* Set the encoding object from the fonts dictionary.
* @param encoding the given encoding.
*/
- protected void setEncoding(COSBase encoding)
+ protected void setEncoding(COSBase encodingValue)
{
- font.setItem( COSName.ENCODING, encoding );
- this.encoding = encoding;
+ font.setItem( COSName.ENCODING, encodingValue );
+ encoding = encodingValue;
}
/**
@@ -451,6 +470,7 @@ public abstract class PDFont implements
* @param isCIDFont indicates that the used font is a CID font.
*
* @return The value of the encoded character.
+ * @throws IOException if something went wrong
*/
protected String cmapEncoding( int code, int length, boolean isCIDFont ) throws IOException
{
@@ -488,10 +508,9 @@ public abstract class PDFont implements
// there is no cmap but probably an encoding with a suitable mapping
if( retval == null )
{
- Encoding encoding = getFontEncoding();
- if( encoding != null )
+ if( fontEncoding != null )
{
- retval = encoding.getCharacter( code );
+ retval = fontEncoding.getCharacter( code );
}
if( retval == null && (cmap == null || length == 2))
{
@@ -602,6 +621,7 @@ public abstract class PDFont implements
private boolean type1Font;
private boolean trueTypeFont;
private boolean typeFont;
+ private boolean type0Font;
/**
* This will get the subtype of font, Type1, Type3, ...
@@ -615,6 +635,7 @@ public abstract class PDFont implements
subtype = font.getNameAsString( COSName.SUBTYPE );
type1Font = "Type1".equals(subtype);
trueTypeFont = "TrueType".equals(subtype);
+ type0Font = "Type0".equals(subtype);
typeFont = type1Font || "Type0".equals(subtype) || trueTypeFont;
}
return subtype;
@@ -630,6 +651,16 @@ public abstract class PDFont implements
return type1Font;
}
+ /**
+ * Determines if the font is a type 0 font.
+ * @return returns true if the font is a type 0 font
+ */
+ protected boolean isType0Font()
+ {
+ getSubType();
+ return type0Font;
+ }
+
private boolean isTrueTypeFont()
{
getSubType();
@@ -725,10 +756,10 @@ public abstract class PDFont implements
*
* @param widths The widths of the character codes.
*/
- public void setWidths( List<Float> widths )
+ public void setWidths( List<Float> widthsList )
{
- this.widths = widths;
- font.setItem( COSName.WIDTHS, COSArrayList.converterToCOSArray( this.widths ) );
+ widths = widthsList;
+ font.setItem( COSName.WIDTHS, COSArrayList.converterToCOSArray( widths ) );
}
/**
@@ -798,8 +829,8 @@ public abstract class PDFont implements
int lastChar = getLastChar();
if (charCode >= firstChar && charCode <= lastChar)
{
- List<Float> widths = getWidths();
// maybe the font doesn't provide any widths
+ getWidths();
if (widths != null)
{
width = widths.get(charCode-firstChar).floatValue();
@@ -829,15 +860,9 @@ public abstract class PDFont implements
* Sets hasToUnicode to the given value.
* @param hasToUnicode the given value for hasToUnicode
*/
- protected void setHasToUnicode(boolean hasToUnicode)
- {
- this.hasToUnicode = hasToUnicode;
- }
-
- public COSString createString(String text) throws IOException
+ protected void setHasToUnicode(boolean hasToUnicodeValue)
{
- return new COSString(text);
-
+ hasToUnicode = hasToUnicodeValue;
}
}
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=1296818&r1=1296817&r2=1296818&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 Sun Mar 4 14:44:39 2012
@@ -20,6 +20,8 @@ import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.NoninvertibleTransformException;
@@ -97,24 +99,48 @@ public abstract class PDSimpleFont exten
/**
* {@inheritDoc}
*/
- public void drawString( String string, Graphics g, float fontSize,
+ public void drawString( String string, int[] codePoints, Graphics g, float fontSize,
AffineTransform at, float x, float y ) throws IOException
{
Font awtFont = getawtFont();
-
- // mdavis - fix fontmanager.so/dll on sun.font.FileFont.getGlyphImage
- // for font with bad cmaps?
- // Type1 fonts are not affected as they don't have cmaps
- if (!isType1Font() && awtFont.canDisplayUpTo(string) != -1)
- {
- LOG.warn("Changing font on <" + string + "> from <"
- + awtFont.getName() + "> to the default font");
- awtFont = Font.decode(null);
+ FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
+ GlyphVector glyphs = null;
+ boolean useCodepoints = codePoints != null && isType0Font();
+ PDFont descendantFont = useCodepoints ? ((PDType0Font)this).getDescendantFont() : null;
+ // symbolic fonts may trigger the same fontmanager.so/dll error as described below
+ if (useCodepoints && !descendantFont.getFontDescriptor().isSymbolic())
+ {
+ PDCIDFontType2Font cid2Font = null;
+ if (descendantFont instanceof PDCIDFontType2Font)
+ {
+ cid2Font = (PDCIDFontType2Font)descendantFont;
+ }
+ if((cid2Font != null && cid2Font.hasCIDToGIDMap()) || isFontSubstituted)
+ {
+ // we still have to use the string if a CIDToGIDMap is used
+ glyphs = awtFont.createGlyphVector(frc, string);
+ }
+ else
+ {
+ glyphs = awtFont.createGlyphVector(frc, codePoints);
+ }
+ }
+ else
+ {
+ // mdavis - fix fontmanager.so/dll on sun.font.FileFont.getGlyphImage
+ // for font with bad cmaps?
+ // Type1 fonts are not affected as they don't have cmaps
+ if (!isType1Font() && awtFont.canDisplayUpTo(string) != -1)
+ {
+ LOG.warn("Changing font on <" + string + "> from <"
+ + awtFont.getName() + "> to the default font");
+ awtFont = Font.decode(null).deriveFont(1f);
+ }
+ glyphs = awtFont.createGlyphVector(frc, string);
}
-
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
- writeFont(g2d, at, awtFont, x, y, string);
+ writeFont(g2d, at, x, y, glyphs);
}
/**
@@ -292,15 +318,14 @@ public abstract class PDSimpleFont exten
* This will draw a string on a canvas using the font.
*
* @param g2d The graphics to draw onto.
- * @param at The transformation matrix with all infos for scaling and shearing of the font.
- * @param awtFont The font to draw.
+ * @param at The transformation matrix with all information for scaling and shearing of the font.
* @param x The x coordinate to draw at.
* @param y The y coordinate to draw at.
- * @param string The string to draw.
+ * @param glyphs The GlyphVector containing the glyphs to be drawn.
*
*/
- protected void writeFont(final Graphics2D g2d, final AffineTransform at, final Font awtFont,
- final float x, final float y, final String string)
+ protected void writeFont(final Graphics2D g2d, final AffineTransform at,
+ final float x, final float y, final GlyphVector glyphs)
{
// check if we have a rotation
if (!at.isIdentity())
@@ -310,14 +335,13 @@ public abstract class PDSimpleFont exten
AffineTransform atInv = at.createInverse();
// do only apply the size of the transform, rotation will be realized by rotating the graphics,
// otherwise the hp printers will not render the font
- g2d.setFont(awtFont.deriveFont(1f));
- // apply the inverse transformation to the graphics, which should be the same as applying the
+ // apply the transformation to the graphics, which should be the same as applying the
// transformation itself to the text
g2d.transform(at);
// translate the coordinates
Point2D.Float newXy = new Point2D.Float(x,y);
atInv.transform(new Point2D.Float( x, y), newXy);
- g2d.drawString( string, (float)newXy.getX(), (float)newXy.getY() );
+ g2d.drawGlyphVector(glyphs, (float)newXy.getX(), (float)newXy.getY() );
// restore the original transformation
g2d.transform(atInv);
}
@@ -328,8 +352,7 @@ public abstract class PDSimpleFont exten
}
else
{
- g2d.setFont( awtFont.deriveFont( at ) );
- g2d.drawString( string, x, y );
+ g2d.drawGlyphVector(glyphs, x, y);
}
}
@@ -459,4 +482,15 @@ public abstract class PDSimpleFont exten
}
}
}
+
+ private boolean isFontSubstituted = false;
+ protected boolean isFontSubstituted()
+ {
+ return isFontSubstituted;
+ }
+
+ protected void setIsFontSubstituted(boolean isSubstituted)
+ {
+ isFontSubstituted = isSubstituted;
+ }
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Sun Mar 4 14:44:39 2012
@@ -400,6 +400,7 @@ public class PDTrueTypeFont extends PDSi
{
log.info("Using font "+awtFont.getName()+ " instead");
}
+ setIsFontSubstituted(true);
}
}
else
@@ -429,6 +430,7 @@ public class PDTrueTypeFont extends PDSi
// we can't find anything, so we have to use the standard font
awtFont = FontManager.getStandardFont();
log.info("Using font "+awtFont.getName()+ " instead");
+ setIsFontSubstituted(true);
}
}
return awtFont;
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Sun Mar 4 14:44:39 2012
@@ -40,10 +40,10 @@ public class PDType0Font extends PDSimpl
/**
* Log instance.
*/
- private static final Log log = LogFactory.getLog(PDType0Font.class);
+ private static final Log LOG = LogFactory.getLog(PDType0Font.class);
private COSArray descendantFontArray;
- private PDFont descendentFont;
+ private PDFont descendantFont;
private COSDictionary descendantFontDictionary;
private Font awtFont;
/**
@@ -68,11 +68,11 @@ public class PDType0Font extends PDSimpl
{
try
{
- descendentFont = PDFontFactory.createFont( descendantFontDictionary );
+ descendantFont = PDFontFactory.createFont( descendantFontDictionary );
}
catch (IOException exception)
{
- log.error("Error while creating the descendant font!");
+ LOG.error("Error while creating the descendant font!");
}
}
}
@@ -84,14 +84,16 @@ public class PDType0Font extends PDSimpl
{
if (awtFont == null)
{
- if (descendentFont != null)
+ if (descendantFont != null)
{
- awtFont = ((PDSimpleFont)descendentFont).getawtFont();
+ awtFont = ((PDSimpleFont)descendantFont).getawtFont();
}
if (awtFont == null)
{
awtFont = FontManager.getStandardFont();
- log.info("Using font "+awtFont.getName()+ " instead of "+descendentFont.getFontDescriptor().getFontName());
+ LOG.info("Using font "+awtFont.getName()
+ + " instead of "+descendantFont.getFontDescriptor().getFontName());
+ setIsFontSubstituted(true);
}
}
return awtFont;
@@ -122,7 +124,7 @@ public class PDType0Font extends PDSimpl
*/
public float getFontWidth( byte[] c, int offset, int length ) throws IOException
{
- return descendentFont.getFontWidth( c, offset, length );
+ return descendantFont.getFontWidth( c, offset, length );
}
/**
@@ -138,7 +140,7 @@ public class PDType0Font extends PDSimpl
*/
public float getFontHeight( byte[] c, int offset, int length ) throws IOException
{
- return descendentFont.getFontHeight( c, offset, length );
+ return descendantFont.getFontHeight( c, offset, length );
}
/**
@@ -150,7 +152,7 @@ public class PDType0Font extends PDSimpl
*/
public float getAverageFontWidth() throws IOException
{
- return descendentFont.getAverageFontWidth();
+ return descendantFont.getAverageFontWidth();
}
private COSArray getDescendantFonts()
@@ -167,7 +169,7 @@ public class PDType0Font extends PDSimpl
*/
public float getFontWidth( int charCode )
{
- return descendentFont.getFontWidth(charCode);
+ return descendantFont.getFontWidth(charCode);
}
@Override
@@ -182,9 +184,20 @@ public class PDType0Font extends PDSimpl
int result = cmap.lookupCID(c, offset, length);
if (result != -1)
{
- return descendentFont.cmapEncoding(result, 2, true);
+ return descendantFont.cmapEncoding(result, 2, true);
}
return null;
}
}
+
+ /**
+ *
+ * Provides the descendant font.
+ * @return the descendant font.
+ *
+ */
+ protected PDFont getDescendantFont()
+ {
+ return descendantFont;
+ }
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Sun Mar 4 14:44:39 2012
@@ -39,7 +39,7 @@ import java.util.Map;
public class PDType3Font extends PDSimpleFont
{
//A map of character code to java.awt.Image for the glyph
- private Map images = new HashMap();
+ private Map<Character, Image> images = new HashMap<Character, Image>();
/**
* Constructor.
@@ -92,26 +92,23 @@ public class PDType3Font extends PDSimpl
/**
* {@inheritDoc}
*/
- public void drawString( String string, Graphics g, float fontSize, AffineTransform at, float x, float y )
+ public void drawString( String string, int[] codePoints, Graphics g, float fontSize, AffineTransform at, float x, float y )
throws IOException
{
- //if( string.equals( "V" )|| string.equals( "o" ) )
+ for(int i=0; i<string.length(); i++)
{
- for(int i=0; i<string.length(); i++)
+ //todo need to use image observers and such
+ char c = string.charAt( i );
+ Image image = createImageIfNecessary( c );
+ if( image != null )
{
- //todo need to use image observers and such
- char c = string.charAt( i );
- Image image = createImageIfNecessary( c );
- if( image != null )
+ int newWidth = (int)(.12*image.getWidth(null));
+ int newHeight = (int)(.12*image.getHeight(null));
+ if( newWidth > 0 && newHeight > 0 )
{
- int newWidth = (int)(.12*image.getWidth(null));
- int newHeight = (int)(.12*image.getHeight(null));
- if( newWidth > 0 && newHeight > 0 )
- {
- image = image.getScaledInstance( newWidth, newHeight, Image.SCALE_SMOOTH );
- g.drawImage( image, (int)x, (int)y, null );
- x+=newWidth;
- }
+ image = image.getScaledInstance( newWidth, newHeight, Image.SCALE_SMOOTH );
+ g.drawImage( image, (int)x, (int)y, null );
+ x+=newWidth;
}
}
}
@@ -124,6 +121,6 @@ public class PDType3Font extends PDSimpl
*/
public void setFontMatrix( PDMatrix matrix )
{
- font.setItem( "FontMatrix", matrix );
+ font.setItem( COSName.FONT_MATRIX, matrix );
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Sun Mar 4 14:44:39 2012
@@ -392,11 +392,13 @@ public class PDFStreamEngine
// Decode the value to a Unicode character
codeLength = 1;
String c = font.encode( string, i, codeLength );
+ int[] codePoints = null;
if( c == null && i+1<string.length)
{
//maybe a multibyte encoding
codeLength++;
c = font.encode( string, i, codeLength );
+ codePoints = new int[] {font.getCodeFromArray(string, i, codeLength)};
}
// the space width has to be transformed into display units
@@ -505,6 +507,7 @@ public class PDFStreamEngine
widthText,
spaceWidthDisp,
c,
+ codePoints,
font,
fontSizeText,
(int)(fontSizeText * textMatrix.getXScale())
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/TextPosition.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/TextPosition.java?rev=1296818&r1=1296817&r2=1296818&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/TextPosition.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/TextPosition.java Sun Mar 4 14:44:39 2012
@@ -44,6 +44,7 @@ public class TextPosition
private float[] widths;
private float widthOfSpace; // width of a space, in display units
private String str;
+ private int[] unicodeCP;
private PDFont font;
private float fontSize;
private int fontSizePt;
@@ -148,7 +149,7 @@ public class TextPosition
{
this(pageRotation, pageWidthValue, pageHeightValue, textPositionSt,
textPositionEnd.getXPosition(), textPositionEnd.getYPosition(),
- maxFontH, individualWidth, spaceWidth, string, currentFont, fontSizeValue, fontSizeInPt);
+ maxFontH, individualWidth, spaceWidth, string, null, currentFont, fontSizeValue, fontSizeInPt);
}
/**
@@ -167,6 +168,9 @@ public class TextPosition
* @param currentFont The current for for this text position.
* @param fontSizeValue The new font size.
* @param fontSizeInPt The font size in pt units.
+ *
+ * @deprecated use {@link #TextPosition(int, float, float, Matrix, float, float, float, float, float,
+ * String, int[], PDFont, float, int)} insetad
*/
public TextPosition(
int pageRotation,
@@ -184,6 +188,44 @@ public class TextPosition
int fontSizeInPt
)
{
+ this(pageRotation, pageWidthValue, pageHeightValue, textPositionSt, endXValue, endYValue,
+ maxFontH, individualWidth, spaceWidth, string, null, currentFont, fontSizeValue, fontSizeInPt);
+ }
+ /**
+ * Constructor.
+ *
+ * @param pageRotation rotation of the page that the text is located in
+ * @param pageWidthValue rotation of the page that the text is located in
+ * @param pageHeightValue rotation of the page that the text is located in
+ * @param textPositionSt TextMatrix for start of text (in display units)
+ * @param endXValue x coordinate of the end position
+ * @param endYValue y coordinate of the end position
+ * @param maxFontH Maximum height of text (in display units)
+ * @param individualWidth The width of the given character/string. (in ? units)
+ * @param spaceWidth The width of the space character. (in display units)
+ * @param string The character to be displayed.
+ * @param codePoints An array containing the codepoints of the given string.
+ * @param currentFont The current font for this text position.
+ * @param fontSizeValue The new font size.
+ * @param fontSizeInPt The font size in pt units.
+ */
+ public TextPosition(
+ int pageRotation,
+ float pageWidthValue,
+ float pageHeightValue,
+ Matrix textPositionSt,
+ float endXValue,
+ float endYValue,
+ float maxFontH,
+ float individualWidth,
+ float spaceWidth,
+ String string,
+ int[] codePoints,
+ PDFont currentFont,
+ float fontSizeValue,
+ int fontSizeInPt
+ )
+ {
this.textPos = textPositionSt;
this.endX = endXValue;
@@ -203,6 +245,7 @@ public class TextPosition
this.widths = new float[]{individualWidth};
this.widthOfSpace = spaceWidth;
this.str = string;
+ this.unicodeCP = codePoints;
this.font = currentFont;
this.fontSize = fontSizeValue;
this.fontSizePt = fontSizeInPt;
@@ -219,6 +262,16 @@ public class TextPosition
}
/**
+ * Return the codepoints of the characters stored in this object.
+ *
+ * @return an array containing all codepoints.
+ */
+ public int[] getCodePoints()
+ {
+ return unicodeCP;
+ }
+
+ /**
* Return the Matrix textPos stored in this object.
*
* @return The Matrix containing all infos of the starting textposition