From: Glen Mazza Date: Thu, 31 Mar 2005 04:32:54 +0000 (+0000) Subject: Moved page viewport creation logic from PSLM to PageViewport. X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b49e8724d01bd0a85f51f6c4e83031fbe6c69dbe;p=xmlgraphics-fop.git Moved page viewport creation logic from PSLM to PageViewport. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_KnuthStylePageBreaking@198556 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index b229e4c09..15381f6f3 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -18,6 +18,7 @@ package org.apache.fop.area; +import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; @@ -30,8 +31,14 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.Constants; +import org.apache.fop.fo.pagination.Region; +import org.apache.fop.fo.pagination.RegionBody; import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.fo.properties.CommonMarginBlock; +import org.apache.fop.layoutmgr.TraitSetter; /** * Page viewport that specifies the viewport area and holds the page contents. @@ -74,13 +81,23 @@ public class PageViewport implements Resolvable, Cloneable { /** * Create a page viewport. - * @param p the page reference area that holds the contents - * @param bounds the bounds of this viewport + * @param spm SimplePageMaster indicating the page and region dimensions + */ + public PageViewport(SimplePageMaster spm) { + this.spm = spm; + createPageAreas(); + } + + /** + * Create a page viewport + * @param spm SimplePageMaster indicating the page and region dimensions + * @param p Page Reference Area + * @param bounds Page Viewport dimensions */ public PageViewport(SimplePageMaster spm, Page p, Rectangle2D bounds) { - page = p; this.spm = spm; - viewArea = bounds; + this.page = p; + this.viewArea = bounds; } /** @@ -437,4 +454,92 @@ public class PageViewport implements Resolvable, Cloneable { public SimplePageMaster getSPM() { return spm; } + + private void createPageAreas() { + int pageWidth = spm.getPageWidth().getValue(); + int pageHeight = spm.getPageHeight().getValue(); + + // Get absolute margin properties (top, left, bottom, right) + CommonMarginBlock mProps = spm.getCommonMarginBlock(); + + /* 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.getValue(), mProps.marginTop.getValue(), + pageWidth - mProps.marginLeft.getValue() - mProps.marginRight.getValue(), + pageHeight - mProps.marginTop.getValue() - mProps.marginBottom.getValue()); + + 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 = CTM.getCTMandRelDims(spm.getReferenceOrientation(), + spm.getWritingMode(), pageRefRect, reldims); + + // Create a RegionViewport/ reference area pair for each page region + RegionReference rr = null; + for (Iterator regenum = spm.getRegions().values().iterator(); + regenum.hasNext();) { + Region r = (Region)regenum.next(); + RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM); + r.setLayoutDimension(PercentBase.BLOCK_IPD, rvp.getIPD()); + r.setLayoutDimension(PercentBase.BLOCK_BPD, rvp.getBPD()); + if (r.getNameId() == Constants.FO_REGION_BODY) { + RegionBody rb = (RegionBody) r; + rr = new BodyRegion(rb.getColumnCount(), rb.getColumnGap(), + rvp); + } else { + rr = new RegionReference(r.getNameId(), rvp); + } + setRegionReferencePosition(rr, r, rvp.getViewArea()); + rvp.setRegionReference(rr); + page.setRegionViewport(r.getNameId(), rvp); + } + + viewArea = new Rectangle(0, 0, pageWidth, pageHeight); + } + + /** + * Creates a RegionViewport Area object for this pagination Region. + * @param reldims relative dimensions + * @param pageCTM page coordinate transformation matrix + * @return the new region viewport + */ + private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) { + Rectangle2D relRegionRect = r.getViewportRectangle(reldims); + Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); + // Get the region viewport rectangle in absolute coords by + // transforming it using the page CTM + RegionViewport rv = new RegionViewport(absRegionRect); + rv.setBPD((int)relRegionRect.getHeight()); + rv.setIPD((int)relRegionRect.getWidth()); + TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground()); + rv.setClip(r.getOverflow() == Constants.EN_HIDDEN + || r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); + return rv; + } + + /** + * Set the region reference position within the region viewport. + * This sets the transform that is used to place the contents of + * the region reference. + * + * @param rr the region reference area + * @param r the region-xxx formatting object + * @param absRegVPRect The region viewport rectangle in "absolute" coordinates + * where x=distance from left, y=distance from bottom, width=right-left + * height=top-bottom + */ + private void setRegionReferencePosition(RegionReference rr, Region r, + Rectangle2D absRegVPRect) { + FODimension reldims = new FODimension(0, 0); + rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), + r.getWritingMode(), absRegVPRect, reldims)); + rr.setIPD(reldims.ipd); + rr.setBPD(reldims.bpd); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index 40ea0c0d1..a5148c810 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -20,41 +20,30 @@ package org.apache.fop.layoutmgr; import org.apache.fop.apps.FOPException; -import org.apache.fop.area.CTM; import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.AreaTreeModel; import org.apache.fop.area.Area; import org.apache.fop.area.PageViewport; import org.apache.fop.area.LineArea; -import org.apache.fop.area.Page; import org.apache.fop.area.RegionViewport; -import org.apache.fop.area.RegionReference; -import org.apache.fop.area.BodyRegion; import org.apache.fop.area.BeforeFloat; import org.apache.fop.area.Footnote; import org.apache.fop.area.Resolvable; import org.apache.fop.area.Trait; import org.apache.fop.datatypes.PercentBase; -import org.apache.fop.datatypes.FODimension; -import org.apache.fop.fo.FObj; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.Marker; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.Region; -import org.apache.fop.fo.pagination.RegionBody; import org.apache.fop.fo.pagination.SideRegion; import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.fo.pagination.StaticContent; -import org.apache.fop.fo.properties.CommonMarginBlock; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.awt.Rectangle; -import java.util.Iterator; -import java.awt.geom.Rectangle2D; import org.apache.fop.traits.MinOptMax; /** @@ -432,6 +421,13 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { // create a new page SimplePageMaster spm = pageSeq.getSimplePageMasterToUse( currentPageNum, bIsFirst, bIsBlank); + + // Unsure if these four lines are needed + int pageWidth = spm.getPageWidth().getValue(); + int pageHeight = spm.getPageHeight().getValue(); + pageSeq.getRoot().setLayoutDimension(PercentBase.BLOCK_IPD, pageWidth); + pageSeq.getRoot().setLayoutDimension(PercentBase.BLOCK_BPD, pageHeight); + Region body = spm.getRegion(FO_REGION_BODY); if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) { // this is fine by the XSL Rec (fo:flow's flow-name can be mapped to @@ -441,7 +437,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { + spm.getMasterName() + "'. FOP presently " + "does not support this."); } - curPage = createPageAreas(spm); + curPage = new PageViewport(spm); } catch (FOPException fopex) { throw new IllegalArgumentException("Cannot create page: " + fopex.getMessage()); } @@ -673,95 +669,4 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { return true; } } - - private PageViewport createPageAreas(SimplePageMaster spm) { - int pageWidth = spm.getPageWidth().getValue(); - int pageHeight = spm.getPageHeight().getValue(); - - // Set the page dimension as the toplevel containing block for margin. - ((FObj) pageSeq.getParent()).setLayoutDimension(PercentBase.BLOCK_IPD, pageWidth); - ((FObj) pageSeq.getParent()).setLayoutDimension(PercentBase.BLOCK_BPD, pageHeight); - - // Get absolute margin properties (top, left, bottom, right) - CommonMarginBlock mProps = spm.getCommonMarginBlock(); - - /* 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.getValue(), mProps.marginTop.getValue(), - pageWidth - mProps.marginLeft.getValue() - mProps.marginRight.getValue(), - pageHeight - mProps.marginTop.getValue() - mProps.marginBottom.getValue()); - - 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 = CTM.getCTMandRelDims(spm.getReferenceOrientation(), - spm.getWritingMode(), pageRefRect, reldims); - - // Create a RegionViewport/ reference area pair for each page region - RegionReference rr = null; - for (Iterator regenum = spm.getRegions().values().iterator(); - regenum.hasNext();) { - Region r = (Region)regenum.next(); - RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM); - r.setLayoutDimension(PercentBase.BLOCK_IPD, rvp.getIPD()); - r.setLayoutDimension(PercentBase.BLOCK_BPD, rvp.getBPD()); - if (r.getNameId() == FO_REGION_BODY) { - RegionBody rb = (RegionBody) r; - rr = new BodyRegion(rb.getColumnCount(), rb.getColumnGap(), - rvp); - } else { - rr = new RegionReference(r.getNameId(), rvp); - } - setRegionReferencePosition(rr, r, rvp.getViewArea()); - rvp.setRegionReference(rr); - page.setRegionViewport(r.getNameId(), rvp); - } - - return new PageViewport(spm, page, new Rectangle(0, 0, pageWidth, pageHeight)); - } - - /** - * Creates a RegionViewport Area object for this pagination Region. - * @param reldims relative dimensions - * @param pageCTM page coordinate transformation matrix - * @return the new region viewport - */ - private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) { - Rectangle2D relRegionRect = r.getViewportRectangle(reldims); - Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); - // Get the region viewport rectangle in absolute coords by - // transforming it using the page CTM - RegionViewport rv = new RegionViewport(absRegionRect); - rv.setBPD((int)relRegionRect.getHeight()); - rv.setIPD((int)relRegionRect.getWidth()); - TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground()); - rv.setClip(r.getOverflow() == EN_HIDDEN || r.getOverflow() == EN_ERROR_IF_OVERFLOW); - return rv; - } - - /** - * Set the region reference position within the region viewport. - * This sets the transform that is used to place the contents of - * the region reference. - * - * @param rr the region reference area - * @param r the region-xxx formatting object - * @param absRegVPRect The region viewport rectangle in "absolute" coordinates - * where x=distance from left, y=distance from bottom, width=right-left - * height=top-bottom - */ - private void setRegionReferencePosition(RegionReference rr, Region r, - Rectangle2D absRegVPRect) { - FODimension reldims = new FODimension(0, 0); - rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), - r.getWritingMode(), absRegVPRect, reldims)); - rr.setIPD(reldims.ipd); - rr.setBPD(reldims.bpd); - } }