Skip to content

Commit cd124c1

Browse files
committed
Fix line wrap for non wrapping italic/bold simulated text
DEVSIX-9051
1 parent 17a166c commit cd124c1

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/TextRenderer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,12 @@ && findPossibleBreaksSplitPosition(specialScriptsWordBreakPoints,
583583

584584
boolean specialScriptWordSplit = textContainsSpecialScriptGlyphs(true)
585585
&& !isSplitForcedByNewLine && isOverflowFit(overflowX);
586-
if ((nonBreakablePartFullWidth > layoutBox.getWidth() && !anythingPlaced && !hyphenationApplied)
586+
// It's not clear why we need
587+
// nonBreakablePartFullWidth + italicSkewAddition + boldSimulationAddition > layoutBox.getWidth()
588+
// condition. We are already in the branch where we could not fit a word. Removing this condition
589+
// does not change anything. Still leaving it here.
590+
if ((nonBreakablePartFullWidth + italicSkewAddition + boldSimulationAddition > layoutBox.getWidth()
591+
&& !anythingPlaced && !hyphenationApplied)
587592
|| forcePartialSplitOnFirstChar
588593
|| -1 != nonBreakingHyphenRelatedChunkStart
589594
|| specialScriptWordSplit) {

layout/src/test/java/com/itextpdf/layout/TableTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,9 +3483,8 @@ private static void startSeveralEmptyRows(Table table) {
34833483
}
34843484

34853485
@Test
3486-
@LogMessages(messages = {@LogMessage(messageTemplate = LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)})
3487-
public void preciseFittingBoldSimulatedTextInCellsTest() throws IOException, InterruptedException {
3488-
String fileName = "preciseFittingBoldSimulatedTextInCells.pdf";
3486+
public void preciseFittingItalicBoldSimulatedTextInCellsTest() throws IOException, InterruptedException {
3487+
String fileName = "preciseFittingItalicBoldSimulatedTextInCells.pdf";
34893488

34903489
try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + fileName));
34913490
Document doc = new Document(pdfDocument)) {
@@ -3496,7 +3495,13 @@ public void preciseFittingBoldSimulatedTextInCellsTest() throws IOException, Int
34963495
table.setFixedLayout();
34973496

34983497
for (int i = 0; i < numberOfColumns; i++) {
3499-
table.addCell(new Cell().add(new Paragraph("Description").simulateBold()));
3498+
Paragraph p = new Paragraph("Description");
3499+
if (i % 2 == 0) {
3500+
p.simulateBold();
3501+
} else {
3502+
p.simulateItalic();
3503+
}
3504+
table.addCell(new Cell().add(p));
35003505
}
35013506

35023507
doc.add(table);

0 commit comments

Comments
 (0)