1 17 18 19 20 package org.apache.fop.fo.properties; 21 22 import org.apache.fop.datatypes.Numeric; 23 import org.apache.fop.fo.FONode; 24 import org.apache.fop.fo.FObj; 25 import org.apache.fop.fo.PropertyList; 26 import org.apache.fop.fo.expr.NumericOp; 27 import org.apache.fop.fo.expr.PropertyException; 28 29 34 public class IndentPropertyMaker extends CorrespondingPropertyMaker { 35 38 private int[] paddingCorresponding = null; 39 40 43 private int[] borderWidthCorresponding = null; 44 45 49 public IndentPropertyMaker(PropertyMaker baseMaker) { 50 super(baseMaker); 51 } 52 53 57 public void setPaddingCorresponding(int[] paddingCorresponding) { 58 this.paddingCorresponding = paddingCorresponding; 59 } 60 61 65 public void setBorderWidthCorresponding(int[] borderWidthCorresponding) { 66 this.borderWidthCorresponding = borderWidthCorresponding; 67 } 68 69 73 public Property compute(PropertyList propertyList) throws PropertyException { 74 if (propertyList.getFObj().getUserAgent() 75 .isBreakIndentInheritanceOnReferenceAreaBoundary()) { 76 return computeAlternativeRuleset(propertyList); 77 } else { 78 return computeConforming(propertyList); 79 } 80 } 81 82 86 public Property computeConforming(PropertyList propertyList) throws PropertyException { 87 PropertyList pList = getWMPropertyList(propertyList); 88 if (pList == null) { 89 return null; 90 } 91 93 Numeric padding = getCorresponding(paddingCorresponding, propertyList).getNumeric(); 94 Numeric border = getCorresponding(borderWidthCorresponding, propertyList).getNumeric(); 95 96 int marginProp = pList.getWritingMode(lr_tb, rl_tb, tb_rl); 97 if (propertyList.getExplicitOrShorthand(marginProp) == null) { 99 Property indent = propertyList.getExplicit(baseMaker.propId); 100 if (indent == null) { 101 return null; 103 } else { 104 return indent; 106 } 107 } else { 108 Numeric margin = propertyList.get(marginProp).getNumeric(); 110 111 Numeric v = new FixedLength(0); 112 if (!propertyList.getFObj().generatesReferenceAreas()) { 113 v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric()); 115 } 116 v = NumericOp.addition(v, margin); 118 v = NumericOp.addition(v, padding); 119 v = NumericOp.addition(v, border); 120 return (Property) v; 121 } 122 123 } 124 125 private boolean isInherited(PropertyList pList) { 126 if (pList.getFObj().getUserAgent().isBreakIndentInheritanceOnReferenceAreaBoundary()) { 127 FONode nd = pList.getFObj().getParent(); 128 return !((nd instanceof FObj) && ((FObj)nd).generatesReferenceAreas()); 129 } else { 130 return true; 131 } 132 } 133 134 141 public Property computeAlternativeRuleset(PropertyList propertyList) throws PropertyException { 142 PropertyList pList = getWMPropertyList(propertyList); 143 if (pList == null) { 144 return null; 145 } 146 147 149 Numeric padding = getCorresponding(paddingCorresponding, propertyList).getNumeric(); 150 Numeric border = getCorresponding(borderWidthCorresponding, propertyList).getNumeric(); 151 152 int marginProp = pList.getWritingMode(lr_tb, rl_tb, tb_rl); 153 154 boolean marginNearest = false; 157 PropertyList pl = propertyList.getParentPropertyList(); 158 while (pl != null) { 159 if (pl.getExplicit(baseMaker.propId) != null) { 160 break; 161 } else if (pl.getExplicitOrShorthand(marginProp) != null) { 162 marginNearest = true; 163 break; 164 } 165 pl = pl.getParentPropertyList(); 166 } 167 168 if (propertyList.getExplicitOrShorthand(marginProp) == null) { 170 Property indent = propertyList.getExplicit(baseMaker.propId); 171 if (indent == null) { 172 if (isInherited(propertyList) || !marginNearest) { 174 return null; 175 } else { 176 return new FixedLength(0); 177 } 178 } else { 179 return indent; 180 } 181 } else { 182 Numeric margin = propertyList.get(marginProp).getNumeric(); 184 185 Numeric v = new FixedLength(0); 186 if (isInherited(propertyList)) { 187 v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric()); 189 } 190 v = NumericOp.addition(v, margin); 192 v = NumericOp.addition(v, padding); 193 v = NumericOp.addition(v, border); 194 return (Property) v; 195 } 196 } 197 198 private Property getCorresponding(int[] corresponding, PropertyList propertyList) 199 throws PropertyException { 200 PropertyList pList = getWMPropertyList(propertyList); 201 if (pList != null) { 202 int wmcorr = pList.getWritingMode(corresponding[0], corresponding[1], corresponding[2]); 203 return propertyList.get(wmcorr); 204 } else { 205 return null; 206 } 207 } 208 } 209 | Popular Tags |