You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/06/28 03:54:22 UTC
svn commit: r1862255 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
Author: tilman
Date: Fri Jun 28 03:54:22 2019
New Revision: 1862255
URL: http://svn.apache.org/viewvc?rev=1862255&view=rev
Log:
PDFBOX-4071: Sonar fix: move private methods into the classes where they are used
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java?rev=1862255&r1=1862254&r2=1862255&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java Fri Jun 28 03:54:22 2019
@@ -128,9 +128,9 @@ final class FileSystemFontProvider exten
FontBoxFont font;
switch (format)
{
- case PFB: font = parent.getType1Font(postScriptName, file); break;
- case TTF: font = parent.getTrueTypeFont(postScriptName, file); break;
- case OTF: font = parent.getOTFFont(postScriptName, file); break;
+ case PFB: font = getType1Font(postScriptName, file); break;
+ case TTF: font = getTrueTypeFont(postScriptName, file); break;
+ case OTF: font = getOTFFont(postScriptName, file); break;
default: throw new RuntimeException("can't happen");
}
if (font != null)
@@ -182,6 +182,95 @@ final class FileSystemFontProvider exten
{
return super.toString() + " " + file;
}
+
+ private TrueTypeFont getTrueTypeFont(String postScriptName, File file)
+ {
+ try
+ {
+ TrueTypeFont ttf = readTrueTypeFont(postScriptName, file);
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Loaded " + postScriptName + " from " + file);
+ }
+ return ttf;
+ }
+ catch (NullPointerException e) // TTF parser is buggy
+ {
+ LOG.error("Could not load font file: " + file, e);
+ }
+ catch (IOException e)
+ {
+ LOG.error("Could not load font file: " + file, e);
+ }
+ return null;
+ }
+
+ private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException
+ {
+ if (file.getName().toLowerCase().endsWith(".ttc"))
+ {
+ TrueTypeCollection ttc = new TrueTypeCollection(file);
+ TrueTypeFont ttf = ttc.getFontByName(postScriptName);
+ if (ttf == null)
+ {
+ ttc.close();
+ throw new IOException("Font " + postScriptName + " not found in " + file);
+ }
+ return ttf;
+ }
+ else
+ {
+ TTFParser ttfParser = new TTFParser(false, true);
+ return ttfParser.parse(file);
+ }
+ }
+
+ private OpenTypeFont getOTFFont(String postScriptName, File file)
+ {
+ try
+ {
+ // todo JH: we don't yet support loading CFF fonts from OTC collectionsâ¨
+ OTFParser parser = new OTFParser(false, true);
+ OpenTypeFont otf = parser.parse(file);
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Loaded " + postScriptName + " from " + file);
+ }
+ return otf;
+ }
+ catch (IOException e)
+ {
+ LOG.error("Could not load font file: " + file, e);
+ }
+ return null;
+ }
+
+ private Type1Font getType1Font(String postScriptName, File file)
+ {
+ InputStream input = null;
+ try
+ {
+ input = new FileInputStream(file);
+ Type1Font type1 = Type1Font.createWithPFB(input);
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Loaded " + postScriptName + " from " + file);
+ }
+ return type1;
+ }
+ catch (IOException e)
+ {
+ LOG.error("Could not load font file: " + file, e);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(input);
+ }
+ return null;
+ }
}
/**
@@ -689,95 +778,6 @@ final class FileSystemFontProvider exten
}
}
- private TrueTypeFont getTrueTypeFont(String postScriptName, File file)
- {
- try
- {
- TrueTypeFont ttf = readTrueTypeFont(postScriptName, file);
-
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Loaded " + postScriptName + " from " + file);
- }
- return ttf;
- }
- catch (NullPointerException e) // TTF parser is buggy
- {
- LOG.error("Could not load font file: " + file, e);
- }
- catch (IOException e)
- {
- LOG.error("Could not load font file: " + file, e);
- }
- return null;
- }
-
- private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException
- {
- if (file.getName().toLowerCase().endsWith(".ttc"))
- {
- TrueTypeCollection ttc = new TrueTypeCollection(file);
- TrueTypeFont ttf = ttc.getFontByName(postScriptName);
- if (ttf == null)
- {
- ttc.close();
- throw new IOException("Font " + postScriptName + " not found in " + file);
- }
- return ttf;
- }
- else
- {
- TTFParser ttfParser = new TTFParser(false, true);
- return ttfParser.parse(file);
- }
- }
-
- private OpenTypeFont getOTFFont(String postScriptName, File file)
- {
- try
- {
- // todo JH: we don't yet support loading CFF fonts from OTC collectionsâ¨
- OTFParser parser = new OTFParser(false, true);
- OpenTypeFont otf = parser.parse(file);
-
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Loaded " + postScriptName + " from " + file);
- }
- return otf;
- }
- catch (IOException e)
- {
- LOG.error("Could not load font file: " + file, e);
- }
- return null;
- }
-
- private Type1Font getType1Font(String postScriptName, File file)
- {
- InputStream input = null;
- try
- {
- input = new FileInputStream(file);
- Type1Font type1 = Type1Font.createWithPFB(input);
-
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Loaded " + postScriptName + " from " + file);
- }
- return type1;
- }
- catch (IOException e)
- {
- LOG.error("Could not load font file: " + file, e);
- }
- finally
- {
- IOUtils.closeQuietly(input);
- }
- return null;
- }
-
@Override
public String toDebugString()
{