1 51 package org.apache.fop.fo.flow; 52 53 import org.apache.fop.fo.*; 55 import org.apache.fop.fo.properties.*; 56 import org.apache.fop.layout.*; 57 import org.apache.fop.layout.inline.*; 58 import org.apache.fop.layout.BlockArea; 59 import org.apache.fop.apps.FOPException; 60 61 public class InstreamForeignObject extends FObj { 62 63 66 public static class Maker extends FObj.Maker { 67 68 76 public FObj make(FObj parent, PropertyList propertyList, 77 String systemId, int line, int column) 78 throws FOPException { 79 return new InstreamForeignObject(parent, propertyList, 80 systemId, line, column); 81 } 82 83 } 84 85 90 public static FObj.Maker maker() { 91 return new InstreamForeignObject.Maker(); 92 } 93 94 int breakBefore; 95 int breakAfter; 96 int scaling; 97 int width; 98 int height; 99 int contwidth; 100 int contheight; 101 boolean wauto; 102 boolean hauto; 103 boolean cwauto; 104 boolean chauto; 105 int spaceBefore; 106 int spaceAfter; 107 int startIndent; 108 int endIndent; 109 110 ForeignObjectArea areaCurrent; 111 112 118 public InstreamForeignObject(FObj parent, PropertyList propertyList, 119 String systemId, int line, int column) { 120 super(parent, propertyList, systemId, line, column); 121 } 122 123 public String getName() { 124 return "fo:instream-foreign-object"; 125 } 126 127 134 public int layout(Area area) throws FOPException { 135 136 if (this.marker == BREAK_AFTER) { 137 return Status.OK; 138 } 139 140 if (this.marker == START) { 141 142 AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); 144 145 AuralProps mAurProps = propMgr.getAuralProps(); 147 148 BorderAndPadding bap = propMgr.getBorderAndPadding(); 150 BackgroundProps bProps = propMgr.getBackgroundProps(); 151 152 MarginInlineProps mProps = propMgr.getMarginInlineProps(); 154 155 RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); 157 158 180 181 String id = this.properties.get("id").getString(); 182 int align = this.properties.get("text-align").getEnum(); 183 int valign = this.properties.get("vertical-align").getEnum(); 184 int overflow = this.properties.get("overflow").getEnum(); 185 186 this.breakBefore = this.properties.get("break-before").getEnum(); 187 this.breakAfter = this.properties.get("break-after").getEnum(); 188 this.width = this.properties.get("width").getLength().mvalue(); 189 this.height = this.properties.get("height").getLength().mvalue(); 190 this.contwidth = 191 this.properties.get("content-width").getLength().mvalue(); 192 this.contheight = 193 this.properties.get("content-height").getLength().mvalue(); 194 this.wauto = this.properties.get("width").getLength().isAuto(); 195 this.hauto = this.properties.get("height").getLength().isAuto(); 196 this.cwauto = 197 this.properties.get("content-width").getLength().isAuto(); 198 this.chauto = 199 this.properties.get("content-height").getLength().isAuto(); 200 201 this.startIndent = 202 this.properties.get("start-indent").getLength().mvalue(); 203 this.endIndent = 204 this.properties.get("end-indent").getLength().mvalue(); 205 this.spaceBefore = 206 this.properties.get("space-before.optimum").getLength().mvalue(); 207 this.spaceAfter = 208 this.properties.get("space-after.optimum").getLength().mvalue(); 209 210 this.scaling = this.properties.get("scaling").getEnum(); 211 212 try { 213 area.getIDReferences().createID(id); 214 } 215 catch(FOPException e) { 216 if (!e.isLocationSet()) { 217 e.setLocation(systemId, line, column); 218 } 219 throw e; 220 } 221 if (this.areaCurrent == null) { 222 this.areaCurrent = 223 new ForeignObjectArea(propMgr.getFontState(area.getFontInfo()), 224 area.getAllocationWidth()); 225 226 this.areaCurrent.start(); 227 areaCurrent.setWidth(this.width); 228 areaCurrent.setHeight(this.height); 229 areaCurrent.setContentWidth(this.contwidth); 230 areaCurrent.setContentHeight(this.contheight); 231 areaCurrent.setScaling(this.scaling); 232 areaCurrent.setAlign(align); 233 areaCurrent.setVerticalAlign(valign); 234 areaCurrent.setOverflow(overflow); 235 areaCurrent.setSizeAuto(wauto, hauto); 236 areaCurrent.setContentSizeAuto(cwauto, chauto); 237 238 areaCurrent.setPage(area.getPage()); 240 241 int numChildren = this.children.size(); 242 if (numChildren > 1) { 243 throw new FOPException("Only one child element is allowed in an instream-foreign-object", systemId, line, column); 244 } 245 246 if (this.children.size() > 0) { 247 FONode fo = (FONode)children.get(0); 248 int status; 249 if (Status.isIncomplete((status = 251 fo.layout(this.areaCurrent)))) { 252 return status; 253 } 254 255 256 this.areaCurrent.end(); 257 } 258 } 259 260 this.marker = 0; 261 262 if (breakBefore == BreakBefore.PAGE 263 || ((spaceBefore + areaCurrent.getEffectiveHeight()) 264 > area.spaceLeft())) { 265 return Status.FORCE_PAGE_BREAK; 266 } 267 268 if (breakBefore == BreakBefore.ODD_PAGE) { 269 return Status.FORCE_PAGE_BREAK_ODD; 270 } 271 272 if (breakBefore == BreakBefore.EVEN_PAGE) { 273 return Status.FORCE_PAGE_BREAK_EVEN; 274 } 275 } 276 277 if (this.areaCurrent == null) { 278 return Status.OK; 279 } 280 281 if (area instanceof BlockArea) { 282 BlockArea ba = (BlockArea)area; 283 LineArea la = ba.getCurrentLineArea(); 284 if (la == null) { 285 return Status.AREA_FULL_NONE; 286 } 287 la.addPending(); 288 if (areaCurrent.getEffectiveWidth() > la.getRemainingWidth()) { 289 la = ba.createNextLineArea(); 290 if (la == null) { 291 return Status.AREA_FULL_NONE; 292 } 293 } 294 la.addInlineArea(areaCurrent, this.getLinkSet()); 295 } else { 296 area.addChild(areaCurrent); 297 area.increaseHeight(areaCurrent.getEffectiveHeight()); 298 } 299 300 if (this.isInTableCell) { 301 startIndent += forcedStartOffset; 302 306 } 307 308 areaCurrent.setStartIndent(startIndent); 309 311 312 if (spaceBefore != 0) { 313 314 } 316 317 318 320 areaCurrent.setPage(area.getPage()); 321 322 323 325 326 if (spaceAfter != 0) { 327 328 } 330 331 332 if (breakAfter == BreakAfter.PAGE) { 333 this.marker = BREAK_AFTER; 334 return Status.FORCE_PAGE_BREAK; 335 } 336 337 if (breakAfter == BreakAfter.ODD_PAGE) { 338 this.marker = BREAK_AFTER; 339 return Status.FORCE_PAGE_BREAK_ODD; 340 } 341 342 if (breakAfter == BreakAfter.EVEN_PAGE) { 343 this.marker = BREAK_AFTER; 344 return Status.FORCE_PAGE_BREAK_EVEN; 345 } 346 347 areaCurrent = null; 348 349 return Status.OK; 350 } 351 352 } 353 354 | Popular Tags |