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 2012/01/29 10:32:03 UTC
svn commit: r1237228 - in /pdfbox/trunk:
preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java
xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java
Author: leleueri
Date: Sun Jan 29 09:32:03 2012
New Revision: 1237228
URL: http://svn.apache.org/viewvc?rev=1237228&view=rev
Log:
https://issues.apache.org/jira/browse/PDFBOX-1204 :
- check the rendering mode when a glyph is missing or when a glyph width is inconsistent.
- fix an issue about date in the XMP metadata
Modified:
pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java
pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java?rev=1237228&r1=1237227&r2=1237228&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java Sun Jan 29 09:32:03 2012
@@ -70,7 +70,7 @@ public class ContentStreamWrapper extend
* @throws ValidationException.
*/
public List<ValidationError> validPageContentStream(PDPage page)
- throws ValidationException {
+ throws ValidationException {
List<ValidationError> errors = new ArrayList<ValidationError>();
try {
@@ -97,7 +97,7 @@ public class ContentStreamWrapper extend
* @throws ValidationException
*/
public List<ValidationError> validXObjContentStream(PDXObjectForm xobj)
- throws ValidationException {
+ throws ValidationException {
List<ValidationError> errors = new ArrayList<ValidationError>();
try {
@@ -122,12 +122,12 @@ public class ContentStreamWrapper extend
* @throws ValidationException
*/
public List<ValidationError> validPatternContentStream(COSStream pattern)
- throws ValidationException {
+ throws ValidationException {
List<ValidationError> errors = new ArrayList<ValidationError>();
try {
COSDictionary res = (COSDictionary) pattern
- .getDictionaryObject(DICTIONARY_KEY_RESOURCES);
+ .getDictionaryObject(DICTIONARY_KEY_RESOURCES);
resetEnginContext();
processSubStream(null, new PDResources(res), pattern);
} catch (ContentStreamException e) {
@@ -156,7 +156,7 @@ public class ContentStreamWrapper extend
* .util.PDFOperator, java.util.List)
*/
protected void processOperator(PDFOperator operator, List arguments)
- throws IOException {
+ throws IOException {
// ---- Here is a copy of the super method because the else block is
// different. (If the operator is unknown, throw an exception)
@@ -195,7 +195,7 @@ public class ContentStreamWrapper extend
* @throws IOException
*/
protected void checkShowTextOperators(PDFOperator operator, List<?> arguments)
- throws ContentStreamException, IOException {
+ throws ContentStreamException, IOException {
String op = operator.getOperation();
if ("Tj".equals(op)
|| "'".equals(op)
@@ -221,7 +221,7 @@ public class ContentStreamWrapper extend
* @throws IOException
*/
private void validStringDefinition(PDFOperator operator, List<?> arguments)
- throws ContentStreamException, IOException {
+ throws ContentStreamException, IOException {
// ---- For a Text operator, the arguments list should contain only one
// COSString object
if ("\"".equals(operator.getOperation())) {
@@ -272,7 +272,7 @@ public class ContentStreamWrapper extend
* @throws IOException
*/
private void validStringArray(PDFOperator operator, List<?> arguments)
- throws ContentStreamException, IOException {
+ throws ContentStreamException, IOException {
for (Object object : arguments) {
if (object instanceof COSArray) {
validStringArray(operator, ((COSArray) object).toList());
@@ -357,7 +357,9 @@ public class ContentStreamWrapper extend
try {
fontContainer.checkCID(cid);
} catch (GlyphException e) {
- throwContentStreamException(e.getMessage(), e.getErrorCode());
+ if (renderingMode != 3) {
+ throwContentStreamException(e.getMessage(), e.getErrorCode());
+ }
}
}
}
Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java?rev=1237228&r1=1237227&r2=1237228&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java Sun Jan 29 09:32:03 2012
@@ -40,204 +40,210 @@ import java.util.SimpleTimeZone;
*/
public class DateConverter {
- // The Date format is supposed to be the PDF_DATE_FORMAT, but not all PDF
- // documents
- // will use that date, so I have added a couple other potential formats
- // to try if the original one does not work.
- private static final SimpleDateFormat[] POTENTIAL_FORMATS = new SimpleDateFormat[] {
- new SimpleDateFormat("EEEE, dd MMM yyyy hh:mm:ss a"),
- new SimpleDateFormat("EEEE, MMM dd, yyyy hh:mm:ss a"),
- new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"),
- new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz") };
-
- /**
- * According to check-style, Utility classes should not have a public or
- * default constructor.
- */
- protected DateConverter() {
- };
-
- /**
- * This will convert a string to a calendar.
- *
- * @param date
- * The string representation of the calendar.
- *
- * @return The calendar that this string represents.
- *
- * @throws IOException
- * If the date string is not in the correct format.
- */
- public static Calendar toCalendar(String date) throws IOException {
- Calendar retval = null;
- if ((date != null) && (date.trim().length() > 0)) {
- // these are the default values
- int year = 0;
- int month = 1;
- int day = 1;
- int hour = 0;
- int minute = 0;
- int second = 0;
- // first string off the prefix if it exists
- try {
- SimpleTimeZone zone = null;
- if (date.startsWith("D:")) {
- date = date.substring(2, date.length());
- }
- date = date.replaceAll("[-:T]", "");
-
- if (date.length() < 4) {
- throw new IOException("Error: Invalid date format '" + date
- + "'");
- }
- year = Integer.parseInt(date.substring(0, 4));
- if (date.length() >= 6) {
- month = Integer.parseInt(date.substring(4, 6));
- }
- if (date.length() >= 8) {
- day = Integer.parseInt(date.substring(6, 8));
- }
- if (date.length() >= 10) {
- hour = Integer.parseInt(date.substring(8, 10));
- }
- if (date.length() >= 12) {
- minute = Integer.parseInt(date.substring(10, 12));
- }
- if (date.length() >= 14) {
- second = Integer.parseInt(date.substring(12, 14));
- }
- if (date.length() >= 15) {
- char sign = date.charAt(14);
- if (sign == 'Z') {
- zone = new SimpleTimeZone(0, "Unknown");
- } else {
- int hours = 0;
- int minutes = 0;
- if (date.length() >= 17) {
- if (sign == '+') {
- // parseInt cannot handle the + sign
- hours = Integer
- .parseInt(date.substring(15, 17));
- } else {
- hours = -Integer.parseInt(date
- .substring(14, 16));
- }
- }
- if (sign == '+') {
- if (date.length() >= 19) {
- minutes = Integer.parseInt(date.substring(17,
- 19));
- }
- } else {
- if (date.length() >= 18) {
- minutes = Integer.parseInt(date.substring(16,
- 18));
- }
- }
- zone = new SimpleTimeZone(hours * 60 * 60 * 1000
- + minutes * 60 * 1000, "Unknown");
- }
- }
- if (zone == null) {
- retval = new GregorianCalendar();
- } else {
- retval = new GregorianCalendar(zone);
- }
- retval.clear();
- retval.set(year, month - 1, day, hour, minute, second);
- } catch (NumberFormatException e) {
-
- // remove the arbitrary : in the timezone. SimpleDateFormat
- // can't handle it
- if (date.substring(date.length() - 3, date.length() - 2)
- .equals(":")
- && (date
- .substring(date.length() - 6, date.length() - 5)
- .equals("+") || date.substring(
- date.length() - 6, date.length() - 5).equals(
- "-"))) {
- // thats a timezone string, remove the :
- date = date.substring(0, date.length() - 3)
- + date.substring(date.length() - 2);
- }
- for (int i = 0; (retval == null)
- && (i < POTENTIAL_FORMATS.length); i++) {
- try {
- Date utilDate = POTENTIAL_FORMATS[i].parse(date);
- retval = new GregorianCalendar();
- retval.setTime(utilDate);
- } catch (ParseException pe) {
- // ignore and move to next potential format
- }
- }
- if (retval == null) {
- // we didn't find a valid date format so throw an exception
- throw new IOException("Error converting date:" + date);
- }
- }
- }
- return retval;
- }
-
- /**
- * Append Zero to String Buffer before number < 10 ('1' become '01')
- *
- * @param out
- * The String buffer
- * @param number
- * The concerned number
- */
- private static void zeroAppend(StringBuffer out, int number) {
- if (number < 10) {
- out.append("0");
- }
- out.append(number);
- }
-
- /**
- * Convert the date to iso 8601 string format.
- *
- * @param cal
- * The date to convert.
- * @return The date represented as an ISO 8601 string.
- */
- public static String toISO8601(Calendar cal) {
- StringBuffer retval = new StringBuffer();
-
- retval.append(cal.get(Calendar.YEAR));
- retval.append("-");
- zeroAppend(retval, cal.get(Calendar.MONTH) + 1);
- retval.append("-");
- zeroAppend(retval, cal.get(Calendar.DAY_OF_MONTH));
- retval.append("T");
- zeroAppend(retval, cal.get(Calendar.HOUR_OF_DAY));
- retval.append(":");
- zeroAppend(retval, cal.get(Calendar.MINUTE));
- retval.append(":");
- zeroAppend(retval, cal.get(Calendar.SECOND));
-
- int timeZone = cal.get(Calendar.ZONE_OFFSET)
- + cal.get(Calendar.DST_OFFSET);
- if (timeZone < 0) {
- retval.append("-");
- } else {
- retval.append("+");
- }
- timeZone = Math.abs(timeZone);
- // milliseconds/1000 = seconds = seconds / 60 = minutes = minutes/60 =
- // hours
- int hours = timeZone / 1000 / 60 / 60;
- int minutes = (timeZone - (hours * 1000 * 60 * 60)) / 1000 / 1000;
- if (hours < 10) {
- retval.append("0");
- }
- retval.append(Integer.toString(hours));
- retval.append(":");
- if (minutes < 10) {
- retval.append("0");
- }
- retval.append(Integer.toString(minutes));
-
- return retval.toString();
- }
+ // The Date format is supposed to be the PDF_DATE_FORMAT, but not all PDF
+ // documents
+ // will use that date, so I have added a couple other potential formats
+ // to try if the original one does not work.
+ private static final SimpleDateFormat[] POTENTIAL_FORMATS = new SimpleDateFormat[] {
+ new SimpleDateFormat("EEEE, dd MMM yyyy hh:mm:ss a"),
+ new SimpleDateFormat("EEEE, MMM dd, yyyy hh:mm:ss a"),
+ new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"),
+ new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz") };
+
+ /**
+ * According to check-style, Utility classes should not have a public or
+ * default constructor.
+ */
+ protected DateConverter() {
+ };
+
+ /**
+ * This will convert a string to a calendar.
+ *
+ * @param date
+ * The string representation of the calendar.
+ *
+ * @return The calendar that this string represents.
+ *
+ * @throws IOException
+ * If the date string is not in the correct format.
+ */
+ public static Calendar toCalendar(String date) throws IOException {
+ Calendar retval = null;
+ if ((date != null) && (date.trim().length() > 0)) {
+ // these are the default values
+ int year = 0;
+ int month = 1;
+ int day = 1;
+ int hour = 0;
+ int minute = 0;
+ int second = 0;
+ // first string off the prefix if it exists
+ try {
+ SimpleTimeZone zone = null;
+ if (date.startsWith("D:")) {
+ date = date.substring(2, date.length());
+ }
+
+ date = date.replaceAll("[-:T]", "");
+
+ if (date.length() < 4) {
+ throw new IOException("Error: Invalid date format '" + date
+ + "'");
+ }
+ year = Integer.parseInt(date.substring(0, 4));
+ if (date.length() >= 6) {
+ month = Integer.parseInt(date.substring(4, 6));
+ }
+ if (date.length() >= 8) {
+ day = Integer.parseInt(date.substring(6, 8));
+ }
+ if (date.length() >= 10) {
+ hour = Integer.parseInt(date.substring(8, 10));
+ }
+ if (date.length() >= 12) {
+ minute = Integer.parseInt(date.substring(10, 12));
+ }
+
+ int timeZonePos = 12;
+ if (date.length() - 12 > 5 ||(date.length() - 12 == 3 && date.endsWith("Z"))) {
+ if (date.length() >= 14) {
+ second = Integer.parseInt(date.substring(12, 14));
+ }
+ timeZonePos = 14;
+ } else {
+ second = 0;
+ }
+
+ if (date.length() >= (timeZonePos+1)) {
+ char sign = date.charAt(timeZonePos);
+ if (sign == 'Z') {
+ zone = new SimpleTimeZone(0, "Unknown");
+ } else {
+ int hours = 0;
+ int minutes = 0;
+ if (date.length() >= (timeZonePos+3)) {
+ if (sign == '+') {
+ // parseInt cannot handle the + sign
+ hours = Integer.parseInt(date.substring((timeZonePos+1), (timeZonePos+3)));
+ } else {
+ hours = -Integer.parseInt(date.substring(timeZonePos, (timeZonePos+2)));
+ }
+ }
+ if (sign == '+') {
+ if (date.length() >= (timeZonePos+5)) {
+ minutes = Integer.parseInt(date.substring((timeZonePos+3), (timeZonePos+5)));
+ }
+ } else {
+ if (date.length() >= (timeZonePos+4)) {
+ minutes = Integer.parseInt(date.substring((timeZonePos+2), (timeZonePos+4)));
+ }
+ }
+ zone = new SimpleTimeZone(hours * 60 * 60 * 1000
+ + minutes * 60 * 1000, "Unknown");
+ }
+ }
+
+
+ if (zone == null) {
+ retval = new GregorianCalendar();
+ } else {
+ retval = new GregorianCalendar(zone);
+ }
+ retval.clear();
+ retval.set(year, month - 1, day, hour, minute, second);
+ } catch (NumberFormatException e) {
+
+ // remove the arbitrary : in the timezone. SimpleDateFormat
+ // can't handle it
+ if (date.substring(date.length() - 3, date.length() - 2)
+ .equals(":")
+ && (date
+ .substring(date.length() - 6, date.length() - 5)
+ .equals("+") || date.substring(
+ date.length() - 6, date.length() - 5).equals(
+ "-"))) {
+ // thats a timezone string, remove the :
+ date = date.substring(0, date.length() - 3)
+ + date.substring(date.length() - 2);
+ }
+ for (int i = 0; (retval == null)
+ && (i < POTENTIAL_FORMATS.length); i++) {
+ try {
+ Date utilDate = POTENTIAL_FORMATS[i].parse(date);
+ retval = new GregorianCalendar();
+ retval.setTime(utilDate);
+ } catch (ParseException pe) {
+ // ignore and move to next potential format
+ }
+ }
+ if (retval == null) {
+ // we didn't find a valid date format so throw an exception
+ throw new IOException("Error converting date:" + date);
+ }
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * Append Zero to String Buffer before number < 10 ('1' become '01')
+ *
+ * @param out
+ * The String buffer
+ * @param number
+ * The concerned number
+ */
+ private static void zeroAppend(StringBuffer out, int number) {
+ if (number < 10) {
+ out.append("0");
+ }
+ out.append(number);
+ }
+
+ /**
+ * Convert the date to iso 8601 string format.
+ *
+ * @param cal
+ * The date to convert.
+ * @return The date represented as an ISO 8601 string.
+ */
+ public static String toISO8601(Calendar cal) {
+ StringBuffer retval = new StringBuffer();
+
+ retval.append(cal.get(Calendar.YEAR));
+ retval.append("-");
+ zeroAppend(retval, cal.get(Calendar.MONTH) + 1);
+ retval.append("-");
+ zeroAppend(retval, cal.get(Calendar.DAY_OF_MONTH));
+ retval.append("T");
+ zeroAppend(retval, cal.get(Calendar.HOUR_OF_DAY));
+ retval.append(":");
+ zeroAppend(retval, cal.get(Calendar.MINUTE));
+ retval.append(":");
+ zeroAppend(retval, cal.get(Calendar.SECOND));
+
+ int timeZone = cal.get(Calendar.ZONE_OFFSET)
+ + cal.get(Calendar.DST_OFFSET);
+ if (timeZone < 0) {
+ retval.append("-");
+ } else {
+ retval.append("+");
+ }
+ timeZone = Math.abs(timeZone);
+ // milliseconds/1000 = seconds = seconds / 60 = minutes = minutes/60 =
+ // hours
+ int hours = timeZone / 1000 / 60 / 60;
+ int minutes = (timeZone - (hours * 1000 * 60 * 60)) / 1000 / 1000;
+ if (hours < 10) {
+ retval.append("0");
+ }
+ retval.append(Integer.toString(hours));
+ retval.append(":");
+ if (minutes < 10) {
+ retval.append("0");
+ }
+ retval.append(Integer.toString(minutes));
+ return retval.toString();
+ }
}