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