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