diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2016-03-08 21:36:11 +1000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-03-09 10:20:48 +0000 |
commit | 345d5b172cb81f86e91cb5c0b49f54d4957b9663 (patch) | |
tree | 6d075b7cf8cd08a1ab0abbaf7093eccd304bc215 /sdext | |
parent | 8b009ed87a2690ae0a307b52369c72cf968ab3b1 (diff) |
tdf#98421: properly import vertical mirroring of images from PDF
Since commit ae0e830f9ace78b889713e7e74ce46f88fa21470, mirroring
is handled correctly in LO, so no need to handle it specially in
PDF import code. Commit 11c865031cffc170d3db6b00fb48c683fb4ff070
fixed import to Draw, this one fixes import to Writer.
Also, unit tests for both cases are provided.
Change-Id: I9ef9753a364af34f9e158052855c5dba1300c934
Reviewed-on: https://gerrit.libreoffice.org/23028
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sdext')
-rw-r--r-- | sdext/source/pdfimport/test/outputwrap.hxx | 27 | ||||
-rw-r--r-- | sdext/source/pdfimport/test/testTdf96993.pdf | bin | 0 -> 12665 bytes | |||
-rw-r--r-- | sdext/source/pdfimport/test/tests.cxx | 31 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/writertreevisiting.cxx | 9 |
4 files changed, 67 insertions, 0 deletions
diff --git a/sdext/source/pdfimport/test/outputwrap.hxx b/sdext/source/pdfimport/test/outputwrap.hxx index 015a3e288e88..aa4c541229df 100644 --- a/sdext/source/pdfimport/test/outputwrap.hxx +++ b/sdext/source/pdfimport/test/outputwrap.hxx @@ -25,6 +25,7 @@ #include <cppuhelper/compbase.hxx> #include <com/sun/star/io/XOutputStream.hpp> #include <osl/file.hxx> +#include <rtl/strbuf.hxx> namespace pdfi { @@ -59,6 +60,32 @@ typedef ::cppu::WeakComponentImplHelper< maFile.close(); } }; + + class OutputWrapString : private cppu::BaseMutex, public OutputWrapBase + { + OString& mrString; + OStringBuffer maBuffer; + + public: + + explicit OutputWrapString(OString& rString) : OutputWrapBase(m_aMutex), mrString(rString), maBuffer(rString) + { + } + + virtual void SAL_CALL writeBytes(const css::uno::Sequence< ::sal_Int8 >& aData) throw (css::io::NotConnectedException, css::io::BufferSizeExceededException, css::io::IOException, css::uno::RuntimeException, std::exception) override + { + maBuffer.append(reinterpret_cast<const sal_Char *>(aData.getConstArray()), aData.getLength()); + } + + virtual void SAL_CALL flush() throw (css::io::NotConnectedException, css::io::BufferSizeExceededException, css::io::IOException, css::uno::RuntimeException, std::exception) override + { + } + + virtual void SAL_CALL closeOutput() throw (css::io::NotConnectedException, css::io::BufferSizeExceededException, css::io::IOException, css::uno::RuntimeException, std::exception) override + { + mrString = maBuffer.makeStringAndClear(); + } + }; } #endif diff --git a/sdext/source/pdfimport/test/testTdf96993.pdf b/sdext/source/pdfimport/test/testTdf96993.pdf Binary files differnew file mode 100644 index 000000000000..73abbd129eb1 --- /dev/null +++ b/sdext/source/pdfimport/test/testTdf96993.pdf diff --git a/sdext/source/pdfimport/test/tests.cxx b/sdext/source/pdfimport/test/tests.cxx index cdad633c0ded..e2b043c9defc 100644 --- a/sdext/source/pdfimport/test/tests.cxx +++ b/sdext/source/pdfimport/test/tests.cxx @@ -496,10 +496,41 @@ namespace osl::File::remove( tempFileURL ); } + void testTdf96993() + { + uno::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext())); + xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory()); + + OString aOutput; + CPPUNIT_ASSERT_MESSAGE("Exporting to ODF", + xAdaptor->odfConvert(getURLFromSrc("/sdext/source/pdfimport/test/testTdf96993.pdf"), + new OutputWrapString(aOutput), + nullptr)); + // This ensures that the imported image arrives properly flipped + CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"matrix(18520.8333333333 0 0 26281.9444444444 0 0)\"") != -1); + } + + void testTdf98421() + { + uno::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext())); + xAdaptor->setTreeVisitorFactory(createWriterTreeVisitorFactory()); + + OString aOutput; + CPPUNIT_ASSERT_MESSAGE("Exporting to ODF", + xAdaptor->odfConvert(getURLFromSrc("/sdext/source/pdfimport/test/testTdf96993.pdf"), + new OutputWrapString(aOutput), + nullptr)); + // This ensures that the imported image arrives properly flipped + CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"scale( 1.0 -1.0 ) translate( 0mm 0mm )\"") != -1); + CPPUNIT_ASSERT(aOutput.indexOf("svg:height=\"-262.82mm\"") != -1); + } + CPPUNIT_TEST_SUITE(PDFITest); CPPUNIT_TEST(testXPDFParser); CPPUNIT_TEST(testOdfWriterExport); CPPUNIT_TEST(testOdfDrawExport); + CPPUNIT_TEST(testTdf96993); + CPPUNIT_TEST(testTdf98421); CPPUNIT_TEST_SUITE_END(); }; diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx index b184828b307d..9e946e49f7db 100644 --- a/sdext/source/pdfimport/tree/writertreevisiting.cxx +++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx @@ -164,6 +164,15 @@ void WriterXmlEmitter::fillFrameProps( DrawElement& rElem, // that ODF rotation is oriented the other way // build transformation string + if (rElem.MirrorVertical) + { + // At some point, rElem.h may start arriving positive, + // so use robust adjusting math + rel_y -= std::abs(rElem.h); + if (!aBuf.isEmpty()) + aBuf.append(' '); + aBuf.append("scale( 1.0 -1.0 )"); + } if( fShearX != 0.0 ) { aBuf.append( "skewX( " ); |