[Libreoffice-commits] core.git: vcl/qa vcl/source
Miklos Vajna
vmiklos at collabora.co.uk
Mon Feb 27 18:01:22 UTC 2017
vcl/qa/cppunit/pdfexport/data/tdf106206.odt |binary
vcl/qa/cppunit/pdfexport/pdfexport.cxx | 54 ++++++++++++++++++++++++++++
vcl/source/gdi/pdfwriter_impl.cxx | 5 ++
3 files changed, 58 insertions(+), 1 deletion(-)
New commits:
commit e7adffff8039175bc50b56b4c07ce0b9d8fed629
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Feb 27 16:38:54 2017 +0100
tdf#106206 PDF export: fix unexpected /Im0 in page contents stream
The early return should just skip the code that's specific to pdf
images, not everything.
Change-Id: Ia9e02b05051a085a9fdf2f690c21f9ffccb7bf4d
Reviewed-on: https://gerrit.libreoffice.org/34685
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf106206.odt b/vcl/qa/cppunit/pdfexport/data/tdf106206.odt
new file mode 100644
index 0000000..3581157
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf106206.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index af6e86b..edd63e6 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -44,6 +44,8 @@ public:
void testTdf105461();
/// Tests that embedded video from Impress is not exported as a linked one.
void testTdf105093();
+ /// Tests export of non-PDF images.
+ void testTdf106206();
#endif
CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -51,6 +53,7 @@ public:
CPPUNIT_TEST(testTdf106059);
CPPUNIT_TEST(testTdf105461);
CPPUNIT_TEST(testTdf105093);
+ CPPUNIT_TEST(testTdf106206);
#endif
CPPUNIT_TEST_SUITE_END();
};
@@ -200,6 +203,57 @@ void PdfExportTest::testTdf105093()
// This key was missing, the embedded video was handled as a linked one.
CPPUNIT_ASSERT(pFileSpec->LookupElement("EF"));
}
+
+void PdfExportTest::testTdf106206()
+{
+ // Import the bugdoc and export as PDF.
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf106206.odt";
+ mxComponent = loadFromDesktop(aURL);
+ CPPUNIT_ASSERT(mxComponent.is());
+
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+ xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+ // Parse the export result.
+ xmlsecurity::pdfio::PDFDocument aDocument;
+ SvFileStream aStream(aTempFile.GetURL(), StreamMode::READ);
+ CPPUNIT_ASSERT(aDocument.Read(aStream));
+
+ // The document has one page.
+ std::vector<xmlsecurity::pdfio::PDFObjectElement*> aPages = aDocument.GetPages();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+ // The page has a stream.
+ xmlsecurity::pdfio::PDFObjectElement* pContents = aPages[0]->LookupObject("Contents");
+ CPPUNIT_ASSERT(pContents);
+ xmlsecurity::pdfio::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());
+
+ // Make sure there is an image reference there.
+ OString aImage("/Im");
+ auto pStart = static_cast<const char*>(aUncompressed.GetData());
+ const char* pEnd = pStart + aUncompressed.GetSize();
+ auto it = std::search(pStart, pEnd, aImage.getStr(), aImage.getStr() + aImage.getLength());
+ CPPUNIT_ASSERT(it != pEnd);
+
+ // And also that it's not an invalid one.
+ OString aInvalidImage("/Im0");
+ it = std::search(pStart, pEnd, aInvalidImage.getStr(), aInvalidImage.getStr() + aInvalidImage.getLength());
+ // This failed, object #0 was referenced.
+ CPPUNIT_ASSERT(bool(it == pEnd));
+}
#endif
CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 054b7a3..fc9443c 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -11252,6 +11252,10 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObjectEmit& rEmit, sal_Int32 nBitmapObject)
{
+ // The bitmap object is always a valid identifier, even if the graphic has
+ // no pdf data.
+ rEmit.m_nBitmapObject = nBitmapObject;
+
if (!rGraphic.getPdfData().hasElements())
return;
@@ -11262,7 +11266,6 @@ void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObject
rEmit.m_nFormObject = createObject();
rEmit.m_nEmbeddedObject = m_aEmbeddedFiles.back().m_nObject;
- rEmit.m_nBitmapObject = nBitmapObject;
rEmit.m_aPixelSize = rGraphic.GetBitmap().GetPrefSize();
}
More information about the Libreoffice-commits
mailing list