Top Description Fields Constructors Methods
org.apache.pdfbox.util

public final Class Matrix

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
org.apache.pdfbox.cos.COSArray, .COSFloat, .COSNumber, .COSBase, java.awt.geom.AffineTransform, .Point2D, java.util.Arrays

This class will be used for matrix manipulation.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private float[]
public static final int

Constructor Summary

AccessConstructor and Description
public
Matrix()

Constructor.

private
Matrix(float[] src)

Constructor.

private
Matrix(COSArray
source array, elements must be or extend COSNumber
array
)

Creates a matrix from a 6-element (a b c d e f) COS array.

public
Matrix(float
the X coordinate scaling element (m00) of the 3x3 matrix
a
,
float
the Y coordinate shearing element (m10) of the 3x3 matrix
b
,
float
the X coordinate shearing element (m01) of the 3x3 matrix
c
,
float
the Y coordinate scaling element (m11) of the 3x3 matrix
d
,
float
the X coordinate translation element (m02) of the 3x3 matrix
e
,
float
the Y coordinate translation element (m12) of the 3x3 matrix
f
)

Creates a transformation matrix with the given 6 elements.

public
Matrix(AffineTransform
matrix elements will be initialize with the values from this affine transformation, as follows: scaleX shearY 0 shearX scaleY 0 transX transY 1
at
)

Creates a matrix with the same elements as the given AffineTransform.

Method Summary

Modifier and TypeMethod and Description
private float[]
checkFloatValues(float[] values)

public Matrix

Returns:

cloned matrix as an object.
clone
()

Overrides java.lang.Object.clone.

Clones this object.

public void
concatenate(Matrix
The matrix to concatenate.
matrix
)

Concatenates (premultiplies) the given matrix to this matrix.

public static Matrix

Returns:

a copy of the first matrix with the second matrix concatenated
concatenate
(Matrix
The matrix to copy.
a
,
Matrix
The matrix to concatenate.
b
)

Produces a copy of the first matrix, with the second matrix concatenated.

public AffineTransform

Returns:

An affine transform with this matrix's values.
createAffineTransform
()

Create an affine transform from this matrix's values.

public static Matrix

Returns:

a Matrix object.
createMatrix
(COSBase
a COS object, preferably a COSArray with six numbers.
base
)

Convenience method to be used when creating a matrix from unverified data.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static Matrix

Returns:

A new matrix with the rotation and the x/y translating.
getRotateInstance
(double
The angle of rotation measured in radians
theta
,
float
The x translation.
tx
,
float
The y translation.
ty
)

Convenience method to create a rotated instance.

public static Matrix

Returns:

A new matrix with just the x/y scaling
getScaleInstance
(float
The xscale operator.
x
,
float
The yscale operator.
y
)

Convenience method to create a scaled instance.

public float

Returns:

the x-scaling element of the matrix
getScaleX
()

Returns the x-scaling element of this matrix.

public float

Returns:

the y-scaling element of the matrix
getScaleY
()

Returns the y-scaling element of this matrix.

public float

Returns:

The x-scaling factor.
getScalingFactorX
()

Returns the x-scaling factor of this matrix.

public float

Returns:

The y-scaling factor.
getScalingFactorY
()

Returns the y-scaling factor of this matrix.

public float

Returns:

the x-sheard element of the matrix
getShearX
()

Returns the x-shear element of this matrix.

public float

Returns:

the y-shear element of the matrix
getShearY
()

Returns the y-shear element of this matrix.

public static Matrix

Returns:

A new matrix with just the x/y translating.
getTranslateInstance
(float
The x translating operator.
x
,
float
The y translating operator.
y
)

Convenience method to create a translating instance.

public float

Returns:

the x-translation element of the matrix
getTranslateX
()

Returns the x-translation element of this matrix.

public float

Returns:

the y-translation element of the matrix
getTranslateY
()

Returns the y-translation element of this matrix.

public float

Returns:

The value at the row/column position.
getValue
(int
The row to get the value from.
row
,
int
The column to get the value from.
column
)

This will get a matrix value at some point.

public float[][]

Returns:

The values of this matrix.
getValues
()

Return a single dimension array of all values in the matrix.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Matrix

Returns:

the product of the two matrices.
multiply
(Matrix
the second operand Matrix in the multiplication; required
other
)

This method multiplies this Matrix with the specified other Matrix, storing the product in a new instance.

