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 <svx/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 <svx/svdmodel.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
29 #include <drawinglayer/processor2d/processor2dtools.hxx>
30 #include <svx/unoapi.hxx>
31 #include <tools/debug.hxx>
32 #include <vcl/gdimtf.hxx>
33 #include <memory>
34 
35 namespace sdr { namespace contact {
36 
ObjectContactPainter()37 ObjectContactPainter::ObjectContactPainter()
38 {
39 }
40 
41 // The destructor.
~ObjectContactPainter()42 ObjectContactPainter::~ObjectContactPainter()
43 {
44 }
45 
GetPaintObjectCount() const46 sal_uInt32 ObjectContactOfObjListPainter::GetPaintObjectCount() const
47 {
48     return maStartObjects.size();
49 }
50 
GetPaintObjectViewContact(sal_uInt32 nIndex)51 ViewContact& ObjectContactOfObjListPainter::GetPaintObjectViewContact(sal_uInt32 nIndex)
52 {
53     const SdrObject* pObj = maStartObjects[nIndex];
54     DBG_ASSERT(pObj, "ObjectContactOfObjListPainter: Corrupt SdrObjectVector (!)");
55     return pObj->GetViewContact();
56 }
57 
ObjectContactOfObjListPainter(OutputDevice & rTargetDevice,const SdrObjectVector & rObjects,const SdrPage * pProcessedPage)58 ObjectContactOfObjListPainter::ObjectContactOfObjListPainter(
59     OutputDevice& rTargetDevice,
60     const SdrObjectVector& rObjects,
61     const SdrPage* pProcessedPage)
62 :   ObjectContactPainter(),
63     mrTargetOutputDevice(rTargetDevice),
64     maStartObjects(rObjects),
65     mpProcessedPage(pProcessedPage)
66 {
67 }
68 
~ObjectContactOfObjListPainter()69 ObjectContactOfObjListPainter::~ObjectContactOfObjListPainter()
70 {
71 }
72 
73 // Process the whole displaying
ProcessDisplay(DisplayInfo & rDisplayInfo)74 void ObjectContactOfObjListPainter::ProcessDisplay(DisplayInfo& rDisplayInfo)
75 {
76     const sal_uInt32 nCount(GetPaintObjectCount());
77 
78     if(nCount)
79     {
80         OutputDevice* pTargetDevice = TryToGetOutputDevice();
81 
82         if(pTargetDevice)
83         {
84             // update current ViewInformation2D at the ObjectContact
85             const GDIMetaFile* pMetaFile = pTargetDevice->GetConnectMetaFile();
86             const bool bOutputToRecordingMetaFile(pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
87             basegfx::B2DRange aViewRange;
88 
89             // create ViewRange
90             if(!bOutputToRecordingMetaFile)
91             {
92                 // use visible pixels, but transform to world coordinates
93                 const Size aOutputSizePixel(pTargetDevice->GetOutputSizePixel());
94                 aViewRange = ::basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
95                 aViewRange.transform(pTargetDevice->GetInverseViewTransformation());
96             }
97 
98             // update local ViewInformation2D
99             const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(
100                 basegfx::B2DHomMatrix(),
101                 pTargetDevice->GetViewTransformation(),
102                 aViewRange,
103                 GetXDrawPageForSdrPage(const_cast< SdrPage* >(mpProcessedPage)),
104                 0.0,
105                 css::uno::Sequence<css::beans::PropertyValue>());
106             updateViewInformation2D(aNewViewInformation2D);
107 
108             // collect primitive data in a sequence; this will already use the updated ViewInformation2D
109             drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence;
110 
111             for(sal_uInt32 a(0); a < nCount; a++)
112             {
113                 const ViewObjectContact& rViewObjectContact = GetPaintObjectViewContact(a).GetViewObjectContact(*this);
114 
115                 xPrimitiveSequence.append(rViewObjectContact.getPrimitive2DSequenceHierarchy(rDisplayInfo));
116             }
117 
118             // if there is something to show, use a vclProcessor to render it
119             if(!xPrimitiveSequence.empty())
120             {
121                 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createProcessor2DFromOutputDevice(
122                     *pTargetDevice,
123                     getViewInformation2D()));
124 
125                 if(pProcessor2D)
126                 {
127                     pProcessor2D->process(xPrimitiveSequence);
128                 }
129             }
130         }
131     }
132 }
133 
134 // recording MetaFile?
isOutputToRecordingMetaFile() const135 bool ObjectContactOfObjListPainter::isOutputToRecordingMetaFile() const
136 {
137     GDIMetaFile* pMetaFile = mrTargetOutputDevice.GetConnectMetaFile();
138     return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
139 }
140 
141 // pdf export?
isOutputToPDFFile() const142 bool ObjectContactOfObjListPainter::isOutputToPDFFile() const
143 {
144     return OUTDEV_PDF == mrTargetOutputDevice.GetOutDevType();
145 }
146 
TryToGetOutputDevice() const147 OutputDevice* ObjectContactOfObjListPainter::TryToGetOutputDevice() const
148 {
149     return &mrTargetOutputDevice;
150 }
151 
GetPaintObjectCount() const152 sal_uInt32 ObjectContactOfPagePainter::GetPaintObjectCount() const
153 {
154     return (GetStartPage() ? 1 : 0);
155 }
156 
GetPaintObjectViewContact(sal_uInt32)157 ViewContact& ObjectContactOfPagePainter::GetPaintObjectViewContact(sal_uInt32 /*nIndex*/)
158 {
159     DBG_ASSERT(GetStartPage(), "ObjectContactOfPagePainter::GetPaintObjectViewContact: no StartPage set (!)");
160     return GetStartPage()->GetViewContact();
161 }
162 
ObjectContactOfPagePainter(ObjectContact & rOriginalObjectContact)163 ObjectContactOfPagePainter::ObjectContactOfPagePainter(
164     ObjectContact& rOriginalObjectContact)
165 :   ObjectContactPainter(),
166     mrOriginalObjectContact(rOriginalObjectContact),
167     mxStartPage()
168 {
169 }
170 
~ObjectContactOfPagePainter()171 ObjectContactOfPagePainter::~ObjectContactOfPagePainter()
172 {
173 }
174 
SetStartPage(const SdrPage * pPage)175 void ObjectContactOfPagePainter::SetStartPage(const SdrPage* pPage)
176 {
177     if(pPage != GetStartPage())
178     {
179         mxStartPage.reset(const_cast< SdrPage* >(pPage)); // no tools::WeakReference<SdrPage> available to hold a const SdrPage*
180     }
181 }
182 
TryToGetOutputDevice() const183 OutputDevice* ObjectContactOfPagePainter::TryToGetOutputDevice() const
184 {
185     return mrOriginalObjectContact.TryToGetOutputDevice();
186 }
187 
188 }}
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
191