cbowditch 2004/05/27 03:52:33 Modified: src/java/org/apache/fop/area BodyRegion.java MainReference.java Page.java Trait.java src/java/org/apache/fop/layoutmgr BlockLayoutManager.java PageLayoutManager.java TraitSetter.java Log: implemented break-before property Revision Changes Path 1.5 +14 -4 xml-fop/src/java/org/apache/fop/area/BodyRegion.java Index: BodyRegion.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/BodyRegion.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- BodyRegion.java 27 Feb 2004 17:41:26 -0000 1.4 +++ BodyRegion.java 27 May 2004 10:52:33 -0000 1.5 @@ -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. @@ -115,6 +115,16 @@ public MainReference getMainReference() { return mainReference; } + + /** + * 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. 1.3 +35 -5 xml-fop/src/java/org/apache/fop/area/MainReference.java Index: MainReference.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/MainReference.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MainReference.java 27 Feb 2004 17:41:26 -0000 1.2 +++ MainReference.java 27 May 2004 10:52:33 -0000 1.3 @@ -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. @@ -15,10 +15,11 @@ */ /* $Id$ */ - + package org.apache.fop.area; import java.util.List; +import java.util.Iterator; /** * The main body reference area. @@ -28,6 +29,7 @@ private List spanAreas = new java.util.ArrayList(); private int columnGap; private int width; + private boolean isEmpty = true; /** * Add a span area to this area. @@ -45,6 +47,34 @@ */ public List getSpans() { return spanAreas; + } + + /** + * 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; } /** 1.5 +19 -4 xml-fop/src/java/org/apache/fop/area/Page.java Index: Page.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/Page.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Page.java 27 Feb 2004 17:41:26 -0000 1.4 +++ Page.java 27 May 2004 10:52:33 -0000 1.5 @@ -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. @@ -84,6 +84,21 @@ return regionAfter; } return null; + } + + /** + * 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(); + } } /** 1.5 +28 -12 xml-fop/src/java/org/apache/fop/area/Trait.java Index: Trait.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/Trait.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Trait.java 27 Feb 2004 17:41:26 -0000 1.4 +++ Trait.java 27 May 2004 10:52:33 -0000 1.5 @@ -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. @@ -15,7 +15,7 @@ */ /* $Id$ */ - + package org.apache.fop.area; import org.apache.fop.datatypes.ColorType; @@ -149,21 +149,31 @@ */ 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 @@ 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 @@ 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 @@ * 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 @@ /** Background vertical offset for images. */ private int vertical; - + /** * Returns the background color. * @return background color, null if n/a 1.20 +2 -1 xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java Index: BlockLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- BlockLayoutManager.java 26 May 2004 04:22:39 -0000 1.19 +++ BlockLayoutManager.java 27 May 2004 10:52:33 -0000 1.20 @@ -315,6 +315,7 @@ 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 1.39 +45 -41 xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java Index: PageLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- PageLayoutManager.java 22 May 2004 21:44:38 -0000 1.38 +++ PageLayoutManager.java 27 May 2004 10:52:33 -0000 1.39 @@ -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. @@ -36,6 +36,7 @@ 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.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 @@ 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 @@ * 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 @@ //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 @@ // 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 @@ staticContentLMs.put(sc.getFlowName(), lm); return lm; } - + /** * @return the apps.Document object controlling this generation */ 1.7 +17 -11 xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java Index: TraitSetter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TraitSetter.java 27 Feb 2004 17:49:25 -0000 1.6 +++ TraitSetter.java 27 May 2004 10:52:33 -0000 1.7 @@ -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. @@ -15,11 +15,12 @@ */ /* $Id$ */ - + 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 @@ * @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 @@ 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 @@ 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 @@ * @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) { @@ -197,5 +198,10 @@ if (spaceEnd != 0) { 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)); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]