import org.apache.fop.area.CTM;
import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.RegionReference;
+import org.apache.fop.layoutmgr.AbstractLayoutManager;
import org.xml.sax.Attributes;
Rectangle2D absRegionRect = pageCTM.transform(relRegionRect);
// Get the region viewport rectangle in absolute coords by
// transforming it using the page CTM
- return new RegionViewport(absRegionRect);
+ RegionViewport rv = new RegionViewport(absRegionRect);
+ setRegionViewportTraits(rv);
+ return rv;
}
+ /**
+ * Set the region viewport traits.
+ * The viewport has the border, background and
+ * clipping overflow traits.
+ *
+ * @param r the region viewport
+ */
+ protected void setRegionViewportTraits(RegionViewport r) {
+ // Common Border, Padding, and Background Properties
+ BorderAndPadding bap = propMgr.getBorderAndPadding();
+ BackgroundProps bProps = propMgr.getBackgroundProps();
+ AbstractLayoutManager.addBorders(r, bap);
+ AbstractLayoutManager.addBackground(r, bProps);
+
+ // this.properties.get("clip");
+ // this.properties.get("display-align");
+ this.overflow = this.properties.get("overflow").getEnum();
+ }
protected abstract Rectangle getViewportRectangle(FODimension pageRefRect);
*/
public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) {
RegionReference r = new RegionReference(getRegionAreaClass());
- setRegionTraits(r, absRegVPRect);
+ setRegionPosition(r, absRegVPRect);
return r;
}
- protected void setRegionTraits(RegionReference r, Rectangle2D absRegVPRect) {
- // Common Border, Padding, and Background Properties
- BorderAndPadding bap = propMgr.getBorderAndPadding();
- BackgroundProps bProps = propMgr.getBackgroundProps();
-/* backgroundColor = properties.get("background-color").getColorType();*/
-
- // this.properties.get("clip");
- // this.properties.get("display-align");
- this.overflow = this.properties.get("overflow").getEnum();
+ /**
+ * Set the region position inside the region viewport.
+ * This sets the trasnform that is used to place the contents of
+ * the region.
+ *
+ * @param r the region reference area
+ * @param absRegVPRect the rectangle to place the region contents
+ */
+ protected void setRegionPosition(RegionReference r, Rectangle2D absRegVPRect) {
FODimension reldims = new FODimension(0,0);
r.setCTM(propMgr.getCTMandRelDims(absRegVPRect, reldims));
-
- //r.setBackground(bProps);
}
/**
return ((prop != null)? prop.getLength().mvalue() : 0);
}
- protected void setRegionTraits(RegionReference r, Rectangle2D absRegVPRect) {
- super.setRegionTraits(r, absRegVPRect);
-
-// r.setBackgroundColor(backgroundColor);
- }
-
protected String getDefaultRegionName() {
return "xsl-region-body";
}
-
public String getRegionClass() {
return Region.BODY;
}
public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) {
// Should set some column stuff here I think, or put it elsewhere
BodyRegion body = new BodyRegion();
- setRegionTraits(body, absRegVPRect);
+ setRegionPosition(body, absRegVPRect);
int columnCount=
this.properties.get("column-count").getNumber().intValue();
if ((columnCount > 1) && (overflow == Overflow.SCROLL)) {
* Layout managers that create areas with borders can use this to
* add the borders to the area.
*/
- public void addBorders(Area curBlock, BorderAndPadding bordProps) {
+ public static void addBorders(Area curBlock, BorderAndPadding bordProps) {
BorderProps bps = getBorderProps(bordProps, BorderAndPadding.TOP);
if(bps.width != 0) {
curBlock.addTrait(Trait.BORDER_BEFORE, bps);
}
}
- private BorderProps getBorderProps(BorderAndPadding bordProps, int side) {
+ private static BorderProps getBorderProps(BorderAndPadding bordProps, int side) {
BorderProps bps;
bps = new BorderProps(bordProps.getBorderStyle(side),
bordProps.getBorderWidth(side, false),
* Layout managers that create areas with a background can use this to
* add the background to the area.
*/
- public void addBackground(Area curBlock, BackgroundProps backProps) {
+ public static void addBackground(Area curBlock, BackgroundProps backProps) {
Trait.Background back = new Trait.Background();
back.color = backProps.backColor;
// The CTM will transform coordinates relative to
// this region-reference area into page coords, so
// set origin for the region to 0,0.
- currentBPPosition = 0;// (int) (view.getY() / 1000);
- currentIPPosition = 0;// (int) (view.getX() / 1000);
+ currentBPPosition = 0;
+ currentIPPosition = 0;
currentBlockIPPosition = currentIPPosition;
RegionReference region = port.getRegion();
+ // shouldn't the viewport have the CTM
startVParea(region.getCTM());
+
+ // do after starting viewport area
+ handleViewportTraits(port);
if (region.getRegionClass() == RegionReference.BODY) {
renderBodyRegion((BodyRegion) region);
} else {
*/
protected void startVParea(CTM ctm) { }
+ /**
+ * Handle viewport traits.
+ * This should be overridden to draw border and background
+ * traits for the viewport area.
+ *
+ * @param vp the region viewport area
+ */
+ protected void handleViewportTraits(RegionViewport rv) {
+ // draw border and background
+ }
+
/**
* @todo Description of the Method
*/
import org.apache.fop.area.Title;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Page;
-import org.apache.fop.area.RegionReference;
+import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
}
}
+ /**
+ * Start the next page sequence.
+ * For the pdf renderer there is no concept of page sequences
+ * but it uses the first available page sequence title to set
+ * as the title of the pdf document.
+ *
+ * @param seqTitle the title of the page sequence
+ */
public void startPageSequence(Title seqTitle) {
if (seqTitle != null) {
String str = convertTitleToString(seqTitle);
* and then stored to add the contents later.
* The page objects is stored using the area tree PageViewport
* as a key.
+ *
+ * @param page the page to prepare
*/
public void preparePage(PageViewport page) {
this.pdfResources = this.pdfDoc.getResources();
currentState.pop();
}
- protected void renderRegion(RegionReference region) {
- // Draw a rectangle so we can see it!
- // x=0,y=0,w=ipd,h=bpd
+ /**
+ * Handle the viewport traits.
+ * This is used to draw the traits for a viewport.
+ *
+ * @param region the viewport region to handle
+ */
+ protected void handleViewportTraits(RegionViewport region) {
currentFontName = "";
- super.renderRegion(region);
+ float startx = 0;
+ float starty = 0;
+ Rectangle2D viewArea = region.getViewArea();
+ float width = (float)(viewArea.getWidth() / 1000f);
+ float height = (float)(viewArea.getHeight() / 1000f);
+ Trait.Background back;
+ back = (Trait.Background)region.getTrait(Trait.BACKGROUND);
+ drawBackAndBorders(region, startx, starty, width, height);
}
/**
*/
public void renderViewport(Viewport viewport) {
closeText();
+
+ float x = currentBlockIPPosition / 1000f;
+ float y = (currentBPPosition + viewport.getOffset()) / 1000f;
+ float width = viewport.getWidth() / 1000f;
+ float height = viewport.getHeight() / 1000f;
+ drawBackAndBorders(viewport, x, y, width, height);
+
currentStream.add("ET\n");
+
if (viewport.getClip()) {
currentStream.add("q\n");
- float x = currentBlockIPPosition / 1000f;
- float y = (currentBPPosition + viewport.getOffset()) / 1000f;
- float width = viewport.getWidth() / 1000f;
- float height = viewport.getHeight() / 1000f;
clip(x, y, width, height);
}
super.renderViewport(viewport);