Line data Source code
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 :
21 : #include "pdffilter.hxx"
22 : #include "pdfexport.hxx"
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/window.hxx>
25 : #include <svl/outstrm.hxx>
26 : #include <svtools/FilterConfigItem.hxx>
27 :
28 : // -------------
29 : // - PDFFilter -
30 : // -------------
31 :
32 0 : PDFFilter::PDFFilter( const Reference< XMultiServiceFactory > &rxMSF ) :
33 0 : mxMSF( rxMSF )
34 : {
35 0 : }
36 :
37 : // -----------------------------------------------------------------------------
38 :
39 0 : PDFFilter::~PDFFilter()
40 : {
41 0 : }
42 :
43 : // -----------------------------------------------------------------------------
44 :
45 0 : sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
46 : {
47 0 : Reference< XOutputStream > xOStm;
48 0 : Sequence< PropertyValue > aFilterData;
49 0 : sal_Int32 nLength = rDescriptor.getLength();
50 0 : const PropertyValue* pValue = rDescriptor.getConstArray();
51 0 : sal_Bool bRet = sal_False;
52 0 : Reference< task::XStatusIndicator > xStatusIndicator;
53 0 : Reference< task::XInteractionHandler > xIH;
54 :
55 0 : for ( sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
56 : {
57 0 : if ( pValue[ i ].Name == "OutputStream" )
58 0 : pValue[ i ].Value >>= xOStm;
59 0 : else if ( pValue[ i ].Name == "FilterData" )
60 0 : pValue[ i ].Value >>= aFilterData;
61 0 : else if ( pValue[ i ].Name == "StatusIndicator" )
62 0 : pValue[ i ].Value >>= xStatusIndicator;
63 0 : else if ( pValue[i].Name == "InteractionHandler" )
64 0 : pValue[i].Value >>= xIH;
65 : }
66 :
67 : /* we don't get FilterData if we are exporting directly
68 : to pdf, but we have to use the last user settings (especially for the CompressMode) */
69 0 : if ( !aFilterData.getLength() )
70 : {
71 0 : FilterConfigItem aCfgItem( String( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/PDF/Export/" ) ) );
72 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseLosslessCompression" ) ), sal_False );
73 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 90 );
74 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ReduceImageResolution" ) ), sal_False );
75 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "MaxImageResolution" ) ), 300 );
76 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseTaggedPDF" ) ), sal_False );
77 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "SelectPdfVersion" ) ), 0 );
78 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportNotes" ) ), sal_False );
79 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportNotesPages" ) ), sal_False );
80 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseTransitionEffects" ) ), sal_True );
81 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsSkipEmptyPages" ) ), sal_False );
82 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportFormFields" ) ), sal_True );
83 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FormsType" ) ), 0 );
84 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerToolbar" ) ), sal_False );
85 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerMenubar" ) ), sal_False );
86 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerWindowControls" ) ), sal_False );
87 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ResizeWindowToInitialPage" ) ), sal_False );
88 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "CenterWindow" ) ), sal_False );
89 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "OpenInFullScreenMode" ) ), sal_False );
90 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "DisplayPDFDocumentTitle" ) ), sal_True );
91 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "InitialView" ) ), 0 );
92 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Magnification" ) ), 0 );
93 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PageLayout" ) ), 0 );
94 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "FirstPageOnLeft" ) ), sal_False );
95 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsAddStream" ) ), sal_False );
96 : //
97 : // the encryption is not available when exporting directly, since the encryption is off by default and the selection
98 : // (encrypt or not) is not persistent; it's available through macro though,
99 : // provided the correct property values are set, see help
100 : //
101 : // now, the relative link stuff
102 0 : aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportLinksRelativeFsys" ) ), sal_False );
103 0 : aCfgItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PDFViewSelection" ) ), 0 );
104 0 : aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ConvertOOoTargetToPDFTarget" ) ), sal_False );
105 0 : aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarksToPDFDestination" ) ), sal_False );
106 :
107 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarks" ) ), sal_True );
108 0 : aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportHiddenSlides" ) ), sal_False );
109 0 : aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "OpenBookmarkLevels" ) ), -1 );
110 0 : aFilterData = aCfgItem.GetFilterData();
111 : }
112 0 : if( mxSrcDoc.is() && xOStm.is() )
113 : {
114 0 : PDFExport aExport( mxSrcDoc, xStatusIndicator, xIH, mxMSF );
115 0 : ::utl::TempFile aTempFile;
116 :
117 0 : aTempFile.EnableKillingFile();
118 0 : bRet = aExport.Export( aTempFile.GetURL(), aFilterData );
119 :
120 0 : if( bRet )
121 : {
122 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
123 :
124 0 : if( pIStm )
125 : {
126 0 : SvOutputStream aOStm( xOStm );
127 :
128 0 : aOStm << *pIStm;
129 0 : bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) );
130 :
131 0 : delete pIStm;
132 : }
133 0 : }
134 : }
135 :
136 0 : return bRet;
137 : }
138 :
139 : // -----------------------------------------------------------------------------
140 : class FocusWindowWaitCursor
141 : {
142 : Window* m_pFocusWindow;
143 : public:
144 0 : FocusWindowWaitCursor() :
145 0 : m_pFocusWindow( Application::GetFocusWindow() )
146 : {
147 0 : if( m_pFocusWindow )
148 : {
149 0 : m_pFocusWindow->AddEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
150 0 : m_pFocusWindow->EnterWait();
151 : }
152 0 : }
153 0 : ~FocusWindowWaitCursor()
154 : {
155 0 : if( m_pFocusWindow )
156 : {
157 0 : m_pFocusWindow->LeaveWait();
158 0 : m_pFocusWindow->RemoveEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
159 : }
160 0 : }
161 :
162 : DECL_LINK( DestroyedLink, VclWindowEvent* );
163 : };
164 :
165 0 : IMPL_LINK( FocusWindowWaitCursor, DestroyedLink, VclWindowEvent*, pEvent )
166 : {
167 0 : if( pEvent->GetId() == VCLEVENT_OBJECT_DYING )
168 0 : m_pFocusWindow = NULL;
169 0 : return 0;
170 : }
171 :
172 0 : sal_Bool SAL_CALL PDFFilter::filter( const Sequence< PropertyValue >& rDescriptor )
173 : throw (RuntimeException)
174 : {
175 0 : FocusWindowWaitCursor aCur;
176 :
177 0 : const sal_Bool bRet = implExport( rDescriptor );
178 :
179 0 : return bRet;
180 : }
181 :
182 : // -----------------------------------------------------------------------------
183 :
184 0 : void SAL_CALL PDFFilter::cancel( ) throw (RuntimeException)
185 : {
186 0 : }
187 :
188 : // -----------------------------------------------------------------------------
189 :
190 0 : void SAL_CALL PDFFilter::setSourceDocument( const Reference< XComponent >& xDoc )
191 : throw (IllegalArgumentException, RuntimeException)
192 : {
193 0 : mxSrcDoc = xDoc;
194 0 : }
195 :
196 : // -----------------------------------------------------------------------------
197 :
198 0 : void SAL_CALL PDFFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& )
199 : throw (Exception, RuntimeException)
200 : {
201 0 : }
202 :
203 : // -----------------------------------------------------------------------------
204 :
205 0 : OUString PDFFilter_getImplementationName ()
206 : throw (RuntimeException)
207 : {
208 0 : return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PDF.PDFFilter" ) );
209 : }
210 :
211 : // -----------------------------------------------------------------------------
212 :
213 : #define SERVICE_NAME "com.sun.star.document.PDFFilter"
214 :
215 0 : sal_Bool SAL_CALL PDFFilter_supportsService( const OUString& ServiceName )
216 : throw (RuntimeException)
217 : {
218 0 : return ServiceName == SERVICE_NAME;
219 : }
220 :
221 : // -----------------------------------------------------------------------------
222 :
223 0 : Sequence< OUString > SAL_CALL PDFFilter_getSupportedServiceNames( ) throw (RuntimeException)
224 : {
225 0 : Sequence < OUString > aRet(1);
226 0 : OUString* pArray = aRet.getArray();
227 0 : pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
228 0 : return aRet;
229 : }
230 :
231 : #undef SERVICE_NAME
232 :
233 : // -----------------------------------------------------------------------------
234 :
235 0 : Reference< XInterface > SAL_CALL PDFFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
236 : {
237 0 : return (cppu::OWeakObject*) new PDFFilter( rSMgr );
238 : }
239 :
240 : // -----------------------------------------------------------------------------
241 :
242 0 : OUString SAL_CALL PDFFilter::getImplementationName()
243 : throw (RuntimeException)
244 : {
245 0 : return PDFFilter_getImplementationName();
246 : }
247 :
248 : // -----------------------------------------------------------------------------
249 :
250 0 : sal_Bool SAL_CALL PDFFilter::supportsService( const OUString& rServiceName )
251 : throw (RuntimeException)
252 : {
253 0 : return PDFFilter_supportsService( rServiceName );
254 : }
255 :
256 : // -----------------------------------------------------------------------------
257 :
258 0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL PDFFilter::getSupportedServiceNames( ) throw (RuntimeException)
259 : {
260 0 : return PDFFilter_getSupportedServiceNames();
261 : }
262 :
263 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|