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 2009/07/28 20:25:33 UTC
svn commit: r798640 [1/2] - in
/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox:
pdmodel/graphics/color/ pdmodel/graphics/xobject/ persistence/util/ util/
Author: lehmi
Date: Tue Jul 28 18:25:32 2009
New Revision: 798640
URL: http://svn.apache.org/viewvc?rev=798640&view=rev
Log:
PDFBOX-464: reestablish checkstyle compliance
Modified:
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCMYK.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCalRGB.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalRGB.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/persistence/util/COSHEXTable.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/ICU4JImpl.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/Matrix.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFHighlighter.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFText2HTML.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextNormalize.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPosition.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPositionComparator.java
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCMYK.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCMYK.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCMYK.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCMYK.java Tue Jul 28 18:25:32 2009
@@ -26,112 +26,128 @@
*/
public class ColorSpaceCMYK extends ColorSpace
{
- /**
- * IDfor serialization
- */
- private static final long serialVersionUID = -6362864473145799405L;
-
- /**
- * Constructor
- */
- public ColorSpaceCMYK()
- {
- super(ColorSpace.TYPE_CMYK,4);
- }
-
- /**
- * Converts colorvalues from RGB-colorspace to CIEXYZ-colorspace
- * @param rgbvalue RGB colorvalues to be converted.
- * @return Returns converted colorvalues.
- */
- private float[] fromRGBtoCIEXYZ(float[] rgbvalue) {
- ColorSpace colorspaceRGB = ColorSpace.getInstance(CS_sRGB);
- return colorspaceRGB.toCIEXYZ(rgbvalue);
- }
-
- /**
- * Converts colorvalues from CIEXYZ-colorspace to RGB-colorspace
- * @param rgbvalue CIEXYZ colorvalues to be converted.
- * @return Returns converted colorvalues.
- */
- private float[] fromCIEXYZtoRGB(float[] xyzvalue) {
- ColorSpace colorspaceXYZ = ColorSpace.getInstance(CS_CIEXYZ);
- return colorspaceXYZ.toRGB(xyzvalue);
- }
+ /**
+ * IDfor serialization.
+ */
+ private static final long serialVersionUID = -6362864473145799405L;
+
+ /**
+ * Constructor.
+ */
+ public ColorSpaceCMYK()
+ {
+ super(ColorSpace.TYPE_CMYK,4);
+ }
+
+ /**
+ * Converts colorvalues from RGB-colorspace to CIEXYZ-colorspace.
+ * @param rgbvalue RGB colorvalues to be converted.
+ * @return Returns converted colorvalues.
+ */
+ private float[] fromRGBtoCIEXYZ(float[] rgbvalue)
+ {
+ ColorSpace colorspaceRGB = ColorSpace.getInstance(CS_sRGB);
+ return colorspaceRGB.toCIEXYZ(rgbvalue);
+ }
+
+ /**
+ * Converts colorvalues from CIEXYZ-colorspace to RGB-colorspace.
+ * @param rgbvalue CIEXYZ colorvalues to be converted.
+ * @return Returns converted colorvalues.
+ */
+ private float[] fromCIEXYZtoRGB(float[] xyzvalue)
+ {
+ ColorSpace colorspaceXYZ = ColorSpace.getInstance(CS_CIEXYZ);
+ return colorspaceXYZ.toRGB(xyzvalue);
+ }
/**
* {@inheritDoc}
*/
- public float[] fromCIEXYZ(float[] colorvalue) {
- if (colorvalue != null && colorvalue.length == 3)
- // We have to convert from XYV to RGB to CMYK
- return fromRGB(fromCIEXYZtoRGB(colorvalue));
- else
- return null;
- }
+ public float[] fromCIEXYZ(float[] colorvalue)
+ {
+ if (colorvalue != null && colorvalue.length == 3)
+ {
+ // We have to convert from XYV to RGB to CMYK
+ return fromRGB(fromCIEXYZtoRGB(colorvalue));
+ }
+ return null;
+ }
/**
* {@inheritDoc}
*/
- public float[] fromRGB(float[] rgbvalue) {
- if (rgbvalue != null && rgbvalue.length == 3) {
- // First of all we have to convert from RGB to CMY
- float c = 1 - rgbvalue[0];
- float m = 1 - rgbvalue[1];
- float y = 1 - rgbvalue[2];
- // Now we have to convert from CMY to CMYK
- float var_K = 1;
- float[] cmyk = new float[4];
- if ( c < var_K )
- var_K = c;
- if ( m < var_K )
- var_K = m;
- if ( y < var_K )
- var_K = y;
- if ( var_K == 1 ) {
- cmyk[0] = cmyk[1] = cmyk[2] = 0;
- }
- else {
- cmyk[0] = ( c - var_K ) / ( 1 - var_K );
- cmyk[1] = ( m - var_K ) / ( 1 - var_K );
- cmyk[2] = ( y - var_K ) / ( 1 - var_K );
- }
- cmyk[3] = var_K;
- return cmyk;
- }
- else
- return null;
- }
+ public float[] fromRGB(float[] rgbvalue)
+ {
+ if (rgbvalue != null && rgbvalue.length == 3)
+ {
+ // First of all we have to convert from RGB to CMY
+ float c = 1 - rgbvalue[0];
+ float m = 1 - rgbvalue[1];
+ float y = 1 - rgbvalue[2];
+ // Now we have to convert from CMY to CMYK
+ float varK = 1;
+ float[] cmyk = new float[4];
+ if ( c < varK )
+ {
+ varK = c;
+ }
+ if ( m < varK )
+ {
+ varK = m;
+ }
+ if ( y < varK )
+ {
+ varK = y;
+ }
+ if ( varK == 1 )
+ {
+ cmyk[0] = cmyk[1] = cmyk[2] = 0;
+ }
+ else
+ {
+ cmyk[0] = ( c - varK ) / ( 1 - varK );
+ cmyk[1] = ( m - varK ) / ( 1 - varK );
+ cmyk[2] = ( y - varK ) / ( 1 - varK );
+ }
+ cmyk[3] = varK;
+ return cmyk;
+ }
+ return null;
+ }
/**
* {@inheritDoc}
*/
- public float[] toCIEXYZ(float[] colorvalue) {
- if (colorvalue != null && colorvalue.length == 4)
- // We have to convert from CMYK to RGB to XYV
- return fromRGBtoCIEXYZ(toRGB(colorvalue));
- else
- return null;
- }
+ public float[] toCIEXYZ(float[] colorvalue)
+ {
+ if (colorvalue != null && colorvalue.length == 4)
+ {
+ // We have to convert from CMYK to RGB to XYV
+ return fromRGBtoCIEXYZ(toRGB(colorvalue));
+ }
+ return null;
+ }
/**
* {@inheritDoc}
*/
- public float[] toRGB(float[] colorvalue) {
- if (colorvalue != null && colorvalue.length == 4) {
- // First of all we have to convert from CMYK to CMY
- float c = ( colorvalue[0] * ( 1 - colorvalue[3] ) + colorvalue[3] );
- float m = ( colorvalue[1] * ( 1 - colorvalue[3] ) + colorvalue[3] );
- float y = ( colorvalue[2] * ( 1 - colorvalue[3] ) + colorvalue[3] );
- // Now we have to convert from CMY to RGB
- float[] rgbvalues = new float[3];
- rgbvalues[0] = 1 - c;
- rgbvalues[1] = 1 - m;
- rgbvalues[2] = 1 - y;
- return rgbvalues;
- }
- else
- return null;
- }
+ public float[] toRGB(float[] colorvalue)
+ {
+ if (colorvalue != null && colorvalue.length == 4)
+ {
+ // First of all we have to convert from CMYK to CMY
+ float c = ( colorvalue[0] * ( 1 - colorvalue[3] ) + colorvalue[3] );
+ float m = ( colorvalue[1] * ( 1 - colorvalue[3] ) + colorvalue[3] );
+ float y = ( colorvalue[2] * ( 1 - colorvalue[3] ) + colorvalue[3] );
+ // Now we have to convert from CMY to RGB
+ float[] rgbvalues = new float[3];
+ rgbvalues[0] = 1 - c;
+ rgbvalues[1] = 1 - m;
+ rgbvalues[2] = 1 - y;
+ return rgbvalues;
+ }
+ return null;
+ }
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCalRGB.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCalRGB.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCalRGB.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCalRGB.java Tue Jul 28 18:25:32 2009
@@ -33,98 +33,110 @@
*/
public class ColorSpaceCalRGB extends ColorSpace
{
- private PDGamma gamma = null;
- private PDTristimulus whitepoint = null;
- private PDTristimulus blackpoint = null;
- private PDMatrix matrix = null;
-
- /**
- * IDfor serialization
- */
- private static final long serialVersionUID = -6362864473145799405L;
-
- /**
- * Constructor
- */
- public ColorSpaceCalRGB()
- {
- super(ColorSpace.TYPE_3CLR,3);
- }
-
- /**
- * Constructor
- */
- public ColorSpaceCalRGB(PDGamma gamma, PDTristimulus whitepoint, PDTristimulus blackpoint, PDMatrix matrix)
- {
- this();
- this.gamma = gamma;
- this.whitepoint = whitepoint;
- this.blackpoint = blackpoint;
- this.matrix = matrix;
- }
-
- /**
- * Converts colorvalues from RGB-colorspace to CIEXYZ-colorspace
- * @param rgbvalue RGB colorvalues to be converted.
- * @return Returns converted colorvalues.
- */
- private float[] fromRGBtoCIEXYZ(float[] rgbvalue) {
- ColorSpace colorspaceRGB = ColorSpace.getInstance(CS_sRGB);
- return colorspaceRGB.toCIEXYZ(rgbvalue);
- }
-
- /**
- * Converts colorvalues from CIEXYZ-colorspace to RGB-colorspace
- * @param rgbvalue CIEXYZ colorvalues to be converted.
- * @return Returns converted colorvalues.
- */
- private float[] fromCIEXYZtoRGB(float[] xyzvalue) {
- ColorSpace colorspaceXYZ = ColorSpace.getInstance(CS_CIEXYZ);
- return colorspaceXYZ.toRGB(xyzvalue);
- }
+ private PDGamma gamma = null;
+ private PDTristimulus whitepoint = null;
+ private PDTristimulus blackpoint = null;
+ private PDMatrix matrix = null;
+
+ /**
+ * ID for serialization.
+ */
+ private static final long serialVersionUID = -6362864473145799405L;
+
+ /**
+ * Constructor.
+ */
+ public ColorSpaceCalRGB()
+ {
+ super(ColorSpace.TYPE_3CLR,3);
+ }
+
+ /**
+ * Constructor.
+ * @param gammaValue Gamma
+ * @param whitept Whitepoint
+ * @param blackpt Blackpoint
+ * @param linearMatrix Matrix value
+ */
+ public ColorSpaceCalRGB(PDGamma gammaValue, PDTristimulus whitept, PDTristimulus blackpt, PDMatrix linearMatrix)
+ {
+ this();
+ this.gamma = gammaValue;
+ this.whitepoint = whitept;
+ this.blackpoint = blackpt;
+ this.matrix = linearMatrix;
+ }
+
+ /**
+ * Converts colorvalues from RGB-colorspace to CIEXYZ-colorspace.
+ * @param rgbvalue RGB colorvalues to be converted.
+ * @return Returns converted colorvalues.
+ */
+ private float[] fromRGBtoCIEXYZ(float[] rgbvalue)
+ {
+ ColorSpace colorspaceRGB = ColorSpace.getInstance(CS_sRGB);
+ return colorspaceRGB.toCIEXYZ(rgbvalue);
+ }
+
+ /**
+ * Converts colorvalues from CIEXYZ-colorspace to RGB-colorspace.
+ * @param rgbvalue CIEXYZ colorvalues to be converted.
+ * @return Returns converted colorvalues.
+ */
+ private float[] fromCIEXYZtoRGB(float[] xyzvalue)
+ {
+ ColorSpace colorspaceXYZ = ColorSpace.getInstance(CS_CIEXYZ);
+ return colorspaceXYZ.toRGB(xyzvalue);
+ }
/**
* {@inheritDoc}
*/
- public float[] fromCIEXYZ(float[] colorvalue) {
- if (colorvalue != null && colorvalue.length == 3)
- // We have to convert from XYV to RGB
- return fromCIEXYZtoRGB(colorvalue);
- else
- return null;
- }
+ public float[] fromCIEXYZ(float[] colorvalue)
+ {
+ if (colorvalue != null && colorvalue.length == 3)
+ {
+ // We have to convert from XYV to RGB
+ return fromCIEXYZtoRGB(colorvalue);
+ }
+ return null;
+ }
/**
* {@inheritDoc}
*/
- public float[] fromRGB(float[] rgbvalue) {
- if (rgbvalue != null && rgbvalue.length == 3) {
- return rgbvalue;
- }
- else
- return null;
- }
+ public float[] fromRGB(float[] rgbvalue)
+ {
+ if (rgbvalue != null && rgbvalue.length == 3)
+ {
+ return rgbvalue;
+ }
+ return null;
+ }
/**
* {@inheritDoc}
*/
- public float[] toCIEXYZ(float[] colorvalue) {
- if (colorvalue != null && colorvalue.length == 4)
- // We have to convert from RGB to XYV
- return fromRGBtoCIEXYZ(toRGB(colorvalue));
- else
- return null;
- }
+ public float[] toCIEXYZ(float[] colorvalue)
+ {
+ if (colorvalue != null && colorvalue.length == 4)
+ {
+ // We have to convert from RGB to XYV
+ return fromRGBtoCIEXYZ(toRGB(colorvalue));
+ }
+ return null;
+ }
/**
* {@inheritDoc}
*/
- public float[] toRGB(float[] colorvalue) {
- if (colorvalue != null && colorvalue.length == 3) {
- return colorvalue;
- }
- else
- return null;
- }
+ public float[] toRGB(float[] colorvalue)
+ {
+ if (colorvalue != null && colorvalue.length == 3)
+ {
+ return colorvalue;
+ }
+ return null;
+ }
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalRGB.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalRGB.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalRGB.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDCalRGB.java Tue Jul 28 18:25:32 2009
@@ -99,9 +99,11 @@
*/
public ColorSpace createColorSpace() throws IOException
{
- if (cSpace == null)
- cSpace = new ColorSpaceCalRGB(getGamma(),getWhitepoint(),getBlackPoint(),getLinearInterpretation());
- return cSpace;
+ if (cSpace == null)
+ {
+ cSpace = new ColorSpaceCalRGB(getGamma(),getWhitepoint(),getBlackPoint(),getLinearInterpretation());
+ }
+ return cSpace;
}
/**
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java Tue Jul 28 18:25:32 2009
@@ -37,7 +37,9 @@
*/
public abstract class PDColorSpace extends LoggingObject implements COSObjectable
{
-
+ /**
+ * array for the given parameters.
+ */
protected COSArray array;
/**
@@ -89,11 +91,11 @@
/*
Don't just tell me its color type -- tell me its contents!
*/
+ /**
+ * {@inheritDoc}
+ */
public String toString()
{
-
- String RetVal = getName() + "{ " + (array==null? "" : array.toString() ) + " }";
-
- return RetVal;
+ return getName() + "{ " + (array==null? "" : array.toString() ) + " }";
}
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceInstance.java Tue Jul 28 18:25:32 2009
@@ -19,7 +19,6 @@
import java.awt.Color;
import java.awt.color.ColorSpace;
import java.io.IOException;
-import java.lang.IllegalArgumentException;
import org.apache.pdfbox.exceptions.LoggingObject;
import org.apache.pdfbox.cos.COSArray;
@@ -65,8 +64,8 @@
{
Color retval = null;
float[] components = colorSpaceValue.toFloatArray();
- try{
-
+ try
+ {
if( colorSpace.getName().equals(PDDeviceRGB.NAME) && components.length == 3 )
{
//for some reason, when using RGB and the RGB colorspace
@@ -77,33 +76,36 @@
}
else
{
-
ColorSpace cs = colorSpace.createColorSpace();
-
- if (colorSpace.getName().equals(PDSeparation.NAME) && components.length == 1){
-
+ if (colorSpace.getName().equals(PDSeparation.NAME) && components.length == 1)
+ {
//Use that component as a single-integer RGB value
retval = new Color((int)components[0]);
}
- else{
+ else
+ {
retval = new Color( cs, components, 1f );
}
}
return retval;
- }catch (java.lang.IllegalArgumentException IAe){
- String Values = "Color Values: ";
- for(int i=0; i< components.length; i++){
- Values = Values + components[i] + "\t";
- }
-
- logger().severe(IAe.toString() + "\n" + Values + "\n at\n" + FullStackTrace(IAe));
-
- throw IAe;
- }catch (IOException IOe){
- logger().severe(IOe.toString() + "\n at\n" + FullStackTrace(IOe));
-
- throw IOe;
- }catch (Exception e){
+ }
+ catch (java.lang.IllegalArgumentException exception)
+ {
+ String values = "Color Values: ";
+ for(int i=0; i< components.length; i++)
+ {
+ values = values + components[i] + "\t";
+ }
+ logger().severe(exception.toString() + "\n" + values + "\n at\n" + FullStackTrace(exception));
+ throw exception;
+ }
+ catch (IOException ioexception)
+ {
+ logger().severe(ioexception.toString() + "\n at\n" + FullStackTrace(ioexception));
+ throw ioexception;
+ }
+ catch (Exception e)
+ {
logger().severe(e.toString() + "\n at\n" + FullStackTrace(e));
throw new IOException("Failed to Create Color");
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java Tue Jul 28 18:25:32 2009
@@ -20,15 +20,10 @@
import java.awt.image.ColorModel;
import java.io.IOException;
-
import java.awt.Transparency;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
-import java.io.InputStream;
-
-import org.apache.pdfbox.util.ResourceLoader;
-
/**
* This class represents a CMYK color space.
@@ -92,7 +87,9 @@
public ColorSpace createColorSpace() throws IOException
{
if( cSpace == null )
+ {
cSpace = new ColorSpaceCMYK();
+ }
return cSpace;
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java Tue Jul 28 18:25:32 2009
@@ -329,19 +329,21 @@
stream.getStream().setItem( COSName.getPDFName( "Metadata" ), metadata );
}
- /*
- Need more info on the ICCBased ones ... Array contains very little.
- */
+ // Need more info on the ICCBased ones ... Array contains very little.
+ /**
+ * {@inheritDoc}
+ */
public String toString()
{
-
- String RetVal = super.toString() + "\n\t Number of Components: " ;
- try{
- RetVal = RetVal + getNumberOfComponents();
- }catch (IOException IOe){
- RetVal = RetVal + IOe.toString();
- }
-
- return RetVal;
+ String retVal = super.toString() + "\n\t Number of Components: ";
+ try
+ {
+ retVal = retVal + getNumberOfComponents();
+ }
+ catch (IOException exception)
+ {
+ retVal = retVal + exception.toString();
+ }
+ return retVal;
}
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java Tue Jul 28 18:25:32 2009
@@ -94,9 +94,8 @@
*/
public ColorSpace createColorSpace() throws IOException
{
- //throw new IOException( "Not implemented" );
- try{
-
+ try
+ {
///dump some information to help figure these things out
//logger().info( array.toString());
@@ -104,16 +103,19 @@
//logger().info(alt.toString());
- ColorSpace CS = alt.createColorSpace();///dwilson 12/15/07
- //logger().info(CS.toString() + " reporting type " + CS.getType() + " and having component count of " + CS.getNumComponents());
+ ColorSpace colorspace = alt.createColorSpace();///dwilson 12/15/07
+
+ return colorspace;
+ }
+ catch (IOException ioexception)
+ {
+ logger().severe(ioexception.toString() + "\n at\n" + FullStackTrace(ioexception));
- return CS;
- }catch (IOException IOe){
- logger().severe(IOe.toString() + "\n at\n" + FullStackTrace(IOe));
-
- throw IOe;
- }catch (Exception e){
- logger().severe(e.toString() + "\n at\n" +FullStackTrace(e));
+ throw ioexception;
+ }
+ catch (Exception exception)
+ {
+ logger().severe(exception.toString() + "\n at\n" +FullStackTrace(exception));
throw new IOException("Failed to Create ColorSpace");
}
}
@@ -220,6 +222,11 @@
return (COSDictionary) array.getObject( 3);
}
+ /**
+ * Returns all colorvalues for this colorspace.
+ * @return COSArry with all colorvalues
+ * @throws IOException If there is an error getting the object from the dictionary
+ */
public COSArray getColorValues() throws IOException
{
return (COSArray) getDictionary().getDictionaryObject("C1");
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java Tue Jul 28 18:25:32 2009
@@ -107,16 +107,22 @@
InputStream tiff = new TiffWrapper(
getPDStream().getPartiallyFilteredStream( FAX_FILTERS ),
getCOSStream());
- try {
+ try
+ {
retval = ImageIO.read(tiff);
- }catch (Exception e){
- logger().severe(e.toString() + "\n at\n" + FullStackTrace(e));
- } finally {
- if (tiff != null)
- tiff.close();
-
- return retval;
}
+ catch (Exception e)
+ {
+ logger().severe(e.toString() + "\n at\n" + FullStackTrace(e));
+ }
+ finally
+ {
+ if (tiff != null)
+ {
+ tiff.close();
+ }
+ }
+ return retval;
}
/**
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpeg.java Tue Jul 28 18:25:32 2009
@@ -81,11 +81,12 @@
dic.setItem( COSName.TYPE, COSName.getPDFName( "XObject" ) );
BufferedImage image = getRGBImage();
- if (image != null) {
- setBitsPerComponent( 8 );
- setColorSpace( PDDeviceRGB.INSTANCE );
- setHeight( image.getHeight() );
- setWidth( image.getWidth() );
+ if (image != null)
+ {
+ setBitsPerComponent( 8 );
+ setColorSpace( PDDeviceRGB.INSTANCE );
+ setHeight( image.getHeight() );
+ setWidth( image.getWidth() );
}
}
@@ -132,23 +133,30 @@
File imgFile = null;
BufferedImage bi = null;
boolean readError = false;
- try {
+ try
+ {
imgFile = File.createTempFile("pdjpeg", ".jpeg");
write2file(imgFile);
// 1. try to read jpeg image
- try {
+ try
+ {
bi = ImageIO.read(imgFile);
- } catch (IIOException iioe) {
+ }
+ catch (IIOException iioe)
+ {
// cannot read jpeg
readError = true;
- } catch (Exception ignore) {}
+ }
+ catch (Exception ignore)
+ {}
// 2. try to read jpeg again. some jpegs have some strange header containing
// "Adobe " at some place. so just replace the header with a valid jpeg header.
- // TODO: not sure if it works for all cases
- if (bi == null && readError) {
- byte newImage[] = replaceHeader(imgFile);
+ // TODO : not sure if it works for all cases
+ if (bi == null && readError)
+ {
+ byte[] newImage = replaceHeader(imgFile);
ByteArrayInputStream bai = new ByteArrayInputStream(newImage);
@@ -157,7 +165,8 @@
FileOutputStream o = new FileOutputStream(imgFile);
byte[] buffer = new byte[512];
int read;
- while ((read=bai.read(buffer)) >0) {
+ while ((read=bai.read(buffer)) >0)
+ {
o.write(buffer, 0, read);
}
@@ -166,8 +175,11 @@
bi = ImageIO.read(imgFile);
}
- } finally {
- if (imgFile != null) {
+ }
+ finally
+ {
+ if (imgFile != null)
+ {
imgFile.delete();
}
}
@@ -189,11 +201,19 @@
}
}
- public static byte[] getBytesFromFile(File file) throws IOException {
+ /**
+ * Returns the given file as byte array.
+ * @param file File to be read
+ * @return given file as byte array
+ * @throws IOException if somethin went wrong during reading the file
+ */
+ public static byte[] getBytesFromFile(File file) throws IOException
+ {
InputStream is = new FileInputStream(file);
long length = file.length();
- if (length > Integer.MAX_VALUE) {
+ if (length > Integer.MAX_VALUE)
+ {
// File is too large
throw new IOException("File is tooo large");
}
@@ -206,42 +226,49 @@
int numRead = 0;
while (offset < bytes.length
- && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
+ && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
+ {
offset += numRead;
}
// Ensure all the bytes have been read in
- if (offset < bytes.length) {
+ if (offset < bytes.length)
+ {
throw new IOException("Could not completely read file "+file.getName());
}
-
is.close();
-
return bytes;
}
- private int getHeaderEndPos(byte[] image) {
- for (int i = 0; i < image.length; i++) {
+ private int getHeaderEndPos(byte[] image)
+ {
+ for (int i = 0; i < image.length; i++)
+ {
byte b = image[i];
- if (b == (byte) 0xDB) { // to do: check for ff db
+ if (b == (byte) 0xDB)
+ {
+ // TODO : check for ff db
return i -2;
}
}
return 0;
}
- private byte[] replaceHeader(File jpegFile) throws IOException {
+ private byte[] replaceHeader(File jpegFile) throws IOException
+ {
// read image into memory
- byte image[] = getBytesFromFile(jpegFile);
+ byte[] image = getBytesFromFile(jpegFile);
// get end position of wrong header respectively startposition of "real jpeg data"
int pos = getHeaderEndPos(image);
// simple correct header
- byte header[] = new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte) 0xE0, (byte) 0x00, (byte) 0x10, (byte) 0x4A, (byte) 0x46, (byte) 0x49, (byte) 0x46, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x60, (byte) 0x00, (byte) 0x60, (byte) 0x00, (byte) 0x00};
+ byte[] header = new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte) 0xE0, (byte) 0x00,
+ (byte) 0x10, (byte) 0x4A, (byte) 0x46, (byte) 0x49, (byte) 0x46, (byte) 0x00, (byte) 0x01,
+ (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x60, (byte) 0x00, (byte) 0x60, (byte) 0x00, (byte) 0x00};
// concat
- byte newImage[] = new byte[image.length - pos + header.length - 1];
+ byte[] newImage = new byte[image.length - pos + header.length - 1];
System.arraycopy(header, 0, newImage, 0, header.length);
System.arraycopy(image, pos + 1, newImage, header.length, image.length - pos - 1);
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java Tue Jul 28 18:25:32 2009
@@ -118,74 +118,78 @@
return image;
}
- try{
- int width = getWidth();
- int height = getHeight();
- int bpc = getBitsPerComponent();
- int predictor = getPredictor();
- List filters = getPDStream().getFilters();
- ColorModel cm ;
-
- byte[] array = getPDStream().getByteArray();
-
- //logger().info("array contains " + array.length + " bytes.\nUsing " + bpc + " bits per component.");
-
- // Get the ColorModel right
- PDColorSpace colorspace = getColorSpace();
- if (colorspace == null){
- logger().severe("getColorSpace() returned NULL. Predictor = " + getPredictor());
- return null;
- }
-
- if (bpc == 1){
- byte[] map = new byte[] {(byte)0x00, (byte)0xff};
- cm = new IndexColorModel(1, 2, map, map, map, 1);
- }else{
- cm = colorspace.createColorModel( bpc );
- }
-
- logger().info("ColorModel: " + cm.toString());
- WritableRaster raster = cm.createCompatibleWritableRaster( width, height );
- DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
- byte[] bufferData = buffer.getData();
-
- //logger().info("bufferData contains " + bufferData.length + " bytes.");
-
- /**
- * PDF Spec 1.6 3.3.3 LZW and Flate predictor function
- *
- * Basically if predictor > 10 and LZW or Flate is being used then the
- * predictor is not used.
- *
- * "For LZWDecode and FlateDecode, a Predictor value greater than or equal to 10
- * merely indicates that a PNG predictor is in use; the specific predictor function
- * used is explicitly encoded in the incoming data. The value of Predictor supplied
- * by the decoding filter need not match the value used when the data was encoded
- * if they are both greater than or equal to 10."
- */
- if( predictor < 10 ||
- filters == null || !(filters.contains( COSName.LZW_DECODE.getName()) ||
- filters.contains( COSName.FLATE_DECODE.getName()) ) )
+ try
{
- PredictorAlgorithm filter = PredictorAlgorithm.getFilter(predictor);
- filter.setWidth(width);
- filter.setHeight(height);
- filter.setBpp((bpc * 3) / 8);
- filter.decode(array, bufferData);
- }
- else
+ int width = getWidth();
+ int height = getHeight();
+ int bpc = getBitsPerComponent();
+ int predictor = getPredictor();
+ List filters = getPDStream().getFilters();
+ ColorModel cm;
+
+ byte[] array = getPDStream().getByteArray();
+
+ // Get the ColorModel right
+ PDColorSpace colorspace = getColorSpace();
+ if (colorspace == null)
+ {
+ logger().severe("getColorSpace() returned NULL. Predictor = " + getPredictor());
+ return null;
+ }
+
+ if (bpc == 1)
+ {
+ byte[] map = new byte[] {(byte)0x00, (byte)0xff};
+ cm = new IndexColorModel(1, 2, map, map, map, 1);
+ }
+ else
+ {
+ cm = colorspace.createColorModel( bpc );
+ }
+
+ logger().info("ColorModel: " + cm.toString());
+ WritableRaster raster = cm.createCompatibleWritableRaster( width, height );
+ DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
+ byte[] bufferData = buffer.getData();
+
+ /**
+ * PDF Spec 1.6 3.3.3 LZW and Flate predictor function
+ *
+ * Basically if predictor > 10 and LZW or Flate is being used then the
+ * predictor is not used.
+ *
+ * "For LZWDecode and FlateDecode, a Predictor value greater than or equal to 10
+ * merely indicates that a PNG predictor is in use; the specific predictor function
+ * used is explicitly encoded in the incoming data. The value of Predictor supplied
+ * by the decoding filter need not match the value used when the data was encoded
+ * if they are both greater than or equal to 10."
+ */
+ if( predictor < 10 ||
+ filters == null || !(filters.contains( COSName.LZW_DECODE.getName()) ||
+ filters.contains( COSName.FLATE_DECODE.getName()) ) )
+ {
+ PredictorAlgorithm filter = PredictorAlgorithm.getFilter(predictor);
+ filter.setWidth(width);
+ filter.setHeight(height);
+ filter.setBpp((bpc * 3) / 8);
+ filter.decode(array, bufferData);
+ }
+ else
+ {
+ System.arraycopy( array, 0,bufferData, 0,
+ (array.length<bufferData.length?array.length: bufferData.length) );
+ }
+ image = new BufferedImage(cm, raster, false, null);
+
+ return image;
+ }
+ catch (Exception exception)
{
- System.arraycopy( array, 0,bufferData, 0, (array.length<bufferData.length?array.length: bufferData.length) );
+ logger().severe(exception.toString() + "\n at\n" + FullStackTrace(exception));
+ //A NULL return is caught in pagedrawer.Invoke.process() so don't re-throw.
+ //Returning the NULL falls through to Phlip Koch's TODO section.
+ return null;
}
- image = new BufferedImage(cm, raster, false, null);
-
- return image;
- } catch (Exception IOe){
- logger().severe(IOe.toString() + "\n at\n" + FullStackTrace(IOe));
- //A NULL return is caught in pagedrawer.Invoke.process() so don't re-throw.
- //Returning the NULL falls through to Phlip Koch's TODO section.
- return null;
- }
}
/**
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java Tue Jul 28 18:25:32 2009
@@ -50,7 +50,7 @@
*/
private String suffix;
- protected PDGraphicsState graphicsState;
+ private PDGraphicsState graphicsState;
/**
* Standard constuctor.
@@ -218,7 +218,10 @@
if( cs != null )
{
retval = PDColorSpaceFactory.createColorSpace( cs );
- if (retval == null) logger().info("About to return NULL from createColorSpace branch");
+ if (retval == null)
+ {
+ logger().info("About to return NULL from createColorSpace branch");
+ }
}
else
{
@@ -229,15 +232,23 @@
COSName.CCITTFAX_DECODE_ABBREVIATION.equals( filter ) )
{
retval = new PDDeviceGray();
- if (retval == null) logger().info("About to return NULL from CCITT branch");
- }else if (getImageMask()){
- //Stencil Mask branch. Section 4.8.5 of the reference, page 350 in version 1.7.
- retval = graphicsState.getNonStrokingColorSpace().getColorSpace();
- logger().info("Stencil Mask branch returning " + retval.toString());
- //throw new IOException("Trace the Stencil Mask!!!!");
+ if (retval == null)
+ {
+ logger().info("About to return NULL from CCITT branch");
+ }
+ }
+ else if (getImageMask())
+ {
+ //Stencil Mask branch. Section 4.8.5 of the reference, page 350 in version 1.7.
+ retval = graphicsState.getNonStrokingColorSpace().getColorSpace();
+ logger().info("Stencil Mask branch returning " + retval.toString());
+ //throw new IOException("Trace the Stencil Mask!!!!");
- }else
- logger().info("About to return NULL from unhandled branch. filter = " + filter.toString());
+ }
+ else
+ {
+ logger().info("About to return NULL from unhandled branch. filter = " + filter.toString());
+ }
}
return retval;
}
@@ -278,9 +289,10 @@
}
/**
- * Allow the Invoke operator to set the graphics state so that, in the case of an Image Mask, we can get to the current nonstroking colorspace.
- *
- */
+ * Allow the Invoke operator to set the graphics state so that,
+ * in the case of an Image Mask, we can get to the current nonstroking colorspace.
+ * @param newGS The new graphicstate
+ */
public void setGraphicsState(PDGraphicsState newGS)
{
graphicsState = newGS;
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/persistence/util/COSHEXTable.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/persistence/util/COSHEXTable.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/persistence/util/COSHEXTable.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/persistence/util/COSHEXTable.java Tue Jul 28 18:25:32 2009
@@ -24,6 +24,9 @@
*/
public final class COSHEXTable
{
+ private COSHEXTable()
+ {
+ }
/**
* ASCII byte values for the hex strings.
*/
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/ICU4JImpl.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/ICU4JImpl.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/ICU4JImpl.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/ICU4JImpl.java Tue Jul 28 18:25:32 2009
@@ -22,11 +22,18 @@
/**
* This class is an implementation the the ICU4J class. TextNormalize
* will call this only if the ICU4J library exists in the classpath.
+ * @author <a href="mailto:carrier@digital-evidence.org">Brian Carrier</a>
+ * @version $Revision: 1.0 $
*/
-public class ICU4JImpl {
+public class ICU4JImpl
+{
Bidi bidi;
- public ICU4JImpl() {
+ /**
+ * Constructor.
+ */
+ public ICU4JImpl()
+ {
bidi = new Bidi();
/* We do not use bidi.setInverse() because that uses
@@ -44,9 +51,13 @@
* Takes a line of text in presentation order and converts it to logical order.
* @see TextNormalize.makeLineLogicalOrder(String, boolean)
*
+ * @param str String to convert
+ * @param isRtlDominant RTL (right-to-left) will be the dominant text direction
+ * @return The converted string
*/
- public String makeLineLogicalOrder(String a_str, boolean a_isRtlDominant) {
- bidi.setPara(a_str, a_isRtlDominant?Bidi.RTL:Bidi.LTR, null);
+ public String makeLineLogicalOrder(String str, boolean isRtlDominant)
+ {
+ bidi.setPara(str, isRtlDominant?Bidi.RTL:Bidi.LTR, null);
/* Set the mirror flag so that parentheses and other mirror symbols
* are properly reversed, when needed. With this removed, lines
@@ -60,27 +71,32 @@
* Normalize presentation forms of characters to the separate parts.
* @see TextNormalize.normalizePres(String)
*
- * @param a_str String to normalize
+ * @param str String to normalize
* @return Normalized form
*/
- public String normalizePres(String a_str) {
+ public String normalizePres(String str)
+ {
String retStr = "";
- for (int i = 0; i < a_str.length(); i++) {
+ for (int i = 0; i < str.length(); i++)
+ {
/* We only normalize if the codepoint is in a given range. Otherwise,
* NFKC converts too many things that would cause confusion. For example,
* it converts the micro symbol in extended latin to the value in the greek
* script. We normalize the Unicode Alphabetic and Arabic A&B Presentation forms.
*/
- char c = a_str.charAt(i);
+ char c = str.charAt(i);
if (((c >= 0xFB00) && (c <= 0xFDFF)) ||
- ((c >= 0xFE70) && (c <= 0xFEFF))) {
+ ((c >= 0xFE70) && (c <= 0xFEFF)))
+ {
/* Some fonts map U+FDF2 differently than the Unicode spec.
* They add an extra U+0627 character to compensate.
* This removes the extra character for those fonts. */
- if((c == 0xFDF2) && (i > 0) && ((a_str.charAt(i-1) == 0x0627) || (a_str.charAt(i-1) == 0xFE8D))) {
+ if((c == 0xFDF2) && (i > 0) && ((str.charAt(i-1) == 0x0627) || (str.charAt(i-1) == 0xFE8D)))
+ {
retStr += "\u0644\u0644\u0647";
}
- else{
+ else
+ {
/*
* Trim because some decompositions have an extra space, such as
* U+FC5E
@@ -88,33 +104,39 @@
retStr += Normalizer.normalize(c, Normalizer.NFKC).trim();
}
}
- else {
- retStr += a_str.charAt(i);
+ else
+ {
+ retStr += str.charAt(i);
}
}
return retStr;
}
+
/**
- * Decomposes Diacritic characters to their combining forms
+ * Decomposes Diacritic characters to their combining forms.
*
- * @param a_str String to be Normalized
+ * @param str String to be Normalized
* @return A Normalized String
*/
- public String normalizeDiac(String a_str){
+ public String normalizeDiac(String str)
+ {
String retStr = "";
- for (int i = 0; i < a_str.length(); i++) {
- char c = a_str.charAt(i);
+ for (int i = 0; i < str.length(); i++)
+ {
+ char c = str.charAt(i);
if(Character.getType(c) == Character.NON_SPACING_MARK
|| Character.getType(c) == Character.MODIFIER_SYMBOL
- || Character.getType(c) == Character.MODIFIER_LETTER){
+ || Character.getType(c) == Character.MODIFIER_LETTER)
+ {
/*
* Trim because some decompositions have an extra space, such as
* U+00B4
*/
retStr += Normalizer.normalize(c, Normalizer.NFKC).trim();
}
- else{
- retStr += a_str.charAt(i);
+ else
+ {
+ retStr += str.charAt(i);
}
}
return retStr;
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/Matrix.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/Matrix.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/Matrix.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/Matrix.java Tue Jul 28 18:25:32 2009
@@ -146,18 +146,19 @@
{
Matrix result = new Matrix();
- if (b != null && b.single != null) {
- float[] bMatrix = b.single;
- float[] resultMatrix = result.single;
- resultMatrix[0] = single[0] * bMatrix[0] + single[1] * bMatrix[3] + single[2] * bMatrix[6];
- resultMatrix[1] = single[0] * bMatrix[1] + single[1] * bMatrix[4] + single[2] * bMatrix[7];
- resultMatrix[2] = single[0] * bMatrix[2] + single[1] * bMatrix[5] + single[2] * bMatrix[8];
- resultMatrix[3] = single[3] * bMatrix[0] + single[4] * bMatrix[3] + single[5] * bMatrix[6];
- resultMatrix[4] = single[3] * bMatrix[1] + single[4] * bMatrix[4] + single[5] * bMatrix[7];
- resultMatrix[5] = single[3] * bMatrix[2] + single[4] * bMatrix[5] + single[5] * bMatrix[8];
- resultMatrix[6] = single[6] * bMatrix[0] + single[7] * bMatrix[3] + single[8] * bMatrix[6];
- resultMatrix[7] = single[6] * bMatrix[1] + single[7] * bMatrix[4] + single[8] * bMatrix[7];
- resultMatrix[8] = single[6] * bMatrix[2] + single[7] * bMatrix[5] + single[8] * bMatrix[8];
+ if (b != null && b.single != null)
+ {
+ float[] bMatrix = b.single;
+ float[] resultMatrix = result.single;
+ resultMatrix[0] = single[0] * bMatrix[0] + single[1] * bMatrix[3] + single[2] * bMatrix[6];
+ resultMatrix[1] = single[0] * bMatrix[1] + single[1] * bMatrix[4] + single[2] * bMatrix[7];
+ resultMatrix[2] = single[0] * bMatrix[2] + single[1] * bMatrix[5] + single[2] * bMatrix[8];
+ resultMatrix[3] = single[3] * bMatrix[0] + single[4] * bMatrix[3] + single[5] * bMatrix[6];
+ resultMatrix[4] = single[3] * bMatrix[1] + single[4] * bMatrix[4] + single[5] * bMatrix[7];
+ resultMatrix[5] = single[3] * bMatrix[2] + single[4] * bMatrix[5] + single[5] * bMatrix[8];
+ resultMatrix[6] = single[6] * bMatrix[0] + single[7] * bMatrix[3] + single[8] * bMatrix[6];
+ resultMatrix[7] = single[6] * bMatrix[1] + single[7] * bMatrix[4] + single[8] * bMatrix[7];
+ resultMatrix[8] = single[6] * bMatrix[2] + single[7] * bMatrix[5] + single[8] * bMatrix[8];
}
return result;
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFHighlighter.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFHighlighter.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFHighlighter.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFHighlighter.java Tue Jul 28 18:25:32 2009
@@ -45,7 +45,7 @@
private String[] searchedWords;
private ByteArrayOutputStream textOS = null;
private Writer textWriter = null;
- private static final String encoding = "UTF-16";
+ private static final String ENCODING = "UTF-16";
/**
* Default constructor.
@@ -54,7 +54,7 @@
*/
public PDFHighlighter() throws IOException
{
- super(encoding);
+ super(ENCODING);
super.setLineSeparator( "" );
super.setPageSeparator( "" );
super.setWordSeparator( "" );
@@ -96,7 +96,7 @@
//" mode=active " + */
" version=2>\n<Highlight>\n");
textOS = new ByteArrayOutputStream();
- textWriter = new OutputStreamWriter( textOS, encoding);
+ textWriter = new OutputStreamWriter( textOS, ENCODING);
writeText(pdDocument, textWriter);
highlighterOutput.write("</Highlight>\n</Body>\n</XML>");
highlighterOutput.flush();
@@ -109,14 +109,14 @@
{
textWriter.flush();
- String page = new String( textOS.toByteArray(), encoding );
+ String page = new String( textOS.toByteArray(), ENCODING );
textOS.reset();
//page = page.replaceAll( "\n", "" );
//page = page.replaceAll( "\r", "" );
//page = CCRStringUtil.stripChar(page, '\n');
//page = CCRStringUtil.stripChar(page, '\r');
- // Traitement des listes à puces (caractères spéciaux)
+ // Traitement des listes � puces (caract�res sp�ciaux)
if (page.indexOf("a") != -1)
{
page = page.replaceAll("a[0-9]{1,3}", ".");
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java Tue Jul 28 18:25:32 2009
@@ -274,15 +274,16 @@
destNums = (COSArray)destLabels.getDictionaryObject( COSName.getPDFName( "Nums" ) );
}
COSArray srcNums = (COSArray)srcLabels.getDictionaryObject( COSName.getPDFName( "Nums" ) );
- if (srcNums != null){
- for( int i=0; i<srcNums.size(); i+=2 )
- {
- COSNumber labelIndex = (COSNumber)srcNums.getObject( i );
- long labelIndexValue = labelIndex.intValue();
- destNums.add( new COSInteger( labelIndexValue + destPageCount ) );
- destNums.add( cloneForNewDocument( destination, srcNums.getObject( i+1 ) ) );
- }
- }
+ if (srcNums != null)
+ {
+ for( int i=0; i<srcNums.size(); i+=2 )
+ {
+ COSNumber labelIndex = (COSNumber)srcNums.getObject( i );
+ long labelIndexValue = labelIndex.intValue();
+ destNums.add( new COSInteger( labelIndexValue + destPageCount ) );
+ destNums.add( cloneForNewDocument( destination, srcNums.getObject( i+1 ) ) );
+ }
+ }
}
COSName metadata = COSName.getPDFName( "Metadata" );
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Tue Jul 28 18:25:32 2009
@@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Stack;
+import java.util.Vector;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.cos.COSStream;
@@ -51,6 +52,8 @@
public class PDFStreamEngine extends LoggingObject
{
+ private Vector unsupportedOperators = new Vector();
+
private static final byte[] SPACE_BYTES = { (byte)32 };
private PDGraphicsState graphicsState = null;
@@ -58,7 +61,6 @@
private Matrix textMatrix = null;
private Matrix textLineMatrix = null;
private Stack graphicsStack = new Stack();
- //private PDResources resources = null;
private Map operators = new HashMap();
@@ -70,7 +72,7 @@
private int validCharCnt;
private int totalCharCnt;
-
+
/**
* This is a simple internal class used by the Stream engine to handle the
* resources stack.
@@ -82,6 +84,9 @@
private Map xobjects;
private Map graphicsStates;
private PDResources resources;
+
+ private StreamResources()
+ {};
}
/**
@@ -106,7 +111,8 @@
*/
public PDFStreamEngine( Properties properties ) throws IOException
{
- if( properties == null ) {
+ if( properties == null )
+ {
throw new NullPointerException( "properties cannot be null" );
}
try
@@ -304,7 +310,7 @@
initialMatrix.setValue(1,1,1);
initialMatrix.setValue(1,2,0);
initialMatrix.setValue(2,0,0);
- initialMatrix.setValue(2,1,riseText);
+ initialMatrix.setValue(2,1,riseText);
initialMatrix.setValue(2,2,1);
final Matrix ctm = graphicsState.getCurrentTransformationMatrix();
@@ -335,7 +341,8 @@
//todo, handle horizontal displacement
// get the width and height of this character in text units
- float characterHorizontalDisplacementText = (font.getFontWidth( string, i, codeLength )/glyphSpaceToTextSpaceFactor);
+ float characterHorizontalDisplacementText =
+ (font.getFontWidth( string, i, codeLength )/glyphSpaceToTextSpaceFactor);
maxVerticalDisplacementText =
Math.max(
maxVerticalDisplacementText,
@@ -375,11 +382,10 @@
//The adjustment will always be zero. The adjustment as shown in the
//TJ operator will be handled separately.
float adjustment=0;
- /* TODO: tx should be set for horizontal text and ty for vertical text, which
- * seems to be specified in the font (not the direction in the matrix).
- */
- float tx = ((characterHorizontalDisplacementText-adjustment/glyphSpaceToTextSpaceFactor)*fontSizeText + spacingText)
- *horizontalScalingText;
+ // TODO : tx should be set for horizontal text and ty for vertical text
+ // which seems to be specified in the font (not the direction in the matrix).
+ float tx = ((characterHorizontalDisplacementText-adjustment/glyphSpaceToTextSpaceFactor)*fontSizeText
+ + spacingText) * horizontalScalingText;
float ty = 0;
Matrix td = new Matrix();
@@ -414,7 +420,8 @@
}
validCharCnt += c.length();
}
- else {
+ else
+ {
// PDFBOX-373: Replace a null entry with "?" so it is
// not printed as "(null)"
c = "?";
@@ -430,7 +437,8 @@
if( individualWidthsText.length != resultingString.length() )
{
float[] tmp = new float[resultingString.length()];
- System.arraycopy( individualWidthsText, 0, tmp, 0, Math.min( individualWidthsText.length, resultingString.length() ));
+ System.arraycopy( individualWidthsText, 0, tmp, 0,
+ Math.min( individualWidthsText.length, resultingString.length() ));
individualWidthsText = tmp;
if( resultingString.equals( "- " ))
{
@@ -468,13 +476,14 @@
*/
public void processOperator( String operation, List arguments ) throws IOException
{
- try{
+ try
+ {
PDFOperator oper = PDFOperator.getOperator( operation );
processOperator( oper, arguments );
}
catch (IOException e)
{
- logger().warning (e.toString() + "\n at\n" + FullStackTrace(e));
+ logger().warning(e.toString() + "\n at\n" + FullStackTrace(e));
}
}
@@ -488,20 +497,27 @@
*/
protected void processOperator( PDFOperator operator, List arguments ) throws IOException
{
- try{
+ try
+ {
String operation = operator.getOperation();
OperatorProcessor processor = (OperatorProcessor)operators.get( operation );
if( processor != null )
{
- processor.setContext(this);
+ processor.setContext(this);
processor.process( operator, arguments );
- }/*else{
- logger().warning("NULL processor for operation: " + operation);
- }*/
+ }
+ else
+ {
+ if (!unsupportedOperators.contains(operation))
+ {
+ logger().info("unsupported/disabled operation: " + operation);
+ unsupportedOperators.add(operation);
+ }
+ }
}
catch (Exception e)
{
- logger().warning (e.toString() + "\n at\n" + FullStackTrace(e));
+ logger().warning(e.toString() + "\n at\n" + FullStackTrace(e));
}
}
@@ -649,4 +665,5 @@
{
return totalCharCnt;
}
+
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFText2HTML.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFText2HTML.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFText2HTML.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFText2HTML.java Tue Jul 28 18:25:32 2009
@@ -31,19 +31,20 @@
* @author jjb - http://www.johnjbarton.com
* @version $Revision: 1.3 $
*/
-public class PDFText2HTML extends PDFTextStripper {
+public class PDFText2HTML extends PDFTextStripper
+{
private static final int INITIAL_PDF_TO_HTML_BYTES = 8192;
private boolean onFirstPage = true;
/**
* Constructor.
- *
- * @throws IOException
- * If there is an error during initialization.
+ * @param encoding The encoding to be used
+ * @throws IOException If there is an error during initialization.
*/
- public PDFText2HTML(String encoding) throws IOException {
- this.encoding = encoding;
+ public PDFText2HTML(String encoding) throws IOException
+ {
+ this.outputEncoding = encoding;
this.lineSeparator = "<br>" + System.getProperty("line.separator");
}
@@ -54,13 +55,17 @@
* @throws IOException
* If there is a problem writing out the header to the document.
*/
- protected void writeHeader() throws IOException {
+ protected void writeHeader() throws IOException
+ {
StringBuffer buf = new StringBuffer(INITIAL_PDF_TO_HTML_BYTES);
- buf.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" + "\n" + "\"http://www.w3.org/TR/html4/loose.dtd\">\n");
+ buf.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" + "\n"
+ + "\"http://www.w3.org/TR/html4/loose.dtd\">\n");
buf.append("<html><head>");
buf.append("<title>" + getTitle() + "</title>\n");
- if(encoding != null){
- buf.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + this.encoding + "\">\n");
+ if(outputEncoding != null)
+ {
+ buf.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
+ + this.outputEncoding + "\">\n");
}
buf.append("</head>\n");
buf.append("<body>\n");
@@ -70,8 +75,10 @@
/**
* {@inheritDoc}
*/
- protected void writePage() throws IOException {
- if (onFirstPage) {
+ protected void writePage() throws IOException
+ {
+ if (onFirstPage)
+ {
writeHeader();
onFirstPage = false;
}
@@ -81,7 +88,8 @@
/**
* {@inheritDoc}
*/
- public void endDocument(PDDocument pdf) throws IOException {
+ public void endDocument(PDDocument pdf) throws IOException
+ {
super.writeString("</body></html>");
}
@@ -91,32 +99,39 @@
*
* @return returns the title.
*/
- protected String getTitle() {
+ protected String getTitle()
+ {
String titleGuess = document.getDocumentInformation().getTitle();
- if(titleGuess != null && titleGuess.length() > 0){
+ if(titleGuess != null && titleGuess.length() > 0)
+ {
return titleGuess;
}
- else {
+ else
+ {
Iterator textIter = getCharactersByArticle().iterator();
float lastFontSize = -1.0f;
StringBuffer titleText = new StringBuffer();
- while (textIter.hasNext()) {
-
+ while (textIter.hasNext())
+ {
Iterator textByArticle = ((List) textIter.next()).iterator();
- while (textByArticle.hasNext()) {
+ while (textByArticle.hasNext())
+ {
TextPosition position = (TextPosition) textByArticle.next();
float currentFontSize = position.getFontSize();
//If we're past 64 chars we will assume that we're past the title
//64 is arbitrary
- if (currentFontSize != lastFontSize || titleText.length() > 64) {
- if (titleText.length() > 0) {
+ if (currentFontSize != lastFontSize || titleText.length() > 64)
+ {
+ if (titleText.length() > 0)
+ {
return titleText.toString();
}
lastFontSize = currentFontSize;
}
- if (currentFontSize > 13.0f) { // most body text is 12pt
+ if (currentFontSize > 13.0f)
+ { // most body text is 12pt
titleText.append(position.getCharacter());
}
}
@@ -130,15 +145,18 @@
* Write out the article separator (div tag) with proper text direction
* information.
*
- * @param true if direction of text is left to right
+ * @param isltr true if direction of text is left to right
* @throws IOException
* If there is an error writing to the stream.
*/
- protected void startArticle(boolean isltr) throws IOException {
- if (isltr) {
+ protected void startArticle(boolean isltr) throws IOException
+ {
+ if (isltr)
+ {
super.writeString("<div>");
}
- else {
+ else
+ {
super.writeString("<div dir=\"RTL\">");
}
}
@@ -149,23 +167,33 @@
* @throws IOException
* If there is an error writing to the stream.
*/
- protected void endArticle() throws IOException {
+ protected void endArticle() throws IOException
+ {
super.writeString("</div>");
}
/**
- * Write a string to the output stream and escape some HTML characters
+ * Write a string to the output stream and escape some HTML characters.
+ *
+ * @param chars String to be written to the stream
+ * @throws IOException
+ * If there is an error writing to the stream.
*/
- protected void writeString(String chars) throws IOException {
- for (int i = 0; i < chars.length(); i++) {
+ protected void writeString(String chars) throws IOException
+ {
+ for (int i = 0; i < chars.length(); i++)
+ {
char c = chars.charAt(i);
// write non-ASCII as named entities
- if ((c < 32) || (c > 126)) {
+ if ((c < 32) || (c > 126))
+ {
int charAsInt = c;
super.writeString("&#" + charAsInt + ";");
}
- else {
- switch (c) {
+ else
+ {
+ switch (c)
+ {
case 34:
super.writeString(""");
break;
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java?rev=798640&r1=798639&r2=798640&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java Tue Jul 28 18:25:32 2009
@@ -63,7 +63,6 @@
private int startBookmarkPageNumber = -1;
private PDOutlineItem endBookmark = null;
private int endBookmarkPageNumber = -1;
- protected PDDocument document;
private boolean suppressDuplicateOverlappingText = true;
private boolean shouldSeparateByBeads = true;
private boolean sortByPosition = false;
@@ -93,12 +92,22 @@
private Map characterListMapping = new HashMap();
+ /**
+ * The platforms lineseparator.
+ */
protected String lineSeparator = System.getProperty("line.separator");
private String pageSeparator = System.getProperty("line.separator");
private String wordSeparator = " ";
- protected String encoding; // encoding that text will be written in (or null)
+ /**
+ * encoding that text will be written in (or null).
+ */
+ protected String outputEncoding;
/**
+ * The document to read.
+ */
+ protected PDDocument document;
+ /**
* The stream to write the output to.
*/
protected Writer output;
@@ -118,8 +127,8 @@
public PDFTextStripper() throws IOException
{
super( ResourceLoader.loadProperties( "Resources/PDFTextStripper.properties", true ) );
- this.encoding = null;
- normalize = new TextNormalize(this.encoding);
+ this.outputEncoding = null;
+ normalize = new TextNormalize(this.outputEncoding);
}
@@ -136,8 +145,8 @@
public PDFTextStripper( Properties props ) throws IOException
{
super( props );
- this.encoding = null;
- normalize = new TextNormalize(this.encoding);
+ this.outputEncoding = null;
+ normalize = new TextNormalize(this.outputEncoding);
}
/**
* Instantiate a new PDFTextStripper object. This object will load properties from
@@ -151,8 +160,8 @@
public PDFTextStripper( String encoding ) throws IOException
{
super( ResourceLoader.loadProperties( "Resources/PDFTextStripper.properties", true ));
- this.encoding = encoding;
- normalize = new TextNormalize(this.encoding);
+ this.outputEncoding = encoding;
+ normalize = new TextNormalize(this.outputEncoding);
}
/**
@@ -382,7 +391,7 @@
* Default implementation is to do nothing. Subclasses
* may provide additional information.
*
- * @param true if primary direction of text is left to right
+ * @param isltr true if primary direction of text is left to right.
* @throws IOException If there is any error writing to the stream.
*/
protected void startArticle(boolean isltr) throws IOException
@@ -479,17 +488,20 @@
TextPosition position = (TextPosition)textIter.next();
String stringValue = position.getCharacter();
- for (int a = 0; a < stringValue.length(); a++) {
+ for (int a = 0; a < stringValue.length(); a++)
+ {
byte dir = Character.getDirectionality(stringValue.charAt(a));
if ((dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT ) ||
(dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING) ||
- (dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE )) {
+ (dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE ))
+ {
ltrCnt++;
}
else if ((dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT ) ||
(dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) ||
(dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING) ||
- (dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE )) {
+ (dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE ))
+ {
rtlCnt++;
}
}
@@ -497,7 +509,8 @@
// choose the dominant direction
boolean isRtlDominant = false;
- if (rtlCnt > ltrCnt) {
+ if (rtlCnt > ltrCnt)
+ {
isRtlDominant = true;
}
@@ -506,7 +519,9 @@
// we will later use this to skip reordering
boolean hasRtl = false;
if (rtlCnt > 0)
+ {
hasRtl = true;
+ }
/* Now cycle through to print the text.
* We queue up a line at a time before we print so that we can convert
@@ -533,7 +548,8 @@
//Resets the average character width when we see a change in font
// or a change in the font size
if(lastPosition != null && ((position.getFont() != lastPosition.getFont())
- || (position.getFontSize() != lastPosition.getFontSize()))){
+ || (position.getFontSize() != lastPosition.getFontSize())))
+ {
previousAveCharWidth = -1;
}
@@ -544,13 +560,15 @@
/* If we are sorting, then we need to use the text direction
* adjusted coordinates, because they were used in the sorting. */
- if (sortByPosition) {
+ if (sortByPosition)
+ {
positionX = position.getXDirAdj();
positionY = position.getYDirAdj();
positionWidth = position.getWidthDirAdj();
positionHeight = position.getHeightDir();
}
- else {
+ else
+ {
positionX = position.getX();
positionY = position.getY();
positionWidth = position.getWidth();
@@ -564,14 +582,18 @@
* space character with some margin. */
float wordSpacing = position.getWidthOfSpace();
float deltaSpace = 0;
- if ((wordSpacing == 0) || (wordSpacing == Float.NaN)) {
+ if ((wordSpacing == 0) || (wordSpacing == Float.NaN))
+ {
deltaSpace = Float.MAX_VALUE;
}
- else {
- if( lastWordSpacing < 0 ){
+ else
+ {
+ if( lastWordSpacing < 0 )
+ {
deltaSpace = (wordSpacing * spacingTolerance);
}
- else{
+ else
+ {
deltaSpace = (((wordSpacing+lastWordSpacing)/2f)* spacingTolerance);
}
}
@@ -582,10 +604,12 @@
* best results after numerous experiments. Based on experiments we also found that
* .3 worked well. */
float averageCharWidth = -1;
- if(previousAveCharWidth < 0){
+ if(previousAveCharWidth < 0)
+ {
averageCharWidth = (positionWidth/wordCharCount);
}
- else{
+ else
+ {
averageCharWidth = (previousAveCharWidth + (positionWidth/wordCharCount))/2f;
}
float deltaCharWidth = (averageCharWidth * averageCharTolerance);
@@ -593,16 +617,20 @@
//Compares the values obtained by the average method and the wordSpacing method and picks
//the smaller number.
float expectedStartOfNextWordX = -1;
- if(endOfLastTextX != -1){
- if(deltaCharWidth > deltaSpace){
+ if(endOfLastTextX != -1)
+ {
+ if(deltaCharWidth > deltaSpace)
+ {
expectedStartOfNextWordX = endOfLastTextX + deltaSpace;
}
- else{
+ else
+ {
expectedStartOfNextWordX = endOfLastTextX + deltaCharWidth;
}
}
- if( lastPosition != null ){
+ if( lastPosition != null )
+ {
// RDD - Here we determine whether this text object is on the current
// line. We use the lastBaselineFontSize to handle the superscript
// case, and the size of the current font to handle the subscript case.
@@ -612,10 +640,13 @@
/* XXX BC: In theory, this check should really check if the next char is in full range
* seen in this line. This is what I tried to do with minYTopForLine, but this caused a lot
* of regression test failures. So, I'm leaving it be for now. */
- if(!overlap(positionY, positionHeight, maxYForLine, maxHeightForLine)){
+ if(!overlap(positionY, positionHeight, maxYForLine, maxHeightForLine))
+ {
// If we have RTL text on the page, change the direction
if (hasRtl)
+ {
lineStr = normalize.makeLineLogicalOrder(lineStr, isRtlDominant);
+ }
/* normalize string to remove presentation forms.
* Note that this must come after the line direction
@@ -640,12 +671,14 @@
if (expectedStartOfNextWordX != -1 && expectedStartOfNextWordX < positionX &&
//only bother adding a space if the last character was not a space
lastPosition.getCharacter() != null &&
- !lastPosition.getCharacter().endsWith( " " ) ) {
+ !lastPosition.getCharacter().endsWith( " " ) )
+ {
lineStr += getWordSeparator();
}
}
- if (positionY >= maxYForLine) {
+ if (positionY >= maxYForLine)
+ {
maxYForLine = positionY;
}
@@ -654,7 +687,8 @@
endOfLastTextX = positionX + positionWidth;
// add it to the list
- if (characterValue != null) {
+ if (characterValue != null)
+ {
lineStr += characterValue;
}
maxHeightForLine = Math.max( maxHeightForLine, positionHeight );
@@ -665,9 +699,12 @@
}
// print the final line
- if (lineStr.length() > 0) {
+ if (lineStr.length() > 0)
+ {
if (hasRtl)
+ {
lineStr = normalize.makeLineLogicalOrder(lineStr, isRtlDominant);
+ }
// normalize string to remove presentation forms
lineStr = normalize.normalizePres(lineStr);
@@ -687,8 +724,9 @@
}
/**
- * Write the page separator value to the output stream
+ * Write the page separator value to the output stream.
* @throws IOException
+ * If there is a problem writing out the pageseparator to the document.
*/
protected void writePageSeperator() throws IOException
{
@@ -700,8 +738,9 @@
}
/**
- * Write the line separator value to the output stream
+ * Write the line separator value to the output stream.
* @throws IOException
+ * If there is a problem writing out the lineseparator to the document.
*/
protected void writeLineSeparator( ) throws IOException
{
@@ -710,8 +749,9 @@
/**
- * Write the word separator value to the output stream
+ * Write the word separator value to the output stream.
* @throws IOException
+ * If there is a problem writing out the wordseparator to the document.
*/
protected void writeWordSeparator() throws IOException
{
@@ -893,26 +933,31 @@
* we need to do the overlay. This code recombines the diacritic with
* its associated character if the two are consecutive.
*/
- if(textList.isEmpty()){
+ if(textList.isEmpty())
+ {
textList.add(text);
}
- else{
+ else
+ {
/* test if we overlap the previous entry.
* Note that we are making an assumption that we need to only look back
* one TextPosition to find what we are overlapping.
* This may not always be true. */
TextPosition previousTextPosition = (TextPosition)textList.get(textList.size()-1);
- if(text.isDiacritic() && previousTextPosition.contains(text)){
+ if(text.isDiacritic() && previousTextPosition.contains(text))
+ {
previousTextPosition.mergeDiacritic(text, normalize);
}
/* If the previous TextPosition was the diacritic, merge it into this
* one and remove it from the list. */
- else if(previousTextPosition.isDiacritic() && text.contains(previousTextPosition)){
+ else if(previousTextPosition.isDiacritic() && text.contains(previousTextPosition))
+ {
text.mergeDiacritic(previousTextPosition, normalize);
textList.remove(textList.size()-1);
textList.add(text);
}
- else{
+ else
+ {
textList.add(text);
}
}
@@ -1182,7 +1227,8 @@
*
* @return The current tolerance / scaling factor
*/
- public float getSpacingTolerance() {
+ public float getSpacingTolerance()
+ {
return spacingTolerance;
}
@@ -1192,10 +1238,11 @@
* default value for this has been determined from trial and error.
* Setting this value larger will reduce the number of spaces added.
*
- * @param spacingTolerance tolerance / scaling factor to use
+ * @param spacingToleranceValue tolerance / scaling factor to use
*/
- public void setSpacingTolerance(float spacingTolerance) {
- this.spacingTolerance = spacingTolerance;
+ public void setSpacingTolerance(float spacingToleranceValue)
+ {
+ this.spacingTolerance = spacingToleranceValue;
}
/**
@@ -1205,7 +1252,8 @@
*
* @return The current tolerance / scaling factor
*/
- public float getAverageCharTolerance() {
+ public float getAverageCharTolerance()
+ {
return averageCharTolerance;
}
@@ -1215,9 +1263,10 @@
* default value for this has been determined from trial and error.
* Setting this value larger will reduce the number of spaces added.
*
- * @param spacingTolerance tolerance / scaling factor to use
+ * @param averageCharToleranceValue average tolerance / scaling factor to use
*/
- public void setAverageCharTolerance(float averageCharTolerance) {
- this.averageCharTolerance = averageCharTolerance;
+ public void setAverageCharTolerance(float averageCharToleranceValue)
+ {
+ this.averageCharTolerance = averageCharToleranceValue;
}
}
Re: svn commit: r798640 [1/2] - in /incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox:
pdmodel/graphics/color/ pdmodel/graphics/xobject/ persistence/util/ util/
Posted by Andreas Lehmkühler <an...@lehmi.de>.
lehmi@apache.org schrieb:
> Author: lehmi
> Date: Tue Jul 28 18:25:32 2009
> New Revision: 798640
>
> URL: http://svn.apache.org/viewvc?rev=798640&view=rev
> Log:
> PDFBOX-464: reestablish checkstyle compliance
I've added Brian Carrier as author of the following classes
org.apache.pdfbox.util.ICU4JImpl.TextNormalize.java
org.apache.pdfbox.util.ICU4JImpl.java
to the comment in the header. As Brain committed these 2 classes to svn
I hope that's ok.
BR
Andreas Lehmkühler