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 2022/02/25 19:07:21 UTC

svn commit: r1898423 - /pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java

Author: tilman
Date: Fri Feb 25 19:07:21 2022
New Revision: 1898423

URL: http://svn.apache.org/viewvc?rev=1898423&view=rev
Log:
PDFBOX-5380: improve exception messages

Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java?rev=1898423&r1=1898422&r2=1898423&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java Fri Feb 25 19:07:21 2022
@@ -189,60 +189,66 @@ public class TTFParser
             }
         }
         
-        boolean isPostScript = allowCFF() && font.tables.containsKey(CFFTable.TAG);
+        boolean hasCFF = font.tables.containsKey(CFFTable.TAG);
+        boolean isPostScript = allowCFF() && hasCFF;
         
         HeaderTable head = font.getHeader();
         if (head == null)
         {
-            throw new IOException("head is mandatory");
+            throw new IOException("'head' table is mandatory");
         }
 
         HorizontalHeaderTable hh = font.getHorizontalHeader();
         if (hh == null)
         {
-            throw new IOException("hhead is mandatory");
+            throw new IOException("'hhea' table is mandatory");
         }
 
         MaximumProfileTable maxp = font.getMaximumProfile();
         if (maxp == null)
         {
-            throw new IOException("maxp is mandatory");
+            throw new IOException("'maxp' table is mandatory");
         }
 
         PostScriptTable post = font.getPostScript();
         if (post == null && !isEmbedded)
         {
             // in an embedded font this table is optional
-            throw new IOException("post is mandatory");
+            throw new IOException("'post' table is mandatory");
         }
 
         if (!isPostScript)
         {
+            String messageSuffix = "";
+            if (hasCFF)
+            {
+                messageSuffix = "; this an OpenType CFF font, but we expected a TrueType font here";
+            }
             IndexToLocationTable loc = font.getIndexToLocation();
             if (loc == null)
             {
-                throw new IOException("loca is mandatory");
+                throw new IOException("'loca' table is mandatory" + messageSuffix);
             }
 
             if (font.getGlyph() == null)
             {
-                throw new IOException("glyf is mandatory");
+                throw new IOException("'glyf' table is mandatory" + messageSuffix);
             }
         }
 
         if (font.getNaming() == null && !isEmbedded)
         {
-            throw new IOException("name is mandatory");
+            throw new IOException("'name' table is mandatory");
         }
 
         if (font.getHorizontalMetrics() == null)
         {
-            throw new IOException("hmtx is mandatory");
+            throw new IOException("'hmtx' table is mandatory");
         }
         
         if (!isEmbedded && font.getCmap() == null)
         {
-            throw new IOException("cmap is mandatory");
+            throw new IOException("'cmap' table is mandatory");
         }
     }