diff options
author | Khaled Hosny <khaled@libreoffice.org> | 2023-06-19 14:44:30 +0300 |
---|---|---|
committer | خالد حسني <khaled@libreoffice.org> | 2023-06-19 20:46:25 +0200 |
commit | 5dfaecfd87df45953f6d4a85704aab9eb99b0d0e (patch) | |
tree | 4f0cd9039c184ec3b768d9fafa84b0029613a071 /cppcanvas | |
parent | 1f7a367f0d3722502561701cbafae448cb11cbb3 (diff) |
tdf#155810: Add test
Change-Id: I7cea421778335e8d5dd344dd04efdba843945383
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153264
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
Diffstat (limited to 'cppcanvas')
-rw-r--r-- | cppcanvas/qa/unit/test.cxx | 133 |
1 files changed, 132 insertions, 1 deletions
diff --git a/cppcanvas/qa/unit/test.cxx b/cppcanvas/qa/unit/test.cxx index 9454df0f2ecc..63d75c61bff2 100644 --- a/cppcanvas/qa/unit/test.cxx +++ b/cppcanvas/qa/unit/test.cxx @@ -11,17 +11,55 @@ #include <sal/config.h> -#include <test/bootstrapfixture.hxx> #include <vcl/wrkwin.hxx> #include <vcl/canvastools.hxx> +#include <vcl/virdev.hxx> +#include <vcl/gdimtf.hxx> +#include <vcl/metaact.hxx> #include <com/sun/star/rendering/XBitmap.hpp> #include <com/sun/star/rendering/XCanvas.hpp> #include <com/sun/star/rendering/XBitmapCanvas.hpp> +#include <cppcanvas/vclfactory.hxx> + using namespace ::com::sun::star; +static std::ostream& operator<<(std::ostream& rStream, const KernArray& rArray) +{ + if (rArray.empty()) + { + rStream << "{ }"; + return rStream; + } + + rStream << "{ "; + for (size_t i = 0; i < rArray.size() - 1; i++) + rStream << rArray[i] << ", "; + rStream << rArray.back(); + rStream << " }"; + return rStream; +} + +static std::ostream& operator<<(std::ostream& rStream, const std::vector<sal_Bool>& rVec) +{ + if (rVec.empty()) + { + rStream << "{ }"; + return rStream; + } + + rStream << "{ "; + for (size_t i = 0; i < rVec.size() - 1; i++) + rStream << std::boolalpha << bool(rVec[i]) << ", "; + rStream << std::boolalpha << bool(rVec.back()); + rStream << " }"; + return rStream; +} + +#include <test/bootstrapfixture.hxx> + class CanvasTest : public test::BootstrapFixture { public: @@ -70,6 +108,99 @@ CPPUNIT_TEST_FIXTURE(CanvasTest, testComposite) } } +CPPUNIT_TEST_FIXTURE(CanvasTest, testTdf155810) +{ + GDIMetaFile aInputMetaFile, aOutputMetaFile; + KernArray aDXArray; + std::vector<sal_Bool> aKashidaArray; + + // First create a meta file with a text array action that has Kashida adjustments. + { + ScopedVclPtrInstance<VirtualDevice> pDev; + + vcl::Font aFont(u"Noto Naskh Arabic", u"Regular", Size(0, 72)); + pDev->SetFont(aFont); + + aInputMetaFile.Record(pDev.get()); + + OUString aText(u"خالد"); + pDev->GetTextArray(aText, &aDXArray); + + auto nKashida = 200; + aDXArray.set(0, aDXArray[0] + nKashida); + aDXArray.set(2, aDXArray[2] + nKashida); + aKashidaArray = { true, false, true, false }; + + pDev->DrawTextArray(Point(0, 0), aText, aDXArray, aKashidaArray, 0, -1); + + aInputMetaFile.Stop(); + } + + // Then draw it using canvas + { + ScopedVclPtrInstance<VirtualDevice> pDev; + + aOutputMetaFile.Record(pDev.get()); + + auto xCanvas = pDev->GetCanvas(); + CPPUNIT_ASSERT(xCanvas.is()); + auto pCanvas = cppcanvas::VCLFactory::createCanvas(xCanvas); + + auto pRenderer = cppcanvas::VCLFactory::createRenderer(pCanvas, aInputMetaFile, {}); + pRenderer->draw(); + + aOutputMetaFile.Stop(); + } + + // Then check that the text array drawn by the canvas renderer didn’t loose + // the Kashida insertion positions. + { + auto pInputAction = aInputMetaFile.GetAction(aInputMetaFile.GetActionSize() - 1); + auto pOutputAction = aOutputMetaFile.GetAction(aOutputMetaFile.GetActionSize() - 2); + + CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTARRAY, pInputAction->GetType()); + CPPUNIT_ASSERT_EQUAL(pInputAction->GetType(), pOutputAction->GetType()); + + MetaTextArrayAction* pInputTextAction = static_cast<MetaTextArrayAction*>(pInputAction); + MetaTextArrayAction* pOutputTextAction = static_cast<MetaTextArrayAction*>(pOutputAction); + + CPPUNIT_ASSERT_EQUAL(pInputTextAction->GetDXArray(), aDXArray); + CPPUNIT_ASSERT_EQUAL(pInputTextAction->GetDXArray(), pOutputTextAction->GetDXArray()); + + CPPUNIT_ASSERT_EQUAL(pInputTextAction->GetKashidaArray(), aKashidaArray); + CPPUNIT_ASSERT_EQUAL(pInputTextAction->GetKashidaArray(), + pOutputTextAction->GetKashidaArray()); + } + + // Now, test drawSubset + { + ScopedVclPtrInstance<VirtualDevice> pDev; + + aOutputMetaFile.Clear(); + aOutputMetaFile.Record(pDev.get()); + + auto xCanvas = pDev->GetCanvas(); + CPPUNIT_ASSERT(xCanvas.is()); + auto pCanvas = cppcanvas::VCLFactory::createCanvas(xCanvas); + + auto pRenderer = cppcanvas::VCLFactory::createRenderer(pCanvas, aInputMetaFile, {}); + pRenderer->drawSubset(1, 3); + + aOutputMetaFile.Stop(); + } + + { + auto pOutputAction = aOutputMetaFile.GetAction(aOutputMetaFile.GetActionSize() - 2); + + CPPUNIT_ASSERT_EQUAL(MetaActionType::TEXTARRAY, pOutputAction->GetType()); + + MetaTextArrayAction* pOutputTextAction = static_cast<MetaTextArrayAction*>(pOutputAction); + std::vector<sal_Bool> aSubsetKashidaArray({ false, true }); + + CPPUNIT_ASSERT_EQUAL(aSubsetKashidaArray, pOutputTextAction->GetKashidaArray()); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |