/*
Copyright 2007 Stefano Chizzolini. http://clown.stefanochizzolini.it
Contributors:
* Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it)
This file should be part of the source code distribution of "PDF Clown library"
(the Program): see the accompanying README files for more info.
This Program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later version.
This Program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY, either expressed or implied; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
You should have received a copy of the GNU General Public License along with this
Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
Redistribution and use, with or without modification, are permitted provided that such
redistributions retain the above copyright notice, license and disclaimer, along with
this list of conditions.
*/
using it.stefanochizzolini.clown.bytes;
using it.stefanochizzolini.clown.objects;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
namespace it.stefanochizzolini.clown.documents.contents.objects{
/**
<summary>'Modify the current transformation matrix (CTM) by concatenating the specified matrix'
operation [PDF:1.6:4.3.3].</summary>
*/
public sealed class ModifyCTM
: Operation
{
#region static
#region fields
public static readonly string OperatorKeyword = "cm";
#endregion
#region interface
#region public
public static ModifyCTM GetResetCTM(
double[] ctm
)
{
Matrix matrix = new Matrix((float)ctm[0],(float)ctm[1],(float)ctm[2],(float)ctm[3],(float)ctm[4],(float)ctm[5]);
matrix.Invert();
float[] inverseMatrixData = matrix.Elements;
return new ModifyCTM(
inverseMatrixData[0],
inverseMatrixData[1],
inverseMatrixData[2],
inverseMatrixData[3],
inverseMatrixData[4],
inverseMatrixData[5]
);
}
#endregion
#endregion
#endregion
#region dynamic
#region constructors
public ModifyCTM(
double a,
double b,
double c,
double d,
double e,
double f
) : base(
OperatorKeyword,
new List<PdfDirectObject>(
new PdfDirectObject[]
{
new PdfReal(a),
new PdfReal(b),
new PdfReal(c),
new PdfReal(d),
new PdfReal(e),
new PdfReal(f)
}
)
)
{}
public ModifyCTM(
List<PdfDirectObject> operands
) : base(OperatorKeyword,operands)
{}
#endregion
#region interface
#region public
/**
<summary>Applies the transformation to the specified transformation matrix
by concatenation.</summary>
<param name="ctm">Current Transformation Matrix.</param>
<returns>Transformed transformation matrix.</returns>
*/
public double[] ApplyTo(
double[] ctm
)
{
// Get the new transformation matrix!
double[] ntm = GetMatrix();
// Initialize the resulting transformation matrix!
double[] rtm = new double[6];
// Apply the transformation to the existing transformation matrix!
rtm[0] = ntm[0]*ctm[0] + ntm[1]*ctm[2]; // a.
rtm[1] = ntm[0]*ctm[1] + ntm[1]*ctm[3]; // b.
rtm[2] = ntm[2]*ctm[0] + ntm[3]*ctm[2]; // c.
rtm[3] = ntm[2]*ctm[1] + ntm[3]*ctm[3]; // d.
rtm[4] = ntm[4]*ctm[0] + ntm[5]*ctm[2] + 1*ctm[4]; // e.
rtm[5] = ntm[4]*ctm[1] + ntm[5]*ctm[3] + 1*ctm[5]; // f.
return rtm;
}
public double[] GetMatrix(
)
{
return new double[]
{
((IPdfNumber)operands[0]).RawValue, // a.
((IPdfNumber)operands[1]).RawValue, // b.
((IPdfNumber)operands[2]).RawValue, // c.
((IPdfNumber)operands[3]).RawValue, // d.
((IPdfNumber)operands[4]).RawValue, // e.
((IPdfNumber)operands[5]).RawValue // f.
};
}
#endregion
#endregion
#endregion
}
}
|