1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.Collections ; 23 import java.util.List ; 24 25 import org.apache.fop.fo.Constants; 26 import org.apache.fop.layoutmgr.inline.HyphContext; 27 import org.apache.fop.traits.MinOptMax; 28 import org.apache.fop.layoutmgr.inline.AlignmentContext; 29 30 31 35 public class LayoutContext { 36 39 public static final int LINEBREAK_AT_LF_ONLY = 0x01; 40 41 public static final int NEW_AREA = 0x02; 42 public static final int IPD_UNKNOWN = 0x04; 43 47 public static final int CHECK_REF_AREA = 0x08; 48 49 55 public static final int SUPPRESS_LEADING_SPACE = 0x10; 56 public static final int FIRST_AREA = 0x20; 57 public static final int TRY_HYPHENATE = 0x40; 58 public static final int LAST_AREA = 0x80; 59 60 public static final int RESOLVE_LEADING_SPACE = 0x100; 61 62 66 public static final int KEEP_WITH_NEXT_PENDING = 0x200; 67 71 public static final int KEEP_WITH_PREVIOUS_PENDING = 0x400; 72 73 74 public int flags; 82 MinOptMax stackLimit; 83 84 85 private int nextSpan = Constants.NOT_SET; 86 87 88 int refIPD; 89 90 91 private int writingMode = Constants.EN_LR_TB; 92 93 94 SpaceSpecifier trailingSpace; 95 96 97 SpaceSpecifier leadingSpace; 98 99 103 private List pendingAfterMarks; 104 105 109 private List pendingBeforeMarks; 110 111 112 private HyphContext hyphContext = null; 113 114 115 private int bpAlignment = Constants.EN_START; 116 117 118 private double ipdAdjust = 0.0; 119 120 121 private double dSpaceAdjust = 0.0; 122 123 private AlignmentContext alignmentContext = null; 124 125 126 private int spaceBefore = 0; 127 128 129 private int spaceAfter = 0; 130 131 132 private int lineStartBorderAndPaddingWidth = 0; 133 134 private int lineEndBorderAndPaddingWidth = 0; 135 136 140 public LayoutContext(LayoutContext parentLC) { 141 this.flags = parentLC.flags; 142 this.refIPD = parentLC.refIPD; 143 this.writingMode = parentLC.writingMode; 144 this.stackLimit = null; this.leadingSpace = parentLC.leadingSpace; this.trailingSpace = parentLC.trailingSpace; this.hyphContext = parentLC.hyphContext; 148 this.bpAlignment = parentLC.bpAlignment; 149 this.dSpaceAdjust = parentLC.dSpaceAdjust; 150 this.ipdAdjust = parentLC.ipdAdjust; 151 this.alignmentContext = parentLC.alignmentContext; 152 this.lineStartBorderAndPaddingWidth = parentLC.lineStartBorderAndPaddingWidth; 153 this.lineEndBorderAndPaddingWidth = parentLC.lineEndBorderAndPaddingWidth; 154 copyPendingMarksFrom(parentLC); 155 } 157 158 162 public LayoutContext(int flags) { 163 this.flags = flags; 164 this.refIPD = 0; 165 stackLimit = new MinOptMax(0); 166 leadingSpace = null; 167 trailingSpace = null; 168 } 169 170 public void copyPendingMarksFrom(LayoutContext source) { 171 if (source.pendingAfterMarks != null) { 172 this.pendingAfterMarks = new java.util.ArrayList (source.pendingAfterMarks); 173 } 174 if (source.pendingBeforeMarks != null) { 175 this.pendingBeforeMarks = new java.util.ArrayList (source.pendingBeforeMarks); 176 } 177 } 178 179 public void setFlags(int flags) { 180 setFlags(flags, true); 181 } 182 183 public void setFlags(int flags, boolean bSet) { 184 if (bSet) { 185 this.flags |= flags; 186 } else { 187 this.flags &= ~flags; 188 } 189 } 190 191 public void unsetFlags(int flags) { 192 setFlags(flags, false); 193 } 194 195 public boolean isStart() { 196 return ((this.flags & NEW_AREA) != 0); 197 } 198 199 public boolean startsNewArea() { 200 return ((this.flags & NEW_AREA) != 0 && leadingSpace != null); 201 } 202 203 public boolean isFirstArea() { 204 return ((this.flags & FIRST_AREA) != 0); 205 } 206 207 public boolean isLastArea() { 208 return ((this.flags & LAST_AREA) != 0); 209 } 210 211 public boolean suppressLeadingSpace() { 212 return ((this.flags & SUPPRESS_LEADING_SPACE) != 0); 213 } 214 215 public boolean isKeepWithNextPending() { 216 return ((this.flags & KEEP_WITH_NEXT_PENDING) != 0); 217 } 218 219 public boolean isKeepWithPreviousPending() { 220 return ((this.flags & KEEP_WITH_PREVIOUS_PENDING) != 0); 221 } 222 223 public void setLeadingSpace(SpaceSpecifier space) { 224 leadingSpace = space; 225 } 226 227 public SpaceSpecifier getLeadingSpace() { 228 return leadingSpace; 229 } 230 231 public boolean resolveLeadingSpace() { 232 return ((this.flags & RESOLVE_LEADING_SPACE) != 0); 233 } 234 235 public void setTrailingSpace(SpaceSpecifier space) { 236 trailingSpace = space; 237 } 238 239 public SpaceSpecifier getTrailingSpace() { 240 return trailingSpace; 241 } 242 243 249 public void addPendingAfterMark(UnresolvedListElementWithLength element) { 250 if (this.pendingAfterMarks == null) { 251 this.pendingAfterMarks = new java.util.ArrayList (); 252 } 253 this.pendingAfterMarks.add(element); 254 } 255 256 260 public List getPendingAfterMarks() { 261 if (this.pendingAfterMarks != null) { 262 return Collections.unmodifiableList(this.pendingAfterMarks); 263 } else { 264 return null; 265 } 266 } 267 268 274 public void addPendingBeforeMark(UnresolvedListElementWithLength element) { 275 if (this.pendingBeforeMarks == null) { 276 this.pendingBeforeMarks = new java.util.ArrayList (); 277 } 278 this.pendingBeforeMarks.add(element); 279 } 280 281 285 public List getPendingBeforeMarks() { 286 if (this.pendingBeforeMarks != null) { 287 return Collections.unmodifiableList(this.pendingBeforeMarks); 288 } else { 289 return null; 290 } 291 } 292 293 public void setStackLimit(MinOptMax limit) { 294 stackLimit = limit; 295 } 296 297 public MinOptMax getStackLimit() { 298 return stackLimit; 299 } 300 301 public void setRefIPD(int ipd) { 302 refIPD = ipd; 303 } 304 305 public int getRefIPD() { 306 return refIPD; 307 } 308 309 public void setHyphContext(HyphContext hyph) { 310 hyphContext = hyph; 311 } 312 313 public HyphContext getHyphContext() { 314 return hyphContext; 315 } 316 317 public boolean tryHyphenate() { 318 return ((this.flags & TRY_HYPHENATE) != 0); 319 } 320 321 325 public void setBPAlignment(int alignment) { 326 this.bpAlignment = alignment; 327 } 328 329 330 public int getBPAlignment() { 331 return this.bpAlignment; 332 } 333 334 public void setSpaceAdjust(double adjust) { 335 dSpaceAdjust = adjust; 336 } 337 338 public double getSpaceAdjust() { 339 return dSpaceAdjust; 340 } 341 342 public void setIPDAdjust(double ipdA) { 343 ipdAdjust = ipdA; 344 } 345 346 public double getIPDAdjust() { 347 return ipdAdjust; 348 } 349 350 public void setAlignmentContext(AlignmentContext alignmentContext) { 351 this.alignmentContext = alignmentContext; 352 } 353 354 public AlignmentContext getAlignmentContext() { 355 return this.alignmentContext; 356 } 357 358 public void resetAlignmentContext() { 359 if (this.alignmentContext != null) { 360 this.alignmentContext = this.alignmentContext.getParentAlignmentContext(); 361 } 362 } 363 364 368 public int getLineStartBorderAndPaddingWidth() { 369 return lineStartBorderAndPaddingWidth; 370 } 371 372 376 public void setLineStartBorderAndPaddingWidth(int lineStartBorderAndPaddingWidth) { 377 this.lineStartBorderAndPaddingWidth = lineStartBorderAndPaddingWidth; 378 } 379 380 384 public int getLineEndBorderAndPaddingWidth() { 385 return lineEndBorderAndPaddingWidth; 386 } 387 388 392 public void setLineEndBorderAndPaddingWidth(int lineEndBorderAndPaddingWidth) { 393 this.lineEndBorderAndPaddingWidth = lineEndBorderAndPaddingWidth; 394 } 395 396 400 public int getNextSpan() { 401 return nextSpan; 402 } 403 404 409 public void signalSpanChange(int span) { 410 if (span == Constants.NOT_SET || span == Constants.EN_NONE || span == Constants.EN_ALL) { 411 this.nextSpan = span; 412 } else { 413 throw new IllegalArgumentException ("Illegal value on signalSpanChange() for span: " 414 + span); 415 } 416 } 417 418 422 public int getWritingMode() { 423 return writingMode; 424 } 425 426 430 public void setWritingMode(int writingMode) { 431 this.writingMode = writingMode; 432 } 433 434 438 public int getSpaceBefore() { 439 return spaceBefore; 440 } 441 442 446 public void setSpaceBefore(int spaceBefore) { 447 this.spaceBefore = spaceBefore; 448 } 449 450 454 public int getSpaceAfter() { 455 return spaceAfter; 456 } 457 458 462 public void setSpaceAfter(int spaceAfter) { 463 this.spaceAfter = spaceAfter; 464 } 465 466 467 public String toString() { 468 return "Layout Context:" + 469 "\nStack Limit: \t" + (getStackLimit() == null ? "null" : getStackLimit().toString()) + 470 "\nTrailing Space: \t" + (getTrailingSpace() == null ? "null" : getTrailingSpace().toString()) + 471 "\nLeading Space: \t" + (getLeadingSpace() == null ? "null" : getLeadingSpace().toString()) + 472 "\nReference IPD: \t" + getRefIPD() + 473 "\nSpace Adjust: \t" + getSpaceAdjust() + 474 "\nIPD Adjust: \t" + getIPDAdjust() + 475 "\nResolve Leading Space: \t" + resolveLeadingSpace() + 476 "\nSuppress Leading Space: \t" + suppressLeadingSpace() + 477 "\nIs First Area: \t" + isFirstArea() + 478 "\nStarts New Area: \t" + startsNewArea() + 479 "\nIs Last Area: \t" + isLastArea() + 480 "\nTry Hyphenate: \t" + tryHyphenate() + 481 "\nKeeps: \t[" + (isKeepWithNextPending() ? "keep-with-next" : "") + "][" 482 + (isKeepWithPreviousPending() ? "keep-with-previous" : "") + "] pending"; 483 } 484 485 } 486 487 | Popular Tags |