Skip to content

Commit 65e93d8

Browse files
committed
Do not reset the alignment for RTL elements if it's present.
DEVSIX-2806
1 parent 55c4011 commit 65e93d8

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/main/java/com/itextpdf/html2pdf/css/apply/util/FontStyleApplierUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
137137
}
138138

139139
if (stylesContainer instanceof IElementNode && ((IElementNode) stylesContainer).parentNode() instanceof IElementNode &&
140-
CssConstants.RTL.equals(((IElementNode) ((IElementNode) stylesContainer).parentNode()).getStyles().get(CssConstants.DIRECTION))) {
140+
CssConstants.RTL.equals(((IElementNode) ((IElementNode) stylesContainer).parentNode()).getStyles().get(CssConstants.DIRECTION)) &&
141+
!element.hasProperty(Property.HORIZONTAL_ALIGNMENT)) {
141142
// We should only apply horizontal alignment if parent has dir attribute or direction property
142143
element.setProperty(Property.HORIZONTAL_ALIGNMENT, HorizontalAlignment.RIGHT);
143144
}

src/test/java/com/itextpdf/html2pdf/element/ParagraphTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,10 @@ public void paragraphWithImageTest01() throws IOException, InterruptedException
190190
HtmlConverter.convertToPdf(new File(sourceFolder + "paragraphWithImageTest01.html"), new File(destinationFolder + "paragraphWithImageTest01.pdf"));
191191
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "paragraphWithImageTest01.pdf", sourceFolder + "cmp_paragraphWithImageTest01.pdf", destinationFolder, "diff_paragraphWithImageTest01_"));
192192
}
193+
194+
@Test
195+
public void paragraphWithImageTest01RTL() throws IOException, InterruptedException {
196+
HtmlConverter.convertToPdf(new File(sourceFolder + "paragraphWithImageTest01RTL.html"), new File(destinationFolder + "paragraphWithImageTest01RTL.pdf"));
197+
Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "paragraphWithImageTest01RTL.pdf", sourceFolder + "cmp_paragraphWithImageTest01RTL.pdf", destinationFolder, "diff_paragraphWithImageTest01_"));
198+
}
193199
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<body dir="rtl">
2+
<p><img
3+
style='display: block; margin-left: auto; margin-right: auto;' title='placeholder-170x70.jpg'
4+
src='image.png' width='170'
5+
height='70'/></p>
6+
</body>

0 commit comments

Comments
 (0)