public void performSkipAlignment(final int endIndex) { // Left align all elements after the layouted content .. if (leftAlignProcessor == null) { leftAlignProcessor = new LeftAlignmentProcessor(); } leftAlignProcessor.initializeForSkipAlignment(this, endIndex); leftAlignProcessor.performLastLineAlignment(); leftAlignProcessor.deinitialize(); }
public void performLastLineAlignment() { if (pagebreakCount == 0) { throw new IllegalStateException("Alignment processor has not been initialized correctly."); } Arrays.fill(elementDimensions, 0); Arrays.fill(elementPositions, 0); int lastPosition = iterate(sequenceElements, sequenceFill); if (lastPosition == 0) { // This could evolve into an infinite loop. Thats evil. // We have two choices to prevent that: // (1) Try to break the element. // if (getBreakableIndex() >= 0) // { // // Todo: Breaking is not yet implemented .. // } if (getSkipIndex() >= 0) { // This causes an overflow .. performSkipAlignment(getSkipIndex()); lastPosition = getSkipIndex(); } else { // Skip the complete line. Oh, thats not good, really! lastPosition = sequenceFill; } } // the elements up to the 'lastPosition' are now aligned according to the alignment rules. // now, update the element's positions and dimensions .. if (lastPosition == sequenceFill || lastLineAlignment) { // First, the simple case: The line's content did fully fit into the linebox. No linebreaks // were necessary. RenderBox firstBox = null; for (int i = 0; i < lastPosition; i++) { final RenderNode node = nodes[i]; final InlineSequenceElement element = sequenceElements[i]; if (element instanceof EndSequenceElement) { final long boxX2 = (elementPositions[i] + elementDimensions[i]); final RenderBox box = (RenderBox) node; box.setCachedWidth(boxX2 - box.getCachedX()); continue; } if (element instanceof StartSequenceElement) { final RenderBox box = (RenderBox) node; box.setCachedX(elementPositions[i]); if (firstBox == null) { firstBox = box; } continue; } // Content element: Perform a deep-deriveForAdvance, so that we preserve the // possibly existing sub-nodes. node.setCachedX(elementPositions[i]); node.setCachedWidth(elementDimensions[i]); } return; } // The second case is more complicated. The text did not fit fully into the text-element. // Left align all elements after the layouted content .. if (leftAlignProcessor == null) { leftAlignProcessor = new LeftAlignmentProcessor(); } leftAlignProcessor.initializeForLastLineAlignment(this); leftAlignProcessor.performLastLineAlignment(); leftAlignProcessor.deinitialize(); }