[FOray-commit] SF.net SVN: foray:[10716] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2009-03-19 16:44:16
|
Revision: 10716
http://foray.svn.sourceforge.net/foray/?rev=10716&view=rev
Author: victormote
Date: 2009-03-19 16:44:01 +0000 (Thu, 19 Mar 2009)
Log Message:
-----------
Conform to new aXSL requirements for Pdf gradients.
Modified Paths:
--------------
trunk/foray/foray-graphic/.classpath
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
Modified: trunk/foray/foray-graphic/.classpath
===================================================================
--- trunk/foray/foray-graphic/.classpath 2009-03-19 15:13:07 UTC (rev 10715)
+++ trunk/foray/foray-graphic/.classpath 2009-03-19 16:44:01 UTC (rev 10716)
@@ -30,5 +30,6 @@
<classpathentry kind="lib" path="/FOray Lib/xercesImpl-2.7.1.jar" sourcepath="/FOray Lib-Build/xerces/Xerces-J-src.2.7.1.zip"/>
<classpathentry kind="lib" path="/FOray Lib-Build/junit/junit-4.4.jar" sourcepath="/FOray Lib-Build/junit/junit-4.4-src.jar"/>
<classpathentry kind="lib" path="/FOray Lib/commons-io-1.4.jar" sourcepath="/FOray Lib-Build/commons-io/commons-io-1.4-sources.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/axslPdf"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2009-03-19 15:13:07 UTC (rev 10715)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2009-03-19 16:44:01 UTC (rev 10716)
@@ -42,7 +42,6 @@
import org.foray.pdf.object.PDFDocument;
import org.foray.pdf.object.PDFLink;
import org.foray.pdf.object.PDFPage;
-import org.foray.pdf.object.PDFPattern;
import org.foray.pdf.object.PDFString;
import org.foray.pdf.object.PDFXObject;
@@ -51,6 +50,7 @@
import org.axsl.font.FontUtility;
import org.axsl.graphic.GraphicException;
import org.axsl.graphic.output.GraphicOutputContext;
+import org.axsl.pdf.PdfPattern;
import org.apache.commons.logging.Log;
@@ -584,9 +584,7 @@
final ColorSpace aColorSpace = ColorSpace.getInstance(
ColorSpace.CS_sRGB);
- final PDFPattern myPat = PDFPattern.createGradient(false,
- aColorSpace,
- someColors, null, theCoords, this.pdfDoc);
+ final PdfPattern myPat = this.pdfDoc.createGradient(false, aColorSpace, someColors, null, theCoords);
this.write(myPat.getSetterString(fill));
} else if (paint instanceof TexturePaint) { }
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2009-03-19 15:13:07 UTC (rev 10715)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2009-03-19 16:44:01 UTC (rev 10716)
@@ -36,11 +36,14 @@
package org.foray.pdf.object;
+import org.foray.common.ColorUtil;
+
import org.axsl.font.Font;
import org.axsl.font.FontUse;
import org.axsl.graphic.Graphic;
import org.axsl.pdf.PdfException;
import org.axsl.pdf.PdfPageLabelStyle;
+import org.axsl.pdf.PdfPattern;
import org.axsl.pdf.PdfVersion;
import org.axsl.ps.Encoding;
@@ -83,6 +86,10 @@
/** A bogus object added to the location list to ensure capacity. */
private static final Integer LOCATION_PLACEHOLDER = new Integer(0);
+ /** Constant indicating the number of components in a radial shading, that
+ * is, 6. */
+ private static final int QTY_RADIAL_SHADING_COMPONENTS = 6;
+
/** A binary comment as recommended by the PDF spec (3.4.1). */
private static final String BINARY_COMMENT = new String(new char[] {
(char) 0xAA,
@@ -775,4 +782,102 @@
this.getRoot().addPageLabel(startingPageIndex, newPageLabel);
}
+ /**
+ * {@inheritDoc}
+ */
+ public PdfPattern createGradient(final boolean radial, final ColorSpace theColorSpace, final List<Color> theColors,
+ final List<Double> theBounds, final List<Double> theCoords) {
+ PDFShading myShad;
+ PDFFunction myfunky;
+ PDFFunction myfunc;
+ List<Double> theCzero;
+ List<Double> theCone;
+ PDFPattern myPattern;
+ final double interpolation = 1.000;
+ final List<PDFFunction> theFunctions = new ArrayList<PDFFunction>();
+
+ int currentPosition;
+ final int lastPosition = theColors.size() - 1;
+
+
+ // if 5 elements, the penultimate element is 3.
+ // do not go beyond that, because you always need
+ // to have a next color when creating the function.
+
+ for (currentPosition = 0; currentPosition < lastPosition;
+ currentPosition++) { // for every consecutive color pair
+ Color currentColor = theColors.get(currentPosition);
+ Color nextColor = theColors.get(currentPosition + 1);
+ /* The colorspace must be consistent. */
+ if (theColorSpace.getType()
+ != currentColor.getColorSpace().getType()) {
+ currentColor = ColorUtil.convertColorSpace(currentColor,
+ theColorSpace);
+ }
+
+ if (theColorSpace.getType()
+ != nextColor.getColorSpace().getType()) {
+ nextColor = ColorUtil.convertColorSpace(nextColor,
+ theColorSpace);
+ }
+
+ theCzero = colorToDoubleList(currentColor);
+ theCone = colorToDoubleList(nextColor);
+
+ myfunc = new PDFFunction(this, 2, null, null,
+ theCzero, theCone, interpolation);
+
+ theFunctions.add(myfunc);
+
+ } // end of for every consecutive color pair
+
+ myfunky = new PDFFunction(this, PDFFunction.TYPE_STITCHING, null,
+ null, theFunctions, theBounds, null);
+ if (radial) {
+ if (theCoords.size() == PDFDocument.QTY_RADIAL_SHADING_COMPONENTS) {
+ myShad = new PDFShading(this, PDFShading.TYPE_RADIAL,
+ theColorSpace, null, null,
+ false, theCoords, null, myfunky,
+ null);
+ } else { // if the center x, center y, and radius specifiy
+ // the gradient, then assume the same center x, center y,
+ // and radius of zero for the other necessary component
+ final List<Double> newCoords = new ArrayList<Double>();
+ newCoords.add(theCoords.get(0));
+ newCoords.add(theCoords.get(1));
+ newCoords.add(theCoords.get(2));
+ newCoords.add(theCoords.get(0));
+ newCoords.add(theCoords.get(1));
+ newCoords.add(new Double(0.0));
+ myShad = new PDFShading(this, PDFShading.TYPE_RADIAL,
+ theColorSpace,
+ null, null, false, newCoords, null, myfunky,
+ null);
+ }
+ } else {
+ myShad = new PDFShading(this, 2, theColorSpace,
+ null, null, false, theCoords, null, myfunky, null);
+ }
+ myPattern = new PDFPattern(this, 2, myShad, null,
+ null, null);
+ return myPattern;
+ }
+
+ /**
+ * Convert a color to a list of its components.
+ * @param theColor The color to be converted.
+ * @return The list of the color components.
+ */
+ static List<Double> colorToDoubleList(final Color theColor) {
+ final List<Double> theColorVector = new ArrayList<Double>();
+ if (theColor == null) {
+ return theColorVector;
+ }
+ final float[] colorComponents = theColor.getColorComponents(null);
+ for (int i = 0; i < colorComponents.length; i++) {
+ theColorVector.add(new Double(colorComponents[i]));
+ }
+ return theColorVector;
+ }
+
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java 2009-03-19 15:13:07 UTC (rev 10715)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java 2009-03-19 16:44:01 UTC (rev 10716)
@@ -28,12 +28,8 @@
package org.foray.pdf.object;
-import org.foray.common.ColorUtil;
import org.foray.common.ps.PsUtil;
-import java.awt.Color;
-import java.awt.color.ColorSpace;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -47,12 +43,8 @@
*
* All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range.
*/
-public class PDFPattern extends PDFPathPaint {
+public class PDFPattern extends PDFPathPaint implements org.axsl.pdf.PdfPattern {
- /** Constant indicating the number of components in a radial shading, that
- * is, 6. */
- private static final int QTY_RADIAL_SHADING_COMPONENTS = 6;
-
/** The resources associated with this pattern. */
private PDFResources resources = null;
@@ -186,113 +178,6 @@
}
/**
- * Static method for creating a gradient pattern.
- * @param radial Indicates whether the gradient is a radial gradient.
- * @param theColorSpace The color space for the gradient.
- * @param theColors The colors for the gradient.
- * @param theBounds The bounds of the gradient.
- * @param theCoords The coordinates of the gradient.
- * @param document The parent PDF document.
- * @return The pattern for the gradient.
- */
- public static PDFPattern createGradient(final boolean radial,
- final ColorSpace theColorSpace, final List<Color> theColors,
- final List<Double> theBounds, final List<Double> theCoords,
- final PDFDocument document) {
- PDFShading myShad;
- PDFFunction myfunky;
- PDFFunction myfunc;
- List<Double> theCzero;
- List<Double> theCone;
- PDFPattern myPattern;
- final double interpolation = 1.000;
- final List<PDFFunction> theFunctions = new ArrayList<PDFFunction>();
-
- int currentPosition;
- final int lastPosition = theColors.size() - 1;
-
-
- // if 5 elements, the penultimate element is 3.
- // do not go beyond that, because you always need
- // to have a next color when creating the function.
-
- for (currentPosition = 0; currentPosition < lastPosition;
- currentPosition++) { // for every consecutive color pair
- Color currentColor = theColors.get(currentPosition);
- Color nextColor = theColors.get(currentPosition + 1);
- /* The colorspace must be consistent. */
- if (theColorSpace.getType()
- != currentColor.getColorSpace().getType()) {
- currentColor = ColorUtil.convertColorSpace(currentColor,
- theColorSpace);
- }
-
- if (theColorSpace.getType()
- != nextColor.getColorSpace().getType()) {
- nextColor = ColorUtil.convertColorSpace(nextColor,
- theColorSpace);
- }
-
- theCzero = colorToDoubleList(currentColor);
- theCone = colorToDoubleList(nextColor);
-
- myfunc = new PDFFunction(document, 2, null, null,
- theCzero, theCone, interpolation);
-
- theFunctions.add(myfunc);
-
- } // end of for every consecutive color pair
-
- myfunky = new PDFFunction(document, PDFFunction.TYPE_STITCHING, null,
- null, theFunctions, theBounds, null);
- if (radial) {
- if (theCoords.size() == PDFPattern.QTY_RADIAL_SHADING_COMPONENTS) {
- myShad = new PDFShading(document, PDFShading.TYPE_RADIAL,
- theColorSpace, null, null,
- false, theCoords, null, myfunky,
- null);
- } else { // if the center x, center y, and radius specifiy
- // the gradient, then assume the same center x, center y,
- // and radius of zero for the other necessary component
- final List<Double> newCoords = new ArrayList<Double>();
- newCoords.add(theCoords.get(0));
- newCoords.add(theCoords.get(1));
- newCoords.add(theCoords.get(2));
- newCoords.add(theCoords.get(0));
- newCoords.add(theCoords.get(1));
- newCoords.add(new Double(0.0));
- myShad = new PDFShading(document, PDFShading.TYPE_RADIAL,
- theColorSpace,
- null, null, false, newCoords, null, myfunky,
- null);
- }
- } else {
- myShad = new PDFShading(document, 2, theColorSpace,
- null, null, false, theCoords, null, myfunky, null);
- }
- myPattern = new PDFPattern(document, 2, myShad, null,
- null, null);
- return myPattern;
- }
-
- /**
- * Convert a color to a list of its components.
- * @param theColor The color to be converted.
- * @return The list of the color components.
- */
- static List<Double> colorToDoubleList(final Color theColor) {
- final List<Double> theColorVector = new ArrayList<Double>();
- if (theColor == null) {
- return theColorVector;
- }
- final float[] colorComponents = theColor.getColorComponents(null);
- for (int i = 0; i < colorComponents.length; i++) {
- theColorVector.add(new Double(colorComponents[i]));
- }
- return theColorVector;
- }
-
- /**
* represent as PDF. Whatever the FunctionType is, the correct
* representation spits out. The sets of required and optional
* attributes are different for each type, but if a required
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|