This class will be used for matrix manipulation.
Method from org.apache.pdfbox.util.Matrix Detail: |
public Object clone() {
Matrix clone = new Matrix();
System.arraycopy( single, 0, clone.single, 0, 9 );
return clone;
}
|
public Matrix copy() {
return (Matrix) clone();
}
This will copy the text matrix data. |
public AffineTransform createAffineTransform() {
AffineTransform retval = new AffineTransform(
single[0], single[1],
single[3], single[4],
single[6], single[7] );
return retval;
}
Create an affine transform from this matrix's values. |
public Matrix extractScaling() {
Matrix retval = new Matrix();
retval.single[0] = this.single[0];
retval.single[4] = this.single[4];
return retval;
}
Create a new matrix with just the scaling operators. |
public Matrix extractTranslating() {
Matrix retval = new Matrix();
retval.single[6] = this.single[6];
retval.single[7] = this.single[7];
return retval;
}
Create a new matrix with just the translating operators. |
public static Matrix getScaleInstance(float x,
float y) {
Matrix retval = new Matrix();
retval.single[0] = x;
retval.single[4] = y;
return retval;
}
Convenience method to create a scaled instance. |
public static Matrix getTranslatingInstance(float x,
float y) {
Matrix retval = new Matrix();
retval.single[6] = x;
retval.single[7] = y;
return retval;
}
Convenience method to create a translating instance. |
public float getValue(int row,
int column) {
return single[row*3+column];
}
This will get a matrix value at some point. |
public float[][] getValues() {
float[][] retval = new float[3][3];
retval[0][0] = single[0];
retval[0][1] = single[1];
retval[0][2] = single[2];
retval[1][0] = single[3];
retval[1][1] = single[4];
retval[1][2] = single[5];
retval[2][0] = single[6];
retval[2][1] = single[7];
retval[2][2] = single[8];
return retval;
}
Return a single dimension array of all values in the matrix. |
public double[][] getValuesAsDouble() {
double[][] retval = new double[3][3];
retval[0][0] = single[0];
retval[0][1] = single[1];
retval[0][2] = single[2];
retval[1][0] = single[3];
retval[1][1] = single[4];
retval[1][2] = single[5];
retval[2][0] = single[6];
retval[2][1] = single[7];
retval[2][2] = single[8];
return retval;
}
Return a single dimension array of all values in the matrix. |
public float getXPosition() {
return single[6];
}
Get the x position in the matrix. |
public float getXScale() {
float xScale = single[0];
/**
* BM: if the trm is rotated, the calculation is a little more complicated
*
* The rotation matrix multiplied with the scaling matrix is:
* ( x 0 0) ( cos sin 0) ( x*cos x*sin 0)
* ( 0 y 0) * (-sin cos 0) = (-y*sin y*cos 0)
* ( 0 0 1) ( 0 0 1) ( 0 0 1)
*
* So, if you want to deduce x from the matrix you take
* M(0,0) = x*cos and M(0,1) = x*sin and use the theorem of Pythagoras
*
* sqrt(M(0,0)^2+M(0,1)^2) =
* sqrt(x2*cos2+x2*sin2) =
* sqrt(x2*(cos2+sin2)) = < - here is the trick cos2+sin2 is one
* sqrt(x2) =
* abs(x)
*/
if( !(single[1]==0.0f && single[3]==0.0f) )
{
xScale = (float)Math.sqrt(Math.pow(single[0], 2)+
Math.pow(single[1], 2));
}
return xScale;
}
Get the xscaling factor of this matrix. |
public float getYPosition() {
return single[7];
}
|
public float getYScale() {
float yScale = single[4];
if( !(single[1]==0.0f && single[3]==0.0f) )
{
yScale = (float)Math.sqrt(Math.pow(single[3], 2)+
Math.pow(single[4], 2));
}
return yScale;
}
Get the y scaling factor of this matrix. |
public Matrix multiply(Matrix b) {
Matrix result = new Matrix();
if (b != null && b.single != null)
{
float[] bMatrix = b.single;
float[] resultMatrix = result.single;
resultMatrix[0] = single[0] * bMatrix[0] + single[1] * bMatrix[3] + single[2] * bMatrix[6];
resultMatrix[1] = single[0] * bMatrix[1] + single[1] * bMatrix[4] + single[2] * bMatrix[7];
resultMatrix[2] = single[0] * bMatrix[2] + single[1] * bMatrix[5] + single[2] * bMatrix[8];
resultMatrix[3] = single[3] * bMatrix[0] + single[4] * bMatrix[3] + single[5] * bMatrix[6];
resultMatrix[4] = single[3] * bMatrix[1] + single[4] * bMatrix[4] + single[5] * bMatrix[7];
resultMatrix[5] = single[3] * bMatrix[2] + single[4] * bMatrix[5] + single[5] * bMatrix[8];
resultMatrix[6] = single[6] * bMatrix[0] + single[7] * bMatrix[3] + single[8] * bMatrix[6];
resultMatrix[7] = single[6] * bMatrix[1] + single[7] * bMatrix[4] + single[8] * bMatrix[7];
resultMatrix[8] = single[6] * bMatrix[2] + single[7] * bMatrix[5] + single[8] * bMatrix[8];
}
return result;
}
This will take the current matrix and multipy it with a matrix that is passed in. |
public void setFromAffineTransform(AffineTransform af) {
single[0] = (float)af.getScaleX();
single[1] = (float)af.getShearY();
single[3] = (float)af.getShearX();
single[4] = (float)af.getScaleY();
single[6] = (float)af.getTranslateX();
single[7] = (float)af.getTranslateY();
}
Set the values of the matrix from the AffineTransform. |
public void setValue(int row,
int column,
float value) {
single[row*3+column] = value;
}
This will set a value at a position. |
public String toString() {
StringBuffer result = new StringBuffer( "" );
result.append( "[[" );
result.append( single[0] + "," );
result.append( single[1] + "," );
result.append( single[2] + "][");
result.append( single[3] + "," );
result.append( single[4] + "," );
result.append( single[5] + "][");
result.append( single[6] + "," );
result.append( single[7] + "," );
result.append( single[8] + "]]");
return result.toString();
}
This will return a string representation of the matrix. |