#include <libsswf.h>
Public Member Functions | |
bool | IsNull (void) const |
Check whether the matrix has an effect. | |
Matrix (void) | |
Initialize a matrix to a "no effect" matrix. | |
bool | operator!= (const Matrix &matrix) const |
Compare two matrices for inequality. | |
bool | operator== (const Matrix &matrix) const |
Compare two matrices for equality. | |
ErrorManager::error_code_t | Parse (const Data &data) |
Save a matrix to a data buffer. | |
void | Reset (void) |
Reset a matrix to a "no effect" matrix. | |
void | Save (Data &data) |
Save a matrix to a data buffer. | |
void | SetRotate (double rotate) |
Change the rotation. | |
void | SetScale (double scale) |
Define the scale of the object. | |
void | SetScale (double x, double y) |
Define the horizontal and vertical scaling factors. | |
void | SetSkew (double skew0, double skew1) |
Set a skew (sliding off). | |
void | SetTranslate (long x, long y) |
Define the matrix translation. | |
Private Member Functions | |
void | ComputeMatrix (signed_matrix_t &m) const |
Internal function used to compute the matrix. | |
void | UncomputeMatrix (const signed_matrix_t &m) |
Internal function used to "uncompute" the matrix. | |
Private Attributes | |
double | f_rotate |
double | f_scale_x |
double | f_scale_y |
double | f_skew_0 |
double | f_skew_1 |
long | f_translate_x |
long | f_translate_y |
Classes | |
struct | signed_matrix_t |
Matrix of longs; used to compute the matrix to be saved in the movie. More... |
The matrix is a 2D matrix and thus is only a 3x3.
The default is the identity matrix:
| 1 0 0 | | 0 1 0 | | 0 0 1 |
However, the matrix is not managed as a matrix. Instead, you define the scaling, skewing, rotation and translation parameters. The library takes care of generating the matrix when it is saved in the SWF movie.
Notice that the translation is defined in twips and not floating point values.
Matrix::Matrix | ( | void | ) |
The constructor creates and initializes a matrix with no effect. (i.e. the identity matrix.)
References Reset().
void Matrix::ComputeMatrix | ( | signed_matrix_t & | m | ) | const [private] |
This function computes the matrix of signed values. The matrix is saved as 4x 16.16 fixed point values. This function computes the 4 fixed point values using the current definition of the matrix (i.e. rotation, skew and scaling.) The translation is not added in this matrix since this matrix is a 2x2 matrix.
[out] | m | When the computed matrix is saved |
Matrix::operator == (const Matrix& matrix) const
Matrix::operator != (const Matrix& matrix) const
References sswf::TagBase::Double2Signed(), f_rotate, f_scale_x, f_scale_y, f_skew_0, f_skew_1, and sswf::Matrix::signed_matrix_t::m.
Referenced by IsNull(), operator==(), and Save().
bool Matrix::IsNull | ( | void | ) | const |
This function checks whether the different parameters define a null matrix. If so, then the function returns true.
The test is performed with the floating point values transformed in 16.16 fixed points as when they are saved in the final matrix. To ensures that the normal rounding is applied and thus it catches more matrices as null matrices.
References ComputeMatrix(), f_translate_x, f_translate_y, and sswf::Matrix::signed_matrix_t::m.
bool Matrix::operator!= | ( | const Matrix & | matrix | ) | const |
This operator compares two matrices to know whether they are inequal.
Note that the doubles are first transformed into 16.16 fixed point values and these are compared for inequality. This means less matrices may look inequal than what their exact definitions with doubles would imply.
References operator==().
bool Matrix::operator== | ( | const Matrix & | matrix | ) | const |
This operator compares two matrices to know whether they are equal or not.
Note that the doubles are first transformed into 16.16 fixed point values and these are compared for equality. This means more matrices may look equal than what their exact definitions with doubles would imply.
References ComputeMatrix(), f_translate_x, f_translate_y, and sswf::Matrix::signed_matrix_t::m.
Referenced by operator!=().
ErrorManager::error_code_t Matrix::Parse | ( | const Data & | data | ) |
The Save() function computes the matrix and then saves it in the specified data buffer.
It is valid to save an identity matrix.
[in] | data | The buffer where the matrix is to be saved |
References sswf::ErrorManager::ERROR_CODE_NONE, f_translate_x, f_translate_y, sswf::Data::GetBits(), sswf::Matrix::signed_matrix_t::m, sswf::Data::ReadAlign(), and UncomputeMatrix().
Referenced by sswf::State::Parse().
void Matrix::Reset | ( | void | ) |
The Reset() function sets all the parameters to no effect. (i.e. the identity matrix.)
References f_rotate, f_scale_x, f_scale_y, f_skew_0, f_skew_1, f_translate_x, and f_translate_y.
Referenced by Matrix(), sswf::State::Reset(), and sswf::Style::Reset().
void Matrix::Save | ( | Data & | data | ) |
The Save() function computes the matrix and then saves it in the specified data buffer.
It is valid to save an identity matrix.
[in] | data | The buffer where the matrix is to be saved |
References sswf::Data::Align(), ComputeMatrix(), f_translate_x, f_translate_y, sswf::Matrix::signed_matrix_t::m, sswf::TagBase::SIBitSize(), and sswf::Data::WriteBits().
Referenced by sswf::TagText::Save(), sswf::TagPlace::Save(), sswf::State::Save(), and sswf::Style::Save().
void Matrix::SetRotate | ( | double | rotate | ) |
Set the rotation in radian. The SetRotate() function takes a radian angle and saves it as the current rotation angle. This function is not cumulative. Instead the new angle overwrites any other angle previously defined with SetRotate().
[in] | rotate | The rotation angle |
sswf::Matrix::SetScale | ( | double | scale | ) | [inline] |
This function changes the matrix scaling. This function can be used to change the scaling uniformly in both directions. This is often used when you need to enlarge or reduce an object without losing its aspect ratio.
A call to this function is not cumulative. Each call sets the new scale to the specified value by overwriting the previous value.
It is equivalent to call SetScale() with the same value in x and y:
[in] | scale | Defines the new horizontal and vertical scaling |
sswf::Matrix::SetScale | ( | double | x, | |
double | y | |||
) | [inline] |
This function changes the matrix scaling. This function can be used to change the horizontal and vertical scaling with different values. This let's you scale objects exactly the way you want.
A call to this function is not cumulative. Each call sets the new scaling values to the specified (x, y) scaling by overwriting the previous values.
[in] | x | Defines the new horizontal scaling |
[in] | y | Defines the new vertical scaling |
sswf::Matrix::SetSkew | ( | double | skew0, | |
double | skew1 | |||
) | [inline] |
This function is used to change the skew parameters. The skew makes the top and bottom (or left and right) edges move horizontally (vertically) away from each others.
The skew defined by this function is not cumulative. Instead it replaces the current value with the new values.
The unit of the skew is the twips times the scaling factors.
[in] | skew0 | The horizontal skew |
[in] | skew1 | The vertical skew |
sswf::Matrix::SetTranslate | ( | long | x, | |
long | y | |||
) | [inline] |
Set the translation to (x, y). Previous translations are replaced by each new call to this function.
The translation is defined in twips and taken as long values. (i.e. 20 represents 1 pixel on the screen.)
[in] | x | The horizontal translation |
[in] | y | The vertical translation |
sswf::Matrix::SetScale(double scale)
References f_translate_x, and f_translate_y.
void Matrix::UncomputeMatrix | ( | const signed_matrix_t & | m | ) | [private] |
This function is used when we read a matrix from a Data buffer. We attempt to determine the scaling, rotation, and skewing.
[in] | m | The computed matrix to restore in this matrix |
Matrix::Load(const Data& data)
References f_rotate, f_scale_x, f_scale_y, f_skew_0, f_skew_1, sswf::Matrix::signed_matrix_t::m, and sswf::TagBase::Signed2Double().
Referenced by Parse().
double sswf::Matrix::f_rotate [private] |
Referenced by ComputeMatrix(), Reset(), SetRotate(), and UncomputeMatrix().
double sswf::Matrix::f_scale_x [private] |
Referenced by ComputeMatrix(), Reset(), SetScale(), and UncomputeMatrix().
double sswf::Matrix::f_scale_y [private] |
Referenced by ComputeMatrix(), Reset(), SetScale(), and UncomputeMatrix().
double sswf::Matrix::f_skew_0 [private] |
Referenced by ComputeMatrix(), Reset(), SetSkew(), and UncomputeMatrix().
double sswf::Matrix::f_skew_1 [private] |
Referenced by ComputeMatrix(), Reset(), SetSkew(), and UncomputeMatrix().
long sswf::Matrix::f_translate_x [private] |
Referenced by IsNull(), operator==(), Parse(), Reset(), Save(), and SetTranslate().
long sswf::Matrix::f_translate_y [private] |
Referenced by IsNull(), operator==(), Parse(), Reset(), Save(), and SetTranslate().