include/vcl/test/GraphicsRenderTests.hxx |    1 
 vcl/Library_vcl.mk                       |    1 
 vcl/backendtest/GraphicsRenderTests.cxx  |   20 +++++++-
 vcl/backendtest/outputdevice/common.cxx  |   73 +++++++++++++++++++++++++++++++
 vcl/backendtest/outputdevice/text.cxx    |   34 ++++++++++++++
 vcl/inc/test/outputdevice.hxx            |    6 ++
 vcl/qa/cppunit/BackendTest.cxx           |   12 +++++
 7 files changed, 145 insertions(+), 2 deletions(-)

New commits:
commit 2b8d3d9a209b8020dac734b96a43292332aa5d44
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Thu Jul 15 16:01:09 2021 +0530
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Aug 26 05:52:34 2021 +0200

    backendtest: Text Drawing test
    
    This test revolves around drawing text to a Virtual device
    and testing if it's rendered at the expected position.
    
    Change-Id: Iccfe382103632822befe84d5933d64eacefffa24
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118976
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/vcl/test/GraphicsRenderTests.hxx 
b/include/vcl/test/GraphicsRenderTests.hxx
index 974c47135271..8599cb5893fc 100644
--- a/include/vcl/test/GraphicsRenderTests.hxx
+++ b/include/vcl/test/GraphicsRenderTests.hxx
@@ -117,6 +117,7 @@ class VCL_PLUGIN_PUBLIC GraphicsRenderTests
     void testClosedBezierWithPolyline();
     void testClosedBezierWithPolygon();
     void testFilledAsymmetricalDropShape();
+    void testTextDrawing();
     static OUString returnTestStatus(vcl::test::TestResult const result);
     void runALLTests();
     void appendTestResult(OUString aTestName, OUString aTestStatus, Bitmap 
aTestBitmap = Bitmap());
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index ec5445f2968c..0f714a0ec9b3 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -503,6 +503,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/backendtest/outputdevice/polypolygon_b2d \
     vcl/backendtest/outputdevice/polyline \
     vcl/backendtest/outputdevice/polyline_b2d \
+    vcl/backendtest/outputdevice/text \
     vcl/backendtest/outputdevice/rectangle \
     vcl/backendtest/GraphicsRenderTests \
     vcl/jsdialog/enabled \
diff --git a/vcl/backendtest/GraphicsRenderTests.cxx 
b/vcl/backendtest/GraphicsRenderTests.cxx
index 1ffc8d835cd6..1b98dead0264 100644
--- a/vcl/backendtest/GraphicsRenderTests.cxx
+++ b/vcl/backendtest/GraphicsRenderTests.cxx
@@ -1472,13 +1472,28 @@ void 
GraphicsRenderTests::testFilledAsymmetricalDropShape()
     vcl::test::OutputDeviceTestPolygon aOutDevTest;
     Bitmap aBitmap = aOutDevTest.setupFilledAsymmetricalDropShape();
     OUString aTestName = "testFilledAsymmetricalDropShape";
