Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "pdffilter.hxx"
31 : : #include "pdfexport.hxx"
32 : : #include <vcl/svapp.hxx>
33 : : #include <vcl/window.hxx>
34 : : #include <svl/outstrm.hxx>
35 : : #include <svtools/FilterConfigItem.hxx>
36 : :
37 : : // -------------
38 : : // - PDFFilter -
39 : : // -------------
40 : :
41 : 0 : PDFFilter::PDFFilter( const Reference< XMultiServiceFactory > &rxMSF ) :
42 : 0 : mxMSF( rxMSF )
43 : : {
44 : 0 : }
45 : :
46 : : // -----------------------------------------------------------------------------
47 : :
48 : 0 : PDFFilter::~PDFFilter()
49 : : {
50 : 0 : }
51 : :
52 : : // -----------------------------------------------------------------------------
53 : :
54 : 0 : sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
55 : : {
56 : 0 : Reference< XOutputStream > xOStm;
57 : 0 : Sequence< PropertyValue > aFilterData;
58 : 0 : sal_Int32 nLength = rDescriptor.getLength();
59 : 0 : const PropertyValue* pValue = rDescriptor.getConstArray();
60 : 0 : sal_Bool bRet = sal_False;
61 : 0 : Reference< task::XStatusIndicator > xStatusIndicator;
62 : 0 : Reference< task::XInteractionHandler > xIH;
63 : :
64 : 0 : for ( sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
65 : : {
66 : 0 : if ( pValue[ i ].Name == "OutputStream" )
67 : 0 : pValue[ i ].Value >>= xOStm;
68 : 0 : else if ( pValue[ i ].Name == "FilterData" )
69 : 0 : pValue[ i ].Value >>= aFilterData;
70 : 0 : else if ( pValue[ i ].Name == "StatusIndicator" )
71 : 0 : pValue[ i ].Value >>= xStatusIndicator;
72 : 0 : else if ( pValue[i].Name == "InteractionHandler" )
73 : 0 : pValue[i].Value >>= xIH;
74 : : }
75 : :
76 : : /* we don't get FilterData if we are exporting directly
77 : : to pdf, but we have to use the last user settings (especially for the CompressMode) */
78 : 0 : if ( !aFilterData.getLength() )
79 : : {
80 : 0 : FilterConfigItem aCfgItem( String( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/PDF/Export/" ) ) );
81 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseLosslessCompression" ) ), sal_False );
82 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 90 );
83 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ReduceImageResolution" ) ), sal_False );
84 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "MaxImageResolution" ) ), 300 );
85 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseTaggedPDF" ) ), sal_False );
86 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "SelectPdfVersion" ) ), 0 );
87 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportNotes" ) ), sal_False );
88 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportNotesPages" ) ), sal_False );
89 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseTransitionEffects" ) ), sal_True );
90 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsSkipEmptyPages" ) ), sal_False );
91 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportFormFields" ) ), sal_True );
92 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FormsType" ) ), 0 );
93 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerToolbar" ) ), sal_False );
94 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerMenubar" ) ), sal_False );
95 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerWindowControls" ) ), sal_False );
96 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ResizeWindowToInitialPage" ) ), sal_False );
97 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "CenterWindow" ) ), sal_False );
98 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "OpenInFullScreenMode" ) ), sal_False );
99 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "DisplayPDFDocumentTitle" ) ), sal_True );
100 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "InitialView" ) ), 0 );
101 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Magnification" ) ), 0 );
102 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PageLayout" ) ), 0 );
103 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "FirstPageOnLeft" ) ), sal_False );
104 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsAddStream" ) ), sal_False );
105 : : //
106 : : // the encryption is not available when exporting directly, since the encryption is off by default and the selection
107 : : // (encrypt or not) is not persistent; it's available through macro though,
108 : : // provided the correct property values are set, see help
109 : : //
110 : : // now, the relative link stuff
111 : 0 : aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportLinksRelativeFsys" ) ), sal_False );
112 : 0 : aCfgItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PDFViewSelection" ) ), 0 );
113 : 0 : aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ConvertOOoTargetToPDFTarget" ) ), sal_False );
114 : 0 : aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarksToPDFDestination" ) ), sal_False );
115 : :
116 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarks" ) ), sal_True );
117 : 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportHiddenSlides" ) ), sal_False );
118 : 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "OpenBookmarkLevels" ) ), -1 );
119 : 0 : aFilterData = aCfgItem.GetFilterData();
120 : : }
121 : 0 : if( mxSrcDoc.is() && xOStm.is() )
122 : : {
123 : 0 : PDFExport aExport( mxSrcDoc, xStatusIndicator, xIH, mxMSF );
124 : 0 : ::utl::TempFile aTempFile;
125 : :
126 : 0 : aTempFile.EnableKillingFile();
127 : 0 : bRet = aExport.Export( aTempFile.GetURL(), aFilterData );
128 : :
129 : 0 : if( bRet )
130 : : {
131 : 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
132 : :
133 : 0 : if( pIStm )
134 : : {
135 : 0 : SvOutputStream aOStm( xOStm );
136 : :
137 : 0 : aOStm << *pIStm;
138 : 0 : bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) );
139 : :
140 : 0 : delete pIStm;
141 : : }
142 : 0 : }
143 : : }
144 : :
145 : 0 : return bRet;
146 : : }
147 : :
148 : : // -----------------------------------------------------------------------------
149 : : class FocusWindowWaitCursor
150 : : {
151 : : Window* m_pFocusWindow;
152 : : public:
153 : 0 : FocusWindowWaitCursor() :
154 : 0 : m_pFocusWindow( Application::GetFocusWindow() )
155 : : {
156 : 0 : if( m_pFocusWindow )
157 : : {
158 : 0 : m_pFocusWindow->AddEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
159 : 0 : m_pFocusWindow->EnterWait();
160 : : }
161 : 0 : }
162 : 0 : ~FocusWindowWaitCursor()
163 : : {
164 : 0 : if( m_pFocusWindow )
165 : : {
166 : 0 : m_pFocusWindow->LeaveWait();
167 : 0 : m_pFocusWindow->RemoveEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
168 : : }
169 : 0 : }
170 : :
171 : : DECL_LINK( DestroyedLink, VclWindowEvent* );
172 : : };
173 : :
174 : 0 : IMPL_LINK( FocusWindowWaitCursor, DestroyedLink, VclWindowEvent*, pEvent )
175 : : {
176 : 0 : if( pEvent->GetId() == VCLEVENT_OBJECT_DYING )
177 : 0 : m_pFocusWindow = NULL;
178 : 0 : return 0;
179 : : }
180 : :
181 : 0 : sal_Bool SAL_CALL PDFFilter::filter( const Sequence< PropertyValue >& rDescriptor )
182 : : throw (RuntimeException)
183 : : {
184 : 0 : FocusWindowWaitCursor aCur;
185 : :
186 : 0 : const sal_Bool bRet = implExport( rDescriptor );
187 : :
188 : 0 : return bRet;
189 : : }
190 : :
191 : : // -----------------------------------------------------------------------------
192 : :
193 : 0 : void SAL_CALL PDFFilter::cancel( ) throw (RuntimeException)
194 : : {
195 : 0 : }
196 : :
197 : : // -----------------------------------------------------------------------------
198 : :
199 : 0 : void SAL_CALL PDFFilter::setSourceDocument( const Reference< XComponent >& xDoc )
200 : : throw (IllegalArgumentException, RuntimeException)
201 : : {
202 : 0 : mxSrcDoc = xDoc;
203 : 0 : }
204 : :
205 : : // -----------------------------------------------------------------------------
206 : :
207 : 0 : void SAL_CALL PDFFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& )
208 : : throw (Exception, RuntimeException)
209 : : {
210 : 0 : }
211 : :
212 : : // -----------------------------------------------------------------------------
213 : :
214 : 0 : OUString PDFFilter_getImplementationName ()
215 : : throw (RuntimeException)
216 : : {
217 : 0 : return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PDF.PDFFilter" ) );
218 : : }
219 : :
220 : : // -----------------------------------------------------------------------------
221 : :
222 : : #define SERVICE_NAME "com.sun.star.document.PDFFilter"
223 : :
224 : 0 : sal_Bool SAL_CALL PDFFilter_supportsService( const OUString& ServiceName )
225 : : throw (RuntimeException)
226 : : {
227 : 0 : return ServiceName == SERVICE_NAME;
228 : : }
229 : :
230 : : // -----------------------------------------------------------------------------
231 : :
232 : 0 : Sequence< OUString > SAL_CALL PDFFilter_getSupportedServiceNames( ) throw (RuntimeException)
233 : : {
234 : 0 : Sequence < OUString > aRet(1);
235 : 0 : OUString* pArray = aRet.getArray();
236 : 0 : pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
237 : 0 : return aRet;
238 : : }
239 : :
240 : : #undef SERVICE_NAME
241 : :
242 : : // -----------------------------------------------------------------------------
243 : :
244 : 0 : Reference< XInterface > SAL_CALL PDFFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
245 : : {
246 : 0 : return (cppu::OWeakObject*) new PDFFilter( rSMgr );
247 : : }
248 : :
249 : : // -----------------------------------------------------------------------------
250 : :
251 : 0 : OUString SAL_CALL PDFFilter::getImplementationName()
252 : : throw (RuntimeException)
253 : : {
254 : 0 : return PDFFilter_getImplementationName();
255 : : }
256 : :
257 : : // -----------------------------------------------------------------------------
258 : :
259 : 0 : sal_Bool SAL_CALL PDFFilter::supportsService( const OUString& rServiceName )
260 : : throw (RuntimeException)
261 : : {
262 : 0 : return PDFFilter_supportsService( rServiceName );
263 : : }
264 : :
265 : : // -----------------------------------------------------------------------------
266 : :
267 : 0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL PDFFilter::getSupportedServiceNames( ) throw (RuntimeException)
268 : : {
269 : 0 : return PDFFilter_getSupportedServiceNames();
270 : : }
271 : :
272 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|