return oldList;
}
+ /**
+ * remove the AreaInfo object represented by the given elements,
+ * so that it won't generate any element when getChangedKnuthElements
+ * will be called
+ *
+ * @param oldList the elements representing the word space
+ */
+ public void removeWordSpace(List oldList) {
+ ListIterator oldListIterator = oldList.listIterator();
+ KnuthElement element = null;
+ // "unwrap" the Position stored in each element of oldList
+ while (oldListIterator.hasNext()) {
+ element = (KnuthElement) oldListIterator.next();
+ element.setPosition(((NonLeafPosition)element.getPosition()).getPosition());
+ }
+
+ ((InlineLevelLayoutManager)
+ element.getLayoutManager()).removeWordSpace(oldList);
+
+ }
+
public void getWordChars(StringBuffer sbChars, Position pos) {
Position newPos = ((NonLeafPosition) pos).getPosition();
((InlineLevelLayoutManager)
* representing each space has a different "pattern"
*/
private void removeElementsForTrailingSpaces() {
- KnuthElement removedElement;
+ LinkedList removedElements;
+ InlineLevelLayoutManager inlineLM;
int effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
while (this.size() > ignoreAtStart
&& ((KnuthElement) this.get(this.size() - 1)).isGlue()) {
+ removedElements = new LinkedList();
+ inlineLM = (InlineLevelLayoutManager)
+ ((KnuthElement) this.get(this.size() - 1)).getLayoutManager();
if (effectiveAlignment == EN_CENTER) {
// centered text: the pattern is
// <glue> <penaly> <glue> <box> <penaly> <glue>
- removedElement = (KnuthGlue) this.remove(this.size() - 1);
- removedElement = (KnuthPenalty) this.remove(this.size() - 1);
- removedElement = (KnuthBox) this.remove(this.size() - 1);
- removedElement = (KnuthGlue) this.remove(this.size() - 1);
- removedElement = (KnuthPenalty) this.remove(this.size() - 1);
- removedElement = (KnuthGlue) this.remove(this.size() - 1);
+ removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthBox) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
} else if (effectiveAlignment == EN_START || effectiveAlignment == EN_END) {
// left- or right-aligned text: the pattern is
// <glue> <penalty> <glue>
- removedElement = (KnuthGlue) this.remove(this.size() - 1);
- removedElement = (KnuthPenalty) this.remove(this.size() - 1);
- removedElement = (KnuthGlue) this.remove(this.size() - 1);
+ removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
+ removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
} else {
// justified text: the pattern is
// <glue>
- removedElement = (KnuthGlue) this.remove(this.size() - 1);
+ removedElements.add((KnuthGlue) this.remove(this.size() - 1));
}
// if the space was a non-breaking one, there is also a penalty
if (this.size() > ignoreAtStart
&& ((KnuthElement) this.get(this.size() - 1)).isPenalty()) {
- removedElement = (KnuthPenalty) this.remove(this.size() - 1);
+ removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
}
+ inlineLM.removeWordSpace(removedElements);
}
}
(textAlign == Constants.EN_END) ? difference : 0;
indent += (bestActiveNode.line == 1 && bFirst) ?
textIndent : 0;
- double ratio = (textAlign == Constants.EN_JUSTIFY) ? bestActiveNode.adjustRatio : 0;
+ double ratio = (textAlign == Constants.EN_JUSTIFY
+ || difference < 0 && -difference <= bestActiveNode.availableShrink) ?
+ bestActiveNode.adjustRatio : 0;
// add nodes at the beginning of the list, as they are found
// backwards, from the last one to the first one
public boolean getGeneratesLineArea() {
return true;
}
-
}
return oldList;
}
+ /**
+ * remove the AreaInfo object represented by the given elements,
+ * so that it won't generate any element when getChangedKnuthElements
+ * will be called
+ *
+ * @param oldList the elements representing the word space
+ */
+ public void removeWordSpace(List oldList) {
+ // find the element storing the Position whose value
+ // points to the AreaInfo object
+ ListIterator oldListIterator = oldList.listIterator();
+ if (((KnuthElement) ((LinkedList) oldList).getFirst()).isPenalty()) {
+ // non breaking space: oldList starts with a penalty
+ oldListIterator.next();
+ }
+ if (oldList.size() > 2) {
+ // alignment is either center, start or end:
+ // the first two elements does not store the needed Position
+ oldListIterator.next();
+ oldListIterator.next();
+ }
+ int leafValue = ((LeafPosition) ((KnuthElement) oldListIterator.next()).getPosition()).getLeafPos();
+ // only the last word space can be a trailing space!
+ if (leafValue == vecAreaInfo.size() - 1) {
+ vecAreaInfo.remove(leafValue);
+ } else {
+ log.error("trying to remove a non-trailing word space");
+ }
+ }
+
public void hyphenate(Position pos, HyphContext hc) {
AreaInfo ai
= (AreaInfo) vecAreaInfo.get(((LeafPosition) pos).getLeafPos());