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

svn commit: r1897394 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java

Author: lehmi
Date: Mon Jan 24 06:23:25 2022
New Revision: 1897394

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

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1897394&r1=1897393&r2=1897394&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Mon Jan 24 06:23:25 2022
@@ -129,8 +129,8 @@ public class PDType3Font extends PDSimpl
     @Override
     public boolean hasGlyph(String name) throws IOException
     {
-        COSBase base = getCharProcs().getDictionaryObject(COSName.getPDFName(name));
-        return base instanceof COSStream;
+        return getCharProcs() == null ? false
+                : getCharProcs().getCOSStream(COSName.getPDFName(name)) != null;
     }
 
     @Override
@@ -336,27 +336,34 @@ 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)
             {
-                COSBase base = cp.getDictionaryObject(name);
-                if (base instanceof COSStream)
+                for (COSName name : cp.keySet())
                 {
-                    PDType3CharProc charProc = new PDType3CharProc(this, (COSStream) base);
-                    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
                         }
-                        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
                     }
                 }
             }
@@ -387,20 +394,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;
     }
 }