From 337a90309c7691be009a27760fe42cdf897d0f5e Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Mon, 7 Aug 2000 06:14:06 +0000 Subject: [PATCH] handles page breaking better git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193607 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/flow/InstreamForeignObject.java | 68 +++++++++++-------- src/org/apache/fop/svg/SVG.java | 65 +----------------- 2 files changed, 40 insertions(+), 93 deletions(-) diff --git a/src/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/org/apache/fop/fo/flow/InstreamForeignObject.java index d286c5645..bad9ed132 100644 --- a/src/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -164,12 +164,43 @@ public class InstreamForeignObject extends FObj { /* temporarily end the block area */ area.end(); } - + if(this.areaCurrent == null) { + this.areaCurrent = + new ForeignObjectArea(fs, area.getAllocationWidth(), + area.spaceLeft(), 0); + + this.areaCurrent.start(); + areaCurrent.setPage(area.getPage()); + + /* iterate over the child formatting objects and lay them out + into the SVG area */ + int numChildren = this.children.size(); + if(numChildren > 1) { + throw new FOPException("Only one child element is allowed in an instream-foreign-object"); + } + if(this.children.size() > 0) { + FONode fo = (FONode) children.elementAt(0); + Status status; + // currently FONode must be an SVG + if ((status = fo.layout(this.areaCurrent)).isIncomplete()) { + return status; + } + + /* finish off the foreign object area */ + this.areaCurrent.end(); + } + } + this.marker = 0; - // this doesn't work for auto sizes - if (breakBefore == BreakBefore.PAGE || ((this.height + area.getHeight()) > area.getMaxHeight())) { - return new Status(Status.FORCE_PAGE_BREAK); + if(this.hauto) { + if (breakBefore == BreakBefore.PAGE || ((spaceBefore + areaCurrent.getHeight()) > area.spaceLeft())) { + return new Status(Status.FORCE_PAGE_BREAK); + } + } else { + if (breakBefore == BreakBefore.PAGE || (this.height > area.spaceLeft())) { + return new Status(Status.FORCE_PAGE_BREAK); + } } if (breakBefore == BreakBefore.ODD_PAGE) { @@ -180,43 +211,22 @@ public class InstreamForeignObject extends FObj { return new Status(Status.FORCE_PAGE_BREAK_EVEN); } } - + /* if there is a space-before */ if (spaceBefore != 0) { /* add a display space */ area.addDisplaySpace(spaceBefore); } - this.areaCurrent = - new ForeignObjectArea(fs, area.getAllocationWidth(), - area.spaceLeft(), 0); - areaCurrent.setPage(area.getPage()); - /* layout foreign object */ -// svg.start(); - /* add the SVG area to the containing area */ area.addChild(areaCurrent); - /* iterate over the child formatting objects and lay them out - into the SVG area */ - int numChildren = this.children.size(); - if(numChildren > 1) { - // error - } - if(this.children.size() > 0) { - FONode fo = (FONode) children.elementAt(0); - Status status; - // currently FONode must be an SVG - if ((status = fo.layout(this.areaCurrent)).isIncomplete()) { - return status; - } - - /* finish off the SVG area */ -// svg.end(); + areaCurrent.setPage(area.getPage()); + /* layout foreign object */ +// svg.start(); /* increase the height of the containing area accordingly */ area.increaseHeight(areaCurrent.getHeight()); - } /* if there is a space-after */ if (spaceAfter != 0) { diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java index 3a7e6b416..9c2959224 100644 --- a/src/org/apache/fop/svg/SVG.java +++ b/src/org/apache/fop/svg/SVG.java @@ -96,12 +96,8 @@ public class SVG extends FObj implements GraphicsCreator { } FontState fs; - int breakBefore; - int breakAfter; float width; float height; - int spaceBefore; - int spaceAfter; /** * constructs an SVG object (called by Maker). @@ -191,42 +187,10 @@ public class SVG extends FObj implements GraphicsCreator { this.fs = new FontState(area.getFontInfo(), fontFamily, fontStyle, fontWeight, fontSize); - this.breakBefore = this.properties.get("break-before").getEnum(); - this.breakAfter = this.properties.get("break-after").getEnum(); - Property prop = this.properties.get("width"); this.width = ((SVGLengthProperty)this.properties.get("width")).getSVGLength().getValue(); - prop = this.properties.get("height"); this.height = ((SVGLengthProperty)this.properties.get("height")).getSVGLength().getValue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - /* if the SVG is embedded in a block area */ -// if (area instanceof BlockArea) { - /* temporarily end the block area */ -// area.end(); -// } - this.marker = 0; - -/* if (breakBefore == BreakBefore.PAGE || ((this.height * 1000 + area.getHeight()) > area.getMaxHeight())) { - return new Status(Status.FORCE_PAGE_BREAK); - } - - if (breakBefore == BreakBefore.ODD_PAGE) { - return new Status(Status.FORCE_PAGE_BREAK_ODD); - } - - if (breakBefore == BreakBefore.EVEN_PAGE) { - return new Status(Status.FORCE_PAGE_BREAK_EVEN); - }*/ - } - - /* if there is a space-before */ - if (spaceBefore != 0) { - /* add a display space */ - area.addDisplaySpace(spaceBefore); } /* create an SVG area */ @@ -253,36 +217,9 @@ public class SVG extends FObj implements GraphicsCreator { svg.end(); /* increase the height of the containing area accordingly */ - area.setHeight(svg.getHeight()); + area.increaseHeight(svg.getHeight()); // area.setWidth(svg.getWidth()); - /* if there is a space-after */ -// if (spaceAfter != 0) { - /* add a display space */ -// area.addDisplaySpace(spaceAfter); -// } - - /* if the SVG is embedded in a block area */ -// if (area instanceof BlockArea) { - /* re-start the block area */ -// area.start(); -// } - -/* if (breakAfter == BreakAfter.PAGE) { - this.marker = BREAK_AFTER; - return new Status(Status.FORCE_PAGE_BREAK); - } - - if (breakAfter == BreakAfter.ODD_PAGE) { - this.marker = BREAK_AFTER; - return new Status(Status.FORCE_PAGE_BREAK_ODD); - } - - if (breakAfter == BreakAfter.EVEN_PAGE) { - this.marker = BREAK_AFTER; - return new Status(Status.FORCE_PAGE_BREAK_EVEN); - }*/ - /* return status */ return new Status(Status.OK); } -- 2.39.5