diff options
author | Keiron Liddle <keiron@apache.org> | 2002-06-18 13:42:56 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-06-18 13:42:56 +0000 |
commit | 64c1fb1421bb717edda576a916dc7a566967169c (patch) | |
tree | 106908e06d86a78e62b9bf364d76db1212a4483e /src/org/apache/fop/render/pdf | |
parent | 84be81fe4e07fab92ccbcd8d77fbf4c6d66a8c71 (diff) | |
download | xmlgraphics-fop-64c1fb1421bb717edda576a916dc7a566967169c.tar.gz xmlgraphics-fop-64c1fb1421bb717edda576a916dc7a566967169c.zip |
implemented links in svg both for standalone and in fo documents
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194898 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/render/pdf')
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFXMLHandler.java | 28 |
2 files changed, 32 insertions, 8 deletions
diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 9633c6b3e..c61c9cf86 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -33,6 +33,7 @@ import org.w3c.dom.Document; import java.io.IOException; import java.io.OutputStream; import java.awt.geom.Rectangle2D; +import java.awt.geom.AffineTransform; import java.util.HashMap; import java.util.List; @@ -99,6 +100,8 @@ public class PDFRenderer extends PrintRenderer { PDFPage currentPage; // drawing state + PDFState currentState = null; + PDFColor currentColor; String currentFontName = ""; int currentFontSize = 0; @@ -215,6 +218,9 @@ public class PDFRenderer extends PrintRenderer { pageReferences.put(page, currentPage.referencePDF()); } currentStream = this.pdfDoc.makeStream(); + + currentState = new PDFState(); + currentState.setTransform(new AffineTransform(1, 0, 0, -1, 0, (int) Math.round(pageHeight / 1000))); // Transform origin at top left to origin at bottom left currentStream.add("1 0 0 -1 0 " + (int) Math.round(pageHeight / 1000) + " cm\n"); @@ -233,6 +239,9 @@ public class PDFRenderer extends PrintRenderer { protected void startVParea(CTM ctm) { // Set the given CTM in the graphics state + currentState.push(); + currentState.setTransform(new AffineTransform(ctm.toArray())); + currentStream.add("q\n"); // multiply with current CTM currentStream.add(ctm.toPDFctm() + " cm\n"); @@ -243,6 +252,7 @@ public class PDFRenderer extends PrintRenderer { protected void endVParea() { currentStream.add("ET\n"); currentStream.add("Q\n"); + currentState.pop(); } protected void renderRegion(RegionReference region) { @@ -527,6 +537,8 @@ public class PDFRenderer extends PrintRenderer { context.setUserAgent(userAgent); context.setProperty(PDFXMLHandler.PDF_DOCUMENT, pdfDoc); + context.setProperty(PDFXMLHandler.PDF_STATE, currentState); + context.setProperty(PDFXMLHandler.PDF_PAGE, currentPage); context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream); context.setProperty(PDFXMLHandler.PDF_X, new Integer(currentBlockIPPosition)); context.setProperty(PDFXMLHandler.PDF_Y, new Integer(currentBPPosition)); diff --git a/src/org/apache/fop/render/pdf/PDFXMLHandler.java b/src/org/apache/fop/render/pdf/PDFXMLHandler.java index d5d2e5166..b0b95898e 100644 --- a/src/org/apache/fop/render/pdf/PDFXMLHandler.java +++ b/src/org/apache/fop/render/pdf/PDFXMLHandler.java @@ -44,6 +44,8 @@ import java.awt.geom.AffineTransform; */ public class PDFXMLHandler implements XMLHandler { public static final String PDF_DOCUMENT = "pdfDoc"; +public static final String PDF_STATE = "pdfState"; +public static final String PDF_PAGE = "pdfPage"; public static final String PDF_STREAM = "pdfStream"; public static final String PDF_X = "x"; public static final String PDF_Y = "y"; @@ -71,6 +73,8 @@ public static final String PDF_YPOS = "ypos"; public static PDFInfo getPDFInfo(RendererContext context) { PDFInfo pdfi = new PDFInfo(); pdfi.pdfDoc = (PDFDocument)context.getProperty(PDF_DOCUMENT); + pdfi.pdfState = (PDFState)context.getProperty(PDF_STATE); + pdfi.pdfPage = (PDFPage)context.getProperty(PDF_PAGE); pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM); pdfi.x = ((Integer)context.getProperty(PDF_X)).intValue(); pdfi.y = ((Integer)context.getProperty(PDF_Y)).intValue(); @@ -84,6 +88,8 @@ public static final String PDF_YPOS = "ypos"; public static class PDFInfo { PDFDocument pdfDoc; + PDFState pdfState; + PDFPage pdfPage; public PDFStream currentStream; int x; int y; @@ -108,12 +114,14 @@ public static final String PDF_YPOS = "ypos"; GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(ua); - TextPainter textPainter = null; - textPainter = new PDFTextPainter(pdfInfo.fs); - ctx.setTextPainter(textPainter); + PDFTextElementBridge tBridge = new PDFTextElementBridge(pdfInfo.fs); + ctx.putBridge(tBridge); PDFAElementBridge aBridge = new PDFAElementBridge(); - aBridge.setCurrentTransform(new AffineTransform(sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f)); + // to get the correct transform we need to use the PDFState + AffineTransform transform = pdfInfo.pdfState.getTransform(); + transform.translate(xOffset / 1000f, yOffset / 1000f); + aBridge.setCurrentTransform(transform); ctx.putBridge(aBridge); GraphicsNode root; @@ -156,12 +164,17 @@ public static final String PDF_YPOS = "ypos"; } PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fs, pdfInfo.pdfDoc, - pdfInfo.currentFontName, + pdfInfo.pdfPage, pdfInfo.currentFontName, pdfInfo.currentFontSize, pdfInfo.currentXPosition, pdfInfo.currentYPosition); graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); - + pdfInfo.pdfState.push(); + transform = new AffineTransform(); + // TODO scale to viewbox + transform.translate(xOffset / 1000f, yOffset / 1000f); + pdfInfo.pdfState.setTransform(transform); + graphics.setPDFState(pdfInfo.pdfState); try { root.paint(graphics); pdfInfo.currentStream.add(graphics.getString()); @@ -170,9 +183,8 @@ public static final String PDF_YPOS = "ypos"; + e.getMessage(), e); } - //currentAnnotList = graphics.getAnnotList(); - pdfInfo.currentStream.add("Q\n"); + pdfInfo.pdfState.pop(); } } } |