private float[]
multiplyArrays(float[] a, float[] b)

public void
rotate(double
The angle of rotation measured in radians
theta
)

Rotates this matrix by the given factors.

public void
scale(float
x-scale
sx
,
float
y-scale
sy
)

Scales this matrix by the given factors.

public void
setValue(int
The row to set the value at.
row
,
int
the column to set the value at.
column
,
float
The value to set at the position.
value
)

This will set a value at a position.

public COSArray

Returns:

a COSArray representing the geometric relevant components of the matrix
toCOSArray
()

Returns a COS array which represent the geometric relevant components of the matrix.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
transform(Point2D
point to transform
point
)

Transforms the given point by this matrix.

public Vector

Returns:

the transformed vector.
transform
(Vector
2D vector
vector
)

Transforms the given vector by this matrix.

public Point2D.Float

Returns:

the transformed point.
transformPoint
(float
x-coordinate
x
,
float
y-coordinate
y
)

Transforms the given point by this matrix.

public void
translate(Vector
2D vector
vector
)

Translates this matrix by the given vector.

public void
translate(float
x-translation
tx
,
float
y-translation
ty
)

Translates this matrix by the given amount.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

singleback to summary
private float[] single
SIZEback to summary
public static final int SIZE

Constructor Detail

Matrixback to summary
public Matrix()

Constructor. This produces an identity matrix.

Matrixback to summary
private Matrix(float[] src)

Constructor. This produces a matrix with the given array as data. The source array is not copied or cloned.

Matrixback to summary
private Matrix(COSArray array)

Creates a matrix from a 6-element (a b c d e f) COS array.

Parameters
array:COSArray

source array, elements must be or extend COSNumber

Matrixback to summary
public Matrix(float a, float b, float c, float d, float e, float f)

Creates a transformation matrix with the given 6 elements. Transformation matrices are discussed in 8.3.3, "Common Transformations" and 8.3.4, "Transformation Matrices" of the PDF specification. For simple purposes (rotate, scale, translate) it is recommended to use the static methods below. Produces the following matrix: a b 0 c d 0 e f 1

Parameters
a:float

the X coordinate scaling element (m00) of the 3x3 matrix

b:float

the Y coordinate shearing element (m10) of the 3x3 matrix

c:float

the X coordinate shearing element (m01) of the 3x3 matrix

d:float

the Y coordinate scaling element (m11) of the 3x3 matrix

e:float

the X coordinate translation element (m02) of the 3x3 matrix

f:float

the Y coordinate translation element (m12) of the 3x3 matrix

See Also
Matrix#getRotateInstance(double, float, float), Matrix#getScaleInstance(float, float), Matrix#getTranslateInstance(float, float)
Matrixback to summary
public Matrix(AffineTransform at)

Creates a matrix with the same elements as the given AffineTransform.

Parameters
at:AffineTransform

matrix elements will be initialize with the values from this affine transformation, as follows: scaleX shearY 0 shearX scaleY 0 transX transY 1

Method Detail

checkFloatValuesback to summary
private float[] checkFloatValues(float[] values)
cloneback to summary
public Matrix clone()

Overrides java.lang.Object.clone.

Clones this object.

Returns:Matrix

cloned matrix as an object.

Annotations
@Override
concatenateback to summary
public void concatenate(Matrix matrix)

Concatenates (premultiplies) the given matrix to this matrix.

Parameters
matrix:Matrix

The matrix to concatenate.

concatenateback to summary
public static Matrix concatenate(Matrix a, Matrix b)

Produces a copy of the first matrix, with the second matrix concatenated.

Parameters
a:Matrix

The matrix to copy.

b:Matrix

The matrix to concatenate.

Returns:Matrix

a copy of the first matrix with the second matrix concatenated

createAffineTransformback to summary
public AffineTransform createAffineTransform()

Create an affine transform from this matrix's values.

Returns:AffineTransform

An affine transform with this matrix's values.

createMatrixback to summary
public static Matrix createMatrix(COSBase base)

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.

Parameters
base:COSBase

a COS object, preferably a COSArray with six numbers.

Returns:Matrix

a Matrix object.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getRotateInstanceback to summary
public static Matrix getRotateInstance(double theta, float tx, float ty)

Convenience method to create a rotated instance.

Parameters
theta:double

The angle of rotation measured in radians

