pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1817528 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java
Date Fri, 08 Dec 2017 17:41:18 GMT
Author: tilman
Date: Fri Dec  8 17:41:18 2017
New Revision: 1817528

URL: http://svn.apache.org/viewvc?rev=1817528&view=rev
Log:
PDFBOX-4027: add convenience method that checks everything before creating a Matrix object

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java?rev=1817528&r1=1817527&r2=1817528&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java Fri Dec  8 17:41:18
2017
@@ -23,6 +23,7 @@ import org.apache.pdfbox.cos.COSNumber;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.util.Arrays;
+import org.apache.pdfbox.cos.COSBase;
 
 /**
  * This class will be used for matrix manipulation.
@@ -112,6 +113,36 @@ public final class Matrix implements Clo
     }
 
     /**
+     * Convenience method to be used when creating a matrix from unverified data. If the
parameter
+     * is a COSArray with at least six numbers, a Matrix object is created from the first
six
+     * numbers and returned. If not, then the identity Matrix is returned.
+     *
+     * @param base a COS object, preferably a COSArray with six numbers.
+     *
+     * @return a Matrix object.
+     */
+    static Matrix createMatrix(COSBase base)
+    {
+        if (!(base instanceof COSArray))
+        {
+            return new Matrix();
+        }
+        COSArray array = (COSArray) base;
+        if (array.size() < 6)
+        {
+            return new Matrix();
+        }
+        for (int i = 0; i < 6; ++i)
+        {
+            if (!(array.getObject(i) instanceof COSNumber))
+            {
+                return new Matrix();
+            }
+        }
+        return new Matrix(array);
+    }
+
+    /**
      * This method resets the numbers in this Matrix to the original values, which are
      * the values that a newly constructed Matrix would have.
      *



Mime
View raw message