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 ::rtl;
80 : using namespace ::vcl;
81 : using namespace ::com::sun::star;
82 : using namespace ::com::sun::star::uno;
83 : using namespace ::com::sun::star::lang;
84 : using namespace ::com::sun::star::beans;
85 : using namespace ::com::sun::star::view;
86 : using namespace ::com::sun::star::graphic;
87 :
88 :
89 : // - PDFExport -
90 :
91 :
92 0 : PDFExport::PDFExport( const Reference< XComponent >& rxSrcDoc,
93 : const Reference< task::XStatusIndicator >& rxStatusIndicator,
94 : const Reference< task::XInteractionHandler >& rxIH,
95 : const Reference< XComponentContext >& xContext ) :
96 : mxSrcDoc ( rxSrcDoc ),
97 : mxContext ( xContext ),
98 : mxStatusIndicator ( rxStatusIndicator ),
99 : mxIH ( rxIH ),
100 : mbUseTaggedPDF ( sal_False ),
101 : mnPDFTypeSelection ( 0 ),
102 : mbExportNotes ( sal_True ),
103 : mbViewPDF ( sal_True ),
104 : mbExportNotesPages ( sal_False ),
105 : mbUseTransitionEffects ( sal_True ),
106 : mbExportBookmarks ( sal_True ),
107 : mbExportHiddenSlides ( sal_False ),
108 : mnOpenBookmarkLevels ( -1 ),
109 : mbUseLosslessCompression ( sal_False ),
110 : mbReduceImageResolution ( sal_True ),
111 : mbSkipEmptyPages ( sal_True ),
112 : mbAddStream ( sal_False ),
113 : mnMaxImageResolution ( 300 ),
114 : mnQuality ( 90 ),
115 : mnFormsFormat ( 0 ),
116 : mbExportFormFields ( sal_True ),
117 : mbAllowDuplicateFieldNames ( sal_False ),
118 : mnProgressValue ( 0 ),
119 : mbRemoveTransparencies ( sal_False ),
120 : mbWatermark ( sal_False ),
121 :
122 : mbHideViewerToolbar ( sal_False ),
123 : mbHideViewerMenubar ( sal_False ),
124 : mbHideViewerWindowControls ( sal_False ),
125 : mbFitWindow ( sal_False ),
126 : mbCenterWindow ( sal_False ),
127 : mbOpenInFullScreenMode ( sal_False ),
128 : mbDisplayPDFDocumentTitle ( sal_True ),
129 : mnPDFDocumentMode ( 0 ),
130 : mnPDFDocumentAction ( 0 ),
131 : mnZoom ( 100 ),
132 : mnInitialPage ( 1 ),
133 : mnPDFPageLayout ( 0 ),
134 : mbFirstPageLeft ( sal_False ),
135 :
136 : mbEncrypt ( sal_False ),
137 : mbRestrictPermissions ( sal_False ),
138 : mnPrintAllowed ( 2 ),
139 : mnChangesAllowed ( 4 ),
140 : mbCanCopyOrExtract ( sal_True ),
141 : mbCanExtractForAccessibility( sal_True ),
142 :
143 : //--->i56629
144 : mbExportRelativeFsysLinks ( sal_False ),
145 : mnDefaultLinkAction ( 0 ),
146 : mbConvertOOoTargetToPDFTarget( sal_False ),
147 : mbExportBmkToDest ( sal_False ),
148 0 : mbSignPDF ( false )
149 : {
150 0 : }
151 :
152 :
153 :
154 0 : PDFExport::~PDFExport()
155 : {
156 0 : }
157 :
158 :
159 :
160 0 : sal_Bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
161 : Reference< com::sun::star::view::XRenderable >& rRenderable,
162 : const Any& rSelection,
163 : const StringRangeEnumerator& rRangeEnum,
164 : Sequence< PropertyValue >& rRenderOptions,
165 : sal_Int32 nPageCount )
166 : {
167 0 : sal_Bool bRet = sal_False;
168 : try
169 : {
170 0 : Any* pFirstPage = NULL;
171 0 : Any* pLastPage = NULL;
172 :
173 0 : sal_Bool bExportNotesPages = sal_False;
174 :
175 0 : for( sal_Int32 nData = 0, nDataCount = rRenderOptions.getLength(); nData < nDataCount; ++nData )
176 : {
177 0 : if ( rRenderOptions[ nData ].Name == "IsFirstPage" )
178 0 : pFirstPage = &rRenderOptions[ nData ].Value;
179 0 : else if ( rRenderOptions[ nData ].Name == "IsLastPage" )
180 0 : pLastPage = &rRenderOptions[ nData ].Value;
181 0 : else if ( rRenderOptions[ nData ].Name == "ExportNotesPages" )
182 0 : rRenderOptions[ nData ].Value >>= bExportNotesPages;
183 : }
184 :
185 0 : OutputDevice* pOut = rPDFWriter.GetReferenceDevice();
186 :
187 0 : if( pOut )
188 : {
189 0 : vcl::PDFExtOutDevData* pPDFExtOutDevData = PTR_CAST( vcl::PDFExtOutDevData, pOut->GetExtOutDevData() );
190 0 : if ( nPageCount )
191 : {
192 0 : pPDFExtOutDevData->SetIsExportNotesPages( bExportNotesPages );
193 :
194 0 : sal_Int32 nCurrentPage(0);
195 0 : StringRangeEnumerator::Iterator aIter = rRangeEnum.begin();
196 0 : StringRangeEnumerator::Iterator aEnd = rRangeEnum.end();
197 0 : while ( aIter != aEnd )
198 : {
199 0 : Sequence< PropertyValue > aRenderer( rRenderable->getRenderer( *aIter, rSelection, rRenderOptions ) );
200 0 : awt::Size aPageSize;
201 :
202 0 : for( sal_Int32 nProperty = 0, nPropertyCount = aRenderer.getLength(); nProperty < nPropertyCount; ++nProperty )
203 : {
204 0 : if ( aRenderer[ nProperty ].Name == "PageSize" )
205 0 : aRenderer[ nProperty].Value >>= aPageSize;
206 : }
207 :
208 0 : pPDFExtOutDevData->SetCurrentPageNumber( nCurrentPage );
209 :
210 0 : GDIMetaFile aMtf;
211 0 : const MapMode aMapMode( MAP_100TH_MM );
212 0 : const Size aMtfSize( aPageSize.Width, aPageSize.Height );
213 :
214 0 : pOut->Push();
215 0 : pOut->EnableOutput( false );
216 0 : pOut->SetMapMode( aMapMode );
217 :
218 0 : aMtf.SetPrefSize( aMtfSize );
219 0 : aMtf.SetPrefMapMode( aMapMode );
220 0 : aMtf.Record( pOut );
221 :
222 : // #i35176#
223 : // IsLastPage property.
224 0 : const sal_Int32 nCurrentRenderer = *aIter;
225 0 : ++aIter;
226 0 : if ( pLastPage && aIter == aEnd )
227 0 : *pLastPage <<= sal_True;
228 :
229 0 : rRenderable->render( nCurrentRenderer, rSelection, rRenderOptions );
230 :
231 0 : aMtf.Stop();
232 0 : aMtf.WindStart();
233 :
234 0 : if( aMtf.GetActionSize() &&
235 0 : ( !mbSkipEmptyPages || aPageSize.Width || aPageSize.Height ) )
236 0 : bRet = ImplExportPage( rPDFWriter, *pPDFExtOutDevData, aMtf ) || bRet;
237 :
238 0 : pOut->Pop();
239 :
240 0 : if ( mxStatusIndicator.is() )
241 0 : mxStatusIndicator->setValue( mnProgressValue );
242 0 : if ( pFirstPage )
243 0 : *pFirstPage <<= sal_False;
244 :
245 0 : ++mnProgressValue;
246 0 : ++nCurrentPage;
247 0 : }
248 : }
249 : else
250 : {
251 0 : bRet = sal_True; // #i18334# SJ: nPageCount == 0,
252 0 : rPDFWriter.NewPage( 10000, 10000 ); // creating dummy page
253 0 : rPDFWriter.SetMapMode( MAP_100TH_MM );
254 : }
255 : }
256 : }
257 0 : catch(const RuntimeException &)
258 : {
259 : }
260 0 : return bRet;
261 : }
262 :
263 : class PDFExportStreamDoc : public vcl::PDFOutputStream
264 : {
265 : Reference< XComponent > m_xSrcDoc;
266 : Sequence< beans::NamedValue > m_aPreparedPassword;
267 : public:
268 0 : PDFExportStreamDoc( const Reference< XComponent >& xDoc, const Sequence<beans::NamedValue>& rPwd )
269 : : m_xSrcDoc( xDoc ),
270 0 : m_aPreparedPassword( rPwd )
271 0 : {}
272 : virtual ~PDFExportStreamDoc();
273 :
274 : virtual void write( const Reference< XOutputStream >& xStream ) SAL_OVERRIDE;
275 : };
276 :
277 0 : PDFExportStreamDoc::~PDFExportStreamDoc()
278 : {
279 0 : }
280 :
281 0 : void PDFExportStreamDoc::write( const Reference< XOutputStream >& xStream )
282 : {
283 0 : Reference< com::sun::star::frame::XStorable > xStore( m_xSrcDoc, UNO_QUERY );
284 0 : if( xStore.is() )
285 : {
286 0 : Sequence< beans::PropertyValue > aArgs( 2 + ((m_aPreparedPassword.getLength() > 0) ? 1 : 0) );
287 0 : aArgs.getArray()[0].Name = "FilterName";
288 0 : aArgs.getArray()[1].Name = "OutputStream";
289 0 : aArgs.getArray()[1].Value <<= xStream;
290 0 : if( m_aPreparedPassword.getLength() )
291 : {
292 0 : aArgs.getArray()[2].Name = "EncryptionData";
293 0 : aArgs.getArray()[2].Value <<= m_aPreparedPassword;
294 : }
295 :
296 : try
297 : {
298 0 : xStore->storeToURL( "private:stream", aArgs );
299 : }
300 0 : catch( const IOException& )
301 : {
302 0 : }
303 0 : }
304 0 : }
305 :
306 0 : static OUString getMimetypeForDocument( const Reference< XComponentContext >& xContext,
307 : const Reference< XComponent >& xDoc ) throw()
308 : {
309 0 : OUString aDocMimetype;
310 : try
311 : {
312 : // get document service name
313 0 : Reference< com::sun::star::frame::XStorable > xStore( xDoc, UNO_QUERY );
314 0 : Reference< frame::XModuleManager2 > xModuleManager = frame::ModuleManager::create(xContext);
315 0 : if( xStore.is() )
316 : {
317 0 : OUString aDocServiceName = xModuleManager->identify( Reference< XInterface >( xStore, uno::UNO_QUERY ) );
318 0 : if ( !aDocServiceName.isEmpty() )
319 : {
320 : // get the actual filter name
321 0 : OUString aFilterName;
322 : Reference< lang::XMultiServiceFactory > xConfigProvider =
323 0 : configuration::theDefaultProvider::get( xContext );
324 0 : uno::Sequence< uno::Any > aArgs( 1 );
325 0 : beans::NamedValue aPathProp;
326 0 : aPathProp.Name = "nodepath";
327 0 : aPathProp.Value <<= OUString( "/org.openoffice.Setup/Office/Factories/" );
328 0 : aArgs[0] <<= aPathProp;
329 :
330 : Reference< container::XNameAccess > xSOFConfig(
331 0 : xConfigProvider->createInstanceWithArguments(
332 0 : "com.sun.star.configuration.ConfigurationAccess", aArgs ),
333 0 : uno::UNO_QUERY );
334 :
335 0 : Reference< container::XNameAccess > xApplConfig;
336 0 : xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig;
337 0 : if ( xApplConfig.is() )
338 : {
339 0 : xApplConfig->getByName( "ooSetupFactoryActualFilter" ) >>= aFilterName;
340 0 : if( !aFilterName.isEmpty() )
341 : {
342 : // find the related type name
343 0 : OUString aTypeName;
344 : Reference< container::XNameAccess > xFilterFactory(
345 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext),
346 0 : uno::UNO_QUERY );
347 :
348 0 : Sequence< beans::PropertyValue > aFilterData;
349 0 : xFilterFactory->getByName( aFilterName ) >>= aFilterData;
350 0 : for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
351 0 : if ( aFilterData[nInd].Name == "Type" )
352 0 : aFilterData[nInd].Value >>= aTypeName;
353 :
354 0 : if ( !aTypeName.isEmpty() )
355 : {
356 : // find the mediatype
357 : Reference< container::XNameAccess > xTypeDetection(
358 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
359 0 : UNO_QUERY );
360 :
361 0 : Sequence< beans::PropertyValue > aTypeData;
362 0 : xTypeDetection->getByName( aTypeName ) >>= aTypeData;
363 0 : for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ )
364 0 : if ( aTypeData[nInd].Name == "MediaType" )
365 0 : aTypeData[nInd].Value >>= aDocMimetype;
366 0 : }
367 : }
368 0 : }
369 0 : }
370 0 : }
371 : }
372 0 : catch (...)
373 : {
374 : }
375 0 : return aDocMimetype;
376 : }
377 :
378 0 : sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& rFilterData )
379 : {
380 0 : INetURLObject aURL( rFile );
381 0 : sal_Bool bRet = sal_False;
382 :
383 0 : std::set< PDFWriter::ErrorCode > aErrors;
384 :
385 0 : if( aURL.GetProtocol() != INET_PROT_FILE )
386 : {
387 0 : OUString aTmp;
388 :
389 0 : if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFile, aTmp ) )
390 0 : aURL = INetURLObject(aTmp);
391 : }
392 :
393 0 : if( aURL.GetProtocol() == INET_PROT_FILE )
394 : {
395 0 : Reference< XRenderable > xRenderable( mxSrcDoc, UNO_QUERY );
396 :
397 0 : if( xRenderable.is() )
398 : {
399 0 : VCLXDevice* pXDevice = new VCLXDevice;
400 0 : OUString aPageRange;
401 0 : Any aSelection;
402 0 : PDFWriter::PDFWriterContext aContext;
403 0 : OUString aOpenPassword, aPermissionPassword;
404 0 : Reference< beans::XMaterialHolder > xEnc;
405 0 : Sequence< beans::NamedValue > aPreparedPermissionPassword;
406 :
407 :
408 : // getting the string for the creator
409 0 : OUString aCreator;
410 0 : Reference< XServiceInfo > xInfo( mxSrcDoc, UNO_QUERY );
411 0 : if ( xInfo.is() )
412 : {
413 0 : if ( xInfo->supportsService( "com.sun.star.presentation.PresentationDocument" ) )
414 0 : aCreator += "Impress";
415 0 : else if ( xInfo->supportsService( "com.sun.star.drawing.DrawingDocument" ) )
416 0 : aCreator += "Draw";
417 0 : else if ( xInfo->supportsService( "com.sun.star.text.TextDocument" ) )
418 0 : aCreator += "Writer";
419 0 : else if ( xInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
420 0 : aCreator += "Calc";
421 0 : else if ( xInfo->supportsService( "com.sun.star.formula.FormulaProperties" ) )
422 0 : aCreator += "Math";
423 : }
424 :
425 0 : Reference< document::XDocumentPropertiesSupplier > xDocumentPropsSupplier( mxSrcDoc, UNO_QUERY );
426 0 : if ( xDocumentPropsSupplier.is() )
427 : {
428 0 : Reference< document::XDocumentProperties > xDocumentProps( xDocumentPropsSupplier->getDocumentProperties() );
429 0 : if ( xDocumentProps.is() )
430 : {
431 0 : aContext.DocumentInfo.Title = xDocumentProps->getTitle();
432 0 : aContext.DocumentInfo.Author = xDocumentProps->getAuthor();
433 0 : aContext.DocumentInfo.Subject = xDocumentProps->getSubject();
434 0 : aContext.DocumentInfo.Keywords = ::comphelper::string::convertCommaSeparated(xDocumentProps->getKeywords());
435 0 : }
436 : }
437 : // getting the string for the producer
438 0 : aContext.DocumentInfo.Producer =
439 0 : utl::ConfigManager::getProductName() +
440 0 : " " +
441 0 : utl::ConfigManager::getProductVersion();
442 0 : aContext.DocumentInfo.Creator = aCreator;
443 :
444 0 : for( sal_Int32 nData = 0, nDataCount = rFilterData.getLength(); nData < nDataCount; ++nData )
445 : {
446 0 : if ( rFilterData[ nData ].Name == "PageRange" )
447 0 : rFilterData[ nData ].Value >>= aPageRange;
448 0 : else if ( rFilterData[ nData ].Name == "Selection" )
449 0 : rFilterData[ nData ].Value >>= aSelection;
450 0 : else if ( rFilterData[ nData ].Name == "UseLosslessCompression" )
451 0 : rFilterData[ nData ].Value >>= mbUseLosslessCompression;
452 0 : else if ( rFilterData[ nData ].Name == "Quality" )
453 0 : rFilterData[ nData ].Value >>= mnQuality;
454 0 : else if ( rFilterData[ nData ].Name == "ReduceImageResolution" )
455 0 : rFilterData[ nData ].Value >>= mbReduceImageResolution;
456 0 : else if ( rFilterData[ nData ].Name == "IsSkipEmptyPages" )
457 0 : rFilterData[ nData ].Value >>= mbSkipEmptyPages;
458 0 : else if ( rFilterData[ nData ].Name == "MaxImageResolution" )
459 0 : rFilterData[ nData ].Value >>= mnMaxImageResolution;
460 0 : else if ( rFilterData[ nData ].Name == "UseTaggedPDF" )
461 0 : rFilterData[ nData ].Value >>= mbUseTaggedPDF;
462 0 : else if ( rFilterData[ nData ].Name == "SelectPdfVersion" )
463 0 : rFilterData[ nData ].Value >>= mnPDFTypeSelection;
464 0 : else if ( rFilterData[ nData ].Name == "ExportNotes" )
465 0 : rFilterData[ nData ].Value >>= mbExportNotes;
466 0 : else if ( rFilterData[ nData ].Name == "ViewPDFAfterExport" )
467 0 : rFilterData[ nData ].Value >>= mbViewPDF;
468 0 : else if ( rFilterData[ nData ].Name == "ExportNotesPages" )
469 0 : rFilterData[ nData ].Value >>= mbExportNotesPages;
470 0 : else if ( rFilterData[ nData ].Name == "UseTransitionEffects" )
471 0 : rFilterData[ nData ].Value >>= mbUseTransitionEffects;
472 0 : else if ( rFilterData[ nData ].Name == "ExportFormFields" )
473 0 : rFilterData[ nData ].Value >>= mbExportFormFields;
474 0 : else if ( rFilterData[ nData ].Name == "FormsType" )
475 0 : rFilterData[ nData ].Value >>= mnFormsFormat;
476 0 : else if ( rFilterData[ nData ].Name == "AllowDuplicateFieldNames" )
477 0 : rFilterData[ nData ].Value >>= mbAllowDuplicateFieldNames;
478 : //viewer properties
479 0 : else if ( rFilterData[ nData ].Name == "HideViewerToolbar" )
480 0 : rFilterData[ nData ].Value >>= mbHideViewerToolbar;
481 0 : else if ( rFilterData[ nData ].Name == "HideViewerMenubar" )
482 0 : rFilterData[ nData ].Value >>= mbHideViewerMenubar;
483 0 : else if ( rFilterData[ nData ].Name == "HideViewerWindowControls" )
484 0 : rFilterData[ nData ].Value >>= mbHideViewerWindowControls;
485 0 : else if ( rFilterData[ nData ].Name == "ResizeWindowToInitialPage" )
486 0 : rFilterData[ nData ].Value >>= mbFitWindow;
487 0 : else if ( rFilterData[ nData ].Name == "CenterWindow" )
488 0 : rFilterData[ nData ].Value >>= mbCenterWindow;
489 0 : else if ( rFilterData[ nData ].Name == "OpenInFullScreenMode" )
490 0 : rFilterData[ nData ].Value >>= mbOpenInFullScreenMode;
491 0 : else if ( rFilterData[ nData ].Name == "DisplayPDFDocumentTitle" )
492 0 : rFilterData[ nData ].Value >>= mbDisplayPDFDocumentTitle;
493 0 : else if ( rFilterData[ nData ].Name == "InitialView" )
494 0 : rFilterData[ nData ].Value >>= mnPDFDocumentMode;
495 0 : else if ( rFilterData[ nData ].Name == "Magnification" )
496 0 : rFilterData[ nData ].Value >>= mnPDFDocumentAction;
497 0 : else if ( rFilterData[ nData ].Name == "Zoom" )
498 0 : rFilterData[ nData ].Value >>= mnZoom;
499 0 : else if ( rFilterData[ nData ].Name == "InitialPage" )
500 0 : rFilterData[ nData ].Value >>= mnInitialPage;
501 0 : else if ( rFilterData[ nData ].Name == "PageLayout" )
502 0 : rFilterData[ nData ].Value >>= mnPDFPageLayout;
503 0 : else if ( rFilterData[ nData ].Name == "FirstPageOnLeft" )
504 0 : rFilterData[ nData ].Value >>= aContext.FirstPageLeft;
505 0 : else if ( rFilterData[ nData ].Name == "IsAddStream" )
506 0 : rFilterData[ nData ].Value >>= mbAddStream;
507 0 : else if ( rFilterData[ nData ].Name == "Watermark" )
508 : {
509 0 : maWatermark = rFilterData[ nData ].Value;
510 0 : mbWatermark = sal_True;
511 : }
512 : //now all the security related properties...
513 0 : else if ( rFilterData[ nData ].Name == "EncryptFile" )
514 0 : rFilterData[ nData ].Value >>= mbEncrypt;
515 0 : else if ( rFilterData[ nData ].Name == "DocumentOpenPassword" )
516 0 : rFilterData[ nData ].Value >>= aOpenPassword;
517 0 : else if ( rFilterData[ nData ].Name == "RestrictPermissions" )
518 0 : rFilterData[ nData ].Value >>= mbRestrictPermissions;
519 0 : else if ( rFilterData[ nData ].Name == "PermissionPassword" )
520 0 : rFilterData[ nData ].Value >>= aPermissionPassword;
521 0 : else if ( rFilterData[ nData ].Name == "PreparedPasswords" )
522 0 : rFilterData[ nData ].Value >>= xEnc;
523 0 : else if ( rFilterData[ nData ].Name == "PreparedPermissionPassword" )
524 0 : rFilterData[ nData ].Value >>= aPreparedPermissionPassword;
525 0 : else if ( rFilterData[ nData ].Name == "Printing" )
526 0 : rFilterData[ nData ].Value >>= mnPrintAllowed;
527 0 : else if ( rFilterData[ nData ].Name == "Changes" )
528 0 : rFilterData[ nData ].Value >>= mnChangesAllowed;
529 0 : else if ( rFilterData[ nData ].Name == "EnableCopyingOfContent" )
530 0 : rFilterData[ nData ].Value >>= mbCanCopyOrExtract;
531 0 : else if ( rFilterData[ nData ].Name == "EnableTextAccessForAccessibilityTools" )
532 0 : rFilterData[ nData ].Value >>= mbCanExtractForAccessibility;
533 : //--->i56629 links extra (relative links and other related stuff)
534 0 : else if ( rFilterData[ nData ].Name == "ExportLinksRelativeFsys" )
535 0 : rFilterData[ nData ].Value >>= mbExportRelativeFsysLinks;
536 0 : else if ( rFilterData[ nData ].Name == "PDFViewSelection" )
537 0 : rFilterData[ nData ].Value >>= mnDefaultLinkAction;
538 0 : else if ( rFilterData[ nData ].Name == "ConvertOOoTargetToPDFTarget" )
539 0 : rFilterData[ nData ].Value >>= mbConvertOOoTargetToPDFTarget;
540 0 : else if ( rFilterData[ nData ].Name == "ExportBookmarksToPDFDestination" )
541 0 : rFilterData[ nData ].Value >>= mbExportBmkToDest;
542 0 : else if ( rFilterData[ nData ].Name == "ExportBookmarks" )
543 0 : rFilterData[ nData ].Value >>= mbExportBookmarks;
544 0 : else if ( rFilterData[ nData ].Name == "ExportHiddenSlides" )
545 0 : rFilterData[ nData ].Value >>= mbExportHiddenSlides;
546 0 : else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" )
547 0 : rFilterData[ nData ].Value >>= mnOpenBookmarkLevels;
548 0 : else if ( rFilterData[ nData ].Name == "SignPDF" )
549 0 : rFilterData[ nData ].Value >>= mbSignPDF;
550 0 : else if ( rFilterData[ nData ].Name == "SignatureLocation" )
551 0 : rFilterData[ nData ].Value >>= msSignLocation;
552 0 : else if ( rFilterData[ nData ].Name == "SignatureReason" )
553 0 : rFilterData[ nData ].Value >>= msSignReason;
554 0 : else if ( rFilterData[ nData ].Name == "SignatureContactInfo" )
555 0 : rFilterData[ nData ].Value >>= msSignContact;
556 0 : else if ( rFilterData[ nData ].Name == "SignaturePassword" )
557 0 : rFilterData[ nData ].Value >>= msSignPassword;
558 0 : else if ( rFilterData[ nData ].Name == "SignatureCertificate" )
559 0 : rFilterData[ nData ].Value >>= maSignCertificate;
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 = PDFWriter::PDF_1_4;
569 0 : break;
570 : case 1:
571 0 : aContext.Version = PDFWriter::PDF_A_1;
572 : //force the tagged PDF as well
573 0 : mbUseTaggedPDF = sal_True;
574 : //force disabling of form conversion
575 0 : mbExportFormFields = sal_False;
576 : // PDF/A does not allow transparencies
577 0 : mbRemoveTransparencies = sal_True;
578 : // no encryption
579 0 : mbEncrypt = sal_False;
580 0 : xEnc.clear();
581 0 : break;
582 : }
583 :
584 : //copy in context the values default in the contructor 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 = PDFWriter::ModeDefault;
603 0 : break;
604 : case 1:
605 0 : aContext.PDFDocumentMode = PDFWriter::UseOutlines;
606 0 : break;
607 : case 2:
608 0 : aContext.PDFDocumentMode = PDFWriter::UseThumbs;
609 0 : break;
610 : }
611 0 : switch( mnPDFDocumentAction )
612 : {
613 : default:
614 : case 0:
615 0 : aContext.PDFDocumentAction = PDFWriter::ActionDefault;
616 0 : break;
617 : case 1:
618 0 : aContext.PDFDocumentAction = PDFWriter::FitInWindow;
619 0 : break;
620 : case 2:
621 0 : aContext.PDFDocumentAction = PDFWriter::FitWidth;
622 0 : break;
623 : case 3:
624 0 : aContext.PDFDocumentAction = PDFWriter::FitVisible;
625 0 : break;
626 : case 4:
627 0 : aContext.PDFDocumentAction = 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 = PDFWriter::DefaultLayout;
637 0 : break;
638 : case 1:
639 0 : aContext.PageLayout = PDFWriter::SinglePage;
640 0 : break;
641 : case 2:
642 0 : aContext.PageLayout = PDFWriter::Continuous;
643 0 : break;
644 : case 3:
645 0 : aContext.PageLayout = 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 != 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 = sal_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 = sal_True;
674 0 : mbCanExtractForAccessibility = sal_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 = 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 = OUString();
722 0 : aOpenPassword = OUString();
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 = PDFWriter::PDF;
732 0 : break;
733 : case 2:
734 0 : aContext.SubmitFormat = PDFWriter::HTML;
735 0 : break;
736 : case 3:
737 0 : aContext.SubmitFormat = PDFWriter::XML;
738 0 : break;
739 : default:
740 : case 0:
741 0 : aContext.SubmitFormat = 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 = PDFWriter::URIAction;
762 0 : break;
763 : //view PDF through the reader application
764 : case 1:
765 0 : aContext.ForcePDFAction = true;
766 0 : aContext.DefaultLinkAction = PDFWriter::LaunchAction;
767 0 : break;
768 : //view PDF through an Internet browser
769 : case 2:
770 0 : aContext.DefaultLinkAction = 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 == PDFWriter::PDF_A_1 &&
777 0 : aContext.DefaultLinkAction == PDFWriter::LaunchAction )
778 : { //force the similar allowed URI action
779 0 : aContext.DefaultLinkAction = 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 :
792 : // all context data set, time to create the printing device
793 0 : boost::scoped_ptr<PDFWriter> pPDFWriter(new PDFWriter( aContext, xEnc ));
794 0 : OutputDevice* pOut = pPDFWriter->GetReferenceDevice();
795 :
796 : DBG_ASSERT( pOut, "PDFExport::Export: no reference device" );
797 0 : pXDevice->SetOutputDevice( pOut );
798 :
799 0 : if( mbAddStream )
800 : {
801 : // export stream
802 : // get mimetype
803 0 : OUString aSrcMimetype = getMimetypeForDocument( mxContext, mxSrcDoc );
804 : pPDFWriter->AddStream( aSrcMimetype,
805 0 : new PDFExportStreamDoc( mxSrcDoc, aPreparedPermissionPassword ),
806 : false
807 0 : );
808 : }
809 :
810 0 : if ( pOut )
811 : {
812 : DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" );
813 0 : boost::scoped_ptr<vcl::PDFExtOutDevData> pPDFExtOutDevData(new vcl::PDFExtOutDevData( *pOut ));
814 0 : pOut->SetExtOutDevData( pPDFExtOutDevData.get() );
815 0 : pPDFExtOutDevData->SetIsExportNotes( mbExportNotes );
816 0 : pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF );
817 0 : pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects );
818 0 : pPDFExtOutDevData->SetFormsFormat( mnFormsFormat );
819 0 : pPDFExtOutDevData->SetIsExportFormFields( mbExportFormFields );
820 0 : pPDFExtOutDevData->SetIsExportBookmarks( mbExportBookmarks );
821 0 : pPDFExtOutDevData->SetIsExportHiddenSlides( mbExportHiddenSlides );
822 0 : pPDFExtOutDevData->SetIsLosslessCompression( mbUseLosslessCompression );
823 0 : pPDFExtOutDevData->SetIsReduceImageResolution( mbReduceImageResolution );
824 0 : pPDFExtOutDevData->SetIsExportNamedDestinations( mbExportBmkToDest );
825 :
826 0 : Sequence< PropertyValue > aRenderOptions( 6 );
827 0 : aRenderOptions[ 0 ].Name = "RenderDevice";
828 0 : aRenderOptions[ 0 ].Value <<= Reference< awt::XDevice >( pXDevice );
829 0 : aRenderOptions[ 1 ].Name = "ExportNotesPages";
830 0 : aRenderOptions[ 1 ].Value <<= sal_False;
831 0 : Any& rExportNotesValue = aRenderOptions[ 1 ].Value;
832 0 : aRenderOptions[ 2 ].Name = "IsFirstPage";
833 0 : aRenderOptions[ 2 ].Value <<= sal_True;
834 0 : aRenderOptions[ 3 ].Name = "IsLastPage";
835 0 : aRenderOptions[ 3 ].Value <<= sal_False;
836 0 : aRenderOptions[ 4 ].Name = "IsSkipEmptyPages";
837 0 : aRenderOptions[ 4 ].Value <<= mbSkipEmptyPages;
838 0 : aRenderOptions[ 5 ].Name = "PageRange";
839 0 : aRenderOptions[ 5 ].Value <<= aPageRange;
840 :
841 0 : if( !aPageRange.isEmpty() || !aSelection.hasValue() )
842 : {
843 0 : aSelection = Any();
844 0 : aSelection <<= mxSrcDoc;
845 : }
846 0 : sal_Bool bSecondPassForImpressNotes = sal_False;
847 0 : bool bReChangeToNormalView = false;
848 0 : OUString sShowOnlineLayout( "ShowOnlineLayout" );
849 0 : uno::Reference< beans::XPropertySet > xViewProperties;
850 :
851 0 : if ( aCreator.equalsAscii( "Writer" ) )
852 : {
853 : //i92835 if Writer is in web layout mode this has to be switched to normal view and back to web view in the end
854 : try
855 : {
856 0 : Reference< view::XViewSettingsSupplier > xVSettingsSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
857 0 : xViewProperties = xVSettingsSupplier->getViewSettings();
858 0 : xViewProperties->getPropertyValue( sShowOnlineLayout ) >>= bReChangeToNormalView;
859 0 : if( bReChangeToNormalView )
860 : {
861 0 : xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( false ) );
862 0 : }
863 : }
864 0 : catch( const uno::Exception& )
865 : {
866 : }
867 :
868 : }
869 :
870 0 : const sal_Int32 nPageCount = xRenderable->getRendererCount( aSelection, aRenderOptions );
871 :
872 0 : if ( mbExportNotesPages && aCreator.equalsAscii( "Impress" ) )
873 : {
874 0 : uno::Reference< drawing::XShapes > xShapes; // sj: do not allow to export notes when
875 0 : if ( ! ( aSelection >>= xShapes ) ) // exporting a selection -> todo: in the dialog
876 0 : bSecondPassForImpressNotes = sal_True; // the export notes checkbox needs to be disabled
877 : }
878 :
879 0 : if( aPageRange.isEmpty() )
880 : {
881 0 : aPageRange = OUString::number( 1 ) + "-" + OUString::number(nPageCount );
882 : }
883 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
884 :
885 0 : if ( mxStatusIndicator.is() )
886 : {
887 0 : boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() ));
888 0 : if ( pResMgr )
889 : {
890 0 : sal_Int32 nTotalPageCount = aRangeEnum.size();
891 0 : if ( bSecondPassForImpressNotes )
892 0 : nTotalPageCount *= 2;
893 0 : mxStatusIndicator->start( OUString( ResId( PDF_PROGRESS_BAR, *pResMgr ) ), nTotalPageCount );
894 0 : }
895 : }
896 :
897 0 : if( nPageCount > 0 )
898 0 : bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
899 : else
900 0 : bRet = sal_False;
901 :
902 0 : if ( bRet && bSecondPassForImpressNotes )
903 : {
904 0 : rExportNotesValue <<= sal_True;
905 0 : bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
906 : }
907 0 : if ( mxStatusIndicator.is() )
908 0 : mxStatusIndicator->end();
909 :
910 : // if during the export the doc locale was set copy it to PDF writer
911 0 : const com::sun::star::lang::Locale& rLoc( pPDFExtOutDevData->GetDocumentLocale() );
912 0 : if( !rLoc.Language.isEmpty() )
913 0 : pPDFWriter->SetDocumentLocale( rLoc );
914 :
915 0 : if( bRet )
916 : {
917 0 : pPDFExtOutDevData->PlayGlobalActions( *pPDFWriter );
918 0 : pPDFWriter->Emit();
919 0 : aErrors = pPDFWriter->GetErrors();
920 : }
921 0 : pOut->SetExtOutDevData( NULL );
922 0 : if( bReChangeToNormalView )
923 : {
924 : try
925 : {
926 0 : xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( true ) );
927 : }
928 0 : catch( const uno::Exception& )
929 : {
930 : }
931 0 : }
932 0 : }
933 0 : }
934 : }
935 :
936 : // show eventual errors during export
937 0 : showErrors( aErrors );
938 :
939 0 : return bRet;
940 : }
941 :
942 : namespace
943 : {
944 :
945 : typedef cppu::WeakComponentImplHelper1< task::XInteractionRequest > PDFErrorRequestBase;
946 :
947 0 : class PDFErrorRequest : private cppu::BaseMutex,
948 : public PDFErrorRequestBase
949 : {
950 : task::PDFExportException maExc;
951 : public:
952 : PDFErrorRequest( const task::PDFExportException& i_rExc );
953 :
954 : // XInteractionRequest
955 : virtual uno::Any SAL_CALL getRequest() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
956 : virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
957 : };
958 :
959 0 : PDFErrorRequest::PDFErrorRequest( const task::PDFExportException& i_rExc ) :
960 : PDFErrorRequestBase( m_aMutex ),
961 0 : maExc( i_rExc )
962 : {
963 0 : }
964 :
965 0 : uno::Any SAL_CALL PDFErrorRequest::getRequest() throw (uno::RuntimeException, std::exception)
966 : {
967 0 : osl::MutexGuard const guard( m_aMutex );
968 :
969 0 : uno::Any aRet;
970 0 : aRet <<= maExc;
971 0 : return aRet;
972 : }
973 :
974 0 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL PDFErrorRequest::getContinuations() throw (uno::RuntimeException, std::exception)
975 : {
976 0 : return uno::Sequence< uno::Reference< task::XInteractionContinuation > >();
977 : }
978 :
979 : } // namespace
980 :
981 0 : void PDFExport::showErrors( const std::set< PDFWriter::ErrorCode >& rErrors )
982 : {
983 0 : if( ! rErrors.empty() && mxIH.is() )
984 : {
985 0 : task::PDFExportException aExc;
986 0 : aExc.ErrorCodes.realloc( sal_Int32(rErrors.size()) );
987 0 : sal_Int32 i = 0;
988 0 : for( std::set< PDFWriter::ErrorCode >::const_iterator it = rErrors.begin();
989 0 : it != rErrors.end(); ++it, i++ )
990 : {
991 0 : aExc.ErrorCodes.getArray()[i] = (sal_Int32)*it;
992 : }
993 0 : Reference< task::XInteractionRequest > xReq( new PDFErrorRequest( aExc ) );
994 0 : mxIH->handle( xReq );
995 : }
996 0 : }
997 :
998 :
999 :
1000 0 : sal_Bool PDFExport::ImplExportPage( PDFWriter& rWriter, PDFExtOutDevData& rPDFExtOutDevData, const GDIMetaFile& rMtf )
1001 : {
1002 0 : const Size aSizePDF( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_POINT ) );
1003 0 : Point aOrigin;
1004 0 : Rectangle aPageRect( aOrigin, rMtf.GetPrefSize() );
1005 0 : sal_Bool bRet = sal_True;
1006 :
1007 0 : rWriter.NewPage( aSizePDF.Width(), aSizePDF.Height() );
1008 0 : rWriter.SetMapMode( rMtf.GetPrefMapMode() );
1009 :
1010 0 : vcl::PDFWriter::PlayMetafileContext aCtx;
1011 0 : GDIMetaFile aMtf;
1012 0 : if( mbRemoveTransparencies )
1013 : {
1014 : aCtx.m_bTransparenciesWereRemoved = rWriter.GetReferenceDevice()->
1015 : RemoveTransparenciesFromMetaFile( rMtf, aMtf, mnMaxImageResolution, mnMaxImageResolution,
1016 0 : false, true, mbReduceImageResolution );
1017 : }
1018 : else
1019 : {
1020 0 : aMtf = rMtf;
1021 : }
1022 0 : aCtx.m_nMaxImageResolution = mbReduceImageResolution ? mnMaxImageResolution : 0;
1023 0 : aCtx.m_bOnlyLosslessCompression = mbUseLosslessCompression;
1024 0 : aCtx.m_nJPEGQuality = mnQuality;
1025 :
1026 :
1027 0 : basegfx::B2DRectangle aB2DRect( aPageRect.Left(), aPageRect.Top(), aPageRect.Right(), aPageRect.Bottom() );
1028 0 : rWriter.SetClipRegion( basegfx::B2DPolyPolygon( basegfx::tools::createPolygonFromRect( aB2DRect ) ) );
1029 :
1030 0 : rWriter.PlayMetafile( aMtf, aCtx, &rPDFExtOutDevData );
1031 :
1032 0 : rPDFExtOutDevData.ResetSyncData();
1033 :
1034 0 : if( mbWatermark )
1035 0 : ImplWriteWatermark( rWriter, aSizePDF );
1036 :
1037 0 : return bRet;
1038 : }
1039 :
1040 :
1041 :
1042 0 : void PDFExport::ImplWriteWatermark( PDFWriter& rWriter, const Size& rPageSize )
1043 : {
1044 0 : OUString aText( "Watermark" );
1045 0 : Font aFont( OUString( "Helvetica" ), Size( 0, 3*rPageSize.Height()/4 ) );
1046 0 : aFont.SetItalic( ITALIC_NONE );
1047 0 : aFont.SetWidthType( WIDTH_NORMAL );
1048 0 : aFont.SetWeight( WEIGHT_NORMAL );
1049 0 : aFont.SetAlign( ALIGN_BOTTOM );
1050 0 : long nTextWidth = rPageSize.Width();
1051 0 : if( rPageSize.Width() < rPageSize.Height() )
1052 : {
1053 0 : nTextWidth = rPageSize.Height();
1054 0 : aFont.SetOrientation( 2700 );
1055 : }
1056 :
1057 0 : if( ! ( maWatermark >>= aText ) )
1058 : {
1059 : // more complicated watermark ?
1060 : }
1061 :
1062 : // adjust font height for text to fit
1063 0 : OutputDevice* pDev = rWriter.GetReferenceDevice();
1064 0 : pDev->Push( PUSH_ALL );
1065 0 : pDev->SetFont( aFont );
1066 0 : pDev->SetMapMode( MapMode( MAP_POINT ) );
1067 0 : int w = 0;
1068 0 : while( ( w = pDev->GetTextWidth( aText ) ) > nTextWidth )
1069 : {
1070 0 : long nNewHeight = aFont.GetHeight() * nTextWidth / w;
1071 0 : if( nNewHeight == aFont.GetHeight() )
1072 : {
1073 0 : nNewHeight--;
1074 0 : if( nNewHeight <= 0 )
1075 0 : break;
1076 : }
1077 0 : aFont.SetHeight( nNewHeight );
1078 0 : pDev->SetFont( aFont );
1079 : }
1080 0 : long nTextHeight = pDev->GetTextHeight();
1081 : // leave some maneuvering room for rounding issues, also
1082 : // some fonts go a little outside ascent/descent
1083 0 : nTextHeight += nTextHeight/20;
1084 0 : pDev->Pop();
1085 :
1086 0 : rWriter.Push( PUSH_ALL );
1087 0 : rWriter.SetMapMode( MapMode( MAP_POINT ) );
1088 0 : rWriter.SetFont( aFont );
1089 0 : rWriter.SetTextColor( COL_LIGHTGREEN );
1090 0 : Point aTextPoint;
1091 0 : Rectangle aTextRect;
1092 0 : if( rPageSize.Width() > rPageSize.Height() )
1093 : {
1094 0 : aTextPoint = Point( (rPageSize.Width()-w)/2,
1095 0 : rPageSize.Height()-(rPageSize.Height()-nTextHeight)/2 );
1096 0 : aTextRect = Rectangle( Point( (rPageSize.Width()-w)/2,
1097 0 : (rPageSize.Height()-nTextHeight)/2 ),
1098 0 : Size( w, nTextHeight ) );
1099 : }
1100 : else
1101 : {
1102 0 : aTextPoint = Point( (rPageSize.Width()-nTextHeight)/2,
1103 0 : (rPageSize.Height()-w)/2 );
1104 0 : aTextRect = Rectangle( aTextPoint, Size( nTextHeight, w ) );
1105 : }
1106 0 : rWriter.SetClipRegion();
1107 0 : rWriter.BeginTransparencyGroup();
1108 0 : rWriter.DrawText( aTextPoint, aText );
1109 0 : rWriter.EndTransparencyGroup( aTextRect, 50 );
1110 0 : rWriter.Pop();
1111 0 : }
1112 :
1113 :
1114 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|