pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leleu...@apache.org
Subject svn commit: r1435867 - in /pdfbox/trunk: preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java
Date Sun, 20 Jan 2013 15:54:29 GMT
Author: leleueri
Date: Sun Jan 20 15:54:29 2013
New Revision: 1435867

URL: http://svn.apache.org/viewvc?rev=1435867&view=rev
Log:
[PDFBOX-1484] Avoid NumberFormatException if the CharString doesn't have the right number
of elements + Fix an issue on XMPBox

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java?rev=1435867&r1=1435866&r2=1435867&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/Type1Parser.java
Sun Jan 20 15:54:29 2013
@@ -37,6 +37,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.cff.IndexData;
 import org.apache.fontbox.cff.Type1CharStringParser;
 import org.apache.fontbox.cff.Type1FontUtil;
+import org.apache.log4j.Logger;
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.encoding.MacRomanEncoding;
 import org.apache.pdfbox.encoding.PdfDocEncoding;
@@ -44,6 +45,9 @@ import org.apache.pdfbox.encoding.Standa
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
 
 public final class Type1Parser {
+
+	public static final Logger LOGGER = Logger.getLogger(Type1Parser.class);
+	
 	protected static final char NAME_START = '/';
 	protected static final String NOTDEF = NAME_START + ".notdef";
 	protected static final int DEFAULT_LEN_IV = 4;
@@ -256,7 +260,30 @@ public final class Type1Parser {
 		goToBeginOfCharStringElements(stream);
 		
 		while (numberOfElements > 0) {
-			readCharStringElement(stream, lenIV);
+			byte[] labelToken = readToken(stream);
+			String label = new String(labelToken, TOKEN_ENCODING);
+ 
+			if (label.equals("end")){
+				// TODO thrown exception ? add an error/warning in the PreflightContext ??	
+				LOGGER.warn("[Type 1] Invalid number of elements in the CharString");
+				break;
+			}
+			
+			byte[] sizeOfCharStringToken = readToken(stream);
+			int sizeOfCharString = Integer.parseInt(new String(sizeOfCharStringToken,TOKEN_ENCODING));
+
+			readToken(stream); // skip "RD" or "-|" token
+			skipSingleBlankSeparator(stream); // "RD" or "-|" are followed by a space
+
+			byte[] descBinary = new byte[sizeOfCharString];
+			stream.read(descBinary, 0, sizeOfCharString);
+			byte[] description = Type1FontUtil.charstringDecrypt(descBinary, lenIV);
+			Type1CharStringParser t1p = new Type1CharStringParser();
+			// TODO provide the local subroutine indexes
+			List<Object> operations = t1p.parse(description, new IndexData(0));
+			type1Font.addGlyphDescription(label, new GlyphDescription(operations));
+
+			readToken(stream); // skip "ND" or "|-" token
 			--numberOfElements;
 		}
 	}
@@ -267,27 +294,6 @@ public final class Type1Parser {
 			token = readToken(stream);
 		} while(isNotBeginKeyWord(token));
 	}
-
-	private void readCharStringElement(PeekInputStream stream, int lenIV) throws IOException
{
-		byte[] labelToken = readToken(stream);
-		String label = new String(labelToken, TOKEN_ENCODING);
-
-		byte[] sizeOfCharStringToken = readToken(stream);
-		int sizeOfCharString = Integer.parseInt(new String(sizeOfCharStringToken,TOKEN_ENCODING));
-
-		readToken(stream); // skip "RD" or "-|" token
-		skipSingleBlankSeparator(stream); // "RD" or "-|" are followed by a space
-
-		byte[] descBinary = new byte[sizeOfCharString];
-		stream.read(descBinary, 0, sizeOfCharString);
-		byte[] description = Type1FontUtil.charstringDecrypt(descBinary, lenIV);
-		Type1CharStringParser t1p = new Type1CharStringParser();
-		// TODO provide the local subroutine indexes
-		List<Object> operations = t1p.parse(description, new IndexData(0));
-		type1Font.addGlyphDescription(label, new GlyphDescription(operations));
-
-		readToken(stream); // skip "ND" or "|-" token
-	}
 	
 	private boolean isNotBeginKeyWord(byte[] token) throws IOException {
 		String word = new String(token, TOKEN_ENCODING);

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java?rev=1435867&r1=1435866&r2=1435867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java Sun Jan
20 15:54:29 2013
@@ -184,10 +184,7 @@ public class DomXmpParser {
 				if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix())) {
 					// do nothing
 				} else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix()) && XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
{
-//					// do nothing
-//					if (schema instanceof XMPSchema) {
-//						((XMPSchema)sp).setAboutAsSimple(attr.getValue());
-//					}
+					// do nothing
 				} else if (attr.getPrefix()==null && XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
{
 					// do nothing
 				} else {
@@ -198,12 +195,13 @@ public class DomXmpParser {
 						loadAttributes(schema, description);
 					}
 					ComplexPropertyContainer container = schema.getContainer();
+					PropertyType type = checkPropertyDefinition(xmp, new QName(attr.getNamespaceURI(), attr.getLocalName()));
 					AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
 							namespace, 
 							schema.getPrefix(), 
 							attr.getLocalName(), 
 							attr.getValue(),
-							Types.Text);
+							type.type());
 					container.addProperty(sp);
 				}
 				



Mime
View raw message