diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-05-26 11:03:06 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-05-26 15:55:37 +0200 |
commit | 3a93748c9c4faadeb9ab4eb21706d187677549fa (patch) | |
tree | a89371682cb4729a15df1630cf26a19fb6d0e8aa /vcl/backendtest | |
parent | 6cd885b46bf168a1fe0d91231a1b6d283f813ed3 (diff) |
use Skia to do dashed lines, no need to do it manually (tdf#130431)
Change-Id: Id5efe7227f3c2bcb5ef6f1b990327e72014e8c47
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94857
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/backendtest')
-rw-r--r-- | vcl/backendtest/VisualBackendTest.cxx | 9 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/common.cxx | 5 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/line.cxx | 87 |
3 files changed, 100 insertions, 1 deletions
diff --git a/vcl/backendtest/VisualBackendTest.cxx b/vcl/backendtest/VisualBackendTest.cxx index 5daa9a642d55..08efc1d381a3 100644 --- a/vcl/backendtest/VisualBackendTest.cxx +++ b/vcl/backendtest/VisualBackendTest.cxx @@ -576,7 +576,7 @@ public: } else if (mnTest % gnNumberOfTests == 7) { - std::vector<tools::Rectangle> aRegions = setupRegions(3, 1, nWidth, nHeight); + std::vector<tools::Rectangle> aRegions = setupRegions(2, 2, nWidth, nHeight); aRectangle = aRegions[index++]; { @@ -587,6 +587,13 @@ public: } aRectangle = aRegions[index++]; { + vcl::test::OutputDeviceTestLine aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDashedLine(); + assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkDashedLine(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + aRectangle = aRegions[index++]; + { vcl::test::OutputDeviceTestGradient aOutDevTest; Bitmap aBitmap = aOutDevTest.setupLinearGradient(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx index f9052fb77201..a5d032315474 100644 --- a/vcl/backendtest/outputdevice/common.cxx +++ b/vcl/backendtest/outputdevice/common.cxx @@ -416,6 +416,11 @@ TestResult OutputDeviceTestCommon::checkRectangles(Bitmap& aBitmap, std::vector< return aReturnValue; } +TestResult OutputDeviceTestCommon::checkRectangle(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor) +{ + return checkRect(rBitmap, aLayerNumber, aExpectedColor); +} + tools::Rectangle OutputDeviceTestCommon::alignToCenter(tools::Rectangle aRect1, tools::Rectangle aRect2) { Point aPoint((aRect1.GetWidth() / 2.0) - (aRect2.GetWidth() / 2.0), diff --git a/vcl/backendtest/outputdevice/line.cxx b/vcl/backendtest/outputdevice/line.cxx index b9236dcc210d..5b5d73261135 100644 --- a/vcl/backendtest/outputdevice/line.cxx +++ b/vcl/backendtest/outputdevice/line.cxx @@ -10,6 +10,11 @@ #include <test/outputdevice.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <vcl/bitmapaccess.hxx> + +#include <list> + namespace vcl::test { namespace @@ -108,6 +113,88 @@ Bitmap OutputDeviceTestLine::setupAALines() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestLine::setupDashedLine() +{ + initialSetup(13, 13, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + tools::Rectangle rectangle = maVDRectangle; + rectangle.shrink(2); + + std::vector stroke({ 2.0, 1.0 }); + mpVirtualDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(), + basegfx::B2DPolygon{ + basegfx::B2DPoint(rectangle.getX(), rectangle.getY()), + basegfx::B2DPoint(rectangle.getX(), rectangle.getY() + rectangle.getHeight()), + basegfx::B2DPoint(rectangle.getX() + rectangle.getWidth(), + rectangle.getY() + rectangle.getHeight()), + basegfx::B2DPoint(rectangle.getX() + rectangle.getWidth(), rectangle.getY()), + basegfx::B2DPoint(rectangle.getX(), rectangle.getY())}, + 1, 0, &stroke, basegfx::B2DLineJoin::NONE, css::drawing::LineCap_BUTT, basegfx::deg2rad(15.0), true ); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +TestResult OutputDeviceTestLine::checkDashedLine(Bitmap& rBitmap) +{ + TestResult returnValue = TestResult::Passed; + for (int i = 0; i < 7; i++) + { + TestResult eResult = TestResult::Passed; + if( i == 2 ) + { + // Build a sequence of pixels for the drawn rectangle border, + // check that they alternate appropriately (there should be + // normally 2 line, 1 background). + std::list< bool > dash; // true - line color, false - background + const int width = rBitmap.GetSizePixel().Width(); + const int height = rBitmap.GetSizePixel().Height(); + BitmapReadAccess access(rBitmap); + for( int x = 2; x < width - 2; ++x ) + dash.push_back( access.GetPixel( 2, x ) == constLineColor ); + for( int y = 3; y < height - 3; ++y ) + dash.push_back( access.GetPixel( y, width - 3 ) == constLineColor ); + for( int x = width - 3; x >= 2; --x ) + dash.push_back( access.GetPixel( height - 3, x ) == constLineColor ); + for( int y = height - 4; y >= 3; --y ) + dash.push_back( access.GetPixel( y, 2 ) == constLineColor ); + for( int x = 2; x < width - 2; ++x ) // repeat, to check also the corner + dash.push_back( access.GetPixel( 2, x ) == constLineColor ); + bool last = false; + int lastCount = 0; + while( !dash.empty()) + { + if( dash.front() == last ) + { + ++lastCount; + if( lastCount > ( last ? 4 : 3 )) + eResult = TestResult::Failed; + else if( lastCount > ( last ? 3 : 2 ) && eResult != TestResult::Failed) + eResult = TestResult::PassedWithQuirks; + } + else + { + last = dash.front(); + lastCount = 1; + } + dash.pop_front(); + } + } + else + { + eResult = OutputDeviceTestCommon::checkRectangle(rBitmap, i, constBackgroundColor); + } + + if (eResult == TestResult::Failed) + returnValue = TestResult::Failed; + if (eResult == TestResult::PassedWithQuirks && returnValue != TestResult::Failed) + returnValue = TestResult::PassedWithQuirks; + } + return returnValue; +} + } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |