From 3d1baf5455c62ebca26b523176690d304b637bec Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 25 Jan 2006 13:48:32 +0000 Subject: [PATCH] Bugfix: Regions with non-standard names got ignored in RTF output leading to missing headers and footers. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@372214 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/rtf/RTFHandler.java | 56 ++++++++++++++----- status.xml | 4 ++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 68addd742..3161c0ce1 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -32,6 +32,9 @@ import org.xml.sax.SAXException; // FOP import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.datatypes.LengthBase; +import org.apache.fop.datatypes.PercentBaseContext; +import org.apache.fop.datatypes.SimplePercentBaseContext; import org.apache.fop.fo.FOEventHandler; import org.apache.fop.fo.FONode; import org.apache.fop.fo.flow.BasicLink; @@ -57,6 +60,7 @@ import org.apache.fop.fo.flow.TableHeader; import org.apache.fop.fo.flow.TableRow; import org.apache.fop.fo.pagination.Flow; import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.Region; import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.fo.pagination.StaticContent; import org.apache.fop.fo.Constants; @@ -121,6 +125,7 @@ public class RTFHandler extends FOEventHandler { //in current page-sequence private BuilderContext builderContext = new BuilderContext(null); + private SimplePageMaster pagemaster; /** * Creates a new RTF structure handler. @@ -179,7 +184,7 @@ public class RTFHandler extends FOEventHandler { String reference = pageSeq.getMasterReference(); - SimplePageMaster pagemaster + this.pagemaster = pageSeq.getRoot().getLayoutMasterSet().getSimplePageMaster(reference); //only simple-page-master supported, so pagemaster may be null @@ -232,7 +237,11 @@ public class RTFHandler extends FOEventHandler { try { log.debug("starting flow: " + fl.getFlowName()); - if (fl.getFlowName().equals("xsl-region-body")) { + boolean handled = false; + Region regionBody = pagemaster.getRegion(Constants.FO_REGION_BODY); + Region regionBefore = pagemaster.getRegion(Constants.FO_REGION_BEFORE); + Region regionAfter = pagemaster.getRegion(Constants.FO_REGION_AFTER); + if (fl.getFlowName().equals(regionBody.getRegionName())) { // if there is no header in current page-sequence but there has been // a header in a previous page-sequence, insert an empty header. if (bPrevHeaderSpecified && !bHeaderSpecified) { @@ -256,8 +265,9 @@ public class RTFHandler extends FOEventHandler { (IRtfAfterContainer.class, true, this); contAfter.newAfter(attr); } - - } else if (fl.getFlowName().equals("xsl-region-before")) { + handled = true; + } else if (regionBefore != null + && fl.getFlowName().equals(regionBefore.getRegionName())) { bHeaderSpecified = true; bPrevHeaderSpecified = true; @@ -274,7 +284,9 @@ public class RTFHandler extends FOEventHandler { RtfBefore before = c.newBefore(beforeAttributes); builderContext.pushContainer(before); - } else if (fl.getFlowName().equals("xsl-region-after")) { + handled = true; + } else if (regionAfter != null + && fl.getFlowName().equals(regionAfter.getRegionName())) { bFooterSpecified = true; bPrevFooterSpecified = true; @@ -292,6 +304,10 @@ public class RTFHandler extends FOEventHandler { RtfAfter after = c.newAfter(afterAttributes); builderContext.pushContainer(after); + handled = true; + } + if (!handled) { + log.warn("A " + fl.getLocalName() + " has been skipped: " + fl.getFlowName()); } } catch (IOException ioe) { log.error("startFlow: " + ioe.getMessage()); @@ -312,11 +328,16 @@ public class RTFHandler extends FOEventHandler { } try { - if (fl.getFlowName().equals("xsl-region-body")) { + Region regionBody = pagemaster.getRegion(Constants.FO_REGION_BODY); + Region regionBefore = pagemaster.getRegion(Constants.FO_REGION_BEFORE); + Region regionAfter = pagemaster.getRegion(Constants.FO_REGION_AFTER); + if (fl.getFlowName().equals(regionBody.getRegionName())) { //just do nothing - } else if (fl.getFlowName().equals("xsl-region-before")) { + } else if (regionBefore != null + && fl.getFlowName().equals(regionBefore.getRegionName())) { builderContext.popContainer(); - } else if (fl.getFlowName().equals("xsl-region-after")) { + } else if (regionAfter != null + && fl.getFlowName().equals(regionAfter.getRegionName())) { builderContext.popContainer(); } } catch (Exception e) { @@ -1421,17 +1442,24 @@ public class RTFHandler extends FOEventHandler { if (foNode instanceof PageSequence) { PageSequence pageSequence = (PageSequence) foNode; - FONode regionBefore = (FONode) pageSequence.flowMap.get("xsl-region-before"); - FONode regionAfter = (FONode) pageSequence.flowMap.get("xsl-region-after"); - + Region regionBefore = pagemaster.getRegion(Constants.FO_REGION_BEFORE); if (regionBefore != null) { - recurseFONode(regionBefore); + FONode staticBefore = (FONode) pageSequence.flowMap.get( + regionBefore.getRegionName()); + if (staticBefore != null) { + recurseFONode(staticBefore); + } } - + Region regionAfter = pagemaster.getRegion(Constants.FO_REGION_AFTER); if (regionAfter != null) { - recurseFONode(regionAfter); + FONode staticAfter = (FONode) pageSequence.flowMap.get( + regionAfter.getRegionName()); + if (staticAfter != null) { + recurseFONode(staticAfter); + } } + recurseFONode( pageSequence.getMainFlow() ); } else if (foNode instanceof Table) { Table table = (Table) foNode; diff --git a/status.xml b/status.xml index 1991f3bf8..f8f2acdb7 100644 --- a/status.xml +++ b/status.xml @@ -27,6 +27,10 @@ + + Bugfix: Regions with non-standard names got ignored in RTF output leading to + missing headers and footers. + The RTF output now properly generates the "\landscape" flag for documents in landscape orientation. -- 2.39.5