vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / pdfimport / test / tests.cxx
blob0cf64eeec424588c7fc329484efad98088c06f49
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include "outputwrap.hxx"
23 #include <contentsink.hxx>
24 #include <pdfihelper.hxx>
25 #include <wrapper.hxx>
26 #include <pdfparse.hxx>
27 #include "../pdfiadaptor.hxx"
29 #include <rtl/math.hxx>
30 #include <osl/file.hxx>
31 #include <comphelper/sequence.hxx>
33 #include <cppunit/TestAssert.h>
34 #include <cppunit/extensions/HelperMacros.h>
35 #include <cppunit/plugin/TestPlugIn.h>
36 #include <test/bootstrapfixture.hxx>
38 #include <com/sun/star/geometry/RealRectangle2D.hpp>
39 #include <com/sun/star/geometry/RealSize2D.hpp>
40 #include <com/sun/star/rendering/PathJoinType.hpp>
41 #include <com/sun/star/rendering/PathCapType.hpp>
42 #include <com/sun/star/rendering/BlendMode.hpp>
44 #include <basegfx/utils/canvastools.hxx>
45 #include <basegfx/polygon/b2dpolypolygon.hxx>
46 #include <basegfx/polygon/b2dpolypolygontools.hxx>
47 #include <basegfx/polygon/b2dpolygonclipper.hxx>
49 #include <unordered_map>
50 #include <vector>
52 #include <rtl/ustring.hxx>
53 #include <rtl/ref.hxx>
55 using namespace ::pdfparse;
56 using namespace ::pdfi;
57 using namespace ::com::sun::star;
59 namespace
62 class TestSink : public ContentSink
64 public:
65 TestSink() :
66 m_nNextFontId( 1 ),
67 m_aIdToFont(),
68 m_aFontToId(),
69 m_aGCStack(1),
70 m_aPageSize(),
71 m_aHyperlinkBounds(),
72 m_aURI(),
73 m_aTextOut(),
74 m_nNumPages(0),
75 m_bPageEnded(false),
76 m_bRedCircleSeen(false),
77 m_bGreenStrokeSeen(false),
78 m_bDashedLineSeen(false),
79 m_bImageSeen(false)
82 void check()
84 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Width", 79400, m_aPageSize.Width, 0.00000001);
85 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Height", 59500, m_aPageSize.Height, 0.0000001 );
86 CPPUNIT_ASSERT_MESSAGE( "endPage() called", m_bPageEnded );
87 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Num pages equal one", sal_Int32(1), m_nNumPages );
88 CPPUNIT_ASSERT_MESSAGE( "Correct hyperlink bounding box",
89 rtl::math::approxEqual(m_aHyperlinkBounds.X1,34.7 ) &&
90 rtl::math::approxEqual(m_aHyperlinkBounds.Y1,386.0) &&
91 rtl::math::approxEqual(m_aHyperlinkBounds.X2,166.7) &&
92 rtl::math::approxEqual(m_aHyperlinkBounds.Y2,406.2) );
93 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Correct hyperlink URI", OUString("http://download.openoffice.org/"), m_aURI );
95 const char* const sText = " \n \nThis is a testtext\nNew paragraph,\nnew line\n"
96 "Hyperlink, this is\n?\nThis is more text\noutline mode\n?\nNew paragraph\n";
97 OString aTmp;
98 m_aTextOut.makeStringAndClear().convertToString( &aTmp,
99 RTL_TEXTENCODING_ASCII_US,
100 OUSTRING_TO_OSTRING_CVTFLAGS );
101 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Imported text is \"This is a testtext New paragraph, new line"
102 " Hyperlink, this is * This is more text outline mode * New paragraph\"",
103 aTmp, OString(sText) );
105 CPPUNIT_ASSERT_MESSAGE( "red circle seen in input", m_bRedCircleSeen );
106 CPPUNIT_ASSERT_MESSAGE( "green stroke seen in input", m_bGreenStrokeSeen );
107 CPPUNIT_ASSERT_MESSAGE( "dashed line seen in input", m_bDashedLineSeen );
108 CPPUNIT_ASSERT_MESSAGE( "image seen in input", m_bImageSeen );
111 private:
112 GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
114 // ContentSink interface implementation
115 virtual void setPageNum( sal_Int32 nNumPages ) override
117 m_nNumPages = nNumPages;
120 virtual void startPage( const geometry::RealSize2D& rSize ) override
122 m_aPageSize = rSize;
125 virtual void endPage() override
127 m_bPageEnded = true;
130 virtual void hyperLink( const geometry::RealRectangle2D& rBounds,
131 const OUString& rURI ) override
133 m_aHyperlinkBounds = rBounds;
134 m_aURI = rURI;
137 virtual void pushState() override
139 GraphicsContextStack::value_type const a(m_aGCStack.back());
140 m_aGCStack.push_back(a);
143 virtual void popState() override
145 m_aGCStack.pop_back();
148 virtual void setTransformation( const geometry::AffineMatrix2D& rMatrix ) override
150 basegfx::unotools::homMatrixFromAffineMatrix(
151 getCurrentContext().Transformation,
152 rMatrix );
155 virtual void setLineDash( const uno::Sequence<double>& dashes,
156 double start ) override
158 GraphicsContext& rContext( getCurrentContext() );
159 if( dashes.hasElements() )
160 comphelper::sequenceToContainer(rContext.DashArray,dashes);
161 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "line dashing start offset", 0.0, start, 0.000000001 );
164 virtual void setFlatness( double nFlatness ) override
166 getCurrentContext().Flatness = nFlatness;
169 virtual void setLineJoin(sal_Int8 nJoin) override
171 getCurrentContext().LineJoin = nJoin;
174 virtual void setLineCap(sal_Int8 nCap) override
176 getCurrentContext().LineCap = nCap;
179 virtual void setMiterLimit(double nVal) override
181 getCurrentContext().MiterLimit = nVal;
184 virtual void setLineWidth(double nVal) override
186 getCurrentContext().LineWidth = nVal;
189 virtual void setFillColor( const rendering::ARGBColor& rColor ) override
191 getCurrentContext().FillColor = rColor;
194 virtual void setStrokeColor( const rendering::ARGBColor& rColor ) override
196 getCurrentContext().LineColor = rColor;
199 virtual void setFont( const FontAttributes& rFont ) override
201 FontToIdMap::const_iterator it = m_aFontToId.find( rFont );
202 if( it != m_aFontToId.end() )
203 getCurrentContext().FontId = it->second;
204 else
206 m_aFontToId[ rFont ] = m_nNextFontId;
207 m_aIdToFont[ m_nNextFontId ] = rFont;
208 getCurrentContext().FontId = m_nNextFontId;
209 m_nNextFontId++;
213 virtual void strokePath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) override
215 GraphicsContext& rContext( getCurrentContext() );
216 basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
217 aPath.transform( rContext.Transformation );
219 if( rContext.DashArray.empty() )
221 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 1.0, rContext.LineColor.Alpha, 0.00000001);
222 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 0.0, rContext.LineColor.Blue, 0.00000001);
223 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 1.0, rContext.LineColor.Green, 0.00000001);
224 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", 0.0, rContext.LineColor.Red, 0.00000001);
226 CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
227 rtl::math::approxEqual(rContext.LineWidth, 28.3) );
229 const char sExportString[] = "m53570 7650-35430 24100";
230 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Stroke is m535.7 518.5-354.3-241",
231 OUString(sExportString), basegfx::utils::exportToSvgD( aPath, true, true, false ) );
233 m_bGreenStrokeSeen = true;
235 else
237 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Dash array consists of four entries", std::vector<double>::size_type(4), rContext.DashArray.size());
238 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.3764, rContext.DashArray[0], 1E-12 );
239 CPPUNIT_ASSERT_DOUBLES_EQUAL( rContext.DashArray[0], rContext.DashArray[1], 1E-12 );
240 CPPUNIT_ASSERT_DOUBLES_EQUAL( rContext.DashArray[1], rContext.DashArray[2], 1E-12 );
241 CPPUNIT_ASSERT_DOUBLES_EQUAL( rContext.DashArray[2], rContext.DashArray[3], 1E-12 );
243 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001);
244 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001);
245 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Green, 0.00000001);
246 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Red, 0.00000001);
248 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line width is 0",
249 0, rContext.LineWidth, 0.0000001 );
251 const char sExportString[] = "m49890 5670.00000000001-35430 24090";
252 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Stroke is m49890 5670.00000000001-35430 24090",
253 OUString(sExportString), basegfx::utils::exportToSvgD( aPath, true, true, false ) );
255 m_bDashedLineSeen = true;
257 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Blend mode is normal",
258 rendering::BlendMode::NORMAL, rContext.BlendMode );
259 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Join type is round",
260 rendering::PathJoinType::ROUND, rContext.LineJoin );
261 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Cap type is butt",
262 rendering::PathCapType::BUTT, rContext.LineCap );
263 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line miter limit is 10",
264 10, rContext.MiterLimit, 0.0000001 );
265 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
266 1, rContext.Flatness, 0.00000001 );
267 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
268 sal_Int32(0), rContext.FontId );
271 virtual void fillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) override
273 GraphicsContext& rContext( getCurrentContext() );
274 basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
275 aPath.transform( rContext.Transformation );
277 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001);
278 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001);
279 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Green, 0.00000001);
280 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Red, 0.00000001);
282 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Blend mode is normal",
283 rendering::BlendMode::NORMAL, rContext.BlendMode );
284 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 10",
285 10, rContext.Flatness, 0.00000001 );
286 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
287 sal_Int32(0), rContext.FontId );
290 virtual void eoFillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) override
292 GraphicsContext& rContext( getCurrentContext() );
293 basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
294 aPath.transform( rContext.Transformation );
296 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001);
297 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001);
298 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Green, 0.00000001);
299 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Red, 0.00000001);
301 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Blend mode is normal",
302 rendering::BlendMode::NORMAL, rContext.BlendMode );
303 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
304 1, rContext.Flatness, 0.00000001 );
305 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
306 sal_Int32(0), rContext.FontId );
308 const char sExportString[] = "m12050 49610c-4310 0-7800-3490-7800-7800 0-4300 "
309 "3490-7790 7800-7790 4300 0 7790 3490 7790 7790 0 4310-3490 7800-7790 7800z";
310 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Stroke is a 4-bezier circle",
311 OUString(sExportString), basegfx::utils::exportToSvgD( aPath, true, true, false ) );
313 m_bRedCircleSeen = true;
316 virtual void intersectClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath) override
318 basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
319 basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
321 if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
322 aNewClip = basegfx::utils::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
324 getCurrentContext().Clip = aNewClip;
327 virtual void intersectEoClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath) override
329 basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
330 basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
332 if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
333 aNewClip = basegfx::utils::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
335 getCurrentContext().Clip = aNewClip;
338 virtual void drawGlyphs( const OUString& rGlyphs,
339 const geometry::RealRectangle2D& /*rRect*/,
340 const geometry::Matrix2D& /*rFontMatrix*/,
341 double /*fontSize*/) override
343 m_aTextOut.append(rGlyphs);
346 virtual void endText() override
348 m_aTextOut.append( "\n" );
351 virtual void drawMask(const uno::Sequence<beans::PropertyValue>& xBitmap,
352 bool /*bInvert*/ ) override
354 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask received two properties",
355 sal_Int32(3), xBitmap.getLength() );
356 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask got URL param",
357 OUString("URL"), xBitmap[0].Name );
358 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask got InputStream param",
359 OUString("InputStream"), xBitmap[1].Name );
362 virtual void drawImage(const uno::Sequence<beans::PropertyValue>& xBitmap ) override
364 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage received two properties",
365 sal_Int32(3), xBitmap.getLength() );
366 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage got URL param",
367 OUString("URL"), xBitmap[0].Name );
368 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage got InputStream param",
369 OUString("InputStream"), xBitmap[1].Name );
370 m_bImageSeen = true;
373 virtual void drawColorMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
374 const uno::Sequence<uno::Any>& /*xMaskColors*/ ) override
376 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage received two properties",
377 sal_Int32(3), xBitmap.getLength() );
378 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage got URL param",
379 OUString("URL"), xBitmap[0].Name );
380 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage got InputStream param",
381 OUString("InputStream"), xBitmap[1].Name );
384 virtual void drawMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
385 const uno::Sequence<beans::PropertyValue>& xMask,
386 bool /*bInvertMask*/) override
388 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #1",
389 sal_Int32(3), xBitmap.getLength() );
390 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got URL param #1",
391 OUString("URL"), xBitmap[0].Name );
392 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got InputStream param #1",
393 OUString("InputStream"), xBitmap[1].Name );
395 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #2",
396 sal_Int32(3), xMask.getLength() );
397 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got URL param #2",
398 OUString("URL"), xMask[0].Name );
399 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got InputStream param #2",
400 OUString("InputStream"), xMask[1].Name );
403 virtual void drawAlphaMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
404 const uno::Sequence<beans::PropertyValue>& xMask) override
406 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #1",
407 sal_Int32(3), xBitmap.getLength() );
408 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got URL param #1",
409 OUString("URL"), xBitmap[0].Name );
410 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got InputStream param #1",
411 OUString("InputStream"), xBitmap[1].Name );
413 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #2",
414 sal_Int32(3), xMask.getLength() );
415 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got URL param #2",
416 OUString("URL"), xMask[0].Name );
417 CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got InputStream param #2",
418 OUString("InputStream"), xMask[1].Name );
421 virtual void setTextRenderMode( sal_Int32 ) override
425 typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
426 typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
428 typedef std::vector<GraphicsContext> GraphicsContextStack;
430 sal_Int32 m_nNextFontId;
431 IdToFontMap m_aIdToFont;
432 FontToIdMap m_aFontToId;
434 GraphicsContextStack m_aGCStack;
435 geometry::RealSize2D m_aPageSize;
436 geometry::RealRectangle2D m_aHyperlinkBounds;
437 OUString m_aURI;
438 OUStringBuffer m_aTextOut;
439 sal_Int32 m_nNumPages;
440 bool m_bPageEnded;
441 bool m_bRedCircleSeen;
442 bool m_bGreenStrokeSeen;
443 bool m_bDashedLineSeen;
444 bool m_bImageSeen;
447 class PDFITest : public test::BootstrapFixture
449 public:
450 void testXPDFParser()
452 #if HAVE_FEATURE_POPPLER
453 std::shared_ptr<TestSink> pSink( new TestSink() );
454 CPPUNIT_ASSERT(
455 pdfi::xpdf_ImportFromFile(
456 m_directories.getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
457 pSink,
458 uno::Reference< task::XInteractionHandler >(),
459 OUString(),
460 getComponentContext(), "" ) );
461 pSink->check();
462 #endif
465 void testOdfDrawExport()
467 #if HAVE_FEATURE_POPPLER
468 rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor( new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()) );
469 xAdaptor->setTreeVisitorFactory( createDrawTreeVisitorFactory() );
471 OUString tempFileURL;
472 CPPUNIT_ASSERT_EQUAL( osl::File::E_None, osl::File::createTempFile( nullptr, nullptr, &tempFileURL ) );
473 osl::File::remove( tempFileURL ); // FIXME the below apparently fails silently if the file already exists
474 CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
475 xAdaptor->odfConvert( m_directories.getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
476 new OutputWrap(tempFileURL),
477 nullptr ));
478 osl::File::remove( tempFileURL );
479 #endif
482 void testOdfWriterExport()
484 #if HAVE_FEATURE_POPPLER
485 rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor( new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()) );
486 xAdaptor->setTreeVisitorFactory( createWriterTreeVisitorFactory() );
488 OUString tempFileURL;
489 CPPUNIT_ASSERT_EQUAL( osl::File::E_None, osl::File::createTempFile( nullptr, nullptr, &tempFileURL ) );
490 osl::File::remove( tempFileURL ); // FIXME the below apparently fails silently if the file already exists
491 CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
492 xAdaptor->odfConvert( m_directories.getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
493 new OutputWrap(tempFileURL),
494 nullptr ));
495 osl::File::remove( tempFileURL );
496 #endif
499 void testTdf96993()
501 #if HAVE_FEATURE_POPPLER
502 rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()));
503 xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory());
505 OString aOutput;
506 CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
507 xAdaptor->odfConvert(m_directories.getURLFromSrc("/sdext/source/pdfimport/test/testTdf96993.pdf"),
508 new OutputWrapString(aOutput),
509 nullptr));
510 // This ensures that the imported image arrives properly flipped
511 CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"matrix(18520.8333333333 0 0 26281.9444444444 0 0)\"") != -1);
512 #endif
515 void testTdf98421()
517 #if HAVE_FEATURE_POPPLER
518 rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()));
519 xAdaptor->setTreeVisitorFactory(createWriterTreeVisitorFactory());
521 OString aOutput;
522 CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
523 xAdaptor->odfConvert(m_directories.getURLFromSrc("/sdext/source/pdfimport/test/testTdf96993.pdf"),
524 new OutputWrapString(aOutput),
525 nullptr));
526 // This ensures that the imported image arrives properly flipped
527 CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"scale( 1.0 -1.0 ) translate( 0mm 0mm )\"") != -1);
528 CPPUNIT_ASSERT(aOutput.indexOf("svg:height=\"-262.82mm\"") != -1);
529 #endif
532 void testTdf105536()
534 #if HAVE_FEATURE_POPPLER
535 rtl::Reference<pdfi::PDFIRawAdaptor> xAdaptor(new pdfi::PDFIRawAdaptor(OUString(), getComponentContext()));
536 xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory());
538 OString aOutput;
539 CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
540 xAdaptor->odfConvert(m_directories.getURLFromSrc("/sdext/source/pdfimport/test/testTdf105536.pdf"),
541 new OutputWrapString(aOutput),
542 nullptr));
543 // This ensures that the imported image arrives properly flipped
544 CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"matrix(-21488.4 0 0 -27978.1 21488.4 27978.1)\"") != -1);
545 #endif
548 CPPUNIT_TEST_SUITE(PDFITest);
549 CPPUNIT_TEST(testXPDFParser);
550 CPPUNIT_TEST(testOdfWriterExport);
551 CPPUNIT_TEST(testOdfDrawExport);
552 CPPUNIT_TEST(testTdf96993);
553 CPPUNIT_TEST(testTdf98421);
554 CPPUNIT_TEST(testTdf105536);
555 CPPUNIT_TEST_SUITE_END();
560 CPPUNIT_TEST_SUITE_REGISTRATION(PDFITest);
562 CPPUNIT_PLUGIN_IMPLEMENT();
564 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */