LibreOffice Module svx (master)  1
UnoGraphicExporter.cxx
Go to the documentation of this file.
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 #include <vector>
21 #include <com/sun/star/io/XOutputStream.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XChild.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/drawing/XShape.hpp>
27 #include <com/sun/star/drawing/XDrawPage.hpp>
28 #include <com/sun/star/drawing/XGraphicExportFilter.hpp>
29 #include <com/sun/star/graphic/XGraphic.hpp>
30 #include <com/sun/star/graphic/XGraphicRenderer.hpp>
31 #include <com/sun/star/task/XStatusIndicator.hpp>
32 #include <com/sun/star/task/XInteractionHandler.hpp>
33 #include <com/sun/star/task/XInteractionContinuation.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 
36 #include <tools/debug.hxx>
37 #include <tools/diagnose_ex.h>
38 #include <tools/urlobj.hxx>
41 #include <com/sun/star/drawing/GraphicFilterRequest.hpp>
42 #include <com/sun/star/util/URL.hpp>
43 #include <cppuhelper/implbase.hxx>
45 #include <vcl/metaact.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/virdev.hxx>
48 #include <svl/outstrm.hxx>
53 #include <editeng/numitem.hxx>
54 #include <svx/svdograf.hxx>
55 #include <svx/xoutbmp.hxx>
56 #include <vcl/graphicfilter.hxx>
57 #include <svx/svdpage.hxx>
58 #include <svx/svdmodel.hxx>
59 #include <svx/fmview.hxx>
60 #include <svx/fmmodel.hxx>
61 #include <svx/unopage.hxx>
62 #include <svx/svdoutl.hxx>
63 #include <svx/xlineit0.hxx>
64 #include <editeng/flditem.hxx>
68 #include <comphelper/sequence.hxx>
69 #include "UnoGraphicExporter.hxx"
70 #include <memory>
71 
72 #define MAX_EXT_PIX 2048
73 
74 using namespace ::comphelper;
75 using namespace ::cppu;
76 using namespace ::com::sun::star;
77 using namespace ::com::sun::star::uno;
78 using namespace ::com::sun::star::util;
79 using namespace ::com::sun::star::container;
80 using namespace ::com::sun::star::drawing;
81 using namespace ::com::sun::star::lang;
82 using namespace ::com::sun::star::document;
83 using namespace ::com::sun::star::beans;
84 using namespace ::com::sun::star::task;
85 
86 // #i102251#
87 #include <editeng/editstat.hxx>
88 
89 namespace {
90 
91  struct ExportSettings
92  {
93  OUString maFilterName;
94  OUString maMediaType;
95  URL maURL;
96  css::uno::Reference< css::io::XOutputStream > mxOutputStream;
97  css::uno::Reference< css::graphic::XGraphicRenderer > mxGraphicRenderer;
98  css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator;
99  css::uno::Reference< css::task::XInteractionHandler > mxInteractionHandler;
100 
101  sal_Int32 mnWidth;
102  sal_Int32 mnHeight;
103  bool mbExportOnlyBackground;
104  bool mbScrollText;
105  bool mbUseHighContrast;
106  bool mbTranslucent;
107 
108  Sequence< PropertyValue > maFilterData;
109 
110  Fraction maScaleX;
111  Fraction maScaleY;
112 
113  TriState meAntiAliasing = TRISTATE_INDET;
114 
115  explicit ExportSettings(const SdrModel* pSdrModel);
116  };
117 
118  ExportSettings::ExportSettings(const SdrModel* pSdrModel)
119  : mnWidth( 0 )
120  ,mnHeight( 0 )
121  ,mbExportOnlyBackground( false )
122  ,mbScrollText( false )
123  ,mbUseHighContrast( false )
124  ,mbTranslucent( false )
125  ,maScaleX( 1, 1 )
126  ,maScaleY( 1, 1 )
127  {
128  if (pSdrModel)
129  {
130  maScaleX = pSdrModel->GetScaleFraction();
131  maScaleY = pSdrModel->GetScaleFraction();
132  }
133  }
134 
139  class GraphicExporter : public WeakImplHelper< XGraphicExportFilter, XServiceInfo >
140  {
141  public:
142  GraphicExporter();
143 
144  // XFilter
145  virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) override;
146  virtual void SAL_CALL cancel( ) override;
147 
148  // XExporter
149  virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) override;
150 
151  // XServiceInfo
152  virtual OUString SAL_CALL getImplementationName( ) override;
153  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
154  virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
155 
156  // XMimeTypeInfo
157  virtual sal_Bool SAL_CALL supportsMimeType( const OUString& MimeTypeName ) override;
158  virtual Sequence< OUString > SAL_CALL getSupportedMimeTypeNames( ) override;
159 
160  VclPtr<VirtualDevice> CreatePageVDev( SdrPage* pPage, tools::Long nWidthPixel, tools::Long nHeightPixel ) const;
161 
162  DECL_LINK( CalcFieldValueHdl, EditFieldInfo*, void );
163 
164  void ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings );
165  bool GetGraphic( ExportSettings const & rSettings, Graphic& aGraphic, bool bVectorType );
166 
167  private:
168  Reference< XShape > mxShape;
169  Reference< XDrawPage > mxPage;
170  Reference< XShapes > mxShapes;
172 
173  SvxDrawPage* mpUnoPage;
174 
175  Link<EditFieldInfo*,void> maOldCalcFieldValueHdl;
176  sal_Int32 mnPageNumber;
177  SdrPage* mpCurrentPage;
178  SdrModel* mpDoc;
179  };
180 
183  BitmapEx GetBitmapFromMetaFile( const GDIMetaFile& rMtf, const Size* pSize )
184  {
185  // use new primitive conversion tooling
186  basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0));
187  sal_uInt32 nMaximumQuadraticPixels(500000);
188 
189  if(pSize)
190  {
191  // use 100th mm for primitive bitmap converter tool, input is pixel
192  // use a real OutDev to get the correct DPI, the static LogicToLogic assumes 72dpi which is wrong (!)
193  const Size aSize100th(Application::GetDefaultDevice()->PixelToLogic(*pSize, MapMode(MapUnit::Map100thMM)));
194 
195  aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height()));
196 
197  // when explicitly pixels are requested from the GraphicExporter, use a *very* high limit
198  // of 16gb (4096x4096 pixels), else use the default for the converters
199  nMaximumQuadraticPixels = std::min(sal_uInt32(4096 * 4096), sal_uInt32(pSize->Width() * pSize->Height()));
200  }
201  else
202  {
203  // use 100th mm for primitive bitmap converter tool
204  const Size aSize100th(OutputDevice::LogicToLogic(rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)));
205 
206  aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height()));
207  }
208 
209  return convertMetafileToBitmapEx(rMtf, aRange, nMaximumQuadraticPixels);
210  }
211 
212  Size* CalcSize( sal_Int32 nWidth, sal_Int32 nHeight, const Size& aBoundSize, Size& aOutSize )
213  {
214  if( (nWidth == 0) && (nHeight == 0) )
215  return nullptr;
216 
217  if( (nWidth == 0) && (nHeight != 0) && (aBoundSize.Height() != 0) )
218  {
219  nWidth = ( nHeight * aBoundSize.Width() ) / aBoundSize.Height();
220  }
221  else if( (nWidth != 0) && (nHeight == 0) && (aBoundSize.Width() != 0) )
222  {
223  nHeight = ( nWidth * aBoundSize.Height() ) / aBoundSize.Width();
224  }
225 
226  aOutSize.setWidth( nWidth );
227  aOutSize.setHeight( nHeight );
228 
229  return &aOutSize;
230  }
231 
232 class ImplExportCheckVisisbilityRedirector : public sdr::contact::ViewObjectContactRedirector
233 {
234 public:
235  explicit ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage );
236 
238  const sdr::contact::ViewObjectContact& rOriginal,
239  const sdr::contact::DisplayInfo& rDisplayInfo,
241 
242 private:
243  SdrPage* mpCurrentPage;
244 };
245 
246 ImplExportCheckVisisbilityRedirector::ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage )
247 : mpCurrentPage( pCurrentPage )
248 {
249 }
250 
251 void ImplExportCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence(
252  const sdr::contact::ViewObjectContact& rOriginal,
253  const sdr::contact::DisplayInfo& rDisplayInfo,
255 {
257 
258  if(pObject)
259  {
260  SdrPage* pPage = mpCurrentPage;
261 
262  if(nullptr == pPage)
263  {
264  pPage = pObject->getSdrPageFromSdrObject();
265  }
266 
267  if( (pPage == nullptr) || pPage->checkVisibility(rOriginal, rDisplayInfo, false) )
268  {
270  }
271 
272  return;
273  }
274  else
275  {
276  // not an object, maybe a page
278  }
279 }
280 
281 GraphicExporter::GraphicExporter()
282 : mpUnoPage( nullptr ), mnPageNumber(-1), mpCurrentPage(nullptr), mpDoc( nullptr )
283 {
284 }
285 
286 IMPL_LINK(GraphicExporter, CalcFieldValueHdl, EditFieldInfo*, pInfo, void)
287 {
288  if( pInfo )
289  {
290  if( mpCurrentPage )
291  {
292  pInfo->SetSdrPage( mpCurrentPage );
293  }
294  else if( mnPageNumber != -1 )
295  {
296  const SvxFieldData* pField = pInfo->GetField().GetField();
297  if( dynamic_cast<const SvxPageField*>( pField) )
298  {
299  OUString aPageNumValue;
300  bool bUpper = false;
301 
302  switch(mpDoc->GetPageNumType())
303  {
304  case css::style::NumberingType::CHARS_UPPER_LETTER:
305  aPageNumValue += OUStringChar( sal_Unicode((mnPageNumber - 1) % 26 + 'A') );
306  break;
307  case css::style::NumberingType::CHARS_LOWER_LETTER:
308  aPageNumValue += OUStringChar( sal_Unicode((mnPageNumber - 1) % 26 + 'a') );
309  break;
310  case css::style::NumberingType::ROMAN_UPPER:
311  bUpper = true;
312  [[fallthrough]];
313  case css::style::NumberingType::ROMAN_LOWER:
314  aPageNumValue += SvxNumberFormat::CreateRomanString(mnPageNumber, bUpper);
315  break;
316  case css::style::NumberingType::NUMBER_NONE:
317  aPageNumValue = " ";
318  break;
319  default:
320  aPageNumValue += OUString::number( mnPageNumber );
321  }
322 
323  pInfo->SetRepresentation( aPageNumValue );
324 
325  return;
326  }
327  }
328  }
329 
330  maOldCalcFieldValueHdl.Call( pInfo );
331 
332  if( pInfo && mpCurrentPage )
333  pInfo->SetSdrPage( nullptr );
334 }
335 
340 VclPtr<VirtualDevice> GraphicExporter::CreatePageVDev( SdrPage* pPage, tools::Long nWidthPixel, tools::Long nHeightPixel ) const
341 {
343  MapMode aMM( MapUnit::Map100thMM );
344 
345  Point aPoint( 0, 0 );
346  Size aPageSize(pPage->GetSize());
347 
348  // use scaling?
349  if( nWidthPixel != 0 )
350  {
351  const Fraction aFrac( nWidthPixel, pVDev->LogicToPixel( aPageSize, aMM ).Width() );
352 
353  aMM.SetScaleX( aFrac );
354 
355  if( nHeightPixel == 0 )
356  aMM.SetScaleY( aFrac );
357  }
358 
359  if( nHeightPixel != 0 )
360  {
361  const Fraction aFrac( nHeightPixel, pVDev->LogicToPixel( aPageSize, aMM ).Height() );
362 
363  if( nWidthPixel == 0 )
364  aMM.SetScaleX( aFrac );
365 
366  aMM.SetScaleY( aFrac );
367  }
368 
369  pVDev->SetMapMode( aMM );
370  bool bSuccess(false);
371 
372  // #i122820# If available, use pixel size directly
373  if(nWidthPixel && nHeightPixel)
374  {
375  bSuccess = pVDev->SetOutputSizePixel(Size(nWidthPixel, nHeightPixel));
376  }
377  else
378  {
379  bSuccess = pVDev->SetOutputSize(aPageSize);
380  }
381 
382  if(bSuccess)
383  {
384  SdrView aView(*mpDoc, pVDev);
385 
386  aView.SetPageVisible( false );
387  aView.SetBordVisible( false );
388  aView.SetGridVisible( false );
389  aView.SetHlplVisible( false );
390  aView.SetGlueVisible( false );
391  aView.ShowSdrPage(pPage);
392 
393  vcl::Region aRegion (tools::Rectangle( aPoint, aPageSize ) );
394 
395  ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
396 
397  aView.CompleteRedraw(pVDev, aRegion, &aRedirector);
398  }
399  else
400  {
401  OSL_ENSURE(false, "Could not get a VirtualDevice of requested size (!)");
402  }
403 
404  return pVDev;
405 }
406 
407 void GraphicExporter::ParseSettings(const Sequence<PropertyValue>& rDescriptor,
408  ExportSettings& rSettings)
409 {
410  Sequence<PropertyValue> aDescriptor = rDescriptor;
411  if (aDescriptor.hasElements())
412  {
413  comphelper::SequenceAsHashMap aMap(aDescriptor);
414  Sequence<PropertyValue> aFilterData;
415  OUString aFilterOptions;
416  auto it = aMap.find("FilterData");
417  if (it != aMap.end())
418  {
419  it->second >>= aFilterData;
420  }
421  it = aMap.find("FilterOptions");
422  if (it != aMap.end())
423  {
424  it->second >>= aFilterOptions;
425  }
426  if (!aFilterData.hasElements() && !aFilterOptions.isEmpty())
427  {
428  // Allow setting filter data keys from the cmdline.
429  std::vector<PropertyValue> aData
430  = comphelper::JsonToPropertyValues(aFilterOptions.toUtf8());
431  aFilterData = comphelper::containerToSequence(aData);
432  if (aFilterData.hasElements())
433  {
434  aMap["FilterData"] <<= aFilterData;
435  aDescriptor = aMap.getAsConstPropertyValueList();
436  }
437  }
438  }
439 
440  for( const PropertyValue& rValue : aDescriptor )
441  {
442  if ( rValue.Name == "FilterName" )
443  {
444  rValue.Value >>= rSettings.maFilterName;
445  }
446  else if ( rValue.Name == "MediaType" )
447  {
448  rValue.Value >>= rSettings.maMediaType;
449  }
450  else if ( rValue.Name == "URL" )
451  {
452  if( !( rValue.Value >>= rSettings.maURL ) )
453  {
454  rValue.Value >>= rSettings.maURL.Complete;
455  }
456  }
457  else if ( rValue.Name == "OutputStream" )
458  {
459  rValue.Value >>= rSettings.mxOutputStream;
460  }
461  else if ( rValue.Name == "GraphicRenderer" )
462  {
463  rValue.Value >>= rSettings.mxGraphicRenderer;
464  }
465  else if ( rValue.Name == "StatusIndicator" )
466  {
467  rValue.Value >>= rSettings.mxStatusIndicator;
468  }
469  else if ( rValue.Name == "InteractionHandler" )
470  {
471  rValue.Value >>= rSettings.mxInteractionHandler;
472  }
473  else if( rValue.Name == "Width" ) // for compatibility reasons, deprecated
474  {
475  rValue.Value >>= rSettings.mnWidth;
476  }
477  else if( rValue.Name == "Height" ) // for compatibility reasons, deprecated
478  {
479  rValue.Value >>= rSettings.mnHeight;
480  }
481  else if( rValue.Name == "ExportOnlyBackground" ) // for compatibility reasons, deprecated
482  {
483  rValue.Value >>= rSettings.mbExportOnlyBackground;
484  }
485  else if ( rValue.Name == "FilterData" )
486  {
487  rValue.Value >>= rSettings.maFilterData;
488 
489  for( PropertyValue& rDataValue : asNonConstRange(rSettings.maFilterData) )
490  {
491  if ( rDataValue.Name == "Translucent" )
492  {
493  if ( !( rDataValue.Value >>= rSettings.mbTranslucent ) ) // SJ: TODO: The GIF Transparency is stored as int32 in
494  { // configuration files, this has to be changed to boolean
495  sal_Int32 nTranslucent = 0;
496  if ( rDataValue.Value >>= nTranslucent )
497  rSettings.mbTranslucent = nTranslucent != 0;
498  }
499  }
500  else if ( rDataValue.Name == "PixelWidth" )
501  {
502  rDataValue.Value >>= rSettings.mnWidth;
503  }
504  else if ( rDataValue.Name == "PixelHeight" )
505  {
506  rDataValue.Value >>= rSettings.mnHeight;
507  }
508  else if( rDataValue.Name == "Width" ) // for compatibility reasons, deprecated
509  {
510  rDataValue.Value >>= rSettings.mnWidth;
511  rDataValue.Name = "PixelWidth";
512  }
513  else if( rDataValue.Name == "Height" ) // for compatibility reasons, deprecated
514  {
515  rDataValue.Value >>= rSettings.mnHeight;
516  rDataValue.Name = "PixelHeight";
517  }
518  else if ( rDataValue.Name == "ExportOnlyBackground" )
519  {
520  rDataValue.Value >>= rSettings.mbExportOnlyBackground;
521  }
522  else if ( rDataValue.Name == "HighContrast" )
523  {
524  rDataValue.Value >>= rSettings.mbUseHighContrast;
525  }
526  else if ( rDataValue.Name == "PageNumber" )
527  {
528  rDataValue.Value >>= mnPageNumber;
529  }
530  else if ( rDataValue.Name == "ScrollText" )
531  {
532  // #110496# Read flag solitary scroll text metafile
533  rDataValue.Value >>= rSettings.mbScrollText;
534  }
535  else if ( rDataValue.Name == "CurrentPage" )
536  {
537  Reference< XDrawPage > xPage;
538  rDataValue.Value >>= xPage;
539  if( xPage.is() )
540  {
541  SvxDrawPage* pUnoPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xPage );
542  if( pUnoPage && pUnoPage->GetSdrPage() )
543  mpCurrentPage = pUnoPage->GetSdrPage();
544  }
545  }
546  else if ( rDataValue.Name == "ScaleXNumerator" )
547  {
548  sal_Int32 nVal = 1;
549  if( rDataValue.Value >>= nVal )
550  rSettings.maScaleX = Fraction( nVal, rSettings.maScaleX.GetDenominator() );
551  }
552  else if ( rDataValue.Name == "ScaleXDenominator" )
553  {
554  sal_Int32 nVal = 1;
555  if( rDataValue.Value >>= nVal )
556  rSettings.maScaleX = Fraction( rSettings.maScaleX.GetNumerator(), nVal );
557  }
558  else if ( rDataValue.Name == "ScaleYNumerator" )
559  {
560  sal_Int32 nVal = 1;
561  if( rDataValue.Value >>= nVal )
562  rSettings.maScaleY = Fraction( nVal, rSettings.maScaleY.GetDenominator() );
563  }
564  else if ( rDataValue.Name == "ScaleYDenominator" )
565  {
566  sal_Int32 nVal = 1;
567  if( rDataValue.Value >>= nVal )
568  rSettings.maScaleY = Fraction( rSettings.maScaleY.GetNumerator(), nVal );
569  }
570  else if (rDataValue.Name == "AntiAliasing")
571  {
572  bool bAntiAliasing;
573  if (rDataValue.Value >>= bAntiAliasing)
574  rSettings.meAntiAliasing = bAntiAliasing ? TRISTATE_TRUE : TRISTATE_FALSE;
575  }
576  }
577  }
578  }
579 
580  // putting the StatusIndicator that we got from the MediaDescriptor into our local FilterData copy
581  if ( rSettings.mxStatusIndicator.is() )
582  {
583  int i = rSettings.maFilterData.getLength();
584  rSettings.maFilterData.realloc( i + 1 );
585  auto pFilterData = rSettings.maFilterData.getArray();
586  pFilterData[ i ].Name = "StatusIndicator";
587  pFilterData[ i ].Value <<= rSettings.mxStatusIndicator;
588  }
589 }
590 
591 bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGraphic, bool bVectorType )
592 {
593  if( !mpDoc || !mpUnoPage )
594  return false;
595 
596  SdrPage* pPage = mpUnoPage->GetSdrPage();
597  if( !pPage )
598  return false;
599 
601  const MapMode aMap( mpDoc->GetScaleUnit(), Point(), rSettings.maScaleX, rSettings.maScaleY );
602 
603  SdrOutliner& rOutl=mpDoc->GetDrawOutliner();
604  maOldCalcFieldValueHdl = rOutl.GetCalcFieldValueHdl();
605  rOutl.SetCalcFieldValueHdl( LINK(this, GraphicExporter, CalcFieldValueHdl) );
606  rOutl.SetBackgroundColor( pPage->GetPageBackgroundColor() );
607 
608  // #i102251#
609  const EEControlBits nOldCntrl(rOutl.GetControlWord());
610  EEControlBits nCntrl = nOldCntrl & ~EEControlBits::ONLINESPELLING;
611  rOutl.SetControlWord(nCntrl);
612 
613  SdrObject* pTempBackgroundShape = nullptr;
614  std::vector< SdrObject* > aShapes;
615  bool bRet = true;
616 
617  // export complete page?
618  if ( !mxShape.is() )
619  {
620  if( rSettings.mbExportOnlyBackground )
621  {
622  const SdrPageProperties* pCorrectProperties = pPage->getCorrectSdrPageProperties();
623 
624  if(pCorrectProperties)
625  {
626  pTempBackgroundShape = new SdrRectObj(
627  *mpDoc,
628  tools::Rectangle(Point(0,0), pPage->GetSize()));
629  pTempBackgroundShape->SetMergedItemSet(pCorrectProperties->GetItemSet());
630  pTempBackgroundShape->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
631  pTempBackgroundShape->NbcSetStyleSheet(pCorrectProperties->GetStyleSheet(), true);
632  aShapes.push_back(pTempBackgroundShape);
633  }
634  }
635  else
636  {
637  const Size aSize( pPage->GetSize() );
638 
639  // generate a bitmap to convert it to a pixel format.
640  // For gif pictures there can also be a vector format used (bTranslucent)
641  if ( !bVectorType && !rSettings.mbTranslucent )
642  {
643  tools::Long nWidthPix = 0;
644  tools::Long nHeightPix = 0;
645  if ( rSettings.mnWidth > 0 && rSettings.mnHeight > 0 )
646  {
647  nWidthPix = rSettings.mnWidth;
648  nHeightPix = rSettings.mnHeight;
649  }
650  else
651  {
652  const Size aSizePix( Application::GetDefaultDevice()->LogicToPixel( aSize, aMap ) );
653  if (aSizePix.Width() > MAX_EXT_PIX || aSizePix.Height() > MAX_EXT_PIX)
654  {
655  if (aSizePix.Width() > MAX_EXT_PIX)
656  nWidthPix = MAX_EXT_PIX;
657  else
658  nWidthPix = aSizePix.Width();
659  if (aSizePix.Height() > MAX_EXT_PIX)
660  nHeightPix = MAX_EXT_PIX;
661  else
662  nHeightPix = aSizePix.Height();
663 
664  double fWidthDif = static_cast<double>(aSizePix.Width()) / nWidthPix;
665  double fHeightDif = static_cast<double>(aSizePix.Height()) / nHeightPix;
666 
667  if (fWidthDif > fHeightDif)
668  nHeightPix = static_cast<tools::Long>(aSizePix.Height() / fWidthDif);
669  else
670  nWidthPix = static_cast<tools::Long>(aSizePix.Width() / fHeightDif);
671  }
672  else
673  {
674  nWidthPix = aSizePix.Width();
675  nHeightPix = aSizePix.Height();
676  }
677  }
678 
679  std::unique_ptr<SdrView> xLocalView;
680 
681  if (FmFormModel* pFormModel = dynamic_cast<FmFormModel*>(mpDoc))
682  {
683  xLocalView.reset(new FmFormView(*pFormModel, aVDev));
684  }
685  else
686  {
687  xLocalView.reset(new SdrView(*mpDoc, aVDev));
688  }
689 
690  ScopedVclPtr<VirtualDevice> pVDev(CreatePageVDev( pPage, nWidthPix, nHeightPix ));
691 
692  if( pVDev )
693  {
694  aGraphic = pVDev->GetBitmapEx( Point(), pVDev->GetOutputSize() );
695  aGraphic.SetPrefMapMode( aMap );
696  aGraphic.SetPrefSize( aSize );
697  }
698  }
699  // create a metafile to export a vector format
700  else
701  {
702  GDIMetaFile aMtf;
703 
704  aVDev->SetMapMode( aMap );
705  if( rSettings.mbUseHighContrast )
706  aVDev->SetDrawMode( aVDev->GetDrawMode() | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient );
707  aVDev->EnableOutput( false );
708  aMtf.Record( aVDev );
709  Size aNewSize;
710 
711  // create a view
712  std::unique_ptr< SdrView > pView;
713 
714  if (FmFormModel *pFormModel = dynamic_cast<FmFormModel*>(mpDoc))
715  {
716  pView.reset(new FmFormView(*pFormModel, aVDev));
717  }
718  else
719  {
720  pView.reset(new SdrView(*mpDoc, aVDev));
721  }
722 
723  pView->SetBordVisible( false );
724  pView->SetPageVisible( false );
725  pView->ShowSdrPage( pPage );
726 
727  // tdf#96922 completely deactivate EditView PageVisualization, including
728  // PageBackground (formerly 'wiese').
729  pView->SetPagePaintingAllowed(false);
730 
731  const Point aNewOrg( pPage->GetLeftBorder(), pPage->GetUpperBorder() );
732  aNewSize = Size( aSize.Width() - pPage->GetLeftBorder() - pPage->GetRightBorder(),
733  aSize.Height() - pPage->GetUpperBorder() - pPage->GetLowerBorder() );
734  const tools::Rectangle aClipRect( aNewOrg, aNewSize );
735  MapMode aVMap( aMap );
736 
737  aVDev->Push();
738  aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
739  aVDev->SetRelativeMapMode( aVMap );
740  aVDev->IntersectClipRegion( aClipRect );
741 
742  // Use new StandardCheckVisisbilityRedirector
743  ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
744 
745  pView->CompleteRedraw(aVDev, vcl::Region(tools::Rectangle(aNewOrg, aNewSize)), &aRedirector);
746 
747  aVDev->Pop();
748 
749  aMtf.Stop();
750  aMtf.WindStart();
751  aMtf.SetPrefMapMode( aMap );
752  aMtf.SetPrefSize( aNewSize );
753 
754  // AW: Here the current version was filtering out the MetaActionType::CLIPREGIONs
755  // from the metafile. I asked some other developers why this was done, but no
756  // one knew a direct reason. Since it's in for long time, it may be an old
757  // piece of code. MetaFiles save and load ClipRegions with polygons with preserving
758  // the polygons, so a resolution-independent roundtrip is supported. Removed this
759  // code since it destroys some MetaFiles where ClipRegions are used. Anyways,
760  // just filtering them out is a hack, at least the encapsulated content would need
761  // to be clipped geometrically.
762  aGraphic = Graphic(aMtf);
763 
764  pView->HideSdrPage();
765 
766  if( rSettings.mbTranslucent )
767  {
768  Size aOutSize;
769  aGraphic = GetBitmapFromMetaFile( aGraphic.GetGDIMetaFile(), CalcSize( rSettings.mnWidth, rSettings.mnHeight, aNewSize, aOutSize ) );
770  }
771  }
772  }
773  }
774 
775  // export only single shape or shape collection
776  else
777  {
778  // build list of SdrObject
779  if( mxShapes.is() )
780  {
781  Reference< XShape > xShape;
782  const sal_Int32 nCount = mxShapes->getCount();
783 
784  for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
785  {
786  mxShapes->getByIndex( nIndex ) >>= xShape;
788  if( pObj )
789  aShapes.push_back( pObj );
790  }
791  }
792  else
793  {
794  // only one shape
796  if( pObj )
797  aShapes.push_back( pObj );
798  }
799 
800  if( aShapes.empty() )
801  bRet = false;
802  }
803 
804  if( bRet && !aShapes.empty() )
805  {
806  // special treatment for only one SdrGrafObj that has text
807  bool bSingleGraphic = false;
808 
809  if( 1 == aShapes.size() )
810  {
811  if( !bVectorType )
812  {
813  if( auto pGrafObj = dynamic_cast<const SdrGrafObj*>(aShapes.front()) )
814  if (pGrafObj->HasText() )
815  {
816  aGraphic = pGrafObj->GetTransformedGraphic();
817  if ( aGraphic.GetType() == GraphicType::Bitmap )
818  {
819  Size aSizePixel( aGraphic.GetSizePixel() );
820  if( rSettings.mnWidth && rSettings.mnHeight &&
821  ( ( rSettings.mnWidth != aSizePixel.Width() ) ||
822  ( rSettings.mnHeight != aSizePixel.Height() ) ) )
823  {
824  BitmapEx aBmpEx( aGraphic.GetBitmapEx() );
825  // export: use highest quality
826  aBmpEx.Scale( Size( rSettings.mnWidth, rSettings.mnHeight ), BmpScaleFlag::Lanczos );
827  aGraphic = aBmpEx;
828  }
829 
830  // #118804# only accept for bitmap graphics, else the
831  // conversion to bitmap will happen anywhere without size control
832  // as evtl. defined in rSettings.mnWidth/mnHeight
833  bSingleGraphic = true;
834  }
835  }
836  }
837  else if( rSettings.mbScrollText )
838  {
839  SdrObject* pObj = aShapes.front();
840  auto pTextObj = dynamic_cast<SdrTextObj*>( pObj);
841  if( pTextObj && pTextObj->HasText() )
842  {
843  tools::Rectangle aScrollRectangle;
844  tools::Rectangle aPaintRectangle;
845 
846  const std::unique_ptr< GDIMetaFile > pMtf(
847  pTextObj->GetTextScrollMetaFileAndRectangle(
848  aScrollRectangle, aPaintRectangle ) );
849 
850  // take the larger one of the two rectangles (that
851  // should be the bound rect of the retrieved
852  // metafile)
853  tools::Rectangle aTextRect;
854 
855  if( aScrollRectangle.Contains( aPaintRectangle ) )
856  aTextRect = aScrollRectangle;
857  else
858  aTextRect = aPaintRectangle;
859 
860  // setup pref size and mapmode
861  pMtf->SetPrefSize( aTextRect.GetSize() );
862 
863  // set actual origin (mtf is at actual shape
864  // output position)
865  MapMode aLocalMapMode( aMap );
866  aLocalMapMode.SetOrigin(
867  Point( -aPaintRectangle.Left(),
868  -aPaintRectangle.Top() ) );
869  pMtf->SetPrefMapMode( aLocalMapMode );
870 
871  pMtf->AddAction( new MetaCommentAction(
872  "XTEXT_SCROLLRECT", 0,
873  reinterpret_cast<sal_uInt8 const*>(&aScrollRectangle),
874  sizeof( tools::Rectangle ) ) );
875  pMtf->AddAction( new MetaCommentAction(
876  "XTEXT_PAINTRECT", 0,
877  reinterpret_cast<sal_uInt8 const*>(&aPaintRectangle),
878  sizeof( tools::Rectangle ) ) );
879 
880  aGraphic = Graphic( *pMtf );
881 
882  bSingleGraphic = true;
883  }
884  }
885  }
886 
887  if( !bSingleGraphic )
888  {
889  // create a metafile for all shapes
891 
892  // calculate bound rect for all shapes
893  // tdf#126319 I did not convert all rendering to primities,
894  // that would be to much for this fix. But I did so for the
895  // range calculation to get a valid high quality range.
896  // Based on that the conversion is reliable. With the BoundRect
897  // fetched from the Metafile it was just not possible to get the
898  // examples from the task handled in a way to fit all cases -
899  // due to bad-quality range data from it.
900  basegfx::B2DRange aBound;
901  const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
902 
903  {
904  for( SdrObject* pObj : aShapes )
905  {
907  pObj->GetViewContact().getViewIndependentPrimitive2DContainer(aSequence);
908  aBound.expand(aSequence.getB2DRange(aViewInformation2D));
909  }
910  }
911 
912  aOut->EnableOutput( false );
913  aOut->SetMapMode( aMap );
914  if( rSettings.mbUseHighContrast )
915  aOut->SetDrawMode( aOut->GetDrawMode() | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient );
916 
917  GDIMetaFile aMtf;
918  aMtf.Clear();
919  aMtf.Record( aOut );
920 
921  MapMode aOutMap( aMap );
922  const Size aOnePixelInMtf(
923  Application::GetDefaultDevice()->PixelToLogic(
924  Size(1, 1),
925  aMap));
926  const Size aHalfPixelInMtf(
927  (aOnePixelInMtf.getWidth() + 1) / 2,
928  (aOnePixelInMtf.getHeight() + 1) / 2);
929 
930  // tdf#126319 Immediately add needed offset to create metafile,
931  // that avoids to do it later by Metafile::Move what would be expensive
932  aOutMap.SetOrigin(
933  Point(
934  basegfx::fround(-aBound.getMinX() - aHalfPixelInMtf.getWidth()),
935  basegfx::fround(-aBound.getMinY() - aHalfPixelInMtf.getHeight()) ) );
936  aOut->SetRelativeMapMode( aOutMap );
937 
938  sdr::contact::DisplayInfo aDisplayInfo;
939 
940  if(mpCurrentPage)
941  {
942  if(mpCurrentPage->TRG_HasMasterPage() && pPage->IsMasterPage())
943  {
944  // MasterPage is processed as another page's SubContent
945  aDisplayInfo.SetProcessLayers(mpCurrentPage->TRG_GetMasterPageVisibleLayers());
946  aDisplayInfo.SetSubContentActive(true);
947  }
948  }
949 
950  if(!aShapes.empty())
951  {
952  // more effective way to paint a vector of SdrObjects. Hand over the processed page
953  // to have it in the
954  ImplExportCheckVisisbilityRedirector aCheckVisibilityRedirector(mpCurrentPage);
955  sdr::contact::ObjectContactOfObjListPainter aMultiObjectPainter(*aOut, std::move(aShapes), mpCurrentPage);
956  aMultiObjectPainter.SetViewObjectContactRedirector(&aCheckVisibilityRedirector);
957 
958  aMultiObjectPainter.ProcessDisplay(aDisplayInfo);
959  }
960 
961  aMtf.Stop();
962  aMtf.WindStart();
963 
964  // tdf#126319 Immediately add needed size to target's PrefSize
965  const Size aBoundSize(
966  basegfx::fround(aBound.getWidth() + aHalfPixelInMtf.getWidth()),
967  basegfx::fround(aBound.getHeight() + aHalfPixelInMtf.getHeight()));
968 
969  aMtf.SetPrefMapMode( aMap );
970  aMtf.SetPrefSize( aBoundSize );
971 
972  if( !bVectorType )
973  {
974  Size aOutSize;
975  aGraphic = GetBitmapFromMetaFile( aMtf, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aBoundSize, aOutSize ) );
976  }
977  else
978  {
979  aGraphic = aMtf;
980  }
981  }
982  }
983 
984  if(pTempBackgroundShape)
985  {
986  SdrObject::Free(pTempBackgroundShape);
987  }
988 
989  rOutl.SetCalcFieldValueHdl( maOldCalcFieldValueHdl );
990 
991  // #i102251#
992  rOutl.SetControlWord(nOldCntrl);
993 
994  return bRet;
995 
996 }
997 
998 // XFilter
999 sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDescriptor )
1000 {
1001  ::SolarMutexGuard aGuard;
1002 
1003  if( maGraphic.IsNone() && nullptr == mpUnoPage )
1004  return false;
1005 
1006  if( maGraphic.IsNone() && ( nullptr == mpUnoPage->GetSdrPage() || nullptr == mpDoc ) )
1007  return false;
1008 
1010 
1011  // get the arguments from the descriptor
1012  ExportSettings aSettings(mpDoc);
1013  ParseSettings(aDescriptor, aSettings);
1014 
1015  const sal_uInt16 nFilter = !aSettings.maMediaType.isEmpty()
1016  ? rFilter.GetExportFormatNumberForMediaType( aSettings.maMediaType )
1017  : rFilter.GetExportFormatNumberForShortName( aSettings.maFilterName );
1018  bool bVectorType = !rFilter.IsExportPixelFormat( nFilter );
1019 
1020  // create the output stuff
1021  Graphic aGraphic = maGraphic;
1022 
1023  ErrCode nStatus = ERRCODE_NONE;
1024  if (maGraphic.IsNone())
1025  {
1026  bool bAntiAliasing = SvtOptionsDrawinglayer::IsAntiAliasing();
1027  AllSettings aAllSettings = Application::GetSettings();
1028  StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
1029  bool bUseFontAAFromSystem = aStyleSettings.GetUseFontAAFromSystem();
1030  if (aSettings.meAntiAliasing != TRISTATE_INDET)
1031  {
1032  // This is safe to do globally as we own the solar mutex.
1033  SvtOptionsDrawinglayer::SetAntiAliasing(aSettings.meAntiAliasing == TRISTATE_TRUE, /*bTemporary*/true);
1034  // Opt in to have AA affect font rendering as well.
1035  aStyleSettings.SetUseFontAAFromSystem(false);
1036  aAllSettings.SetStyleSettings(aStyleSettings);
1037  Application::SetSettings(aAllSettings);
1038  }
1039  nStatus = GetGraphic( aSettings, aGraphic, bVectorType ) ? ERRCODE_NONE : ERRCODE_GRFILTER_FILTERERROR;
1040  if (aSettings.meAntiAliasing != TRISTATE_INDET)
1041  {
1042  SvtOptionsDrawinglayer::SetAntiAliasing(bAntiAliasing, /*bTemporary*/true);
1043  aStyleSettings.SetUseFontAAFromSystem(bUseFontAAFromSystem);
1044  aAllSettings.SetStyleSettings(aStyleSettings);
1045  Application::SetSettings(aAllSettings);
1046  }
1047  }
1048 
1049  if( nStatus == ERRCODE_NONE )
1050  {
1051  // export graphic only if it has a size
1052  const Size aGraphSize( aGraphic.GetPrefSize() );
1053  if ( aGraphSize.IsEmpty() )
1054  {
1055  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1056  }
1057  else
1058  {
1059  // now we have a graphic, so export it
1060  if( aSettings.mxGraphicRenderer.is() )
1061  {
1062  // render graphic directly into given renderer
1063  aSettings.mxGraphicRenderer->render( aGraphic.GetXGraphic() );
1064  }
1065  else if( aSettings.mxOutputStream.is() )
1066  {
1067  // TODO: Either utilize optional XSeekable functionality for the
1068  // SvOutputStream, or adapt the graphic filter to not seek anymore.
1069  SvMemoryStream aStream( 1024, 1024 );
1070 
1071  nStatus = rFilter.ExportGraphic( aGraphic, u"", aStream, nFilter, &aSettings.maFilterData );
1072 
1073  // copy temp stream to XOutputStream
1074  SvOutputStream aOutputStream( aSettings.mxOutputStream );
1075  aStream.Seek(0);
1076  aOutputStream.WriteStream( aStream );
1077  }
1078  else
1079  {
1080  INetURLObject aURLObject( aSettings.maURL.Complete );
1081  DBG_ASSERT( aURLObject.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
1082 
1083  nStatus = XOutBitmap::ExportGraphic( aGraphic, aURLObject, rFilter, nFilter, &aSettings.maFilterData );
1084  }
1085  }
1086  }
1087 
1088  if ( aSettings.mxInteractionHandler.is() && ( nStatus != ERRCODE_NONE ) )
1089  {
1090  Any aInteraction;
1091  Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations{
1092  new ::comphelper::OInteractionApprove()
1093  };
1094 
1095  GraphicFilterRequest aErrorCode;
1096  aErrorCode.ErrCode = sal_uInt32(nStatus);
1097  aInteraction <<= aErrorCode;
1098  aSettings.mxInteractionHandler->handle( framework::InteractionRequest::CreateRequest( aInteraction, lContinuations ) );
1099  }
1100  return nStatus == ERRCODE_NONE;
1101 }
1102 
1103 void SAL_CALL GraphicExporter::cancel()
1104 {
1105 }
1106 
1107 // XExporter
1108 
1110 void SAL_CALL GraphicExporter::setSourceDocument( const Reference< lang::XComponent >& xComponent )
1111 {
1112  ::SolarMutexGuard aGuard;
1113 
1114  mxShapes = nullptr;
1115  mpUnoPage = nullptr;
1116 
1117  try
1118  {
1119  // any break inside this one loop while will throw an IllegalArgumentException
1120  do
1121  {
1122  mxPage.set( xComponent, UNO_QUERY );
1123  mxShapes.set( xComponent, UNO_QUERY );
1124  mxShape.set( xComponent, UNO_QUERY );
1125 
1126  // Step 1: try a generic XShapes
1127  if( !mxPage.is() && !mxShape.is() && mxShapes.is() )
1128  {
1129  // we do not support empty shape collections
1130  if( 0 == mxShapes->getCount() )
1131  break;
1132 
1133  // get first shape to detect corresponding page and model
1134  mxShapes->getByIndex(0) >>= mxShape;
1135  }
1136  else
1137  {
1138  mxShapes = nullptr;
1139  }
1140 
1141  // Step 2: try a shape
1142  if( mxShape.is() )
1143  {
1145  {
1146  // This is not a Draw shape, let's see if it's a Writer one.
1147  uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
1148  if (!xPropertySet.is())
1149  break;
1150  uno::Reference<graphic::XGraphic> xGraphic(
1151  xPropertySet->getPropertyValue("Graphic"), uno::UNO_QUERY);
1152  if (!xGraphic.is())
1153  break;
1154 
1155  maGraphic = Graphic(xGraphic);
1156  if (!maGraphic.IsNone())
1157  return;
1158  else
1159  break;
1160  }
1161 
1162  // get page for this shape
1163  Reference< XChild > xChild( mxShape, UNO_QUERY );
1164  if( !xChild.is() )
1165  break;
1166 
1167  Reference< XInterface > xInt;
1168  do
1169  {
1170  xInt = xChild->getParent();
1171  mxPage.set( xInt, UNO_QUERY );
1172  if( !mxPage.is() )
1173  xChild.set( xInt, UNO_QUERY );
1174  }
1175  while( !mxPage.is() && xChild.is() );
1176 
1177  if( !mxPage.is() )
1178  break;
1179  }
1180 
1181  // Step 3: check the page
1182  if( !mxPage.is() )
1183  break;
1184 
1185  mpUnoPage = comphelper::getFromUnoTunnel<SvxDrawPage>( mxPage );
1186 
1187  if( nullptr == mpUnoPage || nullptr == mpUnoPage->GetSdrPage() )
1188  break;
1189 
1190  mpDoc = &mpUnoPage->GetSdrPage()->getSdrModelFromSdrPage();
1191 
1192  // Step 4: If we got a generic XShapes test all contained shapes
1193  // if they belong to the same XDrawPage
1194 
1195  if( mxShapes.is() )
1196  {
1197  SdrPage* pPage = mpUnoPage->GetSdrPage();
1198  SdrObject* pObj;
1199  Reference< XShape > xShape;
1200 
1201  bool bOk = true;
1202 
1203  const sal_Int32 nCount = mxShapes->getCount();
1204 
1205  // test all but the first shape if they have the same page than
1206  // the first shape
1207  for( sal_Int32 nIndex = 1; bOk && ( nIndex < nCount ); nIndex++ )
1208  {
1209  mxShapes->getByIndex( nIndex ) >>= xShape;
1210  pObj = SdrObject::getSdrObjectFromXShape(xShape);
1211  bOk = pObj && pObj->getSdrPageFromSdrObject() == pPage;
1212  }
1213 
1214  if( !bOk )
1215  break;
1216  }
1217 
1218  // no errors so far
1219  return;
1220  }
1221  while( false );
1222  }
1223  catch( Exception& )
1224  {
1225  }
1226 
1227  throw IllegalArgumentException();
1228 }
1229 
1230 // XServiceInfo
1231 OUString SAL_CALL GraphicExporter::getImplementationName( )
1232 {
1233  return "com.sun.star.comp.Draw.GraphicExporter";
1234 }
1235 
1236 sal_Bool SAL_CALL GraphicExporter::supportsService( const OUString& ServiceName )
1237 {
1238  return cppu::supportsService(this, ServiceName);
1239 }
1240 
1241 Sequence< OUString > SAL_CALL GraphicExporter::getSupportedServiceNames( )
1242 {
1243  Sequence< OUString > aSupportedServiceNames { "com.sun.star.drawing.GraphicExportFilter" };
1244  return aSupportedServiceNames;
1245 }
1246 
1247 // XMimeTypeInfo
1248 sal_Bool SAL_CALL GraphicExporter::supportsMimeType( const OUString& rMimeTypeName )
1249 {
1251  sal_uInt16 nCount = rFilter.GetExportFormatCount();
1252  sal_uInt16 nFilter;
1253  for( nFilter = 0; nFilter < nCount; nFilter++ )
1254  {
1255  if( rMimeTypeName == rFilter.GetExportFormatMediaType( nFilter ) )
1256  {
1257  return true;
1258  }
1259  }
1260 
1261  return false;
1262 }
1263 
1264 Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames( )
1265 {
1267  sal_uInt16 nCount = rFilter.GetExportFormatCount();
1268  sal_uInt16 nFilter;
1269  sal_uInt16 nFound = 0;
1270 
1271  Sequence< OUString > aSeq( nCount );
1272  OUString* pStr = aSeq.getArray();
1273 
1274  for( nFilter = 0; nFilter < nCount; nFilter++ )
1275  {
1276  OUString aMimeType( rFilter.GetExportFormatMediaType( nFilter ) );
1277  if( !aMimeType.isEmpty() )
1278  {
1279  *pStr++ = aMimeType;
1280  nFound++;
1281  }
1282  }
1283 
1284  if( nFound < nCount )
1285  aSeq.realloc( nFound );
1286 
1287  return aSeq;
1288 }
1289 
1290 }
1291 
1293 {
1294  Graphic aGraphic;
1295  try
1296  {
1297  rtl::Reference< GraphicExporter > xExporter( new GraphicExporter() );
1298  Reference< XComponent > xComp( rShape.getUnoShape(), UNO_QUERY_THROW );
1299  xExporter->setSourceDocument( xComp );
1300  ExportSettings aSettings(&rShape.getSdrModelFromSdrObject());
1301  xExporter->GetGraphic( aSettings, aGraphic, true/*bVector*/ );
1302  }
1303  catch( Exception& )
1304  {
1305  TOOLS_WARN_EXCEPTION("svx", "");
1306  }
1307  return aGraphic;
1308 }
1309 
1310 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1312  css::uno::XComponentContext *,
1313  css::uno::Sequence<css::uno::Any> const &)
1314 {
1315  return cppu::acquire(new GraphicExporter);
1316 }
1317 
1318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double mnHeight
bool IsExportPixelFormat(sal_uInt16 nFormat)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
void SetHlplVisible(bool bOn=true)
Definition: svdpntv.hxx:384
sal_Int32 nIndex
Color GetPageBackgroundColor() const
deprecated returns an averaged background color of this page
Definition: svdpage.cxx:1817
void setWidth(tools::Long nWidth)
IMPL_LINK(MaskData, PipetteHdl, const OString &, rId, void)
Definition: _bmpmask.cxx:192
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
bool IsNone() const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
void SetStyleSettings(const StyleSettings &rSet)
virtual SdrObject * TryToGetSdrObject() const
constexpr tools::Long Left() const
bool Contains(const Point &rPOINT) const
const Fraction & GetScaleFraction() const
Definition: svdmodel.hxx:372
const MapMode & GetPrefMapMode() const
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
long Long
void SetPrefMapMode(const MapMode &rPrefMapMode)
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
Definition: unoshape.cxx:4021
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
sal_Int32 GetRightBorder() const
Definition: svdpage.cxx:1559
void SetPrefSize(const Size &rSize)
void Clear()
Graphic SvxGetGraphicForShape(SdrObject &rShape)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
sal_uInt64 Seek(sal_uInt64 nPos)
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
virtual void createRedirectedPrimitive2DSequence(const sdr::contact::ViewObjectContact &rOriginal, const sdr::contact::DisplayInfo &rDisplayInfo, drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Draw_GraphicExporter_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static void Free(SdrObject *&_rpObject)
Definition: svdobj.cxx:476
sal_Int32 GetLowerBorder() const
Definition: svdpage.cxx:1564
EmbeddedObjectRef * pObject
EEControlBits
TRISTATE_TRUE
virtual bool checkVisibility(const sdr::contact::ViewObjectContact &rOriginal, const sdr::contact::DisplayInfo &rDisplayInfo, bool bEdit)
this method returns true if the object from the ViewObjectContact should be visible on this page whil...
Definition: svdpage.cxx:1828
void SetMapMode()
sal_Int32 GetLeftBorder() const
Definition: svdpage.cxx:1549
void SetAntiAliasing(bool bOn, bool bTemporary)
Rectangle objects (rectangle, circle, ...)
Definition: svdorect.hxx:38
static OutputDevice * GetDefaultDevice()
constexpr tools::Long Width() const
HashMap_OWString_Interface aMap
uno::Reference< drawing::XShape > const mxShape
void SetProcessLayers(const SdrLayerIDSet &rSet)
Definition: displayinfo.cxx:35
sal_uInt16 sal_Unicode
void Record(OutputDevice *pOutDev)
void SetSubContentActive(bool bNew)
Definition: displayinfo.cxx:77
SdrPage * getSdrPageFromSdrObject() const
Definition: svdobj.cxx:274
void SetGlueVisible(bool bOn=true)
Definition: svdpntv.hxx:386
int nCount
void SetBordVisible(bool bOn=true)
Definition: svdpntv.hxx:381
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
Definition: svdobj.cxx:2884
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
sal_uInt16 GetExportFormatCount() const
const GDIMetaFile & GetGDIMetaFile() const
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:2002
void SetPageVisible(bool bOn=true)
Definition: svdpntv.hxx:378
SdrPageView * ShowSdrPage(SdrPage *pPage) override
Definition: svdedxv.cxx:128
constexpr tools::Long getHeight() const
std::vector< css::beans::PropertyValue > JsonToPropertyValues(const OString &rJson)
sal_uInt16 GetExportFormatNumberForShortName(std::u16string_view rShortName)
TRISTATE_INDET
B2IRange fround(const B2DRange &rRange)
constexpr OUStringLiteral aData
virtual void ProcessDisplay(DisplayInfo &rDisplayInfo) override
SdrPage * GetSdrPage() const
Definition: unopage.hxx:77
void SetScaleX(const Fraction &rScaleX)
#define TOOLS_WARN_EXCEPTION(area, stream)
const Size & GetPrefSize() const
#define DBG_ASSERT(sCon, aError)
int i
GraphicType GetType() const
static void SetSettings(const AllSettings &rSettings)
Size GetSize() const
Definition: svdpage.cxx:1443
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true)
sal_Int32 GetUpperBorder() const
Definition: svdpage.cxx:1554
TRISTATE_FALSE
void SetOrigin(const Point &rOrigin)
bool SetOutputSize(const Size &rNewSize)
BitmapEx convertMetafileToBitmapEx(const GDIMetaFile &rMtf, const basegfx::B2DRange &rTargetRange, const sal_uInt32 nMaximumQuadraticPixels)
Helper to convert any GDIMetaFile to a good quality BitmapEx, using default parameters and graphic::X...
Definition: svdpntv.cxx:107
sal_uInt16 GetExportFormatNumberForMediaType(std::u16string_view rShortName)
float u
unsigned char sal_Bool
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:284
void SetScaleY(const Fraction &rScaleY)
constexpr tools::Long Top() const
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
bool IsMasterPage() const
Definition: svdpage.hxx:459
const SfxItemSet & GetItemSet() const
Definition: svdpage.hxx:337
void SetMergedItem(const SfxPoolItem &rItem)
Definition: svdobj.cxx:1987
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
void WindStart()
static ErrCode ExportGraphic(const Graphic &rGraphic, const INetURLObject &rURL, GraphicFilter &rFilter, const sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData)
Definition: _xoutbmp.cxx:365
Abstract DrawObject.
Definition: svdobj.hxx:260
ErrCode ExportGraphic(const Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData=nullptr)
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
Size GetPrefSize() const
bool GetUseFontAAFromSystem() const
#define ERRCODE_GRFILTER_FILTERERROR
iterator find(const OUString &rKey)
static OUString CreateRomanString(sal_Int32 nNo, bool bUpper)
#define ERRCODE_NONE
constexpr tools::Long Height() const
SfxStyleSheet * GetStyleSheet() const
Definition: svdpage.hxx:344
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
INetProtocol GetProtocol() const
const SdrPageProperties * getCorrectSdrPageProperties() const
Definition: svdpage.cxx:1882
double mnWidth
void SetGridVisible(bool bOn)
Definition: svdpntv.hxx:382
static VclPtr< reference_type > Create(Arg &&...arg)
static css::uno::Reference< css::task::XInteractionRequest > CreateRequest(const css::uno::Any &aRequest, const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation >> &lContinuations)
Sequence< sal_Int8 > aSeq
virtual void CompleteRedraw(OutputDevice *pOut, const vcl::Region &rReg, sdr::contact::ViewObjectContactRedirector *pRedirector=nullptr)
Definition: svdpntv.cxx:482
void SetPrefSize(const Size &rPrefSize)
const Link< EditFieldInfo *, void > & GetCalcFieldValueHdl() const
void setHeight(tools::Long nHeight)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
ViewContact & GetViewContact() const
static GraphicFilter & GetGraphicFilter()
const sal_Unicode *const aMimeType[]
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
constexpr tools::Long getWidth() const
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:373
void NbcSetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2265
void SetUseFontAAFromSystem(bool bUseFontAAFromSystem)
TriState
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
void expand(const Tuple2D< double > &rTuple)
const Graphic maGraphic
void SetPrefMapMode(const MapMode &rMapMode)
#define MAX_EXT_PIX