diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-12-30 20:38:21 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-12-31 00:10:00 +0100 |
commit | 5a068e585429c9aabfbb36f7c9f028c0acc578aa (patch) | |
tree | 4378bc2cbaf7f80bd277307729b72bb126cf197f /vcl/source/gdi/pdfwriter_impl.cxx | |
parent | f7a2f63994e22c99010c1d25a4493a8a0c57866e (diff) |
pdf: extract Matrix3 to it's own files
Change-Id: Ic855b01d8b812e4604b266427c4f646cd1625b86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86036
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/gdi/pdfwriter_impl.cxx')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 1ec13034a9bf..c5078143874c 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -543,136 +543,6 @@ void PDFWriterImpl::appendNonStrokingColor( const Color& rColor, OStringBuffer& } } -// matrix helper class -// TODO: use basegfx matrix class instead or derive from it -namespace vcl // TODO: use anonymous namespace to keep this class local -{ -/* for sparse matrices of the form (2D linear transformations) - * f[0] f[1] 0 - * f[2] f[3] 0 - * f[4] f[5] 1 - */ -class Matrix3 -{ - double f[6]; - - void set( const double *pn ) { for( int i = 0 ; i < 6; i++ ) f[i] = pn[i]; } -public: - Matrix3(); - - void skew( double alpha, double beta ); - void scale( double sx, double sy ); - void rotate( double angle ); - void translate( double tx, double ty ); - void invert(); - - double get(size_t i) const - { - return f[i]; - } - - Point transform( const Point& rPoint ) const; -}; -} - -Matrix3::Matrix3() -{ - // initialize to unity - f[0] = 1.0; - f[1] = 0.0; - f[2] = 0.0; - f[3] = 1.0; - f[4] = 0.0; - f[5] = 0.0; -} - -Point Matrix3::transform( const Point& rOrig ) const -{ - double x = static_cast<double>(rOrig.X()), y = static_cast<double>(rOrig.Y()); - return Point( static_cast<int>(x*f[0] + y*f[2] + f[4]), static_cast<int>(x*f[1] + y*f[3] + f[5]) ); -} - -void Matrix3::skew( double alpha, double beta ) -{ - double fn[6]; - double tb = tan( beta ); - fn[0] = f[0] + f[2]*tb; - fn[1] = f[1]; - fn[2] = f[2] + f[3]*tb; - fn[3] = f[3]; - fn[4] = f[4] + f[5]*tb; - fn[5] = f[5]; - if( alpha != 0.0 ) - { - double ta = tan( alpha ); - fn[1] += f[0]*ta; - fn[3] += f[2]*ta; - fn[5] += f[4]*ta; - } - set( fn ); -} - -void Matrix3::scale( double sx, double sy ) -{ - double fn[6]; - fn[0] = sx*f[0]; - fn[1] = sy*f[1]; - fn[2] = sx*f[2]; - fn[3] = sy*f[3]; - fn[4] = sx*f[4]; - fn[5] = sy*f[5]; - set( fn ); -} - -void Matrix3::rotate( double angle ) -{ - double fn[6]; - double fSin = sin(angle); - double fCos = cos(angle); - fn[0] = f[0]*fCos - f[1]*fSin; - fn[1] = f[0]*fSin + f[1]*fCos; - fn[2] = f[2]*fCos - f[3]*fSin; - fn[3] = f[2]*fSin + f[3]*fCos; - fn[4] = f[4]*fCos - f[5]*fSin; - fn[5] = f[4]*fSin + f[5]*fCos; - set( fn ); -} - -void Matrix3::translate( double tx, double ty ) -{ - f[4] += tx; - f[5] += ty; -} - -void Matrix3::invert() -{ - // short circuit trivial cases - if( f[1]==f[2] && f[1]==0.0 && f[0]==f[3] && f[0]==1.0 ) - { - f[4] = -f[4]; - f[5] = -f[5]; - return; - } - - // check determinant - const double fDet = f[0]*f[3]-f[1]*f[2]; - if( fDet == 0.0 ) - return; - - // invert the matrix - double fn[6]; - fn[0] = +f[3] / fDet; - fn[1] = -f[1] / fDet; - fn[2] = -f[2] / fDet; - fn[3] = +f[0] / fDet; - - // apply inversion to translation - fn[4] = -(f[4]*fn[0] + f[5]*fn[2]); - fn[5] = -(f[4]*fn[1] + f[5]*fn[3]); - - set( fn ); -} - PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation ) : m_pWriter( pWriter ), |