Package org.apache.pdfbox.util
Class Matrix
- java.lang.Object
-
- org.apache.pdfbox.util.Matrix
-
- All Implemented Interfaces:
java.lang.Cloneable
public class Matrix extends java.lang.Object implements java.lang.Cloneable
This class will be used for matrix manipulation.- Version:
- $Revision: 1.14 $
- Author:
- Ben Litchfield
-
-
Constructor Summary
Constructors Constructor Description Matrix()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Clones this object.Matrix
copy()
This will copy the text matrix data.java.awt.geom.AffineTransform
createAffineTransform()
Create an affine transform from this matrix's values.Matrix
extractScaling()
Create a new matrix with just the scaling operators.Matrix
extractTranslating()
Create a new matrix with just the translating operators.static Matrix
getScaleInstance(float x, float y)
Convenience method to create a scaled instance.static Matrix
getTranslatingInstance(float x, float y)
Convenience method to create a translating instance.float
getValue(int row, int column)
This will get a matrix value at some point.float[][]
getValues()
Return a single dimension array of all values in the matrix.double[][]
getValuesAsDouble()
Return a single dimension array of all values in the matrix.float
getXPosition()
Get the x position in the matrix.float
getXScale()
Get the xscaling factor of this matrix.float
getYPosition()
Get the y position.float
getYScale()
Get the y scaling factor of this matrix.Matrix
multiply(Matrix b)
This will take the current matrix and multipy it with a matrix that is passed in.Matrix
multiply(Matrix other, Matrix result)
This method multiplies this Matrix with the specified other Matrix, storing the product in the specified result Matrix.void
reset()
This method resets the numbers in this Matrix to the original values, which are the values that a newly constructed Matrix would have.void
setFromAffineTransform(java.awt.geom.AffineTransform af)
Set the values of the matrix from the AffineTransform.void
setValue(int row, int column, float value)
This will set a value at a position.java.lang.String
toString()
This will return a string representation of the matrix.
-
-
-
Method Detail
-
reset
public void reset()
This method resets the numbers in this Matrix to the original values, which are the values that a newly constructed Matrix would have.
-
createAffineTransform
public java.awt.geom.AffineTransform createAffineTransform()
Create an affine transform from this matrix's values.- Returns:
- An affine transform with this matrix's values.
-
setFromAffineTransform
public void setFromAffineTransform(java.awt.geom.AffineTransform af)
Set the values of the matrix from the AffineTransform.- Parameters:
af
- The transform to get the values from.
-
getValue
public float getValue(int row, int column)
This will get a matrix value at some point.- Parameters:
row
- The row to get the value from.column
- The column to get the value from.- Returns:
- The value at the row/column position.
-
setValue
public void setValue(int row, int column, float value)
This will set a value at a position.- Parameters:
row
- The row to set the value at.column
- the column to set the value at.value
- The value to set at the position.
-
getValues
public float[][] getValues()
Return a single dimension array of all values in the matrix.- Returns:
- The values ot this matrix.
-
getValuesAsDouble
public double[][] getValuesAsDouble()
Return a single dimension array of all values in the matrix.- Returns:
- The values ot this matrix.
-
multiply
public Matrix multiply(Matrix b)
This will take the current matrix and multipy it with a matrix that is passed in.- Parameters:
b
- The matrix to multiply by.- Returns:
- The result of the two multiplied matrices.
-
multiply
public Matrix multiply(Matrix other, Matrix result)
This method multiplies this Matrix with the specified other Matrix, storing the product in the specified result Matrix. By reusing Matrix instances like this, multiplication chains can be executed without having to create many temporary Matrix objects. It is allowed to have (other == this) or (result == this) or indeed (other == result) but if this is done, the backing float[] matrix values may be copied in order to ensure a correct product.- Parameters:
other
- the second operand Matrix in the multiplicationresult
- the Matrix instance into which the result should be stored. If result is null, a new Matrix instance is created.- Returns:
- the product of the two matrices.
-
extractScaling
public Matrix extractScaling()
Create a new matrix with just the scaling operators.- Returns:
- A new matrix with just the scaling operators.
-
getScaleInstance
public static Matrix getScaleInstance(float x, float y)
Convenience method to create a scaled instance.- Parameters:
x
- The xscale operator.y
- The yscale operator.- Returns:
- A new matrix with just the x/y scaling
-
extractTranslating
public Matrix extractTranslating()
Create a new matrix with just the translating operators.- Returns:
- A new matrix with just the translating operators.
-
getTranslatingInstance
public static Matrix getTranslatingInstance(float x, float y)
Convenience method to create a translating instance.- Parameters:
x
- The x translating operator.y
- The y translating operator.- Returns:
- A new matrix with just the x/y translating.
-
clone
public java.lang.Object clone()
Clones this object.- Overrides:
clone
in classjava.lang.Object
- Returns:
- cloned matrix as an object.
-
copy
public Matrix copy()
This will copy the text matrix data.- Returns:
- a matrix that matches this one.
-
toString
public java.lang.String toString()
This will return a string representation of the matrix.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The matrix as a string.
-
getXScale
public float getXScale()
Get the xscaling factor of this matrix.- Returns:
- The x-scale.
-
getYScale
public float getYScale()
Get the y scaling factor of this matrix.- Returns:
- The y-scale factor.
-
getXPosition
public float getXPosition()
Get the x position in the matrix.- Returns:
- The x-position.
-
getYPosition
public float getYPosition()
Get the y position.- Returns:
- The y position.
-
-