LibreOffice Module sdext (master)  1
tests.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <config_features.h>
21 
22 #include "outputwrap.hxx"
23 #include <contentsink.hxx>
24 #include <pdfihelper.hxx>
25 #include <wrapper.hxx>
26 #include <pdfparse.hxx>
27 #include "../pdfiadaptor.hxx"
28 
29 #include <rtl/math.hxx>
30 #include <osl/file.hxx>
31 #include <comphelper/sequence.hxx>
32 
33 #include <cppunit/TestAssert.h>
34 #include <cppunit/extensions/HelperMacros.h>
35 #include <cppunit/plugin/TestPlugIn.h>
37 
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>
43 
48 
49 #include <unordered_map>
50 #include <vector>
51 
52 #include <rtl/ustring.hxx>
53 #include <rtl/ref.hxx>
54 
55 using namespace ::pdfparse;
56 using namespace ::pdfi;
57 using namespace ::com::sun::star;
58 
59 namespace
60 {
61 
62  class TestSink : public ContentSink
63  {
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)
80  {}
81 
82  void check()
83  {
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 );
94 
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) );
104 
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 );
109  }
110 
111  private:
112  GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
113 
114  // ContentSink interface implementation
115  virtual void setPageNum( sal_Int32 nNumPages ) override
116  {
117  m_nNumPages = nNumPages;
118  }
119 
120  virtual void startPage( const geometry::RealSize2D& rSize ) override
121  {
122  m_aPageSize = rSize;
123  }
124 
125  virtual void endPage() override
126  {
127  m_bPageEnded = true;
128  }
129 
130  virtual void hyperLink( const geometry::RealRectangle2D& rBounds,
131  const OUString& rURI ) override
132  {
133  m_aHyperlinkBounds = rBounds;
134  m_aURI = rURI;
135  }
136 
137  virtual void pushState() override
138  {
139  GraphicsContextStack::value_type const a(m_aGCStack.back());
140  m_aGCStack.push_back(a);
141  }
142 
143  virtual void popState() override
144  {
145  m_aGCStack.pop_back();
146  }
147 
148  virtual void setTransformation( const geometry::AffineMatrix2D& rMatrix ) override
149  {
151  getCurrentContext().Transformation,
152  rMatrix );
153  }
154 
155  virtual void setLineDash( const uno::Sequence<double>& dashes,
156  double start ) override
157  {
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 );
162  }
163 
164  virtual void setFlatness( double nFlatness ) override
165  {
166  getCurrentContext().Flatness = nFlatness;
167  }
168 
169  virtual void setLineJoin(sal_Int8 nJoin) override
170  {
171  getCurrentContext().LineJoin = nJoin;
172  }
173 
174  virtual void setLineCap(sal_Int8 nCap) override
175  {
176  getCurrentContext().LineCap = nCap;
177  }
178 
179  virtual void setMiterLimit(double nVal) override
180  {
181  getCurrentContext().MiterLimit = nVal;
182  }
183 
184  virtual void setLineWidth(double nVal) override
185  {
186  getCurrentContext().LineWidth = nVal;
187  }
188 
189  virtual void setFillColor( const rendering::ARGBColor& rColor ) override
190  {
191  getCurrentContext().FillColor = rColor;
192  }
193 
194  virtual void setStrokeColor( const rendering::ARGBColor& rColor ) override
195  {
196  getCurrentContext().LineColor = rColor;
197  }
198 
199  virtual void setFont( const FontAttributes& rFont ) override
200  {
201  FontToIdMap::const_iterator it = m_aFontToId.find( rFont );
202  if( it != m_aFontToId.end() )
203  getCurrentContext().FontId = it->second;
204  else
205  {
206  m_aFontToId[ rFont ] = m_nNextFontId;
207  m_aIdToFont[ m_nNextFontId ] = rFont;
208  getCurrentContext().FontId = m_nNextFontId;
209  m_nNextFontId++;
210  }
211  }
212 
213  virtual void strokePath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) override
214  {
215  GraphicsContext& rContext( getCurrentContext() );
217  aPath.transform( rContext.Transformation );
218 
219  if( rContext.DashArray.empty() )
220  {
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);
225 
226  CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
227  rtl::math::approxEqual(rContext.LineWidth, 28.3) );
228 
229  static constexpr OUStringLiteral sExportString = u"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 ) );
232 
233  m_bGreenStrokeSeen = true;
234  }
235  else
236  {
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 );
242 
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);
247 
248  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line width is 0",
249  0, rContext.LineWidth, 0.0000001 );
250 
251  static constexpr OUStringLiteral sExportString = u"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 ) );
254 
255  m_bDashedLineSeen = true;
256  }
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 );
269  }
270 
271  virtual void fillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) override
272  {
273  GraphicsContext& rContext( getCurrentContext() );
275  aPath.transform( rContext.Transformation );
276 
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);
281 
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 );
288  }
289 
290  virtual void eoFillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) override
291  {
292  GraphicsContext& rContext( getCurrentContext() );
294  aPath.transform( rContext.Transformation );
295 
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);
300 
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 );
307 
308  static constexpr OUStringLiteral sExportString
309  = u"m12050 49610c-4310 0-7800-3490-7800-7800 0-4300 "
310  "3490-7790 7800-7790 4300 0 7790 3490 7790 7790 0 4310-3490 7800-7790 7800z";
311  CPPUNIT_ASSERT_EQUAL_MESSAGE( "Stroke is a 4-bezier circle",
312  OUString(sExportString), basegfx::utils::exportToSvgD( aPath, true, true, false ) );
313 
314  m_bRedCircleSeen = true;
315  }
316 
317  virtual void intersectClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath) override
318  {
320  basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
321 
322  if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
323  aNewClip = basegfx::utils::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
324 
325  getCurrentContext().Clip = aNewClip;
326  }
327 
328  virtual void intersectEoClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath) override
329  {
331  basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
332 
333  if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
334  aNewClip = basegfx::utils::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
335 
336  getCurrentContext().Clip = aNewClip;
337  }
338 
339  virtual void drawGlyphs( const OUString& rGlyphs,
340  const geometry::RealRectangle2D& /*rRect*/,
341  const geometry::Matrix2D& /*rFontMatrix*/,
342  double /*fontSize*/) override
343  {
344  m_aTextOut.append(rGlyphs);
345  }
346 
347  virtual void endText() override
348  {
349  m_aTextOut.append( "\n" );
350  }
351 
352  virtual void drawMask(const uno::Sequence<beans::PropertyValue>& xBitmap,
353  bool /*bInvert*/ ) override
354  {
355  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask received two properties",
356  sal_Int32(3), xBitmap.getLength() );
357  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask got URL param",
358  OUString("URL"), xBitmap[0].Name );
359  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask got InputStream param",
360  OUString("InputStream"), xBitmap[1].Name );
361  }
362 
363  virtual void drawImage(const uno::Sequence<beans::PropertyValue>& xBitmap ) override
364  {
365  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage received two properties",
366  sal_Int32(3), xBitmap.getLength() );
367  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage got URL param",
368  OUString("URL"), xBitmap[0].Name );
369  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage got InputStream param",
370  OUString("InputStream"), xBitmap[1].Name );
371  m_bImageSeen = true;
372  }
373 
374  virtual void drawColorMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
375  const uno::Sequence<uno::Any>& /*xMaskColors*/ ) override
376  {
377  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage received two properties",
378  sal_Int32(3), xBitmap.getLength() );
379  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage got URL param",
380  OUString("URL"), xBitmap[0].Name );
381  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage got InputStream param",
382  OUString("InputStream"), xBitmap[1].Name );
383  }
384 
385  virtual void drawMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
386  const uno::Sequence<beans::PropertyValue>& xMask,
387  bool /*bInvertMask*/) override
388  {
389  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #1",
390  sal_Int32(3), xBitmap.getLength() );
391  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got URL param #1",
392  OUString("URL"), xBitmap[0].Name );
393  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got InputStream param #1",
394  OUString("InputStream"), xBitmap[1].Name );
395 
396  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #2",
397  sal_Int32(3), xMask.getLength() );
398  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got URL param #2",
399  OUString("URL"), xMask[0].Name );
400  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage got InputStream param #2",
401  OUString("InputStream"), xMask[1].Name );
402  }
403 
404  virtual void drawAlphaMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
405  const uno::Sequence<beans::PropertyValue>& xMask) override
406  {
407  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #1",
408  sal_Int32(3), xBitmap.getLength() );
409  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got URL param #1",
410  OUString("URL"), xBitmap[0].Name );
411  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got InputStream param #1",
412  OUString("InputStream"), xBitmap[1].Name );
413 
414  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #2",
415  sal_Int32(3), xMask.getLength() );
416  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got URL param #2",
417  OUString("URL"), xMask[0].Name );
418  CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage got InputStream param #2",
419  OUString("InputStream"), xMask[1].Name );
420  }
421 
422  virtual void setTextRenderMode( sal_Int32 ) override
423  {
424  }
425 
426  typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
427  typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
428 
429  typedef std::vector<GraphicsContext> GraphicsContextStack;
430 
431  sal_Int32 m_nNextFontId;
432  IdToFontMap m_aIdToFont;
433  FontToIdMap m_aFontToId;
434 
435  GraphicsContextStack m_aGCStack;
436  geometry::RealSize2D m_aPageSize;
437  geometry::RealRectangle2D m_aHyperlinkBounds;
438  OUString m_aURI;
439  OUStringBuffer m_aTextOut;
440  sal_Int32 m_nNumPages;
441  bool m_bPageEnded;
442  bool m_bRedCircleSeen;
443  bool m_bGreenStrokeSeen;
444  bool m_bDashedLineSeen;
445  bool m_bImageSeen;
446  };
447 
448  class PDFITest : public test::BootstrapFixture
449  {
450  public:
451  void testXPDFParser()
452  {
453 #if HAVE_FEATURE_POPPLER
454  auto pSink = std::make_shared<TestSink>();
455  CPPUNIT_ASSERT(
457  m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testinput.pdf"),
458  pSink,
459  uno::Reference< task::XInteractionHandler >(),
460  OUString(),
461  getComponentContext(), "" ) );
462  pSink->check();
463 #endif
464  }
465 
466  void testOdfDrawExport()
467  {
468 #if HAVE_FEATURE_POPPLER
470  xAdaptor->setTreeVisitorFactory( createDrawTreeVisitorFactory() );
471 
472  OUString tempFileURL;
473  CPPUNIT_ASSERT_EQUAL( osl::File::E_None, osl::File::createTempFile( nullptr, nullptr, &tempFileURL ) );
474  osl::File::remove( tempFileURL ); // FIXME the below apparently fails silently if the file already exists
475  CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
476  xAdaptor->odfConvert( m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testinput.pdf"),
477  new OutputWrap(tempFileURL),
478  nullptr ));
479  osl::File::remove( tempFileURL );
480 #endif
481  }
482 
483  void testOdfWriterExport()
484  {
485 #if HAVE_FEATURE_POPPLER
487  xAdaptor->setTreeVisitorFactory( createWriterTreeVisitorFactory() );
488 
489  OUString tempFileURL;
490  CPPUNIT_ASSERT_EQUAL( osl::File::E_None, osl::File::createTempFile( nullptr, nullptr, &tempFileURL ) );
491  osl::File::remove( tempFileURL ); // FIXME the below apparently fails silently if the file already exists
492  CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
493  xAdaptor->odfConvert( m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testinput.pdf"),
494  new OutputWrap(tempFileURL),
495  nullptr ));
496  osl::File::remove( tempFileURL );
497 #endif
498  }
499 
500  void testTdf96993()
501  {
502 #if HAVE_FEATURE_POPPLER
504  xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory());
505 
506  OString aOutput;
507  CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
508  xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testTdf96993.pdf"),
509  new OutputWrapString(aOutput),
510  nullptr));
511  // This ensures that the imported image arrives properly flipped
512  CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"matrix(18520.8333333333 0 0 26281.9444444444 0 0)\"") != -1);
513 #endif
514  }
515 
516  void testTdf98421()
517  {
518 #if HAVE_FEATURE_POPPLER
520  xAdaptor->setTreeVisitorFactory(createWriterTreeVisitorFactory());
521 
522  OString aOutput;
523  CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
524  xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testTdf96993.pdf"),
525  new OutputWrapString(aOutput),
526  nullptr));
527  // This ensures that the imported image arrives properly flipped
528  CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"scale( 1.0 -1.0 ) translate( 0mm 0mm )\"") != -1);
529  CPPUNIT_ASSERT(aOutput.indexOf("svg:height=\"-262.82mm\"") != -1);
530 #endif
531  }
532 
533  void testTdf105536()
534  {
535 #if HAVE_FEATURE_POPPLER
537  xAdaptor->setTreeVisitorFactory(createDrawTreeVisitorFactory());
538 
539  OString aOutput;
540  CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
541  xAdaptor->odfConvert(m_directories.getURLFromSrc(u"/sdext/source/pdfimport/test/testTdf105536.pdf"),
542  new OutputWrapString(aOutput),
543  nullptr));
544  // This ensures that the imported image arrives properly flipped
545  CPPUNIT_ASSERT(aOutput.indexOf("draw:transform=\"matrix(-21488.4 0 0 -27978.1 21488.4 27978.1)\"") != -1);
546 #endif
547  }
548 
549  CPPUNIT_TEST_SUITE(PDFITest);
550  CPPUNIT_TEST(testXPDFParser);
551  CPPUNIT_TEST(testOdfWriterExport);
552  CPPUNIT_TEST(testOdfDrawExport);
553  CPPUNIT_TEST(testTdf96993);
554  CPPUNIT_TEST(testTdf98421);
555  CPPUNIT_TEST(testTdf105536);
556  CPPUNIT_TEST_SUITE_END();
557  };
558 
559 }
560 
562 
564 
565 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
signed char sal_Int8
B2DPolyPolygon clipPolyPolygonOnPolyPolygon(const B2DPolyPolygon &rCandidate, const B2DPolyPolygon &rClip, bool bInside, bool bStroke)
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
bool xpdf_ImportFromFile(const OUString &rURL, const ContentSinkSharedPtr &rSink, const css::uno::Reference< css::task::XInteractionHandler > &xIHdl, const OUString &rPwd, const css::uno::Reference< css::uno::XComponentContext > &xContext, const OUString &rFilterOptions)
Adapts raw pdf import to XImportFilter interface.
Definition: pdfiadaptor.hxx:82
def getCurrentContext()
uno_Any a
TreeVisitorFactorySharedPtr createWriterTreeVisitorFactory()
float u
void transform(const basegfx::B2DHomMatrix &rMatrix)
::basegfx::B2DPolyPolygon b2DPolyPolygonFromXPolyPolygon2D(const uno::Reference< rendering::XPolyPolygon2D > &xPoly)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
sal_uInt32 count() const
CPPUNIT_PLUGIN_IMPLEMENT()
CPPUNIT_TEST_SUITE_REGISTRATION(PDFITest)
::basegfx::B2DHomMatrix & homMatrixFromAffineMatrix(::basegfx::B2DHomMatrix &output, const geometry::AffineMatrix2D &input)
OUString exportToSvgD(const B2DPolyPolygon &rPolyPoly, bool bUseRelativeCoordinates, bool bDetectQuadraticBeziers, bool bHandleRelativeNextPointCompatible, bool bOOXMLMotionPath=false)
TreeVisitorFactorySharedPtr createDrawTreeVisitorFactory()