From 89334b80f73efa8abfbd6a4d7db94a6fbd8e854f Mon Sep 17 00:00:00 2001 From: Oleg Tkachenko Date: Sun, 5 Jan 2003 09:03:12 +0000 Subject: [PATCH] =?utf8?q?Made=20regions=20to=20be=20writing-mod=EF=BF=BD?= =?utf8?q?=20aware,=20now=20it's=20ok=20for=20lr-tb,=20rl-tb=20and=20tb-rl?= =?utf8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195815 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/pagination/Region.java | 26 +++--- .../apache/fop/fo/pagination/RegionAfter.java | 14 +-- .../apache/fop/fo/pagination/RegionBA.java | 18 ++-- .../fop/fo/pagination/RegionBefore.java | 34 ++++---- .../apache/fop/fo/pagination/RegionBody.java | 71 +++++++++------- .../apache/fop/fo/pagination/RegionEnd.java | 16 ++-- .../apache/fop/fo/pagination/RegionSE.java | 18 ++-- .../apache/fop/fo/pagination/RegionStart.java | 13 +-- .../fop/fo/pagination/SimplePageMaster.java | 85 ++++++++++--------- 9 files changed, 163 insertions(+), 132 deletions(-) diff --git a/src/org/apache/fop/fo/pagination/Region.java b/src/org/apache/fop/fo/pagination/Region.java index 8a0b3480b..a11d94809 100644 --- a/src/org/apache/fop/fo/pagination/Region.java +++ b/src/org/apache/fop/fo/pagination/Region.java @@ -7,11 +7,11 @@ 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; @@ -23,24 +23,26 @@ import org.apache.fop.area.RegionViewport; 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); @@ -60,8 +62,8 @@ public abstract class Region extends FObj { if (isReserved(getRegionName()) &&!getRegionName().equals(getDefaultRegionName())) { throw new FOPException(PROP_REGION_NAME + " '" + _regionName - + "' for " + this.name - + " not permitted."); + + "' for " + this.name + + " not permitted."); } } @@ -69,9 +71,10 @@ public abstract class Region extends FObj { _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(); } /** @@ -195,5 +198,4 @@ public abstract class Region extends FObj { int getExtent() { return 0; } - } diff --git a/src/org/apache/fop/fo/pagination/RegionAfter.java b/src/org/apache/fop/fo/pagination/RegionAfter.java index 15202520c..f6484a154 100644 --- a/src/org/apache/fop/fo/pagination/RegionAfter.java +++ b/src/org/apache/fop/fo/pagination/RegionAfter.java @@ -9,6 +9,7 @@ package org.apache.fop.fo.pagination; // 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; @@ -22,12 +23,14 @@ public class RegionAfter extends RegionBA { } 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; } @@ -43,6 +46,5 @@ public class RegionAfter extends RegionBA { public String getRegionClass() { return Region.AFTER; } - } diff --git a/src/org/apache/fop/fo/pagination/RegionBA.java b/src/org/apache/fop/fo/pagination/RegionBA.java index 94d34760a..88d88ec50 100644 --- a/src/org/apache/fop/fo/pagination/RegionBA.java +++ b/src/org/apache/fop/fo/pagination/RegionBA.java @@ -10,6 +10,7 @@ package org.apache.fop.fo.pagination; // 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; @@ -39,19 +40,22 @@ public abstract class RegionBA extends RegionBASE { * 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; } } } diff --git a/src/org/apache/fop/fo/pagination/RegionBefore.java b/src/org/apache/fop/fo/pagination/RegionBefore.java index 7c9d96b13..5ec2a64d6 100644 --- a/src/org/apache/fop/fo/pagination/RegionBefore.java +++ b/src/org/apache/fop/fo/pagination/RegionBefore.java @@ -9,7 +9,8 @@ package org.apache.fop.fo.pagination; // 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 @@ -21,10 +22,6 @@ public class RegionBefore extends RegionBA { super(parent); } -// public void handleAttrs(Attributes attlist) throws FOPException { -// super.handleAttrs(attlist); -// } - protected String getDefaultRegionName() { return "xsl-region-before"; } @@ -38,18 +35,21 @@ public class RegionBefore extends RegionBA { } 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; } - } diff --git a/src/org/apache/fop/fo/pagination/RegionBody.java b/src/org/apache/fop/fo/pagination/RegionBody.java index be058b33b..938ea1ac3 100644 --- a/src/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/org/apache/fop/fo/pagination/RegionBody.java @@ -17,6 +17,7 @@ import org.apache.fop.fo.FObj; 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; @@ -33,20 +34,30 @@ public class RegionBody extends Region { 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; } /** @@ -54,14 +65,14 @@ public class RegionBody extends Region { * 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() { @@ -80,24 +91,24 @@ public class RegionBody extends Region { * 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; } } diff --git a/src/org/apache/fop/fo/pagination/RegionEnd.java b/src/org/apache/fop/fo/pagination/RegionEnd.java index 7b6cf0d99..7d13ebb7b 100644 --- a/src/org/apache/fop/fo/pagination/RegionEnd.java +++ b/src/org/apache/fop/fo/pagination/RegionEnd.java @@ -12,6 +12,7 @@ import java.awt.Rectangle; // 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; @@ -25,11 +26,15 @@ public class RegionEnd extends RegionSE { 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; } @@ -45,6 +50,5 @@ public class RegionEnd extends RegionSE { public int getRegionAreaClass() { return RegionReference.END; } - } diff --git a/src/org/apache/fop/fo/pagination/RegionSE.java b/src/org/apache/fop/fo/pagination/RegionSE.java index b3e84eb84..f4b4a3164 100644 --- a/src/org/apache/fop/fo/pagination/RegionSE.java +++ b/src/org/apache/fop/fo/pagination/RegionSE.java @@ -9,6 +9,7 @@ package org.apache.fop.fo.pagination; // FOP import org.apache.fop.fo.*; +import org.apache.fop.fo.properties.WritingMode; // Java import java.awt.Rectangle; @@ -27,19 +28,22 @@ public abstract class RegionSE extends RegionBASE { * 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; } } } diff --git a/src/org/apache/fop/fo/pagination/RegionStart.java b/src/org/apache/fop/fo/pagination/RegionStart.java index 9607b638f..d55096d20 100644 --- a/src/org/apache/fop/fo/pagination/RegionStart.java +++ b/src/org/apache/fop/fo/pagination/RegionStart.java @@ -12,6 +12,7 @@ import java.awt.Rectangle; // 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; @@ -24,12 +25,15 @@ public class RegionStart extends RegionSE { 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; } @@ -44,6 +48,5 @@ public class RegionStart extends RegionSE { public int getRegionAreaClass() { return RegionReference.START; } - } diff --git a/src/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/org/apache/fop/fo/pagination/SimplePageMaster.java index a14beb534..fd5c310c5 100644 --- a/src/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -1,9 +1,9 @@ /* - * $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; @@ -52,16 +52,17 @@ public class SimplePageMaster extends FObj { 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); } /** @@ -70,57 +71,57 @@ public class SimplePageMaster extends FObj { */ 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; } @@ -146,7 +147,7 @@ public class SimplePageMaster extends FObj { addRegion((Region)child); } else { getLogger().error("SimplePageMaster cannot have child of type " + - child.getName()); + child.getName()); } } @@ -154,8 +155,8 @@ public class SimplePageMaster extends FObj { 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."); @@ -174,7 +175,7 @@ public class SimplePageMaster extends FObj { 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; -- 2.39.5