Kaydet (Commit) 345d5b17 authored tarafından Mike Kaganski's avatar Mike Kaganski Kaydeden (comit) Caolán McNamara

tdf#98421: properly import vertical mirroring of images from PDF

Since commit ae0e830f, mirroring
is handled correctly in LO, so no need to handle it specially in
PDF import code. Commit 11c86503
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/23028Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 8b009ed8
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <cppuhelper/compbase.hxx> #include <cppuhelper/compbase.hxx>
#include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <rtl/strbuf.hxx>
namespace pdfi namespace pdfi
{ {
...@@ -59,6 +60,32 @@ typedef ::cppu::WeakComponentImplHelper< ...@@ -59,6 +60,32 @@ typedef ::cppu::WeakComponentImplHelper<
maFile.close(); 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 #endif
......
...@@ -496,10 +496,41 @@ namespace ...@@ -496,10 +496,41 @@ namespace
osl::File::remove( tempFileURL ); 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_SUITE(PDFITest);
CPPUNIT_TEST(testXPDFParser); CPPUNIT_TEST(testXPDFParser);
CPPUNIT_TEST(testOdfWriterExport); CPPUNIT_TEST(testOdfWriterExport);
CPPUNIT_TEST(testOdfDrawExport); CPPUNIT_TEST(testOdfDrawExport);
CPPUNIT_TEST(testTdf96993);
CPPUNIT_TEST(testTdf98421);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
......
...@@ -164,6 +164,15 @@ void WriterXmlEmitter::fillFrameProps( DrawElement& rElem, ...@@ -164,6 +164,15 @@ void WriterXmlEmitter::fillFrameProps( DrawElement& rElem,
// that ODF rotation is oriented the other way // that ODF rotation is oriented the other way
// build transformation string // 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 ) if( fShearX != 0.0 )
{ {
aBuf.append( "skewX( " ); aBuf.append( "skewX( " );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment