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