summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-12-30 20:38:21 +0100
committerTomaž Vajngerl <quikee@gmail.com>2019-12-31 00:10:00 +0100
commit5a068e585429c9aabfbb36f7c9f028c0acc578aa (patch)
tree4378bc2cbaf7f80bd277307729b72bb126cf197f /vcl
parentf7a2f63994e22c99010c1d25a4493a8a0c57866e (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')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/inc/pdf/Matrix3.hxx54
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx130
-rw-r--r--vcl/source/gdi/pdfwriter_impl.hxx2
-rw-r--r--vcl/source/pdf/Matrix3.cxx117
5 files changed, 173 insertions, 131 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index d557ce3f0bc4..e2a3fc9fb889 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -317,6 +317,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/gdi/CommonSalLayout \
vcl/source/gdi/TypeSerializer \
vcl/source/pdf/ResourceDict \
+ vcl/source/pdf/Matrix3 \
vcl/source/graphic/GraphicLoader \
vcl/source/graphic/GraphicObject \
vcl/source/graphic/GraphicObject2 \
diff --git a/vcl/inc/pdf/Matrix3.hxx b/vcl/inc/pdf/Matrix3.hxx
new file mode 100644
index 000000000000..c36332015c13
--- /dev/null
+++ b/vcl/inc/pdf/Matrix3.hxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_PDF_MATRIX3_HXX
+#define INCLUDED_VCL_INC_PDF_MATRIX3_HXX
+
+#include <vcl/dllapi.h>
+#include <tools/gen.hxx>
+
+namespace vcl::pdf
+{
+// matrix helper class
+// TODO: use basegfx matrix class instead or derive from it
+
+/* 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;
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 ),
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index be201c3be127..cccd38fe161f 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -27,6 +27,7 @@
#include <pdf/ResourceDict.hxx>
#include <pdf/BitmapID.hxx>
+#include <pdf/Matrix3.hxx>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
@@ -97,7 +98,6 @@ namespace vcl
using namespace vcl::pdf;
class PDFStreamIf;
-class Matrix3;
namespace filter
{
diff --git a/vcl/source/pdf/Matrix3.cxx b/vcl/source/pdf/Matrix3.cxx
new file mode 100644
index 000000000000..22e5c4d73344
--- /dev/null
+++ b/vcl/source/pdf/Matrix3.cxx
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <pdf/Matrix3.hxx>
+#include <cmath>
+
+namespace vcl::pdf
+{
+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);
+}
+
+} // end vcl::pdf
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */