File: | home/maarten/src/libreoffice/core/xmloff/source/draw/ximp3dscene.cxx |
Warning: | line 232, column 5 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 <sax/tools/converter.hxx> | |||
21 | #include <rtl/math.hxx> | |||
22 | #include <sal/log.hxx> | |||
23 | ||||
24 | #include "ximp3dscene.hxx" | |||
25 | #include <xmloff/xmluconv.hxx> | |||
26 | #include <xexptran.hxx> | |||
27 | #include <xmloff/xmltoken.hxx> | |||
28 | #include <xmloff/xmlnamespace.hxx> | |||
29 | #include <com/sun/star/beans/XPropertySet.hpp> | |||
30 | #include <com/sun/star/drawing/Direction3D.hpp> | |||
31 | #include <com/sun/star/drawing/CameraGeometry.hpp> | |||
32 | #include "eventimp.hxx" | |||
33 | #include "descriptionimp.hxx" | |||
34 | ||||
35 | using namespace ::com::sun::star; | |||
36 | using namespace ::xmloff::token; | |||
37 | ||||
38 | // dr3d:3dlight context | |||
39 | ||||
40 | SdXML3DLightContext::SdXML3DLightContext( | |||
41 | SvXMLImport& rImport, | |||
42 | sal_uInt16 nPrfx, | |||
43 | const OUString& rLName, | |||
44 | const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList) | |||
45 | : SvXMLImportContext( rImport, nPrfx, rLName), | |||
46 | maDiffuseColor(0x00000000), | |||
47 | maDirection(0.0, 0.0, 1.0), | |||
48 | mbEnabled(false), | |||
49 | mbSpecular(false) | |||
50 | { | |||
51 | // read attributes for the 3DScene | |||
52 | sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; | |||
53 | for(sal_Int16 i=0; i < nAttrCount; i++) | |||
54 | { | |||
55 | OUString sAttrName = xAttrList->getNameByIndex( i ); | |||
56 | OUString aLocalName; | |||
57 | sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); | |||
58 | OUString sValue = xAttrList->getValueByIndex( i ); | |||
59 | const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DLightAttrTokenMap(); | |||
60 | ||||
61 | switch(rAttrTokenMap.Get(nPrefix, aLocalName)) | |||
62 | { | |||
63 | case XML_TOK_3DLIGHT_DIFFUSE_COLOR: | |||
64 | { | |||
65 | ::sax::Converter::convertColor(maDiffuseColor, sValue); | |||
66 | break; | |||
67 | } | |||
68 | case XML_TOK_3DLIGHT_DIRECTION: | |||
69 | { | |||
70 | ::basegfx::B3DVector aVal; | |||
71 | SvXMLUnitConverter::convertB3DVector(aVal, sValue); | |||
72 | if (!std::isnan(aVal.getX()) && !std::isnan(aVal.getY()) && !std::isnan(aVal.getZ())) | |||
73 | { | |||
74 | maDirection = aVal; | |||
75 | } | |||
76 | else | |||
77 | { | |||
78 | SAL_WARN("xmloff", "NaNs found in light direction: " << sValue)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "xmloff")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "NaNs found in light direction: " << sValue) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("xmloff"), ("/home/maarten/src/libreoffice/core/xmloff/source/draw/ximp3dscene.cxx" ":" "78" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "NaNs found in light direction: " << sValue), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "NaNs found in light direction: " << sValue; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("xmloff"), ("/home/maarten/src/libreoffice/core/xmloff/source/draw/ximp3dscene.cxx" ":" "78" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "NaNs found in light direction: " << sValue ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("xmloff" ), ("/home/maarten/src/libreoffice/core/xmloff/source/draw/ximp3dscene.cxx" ":" "78" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "NaNs found in light direction: " << sValue), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "NaNs found in light direction: " << sValue; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("xmloff"), ("/home/maarten/src/libreoffice/core/xmloff/source/draw/ximp3dscene.cxx" ":" "78" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
79 | } | |||
80 | break; | |||
81 | } | |||
82 | case XML_TOK_3DLIGHT_ENABLED: | |||
83 | { | |||
84 | (void)::sax::Converter::convertBool(mbEnabled, sValue); | |||
85 | break; | |||
86 | } | |||
87 | case XML_TOK_3DLIGHT_SPECULAR: | |||
88 | { | |||
89 | (void)::sax::Converter::convertBool(mbSpecular, sValue); | |||
90 | break; | |||
91 | } | |||
92 | } | |||
93 | } | |||
94 | } | |||
95 | ||||
96 | SdXML3DLightContext::~SdXML3DLightContext() | |||
97 | { | |||
98 | } | |||
99 | ||||
100 | ||||
101 | SdXML3DSceneShapeContext::SdXML3DSceneShapeContext( | |||
102 | SvXMLImport& rImport, | |||
103 | sal_uInt16 nPrfx, | |||
104 | const OUString& rLocalName, | |||
105 | const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, | |||
106 | uno::Reference< drawing::XShapes > const & rShapes, | |||
107 | bool bTemporaryShapes) | |||
108 | : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShapes ), SdXML3DSceneAttributesHelper( rImport ) | |||
109 | { | |||
110 | } | |||
111 | ||||
112 | SdXML3DSceneShapeContext::~SdXML3DSceneShapeContext() | |||
113 | { | |||
114 | } | |||
115 | ||||
116 | void SdXML3DSceneShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) | |||
117 | { | |||
118 | // create new 3DScene shape and add it to rShapes, use it | |||
119 | // as base for the new 3DScene import | |||
120 | AddShape( "com.sun.star.drawing.Shape3DSceneObject" ); | |||
121 | if( mxShape.is() ) | |||
122 | { | |||
123 | SetStyle(); | |||
124 | ||||
125 | mxChildren.set( mxShape, uno::UNO_QUERY ); | |||
126 | if( mxChildren.is() ) | |||
127 | GetImport().GetShapeImport()->pushGroupForPostProcessing( mxChildren ); | |||
128 | ||||
129 | SetLayer(); | |||
130 | ||||
131 | // set pos, size, shear and rotate | |||
132 | SetTransformation(); | |||
133 | } | |||
134 | ||||
135 | // read attributes for the 3DScene | |||
136 | sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; | |||
137 | for(sal_Int16 i=0; i < nAttrCount; i++) | |||
138 | { | |||
139 | OUString sAttrName = xAttrList->getNameByIndex( i ); | |||
140 | OUString aLocalName; | |||
141 | sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); | |||
142 | OUString sValue = xAttrList->getValueByIndex( i ); | |||
143 | processSceneAttribute( nPrefix, aLocalName, sValue ); | |||
144 | } | |||
145 | ||||
146 | // #91047# call parent function is missing here, added it | |||
147 | if(mxShape.is()) | |||
148 | { | |||
149 | // call parent | |||
150 | SdXMLShapeContext::StartElement(xAttrList); | |||
151 | } | |||
152 | } | |||
153 | ||||
154 | void SdXML3DSceneShapeContext::EndElement() | |||
155 | { | |||
156 | if(!mxShape.is()) | |||
157 | return; | |||
158 | ||||
159 | uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); | |||
160 | if(xPropSet.is()) | |||
161 | { | |||
162 | setSceneAttributes( xPropSet ); | |||
163 | } | |||
164 | ||||
165 | if( mxChildren.is() ) | |||
166 | GetImport().GetShapeImport()->popGroupAndPostProcess(); | |||
167 | ||||
168 | // call parent | |||
169 | SdXMLShapeContext::EndElement(); | |||
170 | } | |||
171 | ||||
172 | SvXMLImportContextRef SdXML3DSceneShapeContext::CreateChildContext( sal_uInt16 nPrefix, | |||
173 | const OUString& rLocalName, | |||
174 | const uno::Reference< xml::sax::XAttributeList>& xAttrList ) | |||
175 | { | |||
176 | SvXMLImportContextRef xContext; | |||
177 | ||||
178 | // #i68101# | |||
179 | if( nPrefix == XML_NAMESPACE_SVG && | |||
| ||||
180 | (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) ) | |||
181 | { | |||
182 | xContext = new SdXMLDescriptionContext( GetImport(), nPrefix, rLocalName, xAttrList, mxShape ); | |||
183 | } | |||
184 | else if( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) | |||
185 | { | |||
186 | xContext = new SdXMLEventsContext( GetImport(), nPrefix, rLocalName, xAttrList, mxShape ); | |||
187 | } | |||
188 | // look for local light context first | |||
189 | else if(nPrefix == XML_NAMESPACE_DR3D && IsXMLToken( rLocalName, XML_LIGHT ) ) | |||
190 | { | |||
191 | // dr3d:light inside dr3d:scene context | |||
192 | xContext = create3DLightContext( nPrefix, rLocalName, xAttrList ); | |||
193 | } | |||
194 | ||||
195 | // call GroupChildContext function at common ShapeImport | |||
196 | if (!xContext) | |||
197 | { | |||
198 | xContext = GetImport().GetShapeImport()->Create3DSceneChildContext( | |||
199 | GetImport(), nPrefix, rLocalName, xAttrList, mxChildren); | |||
200 | } | |||
201 | ||||
202 | return xContext; | |||
203 | } | |||
204 | ||||
205 | SdXML3DSceneAttributesHelper::SdXML3DSceneAttributesHelper( SvXMLImport& rImporter ) | |||
206 | : mrImport( rImporter ), | |||
207 | mbSetTransform( false ), | |||
208 | mxPrjMode(drawing::ProjectionMode_PERSPECTIVE), | |||
209 | mnDistance(1000), | |||
210 | mnFocalLength(1000), | |||
211 | mnShadowSlant(0), | |||
212 | mxShadeMode(drawing::ShadeMode_SMOOTH), | |||
213 | maAmbientColor(0x00666666), | |||
214 | mbLightingMode(false), | |||
215 | maVRP(0.0, 0.0, 1.0), | |||
216 | maVPN(0.0, 0.0, 1.0), | |||
217 | maVUP(0.0, 1.0, 0.0), | |||
218 | mbVRPUsed(false), | |||
219 | mbVPNUsed(false), | |||
220 | mbVUPUsed(false) | |||
221 | { | |||
222 | } | |||
223 | ||||
224 | /** creates a 3d light context and adds it to the internal list for later processing */ | |||
225 | SvXMLImportContext * SdXML3DSceneAttributesHelper::create3DLightContext( sal_uInt16 nPrfx, const OUString& rLName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList) | |||
226 | { | |||
227 | const rtl::Reference<SdXML3DLightContext> xContext{new SdXML3DLightContext(mrImport, nPrfx, rLName, xAttrList)}; | |||
228 | ||||
229 | // remember SdXML3DLightContext for later evaluation | |||
230 | maList.push_back(xContext); | |||
231 | ||||
232 | return xContext.get(); | |||
| ||||
233 | } | |||
234 | ||||
235 | /** this should be called for each scene attribute */ | |||
236 | void SdXML3DSceneAttributesHelper::processSceneAttribute( sal_uInt16 nPrefix, const OUString& rLocalName, const OUString& rValue ) | |||
237 | { | |||
238 | if( XML_NAMESPACE_DR3D != nPrefix ) | |||
239 | return; | |||
240 | ||||
241 | if( IsXMLToken( rLocalName, XML_TRANSFORM ) ) | |||
242 | { | |||
243 | SdXMLImExTransform3D aTransform(rValue, mrImport.GetMM100UnitConverter()); | |||
244 | if(aTransform.NeedsAction()) | |||
245 | mbSetTransform = aTransform.GetFullHomogenTransform(mxHomMat); | |||
246 | return; | |||
247 | } | |||
248 | else if( IsXMLToken( rLocalName, XML_VRP ) ) | |||
249 | { | |||
250 | ::basegfx::B3DVector aNewVec; | |||
251 | SvXMLUnitConverter::convertB3DVector(aNewVec, rValue); | |||
252 | ||||
253 | if(aNewVec != maVRP) | |||
254 | { | |||
255 | maVRP = aNewVec; | |||
256 | mbVRPUsed = true; | |||
257 | } | |||
258 | return; | |||
259 | } | |||
260 | else if( IsXMLToken( rLocalName, XML_VPN ) ) | |||
261 | { | |||
262 | ::basegfx::B3DVector aNewVec; | |||
263 | SvXMLUnitConverter::convertB3DVector(aNewVec, rValue); | |||
264 | ||||
265 | if(aNewVec != maVPN) | |||
266 | { | |||
267 | maVPN = aNewVec; | |||
268 | mbVPNUsed = true; | |||
269 | } | |||
270 | return; | |||
271 | } | |||
272 | else if( IsXMLToken( rLocalName, XML_VUP ) ) | |||
273 | { | |||
274 | ::basegfx::B3DVector aNewVec; | |||
275 | SvXMLUnitConverter::convertB3DVector(aNewVec, rValue); | |||
276 | ||||
277 | if(aNewVec != maVUP) | |||
278 | { | |||
279 | maVUP = aNewVec; | |||
280 | mbVUPUsed = true; | |||
281 | } | |||
282 | return; | |||
283 | } | |||
284 | else if( IsXMLToken( rLocalName, XML_PROJECTION ) ) | |||
285 | { | |||
286 | if( IsXMLToken( rValue, XML_PARALLEL ) ) | |||
287 | mxPrjMode = drawing::ProjectionMode_PARALLEL; | |||
288 | else | |||
289 | mxPrjMode = drawing::ProjectionMode_PERSPECTIVE; | |||
290 | return; | |||
291 | } | |||
292 | else if( IsXMLToken( rLocalName, XML_DISTANCE ) ) | |||
293 | { | |||
294 | mrImport.GetMM100UnitConverter().convertMeasureToCore(mnDistance, | |||
295 | rValue); | |||
296 | return; | |||
297 | } | |||
298 | else if( IsXMLToken( rLocalName, XML_FOCAL_LENGTH ) ) | |||
299 | { | |||
300 | mrImport.GetMM100UnitConverter().convertMeasureToCore(mnFocalLength, | |||
301 | rValue); | |||
302 | return; | |||
303 | } | |||
304 | else if( IsXMLToken( rLocalName, XML_SHADOW_SLANT ) ) | |||
305 | { | |||
306 | ::sax::Converter::convertNumber(mnShadowSlant, rValue); | |||
307 | return; | |||
308 | } | |||
309 | else if( IsXMLToken( rLocalName, XML_SHADE_MODE ) ) | |||
310 | { | |||
311 | if( IsXMLToken( rValue, XML_FLAT ) ) | |||
312 | mxShadeMode = drawing::ShadeMode_FLAT; | |||
313 | else if( IsXMLToken( rValue, XML_PHONG ) ) | |||
314 | mxShadeMode = drawing::ShadeMode_PHONG; | |||
315 | else if( IsXMLToken( rValue, XML_GOURAUD ) ) | |||
316 | mxShadeMode = drawing::ShadeMode_SMOOTH; | |||
317 | else | |||
318 | mxShadeMode = drawing::ShadeMode_DRAFT; | |||
319 | return; | |||
320 | } | |||
321 | else if( IsXMLToken( rLocalName, XML_AMBIENT_COLOR ) ) | |||
322 | { | |||
323 | ::sax::Converter::convertColor(maAmbientColor, rValue); | |||
324 | return; | |||
325 | } | |||
326 | else if( IsXMLToken( rLocalName, XML_LIGHTING_MODE ) ) | |||
327 | { | |||
328 | (void)::sax::Converter::convertBool(mbLightingMode, rValue); | |||
329 | return; | |||
330 | } | |||
331 | } | |||
332 | ||||
333 | /** this sets the scene attributes at this propertyset */ | |||
334 | void SdXML3DSceneAttributesHelper::setSceneAttributes( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ) | |||
335 | { | |||
336 | uno::Any aAny; | |||
337 | ||||
338 | // world transformation | |||
339 | if(mbSetTransform) | |||
340 | { | |||
341 | xPropSet->setPropertyValue("D3DTransformMatrix", uno::Any(mxHomMat)); | |||
342 | } | |||
343 | ||||
344 | // distance | |||
345 | xPropSet->setPropertyValue("D3DSceneDistance", uno::Any(mnDistance)); | |||
346 | // focalLength | |||
347 | xPropSet->setPropertyValue("D3DSceneFocalLength", uno::Any(mnFocalLength)); | |||
348 | // shadowSlant | |||
349 | xPropSet->setPropertyValue("D3DSceneShadowSlant", uno::Any(static_cast<sal_Int16>(mnShadowSlant))); | |||
350 | // shadeMode | |||
351 | xPropSet->setPropertyValue("D3DSceneShadeMode", uno::Any(mxShadeMode)); | |||
352 | // ambientColor | |||
353 | xPropSet->setPropertyValue("D3DSceneAmbientColor", uno::Any(maAmbientColor)); | |||
354 | // lightingMode | |||
355 | xPropSet->setPropertyValue("D3DSceneTwoSidedLighting", uno::Any(mbLightingMode)); | |||
356 | ||||
357 | if( !maList.empty() ) | |||
358 | { | |||
359 | uno::Any aAny2; | |||
360 | uno::Any aAny3; | |||
361 | ||||
362 | // set lights | |||
363 | for( size_t a = 0; a < maList.size(); a++) | |||
364 | { | |||
365 | SdXML3DLightContext* pCtx = maList[ a ].get(); | |||
366 | ||||
367 | // set anys | |||
368 | aAny <<= pCtx->GetDiffuseColor(); | |||
369 | drawing::Direction3D aLightDir; | |||
370 | aLightDir.DirectionX = pCtx->GetDirection().getX(); | |||
371 | aLightDir.DirectionY = pCtx->GetDirection().getY(); | |||
372 | aLightDir.DirectionZ = pCtx->GetDirection().getZ(); | |||
373 | aAny2 <<= aLightDir; | |||
374 | aAny3 <<= pCtx->GetEnabled(); | |||
375 | ||||
376 | switch(a) | |||
377 | { | |||
378 | case 0: | |||
379 | { | |||
380 | xPropSet->setPropertyValue("D3DSceneLightColor1", aAny); | |||
381 | xPropSet->setPropertyValue("D3DSceneLightDirection1", aAny2); | |||
382 | xPropSet->setPropertyValue("D3DSceneLightOn1", aAny3); | |||
383 | break; | |||
384 | } | |||
385 | case 1: | |||
386 | { | |||
387 | xPropSet->setPropertyValue("D3DSceneLightColor2", aAny); | |||
388 | xPropSet->setPropertyValue("D3DSceneLightDirection2", aAny2); | |||
389 | xPropSet->setPropertyValue("D3DSceneLightOn2", aAny3); | |||
390 | break; | |||
391 | } | |||
392 | case 2: | |||
393 | { | |||
394 | xPropSet->setPropertyValue("D3DSceneLightColor3", aAny); | |||
395 | xPropSet->setPropertyValue("D3DSceneLightDirection3", aAny2); | |||
396 | xPropSet->setPropertyValue("D3DSceneLightOn3", aAny3); | |||
397 | break; | |||
398 | } | |||
399 | case 3: | |||
400 | { | |||
401 | xPropSet->setPropertyValue("D3DSceneLightColor4", aAny); | |||
402 | xPropSet->setPropertyValue("D3DSceneLightDirection4", aAny2); | |||
403 | xPropSet->setPropertyValue("D3DSceneLightOn4", aAny3); | |||
404 | break; | |||
405 | } | |||
406 | case 4: | |||
407 | { | |||
408 | xPropSet->setPropertyValue("D3DSceneLightColor5", aAny); | |||
409 | xPropSet->setPropertyValue("D3DSceneLightDirection5", aAny2); | |||
410 | xPropSet->setPropertyValue("D3DSceneLightOn5", aAny3); | |||
411 | break; | |||
412 | } | |||
413 | case 5: | |||
414 | { | |||
415 | xPropSet->setPropertyValue("D3DSceneLightColor6", aAny); | |||
416 | xPropSet->setPropertyValue("D3DSceneLightDirection6", aAny2); | |||
417 | xPropSet->setPropertyValue("D3DSceneLightOn6", aAny3); | |||
418 | break; | |||
419 | } | |||
420 | case 6: | |||
421 | { | |||
422 | xPropSet->setPropertyValue("D3DSceneLightColor7", aAny); | |||
423 | xPropSet->setPropertyValue("D3DSceneLightDirection7", aAny2); | |||
424 | xPropSet->setPropertyValue("D3DSceneLightOn7", aAny3); | |||
425 | break; | |||
426 | } | |||
427 | case 7: | |||
428 | { | |||
429 | xPropSet->setPropertyValue("D3DSceneLightColor8", aAny); | |||
430 | xPropSet->setPropertyValue("D3DSceneLightDirection8", aAny2); | |||
431 | xPropSet->setPropertyValue("D3DSceneLightOn8", aAny3); | |||
432 | break; | |||
433 | } | |||
434 | } | |||
435 | } | |||
436 | } | |||
437 | ||||
438 | // CameraGeometry and camera settings | |||
439 | drawing::CameraGeometry aCamGeo; | |||
440 | aCamGeo.vrp.PositionX = maVRP.getX(); | |||
441 | aCamGeo.vrp.PositionY = maVRP.getY(); | |||
442 | aCamGeo.vrp.PositionZ = maVRP.getZ(); | |||
443 | aCamGeo.vpn.DirectionX = maVPN.getX(); | |||
444 | aCamGeo.vpn.DirectionY = maVPN.getY(); | |||
445 | aCamGeo.vpn.DirectionZ = maVPN.getZ(); | |||
446 | aCamGeo.vup.DirectionX = maVUP.getX(); | |||
447 | aCamGeo.vup.DirectionY = maVUP.getY(); | |||
448 | aCamGeo.vup.DirectionZ = maVUP.getZ(); | |||
449 | xPropSet->setPropertyValue("D3DCameraGeometry", uno::Any(aCamGeo)); | |||
450 | ||||
451 | // #91047# set drawing::ProjectionMode AFTER camera geometry is set | |||
452 | // projection "D3DScenePerspective" drawing::ProjectionMode | |||
453 | xPropSet->setPropertyValue("D3DScenePerspective", uno::Any(mxPrjMode)); | |||
454 | } | |||
455 | ||||
456 | /* 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 | |
20 | #ifndef INCLUDED_XMLOFF_XMLICTXT_HXX |
21 | #define INCLUDED_XMLOFF_XMLICTXT_HXX |
22 | |
23 | #include <sal/config.h> |
24 | #include <xmloff/dllapi.h> |
25 | #include <sal/types.h> |
26 | #include <com/sun/star/xml/sax/XFastContextHandler.hpp> |
27 | #include <com/sun/star/lang/XTypeProvider.hpp> |
28 | #include <rtl/ustring.hxx> |
29 | #include <xmloff/namespacemap.hxx> |
30 | #include <memory> |
31 | |
32 | namespace com::sun::star::xml::sax { class XAttributeList; } |
33 | |
34 | class SvXMLImport; |
35 | |
36 | class SvXMLImportContext; |
37 | |
38 | typedef rtl::Reference<SvXMLImportContext> SvXMLImportContextRef; |
39 | |
40 | /** |
41 | This class deliberately does not support XWeak, to improve performance when loading |
42 | large documents. |
43 | */ |
44 | class XMLOFF_DLLPUBLIC__attribute__ ((visibility("default"))) SvXMLImportContext : public css::xml::sax::XFastContextHandler, |
45 | public css::lang::XTypeProvider |
46 | |
47 | { |
48 | friend class SvXMLImport; |
49 | |
50 | SvXMLImport& mrImport; |
51 | OUString maLocalName; |
52 | std::unique_ptr<SvXMLNamespaceMap> m_pRewindMap; |
53 | oslInterlockedCount m_nRefCount; |
54 | sal_uInt16 mnPrefix; |
55 | bool mbPrefixAndLocalNameFilledIn; |
56 | |
57 | SAL_DLLPRIVATE__attribute__ ((visibility("hidden"))) std::unique_ptr<SvXMLNamespaceMap> TakeRewindMap() { return std::move(m_pRewindMap); } |
58 | SAL_DLLPRIVATE__attribute__ ((visibility("hidden"))) void PutRewindMap(std::unique_ptr<SvXMLNamespaceMap> p) { m_pRewindMap = std::move(p); } |
59 | |
60 | protected: |
61 | |
62 | SvXMLImport& GetImport() { return mrImport; } |
63 | const SvXMLImport& GetImport() const { return mrImport; } |
64 | |
65 | public: |
66 | |
67 | bool IsPrefixFilledIn() const { return mnPrefix != 0; } |
68 | sal_uInt16 GetPrefix() const { assert(mbPrefixAndLocalNameFilledIn && "those fields not filled, probably fast-parser context")(static_cast <bool> (mbPrefixAndLocalNameFilledIn && "those fields not filled, probably fast-parser context") ? void (0) : __assert_fail ("mbPrefixAndLocalNameFilledIn && \"those fields not filled, probably fast-parser context\"" , "/home/maarten/src/libreoffice/core/include/xmloff/xmlictxt.hxx" , 68, __extension__ __PRETTY_FUNCTION__)); return mnPrefix; } |
69 | const OUString& GetLocalName() const { assert(mbPrefixAndLocalNameFilledIn && "those fields not filled, probably fast-parser context")(static_cast <bool> (mbPrefixAndLocalNameFilledIn && "those fields not filled, probably fast-parser context") ? void (0) : __assert_fail ("mbPrefixAndLocalNameFilledIn && \"those fields not filled, probably fast-parser context\"" , "/home/maarten/src/libreoffice/core/include/xmloff/xmlictxt.hxx" , 69, __extension__ __PRETTY_FUNCTION__)); return maLocalName; } |
70 | |
71 | /** A contexts constructor does anything that is required if an element |
72 | * starts. Namespace processing has been done already. |
73 | * Note that virtual methods cannot be used inside constructors. Use |
74 | * StartElement instead if this is required. */ |
75 | SvXMLImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, |
76 | const OUString& rLName ); |
77 | |
78 | SvXMLImportContext( SvXMLImport& rImport ); |
79 | |
80 | /** A contexts destructor does anything that is required if an element |
81 | * ends. By default, nothing is done. |
82 | * Note that virtual methods cannot be used inside destructors. Use |
83 | * EndElement instead if this is required. */ |
84 | virtual ~SvXMLImportContext(); |
85 | |
86 | /** Create a children element context. By default, the import's |
87 | * CreateContext method is called to create a new default context. */ |
88 | virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, |
89 | const OUString& rLocalName, |
90 | const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ); |
91 | |
92 | /** StartElement is called after a context has been constructed and |
93 | * before an elements context is parsed. It may be used for actions that |
94 | * require virtual methods. The default is to do nothing. */ |
95 | virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ); |
96 | |
97 | /** EndElement is called before a context will be destructed, but |
98 | * after an elements context has been parsed. It may be used for actions |
99 | * that require virtual methods. The default is to do nothing. */ |
100 | virtual void EndElement(); |
101 | |
102 | /** This method is called for all characters that are contained in the |
103 | * current element. The default is to ignore them. */ |
104 | virtual void Characters( const OUString& rChars ); |
105 | |
106 | // css::xml::sax::XFastContextHandler: |
107 | virtual void SAL_CALL startFastElement (sal_Int32 Element, |
108 | const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override; |
109 | |
110 | virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, |
111 | const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; |
112 | |
113 | virtual void SAL_CALL endFastElement(sal_Int32 Element) override; |
114 | |
115 | virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name) override; |
116 | |
117 | virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, |
118 | const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs) override; |
119 | |
120 | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext( |
121 | const OUString & Namespace, const OUString & Name, |
122 | const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; |
123 | |
124 | virtual void SAL_CALL characters(const OUString & aChars) override; |
125 | |
126 | // XInterface |
127 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) final override; |
128 | virtual void SAL_CALL acquire() throw () final override |
129 | { osl_atomic_increment(&m_nRefCount)__sync_add_and_fetch((&m_nRefCount), 1); } |
130 | virtual void SAL_CALL release() throw () final override |
131 | { if (osl_atomic_decrement(&m_nRefCount)__sync_sub_and_fetch((&m_nRefCount), 1) == 0) delete this; } |
132 | |
133 | // XTypeProvider |
134 | virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) final override; |
135 | virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) final override; |
136 | }; |
137 | |
138 | #endif // INCLUDED_XMLOFF_XMLICTXT_HXX |
139 | |
140 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |