/*
* 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.
* limitations under the License.
*/
-/* $Id$ */
+/* $Id: BodyRegion.java,v 1.4 2004/02/27 17:41:26 jeremias Exp $ */
package org.apache.fop.area;
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.
*
/*
* 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.
* 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.
private List spanAreas = new java.util.ArrayList();
private int columnGap;
private int width;
+ private boolean isEmpty = true;
/**
* Add a span area to this area.
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;
+ }
+
/**
* Get the column gap in millipoints.
*
/*
* 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.
* limitations under the License.
*/
-/* $Id$ */
+/* $Id: Page.java,v 1.4 2004/02/27 17:41:26 jeremias Exp $ */
package org.apache.fop.area;
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();
+ }
+ }
+
/**
* Clone this page.
* This returns a new page with a clone of all the regions.
/*
* 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.
* 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;
*/
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;
}
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));
+
+
}
/**
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;
}
* Used for storing back trait information which are related.
*/
public static class Background implements Serializable {
-
+
/** The background color if any. */
private ColorType color = null;
/** Background vertical offset for images. */
private int vertical;
-
+
/**
* Returns the background color.
* @return background color, null if n/a
* 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;
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
/*
* 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.
* limitations under the License.
*/
-/* $Id$ */
+/* $Id: PageLayoutManager.java,v 1.38 2004/05/22 21:44:38 gmazza Exp $ */
package org.apache.fop.layoutmgr;
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;
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;
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);
* 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() {
//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();
// 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();
staticContentLMs.put(sc.getFlowName(), lm);
return lm;
}
-
+
/**
* @return the apps.Document object controlling this generation
*/
/*
* 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.
* 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;
* @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);
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));
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));
* @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) {
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));
+ }
}