1 17 18 19 20 package org.apache.fop.area; 21 22 import java.awt.Rectangle ; 23 import java.awt.geom.Rectangle2D ; 24 import java.io.Serializable ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 28 import org.apache.fop.datatypes.FODimension; 29 import org.apache.fop.datatypes.LengthBase; 30 import org.apache.fop.datatypes.SimplePercentBaseContext; 31 import org.apache.fop.fo.Constants; 32 import org.apache.fop.fo.pagination.Region; 33 import org.apache.fop.fo.pagination.RegionBody; 34 import org.apache.fop.fo.pagination.SimplePageMaster; 35 import org.apache.fop.fo.properties.CommonMarginBlock; 36 import org.apache.fop.layoutmgr.TraitSetter; 37 38 49 public class Page extends AreaTreeObject implements Serializable , Cloneable { 50 private RegionViewport regionBefore = null; 52 private RegionViewport regionStart = null; 53 private RegionViewport regionBody = null; 54 private RegionViewport regionEnd = null; 55 private RegionViewport regionAfter = null; 56 57 private Map unresolved = null; 59 60 61 private boolean fakeNonEmpty = false; 62 63 66 public Page() { 67 } 68 69 74 public Page(SimplePageMaster spm) { 75 FODimension pageViewPortDims = new FODimension(spm.getPageWidth().getValue() 77 , spm.getPageHeight().getValue()); 78 79 CommonMarginBlock mProps = spm.getCommonMarginBlock(); 81 82 88 95 SimplePercentBaseContext pageWidthContext 96 = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH 97 , pageViewPortDims.ipd); 98 SimplePercentBaseContext pageHeightContext 99 = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH 100 , pageViewPortDims.bpd); 101 102 Rectangle pageRefRect 103 = new Rectangle (mProps.marginLeft.getValue(pageWidthContext) 104 , mProps.marginTop.getValue(pageHeightContext) 105 , pageViewPortDims.ipd 106 - mProps.marginLeft.getValue(pageWidthContext) 107 - mProps.marginRight.getValue(pageWidthContext) 108 , pageViewPortDims.bpd 109 - mProps.marginTop.getValue(pageHeightContext) 110 - mProps.marginBottom.getValue(pageHeightContext)); 111 112 FODimension reldims = new FODimension(0, 0); 115 CTM pageCTM = CTM.getCTMandRelDims(spm.getReferenceOrientation(), 116 spm.getWritingMode(), pageRefRect, reldims); 117 118 RegionReference rr = null; 120 for (Iterator regenum = spm.getRegions().values().iterator(); 121 regenum.hasNext();) { 122 Region r = (Region)regenum.next(); 123 RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM, spm); 124 if (r.getNameId() == Constants.FO_REGION_BODY) { 125 rr = new BodyRegion((RegionBody) r, rvp); 126 } else { 127 rr = new RegionReference(r, rvp); 128 } 129 setRegionReferencePosition(rr, r, rvp.getViewArea()); 130 rvp.setRegionReference(rr); 131 setRegionViewport(r.getNameId(), rvp); 132 } 133 } 134 135 138 public void fakeNonEmpty() { 139 this.fakeNonEmpty = true; 140 } 141 142 150 private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM, 151 SimplePageMaster spm) { 152 Rectangle2D relRegionRect = r.getViewportRectangle(reldims, spm); 153 Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); 154 RegionViewport rv = new RegionViewport(absRegionRect); 157 rv.setBPD((int)relRegionRect.getHeight()); 158 rv.setIPD((int)relRegionRect.getWidth()); 159 TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground(), null); 160 rv.setClip(r.getOverflow() == Constants.EN_HIDDEN 161 || r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); 162 return rv; 163 } 164 165 176 private void setRegionReferencePosition(RegionReference rr, Region r, 177 Rectangle2D absRegVPRect) { 178 FODimension reldims = new FODimension(0, 0); 179 rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), 180 r.getWritingMode(), absRegVPRect, reldims)); 181 rr.setIPD(reldims.ipd); 182 rr.setBPD(reldims.bpd); 183 } 184 185 191 public void setRegionViewport(int areaclass, RegionViewport port) { 192 if (areaclass == Constants.FO_REGION_BEFORE) { 193 regionBefore = port; 194 } else if (areaclass == Constants.FO_REGION_START) { 195 regionStart = port; 196 } else if (areaclass == Constants.FO_REGION_BODY) { 197 regionBody = port; 198 } else if (areaclass == Constants.FO_REGION_END) { 199 regionEnd = port; 200 } else if (areaclass == Constants.FO_REGION_AFTER) { 201 regionAfter = port; 202 } 203 } 204 205 211 public RegionViewport getRegionViewport(int areaclass) { 212 if (areaclass == Constants.FO_REGION_BEFORE) { 213 return regionBefore; 214 } else if (areaclass == Constants.FO_REGION_START) { 215 return regionStart; 216 } else if (areaclass == Constants.FO_REGION_BODY) { 217 return regionBody; 218 } else if (areaclass == Constants.FO_REGION_END) { 219 return regionEnd; 220 } else if (areaclass == Constants.FO_REGION_AFTER) { 221 return regionAfter; 222 } 223 throw new IllegalArgumentException ("No such area class with ID = " 224 + areaclass); 225 } 226 227 232 public boolean isEmpty() { 233 if (fakeNonEmpty) { 234 return false; 235 } else if (regionBody == null) { 236 return true; 237 } else { 238 BodyRegion body = (BodyRegion)regionBody.getRegionReference(); 239 return body.isEmpty(); 240 } 241 } 242 243 249 public Object clone() { 250 Page p = new Page(); 251 if (regionBefore != null) { 252 p.regionBefore = (RegionViewport)regionBefore.clone(); 253 } 254 if (regionStart != null) { 255 p.regionStart = (RegionViewport)regionStart.clone(); 256 } 257 if (regionBody != null) { 258 p.regionBody = (RegionViewport)regionBody.clone(); 259 } 260 if (regionEnd != null) { 261 p.regionEnd = (RegionViewport)regionEnd.clone(); 262 } 263 if (regionAfter != null) { 264 p.regionAfter = (RegionViewport)regionAfter.clone(); 265 } 266 267 return p; 268 } 269 270 275 public void setUnresolvedReferences(Map unres) { 276 unresolved = unres; 277 } 278 279 286 public Map getUnresolvedReferences() { 287 return unresolved; 288 } 289 290 } 291 292 | Popular Tags |