diff options
author | Tibor Nagy <tibor.nagy.extern@allotropia.de> | 2024-07-05 14:40:11 +0200 |
---|---|---|
committer | Nagy Tibor <tibor.nagy.extern@allotropia.de> | 2024-07-08 18:19:26 +0200 |
commit | 611dc34f19deab7f13d00a4058f6a6ac6b50edb2 (patch) | |
tree | 7574989df4e8a7abafe70fa2e385d8558354b0f3 /vcl | |
parent | 3d0411ef53ccd6bb0af21b69aa557f1f40beffd0 (diff) |
tdf#159900 sw: fix Figure tag placement attribute when exporting to PDF
Paragraph tag is a possible parent element for the Figure tag.
Figure tag and (any structure element) may have a value of “inline”
as a placement attribute and thus, may be a child of a Paragraph tag.
Change-Id: Ie1e0221976dbcfbae9ff01b1c9b76dd2d2e7edcb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170015
Tested-by: Jenkins
Reviewed-by: Nagy Tibor <tibor.nagy.extern@allotropia.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf159900_figurePlacement.odt | bin | 0 -> 34773 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 51 |
2 files changed, 51 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf159900_figurePlacement.odt b/vcl/qa/cppunit/pdfexport/data/tdf159900_figurePlacement.odt Binary files differnew file mode 100644 index 000000000000..0ebe292ce160 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf159900_figurePlacement.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 054496ee4895..d4325fe267ce 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -70,6 +70,57 @@ void PdfExportTest::load(std::u16string_view rFile, vcl::filter::PDFDocument& rD CPPUNIT_ASSERT(rDocument.Read(aStream)); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testFigurePlacement) +{ + aMediaDescriptor[u"FilterName"_ustr] <<= u"impress_pdf_Export"_ustr; + + uno::Sequence<beans::PropertyValue> aFilterData( + comphelper::InitPropertySequence({ { "UseTaggedPDF", uno::Any(true) } })); + aMediaDescriptor[u"FilterData"_ustr] <<= aFilterData; + saveAsPDF(u"tdf159900_figurePlacement.odt"); + + // Parse the export result. + 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()); + + for (const auto& aElement : aDocument.GetElements()) + { + auto pObject = dynamic_cast<vcl::filter::PDFObjectElement*>(aElement.get()); + if (!pObject) + continue; + auto pType = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("Type"_ostr)); + if (pType && pType->GetValue() == "StructElem") + { + auto pS = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("S"_ostr)); + if (pS && pS->GetValue() == "Figure") + { + auto pAttrDict + = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pObject->Lookup("A"_ostr)); + CPPUNIT_ASSERT(pAttrDict); + auto pOwner = dynamic_cast<vcl::filter::PDFNameElement*>( + pAttrDict->LookupElement("O"_ostr)); + CPPUNIT_ASSERT(pOwner); + if (pOwner->GetValue() == "Layout") + { + auto pPlacement = dynamic_cast<vcl::filter::PDFNameElement*>( + pAttrDict->LookupElement("Placement"_ostr)); + CPPUNIT_ASSERT(pPlacement); + + // Without the fix in place, this test would have failed with + // Expected: Inline + // Actual: Block + CPPUNIT_ASSERT_EQUAL("Inline"_ostr, pPlacement->GetValue()); + } + } + } + } +} + /// Tests that a pdf image is roundtripped back to PDF as a vector format. CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf106059) { |