Skip to content

Commit 07bf137

Browse files
author
Benoit Lagae
committed
Log warning when catching edge case exception
DEVSIX-1385, DEVSIX-1359
1 parent b7111bb commit 07bf137

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public final class LogMessageConstant {
6969
public static final String FILE_CHANNEL_CLOSING_FAILED = "Closing of the file channel this source is based on failed.";
7070
public static final String FONT_HAS_INVALID_GLYPH = "Font {0} has invalid glyph: {1}";
7171
public static final String FORBID_RELEASE_IS_SET = "ForbidRelease flag is set and release is called. Releasing will not be performed.";
72+
public static final String FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT = "The Font Property must be a PdfFont object";
7273
public static final String FORM_FIELD_WAS_FLUSHED = "A form field was flushed. There's no way to create this field in the AcroForm dictionary.";
7374
public static final String IMAGE_HAS_AMBIGUOUS_SCALE = "The image cannot be auto scaled and scaled by a certain parameter simultaneously";
7475
public static final String IMAGE_HAS_JBIG2DECODE_FILTER = "Image cannot be inline if it has JBIG2Decode filter. It will be added as an ImageXObject";

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,14 @@ private boolean isGlyphPartOfWordForHyphenation(Glyph g) {
12591259

12601260
private void updateFontAndText() {
12611261
if (strToBeConverted != null) {
1262-
font = resolveFirstPdfFont();
1262+
try {
1263+
font = getPropertyAsFont(Property.FONT);
1264+
}
1265+
catch (ClassCastException cce) {
1266+
font = resolveFirstPdfFont();
1267+
Logger logger = LoggerFactory.getLogger(TextRenderer.class);
1268+
logger.error(LogMessageConstant.FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT);
1269+
}
12631270
text = convertToGlyphLine(strToBeConverted);
12641271
otfFeaturesApplied = false;
12651272
strToBeConverted = null;

layout/src/test/java/com/itextpdf/layout/renderer/TextRendererTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.layout.renderer;
4444

45+
import com.itextpdf.io.LogMessageConstant;
4546
import com.itextpdf.kernel.geom.Rectangle;
4647
import com.itextpdf.kernel.pdf.ByteBufferOutputStream;
4748
import com.itextpdf.kernel.pdf.PdfDocument;
@@ -54,6 +55,8 @@ This file is part of the iText (R) project.
5455
import com.itextpdf.layout.layout.LayoutResult;
5556
import com.itextpdf.layout.property.Property;
5657
import com.itextpdf.test.ExtendedITextTest;
58+
import com.itextpdf.test.annotations.LogMessage;
59+
import com.itextpdf.test.annotations.LogMessages;
5760
import com.itextpdf.test.annotations.type.UnitTest;
5861

5962
import org.junit.Assert;
@@ -88,6 +91,9 @@ public void nextRendererTest() {
8891
}
8992

9093
@Test
94+
@LogMessages(messages = {
95+
@LogMessage(messageTemplate = LogMessageConstant.FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT)
96+
})
9197
public void setTextException() {
9298
final String val = "other text";
9399
final String fontName = "Helvetica";

0 commit comments

Comments
 (0)