diff options
author | Chris Bowditch <cbowditch@apache.org> | 2004-05-27 10:52:33 +0000 |
---|---|---|
committer | Chris Bowditch <cbowditch@apache.org> | 2004-05-27 10:52:33 +0000 |
commit | 0aad68370a237a434a3338151806ba6851551d22 (patch) | |
tree | 1fe2c9d0ba91410bb75ee27593319d643e5cd190 /src/java/org/apache/fop | |
parent | 4a4411bed3a85a4aba3f2eca8c7e488f83105191 (diff) | |
download | xmlgraphics-fop-0aad68370a237a434a3338151806ba6851551d22.tar.gz xmlgraphics-fop-0aad68370a237a434a3338151806ba6851551d22.zip |
implemented break-before property
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197635 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r-- | src/java/org/apache/fop/area/BodyRegion.java | 18 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/MainReference.java | 40 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/Page.java | 23 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/Trait.java | 40 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java | 3 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/PageLayoutManager.java | 86 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/TraitSetter.java | 28 |
7 files changed, 160 insertions, 78 deletions
diff --git a/src/java/org/apache/fop/area/BodyRegion.java b/src/java/org/apache/fop/area/BodyRegion.java index 35d968ef2..5b0970689 100644 --- a/src/java/org/apache/fop/area/BodyRegion.java +++ b/src/java/org/apache/fop/area/BodyRegion.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id$ */ +/* $Id: BodyRegion.java,v 1.4 2004/02/27 17:41:26 jeremias Exp $ */ package org.apache.fop.area; @@ -117,6 +117,16 @@ public class BodyRegion extends RegionReference { } /** + * indicates whether the main reference area has any child areas added to it + * + * @return whether the main reference area has any child areas added to it + */ + public boolean isEmpty() { + return mainReference.isEmpty(); + } + + + /** * Get the footnote area. * * @return the footnote area diff --git a/src/java/org/apache/fop/area/MainReference.java b/src/java/org/apache/fop/area/MainReference.java index bf616e994..c9b50fd68 100644 --- a/src/java/org/apache/fop/area/MainReference.java +++ b/src/java/org/apache/fop/area/MainReference.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,11 +14,12 @@ * limitations under the License. */ -/* $Id$ */ - +/* $Id: MainReference.java,v 1.2 2004/02/27 17:41:26 jeremias Exp $ */ + package org.apache.fop.area; import java.util.List; +import java.util.Iterator; /** * The main body reference area. @@ -28,6 +29,7 @@ public class MainReference extends Area { private List spanAreas = new java.util.ArrayList(); private int columnGap; private int width; + private boolean isEmpty = true; /** * Add a span area to this area. @@ -48,6 +50,34 @@ public class MainReference extends Area { } /** + * indicates whether any child areas have been added to this reference area + * this is achieved by looping through each span + * + * @return + */ + public boolean isEmpty() { + if (isEmpty) { + int areaCount = 0; + if (spanAreas != null) { + for (Iterator spaniter = spanAreas.iterator(); spaniter.hasNext(); ) { + Span spanArea = (Span) spaniter.next(); + for (int i = 0; i < spanArea.getColumnCount(); i++) { + Flow flow = spanArea.getFlow(i); + if (flow != null) { + if (flow.getChildAreas() != null) { + areaCount += flow.getChildAreas().size(); + } + } + } + } + } + + isEmpty = (areaCount == 0); + } + return isEmpty; + } + + /** * Get the column gap in millipoints. * * @return the column gap in millioints diff --git a/src/java/org/apache/fop/area/Page.java b/src/java/org/apache/fop/area/Page.java index 49d74d7f2..f83a5f0eb 100644 --- a/src/java/org/apache/fop/area/Page.java +++ b/src/java/org/apache/fop/area/Page.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id$ */ +/* $Id: Page.java,v 1.4 2004/02/27 17:41:26 jeremias Exp $ */ package org.apache.fop.area; @@ -87,6 +87,21 @@ public class Page implements Serializable, Cloneable { } /** + * indicates whether any FOs have been added to the body region + * + * @return whether any FOs have been added to the body region + */ + public boolean isEmpty() { + if (regionBody == null) { + return true; + } + else { + BodyRegion body = (BodyRegion)regionBody.getRegion(); + return body.isEmpty(); + } + } + + /** * Clone this page. * This returns a new page with a clone of all the regions. * diff --git a/src/java/org/apache/fop/area/Trait.java b/src/java/org/apache/fop/area/Trait.java index b518143f9..6ab9deb00 100644 --- a/src/java/org/apache/fop/area/Trait.java +++ b/src/java/org/apache/fop/area/Trait.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,8 +14,8 @@ * limitations under the License. */ -/* $Id$ */ - +/* $Id: Trait.java,v 1.4 2004/02/27 17:41:26 jeremias Exp $ */ + package org.apache.fop.area; import org.apache.fop.datatypes.ColorType; @@ -149,21 +149,31 @@ public class Trait implements Serializable { */ public static final Integer SPACE_END = new Integer(24); + /** + * break before + */ + public static final Integer BREAK_BEFORE = new Integer(25); + + /** + * break after + */ + public static final Integer BREAK_AFTER = new Integer(26); + private static final Map TRAIT_INFO = new HashMap(); private static class TraitInfo { private String name; private Class clazz; // Class of trait data - + public TraitInfo(String name, Class clazz) { this.name = name; this.clazz = clazz; } - + public String getName() { return this.name; } - + public Class getClazz() { return this.clazz; } @@ -212,6 +222,12 @@ public class Trait implements Serializable { new TraitInfo("space-start", Integer.class)); TRAIT_INFO.put(SPACE_END, new TraitInfo("space-end", Integer.class)); + TRAIT_INFO.put(BREAK_BEFORE, + new TraitInfo("break-before", Integer.class)); + TRAIT_INFO.put(BREAK_AFTER, + new TraitInfo("break-after", Integer.class)); + + } /** @@ -337,11 +353,11 @@ public class Trait implements Serializable { Object o = tclass.newInstance(); //return o.fromString(sTraitValue); } catch (IllegalAccessException e1) { - System.err.println("Can't create instance of " + System.err.println("Can't create instance of " + tclass.getName()); return null; } catch (InstantiationException e2) { - System.err.println("Can't create instance of " + System.err.println("Can't create instance of " + tclass.getName()); return null; } @@ -355,7 +371,7 @@ public class Trait implements Serializable { * Used for storing back trait information which are related. */ public static class Background implements Serializable { - + /** The background color if any. */ private ColorType color = null; @@ -370,7 +386,7 @@ public class Trait implements Serializable { /** Background vertical offset for images. */ private int vertical; - + /** * Returns the background color. * @return background color, null if n/a diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index ec9fdcf05..815df1c58 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id: BlockLayoutManager.java,v 1.17 2004/05/15 21:51:59 gmazza Exp $ */ +/* $Id: BlockLayoutManager.java,v 1.19 2004/05/26 04:22:39 gmazza Exp $ */ package org.apache.fop.layoutmgr; @@ -315,6 +315,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { TraitSetter.addBorders(curBlockArea, borderProps); TraitSetter.addBackground(curBlockArea, backgroundProps); TraitSetter.addMargins(curBlockArea, borderProps, marginProps); + TraitSetter.addBreaks(curBlockArea, layoutProps); // Set up dimensions // Must get dimensions from parent area diff --git a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java index d866023ec..34f9d1891 100644 --- a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id$ */ +/* $Id: PageLayoutManager.java,v 1.38 2004/05/22 21:44:38 gmazza Exp $ */ package org.apache.fop.layoutmgr; @@ -36,6 +36,7 @@ import org.apache.fop.area.Span; import org.apache.fop.area.BeforeFloat; import org.apache.fop.area.Footnote; import org.apache.fop.area.Resolveable; +import org.apache.fop.area.Trait; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.datatypes.FODimension; @@ -52,6 +53,8 @@ import org.apache.fop.fo.properties.CommonBackground; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.fo.properties.CommonMarginBlock; +import org.apache.commons.logging.Log; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -520,7 +523,11 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable if (aclass == Area.CLASS_NORMAL) { // todo: how to get properties from the Area??? // Need span, break - int breakVal = Constants.AUTO; // childArea.getBreakBefore(); + int breakVal = Constants.AUTO; + Integer breakBefore = (Integer)childArea.getTrait(Trait.BREAK_BEFORE); + if (breakBefore != null) { + breakVal = breakBefore.intValue(); + } if (breakVal != Constants.AUTO) { // We may be forced to make new page handleBreak(breakVal); @@ -612,45 +619,42 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * block until the queue of layoutable stuff is empty! */ private boolean needEmptyPage(int breakValue) { - return false; - // if (breakValue == Constants.PAGE || curPage.isEmpty()) { - // // any page is OK or we already have an empty page - // return false; - // } - // else { - // /* IF we are on the kind of page we need, we'll need a new page. */ - // if (curPage.getPageNumber()%2 != 0) { - // // Current page is odd - // return (breakValue == Constants.ODD_PAGE); - // } - // else { - // return (breakValue == Constants.EVEN_PAGE); - // } - // } + + if (breakValue == Constants.PAGE || curPage.getPage().isEmpty()) { + // any page is OK or we already have an empty page + return false; + } + else { + /* IF we are on the kind of page we need, we'll need a new page. */ + if (pageCount%2 != 0) { + // Current page is odd + return (breakValue == Constants.ODD_PAGE); + } + else { + return (breakValue == Constants.EVEN_PAGE); + } + } } /** * See if need to generate a new page for a forced break condition. - * todo: methods to see if the current page is empty and to get - * its number. */ private boolean needNewPage(int breakValue) { - return false; - //if (curPage.isEmpty()) { - //if (breakValue == Constants.PAGE) { - //return false; - //} - //else if (curPage.getPageNumber()%2 != 0) { - //// Current page is odd - //return (breakValue == Constants.EVEN_PAGE); - //} - //else { - //return (breakValue == Constants.ODD_PAGE); - //} - //} - //else { - // return true; - //} + if (curPage.getPage().isEmpty()) { + if (breakValue == Constants.PAGE) { + return false; + } + else if (pageCount%2 != 0) { + // Current page is odd + return (breakValue == Constants.EVEN_PAGE); + } + else { + return (breakValue == Constants.ODD_PAGE); + } + } + else { + return true; + } } private void createBodyMainReferenceArea() { @@ -680,7 +684,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable //else newpos = new MinOptMax(); curSpan = new Span(numCols); // get Width or Height as IPD for span - + RegionViewport rv = curPage.getPage().getRegionViewport(Region.BODY_CODE); int ipdWidth = (int) rv.getRegion().getIPD() - rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd(); @@ -745,7 +749,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // Set the page dimension as the toplevel containing block for margin. ((FObj) fobj.getParent()).setLayoutDimension(PercentBase.BLOCK_IPD, pageWidth); ((FObj) fobj.getParent()).setLayoutDimension(PercentBase.BLOCK_BPD, pageHeight); - + // Get absolute margin properties (top, left, bottom, right) CommonMarginBlock mProps = spm.getPropertyManager().getMarginProps(); @@ -895,7 +899,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable staticContentLMs.put(sc.getFlowName(), lm); return lm; } - + /** * @return the apps.Document object controlling this generation */ diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index e6d4a52d0..ee515ee21 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,12 +14,13 @@ * limitations under the License. */ -/* $Id$ */ - +/* $Id: TraitSetter.java,v 1.6 2004/02/27 17:49:25 jeremias Exp $ */ + package org.apache.fop.layoutmgr; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.traits.BorderProps; +import org.apache.fop.traits.LayoutProps; import org.apache.fop.area.Area; import org.apache.fop.area.Trait; import org.apache.fop.fo.properties.CommonBackground; @@ -78,7 +79,7 @@ public class TraitSetter { * @param bpProps border and padding properties */ private static void addBorderTrait(Area area, - CommonBorderAndPadding bpProps, + CommonBorderAndPadding bpProps, boolean bDiscard, int iSide, Object oTrait) { int iBP = bpProps.getBorderWidth(iSide, bDiscard); @@ -117,12 +118,12 @@ public class TraitSetter { if (bps.width != 0) { curBlock.addTrait(Trait.BORDER_END, bps); } - + int padding = bordProps.getPadding(CommonBorderAndPadding.START, false); if (padding != 0) { curBlock.addTrait(Trait.PADDING_START, new java.lang.Integer(padding)); } - + padding = bordProps.getPadding(CommonBorderAndPadding.END, false); if (padding != 0) { curBlock.addTrait(Trait.PADDING_END, new java.lang.Integer(padding)); @@ -132,7 +133,7 @@ public class TraitSetter { if (padding != 0) { curBlock.addTrait(Trait.PADDING_BEFORE, new java.lang.Integer(padding)); } - + padding = bordProps.getPadding(CommonBorderAndPadding.AFTER, false); if (padding != 0) { curBlock.addTrait(Trait.PADDING_AFTER, new java.lang.Integer(padding)); @@ -182,9 +183,9 @@ public class TraitSetter { * @param marginProps the margin properties. */ public static void addMargins(Area curBlock, - CommonBorderAndPadding bpProps, + CommonBorderAndPadding bpProps, CommonMarginBlock marginProps) { - int spaceStart = marginProps.startIndent - + int spaceStart = marginProps.startIndent - bpProps.getBorderStartWidth(false) - bpProps.getPaddingStart(false); if (spaceStart != 0) { @@ -198,4 +199,9 @@ public class TraitSetter { curBlock.addTrait(Trait.SPACE_END, new Integer(spaceEnd)); } } + + public static void addBreaks(Area curArea, LayoutProps layoutProps) { + curArea.addTrait(Trait.BREAK_AFTER, new Integer(layoutProps.breakAfter)); + curArea.addTrait(Trait.BREAK_BEFORE, new Integer(layoutProps.breakBefore)); + } } |