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:37 UTC

svn commit: r1862258 - /pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java

Author: tilman
Date: Fri Jun 28 03:54:37 2019
New Revision: 1862258

URL: http://svn.apache.org/viewvc?rev=1862258&view=rev
Log:
PDFBOX-4071: Sonar fix: move private methods into the classes where they are used

Modified:
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java?rev=1862258&r1=1862257&r2=1862258&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java (original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java Fri Jun 28 03:54:37 2019
@@ -127,9 +127,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)
@@ -181,6 +181,86 @@ 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 | IOException e)
+            {
+                // NPE due to TTF parser being buggy
+                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)
+        {
+            try (InputStream 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);
+            }
+            return null;
+        }
     }
 
     /**
@@ -664,86 +744,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 | IOException e)
-        {
-            // NPE due to TTF parser being buggy
-            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)
-    {
-        try (InputStream 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);
-        }
-        return null;
-    }
-
     @Override
     public String toDebugString()
     {