aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-08-26 18:59:42 +0000
committerJeremias Maerki <jeremias@apache.org>2006-08-26 18:59:42 +0000
commit787853f18abcb26442dd31270fe50d20fdddd1e2 (patch)
tree1fc03921d8572a20f6d4b86001645a3af4815d98
parentf97b8ac53e034a9ae8d986a8914f04d3e81058bc (diff)
downloadxmlgraphics-fop-787853f18abcb26442dd31270fe50d20fdddd1e2.tar.gz
xmlgraphics-fop-787853f18abcb26442dd31270fe50d20fdddd1e2.zip
My last attempt at fixing SVG gradients in PDF wasn't successful. This one is:
Improved resolution of transformation matrices in PDF patterns. Renamed PDFState.setTransform() to PDFState.concatenate() because setTransform() does a concationation and is therefore misleading. The old method is still there (just in case) but it is deprecated. Simplified the whole transformation tracking by including the basic page transformation in the stack. Verified the changes with basic-links in FO, fixed block-containers, a-links in SVG and SVG gradients. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@437210 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/pdf/PDFPattern.java6
-rw-r--r--src/java/org/apache/fop/pdf/PDFState.java9
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java2
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java21
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFSVGHandler.java39
-rw-r--r--src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java2
-rw-r--r--status.xml4
7 files changed, 42 insertions, 41 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFPattern.java b/src/java/org/apache/fop/pdf/PDFPattern.java
index 611ff5bbd..3bb190c48 100644
--- a/src/java/org/apache/fop/pdf/PDFPattern.java
+++ b/src/java/org/apache/fop/pdf/PDFPattern.java
@@ -250,7 +250,8 @@ public class PDFPattern extends PDFPathPaint {
vectorSize = this.matrix.size();
p.append("/Matrix [ ");
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt)));
+ p.append(PDFNumber.doubleOut(
+ ((Double)this.matrix.get(tempInt)).doubleValue(), 8));
p.append(" ");
}
p.append("] \n");
@@ -303,7 +304,8 @@ public class PDFPattern extends PDFPathPaint {
vectorSize = this.matrix.size();
p.append("/Matrix [ ");
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt)));
+ p.append(PDFNumber.doubleOut(
+ ((Double)this.matrix.get(tempInt)).doubleValue(), 8));
p.append(" ");
}
p.append("] \n");
diff --git a/src/java/org/apache/fop/pdf/PDFState.java b/src/java/org/apache/fop/pdf/PDFState.java
index 3946f0c02..e0a2eae1a 100644
--- a/src/java/org/apache/fop/pdf/PDFState.java
+++ b/src/java/org/apache/fop/pdf/PDFState.java
@@ -267,8 +267,17 @@ public class PDFState {
* the current graphic state.
*
* @param tf the transform to concatonate to the current level transform
+ * @deprecated This method name is misleading. Use concatenate(AffineTransform) instead!
*/
public void setTransform(AffineTransform tf) {
+ concatenate(tf);
+ }
+
+ /**
+ * Concatenates the given AffineTransform to the current one.
+ * @param tf the transform to concatenate to the current level transform
+ */
+ public void concatenate(AffineTransform tf) {
getData().concatenate(tf);
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java b/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
index 8c96d5c23..ce8c23149 100644
--- a/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
@@ -94,7 +94,7 @@ public class PDFGraphics2DAdapter extends AbstractGraphics2DAdapter {
AffineTransform transform = new AffineTransform();
transform.translate(fx, fy);
- pdfInfo.pdfState.setTransform(transform);
+ pdfInfo.pdfState.concatenate(transform);
graphics.setPDFState(pdfInfo.pdfState);
graphics.setOutputStream(pdfInfo.outputStream);
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index 0e3ff63e5..ae75b9290 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -208,9 +208,6 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
/** Optional URI to an output profile to be used. */
protected String outputProfileURI;
- /** The current Transform */
- protected AffineTransform currentBasicTransform;
-
/** drawing state */
protected PDFState currentState = null;
@@ -704,16 +701,11 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
.makeStream(PDFFilterList.CONTENT_FILTER, false);
currentState = new PDFState();
- /* This transform shouldn't affect PDFState as it only sets the basic
- * coordinate system for the rendering process.
- *
- currentState.setTransform(new AffineTransform(1, 0, 0, -1, 0,
- (int) Math.round(pageHeight / 1000)));
- */
- // Transform origin at top left to origin at bottom left
- currentBasicTransform = new AffineTransform(1, 0, 0, -1, 0,
+ // Transform the PDF's default coordinate system (0,0 at lower left) to the PDFRenderer's
+ AffineTransform basicPageTransform = new AffineTransform(1, 0, 0, -1, 0,
pageHeight / 1000f);
- currentStream.add(CTMHelper.toPDFString(currentBasicTransform, false) + " cm\n");
+ currentState.concatenate(basicPageTransform);
+ currentStream.add(CTMHelper.toPDFString(basicPageTransform, false) + " cm\n");
currentFontName = "";
@@ -736,7 +728,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
// Set the given CTM in the graphics state
currentState.push();
- currentState.setTransform(
+ currentState.concatenate(
new AffineTransform(CTMHelper.toPDFArray(ctm)));
saveGraphicsState();
@@ -1069,7 +1061,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
saveGraphicsState();
AffineTransform at = data.getTransform();
if (!at.isIdentity()) {
- currentState.setTransform(at);
+ currentState.concatenate(at);
at.getMatrix(matrix);
tempctm = new CTM(matrix[0], matrix[1], matrix[2], matrix[3],
matrix[4] * 1000, matrix[5] * 1000);
@@ -1130,7 +1122,6 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
// transform rect to absolute coords
AffineTransform transform = currentState.getTransform();
rect = transform.createTransformedShape(rect).getBounds2D();
- rect = currentBasicTransform.createTransformedShape(rect).getBounds2D();
int type = internal ? PDFLink.INTERNAL : PDFLink.EXTERNAL;
PDFLink pdflink = pdfDoc.getFactory().makeLink(
diff --git a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
index c8f5f71a6..cca185a04 100644
--- a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
@@ -26,16 +26,12 @@ import java.awt.Color;
import java.awt.geom.AffineTransform;
import org.w3c.dom.Document;
-import org.w3c.dom.svg.SVGAElement;
-import org.w3c.dom.svg.SVGDocument;
-import org.w3c.dom.svg.SVGSVGElement;
import org.apache.fop.render.AbstractGenericSVGHandler;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.RendererContextConstants;
import org.apache.fop.pdf.PDFDocument;
-import org.apache.fop.pdf.PDFNumber;
import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFState;
import org.apache.fop.pdf.PDFStream;
@@ -56,7 +52,6 @@ import org.apache.avalon.framework.configuration.Configuration;
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.BridgeContext;
-import org.apache.batik.bridge.ViewBox;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.util.SVGConstants;
@@ -173,11 +168,6 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
AffineTransform resolutionScaling = new AffineTransform();
resolutionScaling.scale(s, s);
- //Transformation matrix that establishes the local coordinate system for the SVG graphic
- //in relation to PDF's initial coordinate system.
- AffineTransform baseTransform = (AffineTransform)renderer.currentBasicTransform.clone();
- baseTransform.concatenate(pdfInfo.pdfState.getTransform());
-
GVTBuilder builder = new GVTBuilder();
//Controls whether text painted by Batik is generated using text or path operations
@@ -211,16 +201,12 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
AffineTransform scaling = new AffineTransform(
sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f);
- //Finish the baseTransform, now that we know everything
- baseTransform.concatenate(scaling);
- baseTransform.concatenate(resolutionScaling);
+ //Transformation matrix that establishes the local coordinate system for the SVG graphic
+ //in relation to the current coordinate system
+ AffineTransform imageTransform = new AffineTransform();
+ imageTransform.concatenate(scaling);
+ imageTransform.concatenate(resolutionScaling);
- //Now that we have the full baseTransform, we can update the transformation matrix for
- //the AElementBridge.
- PDFAElementBridge aBridge = (PDFAElementBridge)ctx.getBridge(
- SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG);
- aBridge.getCurrentTransform().setTransform(baseTransform);
-
/*
* Clip to the svg area.
* Note: To have the svg overlay (under) a text area then use
@@ -236,7 +222,7 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
pdfInfo.currentStream.add(CTMHelper.toPDFString(scaling, false) + " cm\n");
}
- SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
+ //SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
if (pdfInfo.pdfContext == null) {
pdfInfo.pdfContext = pdfInfo.pdfPage;
@@ -248,7 +234,8 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
if (!resolutionScaling.isIdentity()) {
- pdfInfo.currentStream.add("%resolution scaling for " + uaResolution + " -> " + deviceResolution + "\n");
+ pdfInfo.currentStream.add("%resolution scaling for " + uaResolution
+ + " -> " + deviceResolution + "\n");
pdfInfo.currentStream.add(
CTMHelper.toPDFString(resolutionScaling, false) + " cm\n");
graphics.scale(1 / s, 1 / s);
@@ -256,8 +243,16 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
pdfInfo.currentStream.add("%SVG start\n");
+ //Save state and update coordinate system for the SVG image
pdfInfo.pdfState.push();
- pdfInfo.pdfState.setTransform(baseTransform);
+ pdfInfo.pdfState.concatenate(imageTransform);
+
+ //Now that we have the complete transformation matrix for the image, we can update the
+ //transformation matrix for the AElementBridge.
+ PDFAElementBridge aBridge = (PDFAElementBridge)ctx.getBridge(
+ SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG);
+ aBridge.getCurrentTransform().setTransform(pdfInfo.pdfState.getTransform());
+
graphics.setPDFState(pdfInfo.pdfState);
graphics.setOutputStream(pdfInfo.outputStream);
try {
diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
index 74dac01fe..0e699dec7 100644
--- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
@@ -355,7 +355,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
scale(1 / s, 1 / s);
}
// Remember the transform we installed.
- graphicsState.setTransform(at);
+ graphicsState.concatenate(at);
pdfContext.increasePageCount();
}
diff --git a/status.xml b/status.xml
index 1f84b1963..9b4fa0b5c 100644
--- a/status.xml
+++ b/status.xml
@@ -28,6 +28,10 @@
<changes>
<release version="FOP Trunk">
+ <action context="Code" dev="JM" type="fix">
+ Bugfix: Corrected painting of shading patterns and position of links for SVG images
+ inside FO documents.
+ </action>
<action context="Code" dev="AD" type="update">
Minor fix: correctly set negative values to zero.
</action>