1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sdext.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifdef SYSTEM_ZLIB
32*cdf0e10cSrcweir #include "zlib.h"
33*cdf0e10cSrcweir #else
34*cdf0e10cSrcweir #include <zlib/zlib.h>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "outputwrap.hxx"
38*cdf0e10cSrcweir #include "contentsink.hxx"
39*cdf0e10cSrcweir #include "pdfihelper.hxx"
40*cdf0e10cSrcweir #include "wrapper.hxx"
41*cdf0e10cSrcweir #include "pdfparse.hxx"
42*cdf0e10cSrcweir #include "../pdfiadaptor.hxx"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <rtl/math.hxx>
45*cdf0e10cSrcweir #include <osl/file.hxx>
46*cdf0e10cSrcweir #include <osl/process.h>
47*cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
48*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
49*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
50*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
51*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/rendering/XColorSpace.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/rendering/BlendMode.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
64*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
65*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
66*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
67*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
68*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygonclipper.hxx>
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir #include <vector>
71*cdf0e10cSrcweir #include <hash_map>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir using namespace ::pdfparse;
75*cdf0e10cSrcweir using namespace ::pdfi;
76*cdf0e10cSrcweir using namespace ::com::sun::star;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir namespace
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     class TestSink : public ContentSink
81*cdf0e10cSrcweir     {
82*cdf0e10cSrcweir     public:
83*cdf0e10cSrcweir         TestSink() :
84*cdf0e10cSrcweir             m_nNextFontId( 1 ),
85*cdf0e10cSrcweir             m_aIdToFont(),
86*cdf0e10cSrcweir             m_aFontToId(),
87*cdf0e10cSrcweir             m_aGCStack(1),
88*cdf0e10cSrcweir             m_aPageSize(),
89*cdf0e10cSrcweir             m_aHyperlinkBounds(),
90*cdf0e10cSrcweir             m_aURI(),
91*cdf0e10cSrcweir             m_aTextOut(),
92*cdf0e10cSrcweir             m_nNumPages(0),
93*cdf0e10cSrcweir             m_bPageEnded(false),
94*cdf0e10cSrcweir             m_bRedCircleSeen(false),
95*cdf0e10cSrcweir             m_bGreenStrokeSeen(false),
96*cdf0e10cSrcweir             m_bDashedLineSeen(false)
97*cdf0e10cSrcweir         {}
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         ~TestSink()
100*cdf0e10cSrcweir         {
101*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "A4 page size (in 100th of points)",
102*cdf0e10cSrcweir                                     m_aPageSize.Width == 79400 && m_aPageSize.Height == 59500 );
103*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "endPage() called", m_bPageEnded );
104*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Num pages equal one", m_nNumPages == 1 );
105*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Correct hyperlink bounding box",
106*cdf0e10cSrcweir                                     rtl::math::approxEqual(m_aHyperlinkBounds.X1,34.7 ) &&
107*cdf0e10cSrcweir                                     rtl::math::approxEqual(m_aHyperlinkBounds.Y1,386.0) &&
108*cdf0e10cSrcweir                                     rtl::math::approxEqual(m_aHyperlinkBounds.X2,166.7) &&
109*cdf0e10cSrcweir                                     rtl::math::approxEqual(m_aHyperlinkBounds.Y2,406.2) );
110*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Correct hyperlink URI",
111*cdf0e10cSrcweir                                     m_aURI == ::rtl::OUString::createFromAscii( "http://download.openoffice.org/" ) );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir             const char* sText = " \n \nThis is a testtext\nNew paragraph,\nnew line\n"
114*cdf0e10cSrcweir                 "Hyperlink, this is\n?\nThis is more text\noutline mode\n?\nNew paragraph\n";
115*cdf0e10cSrcweir             ::rtl::OString aTmp;
116*cdf0e10cSrcweir             m_aTextOut.makeStringAndClear().convertToString( &aTmp,
117*cdf0e10cSrcweir                                                              RTL_TEXTENCODING_ASCII_US,
118*cdf0e10cSrcweir                                                              OUSTRING_TO_OSTRING_CVTFLAGS );
119*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Imported text is \"This is a testtext New paragraph, new line"
120*cdf0e10cSrcweir                                     " Hyperlink, this is * This is more text outline mode * New paragraph\"",
121*cdf0e10cSrcweir                                     sText == aTmp );
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "red circle seen in input", m_bRedCircleSeen );
124*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "green stroke seen in input", m_bGreenStrokeSeen );
125*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "dashed line seen in input", m_bDashedLineSeen );
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     private:
129*cdf0e10cSrcweir         GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir         // ContentSink interface implementation
132*cdf0e10cSrcweir         virtual void setPageNum( sal_Int32 nNumPages )
133*cdf0e10cSrcweir         {
134*cdf0e10cSrcweir             m_nNumPages = nNumPages;
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         virtual void startPage( const geometry::RealSize2D& rSize )
138*cdf0e10cSrcweir         {
139*cdf0e10cSrcweir             m_aPageSize = rSize;
140*cdf0e10cSrcweir         }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         virtual void endPage()
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             m_bPageEnded = true;
145*cdf0e10cSrcweir         }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         virtual void hyperLink( const geometry::RealRectangle2D& rBounds,
148*cdf0e10cSrcweir                                 const ::rtl::OUString&             rURI )
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             m_aHyperlinkBounds = rBounds;
151*cdf0e10cSrcweir             m_aURI = rURI;
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         virtual void pushState()
155*cdf0e10cSrcweir         {
156*cdf0e10cSrcweir             m_aGCStack.push_back( m_aGCStack.back() );
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         virtual void popState()
160*cdf0e10cSrcweir         {
161*cdf0e10cSrcweir             m_aGCStack.pop_back();
162*cdf0e10cSrcweir         }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         virtual void setTransformation( const geometry::AffineMatrix2D& rMatrix )
165*cdf0e10cSrcweir         {
166*cdf0e10cSrcweir             basegfx::unotools::homMatrixFromAffineMatrix(
167*cdf0e10cSrcweir                 getCurrentContext().Transformation,
168*cdf0e10cSrcweir                 rMatrix );
169*cdf0e10cSrcweir         }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         virtual void setLineDash( const uno::Sequence<double>& dashes,
172*cdf0e10cSrcweir                                   double                       start )
173*cdf0e10cSrcweir         {
174*cdf0e10cSrcweir             GraphicsContext& rContext( getCurrentContext() );
175*cdf0e10cSrcweir             if( dashes.getLength() )
176*cdf0e10cSrcweir                 comphelper::sequenceToContainer(rContext.DashArray,dashes);
177*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "line dashing start offset", start == 0.0 );
178*cdf0e10cSrcweir         }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         virtual void setFlatness( double nFlatness )
181*cdf0e10cSrcweir         {
182*cdf0e10cSrcweir             getCurrentContext().Flatness = nFlatness;
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         virtual void setLineJoin(sal_Int8 nJoin)
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             getCurrentContext().LineJoin = nJoin;
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         virtual void setLineCap(sal_Int8 nCap)
191*cdf0e10cSrcweir         {
192*cdf0e10cSrcweir             getCurrentContext().LineCap = nCap;
193*cdf0e10cSrcweir         }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir         virtual void setMiterLimit(double nVal)
196*cdf0e10cSrcweir         {
197*cdf0e10cSrcweir             getCurrentContext().MiterLimit = nVal;
198*cdf0e10cSrcweir         }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         virtual void setLineWidth(double nVal)
201*cdf0e10cSrcweir         {
202*cdf0e10cSrcweir             getCurrentContext().LineWidth = nVal;
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir         virtual void setFillColor( const rendering::ARGBColor& rColor )
206*cdf0e10cSrcweir         {
207*cdf0e10cSrcweir             getCurrentContext().FillColor = rColor;
208*cdf0e10cSrcweir         }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         virtual void setStrokeColor( const rendering::ARGBColor& rColor )
211*cdf0e10cSrcweir         {
212*cdf0e10cSrcweir             getCurrentContext().LineColor = rColor;
213*cdf0e10cSrcweir         }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         virtual void setBlendMode(sal_Int8 nMode)
216*cdf0e10cSrcweir         {
217*cdf0e10cSrcweir             getCurrentContext().BlendMode = nMode;
218*cdf0e10cSrcweir         }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir         virtual void setFont( const FontAttributes& rFont )
221*cdf0e10cSrcweir         {
222*cdf0e10cSrcweir             FontToIdMap::const_iterator it = m_aFontToId.find( rFont );
223*cdf0e10cSrcweir             if( it != m_aFontToId.end() )
224*cdf0e10cSrcweir                 getCurrentContext().FontId = it->second;
225*cdf0e10cSrcweir             else
226*cdf0e10cSrcweir             {
227*cdf0e10cSrcweir                 m_aFontToId[ rFont ] = m_nNextFontId;
228*cdf0e10cSrcweir                 m_aIdToFont[ m_nNextFontId ] = rFont;
229*cdf0e10cSrcweir                 getCurrentContext().FontId = m_nNextFontId;
230*cdf0e10cSrcweir                 m_nNextFontId++;
231*cdf0e10cSrcweir             }
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir         virtual void strokePath( const uno::Reference<rendering::XPolyPolygon2D>& rPath )
235*cdf0e10cSrcweir         {
236*cdf0e10cSrcweir             GraphicsContext& rContext( getCurrentContext() );
237*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
238*cdf0e10cSrcweir             aPath.transform( rContext.Transformation );
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir             if( rContext.DashArray.empty() )
241*cdf0e10cSrcweir             {
242*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Line color is green",
243*cdf0e10cSrcweir                                         rContext.LineColor.Alpha == 1.0 &&
244*cdf0e10cSrcweir                                         rContext.LineColor.Red == 0.0 &&
245*cdf0e10cSrcweir                                         rContext.LineColor.Green == 1.0 &&
246*cdf0e10cSrcweir                                         rContext.LineColor.Blue == 0.0 );
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
249*cdf0e10cSrcweir                                         rtl::math::approxEqual(rContext.LineWidth, 28.3) );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir                 const char* sExportString = "m53570 7650-35430 24100";
252*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Stroke is m535.7 518.5-354.3-241",
253*cdf0e10cSrcweir                                         basegfx::tools::exportToSvgD( aPath ).compareToAscii(sExportString) == 0 );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir                 m_bGreenStrokeSeen = true;
256*cdf0e10cSrcweir             }
257*cdf0e10cSrcweir             else
258*cdf0e10cSrcweir             {
259*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Dash array cons  ists of four entries",
260*cdf0e10cSrcweir                                         rContext.DashArray.size() == 4 &&
261*cdf0e10cSrcweir                                         rtl::math::approxEqual(rContext.DashArray[0],14.3764) &&
262*cdf0e10cSrcweir                                         rContext.DashArray[0] == rContext.DashArray[1] &&
263*cdf0e10cSrcweir                                         rContext.DashArray[1] == rContext.DashArray[2] &&
264*cdf0e10cSrcweir                                         rContext.DashArray[2] == rContext.DashArray[3] );
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Line color is black",
267*cdf0e10cSrcweir                                         rContext.LineColor.Alpha == 1.0 &&
268*cdf0e10cSrcweir                                         rContext.LineColor.Red == 0.0 &&
269*cdf0e10cSrcweir                                         rContext.LineColor.Green == 0.0 &&
270*cdf0e10cSrcweir                                         rContext.LineColor.Blue == 0.0 );
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
273*cdf0e10cSrcweir                                         rContext.LineWidth == 0 );
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir                 const char* sExportString = "m49890 5670.00000000001-35430 24090";
276*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE( "Stroke is m49890 5670.00000000001-35430 24090",
277*cdf0e10cSrcweir                                         basegfx::tools::exportToSvgD( aPath ).compareToAscii(sExportString) == 0 );
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir                 m_bDashedLineSeen = true;
280*cdf0e10cSrcweir             }
281*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
282*cdf0e10cSrcweir                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
283*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Join type is round",
284*cdf0e10cSrcweir                                     rContext.LineJoin == rendering::PathJoinType::ROUND );
285*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Cap type is butt",
286*cdf0e10cSrcweir                                     rContext.LineCap == rendering::PathCapType::BUTT );
287*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Line miter limit is 10",
288*cdf0e10cSrcweir                                     rContext.MiterLimit == 10 );
289*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Flatness is 0",
290*cdf0e10cSrcweir                                     rContext.Flatness == 1 );
291*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Font id is 0",
292*cdf0e10cSrcweir                                     rContext.FontId == 0 );
293*cdf0e10cSrcweir         }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir         virtual void fillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath )
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             GraphicsContext& rContext( getCurrentContext() );
298*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
299*cdf0e10cSrcweir             aPath.transform( rContext.Transformation );
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Fill color is black",
302*cdf0e10cSrcweir                                     rContext.FillColor.Alpha == 1.0 &&
303*cdf0e10cSrcweir                                     rContext.FillColor.Red == 0.0 &&
304*cdf0e10cSrcweir                                     rContext.FillColor.Green == 0.0 &&
305*cdf0e10cSrcweir                                     rContext.FillColor.Blue == 0.0 );
306*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
307*cdf0e10cSrcweir                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
308*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Flatness is 10",
309*cdf0e10cSrcweir                                     rContext.Flatness == 10 );
310*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Font id is 0",
311*cdf0e10cSrcweir                                     rContext.FontId == 0 );
312*cdf0e10cSrcweir         }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir         virtual void eoFillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath )
315*cdf0e10cSrcweir         {
316*cdf0e10cSrcweir             GraphicsContext& rContext( getCurrentContext() );
317*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
318*cdf0e10cSrcweir             aPath.transform( rContext.Transformation );
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Fill color is black",
321*cdf0e10cSrcweir                                     rContext.FillColor.Alpha == 1.0 &&
322*cdf0e10cSrcweir                                     rContext.FillColor.Red == 1.0 &&
323*cdf0e10cSrcweir                                     rContext.FillColor.Green == 0.0 &&
324*cdf0e10cSrcweir                                     rContext.FillColor.Blue == 0.0 );
325*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
326*cdf0e10cSrcweir                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
327*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Flatness is 0",
328*cdf0e10cSrcweir                                     rContext.Flatness == 1 );
329*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Font id is 0",
330*cdf0e10cSrcweir                                     rContext.FontId == 0 );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir             const char* sExportString = "m12050 49610c-4310 0-7800-3490-7800-7800 0-4300 "
333*cdf0e10cSrcweir                 "3490-7790 7800-7790 4300 0 7790 3490 7790 7790 0 4310-3490 7800-7790 7800z";
334*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Stroke is a 4-bezier circle",
335*cdf0e10cSrcweir                                     basegfx::tools::exportToSvgD( aPath ).compareToAscii(sExportString) == 0 );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir             m_bRedCircleSeen = true;
338*cdf0e10cSrcweir         }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir         virtual void intersectClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath)
341*cdf0e10cSrcweir         {
342*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
343*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir             if( aCurClip.count() )  // #i92985# adapted API from (..., false, false) to (..., true, false)
346*cdf0e10cSrcweir                 aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir             getCurrentContext().Clip = aNewClip;
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         virtual void intersectEoClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath)
352*cdf0e10cSrcweir         {
353*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
354*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir             if( aCurClip.count() )  // #i92985# adapted API from (..., false, false) to (..., true, false)
357*cdf0e10cSrcweir                 aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir             getCurrentContext().Clip = aNewClip;
360*cdf0e10cSrcweir         }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir         virtual void drawGlyphs( const rtl::OUString&             rGlyphs,
363*cdf0e10cSrcweir                                  const geometry::RealRectangle2D& /*rRect*/,
364*cdf0e10cSrcweir                                  const geometry::Matrix2D&        /*rFontMatrix*/ )
365*cdf0e10cSrcweir         {
366*cdf0e10cSrcweir             m_aTextOut.append(rGlyphs);
367*cdf0e10cSrcweir         }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir         virtual void endText()
370*cdf0e10cSrcweir         {
371*cdf0e10cSrcweir             m_aTextOut.append( ::rtl::OUString::createFromAscii("\n") );
372*cdf0e10cSrcweir         }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir         virtual void drawMask(const uno::Sequence<beans::PropertyValue>& xBitmap,
375*cdf0e10cSrcweir                               bool                                       /*bInvert*/ )
376*cdf0e10cSrcweir         {
377*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMask received two properties",
378*cdf0e10cSrcweir                                     xBitmap.getLength()==3 );
379*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMask got URL param",
380*cdf0e10cSrcweir                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
381*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMask got InputStream param",
382*cdf0e10cSrcweir                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
383*cdf0e10cSrcweir         }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir         virtual void drawImage(const uno::Sequence<beans::PropertyValue>& xBitmap )
386*cdf0e10cSrcweir         {
387*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawImage received two properties",
388*cdf0e10cSrcweir                                     xBitmap.getLength()==3 );
389*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawImage got URL param",
390*cdf0e10cSrcweir                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
391*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawImage got InputStream param",
392*cdf0e10cSrcweir                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
393*cdf0e10cSrcweir         }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         virtual void drawColorMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
396*cdf0e10cSrcweir                                           const uno::Sequence<uno::Any>&             /*xMaskColors*/ )
397*cdf0e10cSrcweir         {
398*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage received two properties",
399*cdf0e10cSrcweir                                     xBitmap.getLength()==3 );
400*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage got URL param",
401*cdf0e10cSrcweir                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
402*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage got InputStream param",
403*cdf0e10cSrcweir                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
404*cdf0e10cSrcweir         }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir         virtual void drawMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
407*cdf0e10cSrcweir                                      const uno::Sequence<beans::PropertyValue>& xMask,
408*cdf0e10cSrcweir                                      bool                                       /*bInvertMask*/)
409*cdf0e10cSrcweir         {
410*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage received two properties #1",
411*cdf0e10cSrcweir                                     xBitmap.getLength()==3 );
412*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got URL param #1",
413*cdf0e10cSrcweir                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
414*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got InputStream param #1",
415*cdf0e10cSrcweir                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage received two properties #2",
418*cdf0e10cSrcweir                                     xMask.getLength()==3 );
419*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got URL param #2",
420*cdf0e10cSrcweir                                     xMask[0].Name.compareToAscii( "URL" ) == 0 );
421*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got InputStream param #2",
422*cdf0e10cSrcweir                                     xMask[1].Name.compareToAscii( "InputStream" ) == 0 );
423*cdf0e10cSrcweir         }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         virtual void drawAlphaMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
426*cdf0e10cSrcweir                                           const uno::Sequence<beans::PropertyValue>& xMask)
427*cdf0e10cSrcweir         {
428*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage received two properties #1",
429*cdf0e10cSrcweir                                     xBitmap.getLength()==3 );
430*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got URL param #1",
431*cdf0e10cSrcweir                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
432*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got InputStream param #1",
433*cdf0e10cSrcweir                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage received two properties #2",
436*cdf0e10cSrcweir                                     xMask.getLength()==3 );
437*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got URL param #2",
438*cdf0e10cSrcweir                                     xMask[0].Name.compareToAscii( "URL" ) == 0 );
439*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got InputStream param #2",
440*cdf0e10cSrcweir                                     xMask[1].Name.compareToAscii( "InputStream" ) == 0 );
441*cdf0e10cSrcweir         }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir         virtual void setTextRenderMode( sal_Int32 )
444*cdf0e10cSrcweir         {
445*cdf0e10cSrcweir         }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir         typedef std::hash_map<sal_Int32,FontAttributes> IdToFontMap;
448*cdf0e10cSrcweir         typedef std::hash_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir         typedef std::hash_map<sal_Int32,GraphicsContext> IdToGCMap;
451*cdf0e10cSrcweir         typedef std::hash_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir         typedef std::vector<GraphicsContext> GraphicsContextStack;
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir         sal_Int32                 m_nNextFontId;
456*cdf0e10cSrcweir         IdToFontMap               m_aIdToFont;
457*cdf0e10cSrcweir         FontToIdMap               m_aFontToId;
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir         GraphicsContextStack      m_aGCStack;
460*cdf0e10cSrcweir         geometry::RealSize2D      m_aPageSize;
461*cdf0e10cSrcweir         geometry::RealRectangle2D m_aHyperlinkBounds;
462*cdf0e10cSrcweir         ::rtl::OUString           m_aURI;
463*cdf0e10cSrcweir         ::rtl::OUStringBuffer     m_aTextOut;
464*cdf0e10cSrcweir         sal_Int32                 m_nNumPages;
465*cdf0e10cSrcweir         bool                      m_bPageEnded;
466*cdf0e10cSrcweir         bool                      m_bRedCircleSeen;
467*cdf0e10cSrcweir         bool                      m_bGreenStrokeSeen;
468*cdf0e10cSrcweir         bool                      m_bDashedLineSeen;
469*cdf0e10cSrcweir     };
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir     class PDFITest : public CppUnit::TestFixture
472*cdf0e10cSrcweir     {
473*cdf0e10cSrcweir         uno::Reference<uno::XComponentContext> mxCtx;
474*cdf0e10cSrcweir         rtl::OUString                          msBaseDir;
475*cdf0e10cSrcweir         bool                                   mbUnoInitialized;
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     public:
478*cdf0e10cSrcweir         PDFITest() : mxCtx(),msBaseDir(),mbUnoInitialized(false)
479*cdf0e10cSrcweir         {}
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir         void setUp()
482*cdf0e10cSrcweir         {
483*cdf0e10cSrcweir             if( !mbUnoInitialized )
484*cdf0e10cSrcweir             {
485*cdf0e10cSrcweir                 const char* pArgs( getForwardString() );
486*cdf0e10cSrcweir                 CPPUNIT_ASSERT_MESSAGE("Test file parameter", pArgs);
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir                 msBaseDir = rtl::OUString::createFromAscii(pArgs);
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir                 // bootstrap UNO
491*cdf0e10cSrcweir                 try
492*cdf0e10cSrcweir                 {
493*cdf0e10cSrcweir                     ::rtl::OUString aIniUrl;
494*cdf0e10cSrcweir                     CPPUNIT_ASSERT_MESSAGE(
495*cdf0e10cSrcweir                         "Converting ini file to URL",
496*cdf0e10cSrcweir                         osl_getFileURLFromSystemPath(
497*cdf0e10cSrcweir                             (msBaseDir+rtl::OUString::createFromAscii("pdfi_unittest_test.ini")).pData,
498*cdf0e10cSrcweir                             &aIniUrl.pData ) == osl_File_E_None );
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir                     mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
501*cdf0e10cSrcweir                     CPPUNIT_ASSERT_MESSAGE("Getting component context", mxCtx.is());
502*cdf0e10cSrcweir                 }
503*cdf0e10cSrcweir                 catch( uno::Exception& )
504*cdf0e10cSrcweir                 {
505*cdf0e10cSrcweir                     CPPUNIT_ASSERT_MESSAGE("Bootstrapping UNO", false);
506*cdf0e10cSrcweir                 }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir                 mbUnoInitialized = true;
509*cdf0e10cSrcweir             }
510*cdf0e10cSrcweir         }
511*cdf0e10cSrcweir         void tearDown()
512*cdf0e10cSrcweir         {
513*cdf0e10cSrcweir         }
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir         void testXPDFParser()
516*cdf0e10cSrcweir         {
517*cdf0e10cSrcweir             pdfi::ContentSinkSharedPtr pSink( new TestSink() );
518*cdf0e10cSrcweir             pdfi::xpdf_ImportFromFile( msBaseDir + rtl::OUString::createFromAscii("pdfi_unittest_test.pdf"),
519*cdf0e10cSrcweir                                        pSink,
520*cdf0e10cSrcweir                                        uno::Reference< task::XInteractionHandler >(),
521*cdf0e10cSrcweir                                        rtl::OUString(),
522*cdf0e10cSrcweir                                        mxCtx );
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir             // make destruction explicit, a bunch of things are
525*cdf0e10cSrcweir             // checked in the destructor
526*cdf0e10cSrcweir             pSink.reset();
527*cdf0e10cSrcweir         }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir         void testOdfDrawExport()
530*cdf0e10cSrcweir         {
531*cdf0e10cSrcweir             pdfi::PDFIRawAdaptor aAdaptor( mxCtx );
532*cdf0e10cSrcweir             aAdaptor.setTreeVisitorFactory( createDrawTreeVisitorFactory() );
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir             ::rtl::OUString aURL, aAbsURL, aBaseURL;
535*cdf0e10cSrcweir             osl_getFileURLFromSystemPath( (msBaseDir + rtl::OUString::createFromAscii("pdfi_unittest_draw.xml")).pData,
536*cdf0e10cSrcweir                                           &aURL.pData );
537*cdf0e10cSrcweir             osl_getProcessWorkingDir(&aBaseURL.pData);
538*cdf0e10cSrcweir             osl_getAbsoluteFileURL(aBaseURL.pData,aURL.pData,&aAbsURL.pData);
539*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
540*cdf0e10cSrcweir                                    aAdaptor.odfConvert( msBaseDir + rtl::OUString::createFromAscii("pdfi_unittest_test.pdf"),
541*cdf0e10cSrcweir                                                         new OutputWrap(aAbsURL),
542*cdf0e10cSrcweir                                                         NULL ));
543*cdf0e10cSrcweir         }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir         void testOdfWriterExport()
546*cdf0e10cSrcweir         {
547*cdf0e10cSrcweir             pdfi::PDFIRawAdaptor aAdaptor( mxCtx );
548*cdf0e10cSrcweir             aAdaptor.setTreeVisitorFactory( createWriterTreeVisitorFactory() );
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir             ::rtl::OUString aURL, aAbsURL, aBaseURL;
551*cdf0e10cSrcweir             osl_getFileURLFromSystemPath( (msBaseDir + rtl::OUString::createFromAscii("pdfi_unittest_writer.xml")).pData,
552*cdf0e10cSrcweir                                           &aURL.pData );
553*cdf0e10cSrcweir             osl_getProcessWorkingDir(&aBaseURL.pData);
554*cdf0e10cSrcweir             osl_getAbsoluteFileURL(aBaseURL.pData,aURL.pData,&aAbsURL.pData);
555*cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
556*cdf0e10cSrcweir                                    aAdaptor.odfConvert( msBaseDir + rtl::OUString::createFromAscii("pdfi_unittest_test.pdf"),
557*cdf0e10cSrcweir                                                         new OutputWrap(aAbsURL),
558*cdf0e10cSrcweir                                                         NULL ));
559*cdf0e10cSrcweir         }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir         CPPUNIT_TEST_SUITE(PDFITest);
562*cdf0e10cSrcweir         CPPUNIT_TEST(testXPDFParser);
563*cdf0e10cSrcweir         CPPUNIT_TEST(testOdfWriterExport);
564*cdf0e10cSrcweir         CPPUNIT_TEST(testOdfDrawExport);
565*cdf0e10cSrcweir         CPPUNIT_TEST_SUITE_END();
566*cdf0e10cSrcweir     };
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir // =======================================================================
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PDFITest, "PDFITest");
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir // -----------------------------------------------------------------------------
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
578*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
579*cdf0e10cSrcweir NOADDITIONAL;
580