1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
27 #include <svx/sdr/contact/displayinfo.hxx>
28 #include <svx/sdr/contact/viewobjectcontact.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svx/svdobj.hxx>
31 #include <svx/sdr/contact/viewcontact.hxx>
32 #include <svx/svdmodel.hxx>
33 #include <drawinglayer/processor2d/vclprocessor2d.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <svx/sdr/contact/objectcontacttools.hxx>
36 #include <svx/unoapi.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace sdr
41 {
42 	namespace contact
43 	{
44 		ObjectContactPainter::ObjectContactPainter()
45 		{
46 		}
47 
48 		// The destructor.
49 		ObjectContactPainter::~ObjectContactPainter()
50 		{
51 		}
52 	} // end of namespace contact
53 } // end of namespace sdr
54 
55 //////////////////////////////////////////////////////////////////////////////
56 
57 namespace sdr
58 {
59 	namespace contact
60 	{
61 		sal_uInt32 ObjectContactOfObjListPainter::GetPaintObjectCount() const
62 		{
63 			return maStartObjects.size();
64 		}
65 
66 		ViewContact& ObjectContactOfObjListPainter::GetPaintObjectViewContact(sal_uInt32 nIndex) const
67 		{
68 			const SdrObject* pObj = maStartObjects[nIndex];
69 			DBG_ASSERT(pObj, "ObjectContactOfObjListPainter: Corrupt SdrObjectVector (!)");
70 			return pObj->GetViewContact();
71 		}
72 
73 		ObjectContactOfObjListPainter::ObjectContactOfObjListPainter(
74 			OutputDevice& rTargetDevice,
75 			const SdrObjectVector& rObjects,
76             const SdrPage* pProcessedPage)
77 		:	ObjectContactPainter(),
78 			mrTargetOutputDevice(rTargetDevice),
79 			maStartObjects(rObjects),
80             mpProcessedPage(pProcessedPage)
81 		{
82 		}
83 
84 		ObjectContactOfObjListPainter::~ObjectContactOfObjListPainter()
85 		{
86 		}
87 
88 		// Process the whole displaying
89 		void ObjectContactOfObjListPainter::ProcessDisplay(DisplayInfo& rDisplayInfo)
90 		{
91 			const sal_uInt32 nCount(GetPaintObjectCount());
92 
93 			if(nCount)
94 			{
95 				OutputDevice* pTargetDevice = TryToGetOutputDevice();
96 
97 				if(pTargetDevice)
98 				{
99 					// update current ViewInformation2D at the ObjectContact
100 					const GDIMetaFile* pMetaFile = pTargetDevice->GetConnectMetaFile();
101 					const bool bOutputToRecordingMetaFile(pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
102 					basegfx::B2DRange aViewRange;
103 
104 					// create ViewRange
105 					if(!bOutputToRecordingMetaFile)
106 					{
107 						// use visible pixels, but transform to world coordinates
108 						const Size aOutputSizePixel(pTargetDevice->GetOutputSizePixel());
109 						aViewRange = ::basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
110 						aViewRange.transform(pTargetDevice->GetInverseViewTransformation());
111 					}
112 
113 					// upate local ViewInformation2D
114 					const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(
115                         basegfx::B2DHomMatrix(),
116 						pTargetDevice->GetViewTransformation(),
117 						aViewRange,
118         				GetXDrawPageForSdrPage(const_cast< SdrPage* >(mpProcessedPage)),
119 						0.0,
120 						com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>());
121 					updateViewInformation2D(aNewViewInformation2D);
122 
123 					// collect primitive data in a sequence; this will already use the updated ViewInformation2D
124 					drawinglayer::primitive2d::Primitive2DSequence xPrimitiveSequence;
125 
126 					for(sal_uInt32 a(0L); a < nCount; a++)
127 					{
128 						const ViewObjectContact& rViewObjectContact = GetPaintObjectViewContact(a).GetViewObjectContact(*this);
129 
130 						drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xPrimitiveSequence,
131 							rViewObjectContact.getPrimitive2DSequenceHierarchy(rDisplayInfo));
132 					}
133 
134 					// if there is something to show, use a vclProcessor to render it
135 					if(xPrimitiveSequence.hasElements())
136 					{
137 						drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = createBaseProcessor2DFromOutputDevice(
138 							*pTargetDevice, getViewInformation2D());
139 
140 						if(pProcessor2D)
141 						{
142 							pProcessor2D->process(xPrimitiveSequence);
143 							delete pProcessor2D;
144 						}
145 					}
146 				}
147 			}
148 		}
149 
150 		// VirtualDevice?
151 		bool ObjectContactOfObjListPainter::isOutputToVirtualDevice() const
152 		{
153 			return (OUTDEV_VIRDEV == mrTargetOutputDevice.GetOutDevType());
154 		}
155 
156 		// recording MetaFile?
157 		bool ObjectContactOfObjListPainter::isOutputToRecordingMetaFile() const
158 		{
159 			GDIMetaFile* pMetaFile = mrTargetOutputDevice.GetConnectMetaFile();
160 			return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
161 		}
162 
163 		// pdf export?
164 		bool ObjectContactOfObjListPainter::isOutputToPDFFile() const
165 		{
166             return (0 != mrTargetOutputDevice.GetPDFWriter());
167 		}
168 
169 		OutputDevice* ObjectContactOfObjListPainter::TryToGetOutputDevice() const
170 		{
171 			return &mrTargetOutputDevice;
172 		}
173 	} // end of namespace contact
174 } // end of namespace sdr
175 
176 //////////////////////////////////////////////////////////////////////////////
177 
178 namespace sdr
179 {
180 	namespace contact
181 	{
182 		sal_uInt32 ObjectContactOfPagePainter::GetPaintObjectCount() const
183 		{
184 			return (GetStartPage() ? 1L : 0L);
185 		}
186 
187 		ViewContact& ObjectContactOfPagePainter::GetPaintObjectViewContact(sal_uInt32 /*nIndex*/) const
188 		{
189 			DBG_ASSERT(GetStartPage(), "ObjectContactOfPagePainter::GetPaintObjectViewContact: no StartPage set (!)");
190 			return GetStartPage()->GetViewContact();
191 		}
192 
193 		ObjectContactOfPagePainter::ObjectContactOfPagePainter(
194 			const SdrPage* pPage,
195 			ObjectContact& rOriginalObjectContact)
196 		:	ObjectContactPainter(),
197 			mrOriginalObjectContact(rOriginalObjectContact),
198 			mxStartPage(const_cast< SdrPage* >(pPage)) // no SdrPageWeakRef available to hold a const SdrPage*
199 		{
200 		}
201 
202 		ObjectContactOfPagePainter::~ObjectContactOfPagePainter()
203 		{
204 		}
205 
206 		void ObjectContactOfPagePainter::SetStartPage(const SdrPage* pPage)
207 		{
208 			if(pPage != GetStartPage())
209 			{
210 				mxStartPage.reset(const_cast< SdrPage* >(pPage)); // no SdrPageWeakRef available to hold a const SdrPage*
211 			}
212 		}
213 
214 		OutputDevice* ObjectContactOfPagePainter::TryToGetOutputDevice() const
215 		{
216 			return mrOriginalObjectContact.TryToGetOutputDevice();
217 		}
218 	} // end of namespace contact
219 } // end of namespace sdr
220 
221 //////////////////////////////////////////////////////////////////////////////
222 // eof
223