summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2016-03-08 21:36:11 +1000
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-03-09 14:20:58 +0000
commit9fb382d4e6afd40f8c50981cac3cbea9334b5639 (patch)
tree3a43480703a471da4bc453c7e6cbd0219f52ae85
parente1cb3aa56b94fdf75b775e42fe4b039be82b8d32 (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> (cherry picked from commit 345d5b172cb81f86e91cb5c0b49f54d4957b9663) Reviewed-on: https://gerrit.libreoffice.org/23063 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sdext/source/pdfimport/test/outputwrap.hxx27
-rw-r--r--sdext/source/pdfimport/test/testTdf96993.pdfbin0 -> 12665 bytes
-rw-r--r--sdext/source/pdfimport/test/tests.cxx31
-rw-r--r--sdext/source/pdfimport/tree/writertreevisiting.cxx9
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
new file mode 100644
index 000000000000..73abbd129eb1
--- /dev/null
+++ b/sdext/source/pdfimport/test/testTdf96993.pdf
Binary files differ
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 5cf415624a12..922479227cfe 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( " );