1 51 package org.apache.fop.fo; 52 53 import java.lang.StringBuffer ; 54 import java.net.MalformedURLException ; 55 56 import org.apache.fop.apps.FOPException; 57 import org.apache.fop.fo.flow.AbstractFlow; 58 import org.apache.fop.fo.properties.BreakAfter; 59 import org.apache.fop.fo.properties.BreakBefore; 60 import org.apache.fop.fo.properties.Constants; 61 import org.apache.fop.fo.properties.TextDecoration; 62 import org.apache.fop.image.FopImageFactory; 63 import org.apache.fop.image.FopImageException; 64 import org.apache.fop.layout.AbsolutePositionProps; 65 import org.apache.fop.layout.AccessibilityProps; 66 import org.apache.fop.layout.Area; 67 import org.apache.fop.layout.AuralProps; 68 import org.apache.fop.layout.BackgroundProps; 69 import org.apache.fop.layout.BorderAndPadding; 70 import org.apache.fop.layout.ColumnArea; 71 import org.apache.fop.layout.FontInfo; 72 import org.apache.fop.layout.FontState; 73 import org.apache.fop.layout.HyphenationProps; 74 import org.apache.fop.layout.MarginInlineProps; 75 import org.apache.fop.layout.MarginProps; 76 import org.apache.fop.layout.RelativePositionProps; 77 import org.apache.fop.layout.TextState; 78 79 public class PropertyManager { 80 81 private PropertyList properties; 82 private FontState fontState = null; 83 private BorderAndPadding borderAndPadding = null; 84 private HyphenationProps hyphProps = null; 85 private BackgroundProps bgProps = null; 86 87 private String [] saLeft; 88 private String [] saRight; 89 private String [] saTop; 90 private String [] saBottom; 91 92 public PropertyManager(PropertyList pList) { 93 this.properties = pList; 94 } 95 96 private void initDirections() { 97 saLeft = new String [1]; 98 saRight = new String [1]; 99 saTop = new String [1]; 100 saBottom = new String [1]; 101 saTop[0] = properties.wmAbsToRel(PropertyList.TOP); 102 saBottom[0] = properties.wmAbsToRel(PropertyList.BOTTOM); 103 saLeft[0] = properties.wmAbsToRel(PropertyList.LEFT); 104 saRight[0] = properties.wmAbsToRel(PropertyList.RIGHT); 105 } 106 107 public FontState getFontState(FontInfo fontInfo) throws FOPException { 108 if (fontState == null) { 109 String fontFamily = properties.get("font-family").getString(); 110 String fontStyle = properties.get("font-style").getString(); 111 String fontWeight = properties.get("font-weight").getString(); 112 int fontSize = properties.get("font-size").getLength().mvalue(); 115 int fontVariant = properties.get("font-variant").getEnum(); 116 fontState = new FontState(fontInfo, fontFamily, fontStyle, 118 fontWeight, fontSize, fontVariant); 119 } 120 return fontState; 121 } 122 123 124 public BorderAndPadding getBorderAndPadding() { 125 if (borderAndPadding == null) { 126 this.borderAndPadding = new BorderAndPadding(); 127 initDirections(); 128 129 initBorderInfo(BorderAndPadding.TOP, saTop); 130 initBorderInfo(BorderAndPadding.BOTTOM, saBottom); 131 initBorderInfo(BorderAndPadding.LEFT, saLeft); 132 initBorderInfo(BorderAndPadding.RIGHT, saRight); 133 } 134 return borderAndPadding; 135 } 136 137 private void initBorderInfo(int whichSide, String [] saSide) { 138 borderAndPadding.setPadding(whichSide, 139 properties.get(formatPadding(saSide)).getCondLength()); 140 141 int style = properties.get(formatStyle(saSide)).getEnum(); 143 if (style != Constants.NONE) { 144 borderAndPadding.setBorder(whichSide, style, 145 properties.get(formatWidth(saSide)).getCondLength(), 146 properties.get(formatColor(saSide)).getColorType()); 147 } 148 } 149 150 private static final String padding = new String ("padding-"); 151 private static final String border = new String ("border-"); 152 private static final String width = new String ("-width"); 153 private static final String color = new String ("-color"); 154 private static final String style = new String ("-style"); 155 156 private String formatPadding(String [] saSide) { 157 StringBuffer sb = new StringBuffer (14); 158 return sb.append(padding).append(saSide[0]).toString(); 159 } 160 161 private String formatColor(String [] saSide) { 162 StringBuffer sb = new StringBuffer (19); 163 return sb.append(border).append(saSide[0]).append(color).toString(); 164 } 165 private String formatWidth(String [] saSide) { 166 StringBuffer sb = new StringBuffer (19); 167 return sb.append(border).append(saSide[0]).append(width).toString(); 168 } 169 170 private String formatStyle(String [] saSide) { 171 StringBuffer sb = new StringBuffer (19); 172 return sb.append(border).append(saSide[0]).append(style).toString(); 173 } 174 175 public HyphenationProps getHyphenationProps() { 176 if (hyphProps == null) { 177 this.hyphProps = new HyphenationProps(); 178 hyphProps.hyphenate = this.properties.get("hyphenate").getEnum(); 179 hyphProps.hyphenationChar = 180 this.properties.get("hyphenation-character").getCharacter(); 181 hyphProps.hyphenationPushCharacterCount = 182 this.properties.get("hyphenation-push-character-count").getNumber().intValue(); 183 hyphProps.hyphenationRemainCharacterCount = 184 this.properties.get("hyphenation-remain-character-count").getNumber().intValue(); 185 hyphProps.language = this.properties.get("language").getString(); 186 hyphProps.country = this.properties.get("country").getString(); 187 } 188 return hyphProps; 189 } 190 191 public int checkBreakBefore(Area area) { 192 if (!(area instanceof ColumnArea)) { 193 switch (properties.get("break-before").getEnum()) { 194 case BreakBefore.PAGE: 195 return Status.FORCE_PAGE_BREAK; 196 case BreakBefore.ODD_PAGE: 197 return Status.FORCE_PAGE_BREAK_ODD; 198 case BreakBefore.EVEN_PAGE: 199 return Status.FORCE_PAGE_BREAK_EVEN; 200 case BreakBefore.COLUMN: 201 return Status.FORCE_COLUMN_BREAK; 202 default: 203 return Status.OK; 204 } 205 } else { 206 ColumnArea colArea = (ColumnArea)area; 207 switch (properties.get("break-before").getEnum()) { 208 case BreakBefore.PAGE: 209 if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1)) 211 return Status.OK; 212 else 213 return Status.FORCE_PAGE_BREAK; 214 case BreakBefore.ODD_PAGE: 215 if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1) 218 && (colArea.getPage().getNumber() % 2 != 0)) 219 return Status.OK; 220 else 221 return Status.FORCE_PAGE_BREAK_ODD; 222 case BreakBefore.EVEN_PAGE: 223 if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1) 226 && (colArea.getPage().getNumber() % 2 == 0)) 227 return Status.OK; 228 else 229 return Status.FORCE_PAGE_BREAK_EVEN; 230 case BreakBefore.COLUMN: 231 if (!area.hasChildren()) 233 return Status.OK; 234 else 235 return Status.FORCE_COLUMN_BREAK; 236 default: 237 return Status.OK; 238 } 239 } 240 } 241 242 public int checkBreakAfter(Area area) { 243 switch (properties.get("break-after").getEnum()) { 244 case BreakAfter.PAGE: 245 return Status.FORCE_PAGE_BREAK; 246 case BreakAfter.ODD_PAGE: 247 return Status.FORCE_PAGE_BREAK_ODD; 248 case BreakAfter.EVEN_PAGE: 249 return Status.FORCE_PAGE_BREAK_EVEN; 250 case BreakAfter.COLUMN: 251 return Status.FORCE_COLUMN_BREAK; 252 default: 253 return Status.OK; 254 } 255 } 256 257 public MarginProps getMarginProps() { 258 MarginProps props = new MarginProps(); 259 260 props.marginTop = 262 this.properties.get("margin-top").getLength().mvalue(); 263 props.marginBottom = 264 this.properties.get("margin-bottom").getLength().mvalue(); 265 props.marginLeft = 266 this.properties.get("margin-left").getLength().mvalue(); 267 props.marginRight = 268 this.properties.get("margin-right").getLength().mvalue(); 269 276 return props; 277 } 278 279 public BackgroundProps getBackgroundProps() { 280 if (bgProps == null) { 281 this.bgProps = new BackgroundProps(); 282 bgProps.backColor = 284 this.properties.get("background-color").getColorType(); 285 286 String src = this.properties.get("background-image").getString(); 287 if (src.equalsIgnoreCase("none")) { 288 bgProps.backImage = null; 289 } else if (src.equalsIgnoreCase("inherit")) { 290 bgProps.backImage = null; 292 } else { 293 try { 294 bgProps.backImage = FopImageFactory.Make(src); 295 } catch (MalformedURLException urlex) { 296 bgProps.backImage = null; 297 System.out.println("Error creating background image: " 299 + urlex.getMessage()); 300 } catch (FopImageException imgex) { 301 bgProps.backImage = null; 302 System.out.println("Error creating background image: " 304 + imgex.getMessage()); 305 } 306 } 307 308 bgProps.backRepeat = this.properties.get("background-repeat").getEnum(); 309 310 311 } 314 return bgProps; 315 } 316 317 public MarginInlineProps getMarginInlineProps() { 318 MarginInlineProps props = new MarginInlineProps(); 319 return props; 320 } 321 322 public AccessibilityProps getAccessibilityProps() { 323 AccessibilityProps props = new AccessibilityProps(); 324 String str; 325 str = this.properties.get("source-document").getString(); 326 if(!"none".equals(str)) { 327 props.sourceDoc = str; 328 } 329 str = this.properties.get("role").getString(); 330 if(!"none".equals(str)) { 331 props.role = str; 332 } 333 return props; 334 } 335 336 public AuralProps getAuralProps() { 337 AuralProps props = new AuralProps(); 338 return props; 339 } 340 341 public RelativePositionProps getRelativePositionProps() { 342 RelativePositionProps props = new RelativePositionProps(); 343 return props; 344 } 345 346 public AbsolutePositionProps getAbsolutePositionProps() { 347 AbsolutePositionProps props = new AbsolutePositionProps(); 348 return props; 349 } 350 351 public TextState getTextDecoration(FObj parent) throws FOPException { 352 353 TextState tsp = null; 355 boolean found = false; 356 357 do { 358 if (parent instanceof AbstractFlow) { 359 found = true; 360 } else if (parent instanceof FObjMixed) { 361 FObjMixed fom = (FObjMixed) parent; 362 tsp = fom.getTextState(); 363 found = true; 364 } 365 parent = parent.getParent(); 366 } while (!found); 367 368 TextState ts = new TextState(); 369 370 if (tsp != null) { 371 ts.setUnderlined(tsp.getUnderlined()); 372 ts.setOverlined(tsp.getOverlined()); 373 ts.setLineThrough(tsp.getLineThrough()); 374 } 375 376 int textDecoration = this.properties.get("text-decoration").getEnum(); 377 378 if (textDecoration == TextDecoration.UNDERLINE) { 379 ts.setUnderlined(true); 380 } 381 if (textDecoration == TextDecoration.OVERLINE) { 382 ts.setOverlined(true); 383 } 384 if (textDecoration == TextDecoration.LINE_THROUGH) { 385 ts.setLineThrough(true); 386 } 387 if (textDecoration == TextDecoration.NO_UNDERLINE) { 388 ts.setUnderlined(false); 389 } 390 if (textDecoration == TextDecoration.NO_OVERLINE) { 391 ts.setOverlined(false); 392 } 393 if (textDecoration == TextDecoration.NO_LINE_THROUGH) { 394 ts.setLineThrough(false); 395 } 396 397 return ts; 398 } 399 400 } 401 | Popular Tags |