You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2002/06/18 15:42:56 UTC
cvs commit: xml-fop/src/org/apache/fop/svg PDFANode.java PDFDocumentGraphics2D.java PDFGraphics2D.java PDFTextElementBridge.java PDFTranscoder.java
keiron 2002/06/18 06:42:56
Modified: src/org/apache/fop/area CTM.java
src/org/apache/fop/pdf PDFAnnotList.java PDFDocument.java
PDFLink.java PDFPage.java PDFState.java
src/org/apache/fop/render/pdf PDFRenderer.java
PDFXMLHandler.java
src/org/apache/fop/svg PDFANode.java
PDFDocumentGraphics2D.java PDFGraphics2D.java
PDFTextElementBridge.java PDFTranscoder.java
Log:
implemented links in svg both for standalone and in fo documents
Revision Changes Path
1.4 +5 -1 xml-fop/src/org/apache/fop/area/CTM.java
Index: CTM.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/CTM.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CTM.java 23 Feb 2002 16:47:37 -0000 1.3
+++ CTM.java 18 Jun 2002 13:42:55 -0000 1.4
@@ -210,4 +210,8 @@
public String toPDFctm() {
return a + " " + b + " " + c + " " + d + " " + e/1000f + " " + f/1000f;
}
+
+ public double[] toArray() {
+ return new double[] {a, b, c, d, e / 1000.0, f / 1000.0};
+ }
}
1.4 +2 -2 xml-fop/src/org/apache/fop/pdf/PDFAnnotList.java
Index: PDFAnnotList.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFAnnotList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PDFAnnotList.java 30 Jul 2001 20:29:29 -0000 1.3
+++ PDFAnnotList.java 18 Jun 2002 13:42:56 -0000 1.4
@@ -44,7 +44,7 @@
*
* @param link the PDFLink to add.
*/
- public void addLink(PDFLink link) {
+ public void addAnnot(PDFObject link) {
this.links.addElement(link);
this.count++;
}
1.38 +17 -2 xml-fop/src/org/apache/fop/pdf/PDFDocument.java
Index: PDFDocument.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- PDFDocument.java 17 May 2002 14:47:13 -0000 1.37
+++ PDFDocument.java 18 Jun 2002 13:42:56 -0000 1.38
@@ -28,6 +28,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.awt.Rectangle;
/**
@@ -953,7 +954,7 @@
* create a PDFPage with the next object number, the given
* resources, contents and dimensions
*/
- PDFPage page = new PDFPage(++this.objectcount, resources,
+ PDFPage page = new PDFPage(this, ++this.objectcount, resources,
pagewidth, pageheight);
/* add it to the list of objects */
@@ -965,6 +966,20 @@
public void addPage(PDFPage page) {
/* add it to the list of objects */
this.objects.add(page);
+
+ if(pendingLinks != null) {
+ for(Iterator iter = pendingLinks.iterator(); iter.hasNext(); ) {
+ PendingLink pl = (PendingLink)iter.next();
+ PDFGoTo gt = new PDFGoTo(++this.objectcount,
+ page.referencePDF());
+ gt.setDestination(pl.dest);
+ addTrailerObject(gt);
+ PDFInternalLink internalLink =
+ new PDFInternalLink(gt.referencePDF());
+ pl.link.setAction(internalLink);
+ }
+ pendingLinks = null;
+ }
}
/**
1.7 +3 -3 xml-fop/src/org/apache/fop/pdf/PDFLink.java
Index: PDFLink.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFLink.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PDFLink.java 30 Jul 2001 20:29:30 -0000 1.6
+++ PDFLink.java 18 Jun 2002 13:42:56 -0000 1.7
@@ -52,8 +52,8 @@
public byte[] toPDF() {
String p = this.number + " " + this.generation + " obj\n"
+ "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ "
- + (ulx / 1000f) + " " + (uly / 1000f) + " "
- + (brx / 1000f) + " " + (bry / 1000f) + " ]\n" + "/C [ "
+ + (ulx) + " " + (uly) + " "
+ + (brx) + " " + (bry) + " ]\n" + "/C [ "
+ this.color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A "
+ this.action.getAction() + "\n" + "/H /I\n>>\nendobj\n";
return p.getBytes();
1.14 +11 -14 xml-fop/src/org/apache/fop/pdf/PDFPage.java
Index: PDFPage.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPage.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PDFPage.java 12 Nov 2001 13:10:11 -0000 1.13
+++ PDFPage.java 18 Jun 2002 13:42:56 -0000 1.14
@@ -52,6 +52,7 @@
* the list of annotation objects for this page
*/
protected PDFAnnotList annotList;
+ protected PDFDocument document;
/**
* create a /Page object
@@ -62,13 +63,14 @@
* @param pagewidth the page's width in points
* @param pageheight the page's height in points
*/
- public PDFPage(int number, PDFResources resources, PDFStream contents,
+ public PDFPage(PDFDocument doc, int number, PDFResources resources, PDFStream contents,
int pagewidth, int pageheight) {
/* generic creation of object */
super(number);
/* set fields using parameters */
+ this.document = doc;
this.resources = resources;
this.contents = contents;
this.pagewidth = pagewidth;
@@ -85,13 +87,14 @@
* @param pagewidth the page's width in points
* @param pageheight the page's height in points
*/
- public PDFPage(int number, PDFResources resources,
+ public PDFPage(PDFDocument doc, int number, PDFResources resources,
int pagewidth, int pageheight) {
/* generic creation of object */
super(number);
/* set fields using parameters */
+ this.document = doc;
this.resources = resources;
this.pagewidth = pagewidth;
this.pageheight = pageheight;
@@ -122,17 +125,11 @@
*
* @param annotList a PDFAnnotList list of annotations
*/
- public void setAnnotList(PDFAnnotList annotList) {
- this.annotList = annotList;
- }
-
- /**
- * get this page's annotation list
- *
- * @return annotList a PDFAnnotList list of annotations
- */
- public PDFAnnotList getAnnotList() {
- return this.annotList;
+ public void addAnnotation(PDFObject annot) {
+ if(this.annotList == null) {
+ this.annotList = document.makeAnnotList();
+ }
+ this.annotList.addAnnot(annot);
}
public void addShading(PDFShading shading) {
1.3 +24 -12 xml-fop/src/org/apache/fop/pdf/PDFState.java
Index: PDFState.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFState.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PDFState.java 9 Nov 2001 11:32:41 -0000 1.2
+++ PDFState.java 18 Jun 2002 13:42:56 -0000 1.3
@@ -10,9 +10,11 @@
import java.awt.Shape;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.awt.Color;
import java.awt.Paint;
+import java.awt.geom.AffineTransform;
/**
* This keeps information about the current state when writing to pdf.
@@ -57,7 +59,7 @@
boolean text = false;
int dashOffset = 0;
int[] dashArray = new int[0];
- double[] transform = new double[]{1, 0, 0, 1, 0, 0};
+ AffineTransform transform = new AffineTransform();
float fontSize = 0;
String fontName = "";
Shape clip = null;
@@ -89,6 +91,8 @@
saveMap.put(CLIP, clip);
stateStack.add(saveMap);
+
+ transform = new AffineTransform();
}
public void pop() {
@@ -106,7 +110,7 @@
text = ((Boolean)saveMap.get(TEXT)).booleanValue();
dashOffset = ((Integer)saveMap.get(DASHOFFSET)).intValue();
dashArray = (int[])saveMap.get(DASHARRAY);
- transform = (double[])saveMap.get(TRANSFORM);
+ transform = (AffineTransform)saveMap.get(TRANSFORM);
fontSize = ((Float)saveMap.get(FONTSIZE)).floatValue();
fontName = (String)saveMap.get(FONTNAME);
clip = (Shape)saveMap.get(CLIP);
@@ -165,17 +169,25 @@
clip = cl;
}
- public boolean checkTransform(double[] vals) {
- for(int count = 0; count < transform.length; count++) {
- if(transform[count] != vals[count]) {
- return true;
- }
- }
- return false;
+ public boolean checkTransform(AffineTransform tf) {
+ return !tf.equals(transform);
}
- public void setTransform(double[] vals) {
- transform = vals;
+ public void setTransform(AffineTransform tf) {
+ transform.concatenate(tf);
+ }
+
+ public AffineTransform getTransform() {
+ AffineTransform tf;
+ AffineTransform at = new AffineTransform();
+ for(Iterator iter = stateStack.iterator(); iter.hasNext(); ) {
+ HashMap map = (HashMap)iter.next();
+ tf = (AffineTransform)map.get(TRANSFORM);
+ at.concatenate(tf);
+ }
+ at.concatenate(transform);
+
+ return at;
}
}
1.103 +13 -1 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
Index: PDFRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- PDFRenderer.java 26 May 2002 15:02:43 -0000 1.102
+++ PDFRenderer.java 18 Jun 2002 13:42:56 -0000 1.103
@@ -33,6 +33,7 @@
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 @@
PDFPage currentPage;
// drawing state
+ PDFState currentState = null;
+
PDFColor currentColor;
String currentFontName = "";
int currentFontSize = 0;
@@ -215,6 +218,9 @@
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 @@
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 @@
protected void endVParea() {
currentStream.add("ET\n");
currentStream.add("Q\n");
+ currentState.pop();
}
protected void renderRegion(RegionReference region) {
@@ -527,6 +537,8 @@
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));
1.5 +21 -9 xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java
Index: PDFXMLHandler.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PDFXMLHandler.java 11 Apr 2002 09:33:31 -0000 1.4
+++ PDFXMLHandler.java 18 Jun 2002 13:42:56 -0000 1.5
@@ -44,6 +44,8 @@
*/
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 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 class PDFInfo {
PDFDocument pdfDoc;
+ PDFState pdfState;
+ PDFPage pdfPage;
public PDFStream currentStream;
int x;
int y;
@@ -108,12 +114,14 @@
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 @@
}
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 @@
+ e.getMessage(), e);
}
- //currentAnnotList = graphics.getAnnotList();
-
pdfInfo.currentStream.add("Q\n");
+ pdfInfo.pdfState.pop();
}
}
}
1.7 +14 -5 xml-fop/src/org/apache/fop/svg/PDFANode.java
Index: PDFANode.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFANode.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PDFANode.java 29 May 2002 13:53:41 -0000 1.6
+++ PDFANode.java 18 Jun 2002 13:42:56 -0000 1.7
@@ -59,11 +59,11 @@
Shape outline = getOutline();
if(destination.startsWith("#svgView(viewBox(")) {
type = org.apache.fop.layout.LinkSet.INTERNAL;
- String nums = destination.substring(18, destination.length() - 2);
+ String nums = destination.substring(17, destination.length() - 2);
float x = 0;
float y = 0;
float width = 0;
- float height;
+ float height = 0;
int count = 0;
try {
StringTokenizer st = new StringTokenizer(nums, ",");
@@ -88,12 +88,21 @@
}
}
} catch(Exception e) {
+ e.printStackTrace();
}
+ Rectangle2D destRect = new Rectangle2D.Float(x, y, width, height);
+ destRect = transform.createTransformedShape(destRect).getBounds();
// these numbers need conversion to current
// svg position and scaled for the page
- destination = "" + x + " " + y + " " + 200 / width;
+ x = (float)destRect.getX();
+ y = (float)destRect.getY();
+ width = (float)destRect.getWidth();
+ height = (float)destRect.getHeight();
+
+ destination = "" + x + " " + y + " "
+ + (x + width) + " " + (y + height);
}
- pdfg.addLink(outline, transform, destination, type);
+ pdfg.addLink(getBounds(), transform, destination, type);
}
}
}
1.16 +2 -6 xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java
Index: PDFDocumentGraphics2D.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- PDFDocumentGraphics2D.java 15 Nov 2001 08:12:35 -0000 1.15
+++ PDFDocumentGraphics2D.java 18 Jun 2002 13:42:56 -0000 1.16
@@ -37,7 +37,6 @@
public class PDFDocumentGraphics2D extends PDFGraphics2D {
OutputStream stream;
- PDFPage currentPage;
PDFStream pdfStream;
int width;
int height;
@@ -156,9 +155,6 @@
PDFResources pdfResources = this.pdfDoc.getResources();
currentPage.setContents(pdfStream);
this.pdfDoc.addPage(currentPage);
- if(currentAnnotList != null) {
- currentPage.setAnnotList(currentAnnotList);
- }
if (fontInfo != null) {
FontSetup.addToResources(this.pdfDoc, fontInfo);
}
1.28 +16 -25 xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java
Index: PDFGraphics2D.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- PDFGraphics2D.java 29 May 2002 13:53:41 -0000 1.27
+++ PDFGraphics2D.java 18 Jun 2002 13:42:56 -0000 1.28
@@ -51,17 +51,13 @@
* the PDF Document being created
*/
protected PDFDocument pdfDoc;
+ protected PDFPage currentPage;
/**
* the current state of the pdf graphics
*/
PDFState graphicsState;
- /**
- * the current annotation list to add annotations to
- */
- PDFAnnotList currentAnnotList = null;
-
protected FontState fontState;
protected FontState ovFontState = null;
@@ -110,9 +106,10 @@
* existing document.
*/
public PDFGraphics2D(boolean textAsShapes, FontState fs, PDFDocument doc,
- String font, int size, int xpos, int ypos) {
+ PDFPage page, String font, int size, int xpos, int ypos) {
super(textAsShapes);
pdfDoc = doc;
+ currentPage = page;
currentFontName = font;
currentFontSize = size;
currentYPosition = ypos;
@@ -125,6 +122,10 @@
super(textAsShapes);
}
+ public void setPDFState(PDFState state) {
+ graphicsState = state;
+ }
+
public String getString() {
return currentStream.toString();
}
@@ -158,32 +159,22 @@
* This is a pdf specific method used to add a link to the
* pdf document.
*/
- public void addLink(Shape bounds, AffineTransform trans, String dest, int linkType) {
- if(currentAnnotList == null) {
- currentAnnotList = pdfDoc.makeAnnotList();
- }
+ public void addLink(Rectangle2D bounds, AffineTransform trans, String dest, int linkType) {
AffineTransform at = getTransform();
Shape b = at.createTransformedShape(bounds);
b = trans.createTransformedShape(b);
Rectangle rect = b.getBounds();
- // this handles the / 1000 in PDFLink
- rect.x = rect.x * 1000;
- rect.y = rect.y * 1000;
- rect.height = -rect.height * 1000;
- rect.width = rect.width * 1000;
+ rect.height = -rect.height;
+
if(linkType != LinkSet.EXTERNAL) {
- String pdfdest = "/XYZ " + dest;
- currentAnnotList.addLink(pdfDoc.makeLinkCurrentPage(rect, pdfdest));
+ String pdfdest = "/FitR " + dest;
+ currentPage.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, pdfdest));
} else {
- currentAnnotList.addLink(pdfDoc.makeLink(rect,
+ currentPage.addAnnotation(pdfDoc.makeLink(rect,
dest, linkType));
}
}
- public PDFAnnotList getAnnotList() {
- return currentAnnotList;
- }
-
public void addJpegImage(JpegImage jpeg, float x, float y, float width, float height) {
int xObjectNum = this.pdfDoc.addImage(jpeg);
@@ -545,7 +536,7 @@
Shape imclip = getClip();
boolean newClip = graphicsState.checkClip(imclip);
- boolean newTransform = graphicsState.checkTransform(tranvals);
+ boolean newTransform = graphicsState.checkTransform(trans);
if(newClip || newTransform) {
currentStream.write("q\n");
1.4 +3 -3 xml-fop/src/org/apache/fop/svg/PDFTextElementBridge.java
Index: PDFTextElementBridge.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTextElementBridge.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PDFTextElementBridge.java 21 Mar 2002 09:28:43 -0000 1.3
+++ PDFTextElementBridge.java 18 Jun 2002 13:42:56 -0000 1.4
@@ -91,9 +91,9 @@
}
}
- if(CSSUtilities.convertFilter(element, node, ctx) != null) {
+ /*if(CSSUtilities.convertFilter(element, node, ctx) != null) {
return false;
- }
+ }*/
return true;
}
1.18 +5 -4 xml-fop/src/org/apache/fop/svg/PDFTranscoder.java
Index: PDFTranscoder.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTranscoder.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- PDFTranscoder.java 21 Mar 2002 09:28:43 -0000 1.17
+++ PDFTranscoder.java 18 Jun 2002 13:42:56 -0000 1.18
@@ -124,9 +124,10 @@
* @version $Id$
*/
public class PDFTranscoder extends XMLAbstractTranscoder {
-
+ /*
public static final TranscodingHints.Key KEY_STROKE_TEXT =
- new StringKey();
+ new BooleanKey();
+ */
/**
* The user agent dedicated to an <tt>ImageTranscoder</tt>.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org