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 "pdfexport.hxx"
22 : #include "impdialog.hxx"
23 :
24 : #include "pdf.hrc"
25 : #include "tools/urlobj.hxx"
26 : #include "tools/fract.hxx"
27 : #include "tools/poly.hxx"
28 : #include "vcl/mapmod.hxx"
29 : #include "vcl/virdev.hxx"
30 : #include "vcl/metaact.hxx"
31 : #include "vcl/gdimtf.hxx"
32 : #include "vcl/jobset.hxx"
33 : #include "vcl/bmpacc.hxx"
34 : #include "vcl/svapp.hxx"
35 : #include "toolkit/awt/vclxdevice.hxx"
36 : #include "unotools/localfilehelper.hxx"
37 : #include <vcl/FilterConfigItem.hxx>
38 : #include <vcl/graphicfilter.hxx>
39 : #include <vcl/settings.hxx>
40 : #include "svl/solar.hrc"
41 : #include "comphelper/string.hxx"
42 : #include "comphelper/storagehelper.hxx"
43 : #include "unotools/streamwrap.hxx"
44 : #include "com/sun/star/io/XSeekable.hpp"
45 :
46 : #include "basegfx/polygon/b2dpolygon.hxx"
47 : #include "basegfx/polygon/b2dpolypolygon.hxx"
48 : #include "basegfx/polygon/b2dpolygontools.hxx"
49 :
50 : #include "unotools/saveopt.hxx"
51 :
52 : #include "vcl/graphictools.hxx"
53 : #include "com/sun/star/beans/XPropertySet.hpp"
54 : #include "com/sun/star/configuration/theDefaultProvider.hpp"
55 : #include "com/sun/star/awt/Rectangle.hpp"
56 : #include "com/sun/star/awt/XDevice.hpp"
57 : #include "com/sun/star/util/MeasureUnit.hpp"
58 : #include "com/sun/star/frame/XModel.hpp"
59 : #include "com/sun/star/frame/ModuleManager.hpp"
60 : #include "com/sun/star/frame/XStorable.hpp"
61 : #include "com/sun/star/frame/XController.hpp"
62 : #include "com/sun/star/document/XDocumentProperties.hpp"
63 : #include "com/sun/star/document/XDocumentPropertiesSupplier.hpp"
64 : #include "com/sun/star/container/XNameAccess.hpp"
65 : #include "com/sun/star/view/XViewSettingsSupplier.hpp"
66 : #include "com/sun/star/task/XInteractionRequest.hpp"
67 : #include "com/sun/star/task/PDFExportException.hpp"
68 :
69 : #include "unotools/configmgr.hxx"
70 : #include "cppuhelper/exc_hlp.hxx"
71 : #include "cppuhelper/compbase1.hxx"
72 : #include "cppuhelper/basemutex.hxx"
73 :
74 : #include "com/sun/star/lang/XServiceInfo.hpp"
75 : #include "com/sun/star/drawing/XShapes.hpp"
76 : #include "com/sun/star/graphic/XGraphicProvider.hpp"
77 : #include <boost/scoped_ptr.hpp>
78 :
79 : using namespace ::com::sun::star;
80 : using namespace ::com::sun::star::uno;
81 : using namespace ::com::sun::star::lang;
82 : using namespace ::com::sun::star::beans;
83 : using namespace ::com::sun::star::view;
84 : using namespace ::com::sun::star::graphic;
85 :
86 :
87 : // - PDFExport -
88 :
89 :
90 0 : PDFExport::PDFExport( const Reference< XComponent >& rxSrcDoc,
91 : const Reference< task::XStatusIndicator >& rxStatusIndicator,
92 : const Reference< task::XInteractionHandler >& rxIH,
93 : const Reference< XComponentContext >& xContext ) :
94 : mxSrcDoc ( rxSrcDoc ),
95 : mxContext ( xContext ),
96 : mxStatusIndicator ( rxStatusIndicator ),
97 : mxIH ( rxIH ),
98 : mbUseTaggedPDF ( false ),
99 : mnPDFTypeSelection ( 0 ),
100 : mbExportNotes ( true ),
101 : mbViewPDF ( true ),
102 : mbExportNotesPages ( false ),
103 : mbUseTransitionEffects ( true ),
104 : mbExportBookmarks ( true ),
105 : mbExportHiddenSlides ( false ),
106 : mnOpenBookmarkLevels ( -1 ),
107 : mbUseLosslessCompression ( false ),
108 : mbReduceImageResolution ( true ),
109 : mbSkipEmptyPages ( true ),
110 : mbAddStream ( false ),
111 : mnMaxImageResolution ( 300 ),
112 : mnQuality ( 90 ),
113 : mnFormsFormat ( 0 ),
114 : mbExportFormFields ( true ),
115 : mbAllowDuplicateFieldNames ( false ),
116 : mnProgressValue ( 0 ),
117 : mbRemoveTransparencies ( false ),
118 : mbWatermark ( false ),
119 :
120 : mbHideViewerToolbar ( false ),
121 : mbHideViewerMenubar ( false ),
122 : mbHideViewerWindowControls ( false ),
123 : mbFitWindow ( false ),
124 : mbCenterWindow ( false ),
125 : mbOpenInFullScreenMode ( false ),
126 : mbDisplayPDFDocumentTitle ( true ),
127 : mnPDFDocumentMode ( 0 ),
128 : mnPDFDocumentAction ( 0 ),
129 : mnZoom ( 100 ),
130 : mnInitialPage ( 1 ),
131 : mnPDFPageLayout ( 0 ),
132 : mbFirstPageLeft ( false ),
133 :
134 : mbEncrypt ( false ),
135 : mbRestrictPermissions ( false ),
136 : mnPrintAllowed ( 2 ),
137 : mnChangesAllowed ( 4 ),
138 : mbCanCopyOrExtract ( true ),
139 : mbCanExtractForAccessibility( true ),
140 :
141 : //--->i56629
142 : mbExportRelativeFsysLinks ( false ),
143 : mnDefaultLinkAction ( 0 ),
144 : mbConvertOOoTargetToPDFTarget( false ),
145 : mbExportBmkToDest ( false ),
146 0 : mbSignPDF ( false )
147 : {
148 0 : }
149 :
150 :
151 :
152 0 : PDFExport::~PDFExport()
153 : {
154 0 : }
155 :
156 :
157 :
158 0 : bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
159 : Reference< com::sun::star::view::XRenderable >& rRenderable,
160 : const Any& rSelection,
161 : const StringRangeEnumerator& rRangeEnum,
162 : Sequence< PropertyValue >& rRenderOptions,
163 : sal_Int32 nPageCount )
164 : {
165 0 : bool bRet = false;
166 : try
167 : {
168 0 : Any* pFirstPage = NULL;
169 0 : Any* pLastPage = NULL;
170 :
171 0 : bool bExportNotesPages = false;
172 :
173 0 : for( sal_Int32 nData = 0, nDataCount = rRenderOptions.getLength(); nData < nDataCount; ++nData )
174 : {
175 0 : if ( rRenderOptions[ nData ].Name == "IsFirstPage" )
176 0 : pFirstPage = &rRenderOptions[ nData ].Value;
177 0 : else if ( rRenderOptions[ nData ].Name == "IsLastPage" )
178 0 : pLastPage = &rRenderOptions[ nData ].Value;
179 0 : else if ( rRenderOptions[ nData ].Name == "ExportNotesPages" )
180 0 : rRenderOptions[ nData ].Value >>= bExportNotesPages;
181 : }
182 :
183 0 : OutputDevice* pOut = rPDFWriter.GetReferenceDevice();
184 :
185 0 : if( pOut )
186 : {
187 0 : vcl::PDFExtOutDevData* pPDFExtOutDevData = PTR_CAST( vcl::PDFExtOutDevData, pOut->GetExtOutDevData() );
188 0 : if ( nPageCount )
189 : {
190 0 : pPDFExtOutDevData->SetIsExportNotesPages( bExportNotesPages );
191 :
192 0 : sal_Int32 nCurrentPage(0);
193 0 : StringRangeEnumerator::Iterator aIter = rRangeEnum.begin();
194 0 : StringRangeEnumerator::Iterator aEnd = rRangeEnum.end();
195 0 : while ( aIter != aEnd )
196 : {
197 0 : Sequence< PropertyValue > aRenderer( rRenderable->getRenderer( *aIter, rSelection, rRenderOptions ) );
198 0 : awt::Size aPageSize;
199 :
200 0 : for( sal_Int32 nProperty = 0, nPropertyCount = aRenderer.getLength(); nProperty < nPropertyCount; ++nProperty )
201 : {
202 0 : if ( aRenderer[ nProperty ].Name == "PageSize" )
203 0 : aRenderer[ nProperty].Value >>= aPageSize;
204 : }
205 :
206 0 : pPDFExtOutDevData->SetCurrentPageNumber( nCurrentPage );
207 :
208 0 : GDIMetaFile aMtf;
209 0 : const MapMode aMapMode( MAP_100TH_MM );
210 0 : const Size aMtfSize( aPageSize.Width, aPageSize.Height );
211 :
212 0 : pOut->Push();
213 0 : pOut->EnableOutput( false );
214 0 : pOut->SetMapMode( aMapMode );
215 :
216 0 : aMtf.SetPrefSize( aMtfSize );
217 0 : aMtf.SetPrefMapMode( aMapMode );
218 0 : aMtf.Record( pOut );
219 :
220 : // #i35176#
221 : // IsLastPage property.
222 0 : const sal_Int32 nCurrentRenderer = *aIter;
223 0 : ++aIter;
224 0 : if ( pLastPage && aIter == aEnd )
225 0 : *pLastPage <<= sal_True;
226 :
227 0 : rRenderable->render( nCurrentRenderer, rSelection, rRenderOptions );
228 :
229 0 : aMtf.Stop();
230 0 : aMtf.WindStart();
231 :
232 0 : if( aMtf.GetActionSize() &&
233 0 : ( !mbSkipEmptyPages || aPageSize.Width || aPageSize.Height ) )
234 0 : bRet = ImplExportPage( rPDFWriter, *pPDFExtOutDevData, aMtf ) || bRet;
235 :
236 0 : pOut->Pop();
237 :
238 0 : if ( mxStatusIndicator.is() )
239 0 : mxStatusIndicator->setValue( mnProgressValue );
240 0 : if ( pFirstPage )
241 0 : *pFirstPage <<= sal_False;
242 :
243 0 : ++mnProgressValue;
244 0 : ++nCurrentPage;
245 0 : }
246 : }
247 : else
248 : {
249 0 : bRet = true; // #i18334# SJ: nPageCount == 0,
250 0 : rPDFWriter.NewPage( 10000, 10000 ); // creating dummy page
251 0 : rPDFWriter.SetMapMode( MAP_100TH_MM );
252 : }
253 : }
254 : }
255 0 : catch(const RuntimeException &)
256 : {
257 : }
258 0 : return bRet;
259 : }
260 :
261 : class PDFExportStreamDoc : public vcl::PDFOutputStream
262 : {
263 : Reference< XComponent > m_xSrcDoc;
264 : Sequence< beans::NamedValue > m_aPreparedPassword;
265 : public:
266 0 : PDFExportStreamDoc( const Reference< XComponent >& xDoc, const Sequence<beans::NamedValue>& rPwd )
267 : : m_xSrcDoc( xDoc ),
268 0 : m_aPreparedPassword( rPwd )
269 0 : {}
270 : virtual ~PDFExportStreamDoc();
271 :
272 : virtual void write( const Reference< XOutputStream >& xStream ) SAL_OVERRIDE;
273 : };
274 :
275 0 : PDFExportStreamDoc::~PDFExportStreamDoc()
276 : {
277 0 : }
278 :
279 0 : void PDFExportStreamDoc::write( const Reference< XOutputStream >& xStream )
280 : {
281 0 : Reference< com::sun::star::frame::XStorable > xStore( m_xSrcDoc, UNO_QUERY );
282 0 : if( xStore.is() )
283 : {
284 0 : Sequence< beans::PropertyValue > aArgs( 2 + ((m_aPreparedPassword.getLength() > 0) ? 1 : 0) );
285 0 : aArgs.getArray()[0].Name = "FilterName";
286 0 : aArgs.getArray()[1].Name = "OutputStream";
287 0 : aArgs.getArray()[1].Value <<= xStream;
288 0 : if( m_aPreparedPassword.getLength() )
289 : {
290 0 : aArgs.getArray()[2].Name = "EncryptionData";
291 0 : aArgs.getArray()[2].Value <<= m_aPreparedPassword;
292 : }
293 :
294 : try
295 : {
296 0 : xStore->storeToURL( "private:stream", aArgs );
297 : }
298 0 : catch( const IOException& )
299 : {
300 0 : }
301 0 : }
302 0 : }
303 :
304 0 : static OUString getMimetypeForDocument( const Reference< XComponentContext >& xContext,
305 : const Reference< XComponent >& xDoc ) throw()
306 : {
307 0 : OUString aDocMimetype;
308 : try
309 : {
310 : // get document service name
311 0 : Reference< com::sun::star::frame::XStorable > xStore( xDoc, UNO_QUERY );
312 0 : Reference< frame::XModuleManager2 > xModuleManager = frame::ModuleManager::create(xContext);
313 0 : if( xStore.is() )
314 : {
315 0 : OUString aDocServiceName = xModuleManager->identify( Reference< XInterface >( xStore, uno::UNO_QUERY ) );
316 0 : if ( !aDocServiceName.isEmpty() )
317 : {
318 : // get the actual filter name
319 0 : OUString aFilterName;
320 : Reference< lang::XMultiServiceFactory > xConfigProvider =
321 0 : configuration::theDefaultProvider::get( xContext );
322 0 : uno::Sequence< uno::Any > aArgs( 1 );
323 0 : beans::NamedValue aPathProp;
324 0 : aPathProp.Name = "nodepath";
325 0 : aPathProp.Value <<= OUString( "/org.openoffice.Setup/Office/Factories/" );
326 0 : aArgs[0] <<= aPathProp;
327 :
328 : Reference< container::XNameAccess > xSOFConfig(
329 0 : xConfigProvider->createInstanceWithArguments(
330 0 : "com.sun.star.configuration.ConfigurationAccess", aArgs ),
331 0 : uno::UNO_QUERY );
332 :
333 0 : Reference< container::XNameAccess > xApplConfig;
334 0 : xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig;
335 0 : if ( xApplConfig.is() )
336 : {
337 0 : xApplConfig->getByName( "ooSetupFactoryActualFilter" ) >>= aFilterName;
338 0 : if( !aFilterName.isEmpty() )
339 : {
340 : // find the related type name
341 0 : OUString aTypeName;
342 : Reference< container::XNameAccess > xFilterFactory(
343 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext),
344 0 : uno::UNO_QUERY );
345 :
346 0 : Sequence< beans::PropertyValue > aFilterData;
347 0 : xFilterFactory->getByName( aFilterName ) >>= aFilterData;
348 0 : for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
349 0 : if ( aFilterData[nInd].Name == "Type" )
350 0 : aFilterData[nInd].Value >>= aTypeName;
351 :
352 0 : if ( !aTypeName.isEmpty() )
353 : {
354 : // find the mediatype
355 : Reference< container::XNameAccess > xTypeDetection(
356 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
357 0 : UNO_QUERY );
358 :
359 0 : Sequence< beans::PropertyValue > aTypeData;
360 0 : xTypeDetection->getByName( aTypeName ) >>= aTypeData;
361 0 : for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ )
362 0 : if ( aTypeData[nInd].Name == "MediaType" )
363 0 : aTypeData[nInd].Value >>= aDocMimetype;
364 0 : }
365 : }
366 0 : }
367 0 : }
368 0 : }
369 : }
370 0 : catch (...)
371 : {
372 : }
373 0 : return aDocMimetype;
374 : }
375 :
376 0 : bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& rFilterData )
377 : {
378 0 : INetURLObject aURL( rFile );
379 0 : bool bRet = false;
380 :
381 0 : std::set< vcl::PDFWriter::ErrorCode > aErrors;
382 :
383 0 : if( aURL.GetProtocol() != INetProtocol::File )
384 : {
385 0 : OUString aTmp;
386 :
387 0 : if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFile, aTmp ) )
388 0 : aURL = INetURLObject(aTmp);
389 : }
390 :
391 0 : if( aURL.GetProtocol() == INetProtocol::File )
392 : {
393 0 : Reference< XRenderable > xRenderable( mxSrcDoc, UNO_QUERY );
394 :
395 0 : if( xRenderable.is() )
396 : {
397 0 : VCLXDevice* pXDevice = new VCLXDevice;
398 0 : OUString aPageRange;
399 0 : Any aSelection;
400 0 : vcl::PDFWriter::PDFWriterContext aContext;
401 0 : OUString aOpenPassword, aPermissionPassword;
402 0 : Reference< beans::XMaterialHolder > xEnc;
403 0 : Sequence< beans::NamedValue > aPreparedPermissionPassword;
404 :
405 :
406 : // getting the string for the creator
407 0 : OUString aCreator;
408 0 : Reference< XServiceInfo > xInfo( mxSrcDoc, UNO_QUERY );
409 0 : if ( xInfo.is() )
410 : {
411 0 : if ( xInfo->supportsService( "com.sun.star.presentation.PresentationDocument" ) )
412 0 : aCreator += "Impress";
413 0 : else if ( xInfo->supportsService( "com.sun.star.drawing.DrawingDocument" ) )
414 0 : aCreator += "Draw";
415 0 : else if ( xInfo->supportsService( "com.sun.star.text.TextDocument" ) )
416 0 : aCreator += "Writer";
417 0 : else if ( xInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
418 0 : aCreator += "Calc";
419 0 : else if ( xInfo->supportsService( "com.sun.star.formula.FormulaProperties" ) )
420 0 : aCreator += "Math";
421 : }
422 :
423 0 : Reference< document::XDocumentPropertiesSupplier > xDocumentPropsSupplier( mxSrcDoc, UNO_QUERY );
424 0 : if ( xDocumentPropsSupplier.is() )
425 : {
426 0 : Reference< document::XDocumentProperties > xDocumentProps( xDocumentPropsSupplier->getDocumentProperties() );
427 0 : if ( xDocumentProps.is() )
428 : {
429 0 : aContext.DocumentInfo.Title = xDocumentProps->getTitle();
430 0 : aContext.DocumentInfo.Author = xDocumentProps->getAuthor();
431 0 : aContext.DocumentInfo.Subject = xDocumentProps->getSubject();
432 0 : aContext.DocumentInfo.Keywords = ::comphelper::string::convertCommaSeparated(xDocumentProps->getKeywords());
433 0 : }
434 : }
435 : // getting the string for the producer
436 0 : aContext.DocumentInfo.Producer =
437 0 : utl::ConfigManager::getProductName() +
438 0 : " " +
439 0 : utl::ConfigManager::getProductVersion();
440 0 : aContext.DocumentInfo.Creator = aCreator;
441 :
442 0 : for( sal_Int32 nData = 0, nDataCount = rFilterData.getLength(); nData < nDataCount; ++nData )
443 : {
444 0 : if ( rFilterData[ nData ].Name == "PageRange" )
445 0 : rFilterData[ nData ].Value >>= aPageRange;
446 0 : else if ( rFilterData[ nData ].Name == "Selection" )
447 0 : rFilterData[ nData ].Value >>= aSelection;
448 0 : else if ( rFilterData[ nData ].Name == "UseLosslessCompression" )
449 0 : rFilterData[ nData ].Value >>= mbUseLosslessCompression;
450 0 : else if ( rFilterData[ nData ].Name == "Quality" )
451 0 : rFilterData[ nData ].Value >>= mnQuality;
452 0 : else if ( rFilterData[ nData ].Name == "ReduceImageResolution" )
453 0 : rFilterData[ nData ].Value >>= mbReduceImageResolution;
454 0 : else if ( rFilterData[ nData ].Name == "IsSkipEmptyPages" )
455 0 : rFilterData[ nData ].Value >>= mbSkipEmptyPages;
456 0 : else if ( rFilterData[ nData ].Name == "MaxImageResolution" )
457 0 : rFilterData[ nData ].Value >>= mnMaxImageResolution;
458 0 : else if ( rFilterData[ nData ].Name == "UseTaggedPDF" )
459 0 : rFilterData[ nData ].Value >>= mbUseTaggedPDF;
460 0 : else if ( rFilterData[ nData ].Name == "SelectPdfVersion" )
461 0 : rFilterData[ nData ].Value >>= mnPDFTypeSelection;
462 0 : else if ( rFilterData[ nData ].Name == "ExportNotes" )
463 0 : rFilterData[ nData ].Value >>= mbExportNotes;
464 0 : else if ( rFilterData[ nData ].Name == "ViewPDFAfterExport" )
465 0 : rFilterData[ nData ].Value >>= mbViewPDF;
466 0 : else if ( rFilterData[ nData ].Name == "ExportNotesPages" )
467 0 : rFilterData[ nData ].Value >>= mbExportNotesPages;
468 0 : else if ( rFilterData[ nData ].Name == "UseTransitionEffects" )
469 0 : rFilterData[ nData ].Value >>= mbUseTransitionEffects;
470 0 : else if ( rFilterData[ nData ].Name == "ExportFormFields" )
471 0 : rFilterData[ nData ].Value >>= mbExportFormFields;
472 0 : else if ( rFilterData[ nData ].Name == "FormsType" )
473 0 : rFilterData[ nData ].Value >>= mnFormsFormat;
474 0 : else if ( rFilterData[ nData ].Name == "AllowDuplicateFieldNames" )
475 0 : rFilterData[ nData ].Value >>= mbAllowDuplicateFieldNames;
476 : //viewer properties
477 0 : else if ( rFilterData[ nData ].Name == "HideViewerToolbar" )
478 0 : rFilterData[ nData ].Value >>= mbHideViewerToolbar;
479 0 : else if ( rFilterData[ nData ].Name == "HideViewerMenubar" )
480 0 : rFilterData[ nData ].Value >>= mbHideViewerMenubar;
481 0 : else if ( rFilterData[ nData ].Name == "HideViewerWindowControls" )
482 0 : rFilterData[ nData ].Value >>= mbHideViewerWindowControls;
483 0 : else if ( rFilterData[ nData ].Name == "ResizeWindowToInitialPage" )
484 0 : rFilterData[ nData ].Value >>= mbFitWindow;
485 0 : else if ( rFilterData[ nData ].Name == "CenterWindow" )
486 0 : rFilterData[ nData ].Value >>= mbCenterWindow;
487 0 : else if ( rFilterData[ nData ].Name == "OpenInFullScreenMode" )
488 0 : rFilterData[ nData ].Value >>= mbOpenInFullScreenMode;
489 0 : else if ( rFilterData[ nData ].Name == "DisplayPDFDocumentTitle" )
490 0 : rFilterData[ nData ].Value >>= mbDisplayPDFDocumentTitle;
491 0 : else if ( rFilterData[ nData ].Name == "InitialView" )
492 0 : rFilterData[ nData ].Value >>= mnPDFDocumentMode;
493 0 : else if ( rFilterData[ nData ].Name == "Magnification" )
494 0 : rFilterData[ nData ].Value >>= mnPDFDocumentAction;
495 0 : else if ( rFilterData[ nData ].Name == "Zoom" )
496 0 : rFilterData[ nData ].Value >>= mnZoom;
497 0 : else if ( rFilterData[ nData ].Name == "InitialPage" )
498 0 : rFilterData[ nData ].Value >>= mnInitialPage;
499 0 : else if ( rFilterData[ nData ].Name == "PageLayout" )
500 0 : rFilterData[ nData ].Value >>= mnPDFPageLayout;
501 0 : else if ( rFilterData[ nData ].Name == "FirstPageOnLeft" )
502 0 : rFilterData[ nData ].Value >>= aContext.FirstPageLeft;
503 0 : else if ( rFilterData[ nData ].Name == "IsAddStream" )
504 0 : rFilterData[ nData ].Value >>= mbAddStream;
505 0 : else if ( rFilterData[ nData ].Name == "Watermark" )
506 : {
507 0 : maWatermark = rFilterData[ nData ].Value;
508 0 : mbWatermark = true;
509 : }
510 : //now all the security related properties...
511 0 : else if ( rFilterData[ nData ].Name == "EncryptFile" )
512 0 : rFilterData[ nData ].Value >>= mbEncrypt;
513 0 : else if ( rFilterData[ nData ].Name == "DocumentOpenPassword" )
514 0 : rFilterData[ nData ].Value >>= aOpenPassword;
515 0 : else if ( rFilterData[ nData ].Name == "RestrictPermissions" )
516 0 : rFilterData[ nData ].Value >>= mbRestrictPermissions;
517 0 : else if ( rFilterData[ nData ].Name == "PermissionPassword" )
518 0 : rFilterData[ nData ].Value >>= aPermissionPassword;
519 0 : else if ( rFilterData[ nData ].Name == "PreparedPasswords" )
520 0 : rFilterData[ nData ].Value >>= xEnc;
521 0 : else if ( rFilterData[ nData ].Name == "PreparedPermissionPassword" )
522 0 : rFilterData[ nData ].Value >>= aPreparedPermissionPassword;
523 0 : else if ( rFilterData[ nData ].Name == "Printing" )
524 0 : rFilterData[ nData ].Value >>= mnPrintAllowed;
525 0 : else if ( rFilterData[ nData ].Name == "Changes" )
526 0 : rFilterData[ nData ].Value >>= mnChangesAllowed;
527 0 : else if ( rFilterData[ nData ].Name == "EnableCopyingOfContent" )
528 0 : rFilterData[ nData ].Value >>= mbCanCopyOrExtract;
529 0 : else if ( rFilterData[ nData ].Name == "EnableTextAccessForAccessibilityTools" )
530 0 : rFilterData[ nData ].Value >>= mbCanExtractForAccessibility;
531 : //--->i56629 links extra (relative links and other related stuff)
532 0 : else if ( rFilterData[ nData ].Name == "ExportLinksRelativeFsys" )
533 0 : rFilterData[ nData ].Value >>= mbExportRelativeFsysLinks;
534 0 : else if ( rFilterData[ nData ].Name == "PDFViewSelection" )
535 0 : rFilterData[ nData ].Value >>= mnDefaultLinkAction;
536 0 : else if ( rFilterData[ nData ].Name == "ConvertOOoTargetToPDFTarget" )
537 0 : rFilterData[ nData ].Value >>= mbConvertOOoTargetToPDFTarget;
538 0 : else if ( rFilterData[ nData ].Name == "ExportBookmarksToPDFDestination" )
539 0 : rFilterData[ nData ].Value >>= mbExportBmkToDest;
540 0 : else if ( rFilterData[ nData ].Name == "ExportBookmarks" )
541 0 : rFilterData[ nData ].Value >>= mbExportBookmarks;
542 0 : else if ( rFilterData[ nData ].Name == "ExportHiddenSlides" )
543 0 : rFilterData[ nData ].Value >>= mbExportHiddenSlides;
544 0 : else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" )
545 0 : rFilterData[ nData ].Value >>= mnOpenBookmarkLevels;
546 0 : else if ( rFilterData[ nData ].Name == "SignPDF" )
547 0 : rFilterData[ nData ].Value >>= mbSignPDF;
548 0 : else if ( rFilterData[ nData ].Name == "SignatureLocation" )
549 0 : rFilterData[ nData ].Value >>= msSignLocation;
550 0 : else if ( rFilterData[ nData ].Name == "SignatureReason" )
551 0 : rFilterData[ nData ].Value >>= msSignReason;
552 0 : else if ( rFilterData[ nData ].Name == "SignatureContactInfo" )
553 0 : rFilterData[ nData ].Value >>= msSignContact;
554 0 : else if ( rFilterData[ nData ].Name == "SignaturePassword" )
555 0 : rFilterData[ nData ].Value >>= msSignPassword;
556 0 : else if ( rFilterData[ nData ].Name == "SignatureCertificate" )
557 0 : rFilterData[ nData ].Value >>= maSignCertificate;
558 0 : else if ( rFilterData[ nData ].Name == "SignatureTSA" )
559 0 : rFilterData[ nData ].Value >>= msSignTSA;
560 : }
561 0 : aContext.URL = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
562 :
563 : //set the correct version, depending on user request
564 0 : switch( mnPDFTypeSelection )
565 : {
566 : default:
567 : case 0:
568 0 : aContext.Version = vcl::PDFWriter::PDF_1_4;
569 0 : break;
570 : case 1:
571 0 : aContext.Version = vcl::PDFWriter::PDF_A_1;
572 : //force the tagged PDF as well
573 0 : mbUseTaggedPDF = true;
574 : //force disabling of form conversion
575 0 : mbExportFormFields = false;
576 : // PDF/A does not allow transparencies
577 0 : mbRemoveTransparencies = true;
578 : // no encryption
579 0 : mbEncrypt = false;
580 0 : xEnc.clear();
581 0 : break;
582 : }
583 :
584 : //copy in context the values default in the constructor or set by the FilterData sequence of properties
585 0 : aContext.Tagged = mbUseTaggedPDF;
586 :
587 : //values used in viewer
588 0 : aContext.HideViewerToolbar = mbHideViewerToolbar;
589 0 : aContext.HideViewerMenubar = mbHideViewerMenubar;
590 0 : aContext.HideViewerWindowControls = mbHideViewerWindowControls;
591 0 : aContext.FitWindow = mbFitWindow;
592 0 : aContext.CenterWindow = mbCenterWindow;
593 0 : aContext.OpenInFullScreenMode = mbOpenInFullScreenMode;
594 0 : aContext.DisplayPDFDocumentTitle = mbDisplayPDFDocumentTitle;
595 0 : aContext.InitialPage = mnInitialPage-1;
596 0 : aContext.OpenBookmarkLevels = mnOpenBookmarkLevels;
597 :
598 0 : switch( mnPDFDocumentMode )
599 : {
600 : default:
601 : case 0:
602 0 : aContext.PDFDocumentMode = vcl::PDFWriter::ModeDefault;
603 0 : break;
604 : case 1:
605 0 : aContext.PDFDocumentMode = vcl::PDFWriter::UseOutlines;
606 0 : break;
607 : case 2:
608 0 : aContext.PDFDocumentMode = vcl::PDFWriter::UseThumbs;
609 0 : break;
610 : }
611 0 : switch( mnPDFDocumentAction )
612 : {
613 : default:
614 : case 0:
615 0 : aContext.PDFDocumentAction = vcl::PDFWriter::ActionDefault;
616 0 : break;
617 : case 1:
618 0 : aContext.PDFDocumentAction = vcl::PDFWriter::FitInWindow;
619 0 : break;
620 : case 2:
621 0 : aContext.PDFDocumentAction = vcl::PDFWriter::FitWidth;
622 0 : break;
623 : case 3:
624 0 : aContext.PDFDocumentAction = vcl::PDFWriter::FitVisible;
625 0 : break;
626 : case 4:
627 0 : aContext.PDFDocumentAction = vcl::PDFWriter::ActionZoom;
628 0 : aContext.Zoom = mnZoom;
629 0 : break;
630 : }
631 :
632 0 : switch( mnPDFPageLayout )
633 : {
634 : default:
635 : case 0:
636 0 : aContext.PageLayout = vcl::PDFWriter::DefaultLayout;
637 0 : break;
638 : case 1:
639 0 : aContext.PageLayout = vcl::PDFWriter::SinglePage;
640 0 : break;
641 : case 2:
642 0 : aContext.PageLayout = vcl::PDFWriter::Continuous;
643 0 : break;
644 : case 3:
645 0 : aContext.PageLayout = vcl::PDFWriter::ContinuousFacing;
646 0 : break;
647 : }
648 :
649 0 : aContext.FirstPageLeft = mbFirstPageLeft;
650 :
651 : //check if PDF/A, which does not allow encryption
652 0 : if( aContext.Version != vcl::PDFWriter::PDF_A_1 )
653 : {
654 : //set values needed in encryption
655 : //set encryption level, fixed, but here it can set by the UI if needed.
656 : // true is 128 bit, false 40
657 : //note that in 40 bit mode the UI needs reworking, since the current UI is meaningfull only for
658 : //128bit security mode
659 0 : aContext.Encryption.Security128bit = true;
660 :
661 : //set check for permission change password
662 : // if not enabled and no permission password, force permissions to default as if PDF where without encryption
663 0 : if( mbRestrictPermissions && (xEnc.is() || !aPermissionPassword.isEmpty()) )
664 : {
665 0 : mbEncrypt = true;
666 : //permission set as desired, done after
667 : }
668 : else
669 : {
670 : //force permission to default
671 0 : mnPrintAllowed = 2 ;
672 0 : mnChangesAllowed = 4 ;
673 0 : mbCanCopyOrExtract = true;
674 0 : mbCanExtractForAccessibility = true ;
675 : }
676 :
677 0 : switch( mnPrintAllowed )
678 : {
679 : case 0: //initialized when aContext is build, means no printing
680 0 : break;
681 : default:
682 : case 2:
683 0 : aContext.Encryption.CanPrintFull = true;
684 : case 1:
685 0 : aContext.Encryption.CanPrintTheDocument = true;
686 0 : break;
687 : }
688 :
689 0 : switch( mnChangesAllowed )
690 : {
691 : case 0: //already in struct PDFSecPermissions CTOR
692 0 : break;
693 : case 1:
694 0 : aContext.Encryption.CanAssemble = true;
695 0 : break;
696 : case 2:
697 0 : aContext.Encryption.CanFillInteractive = true;
698 0 : break;
699 : case 3:
700 0 : aContext.Encryption.CanAddOrModify = true;
701 0 : break;
702 : default:
703 : case 4:
704 : aContext.Encryption.CanModifyTheContent =
705 : aContext.Encryption.CanCopyOrExtract =
706 : aContext.Encryption.CanAddOrModify =
707 0 : aContext.Encryption.CanFillInteractive = true;
708 0 : break;
709 : }
710 :
711 0 : aContext.Encryption.CanCopyOrExtract = mbCanCopyOrExtract;
712 0 : aContext.Encryption.CanExtractForAccessibility = mbCanExtractForAccessibility;
713 0 : if( mbEncrypt && ! xEnc.is() )
714 0 : xEnc = vcl::PDFWriter::InitEncryption( aPermissionPassword, aOpenPassword, aContext.Encryption.Security128bit );
715 0 : if( mbEncrypt && !aPermissionPassword.isEmpty() && ! aPreparedPermissionPassword.getLength() )
716 0 : aPreparedPermissionPassword = comphelper::OStorageHelper::CreatePackageEncryptionData( aPermissionPassword );
717 : }
718 : // after this point we don't need the legacy clear passwords anymore
719 : // however they are still inside the passed filter data sequence
720 : // which is sadly out out our control
721 0 : aPermissionPassword.clear();
722 0 : aOpenPassword.clear();
723 :
724 : /*
725 : * FIXME: the entries are only implicitly defined by the resource file. Should there
726 : * ever be an additional form submit format this could get invalid.
727 : */
728 0 : switch( mnFormsFormat )
729 : {
730 : case 1:
731 0 : aContext.SubmitFormat = vcl::PDFWriter::PDF;
732 0 : break;
733 : case 2:
734 0 : aContext.SubmitFormat = vcl::PDFWriter::HTML;
735 0 : break;
736 : case 3:
737 0 : aContext.SubmitFormat = vcl::PDFWriter::XML;
738 0 : break;
739 : default:
740 : case 0:
741 0 : aContext.SubmitFormat = vcl::PDFWriter::FDF;
742 0 : break;
743 : }
744 0 : aContext.AllowDuplicateFieldNames = mbAllowDuplicateFieldNames;
745 :
746 : //get model
747 0 : Reference< frame::XModel > xModel( mxSrcDoc, UNO_QUERY );
748 : {
749 : //---> i56629 Relative link stuff
750 : //set the base URL of the file:
751 : //then base URL
752 0 : aContext.BaseURL = xModel->getURL();
753 : //relative link option is private to PDF Export filter and limited to local filesystem only
754 0 : aContext.RelFsys = mbExportRelativeFsysLinks;
755 : //determine the default acton for PDF links
756 0 : switch( mnDefaultLinkAction )
757 : {
758 : default:
759 : //default: URI, without fragment conversion (the bookmark in PDF may not work)
760 : case 0:
761 0 : aContext.DefaultLinkAction = vcl::PDFWriter::URIAction;
762 0 : break;
763 : //view PDF through the reader application
764 : case 1:
765 0 : aContext.ForcePDFAction = true;
766 0 : aContext.DefaultLinkAction = vcl::PDFWriter::LaunchAction;
767 0 : break;
768 : //view PDF through an Internet browser
769 : case 2:
770 0 : aContext.DefaultLinkAction = vcl::PDFWriter::URIActionDestination;
771 0 : break;
772 : }
773 0 : aContext.ConvertOOoTargetToPDFTarget = mbConvertOOoTargetToPDFTarget;
774 : // check for Link Launch action, not allowed on PDF/A-1
775 : // this code chunk checks when the filter is called from scripting
776 0 : if( aContext.Version == vcl::PDFWriter::PDF_A_1 &&
777 0 : aContext.DefaultLinkAction == vcl::PDFWriter::LaunchAction )
778 : { //force the similar allowed URI action
779 0 : aContext.DefaultLinkAction = vcl::PDFWriter::URIActionDestination;
780 : //and remove the remote goto action forced on PDF file
781 0 : aContext.ForcePDFAction = false;
782 : }
783 : }
784 :
785 0 : aContext.SignPDF = mbSignPDF;
786 0 : aContext.SignLocation = msSignLocation;
787 0 : aContext.SignContact = msSignContact;
788 0 : aContext.SignReason = msSignReason;
789 0 : aContext.SignPassword = msSignPassword;
790 0 : aContext.SignCertificate = maSignCertificate;
791 0 : aContext.SignTSA = msSignTSA;
792 :
793 : // all context data set, time to create the printing device
794 0 : boost::scoped_ptr<vcl::PDFWriter> pPDFWriter(new vcl::PDFWriter( aContext, xEnc ));
795 0 : OutputDevice* pOut = pPDFWriter->GetReferenceDevice();
796 :
797 : DBG_ASSERT( pOut, "PDFExport::Export: no reference device" );
798 0 : pXDevice->SetOutputDevice( pOut );
799 :
800 0 : if( mbAddStream )
801 : {
802 : // export stream
803 : // get mimetype
804 0 : OUString aSrcMimetype = getMimetypeForDocument( mxContext, mxSrcDoc );
805 : pPDFWriter->AddStream( aSrcMimetype,
806 0 : new PDFExportStreamDoc( mxSrcDoc, aPreparedPermissionPassword ),
807 : false
808 0 : );
809 : }
810 :
811 0 : if ( pOut )
812 : {
813 : DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" );
814 0 : boost::scoped_ptr<vcl::PDFExtOutDevData> pPDFExtOutDevData(new vcl::PDFExtOutDevData( *pOut ));
815 0 : pOut->SetExtOutDevData( pPDFExtOutDevData.get() );
816 0 : pPDFExtOutDevData->SetIsExportNotes( mbExportNotes );
817 0 : pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF );
818 0 : pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects );
819 0 : pPDFExtOutDevData->SetFormsFormat( mnFormsFormat );
820 0 : pPDFExtOutDevData->SetIsExportFormFields( mbExportFormFields );
821 0 : pPDFExtOutDevData->SetIsExportBookmarks( mbExportBookmarks );
822 0 : pPDFExtOutDevData->SetIsExportHiddenSlides( mbExportHiddenSlides );
823 0 : pPDFExtOutDevData->SetIsLosslessCompression( mbUseLosslessCompression );
824 0 : pPDFExtOutDevData->SetIsReduceImageResolution( mbReduceImageResolution );
825 0 : pPDFExtOutDevData->SetIsExportNamedDestinations( mbExportBmkToDest );
826 :
827 0 : Sequence< PropertyValue > aRenderOptions( 6 );
828 0 : aRenderOptions[ 0 ].Name = "RenderDevice";
829 0 : aRenderOptions[ 0 ].Value <<= Reference< awt::XDevice >( pXDevice );
830 0 : aRenderOptions[ 1 ].Name = "ExportNotesPages";
831 0 : aRenderOptions[ 1 ].Value <<= sal_False;
832 0 : Any& rExportNotesValue = aRenderOptions[ 1 ].Value;
833 0 : aRenderOptions[ 2 ].Name = "IsFirstPage";
834 0 : aRenderOptions[ 2 ].Value <<= sal_True;
835 0 : aRenderOptions[ 3 ].Name = "IsLastPage";
836 0 : aRenderOptions[ 3 ].Value <<= sal_False;
837 0 : aRenderOptions[ 4 ].Name = "IsSkipEmptyPages";
838 0 : aRenderOptions[ 4 ].Value <<= mbSkipEmptyPages;
839 0 : aRenderOptions[ 5 ].Name = "PageRange";
840 0 : aRenderOptions[ 5 ].Value <<= aPageRange;
841 :
842 0 : if( !aPageRange.isEmpty() || !aSelection.hasValue() )
843 : {
844 0 : aSelection = Any();
845 0 : aSelection <<= mxSrcDoc;
846 : }
847 0 : bool bSecondPassForImpressNotes = false;
848 0 : bool bReChangeToNormalView = false;
849 0 : OUString sShowOnlineLayout( "ShowOnlineLayout" );
850 0 : uno::Reference< beans::XPropertySet > xViewProperties;
851 :
852 0 : if ( aCreator == "Writer" )
853 : {
854 : //i92835 if Writer is in web layout mode this has to be switched to normal view and back to web view in the end
855 : try
856 : {
857 0 : Reference< view::XViewSettingsSupplier > xVSettingsSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
858 0 : xViewProperties = xVSettingsSupplier->getViewSettings();
859 0 : xViewProperties->getPropertyValue( sShowOnlineLayout ) >>= bReChangeToNormalView;
860 0 : if( bReChangeToNormalView )
861 : {
862 0 : xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( false ) );
863 0 : }
864 : }
865 0 : catch( const uno::Exception& )
866 : {
867 : }
868 :
869 : }
870 :
871 0 : const sal_Int32 nPageCount = xRenderable->getRendererCount( aSelection, aRenderOptions );
872 :
873 0 : if ( mbExportNotesPages && aCreator == "Impress" )
874 : {
875 0 : uno::Reference< drawing::XShapes > xShapes; // sj: do not allow to export notes when
876 0 : if ( ! ( aSelection >>= xShapes ) ) // exporting a selection -> todo: in the dialog
877 0 : bSecondPassForImpressNotes = true; // the export notes checkbox needs to be disabled
878 : }
879 :
880 0 : if( aPageRange.isEmpty() )
881 : {
882 0 : aPageRange = OUString::number( 1 ) + "-" + OUString::number(nPageCount );
883 : }
884 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
885 :
886 0 : if ( mxStatusIndicator.is() )
887 : {
888 0 : boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() ));
889 0 : if ( pResMgr )
890 : {
891 0 : sal_Int32 nTotalPageCount = aRangeEnum.size();
892 0 : if ( bSecondPassForImpressNotes )
893 0 : nTotalPageCount *= 2;
894 0 : mxStatusIndicator->start( OUString( ResId( PDF_PROGRESS_BAR, *pResMgr ) ), nTotalPageCount );
895 0 : }
896 : }
897 :
898 0 : if( nPageCount > 0 )
899 0 : bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
900 : else
901 0 : bRet = false;
902 :
903 0 : if ( bRet && bSecondPassForImpressNotes )
904 : {
905 0 : rExportNotesValue <<= sal_True;
906 0 : bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
907 : }
908 0 : if ( mxStatusIndicator.is() )
909 0 : mxStatusIndicator->end();
910 :
911 : // if during the export the doc locale was set copy it to PDF writer
912 0 : const com::sun::star::lang::Locale& rLoc( pPDFExtOutDevData->GetDocumentLocale() );
913 0 : if( !rLoc.Language.isEmpty() )
914 0 : pPDFWriter->SetDocumentLocale( rLoc );
915 :
916 0 : if( bRet )
917 : {
918 0 : pPDFExtOutDevData->PlayGlobalActions( *pPDFWriter );
919 0 : bRet = pPDFWriter->Emit();
920 0 : aErrors = pPDFWriter->GetErrors();
921 : }
922 0 : pOut->SetExtOutDevData( NULL );
923 0 : if( bReChangeToNormalView )
924 : {
925 : try
926 : {
927 0 : xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( true ) );
928 : }
929 0 : catch( const uno::Exception& )
930 : {
931 : }
932 0 : }
933 0 : }
934 0 : }
935 : }
936 :
937 : // show eventual errors during export
938 0 : showErrors( aErrors );
939 :
940 0 : return bRet;
941 : }
942 :
943 : namespace
944 : {
945 :
946 : typedef cppu::WeakComponentImplHelper1< task::XInteractionRequest > PDFErrorRequestBase;
947 :
948 0 : class PDFErrorRequest : private cppu::BaseMutex,
949 : public PDFErrorRequestBase
950 : {
951 : task::PDFExportException maExc;
952 : public:
953 : PDFErrorRequest( const task::PDFExportException& i_rExc );
954 :
955 : // XInteractionRequest
956 : virtual uno::Any SAL_CALL getRequest() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
957 : virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
958 : };
959 :
960 0 : PDFErrorRequest::PDFErrorRequest( const task::PDFExportException& i_rExc ) :
961 : PDFErrorRequestBase( m_aMutex ),
962 0 : maExc( i_rExc )
963 : {
964 0 : }
965 :
966 0 : uno::Any SAL_CALL PDFErrorRequest::getRequest() throw (uno::RuntimeException, std::exception)
967 : {
968 0 : osl::MutexGuard const guard( m_aMutex );
969 :
970 0 : uno::Any aRet;
971 0 : aRet <<= maExc;
972 0 : return aRet;
973 : }
974 :
975 0 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL PDFErrorRequest::getContinuations() throw (uno::RuntimeException, std::exception)
976 : {
977 0 : return uno::Sequence< uno::Reference< task::XInteractionContinuation > >();
978 : }
979 :
980 : } // namespace
981 :
982 0 : void PDFExport::showErrors( const std::set< vcl::PDFWriter::ErrorCode >& rErrors )
983 : {
984 0 : if( ! rErrors.empty() && mxIH.is() )
985 : {
986 0 : task::PDFExportException aExc;
987 0 : aExc.ErrorCodes.realloc( sal_Int32(rErrors.size()) );
988 0 : sal_Int32 i = 0;
989 0 : for( std::set< vcl::PDFWriter::ErrorCode >::const_iterator it = rErrors.begin();
990 0 : it != rErrors.end(); ++it, i++ )
991 : {
992 0 : aExc.ErrorCodes.getArray()[i] = (sal_Int32)*it;
993 : }
994 0 : Reference< task::XInteractionRequest > xReq( new PDFErrorRequest( aExc ) );
995 0 : mxIH->handle( xReq );
996 : }
997 0 : }
998 :
999 :
1000 :
1001 0 : bool PDFExport::ImplExportPage( vcl::PDFWriter& rWriter, vcl::PDFExtOutDevData& rPDFExtOutDevData, const GDIMetaFile& rMtf )
1002 : {
1003 0 : const Size aSizePDF( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_POINT ) );
1004 0 : Point aOrigin;
1005 0 : Rectangle aPageRect( aOrigin, rMtf.GetPrefSize() );
1006 0 : bool bRet = true;
1007 :
1008 0 : rWriter.NewPage( aSizePDF.Width(), aSizePDF.Height() );
1009 0 : rWriter.SetMapMode( rMtf.GetPrefMapMode() );
1010 :
1011 0 : vcl::PDFWriter::PlayMetafileContext aCtx;
1012 0 : GDIMetaFile aMtf;
1013 0 : if( mbRemoveTransparencies )
1014 : {
1015 : aCtx.m_bTransparenciesWereRemoved = rWriter.GetReferenceDevice()->
1016 : RemoveTransparenciesFromMetaFile( rMtf, aMtf, mnMaxImageResolution, mnMaxImageResolution,
1017 0 : false, true, mbReduceImageResolution );
1018 : }
1019 : else
1020 : {
1021 0 : aMtf = rMtf;
1022 : }
1023 0 : aCtx.m_nMaxImageResolution = mbReduceImageResolution ? mnMaxImageResolution : 0;
1024 0 : aCtx.m_bOnlyLosslessCompression = mbUseLosslessCompression;
1025 0 : aCtx.m_nJPEGQuality = mnQuality;
1026 :
1027 :
1028 0 : basegfx::B2DRectangle aB2DRect( aPageRect.Left(), aPageRect.Top(), aPageRect.Right(), aPageRect.Bottom() );
1029 0 : rWriter.SetClipRegion( basegfx::B2DPolyPolygon( basegfx::tools::createPolygonFromRect( aB2DRect ) ) );
1030 :
1031 0 : rWriter.PlayMetafile( aMtf, aCtx, &rPDFExtOutDevData );
1032 :
1033 0 : rPDFExtOutDevData.ResetSyncData();
1034 :
1035 0 : if( mbWatermark )
1036 0 : ImplWriteWatermark( rWriter, aSizePDF );
1037 :
1038 0 : return bRet;
1039 : }
1040 :
1041 :
1042 :
1043 0 : void PDFExport::ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize )
1044 : {
1045 0 : OUString aText( "Watermark" );
1046 0 : vcl::Font aFont( OUString( "Helvetica" ), Size( 0, 3*rPageSize.Height()/4 ) );
1047 0 : aFont.SetItalic( ITALIC_NONE );
1048 0 : aFont.SetWidthType( WIDTH_NORMAL );
1049 0 : aFont.SetWeight( WEIGHT_NORMAL );
1050 0 : aFont.SetAlign( ALIGN_BOTTOM );
1051 0 : long nTextWidth = rPageSize.Width();
1052 0 : if( rPageSize.Width() < rPageSize.Height() )
1053 : {
1054 0 : nTextWidth = rPageSize.Height();
1055 0 : aFont.SetOrientation( 2700 );
1056 : }
1057 :
1058 0 : if( ! ( maWatermark >>= aText ) )
1059 : {
1060 : // more complicated watermark ?
1061 : }
1062 :
1063 : // adjust font height for text to fit
1064 0 : OutputDevice* pDev = rWriter.GetReferenceDevice();
1065 0 : pDev->Push( PushFlags::ALL );
1066 0 : pDev->SetFont( aFont );
1067 0 : pDev->SetMapMode( MapMode( MAP_POINT ) );
1068 0 : int w = 0;
1069 0 : while( ( w = pDev->GetTextWidth( aText ) ) > nTextWidth )
1070 : {
1071 0 : if (w == 0)
1072 0 : break;
1073 0 : long nNewHeight = aFont.GetHeight() * nTextWidth / w;
1074 0 : if( nNewHeight == aFont.GetHeight() )
1075 : {
1076 0 : nNewHeight--;
1077 0 : if( nNewHeight <= 0 )
1078 0 : break;
1079 : }
1080 0 : aFont.SetHeight( nNewHeight );
1081 0 : pDev->SetFont( aFont );
1082 : }
1083 0 : long nTextHeight = pDev->GetTextHeight();
1084 : // leave some maneuvering room for rounding issues, also
1085 : // some fonts go a little outside ascent/descent
1086 0 : nTextHeight += nTextHeight/20;
1087 0 : pDev->Pop();
1088 :
1089 0 : rWriter.Push( PushFlags::ALL );
1090 0 : rWriter.SetMapMode( MapMode( MAP_POINT ) );
1091 0 : rWriter.SetFont( aFont );
1092 0 : rWriter.SetTextColor( COL_LIGHTGREEN );
1093 0 : Point aTextPoint;
1094 0 : Rectangle aTextRect;
1095 0 : if( rPageSize.Width() > rPageSize.Height() )
1096 : {
1097 0 : aTextPoint = Point( (rPageSize.Width()-w)/2,
1098 0 : rPageSize.Height()-(rPageSize.Height()-nTextHeight)/2 );
1099 0 : aTextRect = Rectangle( Point( (rPageSize.Width()-w)/2,
1100 0 : (rPageSize.Height()-nTextHeight)/2 ),
1101 0 : Size( w, nTextHeight ) );
1102 : }
1103 : else
1104 : {
1105 0 : aTextPoint = Point( (rPageSize.Width()-nTextHeight)/2,
1106 0 : (rPageSize.Height()-w)/2 );
1107 0 : aTextRect = Rectangle( aTextPoint, Size( nTextHeight, w ) );
1108 : }
1109 0 : rWriter.SetClipRegion();
1110 0 : rWriter.BeginTransparencyGroup();
1111 0 : rWriter.DrawText( aTextPoint, aText );
1112 0 : rWriter.EndTransparencyGroup( aTextRect, 50 );
1113 0 : rWriter.Pop();
1114 3 : }
1115 :
1116 :
1117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|