diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2022-10-19 16:38:02 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-10-21 17:37:15 +0200 |
commit | 72b69b422d33308809070e98a6ea8daad93e16d2 (patch) | |
tree | c441e1566f513de66730b4ab363238d36207703c /vcl/qa | |
parent | 1cccfb05d1aaea33aa370b6f4f080cae95611cd0 (diff) |
tdf#139736 sw: PDF/UA export: flys in header/footer are Artifacts
* flys anchored in header/footer cannot simply be ignored, they need to
get NonStructElement tag which is translated to "/Artifact"
* borders of flys need to get "/Artifact" tag as well; this is also the
case if they're anchored in the body as veraPDF complains
Change-Id: Id69f0d80c59c3ade295da46c4413a5f0e8d96d54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141534
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf139736-1.odt | bin | 0 -> 33041 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 86 |
2 files changed, 86 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf139736-1.odt b/vcl/qa/cppunit/pdfexport/data/tdf139736-1.odt Binary files differnew file mode 100644 index 000000000000..f17f6037885c --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf139736-1.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index b8efd4c5dc6e..7c5ee9f67952 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -3119,6 +3119,92 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfUaMetadata) CPPUNIT_ASSERT_EQUAL(OString("1"), aPdfUaPart); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf139736) +{ + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + + // Enable PDF/UA + uno::Sequence<beans::PropertyValue> aFilterData( + comphelper::InitPropertySequence({ { "PDFUACompliance", uno::Any(true) } })); + aMediaDescriptor["FilterData"] <<= aFilterData; + saveAsPDF(u"tdf139736-1.odt"); + + vcl::filter::PDFDocument aDocument; + SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + 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"); + 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(); + + enum + { + Default, + Artifact, + Tagged + } state + = Default; + + auto nLine(0); + auto nTagged(0); + auto nArtifacts(0); + while (true) + { + ++nLine; + auto const pLine = ::std::find(pStart, pEnd, '\n'); + if (pLine == pEnd) + { + break; + } + std::string_view const line(pStart, pLine - pStart); + pStart = pLine + 1; + if (!line.empty() && line[0] != '%') + { + ::std::cerr << nLine << ": " << line << "\n"; + if (line == "/Artifact BMC") + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("unexpected nesting", Default, state); + state = Artifact; + ++nArtifacts; + } + else if (line == "/Standard<</MCID 0>>BDC") + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("unexpected nesting", Default, state); + state = Tagged; + ++nTagged; + } + else if (line == "EMC") + { + CPPUNIT_ASSERT_MESSAGE("unexpected end", state != Default); + state = Default; + } + else if (nLine > 1) // first line is expected "0.1 w" + { + CPPUNIT_ASSERT_MESSAGE("unexpected content outside MCS", state != Default); + } + } + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("unclosed MCS", Default, state); + CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nTagged)>(1), nTagged); // text in body + // 1 image and 1 frame and 1 header text; arbitrary number of aux stuff like borders + CPPUNIT_ASSERT(nArtifacts >= 3); +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf142129) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "master.odm"; |