diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java
index e78b3132d..ce68a95e9 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java
@@ -337,8 +337,7 @@ private static void startNewInlineLine(LayoutContext c, BlockBox box, int breakA
List pendingInlineLayers, int lineOffset, InlineBox inlineBox, LineBreakContext lbContext) {
IdentValue align = inlineBox.getStyle().getIdent(CSSName.TEXT_ALIGN);
- if (align == IdentValue.JUSTIFY ||
- (align != IdentValue.LEFT && inlineBox.getStyle().getWordWrap() == IdentValue.BREAK_WORD)) {
+ if (align != IdentValue.LEFT) {
current.line.trimTrailingSpace(c);
}
diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-440-trailing-ws-align-right.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-440-trailing-ws-align-right.pdf
new file mode 100644
index 000000000..64e55254f
Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-440-trailing-ws-align-right.pdf differ
diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/arabic-bidi.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/arabic-bidi.pdf
index 4d1f00f8e..58c3946f1 100644
Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/arabic-bidi.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/arabic-bidi.pdf differ
diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/letter-spacing-bidi.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/letter-spacing-bidi.pdf
index 6b1ad944e..14449a6b8 100644
Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/letter-spacing-bidi.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/letter-spacing-bidi.pdf differ
diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-440-trailing-ws-align-right.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-440-trailing-ws-align-right.html
new file mode 100644
index 000000000..5a4369965
--- /dev/null
+++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-440-trailing-ws-align-right.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+ This is some text to show that text aligned right has the trailing spaces removed,
+ just like justified text. All the characters at the right should line up em
+
+
diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java
index 47d197b0d..291b16a23 100644
--- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java
+++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java
@@ -1017,6 +1017,15 @@ public void testIssue446LangSelector() throws IOException {
assertTrue(vt.runTest("issue-446-lang-selector"));
}
+ /**
+ * Tests that aligned right text doesn't have trailing spaces
+ * that cause ragged text on the right.
+ */
+ @Test
+ public void testIssue440TrailingWsAlignRight() throws IOException {
+ assertTrue(vt.runTest("issue-440-trailing-ws-align-right"));
+ }
+
/**
* Don't launch a ClassCastException if a td in a table is floated.
*