Skip to content

Commit 8c9f6df

Browse files
vitali-priText-CI
authored andcommitted
Fix the issue with applying justify align
DEVSIX-2992 Autoported commit. Original commit hash: [c2b3f987d]
1 parent 21c37b5 commit 8c9f6df

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

itext.tests/itext.layout.tests/itext/layout/AlignmentTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class AlignmentTest : ExtendedITextTest {
4545
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
4646
+ "/test/itext/layout/AlignmentTest/";
4747

48+
private static readonly String FONTS_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
49+
.CurrentContext.TestDirectory) + "/resources/itext/layout/fonts/";
50+
4851
[NUnit.Framework.OneTimeSetUp]
4952
public static void BeforeClass() {
5053
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
@@ -519,6 +522,23 @@ public virtual void FlexItemHorizontalAlignmentTest() {
519522
, "diff"));
520523
}
521524

525+
[NUnit.Framework.Test]
526+
public virtual void JustifiedAlignmentWithZeroFreeSpaceTest() {
527+
String outFileName = DESTINATION_FOLDER + "justifiedAlignmentWithZeroFreeSpaceTest.pdf";
528+
String cmpFileName = SOURCE_FOLDER + "cmp_justifiedAlignmentWithZeroFreeSpaceTest.pdf";
529+
using (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName))) {
530+
Document document = new Document(pdfDoc);
531+
PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansCJKjp-Regular.otf");
532+
Text t1 = new Text("期期期").SetFont(font);
533+
Text t2 = new Text("期期期").SetFont(font);
534+
Paragraph p = new Paragraph(t1).Add(t2).SetSpacingRatio(1).SetWidth(60).SetTextAlignment(TextAlignment.JUSTIFIED
535+
);
536+
document.Add(p);
537+
}
538+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
539+
, "diff"));
540+
}
541+
522542
private static void CreateDocumentWithInlineAlignment(String outPdf, String cmpPdf, InlineVerticalAlignmentType?
523543
verticalAlignment1) {
524544
CreateDocumentWithInlineAlignment(outPdf, cmpPdf, verticalAlignment1, null);

itext/itext.layout/itext/layout/renderer/LineRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public virtual void Justify(float width) {
729729
int baseCharsCount = BaseCharactersCount();
730730
float baseFactor = freeWidth / (ratio * numberOfSpaces + (1 - ratio) * (baseCharsCount - 1));
731731
//Prevent a NaN when trying to justify a single word with spacing_ratio == 1.0
732-
if (float.IsInfinity(baseFactor)) {
732+
if (float.IsInfinity(baseFactor) || float.IsNaN(baseFactor)) {
733733
baseFactor = 0;
734734
}
735735
float wordSpacing = ratio * baseFactor;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a390afa1f077eb736e61e6d66d74a7f35354e0e4
1+
c2b3f987d05db32411585f4579adcef01ad857a3

0 commit comments

Comments
 (0)