summaryrefslogtreecommitdiffstats
path: root/drawinglayer/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-04-18 16:53:48 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-04-18 19:06:39 +0000
commit422f10c5d7ebe6f4b778636c9c1eb6dbdf708a27 (patch)
tree48cc1010c22ba6113fc70ae79ef6ed086331c981 /drawinglayer/qa
parenttdf#99371 fix for DDE link update via Function Wizard (diff)
downloadcore-422f10c5d7ebe6f4b778636c9c1eb6dbdf708a27.tar.gz
core-422f10c5d7ebe6f4b778636c9c1eb6dbdf708a27.zip
tdf#99315 VclPixelProcessor2D: fix double border line width
Regression from commit 2c91cb08d65cd35fa8ef6eaca3677aa82fb58cbe (better drawing support for borders of different width, fdo#33634, 2012-04-04), the problem is that previously the width of inner/outer double border lines got rounded to integer values quite early, but after the commit they are kept at a double precision for much longer, which needs pixel correction in VclPixelProcessor2D. Example: if the border with is 1.47, and the line gets moved by 0.2 pixels, then the inner and outer edge of the line will be 0.2 and 1.67, which gets rounded to 0 -> 2 in the pixel processor. Previously the input was rounded to 1, so moving by 0.2 resulted in 0.2 -> 1.2, which got rounded to 0 -> 1. The result is that sometimes the line width is 1 pixel wider than expected. Fix the problem by allowing VclPixelProcessor2D to request pixel correction from BorderLinePrimitive2D. It wouldn't be possible to do pixel correction only in VclPixelProcessor2D, as it has no idea what to correct: it only gets polygons, so it has no idea if e.g. the top of a polygon is the outer edge of a top border line or an inner edge of a bottom border line. Change-Id: I1971f3a952fbcdc598ab46c659e12d976c13cbe6 Reviewed-on: https://gerrit.libreoffice.org/24221 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'drawinglayer/qa')
-rw-r--r--drawinglayer/qa/unit/border.cxx71
1 files changed, 69 insertions, 2 deletions
diff --git a/drawinglayer/qa/unit/border.cxx b/drawinglayer/qa/unit/border.cxx
index 6f49a2447b77..9f0c62187801 100644
--- a/drawinglayer/qa/unit/border.cxx
+++ b/drawinglayer/qa/unit/border.cxx
@@ -8,7 +8,6 @@
*/
#include <cppunit/TestAssert.h>
-#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
@@ -17,20 +16,27 @@
#include <drawinglayer/geometry/viewinformation2d.hxx>
#include <drawinglayer/primitive2d/borderlineprimitive2d.hxx>
#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
+#include <drawinglayer/processor2d/baseprocessor2d.hxx>
+#include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
#include <rtl/ref.hxx>
+#include <test/bootstrapfixture.hxx>
+#include <vcl/vclptr.hxx>
+#include <vcl/virdev.hxx>
using namespace com::sun::star;
namespace
{
-class DrawinglayerBorderTest : public CppUnit::TestFixture
+class DrawinglayerBorderTest : public test::BootstrapFixture
{
public:
void testDoubleDecompositionSolid();
+ void testDoublePixelProcessing();
CPPUNIT_TEST_SUITE(DrawinglayerBorderTest);
CPPUNIT_TEST(testDoubleDecompositionSolid);
+ CPPUNIT_TEST(testDoublePixelProcessing);
CPPUNIT_TEST_SUITE_END();
};
@@ -74,6 +80,67 @@ void DrawinglayerBorderTest::testDoubleDecompositionSolid()
CPPUNIT_ASSERT_DOUBLES_EQUAL(fLeftWidth, rRange.getHeight(), basegfx::fTools::getSmallValue());
}
+void DrawinglayerBorderTest::testDoublePixelProcessing()
+{
+ // Create a pixel processor.
+ ScopedVclPtrInstance<VirtualDevice> pDev;
+ drawinglayer::geometry::ViewInformation2D aView;
+ std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*pDev, aView));
+ CPPUNIT_ASSERT(pProcessor);
+ GDIMetaFile aMetaFile;
+ // Start recording after the processor is created, so we can test the pixel processor.
+ aMetaFile.Record(pDev);
+
+ // Create a border line primitive that's similar to the one from the bugdoc:
+ // 1.47 pixels is 0.03cm at 130% zoom and 96 DPI.
+ basegfx::B2DPoint aStart(0, 20);
+ basegfx::B2DPoint aEnd(100, 20);
+ double fLeftWidth = 1.47;
+ double fDistance = 1.47;
+ double fRightWidth = 1.47;
+ double fExtendLeftStart = 0;
+ double fExtendLeftEnd = 0;
+ double fExtendRightStart = 0;
+ double fExtendRightEnd = 0;
+ basegfx::BColor aColorRight;
+ basegfx::BColor aColorLeft;
+ basegfx::BColor aColorGap;
+ bool bHasGapColor = false;
+ sal_Int16 nStyle = table::BorderLineStyle::DOUBLE;
+ rtl::Reference<drawinglayer::primitive2d::BorderLinePrimitive2D> xBorder(new drawinglayer::primitive2d::BorderLinePrimitive2D(aStart, aEnd, fLeftWidth, fDistance, fRightWidth, fExtendLeftStart, fExtendLeftEnd, fExtendRightStart, fExtendRightEnd, aColorRight, aColorLeft, aColorGap, bHasGapColor, nStyle));
+ drawinglayer::primitive2d::Primitive2DContainer aPrimitives;
+ aPrimitives.push_back(drawinglayer::primitive2d::Primitive2DReference(xBorder.get()));
+
+ // Process the primitives.
+ pProcessor->process(aPrimitives);
+
+ // Now assert the height of the outer (second) border polygon.
+ aMetaFile.Stop();
+ aMetaFile.WindStart();
+ bool bFirst = true;
+ sal_Int32 nHeight = 0;
+ for(std::size_t nAction = 0; nAction < aMetaFile.GetActionSize(); ++nAction)
+ {
+ MetaAction* pAction = aMetaFile.GetAction(nAction);
+ if (pAction->GetType() == MetaActionType::POLYPOLYGON)
+ {
+ if (bFirst)
+ {
+ bFirst = false;
+ continue;
+ }
+
+ auto pMPPAction = static_cast<MetaPolyPolygonAction*>(pAction);
+ const tools::PolyPolygon& rPolyPolygon = pMPPAction->GetPolyPolygon();
+ nHeight = rPolyPolygon.GetBoundRect().getHeight();
+ }
+ }
+ sal_Int32 nExpectedHeight = std::round(fRightWidth);
+ // This was 2, and should be 1: if the logical requested width is 1.47,
+ // then that must be 1 px on the screen, not 2.
+ CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(DrawinglayerBorderTest);
}