Skip to content

Commit a080e83

Browse files
committed
Process empty text renderers.
Currently iText skips empty text renderers. However they can have borders or paddings with background to be drawn. DEVSIX-1552
1 parent 51efef3 commit a080e83

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,16 @@ protected boolean resolveFonts(List<IRenderer> addTo) {
11411141
FontCharacteristics fc = createFontCharacteristics();
11421142
FontSelectorStrategy strategy = provider.getStrategy(strToBeConverted,
11431143
FontFamilySplitter.splitFontFamily((String) font), fc, fontSet);
1144-
while (!strategy.endOfText()) {
1145-
GlyphLine nextGlyphs = new GlyphLine(strategy.nextGlyphs());
1146-
PdfFont currentFont = strategy.getCurrentFont();
1147-
TextRenderer textRenderer = createCopy(replaceSpecialWhitespaceGlyphs(nextGlyphs, currentFont), currentFont);
1148-
addTo.add(textRenderer);
1144+
// process empty renderers because they can have borders or paddings with background to be drawn
1145+
if (null != strToBeConverted && strToBeConverted.isEmpty()) {
1146+
addTo.add(this);
1147+
} else {
1148+
while (!strategy.endOfText()) {
1149+
GlyphLine nextGlyphs = new GlyphLine(strategy.nextGlyphs());
1150+
PdfFont currentFont = strategy.getCurrentFont();
1151+
TextRenderer textRenderer = createCopy(replaceSpecialWhitespaceGlyphs(nextGlyphs, currentFont), currentFont);
1152+
addTo.add(textRenderer);
1153+
}
11491154
}
11501155
return true;
11511156
} else {
@@ -1282,8 +1287,10 @@ private void updateFontAndText() {
12821287
}
12831288
catch (ClassCastException cce) {
12841289
font = resolveFirstPdfFont();
1285-
Logger logger = LoggerFactory.getLogger(TextRenderer.class);
1286-
logger.error(LogMessageConstant.FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT);
1290+
if (!strToBeConverted.isEmpty()) {
1291+
Logger logger = LoggerFactory.getLogger(TextRenderer.class);
1292+
logger.error(LogMessageConstant.FONT_PROPERTY_MUST_BE_PDF_FONT_OBJECT);
1293+
}
12871294
}
12881295
text = convertToGlyphLine(strToBeConverted);
12891296
otfFeaturesApplied = false;

0 commit comments

Comments
 (0)