FileSystemFontProvider.java (pdfbox-2.0.23-src) | : | FileSystemFontProvider.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 203 | skipping to change at line 203 | |||
TrueTypeFont ttf = readTrueTypeFont(postScriptName, file); | TrueTypeFont ttf = readTrueTypeFont(postScriptName, file); | |||
if (LOG.isDebugEnabled()) | if (LOG.isDebugEnabled()) | |||
{ | { | |||
LOG.debug("Loaded " + postScriptName + " from " + file); | LOG.debug("Loaded " + postScriptName + " from " + file); | |||
} | } | |||
return ttf; | return ttf; | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Could not load font file: " + file, e); | LOG.warn("Could not load font file: " + file, e); | |||
} | } | |||
return null; | return null; | |||
} | } | |||
private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException | private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException | |||
{ | { | |||
if (file.getName().toLowerCase().endsWith(".ttc")) | if (file.getName().toLowerCase().endsWith(".ttc")) | |||
{ | { | |||
@SuppressWarnings("squid:S2095") | @SuppressWarnings("squid:S2095") | |||
// ttc not closed here because it is needed later when ttf is ac cessed, | // ttc not closed here because it is needed later when ttf is ac cessed, | |||
// e.g. rendering PDF with non-embedded font which is in ttc fil e in our font directory | // e.g. rendering PDF with non-embedded font which is in ttc fil e in our font directory | |||
TrueTypeCollection ttc = new TrueTypeCollection(file); | TrueTypeCollection ttc = new TrueTypeCollection(file); | |||
TrueTypeFont ttf = null; | TrueTypeFont ttf; | |||
try | try | |||
{ | { | |||
ttf = ttc.getFontByName(postScriptName); | ttf = ttc.getFontByName(postScriptName); | |||
} | } | |||
catch (IOException ex) | catch (IOException ex) | |||
{ | { | |||
ttc.close(); | ttc.close(); | |||
throw ex; | throw ex; | |||
} | } | |||
if (ttf == null) | if (ttf == null) | |||
skipping to change at line 250 | skipping to change at line 250 | |||
private OpenTypeFont getOTFFont(String postScriptName, File file) | private OpenTypeFont getOTFFont(String postScriptName, File file) | |||
{ | { | |||
try | try | |||
{ | { | |||
if (file.getName().toLowerCase().endsWith(".ttc")) | if (file.getName().toLowerCase().endsWith(".ttc")) | |||
{ | { | |||
@SuppressWarnings("squid:S2095") | @SuppressWarnings("squid:S2095") | |||
// ttc not closed here because it is needed later when ttf i s accessed, | // ttc not closed here because it is needed later when ttf i s accessed, | |||
// e.g. rendering PDF with non-embedded font which is in ttc file in our font directory | // e.g. rendering PDF with non-embedded font which is in ttc file in our font directory | |||
TrueTypeCollection ttc = new TrueTypeCollection(file); | TrueTypeCollection ttc = new TrueTypeCollection(file); | |||
TrueTypeFont ttf = null; | TrueTypeFont ttf; | |||
try | try | |||
{ | { | |||
ttf = ttc.getFontByName(postScriptName); | ttf = ttc.getFontByName(postScriptName); | |||
} | } | |||
catch (IOException ex) | catch (IOException ex) | |||
{ | { | |||
LOG.error(ex.getMessage(), ex); | LOG.error(ex.getMessage(), ex); | |||
ttc.close(); | ttc.close(); | |||
return null; | return null; | |||
} | } | |||
skipping to change at line 280 | skipping to change at line 280 | |||
OpenTypeFont otf = parser.parse(file); | OpenTypeFont otf = parser.parse(file); | |||
if (LOG.isDebugEnabled()) | if (LOG.isDebugEnabled()) | |||
{ | { | |||
LOG.debug("Loaded " + postScriptName + " from " + file); | LOG.debug("Loaded " + postScriptName + " from " + file); | |||
} | } | |||
return otf; | return otf; | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Could not load font file: " + file, e); | LOG.warn("Could not load font file: " + file, e); | |||
} | } | |||
return null; | return null; | |||
} | } | |||
private Type1Font getType1Font(String postScriptName, File file) | private Type1Font getType1Font(String postScriptName, File file) | |||
{ | { | |||
InputStream input = null; | InputStream input = null; | |||
try | try | |||
{ | { | |||
input = new FileInputStream(file); | input = new FileInputStream(file); | |||
Type1Font type1 = Type1Font.createWithPFB(input); | Type1Font type1 = Type1Font.createWithPFB(input); | |||
if (LOG.isDebugEnabled()) | if (LOG.isDebugEnabled()) | |||
{ | { | |||
LOG.debug("Loaded " + postScriptName + " from " + file); | LOG.debug("Loaded " + postScriptName + " from " + file); | |||
} | } | |||
return type1; | return type1; | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Could not load font file: " + file, e); | LOG.warn("Could not load font file: " + file, e); | |||
} | } | |||
finally | finally | |||
{ | { | |||
IOUtils.closeQuietly(input); | IOUtils.closeQuietly(input); | |||
} | } | |||
return null; | return null; | |||
} | } | |||
} | } | |||
/** | /** | |||
skipping to change at line 392 | skipping to change at line 392 | |||
{ | { | |||
addTrueTypeCollection(file); | addTrueTypeCollection(file); | |||
} | } | |||
else if (filePath.endsWith(".pfb")) | else if (filePath.endsWith(".pfb")) | |||
{ | { | |||
addType1Font(file); | addType1Font(file); | |||
} | } | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Error parsing font " + file.getPath(), e); | LOG.warn("Error parsing font " + file.getPath(), e); | |||
} | } | |||
} | } | |||
} | } | |||
private File getDiskCacheFile() | private File getDiskCacheFile() | |||
{ | { | |||
String path = System.getProperty("pdfbox.fontcache"); | String path = System.getProperty("pdfbox.fontcache"); | |||
if (path == null || !new File(path).isDirectory() || !new File(path).can Write()) | if (path == null || !new File(path).isDirectory() || !new File(path).can Write()) | |||
{ | { | |||
path = System.getProperty("user.home"); | path = System.getProperty("user.home"); | |||
skipping to change at line 528 | skipping to change at line 528 | |||
BufferedReader reader = null; | BufferedReader reader = null; | |||
try | try | |||
{ | { | |||
reader = new BufferedReader(new FileReader(file)); | reader = new BufferedReader(new FileReader(file)); | |||
String line; | String line; | |||
while ((line = reader.readLine()) != null) | while ((line = reader.readLine()) != null) | |||
{ | { | |||
String[] parts = line.split("\\|", 10); | String[] parts = line.split("\\|", 10); | |||
if (parts.length < 10) | if (parts.length < 10) | |||
{ | { | |||
LOG.error("Incorrect line '" + line + "' in font disk ca che is skipped"); | LOG.warn("Incorrect line '" + line + "' in font disk cac he is skipped"); | |||
continue; | continue; | |||
} | } | |||
String postScriptName; | String postScriptName; | |||
FontFormat format; | FontFormat format; | |||
CIDSystemInfo cidSystemInfo = null; | CIDSystemInfo cidSystemInfo = null; | |||
int usWeightClass = -1; | int usWeightClass = -1; | |||
int sFamilyClass = -1; | int sFamilyClass = -1; | |||
int ulCodePageRange1; | int ulCodePageRange1; | |||
int ulCodePageRange2; | int ulCodePageRange2; | |||
skipping to change at line 591 | skipping to change at line 591 | |||
} | } | |||
else | else | |||
{ | { | |||
LOG.debug("Font file " + fontFile.getAbsolutePath() + " not found, skipped"); | LOG.debug("Font file " + fontFile.getAbsolutePath() + " not found, skipped"); | |||
} | } | |||
pending.remove(fontFile.getAbsolutePath()); | pending.remove(fontFile.getAbsolutePath()); | |||
} | } | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Error loading font cache, will be re-built", e); | LOG.warn("Error loading font cache, will be re-built", e); | |||
return null; | return null; | |||
} | } | |||
finally | finally | |||
{ | { | |||
IOUtils.closeQuietly(reader); | IOUtils.closeQuietly(reader); | |||
} | } | |||
} | } | |||
if (!pending.isEmpty()) | if (!pending.isEmpty()) | |||
{ | { | |||
skipping to change at line 630 | skipping to change at line 630 | |||
{ | { | |||
@Override | @Override | |||
public void process(TrueTypeFont ttf) throws IOException | public void process(TrueTypeFont ttf) throws IOException | |||
{ | { | |||
addTrueTypeFontImpl(ttf, ttcFile); | addTrueTypeFontImpl(ttf, ttcFile); | |||
} | } | |||
}); | }); | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Could not load font file: " + ttcFile, e); | LOG.warn("Could not load font file: " + ttcFile, e); | |||
} | } | |||
finally | finally | |||
{ | { | |||
if (ttc != null) | if (ttc != null) | |||
{ | { | |||
ttc.close(); | ttc.close(); | |||
} | } | |||
} | } | |||
} | } | |||
/** | /** | |||
* Adds an OTF or TTF font to the file cache. To reduce memory, the parsed f ont is not cached. | * Adds an OTF or TTF font to the file cache. To reduce memory, the parsed f ont is not cached. | |||
*/ | */ | |||
private void addTrueTypeFont(File ttfFile) throws IOException | private void addTrueTypeFont(File ttfFile) throws IOException | |||
{ | { | |||
try | try | |||
{ | { | |||
if (ttfFile.getPath().endsWith(".otf")) | if (ttfFile.getPath().toLowerCase().endsWith(".otf")) | |||
{ | { | |||
OTFParser parser = new OTFParser(false, true); | OTFParser parser = new OTFParser(false, true); | |||
OpenTypeFont otf = parser.parse(ttfFile); | OpenTypeFont otf = parser.parse(ttfFile); | |||
addTrueTypeFontImpl(otf, ttfFile); | addTrueTypeFontImpl(otf, ttfFile); | |||
} | } | |||
else | else | |||
{ | { | |||
TTFParser parser = new TTFParser(false, true); | TTFParser parser = new TTFParser(false, true); | |||
TrueTypeFont ttf = parser.parse(ttfFile); | TrueTypeFont ttf = parser.parse(ttfFile); | |||
addTrueTypeFontImpl(ttf, ttfFile); | addTrueTypeFontImpl(ttf, ttfFile); | |||
} | } | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Could not load font file: " + ttfFile, e); | LOG.warn("Could not load font file: " + ttfFile, e); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Adds an OTF or TTF font to the file cache. To reduce memory, the parsed f ont is not cached. | * Adds an OTF or TTF font to the file cache. To reduce memory, the parsed f ont is not cached. | |||
*/ | */ | |||
private void addTrueTypeFontImpl(TrueTypeFont ttf, File file) throws IOExcep tion | private void addTrueTypeFontImpl(TrueTypeFont ttf, File file) throws IOExcep tion | |||
{ | { | |||
try | try | |||
{ | { | |||
skipping to change at line 765 | skipping to change at line 765 | |||
} | } | |||
else | else | |||
{ | { | |||
fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipnonam e*")); | fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipnonam e*")); | |||
LOG.warn("Missing 'name' entry for PostScript name in font " + f ile); | LOG.warn("Missing 'name' entry for PostScript name in font " + f ile); | |||
} | } | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipexception *")); | fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipexception *")); | |||
LOG.error("Could not load font file: " + file, e); | LOG.warn("Could not load font file: " + file, e); | |||
} | } | |||
finally | finally | |||
{ | { | |||
ttf.close(); | ttf.close(); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Adds a Type 1 font to the file cache. To reduce memory, the parsed font i s not cached. | * Adds a Type 1 font to the file cache. To reduce memory, the parsed font i s not cached. | |||
*/ | */ | |||
private void addType1Font(File pfbFile) throws IOException | private void addType1Font(File pfbFile) throws IOException | |||
{ | { | |||
InputStream input = new FileInputStream(pfbFile); | InputStream input = new FileInputStream(pfbFile); | |||
try | try | |||
{ | { | |||
Type1Font type1 = Type1Font.createWithPFB(input); | Type1Font type1 = Type1Font.createWithPFB(input); | |||
if (type1.getName() != null && type1.getName().contains("|")) | if (type1.getName() == null) | |||
{ | ||||
fontInfoList.add(new FSIgnored(pfbFile, FontFormat.PFB, "*skipno | ||||
name*")); | ||||
LOG.warn("Missing 'name' entry for PostScript name in font " + p | ||||
fbFile); | ||||
return; | ||||
} | ||||
if (type1.getName().contains("|")) | ||||
{ | { | |||
fontInfoList.add(new FSIgnored(pfbFile, FontFormat.PFB, "*skippi peinname*")); | fontInfoList.add(new FSIgnored(pfbFile, FontFormat.PFB, "*skippi peinname*")); | |||
LOG.warn("Skipping font with '|' in name " + type1.getName() + " in file " + pfbFile); | LOG.warn("Skipping font with '|' in name " + type1.getName() + " in file " + pfbFile); | |||
return; | return; | |||
} | } | |||
fontInfoList.add(new FSFontInfo(pfbFile, FontFormat.PFB, type1.getNa me(), | fontInfoList.add(new FSFontInfo(pfbFile, FontFormat.PFB, type1.getNa me(), | |||
null, -1, -1, 0, 0, -1, null, this)) ; | null, -1, -1, 0, 0, -1, null, this)) ; | |||
if (LOG.isTraceEnabled()) | if (LOG.isTraceEnabled()) | |||
{ | { | |||
LOG.trace("PFB: '" + type1.getName() + "' / '" + type1.getFamily Name() + "' / '" + | LOG.trace("PFB: '" + type1.getName() + "' / '" + type1.getFamily Name() + "' / '" + | |||
type1.getWeight() + "'"); | type1.getWeight() + "'"); | |||
} | } | |||
} | } | |||
catch (IOException e) | catch (IOException e) | |||
{ | { | |||
LOG.error("Could not load font file: " + pfbFile, e); | LOG.warn("Could not load font file: " + pfbFile, e); | |||
} | } | |||
finally | finally | |||
{ | { | |||
input.close(); | input.close(); | |||
} | } | |||
} | } | |||
@Override | @Override | |||
public String toDebugString() | public String toDebugString() | |||
{ | { | |||
End of changes. 14 change blocks. | ||||
14 lines changed or deleted | 22 lines changed or added |