1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.fop.datatypes.LengthBase; 25 import org.apache.fop.datatypes.PercentBaseContext; 26 import org.apache.fop.fo.FObj; 27 28 34 public abstract class AbstractBaseLayoutManager 35 implements LayoutManager, PercentBaseContext { 36 37 38 protected boolean generatesReferenceArea = false; 39 40 protected boolean generatesBlockArea = false; 41 42 protected FObj fobj = null; 43 44 47 private static Log log = LogFactory.getLog(AbstractBaseLayoutManager.class); 48 49 52 public AbstractBaseLayoutManager() { 53 } 54 55 60 public AbstractBaseLayoutManager(FObj fo) { 61 fobj = fo; 62 setGeneratesReferenceArea(fo.generatesReferenceAreas()); 63 if (getGeneratesReferenceArea()) { 64 setGeneratesBlockArea(true); 65 } 66 } 67 68 70 73 public int getBaseLength(int lengthBase, FObj fobj) { 74 if (fobj == getFObj()) { 75 switch (lengthBase) { 76 case LengthBase.CONTAINING_BLOCK_WIDTH: 77 return getAncestorBlockAreaIPD(); 78 case LengthBase.CONTAINING_BLOCK_HEIGHT: 79 return getAncestorBlockAreaBPD(); 80 case LengthBase.PARENT_AREA_WIDTH: 81 return getParentAreaIPD(); 82 case LengthBase.CONTAINING_REFAREA_WIDTH: 83 return getReferenceAreaIPD(); 84 default: 85 log.error(new Exception ("Unknown base type for LengthBase:" + lengthBase)); 86 return 0; 87 } 88 } else { 89 LayoutManager lm = getParent(); 90 while (lm != null && fobj != lm.getFObj()) { 91 lm = lm.getParent(); 92 } 93 if (lm != null) { 94 return lm.getBaseLength(lengthBase, fobj); 95 } 96 } 97 log.error("Cannot find LM to handle given FO for LengthBase."); 98 return 0; 99 } 100 101 106 protected int getAncestorBlockAreaIPD() { 107 LayoutManager lm = getParent(); 108 while (lm != null) { 109 if (lm.getGeneratesBlockArea() && !lm.getGeneratesLineArea()) { 110 return lm.getContentAreaIPD(); 111 } 112 lm = lm.getParent(); 113 } 114 if (lm == null) { 115 log.error("No parent LM found"); 116 } 117 return 0; 118 } 119 120 125 protected int getAncestorBlockAreaBPD() { 126 LayoutManager lm = getParent(); 127 while (lm != null) { 128 if (lm.getGeneratesBlockArea() && !lm.getGeneratesLineArea()) { 129 return lm.getContentAreaBPD(); 130 } 131 lm = lm.getParent(); 132 } 133 if (lm == null) { 134 log.error("No parent LM found"); 135 } 136 return 0; 137 } 138 139 143 protected int getParentAreaIPD() { 144 LayoutManager lm = getParent(); 145 if (lm != null) { 146 return lm.getContentAreaIPD(); 147 } 148 log.error("No parent LM found"); 149 return 0; 150 } 151 152 156 protected int getParentAreaBPD() { 157 LayoutManager lm = getParent(); 158 if (lm != null) { 159 return lm.getContentAreaBPD(); 160 } 161 log.error("No parent LM found"); 162 return 0; 163 } 164 165 170 public int getReferenceAreaIPD() { 171 LayoutManager lm = getParent(); 172 while (lm != null) { 173 if (lm.getGeneratesReferenceArea()) { 174 return lm.getContentAreaIPD(); 175 } 176 lm = lm.getParent(); 177 } 178 if (lm == null) { 179 log.error("No parent LM found"); 180 } 181 return 0; 182 } 183 184 189 protected int getReferenceAreaBPD() { 190 LayoutManager lm = getParent(); 191 while (lm != null) { 192 if (lm.getGeneratesReferenceArea()) { 193 return lm.getContentAreaBPD(); 194 } 195 lm = lm.getParent(); 196 } 197 if (lm == null) { 198 log.error("No parent LM found"); 199 } 200 return 0; 201 } 202 203 208 public int getContentAreaIPD() { 209 log.error("getContentAreaIPD called when it should have been overwritten"); 210 return 0; 211 } 212 213 218 public int getContentAreaBPD() { 219 log.error("getContentAreaBPD called when it should have been overwritten"); 220 return 0; 221 } 222 223 226 public boolean getGeneratesReferenceArea() { 227 return generatesReferenceArea; 228 } 229 230 236 protected void setGeneratesReferenceArea(boolean generatesReferenceArea) { 237 this.generatesReferenceArea = generatesReferenceArea; 238 } 239 240 243 public boolean getGeneratesBlockArea() { 244 return generatesBlockArea; 245 } 246 247 252 protected void setGeneratesBlockArea(boolean generatesBlockArea) { 253 this.generatesBlockArea = generatesBlockArea; 254 } 255 256 259 public boolean getGeneratesLineArea() { 260 return false; 261 } 262 263 266 public FObj getFObj() { 267 return fobj; 268 } 269 270 } 271 | Popular Tags |