Author: leleueri
Date: Sun Jun 2 14:49:47 2013
New Revision: 1488722
URL: http://svn.apache.org/r1488722
Log:
[PDFBox-1617] Fix NullPointer during Type1C font validation
Modified:
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type0Container.java
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
Modified:
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java?rev=1488722&r1=1488721&r2=1488722&view=diff
==============================================================================
---
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
(original)
+++
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
Sun Jun 2 14:49:47 2013
@@ -142,8 +142,9 @@ public abstract class FontContainer
*
* @param cid
* @return The Glyph width in 'em' unit.
+ * @throws GlyphException
*/
- protected abstract float getFontProgramWidth(int cid);
+ protected abstract float getFontProgramWidth(int cid) throws
GlyphException;
/**
* Test if both width are consistent. At the end of this method, the CID
is marked as valid or invalid.
Modified:
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type0Container.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type0Container.java?rev=1488722&r1=1488721&r2=1488722&view=diff
==============================================================================
---
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type0Container.java
(original)
+++
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type0Container.java
Sun Jun 2 14:49:47 2013
@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.preflight.font.util.GlyphException;
public class Type0Container extends FontContainer
{
@@ -37,7 +38,7 @@ public class Type0Container extends Font
}
@Override
- protected float getFontProgramWidth(int cid)
+ protected float getFontProgramWidth(int cid) throws GlyphException
{
float width = 0;
if (this.delegateFontContainer != null)
Modified:
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java?rev=1488722&r1=1488721&r2=1488722&view=diff
==============================================================================
---
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
(original)
+++
pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
Sun Jun 2 14:49:47 2013
@@ -27,6 +27,7 @@ import java.util.List;
import org.apache.fontbox.cff.CFFFont;
import org.apache.fontbox.cff.CFFFont.Mapping;
import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.preflight.PreflightConstants;
import org.apache.pdfbox.preflight.font.util.GlyphException;
import org.apache.pdfbox.preflight.font.util.Type1;
@@ -52,7 +53,7 @@ public class Type1Container extends Font
}
@Override
- protected float getFontProgramWidth(int cid)
+ protected float getFontProgramWidth(int cid) throws GlyphException
{
float widthResult = -1;
try
@@ -67,41 +68,72 @@ public class Type1Container extends Font
else
{
/*
- * Retrieves the SID with the Character Name in the encoding
map Need more PDF with a Type1C subfont to
- * valid this implementation
+ * Retrieves the SID with the Character Name in the encoding
map Need
+ * more PDF with a Type1C subfont to valid this implementation
+ */
+ String name = null;
+ if (this.font.getFontEncoding() != null) {
+ name = this.font.getFontEncoding().getName(cid);
+ }
+
+ int SID = -1;
+
+ /* For each CFF, try to found the SID that correspond to the
CID.
+ * Look up by name if the encoding entry is present in the
PDFont object
+ * otherwise use the internal encoding map of the font.
*/
- String name = this.font.getFontEncoding().getName(cid);
for (CFFFont cff : lCFonts)
{
- int SID = cff.getEncoding().getSID(cid);
- for (Mapping m : cff.getMappings())
- {
- if (m.getName().equals(name))
+ if (name == null) {
+ SID = cff.getEncoding().getSID(cid);
+ } else {
+ SID = getSIDByCharacterName(name, cff);
+ }
+
+ if (SID > 0) {
+ widthResult = cff.getWidth(SID);
+ if (widthResult != defaultGlyphWidth)
{
- SID = m.getSID();
break;
}
}
- widthResult = cff.getWidth(SID);
- if (widthResult != defaultGlyphWidth)
- {
- break;
- }
+ }
+
+ if (SID < 0)
+ {
+ throw new
GlyphException(PreflightConstants.ERROR_FONTS_GLYPH_MISSING, cid, "Unknown
character CID(" + cid+")");
}
}
}
- catch (GlyphException e)
- {
- widthResult = -1;
- }
catch (IOException e)
{
- widthResult = -1; // TODO validation exception
+ throw new GlyphException(PreflightConstants.ERROR_FONTS_GLYPH,
cid, "Unexpected error during the width validtion for the character CID(" +
cid+") : " + e.getMessage());
}
return widthResult;
}
+ /**
+ * Return the SID of the given character name.
+ *
+ * @param name the character name looked up
+ * @param cff Compact Font Format that represents a sub set of the Type1C
Font.
+ * @return -1 if the name is missing from the Font encoding map, the SID
of the character if it is present in the CFF.
+ */
+ private int getSIDByCharacterName(String name, CFFFont cff)
+ {
+ int SID = -1;
+ for (Mapping m : cff.getMappings())
+ {
+ if (m.getName().equals(name))
+ {
+ SID = m.getSID();
+ break;
+ }
+ }
+ return SID;
+ }
+
public void setType1Font(Type1 type1Font)
{
this.type1Font = type1Font;