sc/qa/extras/scpdfexport.cxx             |   62 +++++++++++++++++++++++++++++++
 sc/qa/extras/testdocuments/tdf159068.ods |binary
 sc/source/core/tool/detfunc.cxx          |    3 +
 3 files changed, 65 insertions(+)

New commits:
commit 510e94913b87fd6a3ea6444da492f6428afa47d8
Author:     Tibor Nagy <tibor.nagy.ext...@allotropia.de>
AuthorDate: Sun Jan 14 21:33:02 2024 +0100
Commit:     Nagy Tibor <tibor.nagy.ext...@allotropia.de>
CommitDate: Mon Jan 15 10:10:23 2024 +0100

    tdf#159068 sc: fix detective shapes (PDF/UA export)
    
    The detective shapes(DetectiveArrow,ValidationCircle) don't have the
    option to set alternative text, so it should be marked as decorative.
    
    Change-Id: If83b29eb071b25f9eaa92a23337e416048b6aa8b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162059
    Tested-by: Jenkins
    Reviewed-by: Nagy Tibor <tibor.nagy.ext...@allotropia.de>

diff --git a/sc/qa/extras/scpdfexport.cxx b/sc/qa/extras/scpdfexport.cxx
index de888c083387..11211607c013 100644
--- a/sc/qa/extras/scpdfexport.cxx
+++ b/sc/qa/extras/scpdfexport.cxx
@@ -65,6 +65,7 @@ public:
     void testExportFitToPage_Tdf103516();
     void testUnoCommands_Tdf120161();
     void testTdf64703_hiddenPageBreak();
+    void testTdf159068();
     void testTdf159066();
     void testTdf159065();
     void testTdf123870();
@@ -79,6 +80,7 @@ public:
     CPPUNIT_TEST(testExportFitToPage_Tdf103516);
     CPPUNIT_TEST(testUnoCommands_Tdf120161);
     CPPUNIT_TEST(testTdf64703_hiddenPageBreak);
+    CPPUNIT_TEST(testTdf159068);
     CPPUNIT_TEST(testTdf159066);
     CPPUNIT_TEST(testTdf159065);
     CPPUNIT_TEST(testTdf123870);
@@ -398,6 +400,66 @@ void ScPDFExportTest::testTdf64703_hiddenPageBreak()
     }
 }
 
+void ScPDFExportTest::testTdf159068()
+{
+    loadFromFile(u"tdf159068.ods");
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+
+    // A1:C3
+    ScRange range1(0, 0, 0, 2, 2, 0);
+    exportToPDF(xModel, range1);
+
+    vcl::filter::PDFDocument aDocument;
+    SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+    CPPUNIT_ASSERT(aDocument.Read(aStream));
+
+    // The document has one page.
+    std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+    vcl::filter::PDFObjectElement* pContents = 
aPages[0]->LookupObject("Contents"_ostr);
+    CPPUNIT_ASSERT(pContents);
+    vcl::filter::PDFStreamElement* pStream = pContents->GetStream();
+    CPPUNIT_ASSERT(pStream);
+
+    SvMemoryStream& rObjectStream = pStream->GetMemory();
+    // Uncompress it.
+    SvMemoryStream aUncompressed;
+    ZCodec aZCodec;
+    aZCodec.BeginCompression();
+    rObjectStream.Seek(0);
+    aZCodec.Decompress(rObjectStream, aUncompressed);
+    CPPUNIT_ASSERT(aZCodec.EndCompression());
+
+    auto pStart = static_cast<const char*>(aUncompressed.GetData());
+    const char* const pEnd = pStart + aUncompressed.GetSize();
+
+    auto nArtifact(0);
+    auto nLine(0);
+    while (true)
+    {
+        ++nLine;
+        auto const pLine = ::std::find(pStart, pEnd, '
');
+        if (pLine == pEnd)
+        {
+            break;
+        }
+        std::string_view const line(pStart, pLine - pStart);
+        pStart = pLine + 1;
+        if (!line.empty() && line[0] != '%')
+        {
+            ::std::cerr << nLine << ": " << line << "
 ";
+            if (o3tl::starts_with(line, "/Artifact BMC"))
+                nArtifact++;
+        }
+    }
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 5 (Artifact: Header, Footer, Rectangel, DetectiveArrow, 
ValidationCircle)
+    // - Actual  : 2 (Artifact: Header, Footer)
+    CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nArtifact)>(5), nArtifact);
+}
+
 void ScPDFExportTest::testTdf159066()
 {
     loadFromFile(u"tdf159066.ods");
diff --git a/sc/qa/extras/testdocuments/tdf159068.ods 
b/sc/qa/extras/testdocuments/tdf159068.ods
new file mode 100644
index 000000000000..a0745d924c84
Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf159068.ods differ
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index b5dc71b92a63..59efb5ad6469 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -373,6 +373,7 @@ void ScDetectiveFunc::InsertArrow( SCCOL nCol, SCROW nRow,
         pBox->NbcSetStyleSheet(nullptr, true);
         pBox->SetMergedItemSetAndBroadcast(rData.GetBoxSet());
 
+        pBox->SetDecorative(true);
         pBox->SetLayer( SC_LAYER_INTERN );
         pPage->InsertObject( pBox.get() );
         pModel->AddCalcUndo( std::make_unique<SdrUndoInsertObj>( *pBox ) );
@@ -418,6 +419,7 @@ void ScDetectiveFunc::InsertArrow( SCCOL nCol, SCROW nRow,
     pArrow->NbcSetLogicRect(tools::Rectangle::Normalize(aStartPos,aEndPos));  
//TODO: needed ???
     pArrow->SetMergedItemSetAndBroadcast(rAttrSet);
 
+    pArrow->SetDecorative(true);
     pArrow->SetLayer( SC_LAYER_INTERN );
     pPage->InsertObject( pArrow.get() );
     pModel->AddCalcUndo( std::make_unique<SdrUndoInsertObj>( *pArrow ) );
@@ -561,6 +563,7 @@ void ScDetectiveFunc::DrawCircle( SCCOL nCol, SCROW nRow, 
ScDetectiveData& rData
     pCircle->NbcSetStyleSheet(nullptr, true);
     pCircle->SetMergedItemSetAndBroadcast(rAttrSet);
 
+    pCircle->SetDecorative(true);
     pCircle->SetLayer( SC_LAYER_INTERN );
     pPage->InsertObject( pCircle.get() );
     pModel->AddCalcUndo( std::make_unique<SdrUndoInsertObj>( *pCircle ) );

Reply via email to