Skip to content

Commit 97ece58

Browse files
committed
Remove PdfFontFactory#createStandardFont() and #createType1Font()
Remove #createStandardFont() in favour to #createFont(). If user wants to create specific PdfType1Font, he should firstly create FontProgram with FontFactory.createType1Font()
1 parent 4537957 commit 97ece58

File tree

28 files changed

+226
-374
lines changed

28 files changed

+226
-374
lines changed

barcodes/src/main/java/com/itextpdf/barcodes/Barcode128.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public Barcode128(PdfDocument document) {
187187
super(document);
188188
try {
189189
x = 0.8f;
190-
font = PdfFontFactory.createStandardFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
190+
font = PdfFontFactory.createFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
191191
size = 8;
192192
baseline = size;
193193
barHeight = size * 3;

barcodes/src/main/java/com/itextpdf/barcodes/Barcode39.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Barcode39(PdfDocument document) {
9393
try {
9494
x = 0.8f;
9595
n = 2;
96-
font = PdfFontFactory.createStandardFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
96+
font = PdfFontFactory.createFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
9797
size = 8;
9898
baseline = size;
9999
barHeight = size * 3;

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeCodabar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public BarcodeCodabar(PdfDocument document) {
5353
try {
5454
x = 0.8f;
5555
n = 2;
56-
font = PdfFontFactory.createStandardFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
56+
font = PdfFontFactory.createFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
5757
size = 8;
5858
baseline = size;
5959
barHeight = size * 3;

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeEAN.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public BarcodeEAN(PdfDocument document) {
170170
super(document);
171171
try {
172172
x = 0.8f;
173-
font = PdfFontFactory.createStandardFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
173+
font = PdfFontFactory.createFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
174174
size = 8;
175175
baseline = size;
176176
barHeight = size * 3;

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeInter25.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public BarcodeInter25(PdfDocument document) {
5757
try {
5858
x = 0.8f;
5959
n = 2;
60-
font = PdfFontFactory.createStandardFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
60+
font = PdfFontFactory.createFont(FontConstants.HELVETICA, PdfEncodings.WINANSI);
6161
size = 8;
6262
baseline = size;
6363
barHeight = size * 3;

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ public void setCheckType(int checkType) {
13561356
this.checkType = checkType;
13571357
text = typeChars[checkType - 1];
13581358
try {
1359-
font = PdfFontFactory.createStandardFont(FontConstants.ZAPFDINGBATS);
1359+
font = PdfFontFactory.createFont(FontConstants.ZAPFDINGBATS);
13601360
} catch (IOException e) {
13611361
throw new PdfException(e.getLocalizedMessage());
13621362
}

io/src/main/java/com/itextpdf/io/font/FontCache.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,21 @@ public static FontProgram getFont(String fontName) {
116116
return fontCache.get(key);
117117
}
118118

119-
public static void saveFont(FontProgram font, String fontName) {
119+
public static FontProgram saveFont(FontProgram font, String fontName) {
120120
// for most of the fonts we can retrieve encoding from FontProgram, but
121121
// for Cid there is no such possibility, since it is used in conjunction
122122
// with cmap to produce Type0 font, so I added fontName and encoding parameters
123123
// just for convenience.
124124
// TODO: probably it's better to declare saveFont(FontProgram) and saveFont(CidFont, encoding or cmap) in the future
125+
FontProgram fontFound = getFont(fontName);
126+
if (fontFound != null) {
127+
//TODO add close method
128+
//fontBuilt.close();
129+
return fontFound;
130+
}
125131
String key = getFontCacheKey(fontName);
126132
fontCache.put(key, font);
133+
return font;
127134
}
128135

129136
private static void loadRegistry() throws java.io.IOException {

io/src/main/java/com/itextpdf/io/font/FontFactory.java

Lines changed: 102 additions & 155 deletions
Large diffs are not rendered by default.

io/src/main/java/com/itextpdf/io/font/Type1Font.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,14 @@ public class Type1Font extends FontProgram {
3232
private byte[] fontStreamBytes;
3333
private int[] fontStreamLengths;
3434

35-
public static Type1Font createStandardFont(String name) throws java.io.IOException {
35+
protected static Type1Font createStandardFont(String name) throws java.io.IOException {
3636
if (FontConstants.BUILTIN_FONTS_14.contains(name)) {
37-
return createFont(name);
37+
return new Type1Font(name, null, null, null);
3838
} else {
3939
throw new IOException("1.is.not.a.standard.type1.font").setMessageParams(name);
4040
}
4141
}
4242

43-
public static Type1Font createFont(String metricsPath) throws java.io.IOException {
44-
return new Type1Font(metricsPath, null, null, null);
45-
}
46-
47-
public static Type1Font createFont(String metricsPath, String binaryPath) throws java.io.IOException {
48-
return new Type1Font(metricsPath, binaryPath, null, null);
49-
}
50-
51-
public static Type1Font createFont(byte[] metricsData) throws java.io.IOException {
52-
return new Type1Font(null, null, metricsData, null);
53-
}
54-
55-
public static Type1Font createFont(byte[] metricsData, byte[] binaryData) throws java.io.IOException {
56-
return new Type1Font(null, null, metricsData, binaryData);
57-
}
58-
5943
protected Type1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb) throws java.io.IOException {
6044
checkFilePath(metricsPath);
6145
checkFilePath(binaryPath);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static Type1Font createFontProgram(PdfDictionary fontDictionary, FontEncoding fo
3333
try {
3434
//if there are no font modifiers, cached font could be used,
3535
//otherwise a new instance should be created.
36-
type1StdFont = createStandardFont(baseFont);
36+
type1StdFont = Type1Font.createStandardFont(baseFont);
3737
} catch (Exception e) {
3838
type1StdFont = null;
3939
}

0 commit comments

Comments
 (0)