You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2022/01/24 06:23:38 UTC

svn commit: r1897395 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java

Author: lehmi
Date: Mon Jan 24 06:23:38 2022
New Revision: 1897395

URL: http://svn.apache.org/viewvc?rev=1897395&view=rev
Log:
PDFBOX-5339: avoid NPE, simplify

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1897395&r1=1897394&r2=1897395&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Mon Jan 24 06:23:38 2022
@@ -131,7 +131,8 @@ public class PDType3Font extends PDSimpl
     @Override
     public boolean hasGlyph(String name) throws IOException
     {
-        return getCharProcs().getCOSStream(COSName.getPDFName(name)) != null;
+        return getCharProcs() == null ? false
+                : getCharProcs().getCOSStream(COSName.getPDFName(name)) != null;
     }
 
     @Override
@@ -323,28 +324,37 @@ public class PDType3Font extends PDSimpl
         {
             // Plan B: get the max bounding box of the glyphs
             COSDictionary cp = getCharProcs();
-            for (COSName name : cp.keySet())
+            if (cp != null)
             {
-                COSStream typ3CharProcStream = cp.getCOSStream(name);
-                if (typ3CharProcStream != null)
+                for (COSName name : cp.keySet())
                 {
-                    PDType3CharProc charProc = new PDType3CharProc(this, typ3CharProcStream);
-                    try
+                    COSStream typ3CharProcStream = cp.getCOSStream(name);
+                    if (typ3CharProcStream != null)
                     {
-                        PDRectangle glyphBBox = charProc.getGlyphBBox();
-                        if (glyphBBox == null)
+                        PDType3CharProc charProc = new PDType3CharProc(this, typ3CharProcStream);
+                        try
                         {
-                            continue;
+                            PDRectangle glyphBBox = charProc.getGlyphBBox();
+                            if (glyphBBox == null)
+                            {
+                                continue;
+                            }
+                            rect.setLowerLeftX(
+                                    Math.min(rect.getLowerLeftX(), glyphBBox.getLowerLeftX()));
+                            rect.setLowerLeftY(
+                                    Math.min(rect.getLowerLeftY(), glyphBBox.getLowerLeftY()));
+                            rect.setUpperRightX(
+                                    Math.max(rect.getUpperRightX(), glyphBBox.getUpperRightX()));
+                            rect.setUpperRightY(
+                                    Math.max(rect.getUpperRightY(), glyphBBox.getUpperRightY()));
+                        }
+                        catch (IOException ex)
+                        {
+                            // ignore
+                            LOG.debug(
+                                    "error getting the glyph bounding box - font bounding box will be used",
+                                    ex);
                         }
-                        rect.setLowerLeftX(Math.min(rect.getLowerLeftX(), glyphBBox.getLowerLeftX()));
-                        rect.setLowerLeftY(Math.min(rect.getLowerLeftY(), glyphBBox.getLowerLeftY()));
-                        rect.setUpperRightX(Math.max(rect.getUpperRightX(), glyphBBox.getUpperRightX()));
-                        rect.setUpperRightY(Math.max(rect.getUpperRightY(), glyphBBox.getUpperRightY()));
-                    }
-                    catch (IOException ex)
-                    {
-                        // ignore
-                        LOG.debug("error getting the glyph bounding box - font bounding box will be used", ex);
                     }
                 }
             }
@@ -375,20 +385,12 @@ public class PDType3Font extends PDSimpl
      */
     public PDType3CharProc getCharProc(int code)
     {
-        if (getEncoding() == null)
+        if (getEncoding() == null || getCharProcs() == null)
         {
             return null;
         }
         String name = getEncoding().getName(code);
-        if (getCharProcs() == null)
-        {
-            return null;
-        }
         COSStream stream = getCharProcs().getCOSStream(COSName.getPDFName(name));
-        if (stream != null)
-        {
-            return new PDType3CharProc(this, stream);
-        }
-        return null;
+        return stream != null ? new PDType3CharProc(this, stream) : null;
     }
 }