keiron 2002/11/03 08:24:22
Modified: src/org/apache/fop/area AreaTree.java
CachedRenderPagesModel.java PageViewport.java
Trait.java
src/org/apache/fop/datatypes ColorType.java
src/org/apache/fop/fo/flow BasicLink.java
src/org/apache/fop/pdf PDFDocument.java PDFGoTo.java
PDFPage.java
src/org/apache/fop/render/pdf PDFRenderer.java
src/org/apache/fop/svg PDFGraphics2D.java
src/org/apache/fop/traits BorderProps.java
Log:
fixed link/resolving problem
made sure area tree is serializable
Revision Changes Path
1.11 +23 -10 xml-fop/src/org/apache/fop/area/AreaTree.java
Index: AreaTree.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/AreaTree.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AreaTree.java 1 Nov 2002 10:49:34 -0000 1.10
+++ AreaTree.java 3 Nov 2002 16:24:21 -0000 1.11
@@ -397,23 +397,31 @@
public void addPage(PageViewport page) {
super.addPage(page);
- // check prepared pages
- boolean cont = checkPreparedPages();
-
- // if page finished
- if (cont && page.isResolved()) {
+ // for links the renderer needs to prepare the page
+ // it is more appropriate to do this after queued pages but
+ // it will mean that the renderer has not prepared a page that
+ // could be referenced
+ boolean done = renderer.supportsOutOfOrder() && page.isResolved();
+ if (done) {
try {
renderer.renderPage(page);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
+ e.printStackTrace();
}
page.clear();
} else {
preparePage(page);
}
- renderExtensions(pendingExt);
- pendingExt.clear();
+
+ // check prepared pages
+ boolean cont = checkPreparedPages(page);
+
+ if (cont) {
+ renderExtensions(pendingExt);
+ pendingExt.clear();
+ }
}
/**
@@ -422,7 +430,7 @@
* false if the renderer doesn't support out of order
* rendering and there are pending pages
*/
- protected boolean checkPreparedPages() {
+ protected boolean checkPreparedPages(PageViewport newpage) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport p = (PageViewport)iter.next();
if (p.isResolved()) {
@@ -430,6 +438,7 @@
renderer.renderPage(p);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
+ e.printStackTrace();
}
p.clear();
iter.remove();
@@ -491,7 +500,11 @@
*/
public void endDocument() {
// render any pages that had unresolved ids
- checkPreparedPages();
+ checkPreparedPages(null);
+
+ renderExtensions(pendingExt);
+ pendingExt.clear();
+
renderExtensions(endDocExt);
}
}
1.2 +26 -22 xml-fop/src/org/apache/fop/area/CachedRenderPagesModel.java
Index: CachedRenderPagesModel.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/CachedRenderPagesModel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CachedRenderPagesModel.java 9 Sep 2002 05:58:14 -0000 1.1
+++ CachedRenderPagesModel.java 3 Nov 2002 16:24:21 -0000 1.2
@@ -45,30 +45,33 @@
* false if the renderer doesn't support out of order
* rendering and there are pending pages
*/
- protected boolean checkPreparedPages() {
+ protected boolean checkPreparedPages(PageViewport newpage) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport p = (PageViewport)iter.next();
if (p.isResolved()) {
- try {
- // load page from cache
- String name = (String)pageMap.get(p);
- File temp = new File(name);
- System.out.println("page serialized to: " + temp.length());
- ObjectInputStream in = new ObjectInputStream(
- new BufferedInputStream(
- new FileInputStream(temp)));
- p.loadPage(in);
- in.close();
- temp.delete();
- pageMap.remove(p);
- } catch (Exception e) {
- e.printStackTrace();
+ if(p != newpage) {
+ try {
+ // load page from cache
+ String name = (String)pageMap.get(p);
+ File temp = new File(name);
+ System.out.println("page serialized to: " + temp.length());
+ ObjectInputStream in = new ObjectInputStream(
+ new BufferedInputStream(
+ new FileInputStream(temp)));
+ p.loadPage(in);
+ in.close();
+ temp.delete();
+ pageMap.remove(p);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
try {
renderer.renderPage(p);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
+ e.printStackTrace();
}
p.clear();
iter.remove();
@@ -78,18 +81,19 @@
}
}
}
+ if(newpage != null && newpage.getPage() != null) {
+ savePage(newpage);
+ }
return renderer.supportsOutOfOrder() || prepared.isEmpty();
}
/**
- * Prepare a page.
- * This uses the parent to prepare the page.
- * It then saves the contents of the page to a file.
+ * Save a page.
+ * It saves the contents of the page to a file.
+ *
* @param page the page to prepare
*/
- protected void preparePage(PageViewport page) {
- super.preparePage(page);
-
+ protected void savePage(PageViewport page) {
try {
// save page to cache
ObjectOutputStream tempstream;
1.9 +12 -1 xml-fop/src/org/apache/fop/area/PageViewport.java
Index: PageViewport.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/PageViewport.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PageViewport.java 16 Sep 2002 07:35:46 -0000 1.8
+++ PageViewport.java 3 Nov 2002 16:24:21 -0000 1.9
@@ -90,6 +90,17 @@
}
/**
+ * Get the key for this page viewport.
+ * This is used so that a serializable key can be used to
+ * lookup the page or some other reference.
+ *
+ * @return a unique page viewport key for this area tree
+ */
+ public String getKey() {
+ return toString();
+ }
+
+ /**
* Add an unresolved id to this page.
* All unresolved ids for the contents of this page are
* added to this page. This is so that the resolvers can be
1.8 +3 -3 xml-fop/src/org/apache/fop/area/Trait.java
Index: Trait.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/Trait.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Trait.java 1 Nov 2002 10:49:34 -0000 1.7
+++ Trait.java 3 Nov 2002 16:24:21 -0000 1.8
@@ -117,7 +117,7 @@
shmTraitInfo = new HashMap();
shmTraitInfo.put(ID_LINK, new TraitInfo("id-link", String.class));
shmTraitInfo.put(INTERNAL_LINK,
- new TraitInfo("internal-link", PageViewport.class));
+ new TraitInfo("internal-link", String.class));
shmTraitInfo.put(EXTERNAL_LINK,
new TraitInfo("external-link", String.class));
shmTraitInfo.put(FONT_NAME,
@@ -229,7 +229,7 @@
return null;
}
- public static class Background {
+ public static class Background implements Serializable {
public ColorType color = null;
public String url = null;
public int repeat;
1.20 +3 -2 xml-fop/src/org/apache/fop/datatypes/ColorType.java
Index: ColorType.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/ColorType.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ColorType.java 25 Oct 2002 09:29:40 -0000 1.19
+++ ColorType.java 3 Nov 2002 16:24:21 -0000 1.20
@@ -8,11 +8,12 @@
package org.apache.fop.datatypes;
import java.util.*;
+import java.io.Serializable;
/**
* a colour quantity in XSL
*/
-public class ColorType {
+public class ColorType implements Serializable {
/**
* the red component
1.17 +3 -3 xml-fop/src/org/apache/fop/fo/flow/BasicLink.java
Index: BasicLink.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/BasicLink.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- BasicLink.java 9 Sep 2002 05:58:15 -0000 1.16
+++ BasicLink.java 3 Nov 2002 16:24:21 -0000 1.17
@@ -63,7 +63,7 @@
} else {
PageViewport page = parentLM.resolveRefID(link);
if (page != null) {
- area.addTrait(Trait.INTERNAL_LINK, page);
+ area.addTrait(Trait.INTERNAL_LINK, page.getKey());
} else {
LinkResolver res = new LinkResolver(link, area);
parentLM.addUnresolvedArea(link, res);
@@ -148,7 +148,7 @@
resolved = true;
if (idRef.equals(id) && pages != null) {
PageViewport page = (PageViewport)pages.get(0);
- area.addTrait(Trait.INTERNAL_LINK, page);
+ area.addTrait(Trait.INTERNAL_LINK, page.getKey());
}
}
}
1.56 +13 -8 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.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- PDFDocument.java 25 Oct 2002 09:29:46 -0000 1.55
+++ PDFDocument.java 3 Nov 2002 16:24:21 -0000 1.56
@@ -1229,7 +1229,7 @@
* @return the PDFLink object created
*/
public PDFLink makeLink(Rectangle2D rect, String destination,
- int linkType) {
+ int linkType, float yoffset) {
PDFLink linkObject;
PDFAction action;
@@ -1240,7 +1240,10 @@
if (linkType == PDFLink.EXTERNAL) {
// check destination
- if (destination.endsWith(".pdf")) { // FileSpec
+ if (destination.startsWith("http://")) {
+ PDFUri uri = new PDFUri(destination);
+ link.setAction(uri);
+ } else if (destination.endsWith(".pdf")) { // FileSpec
PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount,
destination);
this.objects.add(fileSpec);
@@ -1267,17 +1270,19 @@
PDFUri uri = new PDFUri(destination);
link.setAction(uri);
}
- } else { // linkType is internal
- String goToReference = getGoToReference(destination);
+ } else {
+ // linkType is internal
+ String goToReference = getGoToReference(destination, yoffset);
PDFInternalLink internalLink = new PDFInternalLink(goToReference);
link.setAction(internalLink);
}
return link;
}
- private String getGoToReference(String destination) {
+ private String getGoToReference(String destination, float yoffset) {
String goToReference = null;
PDFGoTo gt = new PDFGoTo(++this.objectcount, destination);
+ gt.setYPosition(yoffset);
goToReference = gt.referencePDF();
addTrailerObject(gt);
return goToReference;
@@ -1383,8 +1388,8 @@
* @return the new PDF outline object
*/
public PDFOutline makeOutline(PDFOutline parent, String label,
- String destination) {
- String goToRef = getGoToReference(destination);
+ String destination, float yoffset) {
+ String goToRef = getGoToReference(destination, yoffset);
PDFOutline obj = new PDFOutline(++this.objectcount, label, goToRef);
1.7 +3 -3 xml-fop/src/org/apache/fop/pdf/PDFGoTo.java
Index: PDFGoTo.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFGoTo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PDFGoTo.java 7 Sep 2001 09:26:16 -0000 1.6
+++ PDFGoTo.java 3 Nov 2002 16:24:22 -0000 1.7
@@ -52,8 +52,8 @@
*
* @param yPosition y position
*/
- public void setYPosition(int yPosition) {
- this.yPosition = (yPosition / 1000f);
+ public void setYPosition(float yPosition) {
+ this.yPosition = yPosition;
}
public void setDestination(String dest) {
1.17 +1 -2 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- PDFPage.java 28 Jun 2002 10:09:06 -0000 1.16
+++ PDFPage.java 3 Nov 2002 16:24:22 -0000 1.17
@@ -121,7 +121,6 @@
}
sb = sb.append(">>\nendobj\n");
-
return sb.toString().getBytes();
}
1.126 +24 -10 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.125
retrieving revision 1.126
diff -u -r1.125 -r1.126
--- PDFRenderer.java 1 Nov 2002 10:49:35 -0000 1.125
+++ PDFRenderer.java 3 Nov 2002 16:24:22 -0000 1.126
@@ -109,6 +109,7 @@
* for pdf this means we need the pdf page reference
*/
protected HashMap pageReferences = new HashMap();
+ protected HashMap pvReferences = new HashMap();
private String producer;
@@ -273,14 +274,18 @@
private void renderOutline(BookmarkData outline, PDFOutline parentOutline) {
PDFOutline outlineRoot = pdfDoc.getOutlineRoot();
PDFOutline pdfOutline = null;
- String intDest = (String)pageReferences.get(outline.getPage());
+ PageViewport pv = outline.getPage();
+ Rectangle2D bounds = pv.getViewArea();
+ double h = bounds.getHeight();
+ float yoffset = (float)h / 1000f;
+ String intDest = (String)pageReferences.get(pv.getKey());
if (parentOutline == null) {
pdfOutline = pdfDoc.makeOutline(outlineRoot,
- outline.getLabel(), intDest);
+ outline.getLabel(), intDest, yoffset);
} else {
PDFOutline pdfParentOutline = parentOutline;
pdfOutline = pdfDoc.makeOutline(pdfParentOutline,
- outline.getLabel(), intDest);
+ outline.getLabel(), intDest, yoffset);
}
for (int i = 0; i < outline.getCount(); i++) {
@@ -315,7 +320,8 @@
pages = new HashMap();
}
pages.put(page, currentPage);
- pageReferences.put(page, currentPage.referencePDF());
+ pageReferences.put(page.getKey(), currentPage.referencePDF());
+ pvReferences.put(page.getKey(), page);
}
/**
@@ -339,7 +345,8 @@
pageHeight = (int) h;
currentPage = this.pdfDoc.makePage(this.pdfResources,
(int) Math.round(w / 1000), (int) Math.round(h /
1000));
- pageReferences.put(page, currentPage.referencePDF());
+ pageReferences.put(page.getKey(), currentPage.referencePDF());
+ pvReferences.put(page.getKey(), page);
}
currentStream =
this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER, false);
@@ -678,12 +685,19 @@
Object tr = ip.getTrait(Trait.INTERNAL_LINK);
boolean internal = false;
String dest = null;
+ float yoffset = 0;
if (tr == null) {
dest = (String)ip.getTrait(Trait.EXTERNAL_LINK);
} else {
- PageViewport pv = (PageViewport)tr;
- dest = (String)pageReferences.get(pv);
- internal = true;
+ String pvKey = (String)tr;
+ dest = (String)pageReferences.get(pvKey);
+ if(dest != null) {
+ PageViewport pv = (PageViewport)pvReferences.get(pvKey);
+ Rectangle2D bounds = pv.getViewArea();
+ double h = bounds.getHeight();
+ yoffset = (float)h / 1000f;
+ internal = true;
+ }
}
if (dest != null) {
// add link to pdf document
@@ -693,7 +707,7 @@
rect = transform.createTransformedShape(rect).getBounds();
int type = internal ? PDFLink.INTERNAL : PDFLink.EXTERNAL;
- PDFLink pdflink = pdfDoc.makeLink(rect, dest, type);
+ PDFLink pdflink = pdfDoc.makeLink(rect, dest, type, yoffset);
currentPage.addAnnotation(pdflink);
}
}
1.43 +3 -3 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.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- PDFGraphics2D.java 11 Sep 2002 09:51:13 -0000 1.42
+++ PDFGraphics2D.java 3 Nov 2002 16:24:22 -0000 1.43
@@ -277,7 +277,7 @@
resourceContext.addAnnotation(pdfDoc.makeLink(rect, pageRef, pdfdest));
} else {
resourceContext.addAnnotation(pdfDoc.makeLink(rect,
- dest, linkType));
+ dest, linkType, 0));
}
}
1.3 +8 -2 xml-fop/src/org/apache/fop/traits/BorderProps.java
Index: BorderProps.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/traits/BorderProps.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BorderProps.java 13 Sep 2002 08:21:55 -0000 1.2
+++ BorderProps.java 3 Nov 2002 16:24:22 -0000 1.3
@@ -9,7 +9,13 @@
import org.apache.fop.datatypes.ColorType;
-public class BorderProps {
+import java.io.Serializable;
+
+/**
+ * Border properties.
+ * Class to store border trait propties for the area tree.
+ */
+public class BorderProps implements Serializable {
public int style; // Enum for border style
public ColorType color; // Border color
public int width; // Border width
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]