tdf#156681: Revert "tdf#152048: Fix underline width for Kashida-justified text"

This reverts commit 43a5400063b17ed4ba4cbb38bdf5da4a991f60e2.

The idea is to revert it in libreoffice-7-6 and libreoffice-7-5 branches
only since tdf#156681 is fixed in master by 507a8745870e9a755be3a72f59c6e9a9d811fdcf
"vcl: Use doubles for glyph item coordinates"

This commit also reverts 34df6c92e513c5f428eff7c9cb1d6b9831eeb323
"tdf#152048: Add test"

Change-Id: Id246c388df45d16b9bce86d1827949c644fc8517
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155969
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index 5c6297e..423192a 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -381,44 +381,6 @@ CPPUNIT_TEST_FIXTURE(VclComplexTextTest, testGdefCaret)
#endif
}

CPPUNIT_TEST_FIXTURE(VclComplexTextTest, testTdf152048)
{
#if HAVE_MORE_FONTS
    OUString aText(u"می‌شود");

    vcl::Font aFont(u"Noto Naskh Arabic", u"Regular", Size(0, 72));

    ScopedVclPtrInstance<VirtualDevice> pOutDev;
    pOutDev->SetFont(aFont);

    // get an compare the default text array
    std::vector<sal_Int32> aRefCharWidths{ 33, 82, 82, 129, 163, 193 };
    tools::Long nRefTextWidth(193);

    KernArray aCharWidths;
    tools::Long nTextWidth = pOutDev->GetTextArray(aText, &aCharWidths);

    CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths.get_subunit_array());
    CPPUNIT_ASSERT_EQUAL(nRefTextWidth, nTextWidth);
    CPPUNIT_ASSERT_EQUAL(sal_Int32(nTextWidth), aCharWidths.back());

    // Simulate Kashida insertion using Kashida array and extending text array
    // to have room for Kashida.
    std::vector<sal_Bool> aKashidaArray{ false, false, false, true, false, false };
    auto nKashida = 200;

    aCharWidths.set(3, aCharWidths[3] + nKashida);
    aCharWidths.set(4, aCharWidths[4] + nKashida);
    aCharWidths.set(5, aCharWidths[5] + nKashida);
    auto pLayout = pOutDev->ImplLayout(aText, 0, -1, Point(0, 0), 0, aCharWidths, aKashidaArray);

    // Without the fix this fails with:
    // - Expected: 393
    // - Actual  : 511
    CPPUNIT_ASSERT_EQUAL(DeviceCoordinate(nRefTextWidth + nKashida), pLayout->GetTextWidth());
#endif
}

CPPUNIT_TEST_FIXTURE(VclComplexTextTest, testTdf152048_2)
{
#if HAVE_MORE_FONTS
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 31ee1e4..af246ef 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -777,15 +777,15 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf108963)
            pSegment = pPdfPageObject->getPathSegment(1);
            CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, pSegment->getType());
            aPoint = pSegment->getPoint();
            CPPUNIT_ASSERT_DOUBLES_EQUAL(275.216, aPoint.getX(), 0.0005);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(267.732, aPoint.getY(), 0.0005);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(275.074, aPoint.getX(), 0.0005);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(267.590, aPoint.getY(), 0.0005);
            CPPUNIT_ASSERT(!pSegment->isClosed());

            pSegment = pPdfPageObject->getPathSegment(2);
            CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, pSegment->getType());
            aPoint = pSegment->getPoint();
            CPPUNIT_ASSERT_DOUBLES_EQUAL(287.660, aPoint.getX(), 0.0005);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(251.914, aPoint.getY(), 0.0005);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(287.490, aPoint.getX(), 0.0005);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(251.801, aPoint.getY(), 0.0005);
            CPPUNIT_ASSERT(!pSegment->isClosed());

            pSegment = pPdfPageObject->getPathSegment(3);
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 944587f..faa127e 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -849,7 +849,7 @@ void GenericSalLayout::ApplyDXArray(const double* pDXArray, const sal_Bool* pKas
        aPos.adjustX(-nClusterWidth + pGlyphIter->origWidth());
        while (nCopies--)
        {
            GlyphItem aKashida(nCharPos, 0, nKashidaIndex, aPos, nFlags, 0, 0, 0);
            GlyphItem aKashida(nCharPos, 0, nKashidaIndex, aPos, nFlags, nKashidaWidth, 0, 0);
            pGlyphIter = m_GlyphItems.insert(pGlyphIter, aKashida);
            aPos.adjustX(nKashidaWidth - nOverlap);
            ++pGlyphIter;
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 3cdd716..ed368f0 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -269,10 +269,19 @@ DeviceCoordinate GenericSalLayout::GetTextWidth() const
    if (!m_GlyphItems.IsValid())
        return 0;

    DeviceCoordinate nWidth = 0;
    for (auto const& aGlyphItem : m_GlyphItems)
        nWidth += aGlyphItem.newWidth();
    // initialize the extent
    DeviceCoordinate nMinPos = 0;
    DeviceCoordinate nMaxPos = 0;

    for (auto const& aGlyphItem : m_GlyphItems)
    {
        // update the text extent with the glyph extent
        DeviceCoordinate nXPos = aGlyphItem.linearPos().getX() - aGlyphItem.xOffset();
        nMinPos = std::min(nMinPos, nXPos);
        nMaxPos = std::max(nMaxPos, nXPos + aGlyphItem.newWidth());
    }

    DeviceCoordinate nWidth = nMaxPos - nMinPos;
    return nWidth;
}