package org.apache.fop.fo.pagination;
+// Java
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
// FOP
-
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FONode;
import org.apache.fop.area.RegionReference;
import org.apache.fop.layoutmgr.AbstractLayoutManager;
+// SAX
import org.xml.sax.Attributes;
/**
* This is an abstract base class for pagination regions
*/
public abstract class Region extends FObj {
- public static final String PROP_REGION_NAME = "region-name";
+ private static final String PROP_REGION_NAME = "region-name";
- public static final String BEFORE = "before";
- public static final String START = "start";
- public static final String END = "end";
- public static final String AFTER = "after";
- public static final String BODY = "body";
+ protected static final String BEFORE = "before";
+ protected static final String START = "start";
+ protected static final String END = "end";
+ protected static final String AFTER = "after";
+ protected static final String BODY = "body";
private SimplePageMaster _layoutMaster;
private String _regionName;
protected int overflow;
+ protected int wm;
protected Region(FONode parent) {
super(parent);
if (isReserved(getRegionName())
&&!getRegionName().equals(getDefaultRegionName())) {
throw new FOPException(PROP_REGION_NAME + " '" + _regionName
- + "' for " + this.name
- + " not permitted.");
+ + "' for " + this.name
+ + " not permitted.");
}
}
_layoutMaster = (SimplePageMaster)parent;
} else {
throw new FOPException(this.name + " must be child "
- + "of simple-page-master, not "
- + parent.getName());
+ + "of simple-page-master, not "
+ + parent.getName());
}
+ this.wm = this.properties.get("writing-mode").getEnum();
}
/**
int getExtent() {
return 0;
}
-
}
// FOP
import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.WritingMode;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.area.RegionReference;
}
protected Rectangle getViewportRectangle (FODimension reldims) {
- // Depends on extent and precedence
- Rectangle vpRect =
- new Rectangle(0, reldims.bpd - getExtent(),
- reldims.ipd, getExtent());
+ // Depends on extent, precedence ans writing mode
+ Rectangle vpRect;
+ if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB)
+ vpRect = new Rectangle(0, reldims.bpd - getExtent(), reldims.ipd, getExtent());
+ else
+ vpRect = new Rectangle(0, reldims.bpd - getExtent(), getExtent(), reldims.ipd);
if (getPrecedence() == false) {
- adjustIPD(vpRect);
+ adjustIPD(vpRect, this.wm);
}
return vpRect;
}
public String getRegionClass() {
return Region.AFTER;
}
-
}
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.Precedence;
+import org.apache.fop.fo.properties.WritingMode;
// Java
import java.awt.Rectangle;
* inline-progression-dimension is limited by the extent of the start
* and end regions if they are present.
*/
- protected void adjustIPD(Rectangle vpRect) {
- int xoff = 0;
+ protected void adjustIPD(Rectangle vpRect, int wm) {
+ int offset = 0;
Region start = getSiblingRegion(Region.START);
if (start != null) {
- xoff = start.getExtent();
- vpRect.translate(xoff, 0);
+ offset = start.getExtent();
+ vpRect.translate(offset, 0);
}
Region end =getSiblingRegion(Region.END);
if (end != null) {
- xoff += end.getExtent();
+ offset += end.getExtent();
}
- if (xoff > 0) {
- vpRect.grow(-xoff,0);
+ if (offset > 0) {
+ if (wm == WritingMode.LR_TB || wm == WritingMode.RL_TB)
+ vpRect.width-=offset;
+ else
+ vpRect.height-=offset;
}
}
}
// FOP
import org.apache.fop.datatypes.FODimension;
-import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.WritingMode;
+import org.apache.fop.fo.FONode;
import org.apache.fop.area.RegionReference;
// Java
super(parent);
}
-// public void handleAttrs(Attributes attlist) throws FOPException {
-// super.handleAttrs(attlist);
-// }
-
protected String getDefaultRegionName() {
return "xsl-region-before";
}
}
protected Rectangle getViewportRectangle (FODimension reldims) {
- // Depends on extent and precedence
- // This should return rectangle in writing-mode coordinates relative
- // to the page-reference area rectangle
- // This means the origin is (start, before) and the dimensions are (ipd,bpd)
- // Before is always 0, start depends on extent
- // ipd depends on precedence, bpd=extent
- Rectangle vpRect = new Rectangle(0, 0, reldims.ipd, getExtent());
- if (getPrecedence() == false) {
- adjustIPD(vpRect);
- }
- return vpRect;
+ // Depends on extent, precedence and writing mode
+ // This should return rectangle in writing-mode coordinates relative
+ // to the page-reference area rectangle
+ // This means the origin is (start, before) and the dimensions are (ipd,bpd)
+ // Before is always 0, start depends on extent
+ // ipd depends on precedence, bpd=extent
+ Rectangle vpRect;
+ if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB)
+ vpRect = new Rectangle(0, 0, reldims.ipd, getExtent());
+ else
+ vpRect = new Rectangle(0, 0, getExtent(), reldims.ipd);
+ if (getPrecedence() == false) {
+ adjustIPD(vpRect, this.wm);
+ }
+ return vpRect;
}
-
}
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.Property;
import org.apache.fop.fo.properties.Overflow;
+import org.apache.fop.fo.properties.WritingMode;
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.area.RegionReference;
protected Rectangle getViewportRectangle (FODimension reldims)
{
- /*
- * Use space-before and space-after which will use corresponding
- * absolute margin properties if specified. For indents:
- * try to get corresponding absolute margin property using the
- * writing-mode on the page (not on the region-body!). If that's not
- * set but indent is explicitly set, it will return that.
- */
+ /*
+ * Use space-before and space-after which will use corresponding
+ * absolute margin properties if specified. For indents:
+ * try to get corresponding absolute margin property using the
+ * writing-mode on the page (not on the region-body!). If that's not
+ * set but indent is explicitly set, it will return that.
+ */
MarginProps mProps = propMgr.getMarginProps();
- int start = getRelMargin(PropertyList.START, "start-indent");
- return new Rectangle( start, mProps.spaceBefore,
- reldims.ipd - start -
- getRelMargin(PropertyList.END, "end-indent"),
- reldims.bpd - mProps.spaceBefore -
- mProps.spaceAfter);
+ int start = getRelMargin(PropertyList.START, "start-indent");
+ Rectangle vpRect;
+ if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB)
+ vpRect = new Rectangle( start, mProps.spaceBefore,
+ reldims.ipd - start -
+ getRelMargin(PropertyList.END, "end-indent"),
+ reldims.bpd - mProps.spaceBefore -
+ mProps.spaceAfter);
+ else
+ vpRect = new Rectangle( start, mProps.spaceBefore,
+ reldims.bpd - mProps.spaceBefore -
+ mProps.spaceAfter,
+ reldims.ipd - start -
+ getRelMargin(PropertyList.END, "end-indent")
+ );
+ return vpRect;
}
/**
* writing mode.
*/
private int getRelMargin(int reldir, String sRelPropName) {
- FObj parent = (FObj) getParent();
- String sPropName = "margin-" +
- parent.properties.wmRelToAbs(reldir);
- Property prop = properties.getExplicitBaseProp(sPropName);
- if (prop == null) {
- prop = properties.getExplicitBaseProp(sRelPropName);
- }
- return ((prop != null)? prop.getLength().mvalue() : 0);
+ FObj parent = (FObj) getParent();
+ String sPropName = "margin-" +
+ parent.properties.wmRelToAbs(reldir);
+ Property prop = properties.getExplicitBaseProp(sPropName);
+ if (prop == null) {
+ prop = properties.getExplicitBaseProp(sRelPropName);
+ }
+ return ((prop != null)? prop.getLength().mvalue() : 0);
}
protected String getDefaultRegionName() {
* Override the inherited method.
*/
public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) {
- // Should set some column stuff here I think, or put it elsewhere
- BodyRegion body = new BodyRegion();
- setRegionPosition(body, absRegVPRect);
+ // Should set some column stuff here I think, or put it elsewhere
+ BodyRegion body = new BodyRegion();
+ setRegionPosition(body, absRegVPRect);
int columnCount=
- this.properties.get("column-count").getNumber().intValue();
+ this.properties.get("column-count").getNumber().intValue();
if ((columnCount > 1) && (overflow == Overflow.SCROLL)) {
// recover by setting 'column-count' to 1. This is allowed but
// not required by the spec.
getLogger().error("Setting 'column-count' to 1 because "
- + "'overflow' is set to 'scroll'");
+ + "'overflow' is set to 'scroll'");
columnCount = 1;
}
- body.setColumnCount(columnCount);
+ body.setColumnCount(columnCount);
int columnGap =
- this.properties.get("column-gap").getLength().mvalue();
- body.setColumnGap(columnGap);
- return body;
+ this.properties.get("column-gap").getLength().mvalue();
+ body.setColumnGap(columnGap);
+ return body;
}
}
// FOP
import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.WritingMode;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.area.RegionReference;
protected Rectangle getViewportRectangle (FODimension reldims) {
- // Depends on extent and precedence
- Rectangle vpRect =
- new Rectangle(reldims.ipd - getExtent(), 0,
- getExtent(), reldims.bpd);
- adjustIPD(vpRect);
+ // Depends on extent, precedence and writing mode
+ Rectangle vpRect;
+ if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB)
+ vpRect = new Rectangle(reldims.ipd - getExtent(), 0,
+ getExtent(), reldims.bpd);
+ else
+ vpRect = new Rectangle(reldims.ipd - getExtent(), 0,
+ reldims.bpd, getExtent());
+ adjustIPD(vpRect, this.wm);
return vpRect;
}
public int getRegionAreaClass() {
return RegionReference.END;
}
-
}
// FOP
import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.WritingMode;
// Java
import java.awt.Rectangle;
* they extend in the BPD to the page reference rectangle
* diminish by extend of start and end if present.
*/
- protected void adjustIPD(Rectangle refRect) {
- int yoff = 0;
+ protected void adjustIPD(Rectangle refRect, int wm) {
+ int offset = 0;
Region before = getSiblingRegion(Region.BEFORE);
if (before != null && before.getPrecedence()) {
- yoff = before.getExtent();
- refRect.translate(0, yoff);
+ offset = before.getExtent();
+ refRect.translate(0, offset);
}
Region after = getSiblingRegion(Region.AFTER);
if (after != null && after.getPrecedence()) {
- yoff += after.getExtent();
+ offset += after.getExtent();
}
- if (yoff > 0) {
- refRect.grow(0,-yoff);
+ if (offset > 0) {
+ if (wm == WritingMode.LR_TB || wm == WritingMode.RL_TB)
+ refRect.height-=offset;
+ else
+ refRect.width-=offset;
}
}
}
// FOP
import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.WritingMode;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.area.RegionReference;
protected Rectangle getViewportRectangle (FODimension reldims) {
- // Depends on extent and precedence
+ // Depends on extent, precedence anâ writing mode
// This is the rectangle relative to the page-reference area in
// writing-mode relative coordinates
- Rectangle vpRect =
- new Rectangle(0, 0, getExtent(), reldims.bpd);
- adjustIPD(vpRect);
+ Rectangle vpRect;
+ if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB)
+ vpRect = new Rectangle(0, 0, getExtent(), reldims.bpd);
+ else
+ vpRect = new Rectangle(0, 0, reldims.bpd, getExtent());
+ adjustIPD(vpRect, this.wm);
return vpRect;
}
public int getRegionAreaClass() {
return RegionReference.START;
}
-
}
/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
+* $Id$
+* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+* For details on use and redistribution please refer to the
+* LICENSE file included with these sources.
+*/
package org.apache.fop.fo.pagination;
masterName = this.properties.get("master-name").getString();
if (masterName == null) {
getLogger().warn("simple-page-master does not have "
- + "a master-name and so is being ignored");
+ + "a master-name and so is being ignored");
} else {
layoutMasterSet.addSimplePageMaster(this);
}
} else {
throw new FOPException("fo:simple-page-master must be child "
- + "of fo:layout-master-set, not "
- + parent.getName());
+ + "of fo:layout-master-set, not "
+ + parent.getName());
}
- _regions = new HashMap();
+ //Well, there are only 5 regions so we can save a bit of memory here
+ _regions = new HashMap(5);
}
/**
*/
protected void end() {
int pageWidth =
- this.properties.get("page-width").getLength().mvalue();
+ this.properties.get("page-width").getLength().mvalue();
int pageHeight =
- this.properties.get("page-height").getLength().mvalue();
+ this.properties.get("page-height").getLength().mvalue();
// this.properties.get("reference-orientation");
// this.properties.get("writing-mode");
// Get absolute margin properties (top, left, bottom, right)
MarginProps mProps = propMgr.getMarginProps();
- /* Create the page reference area rectangle in first quadrant coordinates
- * (ie, 0,0 is at bottom,left of the "page media" and y increases
- * when moving towards the top of the page.
- * The media rectangle itself is (0,0,pageWidth,pageHeight).
- */
- Rectangle pageRefRect =
- new Rectangle(mProps.marginLeft, mProps.marginTop,
- pageWidth - mProps.marginLeft - mProps.marginRight,
- pageHeight - mProps.marginTop - mProps.marginBottom);
+ /* Create the page reference area rectangle (0,0 is at top left
+ * of the "page media" and y increases
+ * when moving towards the bottom of the page.
+ * The media rectangle itself is (0,0,pageWidth,pageHeight).
+ */
+ Rectangle pageRefRect =
+ new Rectangle(mProps.marginLeft, mProps.marginTop,
+ pageWidth - mProps.marginLeft - mProps.marginRight,
+ pageHeight - mProps.marginTop - mProps.marginBottom);
- // ??? KL shouldn't this take the viewport too???
- Page page = new Page(); // page reference area
+ // ??? KL shouldn't this take the viewport too???
+ Page page = new Page(); // page reference area
// Set up the CTM on the page reference area based on writing-mode
// and reference-orientation
- FODimension reldims=new FODimension(0,0);
- CTM pageCTM = propMgr.getCTMandRelDims(pageRefRect, reldims);
+ FODimension reldims=new FODimension(0,0);
+ CTM pageCTM = propMgr.getCTMandRelDims(pageRefRect, reldims);
- // Create a RegionViewport/ reference area pair for each page region
+ // Create a RegionViewport/ reference area pair for each page region
- boolean bHasBody=false;
+ boolean bHasBody=false;
for (Iterator regenum = _regions.values().iterator();
- regenum.hasNext(); ) {
+ regenum.hasNext(); ) {
Region r = (Region)regenum.next();
- RegionViewport rvp = r.makeRegionViewport(reldims, pageCTM);
- rvp.setRegion(r.makeRegionReferenceArea(rvp.getViewArea()));
- page.setRegion(r.getRegionAreaClass(), rvp);
- if (r.getRegionAreaClass() == RegionReference.BODY) {
- bHasBody = true;
- }
+ RegionViewport rvp = r.makeRegionViewport(reldims, pageCTM);
+ rvp.setRegion(r.makeRegionReferenceArea(rvp.getViewArea()));
+ page.setRegion(r.getRegionAreaClass(), rvp);
+ if (r.getRegionAreaClass() == RegionReference.BODY) {
+ bHasBody = true;
+ }
}
- if (!bHasBody) {
+ if (!bHasBody) {
getLogger().error("simple-page-master has no region-body");
}
- this.pageMaster = new PageMaster(new PageViewport(page,
- new Rectangle(0,0,
- pageWidth,pageHeight)));
+ this.pageMaster = new PageMaster(new PageViewport(page,
+ new Rectangle(0,0,
+ pageWidth,pageHeight)));
- // _regions = null; // PageSequence access SimplePageMaster....
+ // _regions = null; // PageSequence access SimplePageMaster....
children = null;
properties = null;
}
addRegion((Region)child);
} else {
getLogger().error("SimplePageMaster cannot have child of type " +
- child.getName());
+ child.getName());
}
}
String key = region.getRegionClass();
if (_regions.containsKey(key)) {
getLogger().error("Only one region of class "
- + key
- + " allowed within a simple-page-master.");
+ + key
+ + " allowed within a simple-page-master.");
// throw new FOPException("Only one region of class "
// + key
// + " allowed within a simple-page-master.");
protected boolean regionNameExists(String regionName) {
for (Iterator regenum = _regions.values().iterator();
- regenum.hasNext(); ) {
+ regenum.hasNext(); ) {
Region r = (Region)regenum.next();
if (r.getRegionName().equals(regionName)) {
return true;