tx:float

The x translation.

ty:float

The y translation.

Returns:Matrix

A new matrix with the rotation and the x/y translating.

getScaleInstanceback to summary
public static Matrix getScaleInstance(float x, float y)

Convenience method to create a scaled instance. Produces the following matrix: x 0 0 0 y 0 0 0 1

Parameters
x:float

The xscale operator.

y:float

The yscale operator.

Returns:Matrix

A new matrix with just the x/y scaling

getScaleXback to summary
public float getScaleX()

Returns the x-scaling element of this matrix.

Returns:float

the x-scaling element of the matrix

See Also
getScalingFactorX()
getScaleYback to summary
public float getScaleY()

Returns the y-scaling element of this matrix.

Returns:float

the y-scaling element of the matrix

See Also
getScalingFactorY()
getScalingFactorXback to summary
public float getScalingFactorX()

Returns the x-scaling factor of this matrix. This is calculated from the scale and shear.

Returns:float

The x-scaling factor.

getScalingFactorYback to summary
public float getScalingFactorY()

Returns the y-scaling factor of this matrix. This is calculated from the scale and shear.

Returns:float

The y-scaling factor.

getShearXback to summary
public float getShearX()

Returns the x-shear element of this matrix.

Returns:float

the x-sheard element of the matrix

getShearYback to summary
public float getShearY()

Returns the y-shear element of this matrix.

Returns:float

the y-shear element of the matrix

getTranslateInstanceback to summary
public static Matrix getTranslateInstance(float x, float y)

Convenience method to create a translating instance. Produces the following matrix: 1 0 0 0 1 0 x y 1

Parameters
x:float

The x translating operator.

y:float

The y translating operator.

Returns:Matrix

A new matrix with just the x/y translating.

getTranslateXback to summary
public float getTranslateX()

Returns the x-translation element of this matrix.

Returns:float

the x-translation element of the matrix

getTranslateYback to summary
public float getTranslateY()

Returns the y-translation element of this matrix.

Returns:float

the y-translation element of the matrix

getValueback to summary
public float getValue(int row, int column)

This will get a matrix value at some point.

Parameters
row:int

The row to get the value from.

column:int

The column to get the value from.

Returns:float

The value at the row/column position.

getValuesback to summary
public float[][] getValues()

Return a single dimension array of all values in the matrix.

Returns:float[][]

The values of this matrix.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
multiplyback to summary
public Matrix multiply(Matrix other)

This method multiplies this Matrix with the specified other Matrix, storing the product in a new instance. It is allowed to have (other == this).

Parameters
other:Matrix

the second operand Matrix in the multiplication; required

Returns:Matrix

the product of the two matrices.

multiplyArraysback to summary
private float[] multiplyArrays(float[] a, float[] b)
rotateback to summary
public void rotate(double theta)

Rotates this matrix by the given factors.

Parameters
theta:double

The angle of rotation measured in radians

scaleback to summary
public void scale(float sx, float sy)

Scales this matrix by the given factors.

Parameters
sx:float

x-scale

sy:float

y-scale

setValueback to summary
public void setValue(int row, int column, float value)

This will set a value at a position.

Parameters
row:int

The row to set the value at.

column:int

the column to set the value at.

value:float

The value to set at the position.

toCOSArrayback to summary
public COSArray toCOSArray()

Returns a COS array which represent the geometric relevant components of the matrix. The last column of the matrix is ignored, only the first two columns are returned. This is analog to the Matrix(COSArray) constructor.

Returns:COSArray

a COSArray representing the geometric relevant components of the matrix

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
transformback to summary
public void transform(Point2D point)

Transforms the given point by this matrix.

Parameters
point:Point2D

point to transform

transformback to summary
public Vector transform(Vector vector)

Transforms the given vector by this matrix.

Parameters
vector:Vector

2D vector

Returns:Vector

the transformed vector.

transformPointback to summary
public Point2D.Float transformPoint(float x, float y)

Transforms the given point by this matrix.

Parameters
x:float

x-coordinate

y:float

y-coordinate

Returns:Point2D.Float

the transformed point.

translateback to summary
public void translate(Vector vector)

Translates this matrix by the given vector.

Parameters
vector:Vector

2D vector

translateback to summary
public void translate(float tx, float ty)

Translates this matrix by the given amount.

Parameters
tx:float

x-translation

ty:float

y-translation