Skip to content

Commit 395d61c

Browse files
BlackEgoistiText-CI
authored andcommitted
Override addFont method in DefaultfontProvide
1 parent 3f1b7a8 commit 395d61c

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/main/java/com/itextpdf/html2pdf/resolver/font/DefaultFontProvider.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This file is part of the iText (R) project.
5353
import java.io.InputStream;
5454
import java.lang.reflect.Method;
5555
import java.util.ArrayList;
56+
import java.util.List;
5657

5758
/**
5859
* The default {@link BasicFontProvider} for pdfHTML, that, as opposed to
@@ -92,6 +93,9 @@ public class DefaultFontProvider extends BasicFontProvider {
9293
private static final Range FREE_FONT_RANGE = new RangeBuilder()
9394
.addRange(0, 0x058F).addRange(0x0E80, Integer.MAX_VALUE).create();
9495

96+
97+
private List<byte[]> fontStreamList = new ArrayList<>();
98+
9599
/**
96100
* Creates a new {@link DefaultFontProvider} instance.
97101
*/
@@ -109,12 +113,14 @@ public DefaultFontProvider() {
109113
public DefaultFontProvider(boolean registerStandardPdfFonts, boolean registerShippedFreeFonts, boolean registerSystemFonts) {
110114
super(registerStandardPdfFonts, registerSystemFonts);
111115
if (registerShippedFreeFonts) {
112-
if(checkCalligraphFonts() != null) {
113-
addShippedFreeFonts(FREE_FONT_RANGE);
114-
addCalligraphFonts();
115-
} else {
116-
addShippedFreeFonts(null);
117-
}
116+
addAllAvailableFonts(addCalligraphFonts());
117+
}
118+
}
119+
120+
private void addAllAvailableFonts(Range rangeToLoad) {
121+
addShippedFreeFonts(rangeToLoad);
122+
for(byte[] fontData : fontStreamList) {
123+
addFont(fontData, null);
118124
}
119125
}
120126

@@ -146,7 +152,10 @@ private void addShippedFreeFonts(Range rangeToLoad) {
146152
*/
147153
protected Range addCalligraphFonts() {
148154
String methodName = "loadShippedFonts";
149-
Class<?> klass = checkCalligraphFonts();
155+
Class<?> klass = null;
156+
try {
157+
klass = getTypographyUtilsClass();
158+
} catch (ClassNotFoundException ignored) { }
150159
if (klass != null) {
151160
try {
152161
Method m = klass.getMethod(methodName);
@@ -163,16 +172,14 @@ protected Range addCalligraphFonts() {
163172
return null;
164173
}
165174

166-
private Class<?> checkCalligraphFonts() {
167-
Class<?> klass = null;
168-
try {
169-
klass = getTypographyUtilsClass();
170-
} catch (ClassNotFoundException ignored) { }
171-
return klass;
172-
}
173-
174175
private static Class<?> getTypographyUtilsClass() throws ClassNotFoundException {
175176
String typographyClassFullName = "com.itextpdf.typography.util.TypographyShippedFontsUtil";
176177
return Class.forName(typographyClassFullName);
177178
}
179+
180+
@Override
181+
public boolean addFont(byte[] fontData) {
182+
this.fontStreamList.add(fontData);
183+
return true;
184+
}
178185
}

0 commit comments

Comments
 (0)