From 66b6662dedb56c74a607a0f5adc3dd4251ef5206 Mon Sep 17 00:00:00 2001 From: Manish Bera Date: Sun, 31 May 2026 12:58:53 +0530 Subject: [PATCH] sw: add layout tests for drop caps Change-Id: I3bfb6de4786466110e2cf60f78556862c0865706 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205858 Tested-by: Jenkins Reviewed-by: Jonathan Clark --- sw/qa/extras/layout/data/drop_asian_word.fodt | 118 ++++++++++++++++ .../extras/layout/data/drop_complex_word.fodt | 118 ++++++++++++++++ .../extras/layout/data/drop_fly_overlap.fodt | 129 ++++++++++++++++++ sw/qa/extras/layout/data/drop_vertical.fodt | 128 +++++++++++++++++ sw/qa/extras/layout/layout3.cxx | 72 ++++++++++ 5 files changed, 565 insertions(+) create mode 100644 sw/qa/extras/layout/data/drop_asian_word.fodt create mode 100644 sw/qa/extras/layout/data/drop_complex_word.fodt create mode 100644 sw/qa/extras/layout/data/drop_fly_overlap.fodt create mode 100644 sw/qa/extras/layout/data/drop_vertical.fodt diff --git a/sw/qa/extras/layout/data/drop_asian_word.fodt b/sw/qa/extras/layout/data/drop_asian_word.fodt new file mode 100644 index 000000000000..a75f585d0da2 --- /dev/null +++ b/sw/qa/extras/layout/data/drop_asian_word.fodt @@ -0,0 +1,118 @@ + + + 2026-05-29T15:51:50.0875069002026-05-29T16:07:32.511417100PT6M13S3LibreOffice/25.2.7.2$Windows_X86_64 LibreOffice_project/5cbfd1ab6520636bb5f7b99185aa69bd7456825d + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + リブレオフィス + + + \ No newline at end of file diff --git a/sw/qa/extras/layout/data/drop_complex_word.fodt b/sw/qa/extras/layout/data/drop_complex_word.fodt new file mode 100644 index 000000000000..910a4cee1009 --- /dev/null +++ b/sw/qa/extras/layout/data/drop_complex_word.fodt @@ -0,0 +1,118 @@ + + + 2026-05-31T11:56:25.6025895002026-05-31T11:57:30.822410400PT1M5S1LibreOffice/25.2.7.2$Windows_X86_64 LibreOffice_project/5cbfd1ab6520636bb5f7b99185aa69bd7456825d + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + লিব্রেঅফিস + + + \ No newline at end of file diff --git a/sw/qa/extras/layout/data/drop_fly_overlap.fodt b/sw/qa/extras/layout/data/drop_fly_overlap.fodt new file mode 100644 index 000000000000..7e149b7a5614 --- /dev/null +++ b/sw/qa/extras/layout/data/drop_fly_overlap.fodt @@ -0,0 +1,129 @@ + + + 2026-05-29T13:21:38.5777155002026-05-29T13:49:18.461713500PT5M6S3LibreOffice/25.2.7.2$Windows_X86_64 LibreOffice_project/5cbfd1ab6520636bb5f7b99185aa69bd7456825d + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu interdum diam, ac hendrerit arcu. Vestibulum quis dictum ipsum. Aenean consequat consectetur condimentum. + + + + Proin maximus, metus non sodales facilisis, neque ex egestas quam, a lobortis est eros euismod felis. Phasellus molestie, nulla a maximus faucibus, magna neque aliquam est, vel aliquet arcu odio ac nisi. Etiam venenatis fermentum tempor. + + + \ No newline at end of file diff --git a/sw/qa/extras/layout/data/drop_vertical.fodt b/sw/qa/extras/layout/data/drop_vertical.fodt new file mode 100644 index 000000000000..55357116daf9 --- /dev/null +++ b/sw/qa/extras/layout/data/drop_vertical.fodt @@ -0,0 +1,128 @@ + + + 2026-05-31T12:28:13.3961196002026-05-31T12:34:36.661210000PT6M23S1LibreOffice/25.2.7.2$Windows_X86_64 LibreOffice_project/5cbfd1ab6520636bb5f7b99185aa69bd7456825d + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Libreoffice + + + + + \ No newline at end of file diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx index ba7438e64b35..ffc2f2c0b10a 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -1701,6 +1701,78 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf165354_long_paragraph_2) u"of the Earth is space "); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testDropFlyOverlap) +{ + // Load the overlapping fly frame document + createSwDoc("drop_fly_overlap.fodt"); + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + CPPUNIT_ASSERT(pXmlDoc); + + // Assert that the layout engine successfully processed the Drop Portion + assertXPath(pXmlDoc, + "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[1]/" + "SwLinePortion[@type='PortionType::Drop']", + 1); + + // Extract the calculated widths as integers + sal_Int32 nDropWidth = getXPath(pXmlDoc, + "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[1]/" + "SwLinePortion[@type='PortionType::Drop']", + "width") + .toInt32(); + sal_Int32 nFlyWidth + = getXPath(pXmlDoc, "/root/page/body/txt[2]/anchored/SwAnchoredDrawObject/bounds", "width") + .toInt32(); + + // Assert that the Drop Cap calculation was safely constrained by the intersecting shape. + CPPUNIT_ASSERT_GREATER(sal_Int32(600), nDropWidth); + CPPUNIT_ASSERT_LESS(sal_Int32(700), nDropWidth); + + CPPUNIT_ASSERT_GREATER(sal_Int32(600), nFlyWidth); +} + +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testDropAsianWord) +{ + // Trigger the ASIAN script case in GetDropLen + createSwDoc("drop_asian_word.fodt"); + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + CPPUNIT_ASSERT(pXmlDoc); + + // Assert that the drop portion exists + assertXPath(pXmlDoc, + "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/" + "SwLinePortion[@type='PortionType::Drop']", + 1); +} + +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testDropComplexWord) +{ + // Trigger the COMPLEX script case in GetDropLen + createSwDoc("drop_complex_word.fodt"); + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + CPPUNIT_ASSERT(pXmlDoc); + + // Assert that the drop portion exists + assertXPath(pXmlDoc, + "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/" + "SwLinePortion[@type='PortionType::Drop']", + 1); +} + +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testDropVertical) +{ + // Trigger the IsVertical() layout calculations for Top-to-Bottom typography + createSwDoc("drop_vertical.fodt"); + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + CPPUNIT_ASSERT(pXmlDoc); + + // Assert the Drop Cap was calculated in the vertical layout tree + // (Since we put it in a frame, we search inside the //fly node) + assertXPath(pXmlDoc, + "//fly/txt/SwParaPortion/SwLineLayout[1]/SwLinePortion[@type='PortionType::Drop']", + 1); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT();