aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Furini <lfurini@apache.org>2005-09-20 11:40:16 +0000
committerLuca Furini <lfurini@apache.org>2005-09-20 11:40:16 +0000
commit6c2d3ac19bf0514660efd0c6efc071fddd4b453a (patch)
treee959067f85f3a7f8802d48b24927b3ca3983e8d0
parent9258cc7397adc444f5b76b23427e256b5a45e932 (diff)
downloadxmlgraphics-fop-6c2d3ac19bf0514660efd0c6efc071fddd4b453a.tar.gz
xmlgraphics-fop-6c2d3ac19bf0514660efd0c6efc071fddd4b453a.zip
Remove the AreaInfo objects representing trailing spaces, in order to prevent them reappearing again when getChangedKnuthElements() is called.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@290422 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java10
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java10
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java8
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java21
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java10
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java34
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java30
7 files changed, 109 insertions, 14 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
index a24e1babe..09a346664 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
@@ -285,6 +285,16 @@ public class ContentLayoutManager extends AbstractBaseLayoutManager
return oldList;
}
+ /**
+ * Remove the word space represented by the given elements
+ *
+ * @param oldList the elements representing the word space
+ */
+ public void removeWordSpace(List oldList) {
+ // do nothing
+ log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)");
+ }
+
public void getWordChars(StringBuffer sbChars, Position pos) {
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
index 44d8fc8ed..9a32ce9a3 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
@@ -122,6 +122,16 @@ public class FootnoteLayoutManager extends AbstractLayoutManager
return oldList;
}
+ /**
+ * Remove the word space represented by the given elements
+ *
+ * @param oldList the elements representing the word space
+ */
+ public void removeWordSpace(List oldList) {
+ // do nothing
+ log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)");
+ }
+
public void getWordChars(StringBuffer sbChars, Position pos) {
log.warn("null implementation of getWordChars() called!");
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java
index 71c6adcaf..d7c1f8424 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java
@@ -39,6 +39,14 @@ public interface InlineLevelLayoutManager extends LayoutManager {
List addALetterSpaceTo(List oldList);
/**
+ * Tell the LM to modify its data, removing the word space
+ * represented by the given elements
+ *
+ * @param oldList the elements representing the word space
+ */
+ void removeWordSpace(List oldList);
+
+ /**
* Get the word chars corresponding to the given position
*
* @param sbChars the StringBuffer used to append word chars
diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
index eb8eab717..f5fc7315f 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
@@ -247,6 +247,27 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager
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)
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java
index 56a8e9f10..e4e037197 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java
@@ -302,6 +302,16 @@ public abstract class LeafNodeLayoutManager extends AbstractLayoutManager
return oldList;
}
+ /**
+ * Remove the word space represented by the given elements
+ *
+ * @param oldList the elements representing the word space
+ */
+ public void removeWordSpace(List oldList) {
+ // do nothing
+ log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)");
+ }
+
public void getWordChars(StringBuffer sbChars, Position pos) {
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
index 86f13b2cd..7056f4dbb 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
@@ -285,35 +285,40 @@ public class LineLayoutManager extends InlineStackingLayoutManager
* 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);
}
}
@@ -405,7 +410,9 @@ public class LineLayoutManager extends InlineStackingLayoutManager
(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
@@ -1807,6 +1814,5 @@ public class LineLayoutManager extends InlineStackingLayoutManager
public boolean getGeneratesLineArea() {
return true;
}
-
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
index 01cc8bba1..3f4de96a1 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
@@ -557,6 +557,36 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
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());