From 804a2ba264030f4ff6a25b3f23ff16cb47593ff1 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 13 Aug 2008 07:13:52 +0000 Subject: [PATCH] Added document-trailer element to the IF (for example for the bookmark tree). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@685472 13f79535-47bb-0310-9956-ffa450edef68 --- .../intermediate/AbstractIFPainter.java | 40 +++++++++++++++++++ .../fop/render/intermediate/IFConstants.java | 1 + .../fop/render/intermediate/IFPainter.java | 20 ++++++++++ .../fop/render/intermediate/IFParser.java | 13 ++++++ .../fop/render/intermediate/IFRenderer.java | 2 + .../fop/render/intermediate/IFSerializer.java | 18 +++++++++ .../org/apache/fop/render/pdf/PDFPainter.java | 20 ---------- .../org/apache/fop/render/svg/SVGPainter.java | 17 +------- 8 files changed, 95 insertions(+), 36 deletions(-) diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java index c7d6a578b..5f904858f 100644 --- a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java @@ -83,6 +83,46 @@ public abstract class AbstractIFPainter implements IFPainter { return this.userAgent; } + /** {@inheritDoc} */ + public void startDocumentHeader() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void endDocumentHeader() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void startDocumentTrailer() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void endDocumentTrailer() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void startPageHeader() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void endPageHeader() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void startPageTrailer() throws IFException { + //nop + } + + /** {@inheritDoc} */ + public void endPageTrailer() throws IFException { + //nop + } + private AffineTransform combine(AffineTransform[] transforms) { AffineTransform at = new AffineTransform(); for (int i = 0, c = transforms.length; i < c; i++) { diff --git a/src/java/org/apache/fop/render/intermediate/IFConstants.java b/src/java/org/apache/fop/render/intermediate/IFConstants.java index 60870fbd8..2ea97a231 100644 --- a/src/java/org/apache/fop/render/intermediate/IFConstants.java +++ b/src/java/org/apache/fop/render/intermediate/IFConstants.java @@ -35,6 +35,7 @@ public interface IFConstants extends XMLConstants { String EL_DOCUMENT = "document"; String EL_HEADER = "header"; + String EL_TRAILER = "trailer"; String EL_PAGE_SEQUENCE = "page-sequence"; String EL_PAGE = "page"; String EL_PAGE_HEADER = "page-header"; diff --git a/src/java/org/apache/fop/render/intermediate/IFPainter.java b/src/java/org/apache/fop/render/intermediate/IFPainter.java index 5181d15c0..026f43a8e 100644 --- a/src/java/org/apache/fop/render/intermediate/IFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/IFPainter.java @@ -60,6 +60,9 @@ import org.apache.fop.fonts.FontInfo; * ]* * endPageSequence() * ]* + * startDocumentTrailer() + * [handleExtension()]* + * endDocumentTrailer() * endDocument() * * #box: @@ -148,6 +151,23 @@ public interface IFPainter { */ void endDocumentHeader() throws IFException; + /** + * Indicates the start of the document trailer. This method is called after the last + * page sequence. Extensions sent to the painter between + * {@code #startDocumentTrailer()} and {@code #endDocumentTrailer()} apply to the document as + * a whole and is used for document-level content that is only known after all pages have + * been rendered (like named destinations or the bookmark tree). + * @throws IFException if an error occurs while handling this event + */ + void startDocumentTrailer() throws IFException; + + /** + * Indicates the end of the document trailer. This method is called right before the + * {@code #endDocument()} method. + * @throws IFException if an error occurs while handling this event + */ + void endDocumentTrailer() throws IFException; + /** * Indicates the start of a new page sequence. * @param id the page sequence's identifier (or null if none is available) diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java index 6545371fd..9c615427f 100644 --- a/src/java/org/apache/fop/render/intermediate/IFParser.java +++ b/src/java/org/apache/fop/render/intermediate/IFParser.java @@ -124,6 +124,7 @@ public class IFParser implements IFConstants { this.elementMappingRegistry = elementMappingRegistry; elementHandlers.put(EL_DOCUMENT, new DocumentHandler()); elementHandlers.put(EL_HEADER, new DocumentHeaderHandler()); + elementHandlers.put(EL_TRAILER, new DocumentTrailerHandler()); elementHandlers.put(EL_PAGE_SEQUENCE, new PageSequenceHandler()); elementHandlers.put(EL_PAGE, new PageHandler()); elementHandlers.put(EL_PAGE_HEADER, new PageHeaderHandler()); @@ -293,6 +294,18 @@ public class IFParser implements IFConstants { } + private class DocumentTrailerHandler extends AbstractElementHandler { + + public void startElement(Attributes attributes) throws IFException { + painter.startDocumentTrailer(); + } + + public void endElement() throws IFException { + painter.endDocumentTrailer(); + } + + } + private class PageSequenceHandler extends AbstractElementHandler { public void startElement(Attributes attributes) throws IFException { diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index 703b035d1..e5dcccf62 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -232,10 +232,12 @@ public class IFRenderer extends AbstractPathOrientedRenderer { painter.endPageSequence(); this.inPageSequence = false; } + painter.startDocumentTrailer(); finishOpenGoTos(); if (this.bookmarkTree != null) { painter.handleExtensionObject(this.bookmarkTree); } + painter.endDocumentTrailer(); painter.endDocument(); } catch (IFException e) { handleIFExceptionWithIOException(e); diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java index 3cd57435d..9ca242fb9 100644 --- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -98,6 +98,24 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst } } + /** {@inheritDoc} */ + public void startDocumentTrailer() throws IFException { + try { + startElement(EL_TRAILER); + } catch (SAXException e) { + throw new IFException("SAX error in startDocumentTrailer()", e); + } + } + + /** {@inheritDoc} */ + public void endDocumentTrailer() throws IFException { + try { + endElement(EL_TRAILER); + } catch (SAXException e) { + throw new IFException("SAX error in startDocumentTrailer()", e); + } + } + /** {@inheritDoc} */ public void endDocument() throws IFException { try { diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java index 1f087058e..5e57946fb 100644 --- a/src/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java @@ -146,10 +146,6 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter { } } - /** {@inheritDoc} */ - public void startDocumentHeader() throws IFException { - } - /** {@inheritDoc} */ public void endDocumentHeader() throws IFException { pdfUtil.generateDefaultXMPMetadata(); @@ -207,14 +203,6 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter { generator.concatenate(basicPageTransform); } - /** {@inheritDoc} */ - public void startPageHeader() throws IFException { - } - - /** {@inheritDoc} */ - public void endPageHeader() throws IFException { - } - /** {@inheritDoc} */ public void startPageContent() throws IFException { this.state = IFState.create(); @@ -225,14 +213,6 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter { assert this.state.pop() == null; } - /** {@inheritDoc} */ - public void startPageTrailer() throws IFException { - } - - /** {@inheritDoc} */ - public void endPageTrailer() throws IFException { - } - /** {@inheritDoc} */ public void endPage() throws IFException { try { diff --git a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java index 112144e73..7f92de7ed 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java @@ -117,6 +117,7 @@ public class SVGPainter extends AbstractSVGPainter { /** {@inheritDoc} */ public void endDocument() throws IFException { + //nop } /** {@inheritDoc} */ @@ -218,14 +219,6 @@ public class SVGPainter extends AbstractSVGPainter { } } - /** {@inheritDoc} */ - public void startPageHeader() throws IFException { - } - - /** {@inheritDoc} */ - public void endPageHeader() throws IFException { - } - /** {@inheritDoc} */ public void startPageContent() throws IFException { super.startPageContent(); @@ -246,14 +239,6 @@ public class SVGPainter extends AbstractSVGPainter { super.endPageContent(); } - /** {@inheritDoc} */ - public void startPageTrailer() throws IFException { - } - - /** {@inheritDoc} */ - public void endPageTrailer() throws IFException { - } - /** {@inheritDoc} */ public void endPage() throws IFException { try { -- 2.39.5