Skip to content

Commit 57a142d

Browse files
committed
Fix multiple issues in Type 3 font tests.
DEVSIX-1468
1 parent e9a7b08 commit 57a142d

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

kernel/src/main/java/com/itextpdf/kernel/font/PdfType3Font.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public class PdfType3Font extends PdfSimpleFont<Type3Font> {
116116
*/
117117
PdfType3Font(PdfDictionary fontDictionary) {
118118
super(fontDictionary);
119-
ensureObjectIsAddedToDocument(fontDictionary);
120119
subset = true;
121120
embedded = true;
122121
fontProgram = new Type3Font(false);
@@ -324,11 +323,8 @@ public void flush() {
324323
getPdfObject().put(PdfName.FontBBox, new PdfArray(fontProgram.getFontMetrics().getBbox()));
325324

326325
String fontName = fontProgram.getFontNames().getFontName();
327-
if (fontName != null && fontName.length() > 0) {
328-
getPdfObject().put(PdfName.BaseFont, new PdfName(fontName));
329-
}
330326
super.flushFontData(fontName, PdfName.Type3);
331-
//TODO improve
327+
//BaseFont is not listed as key in Type 3 font specification.
332328
getPdfObject().remove(PdfName.BaseFont);
333329
super.flush();
334330
}
@@ -338,13 +334,15 @@ protected PdfDictionary getFontDescriptor(String fontName) {
338334
if (fontName != null && fontName.length() > 0) {
339335
PdfDictionary fontDescriptor = new PdfDictionary();
340336
makeObjectIndirect(fontDescriptor);
341-
FontMetrics fontMetrics = fontProgram.getFontMetrics();
342-
FontNames fontNames = fontProgram.getFontNames();
343337
fontDescriptor.put(PdfName.Type, PdfName.FontDescriptor);
344-
fontDescriptor.put(PdfName.FontName, new PdfName(fontName));
338+
339+
FontMetrics fontMetrics = fontProgram.getFontMetrics();
345340
fontDescriptor.put(PdfName.CapHeight, new PdfNumber(fontMetrics.getCapHeight()));
346341
fontDescriptor.put(PdfName.ItalicAngle, new PdfNumber(fontMetrics.getItalicAngle()));
342+
343+
FontNames fontNames = fontProgram.getFontNames();
347344
fontDescriptor.put(PdfName.FontWeight, new PdfNumber(fontNames.getFontWeight()));
345+
fontDescriptor.put(PdfName.FontName, new PdfName(fontName));
348346
if (fontNames.getFamilyName() != null && fontNames.getFamilyName().length > 0 && fontNames.getFamilyName()[0].length >= 4) {
349347
fontDescriptor.put(PdfName.FontFamily, new PdfString(fontNames.getFamilyName()[0][3]));
350348
}

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ private boolean compareDictionariesExtended(PdfDictionary outDict, PdfDictionary
11311131
if (outDict.isStream() && cmpDict.isStream() && (key.equals(PdfName.Filter) || key.equals(PdfName.Length))) continue;
11321132
if (key.equals(PdfName.BaseFont) || key.equals(PdfName.FontName)) {
11331133
PdfObject cmpObj = cmpDict.get(key);
1134-
if (cmpObj.isName() && cmpObj.toString().indexOf('+') > 0) {
1134+
if (cmpObj != null && cmpObj.isName() && cmpObj.toString().indexOf('+') > 0) {
11351135
PdfObject outObj = outDict.get(key);
11361136
if (!outObj.isName() || outObj.toString().indexOf('+') == -1) {
11371137
if (compareResult != null && currentPath != null)

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfFontTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ public void createTaggedDocumentWithType3Font() throws IOException, InterruptedE
380380
.setFontAndSize(type3, 12)
381381
.moveText(50, 800)
382382
.showText(testString)
383-
.endText();
383+
.endText()
384+
.restoreState();
384385
page.flush();
385386
}
386387
pdfDoc.close();
@@ -863,7 +864,7 @@ public void testUpdateType3FontBasedExistingFont() throws IOException, Interrupt
863864
setCreator(creator).
864865
setTitle(title);
865866

866-
PdfType3Font pdfType3Font = (PdfType3Font) PdfFontFactory.createFont((PdfDictionary) pdfDoc.getPdfObject(4));
867+
PdfType3Font pdfType3Font = (PdfType3Font) PdfFontFactory.createFont((PdfDictionary) pdfDoc.getPdfObject(5));
867868

868869
Type3Glyph newGlyph = pdfType3Font.addGlyph('\u00F6', 600, 0, 0, 600, 700);
869870
newGlyph.setLineWidth(100);
@@ -877,8 +878,9 @@ public void testUpdateType3FontBasedExistingFont() throws IOException, Interrupt
877878
.beginText()
878879
.setFontAndSize(pdfType3Font, 12)
879880
.moveText(50, 800)
880-
.showText("AAAAAA EEEE ~ \u00E9 \u00F6") // é ö
881-
.endText();
881+
.showText("A A A A A A E E E E ~ \u00E9 \u00F6") // é ö
882+
.endText()
883+
.restoreState();
882884
page.flush();
883885
pdfDoc.close();
884886

@@ -905,7 +907,7 @@ public void testNewType3FontBasedExistingFont() throws IOException, InterruptedE
905907
setCreator(creator).
906908
setTitle(title);
907909

908-
PdfDictionary pdfType3FontDict = (PdfDictionary) inputPdfDoc.getPdfObject(4);
910+
PdfDictionary pdfType3FontDict = (PdfDictionary) inputPdfDoc.getPdfObject(5);
909911
PdfType3Font pdfType3Font = (PdfType3Font) PdfFontFactory.createFont((PdfDictionary) pdfType3FontDict.copyTo(outputPdfDoc));
910912

911913
Type3Glyph newGlyph = pdfType3Font.addGlyph('\u00F6', 600, 0, 0, 600, 700);
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)