From: Keiron Liddle Date: Wed, 6 Nov 2002 15:36:29 +0000 (+0000) Subject: background and borders for regions X-Git-Tag: Alt-Design-integration-base~348 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f7bd5a64214f473747680e45369fa214dc6af367;p=xmlgraphics-fop.git background and borders for regions git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195435 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/pagination/Region.java b/src/org/apache/fop/fo/pagination/Region.java index 247984954..58d1989c0 100644 --- a/src/org/apache/fop/fo/pagination/Region.java +++ b/src/org/apache/fop/fo/pagination/Region.java @@ -22,6 +22,7 @@ import org.apache.fop.apps.FOPException; 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; @@ -82,9 +83,29 @@ public abstract class Region extends FObj { 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); @@ -96,23 +117,21 @@ public abstract class Region extends FObj { */ 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); } /** diff --git a/src/org/apache/fop/fo/pagination/RegionBody.java b/src/org/apache/fop/fo/pagination/RegionBody.java index f8dadc4f4..d93f4bfa8 100644 --- a/src/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/org/apache/fop/fo/pagination/RegionBody.java @@ -65,17 +65,10 @@ public class RegionBody extends Region { 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; } @@ -90,7 +83,7 @@ public class RegionBody extends Region { 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)) { diff --git a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 1fee65d2e..53cfdaa34 100644 --- a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -320,7 +320,7 @@ public abstract class AbstractLayoutManager implements LayoutManager { * 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); @@ -339,7 +339,7 @@ public abstract class AbstractLayoutManager implements LayoutManager { } } - 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), @@ -352,7 +352,7 @@ public abstract class AbstractLayoutManager implements LayoutManager { * 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; diff --git a/src/org/apache/fop/render/AbstractRenderer.java b/src/org/apache/fop/render/AbstractRenderer.java index 1e1c060a8..bf489acf6 100644 --- a/src/org/apache/fop/render/AbstractRenderer.java +++ b/src/org/apache/fop/render/AbstractRenderer.java @@ -216,12 +216,16 @@ public abstract class AbstractRenderer extends AbstractLogEnabled // 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 { @@ -238,6 +242,17 @@ public abstract class AbstractRenderer extends AbstractLogEnabled */ 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 */ diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 6fe9dad6b..1fc8d832d 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -37,7 +37,7 @@ import org.apache.fop.area.CTM; 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; @@ -295,6 +295,14 @@ public class PDFRenderer extends PrintRenderer { } } + /** + * 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); @@ -309,6 +317,8 @@ public class PDFRenderer extends PrintRenderer { * 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(); @@ -393,11 +403,22 @@ public class PDFRenderer extends PrintRenderer { 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); } /** @@ -1052,14 +1073,18 @@ public class PDFRenderer extends PrintRenderer { */ 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);