+    vcl::test::TestResult eResult
+        = 
vcl::test::OutputDeviceTestLine::checkFilledAsymmetricalDropShape(aBitmap);
+    appendTestResult(aTestName, returnTestStatus(eResult),
+                     (m_aStoreResultantBitmap ? aBitmap : Bitmap()));
+    if (m_aStoreResultantBitmap)
+    {
+        BitmapEx aBitmapEx(aBitmap);
+        exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", 
aBitmapEx);
+    }
+}
+
+void GraphicsRenderTests::testTextDrawing()
+{
+    vcl::test::OutputDeviceTestText aOutDevTest;
+    Bitmap aBitmap = aOutDevTest.setupTextBitmap();
+    OUString aTestName = "testTextDrawing";
     if (!SHOULD_ASSERT)
     {
         appendTestResult(aTestName, "SKIPPED");
         return;
     }
-    vcl::test::TestResult eResult
-        = 
vcl::test::OutputDeviceTestLine::checkFilledAsymmetricalDropShape(aBitmap);
+    vcl::test::TestResult eResult = 
vcl::test::OutputDeviceTestLine::checkTextLocation(aBitmap);
     appendTestResult(aTestName, returnTestStatus(eResult),
                      (m_aStoreResultantBitmap ? aBitmap : Bitmap()));
     if (m_aStoreResultantBitmap)
@@ -1559,6 +1574,7 @@ void GraphicsRenderTests::runALLTests()
     testClosedBezierWithPolyline();
     testClosedBezierWithPolygon();
     testFilledAsymmetricalDropShape();
+    testTextDrawing();
 }
 
 void GraphicsRenderTests::appendTestResult(OUString aTestName, OUString 
aTestStatus,
diff --git a/vcl/backendtest/outputdevice/common.cxx 
b/vcl/backendtest/outputdevice/common.cxx
index ccf78b1c2df2..b548571e22bb 100644
--- a/vcl/backendtest/outputdevice/common.cxx
+++ b/vcl/backendtest/outputdevice/common.cxx
@@ -895,6 +895,79 @@ TestResult 
OutputDeviceTestCommon::checkFilledAsymmetricalDropShape(Bitmap& rBit
     return aResult;
 }
 
+TestResult OutputDeviceTestCommon::checkTextLocation(Bitmap& rBitmap)
+{
+    BitmapScopedWriteAccess pAccess(rBitmap);
+
+    TestResult aResult = TestResult::Passed;
+
+    //The limit to which error would be tolerated.
+    tools::Long textThreshold = 3;
+    tools::Long textWidth = 3, textHeight = 8;
+    tools::Long deviationX = 0, deviationY = 0;
+    tools::Long verticalStart = 0, verticalEnd = 0;
+    tools::Long horizontalStart = 0, horizontalEnd = 0;
+    tools::Long midX = pAccess->Width() / 2.0;
+    tools::Long midY = pAccess->Height() / 2.0;
+    bool insideFlag = false;
+
+    //Traversing horizontally
+    for (tools::Long x = 0, y = pAccess->Height() / 2.0; x < pAccess->Width(); 
++x)
+    {
+        if (pAccess->GetPixel(y, x) != constBackgroundColor)
+        {
+            if (!insideFlag)
+            {
+                horizontalStart = x;
+                insideFlag = true;
+            }
+            else
+            {
+                horizontalEnd = x;
+            }
+        }
+    }
+
+    deviationX = abs(midX - horizontalStart);
+    midY -= midY / 2.0;
+    midY += 1;
+
+    insideFlag = false;
+    //Traversing vertically
+    for (tools::Long x = 0, y = pAccess->Height() / 2.0; x < 
pAccess->Height(); ++x)
+    {
+        if (pAccess->GetPixel(x, y) != constBackgroundColor)
+        {
+            if (!insideFlag)
+            {
+                verticalStart = x;
+                insideFlag = true;
+            }
+            else
+            {
+                verticalEnd = x;
+            }
+        }
+    }
+
+    deviationY = abs(midY - verticalStart);
+
+    if (deviationX != 0 || deviationY != 0 || abs(horizontalStart - 
horizontalEnd) + 1 != textWidth
+        || abs(verticalStart - verticalEnd) + 1 != textHeight)
+    {
+        aResult = TestResult::PassedWithQuirks;
+    }
+
+    if (deviationX > textThreshold || deviationY > textThreshold
+        || abs((abs(horizontalStart - horizontalEnd) + 1) - textWidth) > 
textThreshold
+        || abs((abs(verticalStart - verticalEnd) + 1) - textHeight) > 
textThreshold)
+    {
+        aResult = TestResult::Failed;
+    }
+
+    return aResult;
+}
+
 // Check 'count' pixels from (x,y) in (addX,addY) direction, the color values 
must not decrease.
 static bool checkGradient(BitmapScopedWriteAccess& pAccess, int x, int y, int 
count, int addX, int addY)
 {
diff --git a/vcl/backendtest/outputdevice/text.cxx 
b/vcl/backendtest/outputdevice/text.cxx
new file mode 100644
index 000000000000..5e53d900babd
--- /dev/null
+++ b/vcl/backendtest/outputdevice/text.cxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: offset; indent-tabs-mode: nil; c-basic-offset: 
offset -*- */
+/*
+ * 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 <test/outputdevice.hxx>
+
+namespace vcl::test
+{
+Bitmap OutputDeviceTestText::setupTextBitmap()
+{
+    initialSetup(21, 21, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    tools::Long midX = (maVDRectangle.Right() - maVDRectangle.Left()) / 2.0;
+    tools::Long midY = (maVDRectangle.Bottom() - maVDRectangle.Top()) / 2.0;
+
+    vcl::Font Font("DejaVu Sans", "Book", Size(0, 10));
+
+    mpVirtualDevice->Erase();
+    mpVirtualDevice->SetFont(Font);
+    mpVirtualDevice->SetTextColor(COL_LIGHTRED);
+    mpVirtualDevice->DrawText(Point(midX, midY - midY / 2), "I");
+
+    return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+}
+}
\ No newline at end of file
diff --git a/vcl/inc/test/outputdevice.hxx b/vcl/inc/test/outputdevice.hxx
index eceb3dd8f81e..df10da2bbe51 100644
--- a/vcl/inc/test/outputdevice.hxx
+++ b/vcl/inc/test/outputdevice.hxx
@@ -92,6 +92,7 @@ public:
     static TestResult checkHalfEllipse(Bitmap& rBitmap, bool aEnableAA = 
false);
     static TestResult checkClosedBezier(Bitmap& rBitmap);
     static TestResult checkFilledAsymmetricalDropShape(Bitmap& rBitmap);
+    static TestResult checkTextLocation(Bitmap& rBitmap);
 private:
     static TestResult checkLineCap(Bitmap& rBitmap, css::drawing::LineCap 
lineCap);
     static TestResult checkLineJoin(Bitmap& rBitmap, basegfx::B2DLineJoin 
lineJoin);
@@ -260,6 +261,11 @@ public:
     static TestResult checkClip(Bitmap& rBitmap);
 };
 
+class VCL_DLLPUBLIC OutputDeviceTestText : public OutputDeviceTestCommon
+{
+public:
+    Bitmap setupTextBitmap();
+};
 
 } // end namespace vcl::test
 
diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index 157489731c13..0146d1dabd50 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -1111,6 +1111,16 @@ public:
 #endif
     }
 
+    void testDrawingText()
+    {
+        vcl::test::OutputDeviceTestText aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupTextBitmap();
+        auto eResult = 
vcl::test::OutputDeviceTestCommon::checkTextLocation(aBitmap);
+        exportImage("17-01_test_text_Drawing.png", aBitmap);
+        if (SHOULD_ASSERT)
+            CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
+    }
+
     void testTdf124848()
     {
 // TODO: This unit test is not executed for macOS unless bitmap scaling is 
implemented
@@ -1270,6 +1280,8 @@ public:
     CPPUNIT_TEST(testDrawBlendExtended);
     CPPUNIT_TEST(testDrawAlphaBitmapMirrored);
 
+    CPPUNIT_TEST(testDrawingText);
+
     CPPUNIT_TEST(testTdf124848);
     CPPUNIT_TEST(testTdf136171);
 

Reply via email to