1 17 18 19 20 package org.apache.fop.layoutmgr.table; 21 22 import org.apache.fop.fo.Constants; 23 import org.apache.fop.fo.flow.Table; 24 import org.apache.fop.fo.flow.TableBody; 25 import org.apache.fop.fo.flow.TableCell; 26 import org.apache.fop.fo.flow.TableColumn; 27 import org.apache.fop.fo.flow.TableRow; 28 import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo; 29 30 35 public class CollapsingBorderModelEyeCatching extends CollapsingBorderModel { 36 37 public BorderInfo determineWinner(GridUnit currentGridUnit, 38 GridUnit otherGridUnit, int side, int flags) { 39 final boolean vertical = isVerticalRelation(side); 40 final int otherSide = getOtherSide(side); 41 42 TableCell currentCell = currentGridUnit.getCell(); 44 TableCell otherCell = null; 45 if (otherGridUnit != null) { 46 otherCell = otherGridUnit.getCell(); 47 } 48 49 TableRow currentRow = currentGridUnit.getRow(); 51 TableRow otherRow = null; 52 if (vertical && otherCell != null) { 53 otherRow = otherGridUnit.getRow(); 54 } 55 56 TableBody currentBody = currentGridUnit.getBody(); 58 TableBody otherBody = null; 59 if (otherRow != null) { 60 otherBody = otherGridUnit.getBody(); 61 } 62 63 TableColumn currentColumn = currentGridUnit.getColumn(); 65 TableColumn otherColumn = null; 66 if (otherGridUnit != null) { 67 otherColumn = otherGridUnit.getColumn(); 68 } 69 70 72 Table table = currentGridUnit.getTable(); 74 75 81 BorderInfo[] current = new BorderInfo[6]; 82 BorderInfo[] other = new BorderInfo[6]; 83 current[0] = currentGridUnit.getOriginalBorderInfoForCell(side); 85 if (otherGridUnit != null) { 86 other[0] = otherGridUnit.getOriginalBorderInfoForCell(otherSide); 87 } 88 if ((currentRow != null) 89 && (side == BEFORE 90 || side == AFTER 91 || (currentGridUnit.getFlag(GridUnit.IN_FIRST_COLUMN) && side == START) 92 || (currentGridUnit.getFlag(GridUnit.IN_LAST_COLUMN) && side == END))) { 93 current[1] = currentRow.getCommonBorderPaddingBackground().getBorderInfo(side); 95 } 96 if (otherRow != null) { 97 other[1] = otherRow.getCommonBorderPaddingBackground().getBorderInfo(otherSide); 99 } 100 if (currentBody != null 101 && ((side == BEFORE && currentGridUnit.getFlag(GridUnit.FIRST_IN_PART)) 102 || (side == AFTER && currentGridUnit.getFlag(GridUnit.LAST_IN_PART)) 103 || (currentGridUnit.getFlag(GridUnit.IN_FIRST_COLUMN) && side == START) 104 || (currentGridUnit.getFlag(GridUnit.IN_LAST_COLUMN) && side == END))) { 105 current[2] = currentBody.getCommonBorderPaddingBackground().getBorderInfo(side); 107 } 108 if (otherGridUnit != null 109 && otherBody != null 110 && ((otherSide == BEFORE && otherGridUnit.getFlag(GridUnit.FIRST_IN_PART)) 111 || (otherSide == AFTER && otherGridUnit.getFlag(GridUnit.LAST_IN_PART)))) { 112 other[2] = otherBody.getCommonBorderPaddingBackground().getBorderInfo(otherSide); 114 } 115 if ((side == BEFORE && otherGridUnit == null) 116 || (side == AFTER && otherGridUnit == null) 117 || (side == START) 118 || (side == END)) { 119 current[3] = currentColumn.getCommonBorderPaddingBackground().getBorderInfo(side); 121 } 122 if (otherColumn != null) { 123 other[3] = otherColumn.getCommonBorderPaddingBackground().getBorderInfo(otherSide); 125 } 126 if (otherGridUnit == null 128 && ((side == BEFORE && (flags & VERTICAL_START_END_OF_TABLE) > 0) 129 || (side == AFTER && (flags & VERTICAL_START_END_OF_TABLE) > 0) 130 || (side == START) 131 || (side == END))) { 132 current[5] = table.getCommonBorderPaddingBackground().getBorderInfo(side); 134 } 135 137 BorderInfo resolved = null; 138 139 resolved = doRule1(current, other); 141 if (resolved != null) { 142 return resolved; 143 } 144 145 if (!doRule2(current, other)) { 147 } 148 149 resolved = doRule3(current, other); 151 if (resolved != null) { 152 return resolved; 153 } 154 155 resolved = doRule4(current, other); 157 if (resolved != null) { 158 return resolved; 159 } 160 161 resolved = doRule5(current, other); 163 if (resolved != null) { 164 return resolved; 165 } 166 167 return null; } 169 170 private BorderInfo doRule1(BorderInfo[] current, BorderInfo[] other) { 171 for (int i = 0; i < current.length; i++) { 172 if ((current[i] != null) && (current[i].getStyle() == Constants.EN_HIDDEN)) { 173 return current[i]; 174 } 175 if ((other[i] != null) && (other[i].getStyle() == Constants.EN_HIDDEN)) { 176 return other[i]; 177 } 178 } 179 return null; 180 } 181 182 private boolean doRule2(BorderInfo[] current, BorderInfo[] other) { 183 boolean found = false; 184 for (int i = 0; i < current.length; i++) { 185 if ((current[i] != null) && (current[i].getStyle() != Constants.EN_NONE)) { 186 found = true; 187 break; 188 } 189 if ((other[i] != null) && (other[i].getStyle() != Constants.EN_NONE)) { 190 found = true; 191 break; 192 } 193 } 194 return found; 195 } 196 197 private BorderInfo doRule3(BorderInfo[] current, BorderInfo[] other) { 198 int width = 0; 199 for (int i = 0; i < current.length; i++) { 201 if ((current[i] != null) && (current[i].getRetainedWidth() > width)) { 202 width = current[i].getRetainedWidth(); 203 } 204 if ((other[i] != null) && (other[i].getRetainedWidth() > width)) { 205 width = other[i].getRetainedWidth(); 206 } 207 } 208 BorderInfo widest = null; 209 int count = 0; 210 for (int i = 0; i < current.length; i++) { 212 if ((current[i] != null) && (current[i].getRetainedWidth() == width)) { 213 count++; 214 if (widest == null) { 215 widest = current[i]; 216 } 217 } else { 218 current[i] = null; } 220 if ((other[i] != null) && (other[i].getRetainedWidth() == width)) { 221 count++; 222 if (widest == null) { 223 widest = other[i]; 224 } 225 } else { 226 other[i] = null; } 228 } 229 if (count == 1) { 230 return widest; 231 } else { 232 return null; 233 } 234 } 235 236 private BorderInfo doRule4(BorderInfo[] current, BorderInfo[] other) { 237 int pref = getPreferenceValue(Constants.EN_INSET); for (int i = 0; i < current.length; i++) { 240 if (current[i] != null) { 241 int currPref = getPreferenceValue(current[i].getStyle()); 242 if (currPref > pref) { 243 pref = currPref; 244 } 245 } 246 if (other[i] != null) { 247 int currPref = getPreferenceValue(other[i].getStyle()); 248 if (currPref > pref) { 249 pref = currPref; 250 } 251 } 252 } 253 BorderInfo preferred = null; 254 int count = 0; 255 for (int i = 0; i < current.length; i++) { 257 if (current[i] != null) { 258 int currPref = getPreferenceValue(current[i].getStyle()); 259 if (currPref == pref) { 260 count++; 261 if (preferred == null) { 262 preferred = current[i]; 263 } 264 break; 265 } 266 } else { 267 current[i] = null; } 269 if (other[i] != null) { 270 int currPref = getPreferenceValue(other[i].getStyle()); 271 if (currPref == pref) { 272 count++; 273 if (preferred == null) { 274 preferred = other[i]; 275 } 276 break; 277 } 278 } else { 279 other[i] = null; } 281 } 282 if (count == 1) { 283 return preferred; 284 } else { 285 return null; 286 } 287 } 288 289 private BorderInfo doRule5(BorderInfo[] current, BorderInfo[] other) { 290 for (int i = 0; i < current.length; i++) { 291 if (current[i] != null) { 292 return current[i]; 293 } 294 if (other[i] != null) { 295 return other[i]; 296 } 297 } 298 return null; 299 } 300 301 } 302 | Popular Tags |