1 51 package org.apache.fop.fo.flow; 52 53 import org.apache.fop.fo.*; 55 import org.apache.fop.datatypes.*; 56 import org.apache.fop.layout.*; 57 import org.apache.fop.layout.BlockArea; 58 import org.apache.fop.layout.LineArea; 59 import org.apache.fop.layout.FontState; 60 import org.apache.fop.apps.FOPException; 61 62 67 68 public class Leader extends FObjMixed { 69 70 public static class Maker extends FObj.Maker { 71 public FObj make(FObj parent, PropertyList propertyList, 72 String systemId, int line, int column) 73 throws FOPException { 74 return new Leader(parent, propertyList, systemId, line, column); 75 } 76 77 } 78 79 public static FObj.Maker maker() { 80 return new Leader.Maker(); 81 } 82 83 public Leader(FObj parent, PropertyList propertyList, 84 String systemId, int line, int column) 85 throws FOPException { 86 super(parent, propertyList, systemId, line, column); 87 } 88 89 public String getName() { 90 return "fo:leader"; 91 } 92 93 public int layout(Area area) throws FOPException { 94 BlockArea blockArea; 95 if (!(area instanceof BlockArea)) { 97 log.warn("in this version of Fop fo:leader must be a direct child of fo:block "); 98 return Status.OK; 99 } else { 100 blockArea = (BlockArea)area; 101 } 102 103 AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); 105 106 AuralProps mAurProps = propMgr.getAuralProps(); 108 109 BorderAndPadding bap = propMgr.getBorderAndPadding(); 111 BackgroundProps bProps = propMgr.getBackgroundProps(); 112 113 116 MarginInlineProps mProps = propMgr.getMarginInlineProps(); 118 119 RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); 121 122 144 ColorType c = this.properties.get("color").getColorType(); 146 float red = c.red(); 147 float green = c.green(); 148 float blue = c.blue(); 149 150 int leaderPattern = this.properties.get("leader-pattern").getEnum(); 153 Length length = this.properties.get("leader-length.minimum").getLength(); 155 int leaderLengthMinimum; 156 if (length instanceof PercentLength) { 157 leaderLengthMinimum = (int)(((PercentLength)length).value() 158 * area.getAllocationWidth()); 159 } else { 160 leaderLengthMinimum = length.mvalue(); 161 } 162 length = this.properties.get("leader-length.optimum").getLength(); 163 int leaderLengthOptimum; 164 if (length instanceof PercentLength) { 165 leaderLengthOptimum = (int)(((PercentLength)length).value() 166 * area.getAllocationWidth()); 167 } else { 168 leaderLengthOptimum = length.mvalue(); 169 } 170 length = this.properties.get("leader-length.maximum").getLength(); 171 int leaderLengthMaximum; 172 if (length instanceof PercentLength) { 173 leaderLengthMaximum = (int)(((PercentLength)length).value() 174 * area.getAllocationWidth()); 175 } else { 176 leaderLengthMaximum = length.mvalue(); 177 } 178 int ruleThickness = 180 this.properties.get("rule-thickness").getLength().mvalue(); 181 int ruleStyle = this.properties.get("rule-style").getEnum(); 182 int leaderPatternWidth = 184 this.properties.get("leader-pattern-width").getLength().mvalue(); 185 int leaderAlignment = 186 this.properties.get("leader-alignment").getEnum(); 187 188 String id = this.properties.get("id").getString(); 190 try { 191 blockArea.getIDReferences().initializeID(id, blockArea); 192 } 193 catch(FOPException e) { 194 if (!e.isLocationSet()) { 195 e.setLocation(systemId, line, column); 196 } 197 throw e; 198 } 199 200 int succeeded = addLeader(blockArea, 202 propMgr.getFontState(area.getFontInfo()), 203 red, green, blue, leaderPattern, 204 leaderLengthMinimum, leaderLengthOptimum, 205 leaderLengthMaximum, ruleThickness, 206 ruleStyle, leaderPatternWidth, 207 leaderAlignment); 208 if (succeeded == 1) { 209 return Status.OK; 210 } else { 211 return Status.AREA_FULL_SOME; 213 } 214 } 215 216 222 public int addLeader(BlockArea ba, FontState fontState, float red, 223 float green, float blue, int leaderPattern, 224 int leaderLengthMinimum, int leaderLengthOptimum, 225 int leaderLengthMaximum, int ruleThickness, 226 int ruleStyle, int leaderPatternWidth, 227 int leaderAlignment) { 228 229 LineArea la = ba.getCurrentLineArea(); 230 if (la == null) { 232 return -1; 233 } 234 235 la.changeFont(fontState); 236 la.changeColor(red, green, blue); 237 238 if (leaderLengthOptimum <= la.getRemainingWidth()) { 244 la.addLeader(leaderPattern, leaderLengthMinimum, 245 leaderLengthOptimum, leaderLengthMaximum, ruleStyle, 246 ruleThickness, leaderPatternWidth, leaderAlignment); 247 } else { 248 la = ba.createNextLineArea(); 249 if (la == null) { 250 return -1; 252 } 253 la.changeFont(fontState); 254 la.changeColor(red, green, blue); 255 256 if (leaderLengthMinimum <= la.getContentWidth()) { 259 la.addLeader(leaderPattern, leaderLengthMinimum, 260 leaderLengthOptimum, leaderLengthMaximum, 261 ruleStyle, ruleThickness, leaderPatternWidth, 262 leaderAlignment); 263 } else { 264 log.error("Leader doesn't fit into line, it will be clipped to fit."); 265 la.addLeader(leaderPattern, la.getRemainingWidth(), 266 la.getRemainingWidth(), la.getRemainingWidth(), 267 ruleStyle, ruleThickness, leaderPatternWidth, 268 leaderAlignment); 269 } 270 } 271 return 1; 272 } 273 274 } 275 | Popular Tags |