summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-06-28 00:03:19 +0900
committerTomaž Vajngerl <quikee@gmail.com>2019-07-01 04:49:07 +0200
commitbfc19d77cb8db445f1c6123347c19a4c0c6a6cf8 (patch)
treed5deaaa44975838dec487d977d064c37080cf40e /basegfx
parent45a2eecfee472d8822130a90999b46ad371dee95 (diff)
Improve the looks of a wave line by draw it with bezier curves
This adds drawing the wave line (typically used to underline the wrongly spelled words) with bezier curves. Previously the wave lines were drawn with drawing pixels, which didn't look that good, especially on HiDPI display, so the looks of wave lines now is therefor much better. The creation of the wave line as a polygon has been added to the basegfx module, so it can be reused if needed. In addition, everytime we draw the waveline, we have to enable antialiasing, to have a much better quality of the curves. By default the antialiasing is disabled for some reason. This also adds ScopedStates.hxx file which currently includes ScopedAntialiasing, which sets the antialiasing to a certain state for the time the object is in scope, and then sets it back to the original state. Change-Id: I4b866fc5d69725eb7f6f78a1acf4176b1205aa73 Reviewed-on: https://gerrit.libreoffice.org/74810 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/Library_basegfx.mk3
-rw-r--r--basegfx/source/polygon/WaveLine.cxx52
2 files changed, 54 insertions, 1 deletions
diff --git a/basegfx/Library_basegfx.mk b/basegfx/Library_basegfx.mk
index 4a89d4995583..8ba2fb7cb32c 100644
--- a/basegfx/Library_basegfx.mk
+++ b/basegfx/Library_basegfx.mk
@@ -39,7 +39,7 @@ $(eval $(call gb_Library_add_exception_objects,basegfx,\
basegfx/source/matrix/b2dhommatrixtools \
basegfx/source/matrix/b3dhommatrix \
basegfx/source/matrix/b3dhommatrixtools \
- basegfx/source/numeric/ftools \
+ basegfx/source/numeric/ftools \
basegfx/source/point/b2dpoint \
basegfx/source/point/b2ipoint \
basegfx/source/point/b3dpoint \
@@ -58,6 +58,7 @@ $(eval $(call gb_Library_add_exception_objects,basegfx,\
basegfx/source/polygon/b3dpolygontools \
basegfx/source/polygon/b3dpolypolygon \
basegfx/source/polygon/b3dpolypolygontools \
+ basegfx/source/polygon/WaveLine \
basegfx/source/range/b2dpolyrange \
basegfx/source/range/b2drange \
basegfx/source/range/b2drangeclipper \
diff --git a/basegfx/source/polygon/WaveLine.cxx b/basegfx/source/polygon/WaveLine.cxx
new file mode 100644
index 000000000000..8385cef7be1b
--- /dev/null
+++ b/basegfx/source/polygon/WaveLine.cxx
@@ -0,0 +1,52 @@
+/* -*- 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 <basegfx/polygon/WaveLine.hxx>
+#include <basegfx/point/b2dpoint.hxx>
+
+namespace basegfx
+{
+BASEGFX_DLLPUBLIC B2DPolygon createWaveLinePolygon(basegfx::B2DRectangle const& rRectangle)
+{
+ basegfx::B2DPolygon aPolygon;
+
+ double fWaveHeight = rRectangle.getHeight();
+ // Wavelength depends on the wave height so it looks nice
+ double fHalfWaveLength = fWaveHeight + 1.0;
+ double fWaveAmplitude = fWaveHeight / 2.0;
+
+ double fLastX = rRectangle.getMinX();
+ double fBaseY = rRectangle.getMinY() + fWaveAmplitude;
+ double fDirection = 1.0;
+
+ // In quadratic bezier the curve is 1/2 of the control height
+ // so we need to compensate for that.
+ double fHeightCompensation = 2.0;
+
+ aPolygon.append(basegfx::B2DPoint(fLastX, fBaseY));
+
+ for (double fI = fHalfWaveLength; fI <= rRectangle.getWidth(); fI += fHalfWaveLength)
+ {
+ basegfx::B2DPoint aPoint(fLastX + fHalfWaveLength, fBaseY);
+ basegfx::B2DPoint aControl(fLastX + (fHalfWaveLength / 2.0),
+ fBaseY + fDirection * fWaveAmplitude * fHeightCompensation);
+
+ aPolygon.appendQuadraticBezierSegment(aControl, aPoint);
+
+ fLastX = aPoint.getX(); // next iteration
+ fDirection *= -1.0; // fDirection iterates between 1 and -1
+ }
+
+ return aPolygon;
+}
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */