[FOray-commit] SF.net SVN: foray:[10722] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2009-04-18 21:32:35
|
Revision: 10722
http://foray.svn.sourceforge.net/foray/?rev=10722&view=rev
Author: victormote
Date: 2009-04-18 21:32:25 +0000 (Sat, 18 Apr 2009)
Log Message:
-----------
Use new aXSL Gradient interface to clean up a dependency that FOrayGraphic had on FOrayPDF.
Modified Paths:
--------------
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-render/src/java/org/foray/render/ps/PSRenderer.java
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/Gradient4a.java
Added: trunk/foray/foray-common/src/java/org/foray/common/Gradient4a.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/Gradient4a.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/Gradient4a.java 2009-04-18 21:32:25 UTC (rev 10722)
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2009 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common;
+
+import org.axsl.common.Gradient;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+import java.util.List;
+
+/**
+ * Describes a radial or linear gradient.
+ */
+public class Gradient4a implements Gradient {
+
+ /** Indicates whether the gradient is linear or radial. */
+ private boolean radial;
+
+ /** The color space for the gradient. */
+ private ColorSpace colorSpace;
+
+ /** The colors in the gradient. */
+ private List<Color> colors;
+
+ /** The bounds of the gradient. */
+ private List<Double> bounds;
+
+ /** The coordinates of the gradient. */
+ private List<Double> coordinates;
+
+ /**
+ * Constructor.
+ * @param radial Indicates whether the gradient is linear or radial.
+ * @param colorSpace The color space for the gradient.
+ * @param colors The colors in the gradient.
+ * @param bounds The bounds of the gradient.
+ * @param coordinates The coordinates of the gradient.
+ */
+ public Gradient4a(final boolean radial, final ColorSpace colorSpace, final List<Color> colors,
+ final List<Double> bounds, final List<Double> coordinates) {
+ this.radial = radial;
+ this.colorSpace = colorSpace;
+ this.colors = colors;
+ this.bounds = bounds;
+ this.coordinates = coordinates;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRadial() {
+ return this.radial;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ColorSpace getColorSpace() {
+ return this.colorSpace;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Color> getColors() {
+ return this.colors;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Double> getBounds() {
+ return this.bounds;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Double> getCoordinates() {
+ return this.coordinates;
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/Gradient4a.java
___________________________________________________________________
Added: svn:keywords
+ "Author Id Rev Date URL"
Added: svn:eol-style
+ native
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-04-18 19:47:38 UTC (rev 10721)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2009-04-18 21:32:25 UTC (rev 10722)
@@ -34,10 +34,10 @@
package org.foray.graphic.batik;
import org.foray.common.CharacterOutputStream;
+import org.foray.common.Gradient4a;
import org.foray.common.WKConstants;
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
-import org.foray.pdf.object.PDFDocument;
import org.foray.pdf.object.PDFString;
import org.axsl.font.FontConsumer;
@@ -47,7 +47,6 @@
import org.axsl.graphic.GraphicException;
import org.axsl.graphic.output.GraphicOutputContext;
import org.axsl.pdf.PdfPage;
-import org.axsl.pdf.PdfPattern;
import org.apache.commons.logging.Log;
@@ -145,9 +144,6 @@
* 2. */
public static final byte QTY_ELEMENTS_LINEAR = 2;
- /** The PDF Document being created. */
- private PDFDocument pdfDoc;
-
/** The current stream to add PDF commands to. */
private CharacterOutputStream currentStream;
@@ -201,9 +197,6 @@
this.currentStream = new CharacterOutputStream(outputStream, true);
this.comment("%%%% Start FOrayGraphic SVG-to-PDF conversion. %%%%");
- /* TODO: What we really need here is a new GraphicsState, not a complete
- * new document. */
- this.pdfDoc = new PDFDocument(null, null);
this.logger = logger;
this.fontConsumer = fontConsumer;
this.pdfContext = pdfContext;
@@ -420,7 +413,6 @@
*/
public void dispose() {
this.comment("%%%% End FOrayGraphic SVG-to-PDF conversion. %%%%");
- this.pdfDoc = null;
this.currentStream = null;
this.graphicsStateStack = null;
}
@@ -597,10 +589,14 @@
someColors.add(c1);
someColors.add(c2);
- final ColorSpace aColorSpace = ColorSpace.getInstance(
- ColorSpace.CS_sRGB);
- final PdfPattern myPat = this.pdfDoc.createGradient(false, aColorSpace, someColors, null, theCoords);
- this.write(myPat.getSetterString(fill));
+ final ColorSpace aColorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ final Gradient4a gradient = new Gradient4a(false, aColorSpace, someColors, null, theCoords);
+ final String gradientName = this.pdfContext.getGradientName(gradient);
+ if (fill) {
+ this.write("/Pattern cs /" + gradientName + " scn" + WKConstants.LINEFEED);
+ } else {
+ this.write("/Pattern CS /" + gradientName + " SCN" + WKConstants.LINEFEED);
+ }
} 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-04-18 19:47:38 UTC (rev 10721)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2009-04-18 21:32:25 UTC (rev 10722)
@@ -38,12 +38,12 @@
import org.foray.common.ColorUtil;
+import org.axsl.common.Gradient;
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;
@@ -774,6 +774,15 @@
/**
* {@inheritDoc}
*/
+ public String getGradientName(final Gradient gradient) {
+ /* TODO: See if this gradient already exists before creating it again. */
+ final PDFPattern pattern = this.createGradient(gradient);
+ return pattern.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void addPageLabelRange(final int startingPageIndex,
final PdfPageLabelStyle labelStyle, final CharSequence labelPrefix,
final int startingPageNumber) {
@@ -785,8 +794,13 @@
/**
* {@inheritDoc}
*/
- public PdfPattern createGradient(final boolean radial, final ColorSpace theColorSpace, final List<Color> theColors,
- final List<Double> theBounds, final List<Double> theCoords) {
+ public PDFPattern createGradient(final Gradient gradient) {
+ final boolean radial = gradient.isRadial();
+ final ColorSpace theColorSpace = gradient.getColorSpace();
+ final List<Color> theColors = gradient.getColors();
+ final List<Double> theBounds = gradient.getBounds();
+ final List<Double> theCoords = gradient.getCoordinates();
+
PDFShading myShad;
PDFFunction myfunky;
PDFFunction myfunc;
Modified: trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java 2009-04-18 19:47:38 UTC (rev 10721)
+++ trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java 2009-04-18 21:32:25 UTC (rev 10722)
@@ -36,6 +36,7 @@
import org.foray.common.CharacterOutputStream;
import org.foray.common.Mime;
+import org.foray.common.StringUtil;
import org.foray.common.WKConstants;
import org.foray.output.OutputConfig;
import org.foray.ps.BoundingBox4a;
@@ -44,6 +45,7 @@
import org.foray.ps.filter.RunLengthEncodeFilter;
import org.foray.render.PrintRenderer;
+import org.axsl.common.Gradient;
import org.axsl.common.value.RuleStyle;
import org.axsl.font.Font;
import org.axsl.font.FontUse;
@@ -1361,4 +1363,12 @@
return psFont.getName();
}
+ /**
+ * {@inheritDoc}
+ */
+ public String getGradientName(final Gradient gradient) {
+ /* TODO: Implement this. */
+ return StringUtil.EMPTY_STRING;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|