Skip to content

Commit 0f19ed4

Browse files
committed
Fix issue with shartTag in reusable Type 3 font.
DEVSIX-1468
1 parent 57a142d commit 0f19ed4

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,13 @@ public class PdfType3Font extends PdfSimpleFont<Type3Font> {
130130
} else {
131131
fontProgram.getFontMetrics().setBbox(0, 0, 0, 0);
132132
}
133-
PdfNumber firstCharNumber = fontDictionary.getAsNumber(PdfName.FirstChar);
134-
int firstChar = firstCharNumber != null ? Math.max(firstCharNumber.intValue(), 0) : 0;
133+
int firstChar = normalizeFirstLastChar(fontDictionary.getAsNumber(PdfName.FirstChar), 0);
134+
int lastChar = normalizeFirstLastChar(fontDictionary.getAsNumber(PdfName.LastChar), 255);
135+
for (int i = firstChar; i <= lastChar; i++) {
136+
shortTag[i] = 1;
137+
}
135138
int[] widths = FontUtil.convertSimpleWidthsArray(fontDictionary.getAsArray(PdfName.Widths), firstChar, 0);
139+
136140
double[] fontMatrix = new double[6];
137141
for (int i = 0; i < fontMatrixArray.size(); i++) {
138142
fontMatrix[i] = ((PdfNumber) fontMatrixArray.get(i)).getValue();
@@ -177,7 +181,7 @@ public void setFontWeight(int fontWeight) {
177181
}
178182

179183
/**
180-
* Sets the PostScript italic angel.
184+
* Sets the PostScript italic angle.
181185
* <br/>
182186
* Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
183187
*
@@ -370,7 +374,6 @@ protected PdfDocument getDocument() {
370374
return getPdfObject().getIndirectReference().getDocument();
371375
}
372376

373-
374377
/**
375378
* Gets first empty code, that could use with {@see addSymbol()}
376379
*
@@ -386,7 +389,6 @@ private int getFirstEmptyCode() {
386389
return -1;
387390
}
388391

389-
390392
private void fillFontDescriptor(PdfDictionary fontDesc) {
391393
if (fontDesc == null) {
392394
return;
@@ -415,4 +417,10 @@ private void fillFontDescriptor(PdfDictionary fontDesc) {
415417
setFontFamily(fontFamily.getValue());
416418
}
417419
}
420+
421+
private int normalizeFirstLastChar(PdfNumber firstLast, int defaultValue) {
422+
if (firstLast == null) return defaultValue;
423+
int result = firstLast.intValue();
424+
return result < 0 || result > 255 ? defaultValue : result;
425+
}
418426
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,4 @@ public void standardAndType3Fonts() throws Exception {
9292

9393
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
9494
}
95-
9695
}

0 commit comments

Comments
 (0)