cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / contact / objectcontactofobjlistpainter.cxx
blob475a3913d3ed160d981535ff922260232f0ab3c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
21 #include <svx/sdr/contact/displayinfo.hxx>
22 #include <svx/sdr/contact/viewobjectcontact.hxx>
23 #include <svx/svdpage.hxx>
24 #include <svx/svdobj.hxx>
25 #include <svx/sdr/contact/viewcontact.hxx>
26 #include <basegfx/matrix/b2dhommatrix.hxx>
27 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
28 #include <drawinglayer/processor2d/processor2dtools.hxx>
29 #include <svx/unoapi.hxx>
30 #include <tools/debug.hxx>
31 #include <vcl/gdimtf.hxx>
32 #include <vcl/pdfextoutdevdata.hxx>
33 #include <memory>
35 namespace sdr::contact {
37 ObjectContactPainter::ObjectContactPainter()
41 // The destructor.
42 ObjectContactPainter::~ObjectContactPainter()
46 sal_uInt32 ObjectContactOfObjListPainter::GetPaintObjectCount() const
48 return maStartObjects.size();
51 ViewContact& ObjectContactOfObjListPainter::GetPaintObjectViewContact(sal_uInt32 nIndex)
53 const SdrObject* pObj = maStartObjects[nIndex];
54 assert(pObj && "ObjectContactOfObjListPainter: Corrupt SdrObjectVector (!)");
55 return pObj->GetViewContact();
58 ObjectContactOfObjListPainter::ObjectContactOfObjListPainter(
59 OutputDevice& rTargetDevice,
60 SdrObjectVector&& rObjects,
61 const SdrPage* pProcessedPage)
62 : mrTargetOutputDevice(rTargetDevice),
63 maStartObjects(std::move(rObjects)),
64 mpProcessedPage(pProcessedPage)
68 ObjectContactOfObjListPainter::~ObjectContactOfObjListPainter()
72 // Process the whole displaying
73 void ObjectContactOfObjListPainter::ProcessDisplay(DisplayInfo& rDisplayInfo)
75 const sal_uInt32 nCount(GetPaintObjectCount());
77 if(!nCount)
78 return;
80 OutputDevice* pTargetDevice = TryToGetOutputDevice();
82 if(!pTargetDevice)
83 return;
85 // update current ViewInformation2D at the ObjectContact
86 const GDIMetaFile* pMetaFile = pTargetDevice->GetConnectMetaFile();
87 const bool bOutputToRecordingMetaFile(pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
88 basegfx::B2DRange aViewRange;
90 // create ViewRange
91 if(!bOutputToRecordingMetaFile)
93 // use visible pixels, but transform to world coordinates
94 const Size aOutputSizePixel(pTargetDevice->GetOutputSizePixel());
95 aViewRange = ::basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
96 aViewRange.transform(pTargetDevice->GetInverseViewTransformation());
99 // update local ViewInformation2D
100 drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
101 aNewViewInformation2D.setViewTransformation(pTargetDevice->GetViewTransformation());
102 aNewViewInformation2D.setViewport(aViewRange);
103 aNewViewInformation2D.setVisualizedPage(GetXDrawPageForSdrPage(const_cast< SdrPage* >(mpProcessedPage)));
104 updateViewInformation2D(aNewViewInformation2D);
106 // collect primitive data in a sequence; this will already use the updated ViewInformation2D
107 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence;
109 for(sal_uInt32 a(0); a < nCount; a++)
111 const ViewObjectContact& rViewObjectContact = GetPaintObjectViewContact(a).GetViewObjectContact(*this);
113 rViewObjectContact.getPrimitive2DSequenceHierarchy(rDisplayInfo, xPrimitiveSequence);
116 // if there is something to show, use a vclProcessor to render it
117 if(!xPrimitiveSequence.empty())
119 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createProcessor2DFromOutputDevice(
120 *pTargetDevice,
121 getViewInformation2D()));
123 pProcessor2D->process(xPrimitiveSequence);
127 // recording MetaFile?
128 bool ObjectContactOfObjListPainter::isOutputToRecordingMetaFile() const
130 GDIMetaFile* pMetaFile = mrTargetOutputDevice.GetConnectMetaFile();
131 return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
134 // pdf export?
135 bool ObjectContactOfObjListPainter::isOutputToPDFFile() const
137 return OUTDEV_PDF == mrTargetOutputDevice.GetOutDevType();
140 bool ObjectContactOfObjListPainter::isExportTaggedPDF() const
142 if (isOutputToPDFFile())
144 vcl::PDFExtOutDevData* pPDFExtOutDevData(dynamic_cast<vcl::PDFExtOutDevData*>(
145 mrTargetOutputDevice.GetExtOutDevData()));
147 if (nullptr != pPDFExtOutDevData)
149 return pPDFExtOutDevData->GetIsExportTaggedPDF();
152 return false;
155 ::vcl::PDFExtOutDevData const* ObjectContactOfObjListPainter::GetPDFExtOutDevData() const
157 if (!isOutputToPDFFile())
159 return nullptr;
161 vcl::PDFExtOutDevData *const pPDFExtOutDevData(
162 dynamic_cast<vcl::PDFExtOutDevData*>(mrTargetOutputDevice.GetExtOutDevData()));
163 return pPDFExtOutDevData;
166 OutputDevice* ObjectContactOfObjListPainter::TryToGetOutputDevice() const
168 return &mrTargetOutputDevice;
171 sal_uInt32 ObjectContactOfPagePainter::GetPaintObjectCount() const
173 return (GetStartPage() ? 1 : 0);
176 ViewContact& ObjectContactOfPagePainter::GetPaintObjectViewContact(sal_uInt32 /*nIndex*/)
178 DBG_ASSERT(GetStartPage(), "ObjectContactOfPagePainter::GetPaintObjectViewContact: no StartPage set (!)");
179 return GetStartPage()->GetViewContact();
182 ObjectContactOfPagePainter::ObjectContactOfPagePainter(
183 ObjectContact& rOriginalObjectContact)
184 : mrOriginalObjectContact(rOriginalObjectContact)
188 ObjectContactOfPagePainter::~ObjectContactOfPagePainter()
192 void ObjectContactOfPagePainter::SetStartPage(const SdrPage* pPage)
194 if(pPage != GetStartPage())
196 mxStartPage = const_cast< SdrPage* >(pPage); // no tools::WeakReference<SdrPage> available to hold a const SdrPage*
200 OutputDevice* ObjectContactOfPagePainter::TryToGetOutputDevice() const
202 return mrOriginalObjectContact.TryToGetOutputDevice();
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */