pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1619957 - in /pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight: content/ font/ font/container/ font/descriptor/ font/util/ process/reflect/
Date Sat, 23 Aug 2014 02:36:06 GMT
Author: jahewson
Date: Sat Aug 23 02:36:05 2014
New Revision: 1619957

URL: http://svn.apache.org/r1619957
Log:
PDFBOX-2262/PDFBOX-2149: Refactor CMaps and Encodings (Preflight)

 These changes allow preflight to work with the changes from the commit 1619956

Added:
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/FontLike.java
Modified:
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType0FontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType2FontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/DescendantFontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/FontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/SimpleFontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/TrueTypeFontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType0Container.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
Sat Aug 23 02:36:05 2014
@@ -26,7 +26,9 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_CONTENT_STREAM_INVALID_ARGUMENT;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_CONTENT_STREAM_UNSUPPORTED_OP;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
 
 import org.apache.pdfbox.cos.COSArray;
@@ -344,23 +346,13 @@ public class PreflightContentStream exte
             return;
         }
 
-        int codeLength = 1;
-        for (int i = 0; i < string.length; i += codeLength)
+        InputStream in = new ByteArrayInputStream(string);
+        while (in.available() > 0)
         {
-            // explore the string to detect character code (length can be 1 or 2 bytes)
-            int cid = -1;
-            codeLength = 1;
             try
             {
-                // according to the encoding, extract the character identifier
-                cid = font.encodeToCID(string, i, codeLength);
-                if (cid == -1 && i + 1 < string.length)
-                {
-                    // maybe a multibyte encoding
-                    codeLength++;
-                    cid = font.encodeToCID(string, i, codeLength);
-                }
-                fontContainer.checkGlyphWidth(cid);
+                int code = font.readCode(in);
+                fontContainer.checkGlyphWidth(code);
             }
             catch (IOException e)
             {

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType0FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType0FontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType0FontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType0FontValidator.java
Sat Aug 23 02:36:05 2014
@@ -22,7 +22,7 @@
 package org.apache.pdfbox.preflight.font;
 
 import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.font.container.CIDType0Container;
 import org.apache.pdfbox.preflight.font.descriptor.CIDType0DescriptorHelper;
@@ -30,7 +30,7 @@ import org.apache.pdfbox.preflight.font.
 public class CIDType0FontValidator extends DescendantFontValidator<CIDType0Container>
 {
 
-    public CIDType0FontValidator(PreflightContext context, PDFont font)
+    public CIDType0FontValidator(PreflightContext context, PDCIDFontType0 font)
     {
         super(context, font, new CIDType0Container(font));
     }

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType2FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType2FontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType2FontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/CIDType2FontValidator.java
Sat Aug 23 02:36:05 2014
@@ -22,7 +22,7 @@
 package org.apache.pdfbox.preflight.font;
 
 import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.font.container.CIDType2Container;
 import org.apache.pdfbox.preflight.font.descriptor.CIDType2DescriptorHelper;
@@ -31,7 +31,7 @@ import org.apache.pdfbox.preflight.font.
 public class CIDType2FontValidator extends DescendantFontValidator<CIDType2Container>
 {
 
-    public CIDType2FontValidator(PreflightContext context, PDFont font)
+    public CIDType2FontValidator(PreflightContext context, PDCIDFontType2 font)
     {
         super(context, font, new CIDType2Container(font));
     }

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/DescendantFontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/DescendantFontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/DescendantFontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/DescendantFontValidator.java
Sat Aug 23 02:36:05 2014
@@ -33,7 +33,7 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDCIDFont;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.font.container.FontContainer;
@@ -42,20 +42,17 @@ import org.apache.pdfbox.preflight.utils
 
 public abstract class DescendantFontValidator<T extends FontContainer> extends SimpleFontValidator<T>
 {
-
     protected COSDocument cosDocument = null;
 
-    public DescendantFontValidator(PreflightContext context, PDFont font, T fContainer)
+    public DescendantFontValidator(PreflightContext context, PDCIDFont font, T fContainer)
     {
-        super(context, font, fContainer);
+        super(context, font.getCOSObject(), fContainer);
         cosDocument = context.getDocument().getDocument();
     }
 
     @Override
     protected void checkMandatoryField()
     {
-        COSDictionary fontDictionary = (COSDictionary) font.getCOSObject();
-
         boolean arePresent = fontDictionary.containsKey(COSName.TYPE);
         arePresent &= fontDictionary.containsKey(COSName.SUBTYPE);
         arePresent &= fontDictionary.containsKey(COSName.BASE_FONT);

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/FontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/FontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/FontValidator.java
Sat Aug 23 02:36:05 2014
@@ -21,7 +21,7 @@
 
 package org.apache.pdfbox.preflight.font;
 
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.font.container.FontContainer;
@@ -29,21 +29,18 @@ import org.apache.pdfbox.preflight.font.
 
 public abstract class FontValidator<T extends FontContainer>
 {
-
     protected T fontContainer;
     protected PreflightContext context;
-    protected PDFont font;
     protected FontDescriptorHelper<T> descriptorHelper;
 
     private static final String SUB_SET_PATTERN = "^[A-Z]{6}\\+.*";
 
-    public FontValidator(PreflightContext context, PDFont font, T fContainer)
+    public FontValidator(PreflightContext context, COSDictionary dict, T fContainer)
     {
         super();
         this.context = context;
-        this.font = font;
         this.fontContainer = fContainer;
-        this.context.addFontContainer(font.getCOSObject(), fContainer);
+        this.context.addFontContainer(dict, fContainer);
     }
 
     public static boolean isSubSet(String fontName)

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/SimpleFontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/SimpleFontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/SimpleFontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/SimpleFontValidator.java
Sat Aug 23 02:36:05 2014
@@ -25,7 +25,7 @@ import static org.apache.pdfbox.prefligh
 
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -33,10 +33,19 @@ import org.apache.pdfbox.preflight.font.
 
 public abstract class SimpleFontValidator<T extends FontContainer> extends FontValidator<T>
 {
+    protected PDSimpleFont font;
+    protected COSDictionary fontDictionary;
 
-    public SimpleFontValidator(PreflightContext context, PDFont font, T fContainer)
+    public SimpleFontValidator(PreflightContext context, PDSimpleFont font, T fContainer)
     {
-        super(context, font, fContainer);
+        super(context, font.getCOSObject(), fContainer);
+        this.fontDictionary = font.getCOSObject();
+    }
+
+    public SimpleFontValidator(PreflightContext context, COSDictionary fontDictionary, T
fContainer)
+    {
+        super(context, fontDictionary, fContainer);
+        this.fontDictionary = fontDictionary;
     }
 
     /**
@@ -60,7 +69,6 @@ public abstract class SimpleFontValidato
 
     protected void checkMandatoryField()
     {
-        COSDictionary fontDictionary = (COSDictionary) font.getCOSObject();
         boolean areFieldsPResent = fontDictionary.containsKey(COSName.TYPE);
         areFieldsPResent &= fontDictionary.containsKey(COSName.SUBTYPE);
         areFieldsPResent &= fontDictionary.containsKey(COSName.BASE_FONT);

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/TrueTypeFontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/TrueTypeFontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/TrueTypeFontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/TrueTypeFontValidator.java
Sat Aug 23 02:36:05 2014
@@ -28,8 +28,8 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.encoding.MacRomanEncoding;
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
-import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
+import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.font.container.TrueTypeContainer;
@@ -37,8 +37,7 @@ import org.apache.pdfbox.preflight.font.
 
 public class TrueTypeFontValidator extends SimpleFontValidator<TrueTypeContainer>
 {
-
-    public TrueTypeFontValidator(PreflightContext context, PDFont font)
+    public TrueTypeFontValidator(PreflightContext context, PDTrueTypeFont font)
     {
         super(context, font, new TrueTypeContainer(font));
     }
@@ -58,7 +57,7 @@ public class TrueTypeFontValidator exten
              */
             if (fd.isNonSymbolic())
             {
-                Encoding encodingValue = this.font.getFontEncoding();
+                Encoding encodingValue = this.font.getEncoding();
                 if (encodingValue == null
                         || !(encodingValue instanceof MacRomanEncoding || encodingValue instanceof
WinAnsiEncoding))
                 {

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
Sat Aug 23 02:36:05 2014
@@ -60,12 +60,12 @@ import org.apache.pdfbox.preflight.utils
 
 public class Type0FontValidator extends FontValidator<Type0Container>
 {
-
+    protected PDFont font;
     protected COSDocument cosDocument = null;
 
     public Type0FontValidator(PreflightContext context, PDFont font)
     {
-        super(context, font, new Type0Container(font));
+        super(context, font.getCOSObject(), new Type0Container(font));
         cosDocument = this.context.getDocument().getDocument();
     }
 

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java
Sat Aug 23 02:36:05 2014
@@ -32,7 +32,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.font.container.Type1Container;
@@ -42,7 +42,7 @@ import org.apache.pdfbox.preflight.utils
 public class Type1FontValidator extends SimpleFontValidator<Type1Container>
 {
 
-    public Type1FontValidator(PreflightContext context, PDFont font)
+    public Type1FontValidator(PreflightContext context, PDSimpleFont font)
     {
         super(context, font, new Type1Container(font));
     }

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java
Sat Aug 23 02:36:05 2014
@@ -28,6 +28,7 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_TYPE3_DAMAGED;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -41,9 +42,11 @@ import org.apache.pdfbox.encoding.Dictio
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDFontFactory;
+import org.apache.pdfbox.pdmodel.font.PDType3Font;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
@@ -59,15 +62,17 @@ import org.apache.pdfbox.preflight.utils
 
 public class Type3FontValidator extends FontValidator<Type3Container>
 {
+    protected PDFont font;
     protected COSDictionary fontDictionary;
     protected COSDocument cosDocument;
     protected Encoding encoding;
 
-    public Type3FontValidator(PreflightContext context, PDFont font)
+    public Type3FontValidator(PreflightContext context, PDType3Font font)
     {
-        super(context, font, new Type3Container(font));
+        super(context, font.getCOSObject(), new Type3Container(font));
         this.cosDocument = context.getDocument().getDocument();
-        this.fontDictionary = (COSDictionary) font.getCOSObject();
+        this.fontDictionary = font.getCOSObject();
+        this.font = font;
     }
 
     public void validate() throws ValidationException
@@ -224,22 +229,13 @@ public class Type3FontValidator extends 
     {
         // Encoding is a Name, check if it is an Existing Encoding
         String enc = COSUtils.getAsString(fontEncoding, cosDocument);
-        try
-        {
-            this.encoding = Encoding.getInstance(COSName.getPDFName(enc));
-        }
-        catch (IOException e)
-        {
-            // the encoding doesn't exist
-            this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING));
-            return;
-        }
+        this.encoding = Encoding.getInstance(COSName.getPDFName(enc));
     }
 
     /**
      * This method is called by the CheckEncoding method if the Encoding entry is an instance
of COSDictionary. In this
      * case, a new instance of {@link DictionaryEncoding} is created. If an IOException is
thrown by the
-     * DictionaryEncoding constructor the {@link PreflightConstants.ERROR_FONTS_ENCODING}
is pushed in the
+     * DictionaryEncoding constructor the ERROR_FONTS_ENCODING is pushed in the
      * FontContainer.
      * 
      * Differences entry validation is implicitly done by the DictionaryEncoding constructor.
@@ -249,16 +245,7 @@ public class Type3FontValidator extends 
     private void checkEncodingAsDictionary(COSBase fontEncoding)
     {
         COSDictionary encodingDictionary = COSUtils.getAsDictionary(fontEncoding, cosDocument);
-        try
-        {
-            this.encoding = new DictionaryEncoding(encodingDictionary);
-        }
-        catch (IOException e)
-        {
-            // the encoding doesn't exist
-            this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING));
-            return;
-        }
+        this.encoding = new DictionaryEncoding(encodingDictionary);
     }
 
     /**
@@ -269,13 +256,10 @@ public class Type3FontValidator extends 
      * the CharProcs doesn't know the Character, it is mapped with the .notdef one.
      * 
      * For each character, the Glyph width must be the same as the Width value declared in
the Widths array.
-     * 
-     * @param errors
-     * @return
      */
     private void checkCharProcsAndMetrics() throws ValidationException
     {
-        List<Integer> widths = font.getWidths();
+        List<Integer> widths = getWidths(font);
         if (widths == null || widths.isEmpty())
         {
             this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
@@ -291,8 +275,8 @@ public class Type3FontValidator extends 
             return;
         }
 
-        int fc = this.font.getFirstChar();
-        int lc = this.font.getLastChar();
+        int fc = font.getCOSObject().getInt(COSName.FIRST_CHAR, -1);
+        int lc = font.getCOSObject().getInt(COSName.LAST_CHAR, -1);
 
         /*
          * wArr length = (lc - fc) + 1 and it is an array of int. 
@@ -353,6 +337,21 @@ public class Type3FontValidator extends 
         }
     }
 
+    public List<Integer> getWidths(PDFont font)
+    {
+        List<Integer> widths;
+        COSArray array = (COSArray) font.getCOSObject().getDictionaryObject(COSName.WIDTHS);
+        if (array != null)
+        {
+            widths = COSArrayList.convertIntegerCOSArrayToList(array);
+        }
+        else
+        {
+            widths = Collections.emptyList();
+        }
+        return widths;
+    }
+
     private PDResources getPDResources()
     {
         COSBase res = this.fontDictionary.getItem(COSName.RESOURCES);

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType0Container.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType0Container.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType0Container.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType0Container.java
Sat Aug 23 02:36:05 2014
@@ -27,15 +27,16 @@ import java.util.List;
 
 import org.apache.fontbox.cff.CFFCIDFont;
 import org.apache.fontbox.cff.CFFFont;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
+import org.apache.pdfbox.preflight.font.util.FontLike;
 
 public class CIDType0Container extends FontContainer
 {
     protected List<CFFFont> lCFonts = new ArrayList<CFFFont>();
 
-    public CIDType0Container(PDFont font)
+    public CIDType0Container(PDCIDFontType0 font)
     {
-        super(font);
+        super(new FontLike(font));
     }
 
     @Override

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java
Sat Aug 23 02:36:05 2014
@@ -22,23 +22,22 @@
 package org.apache.pdfbox.preflight.font.container;
 
 import org.apache.fontbox.ttf.TrueTypeFont;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.font.util.CIDToGIDMap;
+import org.apache.pdfbox.preflight.font.util.FontLike;
 import org.apache.pdfbox.preflight.font.util.GlyphException;
 
 import java.io.IOException;
 
 public class CIDType2Container extends FontContainer
 {
-
     protected CIDToGIDMap cidToGid = null;
-
     protected TrueTypeFont ttf = null;
 
-    public CIDType2Container(PDFont font)
+    public CIDType2Container(PDCIDFontType2 font)
     {
-        super(font);
+        super(new FontLike(font));
     }
 
     @Override

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
Sat Aug 23 02:36:05 2014
@@ -30,6 +30,7 @@ import java.util.Map;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.preflight.font.util.FontLike;
 import org.apache.pdfbox.preflight.font.util.GlyphDetail;
 import org.apache.pdfbox.preflight.font.util.GlyphException;
 
@@ -52,11 +53,15 @@ public abstract class FontContainer
 
     protected boolean errorsAleadyMerged = false;
 
-    protected PDFont font;
+    protected FontLike font;
 
     public FontContainer(PDFont font)
     {
-        super();
+        this.font = new FontLike(font);
+    }
+
+    public FontContainer(FontLike font)
+    {
         this.font = font;
     }
 
@@ -102,7 +107,7 @@ public abstract class FontContainer
 
     /**
      * 
-     * @param cid
+     * @param cid todo: not a CID, this is actually a char code!
      * @throws GlyphException
      */
     public void checkGlyphWidth(int cid) throws GlyphException
@@ -113,7 +118,7 @@ public abstract class FontContainer
         }
         try
         {
-            final float expectedWidth = this.font.getFontWidth(cid);
+            final float expectedWidth = this.font.getWidth(cid);
             final float foundWidth = getFontProgramWidth(cid);
             checkWidthsConsistency(cid, expectedWidth, foundWidth);
         }

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java
Sat Aug 23 02:36:05 2014
@@ -29,20 +29,20 @@ import org.apache.fontbox.ttf.CMAPEncodi
 import org.apache.fontbox.ttf.CMAPTable;
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.pdfbox.encoding.Encoding;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.font.util.GlyphException;
 
 public class TrueTypeContainer extends FontContainer
 {
-
     protected TrueTypeFont ttFont;
-
     private CMAPEncodingEntry[] cmapEncodingEntries = null;
+    private PDTrueTypeFont trueTypeFont;
 
-    public TrueTypeContainer(PDFont font)
+    public TrueTypeContainer(PDTrueTypeFont font)
     {
         super(font);
+        this.trueTypeFont = font;
     }
 
     public void setTrueTypeFont(TrueTypeFont ttFont)
@@ -70,7 +70,7 @@ public class TrueTypeContainer extends F
         try
         {
             CMAPTable cmap = this.ttFont.getCMAP();
-            if (this.font.getFontDescriptor().isSymbolic())
+            if (this.trueTypeFont.getFontDescriptor().isSymbolic())
             {
                 this.cmapEncodingEntries = cmap.getCmaps();
             }
@@ -160,7 +160,7 @@ public class TrueTypeContainer extends F
         int innerFontCid = cid;
         if (cmap.getPlatformEncodingId() == 1 && cmap.getPlatformId() == 3)
         {
-            Encoding fontEncoding = this.font.getFontEncoding();
+            Encoding fontEncoding = this.trueTypeFont.getEncoding();
             String character = fontEncoding.getCharacter(cid);
             if (character == null)
             {

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/Type1Container.java
Sat Aug 23 02:36:05 2014
@@ -26,7 +26,7 @@ import java.util.List;
 
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFType1Font;
-import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.font.util.GlyphException;
 import org.apache.pdfbox.preflight.font.util.Type1;
@@ -47,9 +47,12 @@ public class Type1Container extends Font
     protected Type1 type1Font;
     protected List<CFFFont> lCFonts;
 
-    public Type1Container(PDFont font)
+    private PDSimpleFont simpleFont;
+
+    public Type1Container(PDSimpleFont font)
     {
         super(font);
+        this.simpleFont = font;
     }
 
     @Override
@@ -72,7 +75,7 @@ public class Type1Container extends Font
             else
             {
                 // assuming that "cid" is actually the character code
-                String name = this.font.getFontEncoding().getName(cid);
+                String name = simpleFont.getEncoding().getName(cid);
                 if (name.equals(".notdef"))
                 {
                     throw new GlyphException(PreflightConstants.ERROR_FONTS_GLYPH_MISSING,
cid, "Unknown character CID(" + cid+")");

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java
Sat Aug 23 02:36:05 2014
@@ -44,6 +44,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDFontDescriptorDictionary;
+import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -151,7 +152,7 @@ public class Type1DescriptorHelper exten
             int length2 = streamObj.getInt(COSName.LENGTH2);
             bis = new ByteArrayInputStream(fontFile.getByteArray());
             Type1Parser parserForMetrics = Type1Parser.createParserWithEncodingObject(bis,
length1, length2,
-                    font.getFontEncoding());
+                    ((PDSimpleFont) font).getEncoding());
             Type1 parsedData = parserForMetrics.parse();
 
             this.fContainer.setType1Font(parsedData);
@@ -173,8 +174,7 @@ public class Type1DescriptorHelper exten
 
     /**
      * Type1C is a CFF font format, extract all CFFFont object from the stream
-     * 
-     * @param fontStream
+     *
      * @return
      * @throws ValidationException
      */

Added: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/FontLike.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/FontLike.java?rev=1619957&view=auto
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/FontLike.java
(added)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/FontLike.java
Sat Aug 23 02:36:05 2014
@@ -0,0 +1,88 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.font.util;
+
+import org.apache.pdfbox.pdmodel.font.PDCIDFont;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+
+import java.io.IOException;
+
+/**
+ * Wrapper over font-like objects.
+ */
+public class FontLike
+{
+    private PDFont font;
+    private PDCIDFont cidFont;
+
+    /**
+     * Constructor.
+     *
+     * @param font A font.
+     */
+    public FontLike(PDFont font)
+    {
+        this.font = font;
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param cidFont A CIDFont, this is not actually a font.
+     */
+    public FontLike(PDCIDFont cidFont)
+    {
+        this.cidFont = cidFont;
+    }
+
+    /**
+     * The PostScript name of the font.
+     */
+    public String getBaseFont()
+    {
+        if (font != null)
+        {
+            return font.getBaseFont();
+        }
+        else
+        {
+            return cidFont.getBaseFont();
+        }
+    }
+
+    /**
+     * Returns the width of the given character.
+     *
+     * @param code character code
+     */
+    public float getWidth(int code) throws IOException
+    {
+        if (font != null)
+        {
+            return font.getWidth(code);
+        }
+        else
+        {
+            return cidFont.getWidth(code);
+        }
+    }
+}

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java?rev=1619957&r1=1619956&r2=1619957&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
(original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/FontValidationProcess.java
Sat Aug 23 02:36:05 2014
@@ -32,6 +32,9 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_TYPE3;
 
 import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
+import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
+import org.apache.pdfbox.pdmodel.font.PDType3Font;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
@@ -82,15 +85,15 @@ public class FontValidationProcess exten
         String subtype = font.getSubType();
         if (FONT_DICTIONARY_VALUE_TRUETYPE.equals(subtype))
         {
-            return new TrueTypeFontValidator(context, font);
+            return new TrueTypeFontValidator(context, (PDTrueTypeFont)font);
         }
         else if (FONT_DICTIONARY_VALUE_MMTYPE.equals(subtype) || FONT_DICTIONARY_VALUE_TYPE1.equals(subtype))
         {
-            return new Type1FontValidator(context, font);
+            return new Type1FontValidator(context, (PDSimpleFont)font);
         }
         else if (FONT_DICTIONARY_VALUE_TYPE3.equals(subtype))
         {
-            return new Type3FontValidator(context, font);
+            return new Type3FontValidator(context, (PDType3Font)font);
         }
         else if (FONT_DICTIONARY_VALUE_COMPOSITE.equals(subtype))
         {



Mime
View raw message