provide value of the white-space property to LineArrangement
Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/TestLineArrangement.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/TestLineArrangement.java
index d180a3d..35d4535 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/TestLineArrangement.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/TestLineArrangement.java
@@ -43,26 +43,26 @@
@Test
public void givenAllBoxesFitIntoOneLine_shouldArrangeBoxesInOneLine() throws Exception {
- lines.arrangeBoxes(graphics, joinableBoxes.listIterator(), 210, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, joinableBoxes.listIterator(), 210, TextAlign.LEFT, false);
assertEquals(1, lines.getLines().size());
}
@Test
public void givenJoinableBoxes_whenBoxesFitIntoSameLine_shouldJoinBoxes() throws Exception {
- lines.arrangeBoxes(graphics, joinableBoxes.listIterator(), 210, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, joinableBoxes.listIterator(), 210, TextAlign.LEFT, false);
assertEquals(1, joinableBoxes.size());
}
@Test
public void givenUnjoinableBoxes_whenBoxesFitIntoSameLane_shouldNotJoinBoxes() throws Exception {
- lines.arrangeBoxes(graphics, unjoinableBoxes.listIterator(), 210, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, unjoinableBoxes.listIterator(), 210, TextAlign.LEFT, false);
assertEquals(3, unjoinableBoxes.size());
}
@Test
public void givenUnjoinableBoxFollowedByJoinableBoxWithoutProperSplitPointAtLineEnd_whenAdditionalBoxWithoutProperSplitPointDoesNotFitIntoLine_shouldWrapCompleteJoinedBoxIntoNextLine() throws Exception {
final List<IInlineBox> boxes = boxes(square(10), staticText("L"), staticText("or"));
- lines.arrangeBoxes(graphics, boxes.listIterator(), 18, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, boxes.listIterator(), 18, TextAlign.LEFT, false);
assertEquals(2, boxes.size());
assertEquals("Lor", ((StaticText) boxes.get(1)).getText());
@@ -71,7 +71,7 @@
@Test
public void givenUnjoinableBoxFollowedByJoinableBoxWithoutProperSplitPointAtLineEnd_whenAdditionalBoxWithoutProperSplitPointDoesNotFitIntoLine_shouldRemoveOriginalLastBox() throws Exception {
final List<IInlineBox> boxes = boxes(square(10), staticText("L"), staticText("or"));
- lines.arrangeBoxes(graphics, boxes.listIterator(), 18, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, boxes.listIterator(), 18, TextAlign.LEFT, false);
for (final IInlineBox box : boxes) {
if (box.getWidth() == 0) {
@@ -86,7 +86,7 @@
layout(boxes);
final int widthOfHeadBoxes = boxes.get(0).getWidth() + boxes.get(1).getWidth();
- lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 1, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 1, TextAlign.LEFT, false);
assertEquals(1, lines.getLines().size());
assertEquals(boxes.get(2), lines.getLines().iterator().next().getLastChild());
@@ -98,7 +98,7 @@
layout(boxes);
final int widthOfHeadBoxes = boxes.get(0).getWidth() + boxes.get(1).getWidth();
- lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 1, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 1, TextAlign.LEFT, false);
assertEquals(1, lines.getLines().size());
assertEquals(boxes.get(2), lines.getLines().iterator().next().getLastChild());
@@ -110,7 +110,7 @@
layout(boxes);
final int widthOfHeadBoxes = boxes.get(0).getWidth() + boxes.get(1).getWidth();
- lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 10, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 10, TextAlign.LEFT, false);
assertEquals(2, lines.getLines().size());
assertEquals(" ", ((StaticText) lines.getLines().iterator().next().getLastChild()).getText());
@@ -123,7 +123,7 @@
layout(boxes);
final int widthOfHeadBoxes = boxes.get(0).getWidth() + boxes.get(1).getWidth();
- lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + x, TextAlign.LEFT);
+ lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + x, TextAlign.LEFT, false);
assertEquals("x = " + x, 2, lines.getLines().size());
assertEquals("x = " + x, " ", ((StaticText) lines.getLines().iterator().next().getLastChild()).getText());
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
index 4424362..f7d5806 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
@@ -132,6 +132,25 @@
return paragraph;
}
+ public static Paragraph paragraphPreservingWhitespace(final IInlineBox... children) {
+ final Paragraph paragraph = new Paragraph();
+ for (final IInlineBox child : children) {
+ paragraph.appendChild(child);
+ }
+ paragraph.setPreservingWhitespace(true);
+ return paragraph;
+ }
+
+ public static Paragraph paragraphPreservingWhitespace(final TextAlign textAlign, final IInlineBox... children) {
+ final Paragraph paragraph = new Paragraph();
+ for (final IInlineBox child : children) {
+ paragraph.appendChild(child);
+ }
+ paragraph.setTextAlign(textAlign);
+ paragraph.setPreservingWhitespace(true);
+ return paragraph;
+ }
+
public static InlineContainer inlineContainer(final IInlineBox... children) {
final InlineContainer inlineContainer = new InlineContainer();
for (final IInlineBox child : children) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/LineArrangement.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/LineArrangement.java
index 5a00296..6571e70 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/LineArrangement.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/LineArrangement.java
@@ -27,7 +27,7 @@
private boolean lastBoxWrappedCompletely;
private Line currentLine;
- public void arrangeBoxes(final Graphics graphics, final ListIterator<IInlineBox> boxIterator, final int width, final TextAlign textAlign) {
+ public void arrangeBoxes(final Graphics graphics, final ListIterator<IInlineBox> boxIterator, final int width, final TextAlign textAlign, final boolean preservingWhitespace) {
this.boxIterator = boxIterator;
this.width = width;
reset();
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Paragraph.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Paragraph.java
index 492658c..3dd8f8a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Paragraph.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Paragraph.java
@@ -29,6 +29,7 @@
private int width;
private TextAlign textAlign = TextAlign.LEFT;
+ private boolean preservingWhitespace = false;
private final LinkedList<IInlineBox> children = new LinkedList<IInlineBox>();
private final LineArrangement lines = new LineArrangement();
@@ -103,6 +104,14 @@
this.textAlign = textAlign;
}
+ public boolean isPreservingWhitespace() {
+ return preservingWhitespace;
+ }
+
+ public void setPreservingWhitespace(final boolean preservingWhitespace) {
+ this.preservingWhitespace = preservingWhitespace;
+ }
+
@Override
public void accept(final IBoxVisitor visitor) {
visitor.visit(this);
@@ -160,7 +169,7 @@
}
private void arrangeChildrenOnLines(final Graphics graphics) {
- lines.arrangeBoxes(graphics, children.listIterator(), width, textAlign);
+ lines.arrangeBoxes(graphics, children.listIterator(), width, textAlign, preservingWhitespace);
}
@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
index 0b19e6e..14d4e6f 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
@@ -57,6 +57,7 @@
paragraph.appendChild(child);
}
paragraph.setTextAlign(textAlign(styles));
+ paragraph.setPreservingWhitespace(CSS.PRE.equals(styles.getWhiteSpace()));
return paragraph;
}