Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / view / main / DummyXShape.cxx
blob035353dbd795d132be1e0b9716e6b7470c21f859
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/.
8 */
9 #include "DummyXShape.hxx"
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 #include <fstream>
15 #include <algorithm>
16 #include <stdlib.h>
17 #include <string.h>
19 #include <CommonConverters.hxx>
21 #include <rtl/ustring.hxx>
23 #include <vcl/window.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/svapp.hxx>
26 #include <tools/gen.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/implbase.hxx>
29 #include <editeng/unoprnms.hxx>
30 #include <vcl/unohelp.hxx>
32 #include <basegfx/point/b2dpoint.hxx>
33 #include <basegfx/matrix/b3dhommatrix.hxx>
35 #include <com/sun/star/beans/Property.hpp>
37 #include <com/sun/star/awt/XBitmap.hpp>
39 #define ENABLE_DEBUG_PROPERTIES 0
41 using namespace com::sun::star;
43 using namespace std;
45 namespace chart {
47 namespace dummy {
49 #if 0
51 std::ostream& operator<<(std::ostream& rStrm, const awt::Point& rPoint)
53 rStrm << rPoint.X << "," << rPoint.Y;
54 return rStrm;
57 std::ostream& operator<<(std::ostream& rStrm, const awt::Size& rSize)
59 rStrm << rSize.Width << "," << rSize.Height;
60 return rStrm;
63 #endif
65 bool TextCache::hasEntry(const TextCacheKey& rKey)
67 return maCache.find(rKey) != maCache.end();
70 BitmapEx& TextCache::getBitmap(const TextCacheKey& rKey)
72 return maCache.find(rKey)->second;
75 void TextCache::insertBitmap(const TextCacheKey& rKey, const BitmapEx& rBitmap)
77 maCache.insert(std::pair<TextCacheKey, BitmapEx>(rKey, rBitmap));
80 class DummyPropertySetInfo : public cppu::WeakImplHelper<
81 css::beans::XPropertySetInfo >
83 public:
84 explicit DummyPropertySetInfo(const std::map<OUString, uno::Any>& rProps ):
85 mrProperties(rProps) {}
87 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& rName ) override;
89 virtual beans::Property SAL_CALL getPropertyByName( const OUString& rName ) override;
91 virtual uno::Sequence< beans::Property > SAL_CALL getProperties() override;
93 private:
94 const std::map<OUString, uno::Any>& mrProperties;
97 sal_Bool SAL_CALL DummyPropertySetInfo::hasPropertyByName( const OUString& rName )
99 return mrProperties.find(rName) != mrProperties.end();
102 beans::Property SAL_CALL DummyPropertySetInfo::getPropertyByName( const OUString& rName )
104 beans::Property aRet;
105 if(mrProperties.find(rName) == mrProperties.end())
106 throw beans::UnknownPropertyException();
108 std::map<OUString, uno::Any>::const_iterator itr = mrProperties.find(rName);
109 aRet.Name = rName;
110 aRet.Type = itr->second.getValueType();
112 return aRet;
115 uno::Sequence< beans::Property > SAL_CALL DummyPropertySetInfo::getProperties()
117 uno::Sequence< beans::Property > aRet(mrProperties.size());
119 size_t i = 0;
120 for (auto const& property : mrProperties)
122 beans::Property aProp;
124 aProp.Name = property.first;
125 aProp.Type = property.second.getValueType();
126 aRet[i++] = aProp;
128 return aRet;
131 namespace {
133 struct PrintProperties
135 #if ENABLE_DEBUG_PROPERTIES
136 void operator()(const std::pair<OUString, uno::Any>& rProp)
138 SAL_INFO("chart2.opengl.properties", "Property: " << rProp.first);
140 #else
141 void operator()(const std::pair<OUString, uno::Any>&)
144 #endif
147 void debugProperties(std::map<OUString, uno::Any>& rProperties)
149 for_each(rProperties.begin(), rProperties.end(), PrintProperties());
154 DummyXShape::DummyXShape()
158 OUString SAL_CALL DummyXShape::getName()
160 return maName;
163 void SAL_CALL DummyXShape::setName( const OUString& rName )
165 maName = rName;
168 awt::Point SAL_CALL DummyXShape::getPosition()
170 return maPosition;
173 void SAL_CALL DummyXShape::setPosition( const awt::Point& rPoint )
175 maPosition = rPoint;
178 awt::Size SAL_CALL DummyXShape::getSize()
180 return maSize;
183 void SAL_CALL DummyXShape::setSize( const awt::Size& rSize )
185 maSize = rSize;
188 OUString SAL_CALL DummyXShape::getShapeType()
190 return OUString("dummy shape");
193 uno::Reference< beans::XPropertySetInfo > SAL_CALL DummyXShape::getPropertySetInfo()
195 return new DummyPropertySetInfo(maProperties);
198 void SAL_CALL DummyXShape::setPropertyValue( const OUString& rName, const uno::Any& rValue)
200 SAL_INFO("chart2", "DummyXShape::setProperty: " << rName << " Any");
201 maProperties[rName] = rValue;
202 if(rName == "Transformation")
204 SAL_INFO("chart2.opengl", "Transformation");
208 uno::Any SAL_CALL DummyXShape::getPropertyValue( const OUString& rName )
210 SAL_INFO("chart2.opengl", "DummyXShape::getPropertyValue: " << rName);
211 std::map<OUString, uno::Any>::iterator itr = maProperties.find(rName);
212 if(itr != maProperties.end())
213 return itr->second;
215 return uno::Any();
218 void SAL_CALL DummyXShape::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
222 void SAL_CALL DummyXShape::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
226 void SAL_CALL DummyXShape::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
230 void SAL_CALL DummyXShape::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
234 void SAL_CALL DummyXShape::setPropertyValues( const uno::Sequence< OUString >& rNames,
235 const uno::Sequence< uno::Any >& rValues)
237 size_t n = std::min<size_t>(rNames.getLength(), rValues.getLength());
238 for(size_t i = 0; i < n; ++i)
240 maProperties[rNames[i]] = rValues[i];
244 uno::Sequence< uno::Any > SAL_CALL DummyXShape::getPropertyValues(
245 const uno::Sequence< OUString >& rNames)
247 uno::Sequence< uno::Any > aValues(rNames.getLength());
248 for(sal_Int32 i = 0; i < rNames.getLength(); ++i)
250 OUString aName = rNames[i];
252 std::map<OUString, uno::Any>::iterator itr = maProperties.find(aName);
253 if(itr != maProperties.end())
254 aValues[i] = itr->second;
256 return aValues;
259 void SAL_CALL DummyXShape::addPropertiesChangeListener( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& )
263 void SAL_CALL DummyXShape::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& )
267 void SAL_CALL DummyXShape::firePropertiesChangeEvent( const uno::Sequence< OUString >& ,
268 const uno::Reference< beans::XPropertiesChangeListener >& )
272 OUString SAL_CALL DummyXShape::getImplementationName()
274 return OUString("DummyXShape");
277 namespace {
279 uno::Sequence< OUString > const & listSupportedServices()
281 static const uno::Sequence< OUString > aSupportedServices{
282 "com.sun.star.drawing.Shape",
283 "com.sun.star.container.Named",
284 "com.sun.star.beans.PropertySet"};
285 return aSupportedServices;
290 uno::Sequence< OUString > SAL_CALL DummyXShape::getSupportedServiceNames()
292 return listSupportedServices();
295 sal_Bool SAL_CALL DummyXShape::supportsService( const OUString& rServiceName )
297 return cppu::supportsService(this, rServiceName);
300 uno::Reference< uno::XInterface > SAL_CALL DummyXShape::getParent()
302 return mxParent;
305 void SAL_CALL DummyXShape::setParent( const uno::Reference< uno::XInterface >& xParent )
307 mxParent = xParent;
310 void DummyXShape::render()
312 SAL_WARN("chart2.opengl", "maybe a missing implementation in a subclass?");
315 namespace {
317 void setProperties( const uno::Reference< beans::XPropertySet > & xPropSet, const tPropertyNameMap& rPropertyNameMap,
318 std::map<OUString, uno::Any>& rTargetMap)
320 tNameSequence aNames;
321 tAnySequence aValues;
322 PropertyMapper::getMultiPropertyLists( aNames, aValues,
323 xPropSet, rPropertyNameMap );
325 sal_Int32 nSize = std::min(aNames.getLength(), aValues.getLength());
326 for(sal_Int32 i = 0; i < nSize; ++i)
328 rTargetMap[aNames[i]] = aValues[i];
332 void setProperties( const tNameSequence& rNames, const tAnySequence& rValues,
333 std::map<OUString, uno::Any>& rTargetMap)
335 sal_Int32 nSize = std::min(rNames.getLength(), rValues.getLength());
336 for(sal_Int32 i = 0; i < nSize; ++i)
338 rTargetMap[rNames[i]] = rValues[i];
344 DummyCube::DummyCube(const drawing::Position3D &rPos, const drawing::Direction3D& rSize,
345 const uno::Reference< beans::XPropertySet > & xPropSet,
346 const tPropertyNameMap& rPropertyNameMap )
348 setPosition(Position3DToAWTPoint(rPos));
349 setSize(Direction3DToAWTSize(rSize));
350 setProperties(xPropSet, rPropertyNameMap, maProperties);
353 DummyCylinder::DummyCylinder(const drawing::Position3D& rPos, const drawing::Direction3D& rSize )
355 setPosition(Position3DToAWTPoint(rPos));
356 setSize(Direction3DToAWTSize(rSize));
359 DummyPyramid::DummyPyramid(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
360 const uno::Reference< beans::XPropertySet > & xPropSet,
361 const tPropertyNameMap& rPropertyNameMap)
363 setPosition(Position3DToAWTPoint(rPos));
364 setSize(Direction3DToAWTSize(rSize));
365 setProperties(xPropSet, rPropertyNameMap, maProperties);
368 DummyCone::DummyCone(const drawing::Position3D& rPos, const drawing::Direction3D& rSize)
370 setPosition(Position3DToAWTPoint(rPos));
371 setSize(Direction3DToAWTSize(rSize));
374 DummyPieSegment2D::DummyPieSegment2D(double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree,
375 double fUnitCircleInnerRadius, double fUnitCircleOuterRadius,
376 const drawing::Direction3D& rOffset, const drawing::HomogenMatrix& rUnitCircleToScene):
377 mfUnitCircleStartAngleDegree(fUnitCircleStartAngleDegree),
378 mfUnitCircleWidthAngleDegree(fUnitCircleWidthAngleDegree),
379 mfUnitCircleInnerRadius(fUnitCircleInnerRadius),
380 mfUnitCircleOuterRadius(fUnitCircleOuterRadius),
381 maOffset(rOffset),
382 maUnitCircleToScene(rUnitCircleToScene)
386 void DummyPieSegment2D::render()
388 SAL_INFO("chart2.opengl", "render DummyPieSegment2D");
389 DummyChart* pChart = getRootShape();
391 while(mfUnitCircleWidthAngleDegree>360)
392 mfUnitCircleWidthAngleDegree -= 360.0;
393 while(mfUnitCircleWidthAngleDegree<0)
394 mfUnitCircleWidthAngleDegree += 360.0;
396 pChart->m_GLRender.GeneratePieSegment2D(mfUnitCircleInnerRadius, mfUnitCircleOuterRadius,
397 mfUnitCircleStartAngleDegree, mfUnitCircleWidthAngleDegree);
399 sal_uInt8 nAlpha = 255;
400 std::map<OUString, uno::Any>::const_iterator itr = maProperties.find(UNO_NAME_FILL_TRANSPARENCE);
401 if(itr != maProperties.end())
403 nAlpha = 255 - itr->second.get<sal_Int32>();
406 itr = maProperties.find(UNO_NAME_FILLCOLOR);
407 if(itr != maProperties.end())
409 sal_Int32 nColor = itr->second.get<sal_Int32>();
410 pChart->m_GLRender.SetColor(nColor, nAlpha);
413 float nSize = std::max<float>(maUnitCircleToScene.Line1.Column1, maUnitCircleToScene.Line2.Column2);
414 pChart->m_GLRender.RenderPieSegment2DShape(nSize, maUnitCircleToScene.Line1.Column4 + maOffset.DirectionX,
415 maUnitCircleToScene.Line2.Column4 + maOffset.DirectionY);
419 DummyStripe::DummyStripe(const uno::Reference< beans::XPropertySet > & xPropSet,
420 const tPropertyNameMap& rPropertyNameMap )
422 setProperties(xPropSet, rPropertyNameMap, maProperties);
425 DummyArea2D::DummyArea2D(const drawing::PointSequenceSequence& rShape):
426 maShapes(rShape)
430 void DummyArea2D::render()
432 SAL_INFO("chart2.opengl", "render DummyArea2D");
433 DummyChart* pChart = getRootShape();
434 sal_Int32 nPointssCount = maShapes.getLength();
435 for(sal_Int32 i = 0; i < nPointssCount; i++)
437 const css::uno::Sequence<css::awt::Point>& points = maShapes[i];
438 sal_Int32 nPointsCount = points.getLength();
439 for(sal_Int32 j = 0; j < nPointsCount; j++)
441 const css::awt::Point& p = points[j];
442 pChart->m_GLRender.SetArea2DShapePoint(static_cast<float>(p.X), static_cast<float>(p.Y), nPointsCount);
446 std::map<OUString, uno::Any>::const_iterator itr = maProperties.find(UNO_NAME_FILLCOLOR);
447 if(itr != maProperties.end())
449 sal_Int32 nColor = itr->second.get<sal_Int32>();
450 pChart->m_GLRender.SetColor(nColor, 255);
453 pChart->m_GLRender.RenderArea2DShape();
456 DummySymbol2D::DummySymbol2D(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
457 sal_Int32 nStandardSymbol, sal_Int32 nFillColor):
458 mnStandardSymbol(nStandardSymbol),
459 mnFillColor(nFillColor)
461 setPosition(Position3DToAWTPoint(rPos));
462 setSize(Direction3DToAWTSize(rSize));
465 void DummySymbol2D::render()
467 DummyChart* pChart = getRootShape();
469 pChart->m_GLRender.SetColor(mnFillColor, 255);
471 pChart->m_GLRender.RenderSymbol2DShape(maPosition.X, maPosition.Y, mnStandardSymbol);
474 DummyCircle::DummyCircle(const awt::Point& rPos, const awt::Size& rSize)
476 setPosition(rPos);
477 setSize(rSize);
480 void DummyCircle::render()
482 SAL_INFO("chart2.opengl", "render DummyCircle");
483 debugProperties(maProperties);
484 DummyChart* pChart = getRootShape();
486 sal_uInt8 nAlpha = 255;
487 std::map<OUString, uno::Any>::const_iterator itr = maProperties.find("FillTransparence");
488 if(itr != maProperties.end())
490 sal_Int32 nTrans = itr->second.get<sal_Int32>()/100.0*255;
491 nAlpha = 255 - static_cast<sal_uInt8>(nTrans & 0xFF);
493 if(nAlpha == 0)
494 return;
497 itr = maProperties.find("FillColor");
498 if(itr != maProperties.end())
500 sal_Int32 nColor = itr->second.get<sal_Int32>();
501 pChart->m_GLRender.SetColor(nColor, nAlpha);
503 else
504 SAL_WARN("chart2.opengl", "missing color");
506 pChart->m_GLRender.Bubble2DShapePoint(maPosition.X, maPosition.Y,
507 maSize.Width, maSize.Height);
508 pChart->m_GLRender.RenderBubble2FBO();
511 namespace {
513 void setProperties( const VLineProperties& rLineProperties, std::map<OUString, uno::Any>& rTargetProps )
515 //Transparency
516 if(rLineProperties.Transparence.hasValue())
517 rTargetProps.insert(std::pair<OUString, uno::Any>(
518 UNO_NAME_LINETRANSPARENCE, rLineProperties.Transparence));
520 //LineStyle
521 if(rLineProperties.LineStyle.hasValue())
522 rTargetProps.insert(std::pair<OUString, uno::Any>(
523 UNO_NAME_LINESTYLE, rLineProperties.LineStyle));
525 //LineWidth
526 if(rLineProperties.Width.hasValue())
527 rTargetProps.insert(std::pair<OUString, uno::Any>(
528 UNO_NAME_LINEWIDTH, rLineProperties.Width));
530 //LineColor
531 if(rLineProperties.Color.hasValue())
532 rTargetProps.insert(std::pair<OUString, uno::Any>(
533 UNO_NAME_LINECOLOR, rLineProperties.Color));
535 //LineDashName
536 if(rLineProperties.DashName.hasValue())
537 rTargetProps.insert(std::pair<OUString, uno::Any>(
538 "LineDashName", rLineProperties.DashName));
543 DummyLine3D::DummyLine3D(const VLineProperties& rLineProperties)
545 setProperties(rLineProperties, maProperties);
548 DummyLine2D::DummyLine2D(const drawing::PointSequenceSequence& rPoints, const VLineProperties* pLineProperties):
549 maPoints(rPoints)
551 if(pLineProperties)
552 setProperties(*pLineProperties, maProperties);
555 DummyLine2D::DummyLine2D(const awt::Size& rSize, const awt::Point& rPosition)
557 setPosition(rPosition);
558 setSize(rSize);
561 void DummyLine2D::render()
563 SAL_INFO("chart2.opengl", "rendering line 2D");
564 debugProperties(maProperties);
565 DummyChart* pChart = getRootShape();
567 //add style and transparency
568 std::map< OUString, uno::Any >::const_iterator itr = maProperties.find(UNO_NAME_LINESTYLE);
569 if (itr != maProperties.end())
571 uno::Any cow = itr->second;
572 drawing::LineStyle nStyle = cow.get<drawing::LineStyle>();
573 if (nStyle == drawing::LineStyle_NONE)
575 // nothing to render
576 return;
580 sal_uInt8 nAlpha = 255;
581 itr = maProperties.find("LineTransparence");
582 if(itr != maProperties.end())
584 uno::Any al = itr->second;
585 nAlpha = 255 - al.get<sal_Int32>();
588 itr = maProperties.find(UNO_NAME_LINECOLOR);
589 if(itr != maProperties.end())
591 //set line color
592 uno::Any co = itr->second;
593 sal_Int32 nColorValue = co.get<sal_Int32>();
594 SAL_INFO("chart2.opengl", "line colorvalue = " << nColorValue);
595 sal_uInt8 R = (nColorValue & 0x00FF0000) >> 16;
596 sal_uInt8 G = (nColorValue & 0x0000FF00) >> 8;
597 sal_uInt8 B = (nColorValue & 0x000000FF);
598 pChart->m_GLRender.SetLine2DColor(R, G, B, nAlpha);
600 SAL_INFO("chart2.opengl", "line colorvalue = " << nColorValue << ", R = " << static_cast<int>(R) << ", G = " << static_cast<int>(G) << ", B = " << static_cast<int>(B));
602 else
603 SAL_WARN("chart2.opengl", "no line color set");
605 //set line width
606 itr = maProperties.find(UNO_NAME_LINEWIDTH);
607 if(itr != maProperties.end())
609 uno::Any cow = itr->second;
610 sal_Int32 nWidth = cow.get<sal_Int32>();
611 pChart->m_GLRender.SetLine2DWidth(nWidth);
613 SAL_INFO("chart2.opengl", "width = " << nWidth);
615 else
616 SAL_WARN("chart2.opengl", "no line width set");
618 sal_Int32 pointsscount = maPoints.getLength();
619 for(sal_Int32 i = 0; i < pointsscount; i++)
621 css::uno::Sequence<css::awt::Point>& points = maPoints[i];
622 sal_Int32 pointscount = points.getLength();
623 for(sal_Int32 j = 0; j < pointscount; j++)
625 css::awt::Point& p = points[j];
626 pChart->m_GLRender.SetLine2DShapePoint(static_cast<float>(p.X), static_cast<float>(p.Y), pointscount);
630 pChart->m_GLRender.RenderLine2FBO();
634 DummyRectangle::DummyRectangle()
638 DummyRectangle::DummyRectangle(const awt::Size& rSize)
640 setSize(rSize);
643 DummyRectangle::DummyRectangle(const awt::Size& rSize, const awt::Point& rPoint, const tNameSequence& rNames,
644 const tAnySequence& rValues)
646 setSize(rSize);
647 setPosition(rPoint);
648 setProperties(rNames, rValues, maProperties);
651 void DummyRectangle::render()
653 SAL_INFO("chart2.opengl", "render DummyRectangle");
654 debugProperties(maProperties);
655 DummyChart* pChart = getRootShape();
656 std::map< OUString, uno::Any >::const_iterator itr = maProperties.find("Invisible");
657 if(itr != maProperties.end())
659 return;
662 bool bFill = true;
663 drawing::FillStyle eStyle = drawing::FillStyle_NONE;
664 itr = maProperties.find("FillStyle");
665 if(itr != maProperties.end())
667 eStyle = itr->second.get<drawing::FillStyle>();
668 if(eStyle == drawing::FillStyle_NONE)
670 bFill = false;
674 itr = maProperties.find("FillColor");
675 if(itr != maProperties.end())
677 uno::Any co = itr->second;
678 Color nColorValue(co.get<sal_Int32>());
679 //here FillStyle works for background color and gradients
680 pChart->m_GLRender.SetBackGroundColor(nColorValue, nColorValue, eStyle);
683 bool bBorder = true;
684 itr = maProperties.find(UNO_NAME_LINESTYLE);
685 if (itr != maProperties.end())
687 uno::Any cow = itr->second;
688 drawing::LineStyle nStyle = cow.get<drawing::LineStyle>();
689 if (nStyle == drawing::LineStyle_NONE)
691 bBorder = false;
695 //TODO: moggi: correct handling of gradients
696 itr = maProperties.find("FillTransparenceGradientName");
697 if (itr != maProperties.end())
699 uno::Any co = itr->second;
700 rtl::OUString aGradientValue = co.get<rtl::OUString>();
701 if (aGradientValue.endsWith("1"))
703 pChart->m_GLRender.SetChartTransparencyGradient(1);
706 pChart->m_GLRender.RectangleShapePoint(maPosition.X, maPosition.Y, maSize.Width, maSize.Height);
707 pChart->m_GLRender.RenderRectangleShape(bBorder, bFill);
710 namespace {
712 struct FontAttribSetter
714 explicit FontAttribSetter(vcl::Font& rFont):
715 mrFont(rFont) {}
717 void operator()(const std::pair<OUString, uno::Any>& rProp)
719 const OUString& rPropName = rProp.first;
720 if(rPropName == "CharFontName")
722 OUString aName = rProp.second.get<OUString>();
723 mrFont.SetFamilyName(aName);
725 else if(rPropName == "CharColor")
727 sal_Int32 nColor = rProp.second.get<sal_Int32>();
728 mrFont.SetFillColor(Color(nColor));
730 else if(rPropName == "CharHeight")
732 float fHeight = rProp.second.get<float>();
733 mrFont.SetFontSize(Size(0,(fHeight*127+36)/72)); //taken from the MCW implementation
735 else if(rPropName == "CharUnderline")
737 FontLineStyle eUnderline = static_cast<FontLineStyle>(rProp.second.get<sal_Int16>());
738 mrFont.SetUnderline(eUnderline);
740 else if(rPropName == "CharWeight")
742 float fWeight = rProp.second.get<float>();
743 FontWeight eFontWeight = vcl::unohelper::ConvertFontWeight(fWeight);
744 mrFont.SetWeight(eFontWeight);
746 else if(rPropName == "ChartWidth")
748 float fWidth = rProp.second.get<float>();
749 FontWidth eFontWidth = vcl::unohelper::ConvertFontWidth(fWidth);
750 mrFont.SetAverageFontWidth(eFontWidth);
753 private:
754 vcl::Font& mrFont;
759 DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
760 const tAnySequence& rValues, const uno::Any& rTrans, uno::Reference< drawing::XShapes > const & xTarget, double nRotation ):
761 maTrans(rTrans),
762 mnRotation(nRotation)
764 setProperties(rNames, rValues, maProperties);
766 xTarget->add(this);
767 DummyChart* pChart = getRootShape();
768 TextCache& rCache = pChart->getTextCache();
769 TextCache::TextCacheKey aKey;
770 aKey.maText = rText;
771 aKey.maProperties = maProperties;
772 int bmpWidth;
773 int bmpHeight;
774 if(rCache.hasEntry(aKey))
776 maBitmap = rCache.getBitmap(aKey);
777 bmpWidth = maBitmap.GetSizePixel().Width();
778 bmpHeight = maBitmap.GetSizePixel().Height();
780 else
782 vcl::Font aFont;
783 std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont));
784 ScopedVclPtrInstance< VirtualDevice > pDevice(*Application::GetDefaultDevice(),
785 DeviceFormat::DEFAULT, DeviceFormat::DEFAULT);
786 pDevice->Erase();
787 tools::Rectangle aRect;
788 pDevice->SetFont(aFont);
789 pDevice->GetTextBoundRect(aRect, rText);
790 int screenWidth = aRect.BottomRight().X();
791 int screenHeight = aRect.BottomRight().Y();
792 pDevice->SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
793 pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
794 pDevice->DrawText(Point(0, 0), rText);
795 bmpWidth = aRect.Right() - aRect.Left();
796 bmpHeight = aRect.Bottom() - aRect.Top();
797 maBitmap = pDevice->GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight));
798 rCache.insertBitmap(aKey, maBitmap);
801 if(rTrans.hasValue())
803 drawing::HomogenMatrix3 aTrans = rTrans.get<drawing::HomogenMatrix3>();
804 setSize(awt::Size(20*bmpWidth, 20*bmpHeight));
805 setPosition(awt::Point(aTrans.Line1.Column3, aTrans.Line2.Column3));
806 aTrans.Line1.Column1 = 20 * bmpWidth;
807 aTrans.Line2.Column2 = 20 * bmpHeight;
808 setTransformatAsProperty(aTrans);
810 else
812 setSize(awt::Size(20*bmpWidth, 20*bmpHeight));
813 uno::Reference< drawing::XShape > xTargetShape(xTarget, uno::UNO_QUERY);
814 drawing::HomogenMatrix3 aTrans;
815 aTrans.Line1.Column1 = 20 * bmpWidth;
816 aTrans.Line2.Column2 = 20 * bmpHeight;
817 aTrans.Line3.Column3 = 1;
818 if(xTargetShape.is())
820 const awt::Point rPoint = xTargetShape->getPosition();
821 setPosition(rPoint);
822 aTrans.Line1.Column3 = rPoint.X;
823 aTrans.Line2.Column3 = rPoint.Y;
825 setTransformatAsProperty(aTrans);
829 void DummyText::render()
831 SAL_INFO("chart2.opengl", "render DummyText");
832 debugProperties(maProperties);
834 DummyChart* pChart = getRootShape();
836 drawing::HomogenMatrix3 aTransformation;
837 std::map<OUString, uno::Any>::const_iterator itr =
838 maProperties.find("Transformation");
839 if(itr != maProperties.end())
841 SAL_INFO("chart2.opengl", "found a transformation");
842 if(itr->second.hasValue())
844 aTransformation = itr->second.get<drawing::HomogenMatrix3>();
847 else if(maTrans.hasValue())
849 aTransformation = maTrans.get<drawing::HomogenMatrix3>();
851 pChart->m_GLRender.CreateTextTexture(maBitmap, maSize,
852 mnRotation, aTransformation);
853 pChart->m_GLRender.RenderTextShape();
856 void SAL_CALL DummyText::setPropertyValue( const OUString& rName, const uno::Any& rValue)
858 SAL_INFO("chart2.opengl", "property value set after image has been created");
859 DummyXShape::setPropertyValue(rName, rValue);
862 void SAL_CALL DummyText::setPosition(const awt::Point& rPosition )
864 DummyXShape::setPosition(rPosition);
865 if(maTrans.hasValue())
866 return;
868 std::map<OUString, uno::Any>::const_iterator itr =
869 maProperties.find("Transformation");
870 if(itr != maProperties.end())
872 if(itr->second.hasValue())
874 drawing::HomogenMatrix3 aTrans = itr->second.get<drawing::HomogenMatrix3>();
875 aTrans.Line1.Column3 = rPosition.X;
876 aTrans.Line2.Column3 = rPosition.Y;
877 setTransformatAsProperty(aTrans);
882 void DummyText::setTransformatAsProperty(const drawing::HomogenMatrix3& rMatrix)
884 setPropertyValue("Transformation", uno::Any(rMatrix));
887 DummyGroup3D::DummyGroup3D(const OUString& rName)
889 setName(rName);
892 DummyGroup2D::DummyGroup2D(const OUString& rName)
894 setName(rName);
897 awt::Point SAL_CALL DummyGroup2D::getPosition()
899 long nTop = std::numeric_limits<long>::max();
900 long nLeft = std::numeric_limits<long>::max();
901 for (auto const& shape : maShapes)
903 awt::Point aPoint = shape->getPosition();
904 if(aPoint.X >= 0 && aPoint.Y >= 0)
906 nLeft = std::min<long>(nLeft, aPoint.X);
907 nTop = std::min<long>(nTop, aPoint.Y);
911 return awt::Point(nLeft, nTop);
914 awt::Size SAL_CALL DummyGroup2D::getSize()
916 long nTop = std::numeric_limits<long>::max();
917 long nLeft = std::numeric_limits<long>::max();
918 long nBottom = 0;
919 long nRight = 0;
920 for (auto const& shape : maShapes)
922 awt::Point aPoint = shape->getPosition();
923 nLeft = std::min<long>(nLeft, aPoint.X);
924 nTop = std::min<long>(nTop, aPoint.Y);
925 awt::Size aSize = shape->getSize();
926 nRight = std::max<long>(nRight, aPoint.X + aSize.Width);
927 nBottom = std::max<long>(nBottom, aPoint.Y + aSize.Height);
930 return awt::Size(nRight - nLeft, nBottom - nTop);
933 void SAL_CALL DummyGroup2D::setPosition( const awt::Point& rPos )
935 for (auto const& shape : maShapes)
937 const awt::Point& rOldPos = shape->getPos();
938 awt::Point aNewPos( rPos.X + rOldPos.X, rPos.Y + rOldPos.Y);
939 shape->setPosition(aNewPos);
943 void SAL_CALL DummyGroup2D::setSize( const awt::Size& )
945 SAL_WARN("chart2.opengl", "set size on group shape");
948 DummyGraphic2D::DummyGraphic2D(const drawing::Position3D& rPos, const drawing::Direction3D& rSize)
950 setPosition(Position3DToAWTPoint(rPos));
951 setSize(Direction3DToAWTSize(rSize));
954 DummyChart* DummyXShape::getRootShape()
956 assert(mxParent.is());
957 DummyXShape& rParent = dynamic_cast<DummyXShape&>(*mxParent.get());
958 return rParent.getRootShape();
961 DummyChart* DummyChart::getRootShape()
963 return this;
966 uno::Any SAL_CALL DummyXShapes::queryInterface( const uno::Type& rType )
968 if( rType == cppu::UnoType<drawing::XShapes>::get() )
969 return uno::Any(uno::Reference<drawing::XShapes>(this));
970 if( rType == cppu::UnoType<container::XIndexAccess>::get() )
971 return uno::Any(uno::Reference<container::XIndexAccess>(this));
972 return DummyXShape::queryInterface(rType);
975 uno::Any SAL_CALL DummyXShapes::queryAggregation( const uno::Type & rType )
977 if( rType == cppu::UnoType<drawing::XShapes>::get() )
978 return uno::Any(uno::Reference< drawing::XShapes >(this));
979 else
980 return DummyXShape::queryAggregation( rType );
983 void SAL_CALL DummyXShapes::acquire()
984 throw()
986 DummyXShape::acquire();
989 void DummyXShapes::release()
990 throw()
992 DummyXShape::release();
995 void SAL_CALL DummyXShapes::add( const uno::Reference< drawing::XShape>& xShape )
997 DummyXShape& rChild = dynamic_cast<DummyXShape&>(*xShape.get());
998 maUNOShapes.push_back(xShape);
999 rChild.setParent(static_cast< ::cppu::OWeakObject* >( this ));
1000 maShapes.push_back(&rChild);
1003 void SAL_CALL DummyXShapes::remove( const uno::Reference< drawing::XShape>& xShape )
1005 std::vector< uno::Reference<drawing::XShape> >::iterator itr = std::find(maUNOShapes.begin(), maUNOShapes.end(), xShape);
1006 if(itr != maUNOShapes.end())
1008 DummyXShape* pChild = dynamic_cast<DummyXShape*>((*itr).get());
1009 std::vector< DummyXShape* >::iterator itrShape = std::find(maShapes.begin(), maShapes.end(), pChild);
1010 if(itrShape != maShapes.end())
1011 maShapes.erase(itrShape);
1013 maUNOShapes.erase(itr);
1017 uno::Type SAL_CALL DummyXShapes::getElementType()
1019 return cppu::UnoType<drawing::XShape>::get();
1022 sal_Bool SAL_CALL DummyXShapes::hasElements()
1024 return !maUNOShapes.empty();
1027 sal_Int32 SAL_CALL DummyXShapes::getCount()
1029 return maUNOShapes.size();
1032 uno::Any SAL_CALL DummyXShapes::getByIndex(sal_Int32 nIndex)
1034 uno::Any aShape;
1035 aShape <<= maUNOShapes[nIndex];
1036 return aShape;
1039 void DummyXShapes::render()
1041 SAL_INFO("chart2.opengl", "render DummyShapes");
1042 for (auto const& shape : maShapes)
1044 shape->render();
1048 DummyChart::DummyChart():
1049 mbNotInit(true),
1050 m_GLRender()
1052 SAL_INFO("chart2.opengl", "DummyXShape::DummyChart()-----test: ");
1053 setName("com.sun.star.chart2.shapes");
1056 void SAL_CALL DummyChart::setPosition( const awt::Point& aPosition )
1058 DummyXShape::setPosition(aPosition);
1061 DummyChart::~DummyChart()
1065 void SAL_CALL DummyChart::setSize( const awt::Size& aSize )
1067 SAL_INFO("chart2.opengl", "DummyChart::setSize()---aSize.Width = " << aSize.Width << ", aSize.Height = " << aSize.Height);
1068 int width = aSize.Width;
1069 int height = aSize.Height;
1070 DummyXShape::setSize(awt::Size(0,0));
1071 m_GLRender.SetSize(width, height);
1072 SAL_INFO("chart2.opengl", "DummyChart::GLRender.Width = " << width << ", GLRender.Height = " << height);
1075 void DummyChart::render()
1077 if(mbNotInit)
1079 m_GLRender.InitOpenGL();
1080 mbNotInit = false;
1083 SAL_INFO("chart2.opengl", "render chart");
1084 m_GLRender.prepareToRender();
1085 DummyXShapes::render();
1088 void DummyChart::clear()
1090 maUNOShapes.clear();
1091 maShapes.clear();
1098 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */