Skip to content

Commit 731cad7

Browse files
BlackEgoistiText-CI
authored andcommitted
Refactor code, add comments
1 parent a1d8ac8 commit 731cad7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public class DefaultFontProvider extends BasicFontProvider {
9494
.addRange(0, 0x058F).addRange(0x0E80, Integer.MAX_VALUE).create();
9595

9696

97-
private List<byte[]> fontStreamList = new ArrayList<>();
97+
//we want to add free fonts to font provider before calligraph fonts. However, the existing public API states
98+
// that addCalligraphFonts() should be used first to load calligraph fonts and to define the range for loading free fonts.
99+
// In order to maintain backward compatibility, this temporary field is used to stash calligraph fonts before free fonts are loaded.
100+
private List<byte[]> calligraphyFontsTempList = new ArrayList<>();
98101

99102
/**
100103
* Creates a new {@link DefaultFontProvider} instance.
@@ -119,9 +122,10 @@ public DefaultFontProvider(boolean registerStandardPdfFonts, boolean registerShi
119122

120123
private void addAllAvailableFonts(Range rangeToLoad) {
121124
addShippedFreeFonts(rangeToLoad);
122-
for(byte[] fontData : fontStreamList) {
125+
for(byte[] fontData : calligraphyFontsTempList) {
123126
addFont(fontData, null);
124127
}
128+
calligraphyFontsTempList = null;
125129
}
126130

127131
/**
@@ -146,7 +150,6 @@ private void addShippedFreeFonts(Range rangeToLoad) {
146150
* If it's needed to have a DefaultFontProvider without typography fonts loaded,
147151
* create an extension of DefaultFontProvider and override this method so it does nothing and only returns null.
148152
*
149-
*
150153
* @return a unicode {@link Range} that excludes the loaded from pdfCalligraph fonts,
151154
* i.e. the unicode range that is to be rendered with any other font contained in this FontProvider
152155
*/
@@ -160,8 +163,9 @@ protected Range addCalligraphFonts() {
160163
try {
161164
Method m = klass.getMethod(methodName);
162165
ArrayList<byte[]> fontStreams = (ArrayList<byte[]>) m.invoke(null, null);
163-
for (byte[] font : fontStreams)
164-
addFontToList(font);
166+
for (byte[] font : fontStreams) {
167+
this.calligraphyFontsTempList.add(font);
168+
}
165169
// here we return a unicode range that excludes the loaded from the calligraph module fonts
166170
// i.e. the unicode range that is to be rendered with standard or shipped free fonts
167171
return FREE_FONT_RANGE;
@@ -176,8 +180,4 @@ private static Class<?> getTypographyUtilsClass() throws ClassNotFoundException
176180
String typographyClassFullName = "com.itextpdf.typography.util.TypographyShippedFontsUtil";
177181
return Class.forName(typographyClassFullName);
178182
}
179-
180-
private void addFontToList(byte[] fontData) {
181-
this.fontStreamList.add(fontData);
182-
}
183183
}

0 commit comments

Comments
 (0)