chart2/source/inc/RelativeSizeHelper.hxx | 6 chart2/source/tools/RelativeSizeHelper.cxx | 33 ++++ chart2/source/view/axes/Tickmarks.hxx | 5 chart2/source/view/axes/VCartesianAxis.cxx | 13 - chart2/source/view/axes/VPolarAngleAxis.cxx | 4 chart2/source/view/charttypes/VSeriesPlotter.cxx | 92 +++++------- chart2/source/view/inc/PropertyMapper.hxx | 12 + chart2/source/view/inc/ShapeFactory.hxx | 6 chart2/source/view/inc/VSeriesPlotter.hxx | 2 chart2/source/view/main/PropertyMapper.cxx | 41 +++++ chart2/source/view/main/ShapeFactory.cxx | 167 ++++++++++------------- chart2/source/view/main/VButton.cxx | 6 chart2/source/view/main/VLegend.cxx | 22 +-- chart2/source/view/main/VTitle.cxx | 8 - chart2/source/view/main/VTitle.hxx | 4 15 files changed, 235 insertions(+), 186 deletions(-)
New commits: commit 0691e3a0d901fe0373ec261cb22e8e6745303e5f Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Jan 1 10:06:02 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Jan 2 11:38:12 2022 +0100 use concrete types in chart2, createText Change-Id: Ic3b5920192c62cbdd025b480b01d04fb57d0be00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127837 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/chart2/source/inc/RelativeSizeHelper.hxx b/chart2/source/inc/RelativeSizeHelper.hxx index 8a8f60f8e63f..b07876bb67d3 100644 --- a/chart2/source/inc/RelativeSizeHelper.hxx +++ b/chart2/source/inc/RelativeSizeHelper.hxx @@ -23,6 +23,7 @@ namespace com::sun::star::awt { struct Size; } namespace com::sun::star::beans { class XPropertySet; } namespace com::sun::star::uno { template <class interface_type> class Reference; } +class SvxShapeText; namespace chart { @@ -41,6 +42,11 @@ public: const css::awt::Size & rOldReferenceSize, const css::awt::Size & rNewReferenceSize ); + static void adaptFontSizes( + SvxShapeText& xTargetProperties, + const css::awt::Size & rOldReferenceSize, + const css::awt::Size & rNewReferenceSize ); + private: RelativeSizeHelper() = delete; }; diff --git a/chart2/source/tools/RelativeSizeHelper.cxx b/chart2/source/tools/RelativeSizeHelper.cxx index a142d5b293e8..c1bdc28fcb35 100644 --- a/chart2/source/tools/RelativeSizeHelper.cxx +++ b/chart2/source/tools/RelativeSizeHelper.cxx @@ -21,7 +21,7 @@ #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <tools/diagnose_ex.h> - +#include <svx/unoshape.hxx> #include <vector> #include <algorithm> @@ -51,6 +51,37 @@ double RelativeSizeHelper::calculate( * fValue; } +void RelativeSizeHelper::adaptFontSizes( + SvxShapeText& xTargetProperties, + const awt::Size & rOldReferenceSize, + const awt::Size & rNewReferenceSize ) +{ + float fFontHeight = 0; + + vector< OUString > aProperties; + aProperties.emplace_back("CharHeight" ); + aProperties.emplace_back("CharHeightAsian" ); + aProperties.emplace_back("CharHeightComplex" ); + + for (auto const& property : aProperties) + { + try + { + if( xTargetProperties.SvxShape::getPropertyValue(property) >>= fFontHeight ) + { + xTargetProperties.SvxShape::setPropertyValue( + property, + Any( static_cast< float >( + calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize )))); + } + } + catch( const Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } + } +} + void RelativeSizeHelper::adaptFontSizes( const Reference< XPropertySet > & xTargetProperties, const awt::Size & rOldReferenceSize, diff --git a/chart2/source/view/axes/Tickmarks.hxx b/chart2/source/view/axes/Tickmarks.hxx index 54ae03922e4d..c712f6542b39 100644 --- a/chart2/source/view/axes/Tickmarks.hxx +++ b/chart2/source/view/axes/Tickmarks.hxx @@ -21,7 +21,8 @@ #include <chartview/ExplicitScaleValues.hxx> #include <basegfx/vector/b2dvector.hxx> #include <com/sun/star/drawing/PointSequenceSequence.hpp> - +#include <rtl/ref.hxx> +#include <svx/unoshape.hxx> #include <vector> namespace chart { struct AxisProperties; } @@ -35,7 +36,7 @@ struct TickInfo { double fScaledTickValue; css::uno::Reference<css::chart2::XScaling> xInverseScaling; - css::uno::Reference<css::drawing::XShape> xTextShape; + rtl::Reference<SvxShapeText> xTextShape; OUString aText;//used only for complex categories so far ::basegfx::B2DVector aTickScreenPosition; sal_Int32 nFactorForLimitedTextWidth;//categories in higher levels of complex categories can have more place than a single simple category diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 263bc125742a..991b36001253 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -121,9 +121,8 @@ static void lcl_ResizeTextShapeToFitAvailableSpace( Reference< drawing::XShape > } } -static Reference< drawing::XShape > createSingleLabel( - const Reference< lang::XMultiServiceFactory>& xShapeFactory - , const Reference< drawing::XShapes >& xTarget +static rtl::Reference<SvxShapeText> createSingleLabel( + const Reference< drawing::XShapes >& xTarget , const awt::Point& rAnchorScreenPosition2D , const OUString& rLabel , const AxisLabelProperties& rAxisLabelProperties @@ -141,8 +140,8 @@ static Reference< drawing::XShape > createSingleLabel( uno::Any aATransformation = ShapeFactory::makeTransformation( rAnchorScreenPosition2D, fRotationAnglePi ); OUString aLabel = ShapeFactory::getStackedString( rLabel, rAxisLabelProperties.bStackCharacters ); - Reference< drawing::XShape > xShape2DText = ShapeFactory::getOrCreateShapeFactory(xShapeFactory) - ->createText( xTarget, aLabel, rPropNames, rPropValues, aATransformation ); + rtl::Reference<SvxShapeText> xShape2DText = + ShapeFactory::createText( xTarget, aLabel, rPropNames, rPropValues, aATransformation ); if( rAxisProperties.m_bLimitSpaceForLabels ) lcl_ResizeTextShapeToFitAvailableSpace(xShape2DText, rAxisLabelProperties, aLabel, rPropNames, rPropValues, bIsHorizontalAxis); @@ -875,7 +874,7 @@ bool VCartesianAxis::createTextShapes( //create single label if(!pTickInfo->xTextShape.is()) - pTickInfo->xTextShape = createSingleLabel( m_xShapeFactory, xTarget + pTickInfo->xTextShape = createSingleLabel( xTarget , aAnchorScreenPosition2D, aLabel , rAxisLabelProperties, m_aAxisProperties , aPropNames, aPropValues, bIsHorizontalAxis ); @@ -1044,7 +1043,7 @@ bool VCartesianAxis::createTextShapesSimple( //create single label if(!pTickInfo->xTextShape.is()) - pTickInfo->xTextShape = createSingleLabel( m_xShapeFactory, xTarget + pTickInfo->xTextShape = createSingleLabel( xTarget , aAnchorScreenPosition2D, aLabel , rAxisLabelProperties, m_aAxisProperties , aPropNames, aPropValues, bIsHorizontalAxis ); diff --git a/chart2/source/view/axes/VPolarAngleAxis.cxx b/chart2/source/view/axes/VPolarAngleAxis.cxx index 2223f32b6ead..7bd037096984 100644 --- a/chart2/source/view/axes/VPolarAngleAxis.cxx +++ b/chart2/source/view/axes/VPolarAngleAxis.cxx @@ -53,8 +53,6 @@ void VPolarAngleAxis::createTextShapes_ForAngleAxis( , double fLogicRadius , double fLogicZ ) { - ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory); - FixedNumberFormatter aFixedNumberFormatter( m_xNumberFormatsSupplier, rAxisLabelProperties.nNumberFormatKey ); @@ -127,7 +125,7 @@ void VPolarAngleAxis::createTextShapes_ForAngleAxis( uno::Any aATransformation = ShapeFactory::makeTransformation( aAnchorScreenPosition2D, fRotationAnglePi ); OUString aStackedLabel = ShapeFactory::getStackedString( aLabel, rAxisLabelProperties.bStackCharacters ); - pTickInfo->xTextShape = pShapeFactory->createText( xTarget, aStackedLabel, aPropNames, aPropValues, aATransformation ); + pTickInfo->xTextShape = ShapeFactory::createText( xTarget, aStackedLabel, aPropNames, aPropValues, aATransformation ); } //if NO OVERLAP -> remove overlapping shapes diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index c497d6063880..4e70d803df4f 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -389,7 +389,7 @@ OUString VSeriesPlotter::getLabelTextForValue( VDataSeries const & rDataSeries return aNumber; } -uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Reference< drawing::XShapes >& xTarget +rtl::Reference<SvxShapeText> VSeriesPlotter::createDataLabel( const uno::Reference< drawing::XShapes >& xTarget , VDataSeries& rDataSeries , sal_Int32 nPointIndex , double fValue @@ -399,7 +399,7 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re , sal_Int32 nOffset , sal_Int32 nTextWidth ) { - uno::Reference< drawing::XShape > xTextShape; + rtl::Reference<SvxShapeText> xTextShape; Sequence<uno::Reference<XDataPointCustomLabelField>> aCustomLabels; try @@ -631,7 +631,7 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re comphelper::containerToSequence<uno::Reference<XFormattedString>>(aCustomLabels)); // create text shape - xTextShape = ShapeFactory::getOrCreateShapeFactory( m_xShapeFactory )-> + xTextShape = ShapeFactory:: createText( xTarget_, aFormattedLabels, *pPropNames, *pPropValues, ShapeFactory::makeTransformation( aScreenPosition2D ) ); } @@ -652,7 +652,7 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re } //create text shape - xTextShape = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory)-> + xTextShape = ShapeFactory:: createText( xTarget_, aText.makeStringAndClear(), *pPropNames, *pPropValues, ShapeFactory::makeTransformation( aScreenPosition2D ) ); } @@ -674,25 +674,21 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re // for the text shape if( nTextWidth != 0 && bTextWrap ) { - uno::Reference< beans::XPropertySet > xProp( xTextShape, uno::UNO_QUERY ); - if( xProp.is() ) + // compute the height of a line of text + if( !bMultiLineLabel || nLineCountForSymbolsize <= 0 ) { - // compute the height of a line of text - if( !bMultiLineLabel || nLineCountForSymbolsize <= 0 ) - { - nLineCountForSymbolsize = 1; - } - awt::Size aTextSize = xTextShape->getSize(); - sal_Int32 aTextLineHeight = aTextSize.Height / nLineCountForSymbolsize; + nLineCountForSymbolsize = 1; + } + awt::Size aTextSize = xTextShape->getSize(); + sal_Int32 aTextLineHeight = aTextSize.Height / nLineCountForSymbolsize; - // set maximum text width - uno::Any aTextMaximumFrameWidth( nTextWidth ); - xProp->setPropertyValue( "TextMaximumFrameWidth", aTextMaximumFrameWidth ); + // set maximum text width + uno::Any aTextMaximumFrameWidth( nTextWidth ); + xTextShape->SvxShape::setPropertyValue( "TextMaximumFrameWidth", aTextMaximumFrameWidth ); - // compute the total lines of text - aTextSize = xTextShape->getSize(); - nLineCountForSymbolsize = aTextSize.Height / aTextLineHeight; - } + // compute the total lines of text + aTextSize = xTextShape->getSize(); + nLineCountForSymbolsize = aTextSize.Height / aTextLineHeight; } // in case text is rotated, the transformation property of the text @@ -700,9 +696,7 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re if( fRotationDegrees != 0.0 ) { const double fDegreesPi( -basegfx::deg2rad(fRotationDegrees) ); - uno::Reference< beans::XPropertySet > xProp( xTextShape, uno::UNO_QUERY ); - if( xProp.is() ) - xProp->setPropertyValue( "Transformation", ShapeFactory::makeTransformation( aScreenPosition2D, fDegreesPi ) ); + xTextShape->SvxShape::setPropertyValue( "Transformation", ShapeFactory::makeTransformation( aScreenPosition2D, fDegreesPi ) ); LabelPositionHelper::correctPositionForRotation( xTextShape, eAlignment, fRotationDegrees, true /*bRotateAroundCenter*/ ); } @@ -1581,41 +1575,37 @@ void VSeriesPlotter::createRegressionCurveEquationShapes( tAnySequence aValues; PropertyMapper::getPreparedTextShapePropertyLists( xEquationProperties, aNames, aValues ); - uno::Reference< drawing::XShape > xTextShape = m_pShapeFactory->createText( + rtl::Reference<SvxShapeText> xTextShape = ShapeFactory::createText( xEquationTarget, aFormula.makeStringAndClear(), aNames, aValues, ShapeFactory::makeTransformation( aScreenPosition2D )); - OSL_ASSERT( xTextShape.is()); - if( xTextShape.is()) + ShapeFactory::setShapeName( xTextShape, rEquationCID ); + awt::Size aSize( xTextShape->getSize() ); + awt::Point aPos( RelativePositionHelper::getUpperLeftCornerOfAnchoredObject( + aScreenPosition2D, aSize, aRelativePosition.Anchor ) ); + //ensure that the equation is fully placed within the page (if possible) + if( (aPos.X + aSize.Width) > m_aPageReferenceSize.Width ) + aPos.X = m_aPageReferenceSize.Width - aSize.Width; + if( aPos.X < 0 ) { - ShapeFactory::setShapeName( xTextShape, rEquationCID ); - awt::Size aSize( xTextShape->getSize() ); - awt::Point aPos( RelativePositionHelper::getUpperLeftCornerOfAnchoredObject( - aScreenPosition2D, aSize, aRelativePosition.Anchor ) ); - //ensure that the equation is fully placed within the page (if possible) - if( (aPos.X + aSize.Width) > m_aPageReferenceSize.Width ) - aPos.X = m_aPageReferenceSize.Width - aSize.Width; - if( aPos.X < 0 ) + aPos.X = 0; + if ( nFormulaWidth > 0 ) { - aPos.X = 0; - if ( nFormulaWidth > 0 ) - { - bResizeEquation = true; - if ( nCountIteration < nMaxIteration-1 ) - xEquationTarget->remove( xTextShape ); // remove equation - nFormulaWidth *= m_aPageReferenceSize.Width / static_cast< double >(aSize.Width); - nFormulaWidth -= nCountIteration; - if ( nFormulaWidth < 0 ) - nFormulaWidth = 0; - } + bResizeEquation = true; + if ( nCountIteration < nMaxIteration-1 ) + xEquationTarget->remove( xTextShape ); // remove equation + nFormulaWidth *= m_aPageReferenceSize.Width / static_cast< double >(aSize.Width); + nFormulaWidth -= nCountIteration; + if ( nFormulaWidth < 0 ) + nFormulaWidth = 0; } - if( (aPos.Y + aSize.Height) > m_aPageReferenceSize.Height ) - aPos.Y = m_aPageReferenceSize.Height - aSize.Height; - if( aPos.Y < 0 ) - aPos.Y = 0; - if ( !bResizeEquation || nCountIteration == nMaxIteration-1 ) - xTextShape->setPosition(aPos); // if equation was not removed } + if( (aPos.Y + aSize.Height) > m_aPageReferenceSize.Height ) + aPos.Y = m_aPageReferenceSize.Height - aSize.Height; + if( aPos.Y < 0 ) + aPos.Y = 0; + if ( !bResizeEquation || nCountIteration == nMaxIteration-1 ) + xTextShape->setPosition(aPos); // if equation was not removed } } } diff --git a/chart2/source/view/inc/PropertyMapper.hxx b/chart2/source/view/inc/PropertyMapper.hxx index 54699b95017a..73e50fab1769 100644 --- a/chart2/source/view/inc/PropertyMapper.hxx +++ b/chart2/source/view/inc/PropertyMapper.hxx @@ -26,6 +26,7 @@ #include <com/sun/star/uno/Reference.h> namespace com::sun::star::beans { class XPropertySet; } +class SvxShape; namespace chart { @@ -50,6 +51,12 @@ public: , const tPropertyNameMap& rMap , tPropertyNameValueMap const * pOverwriteMap=nullptr ); + static void setMappedProperties( + SvxShape& xTarget + , const css::uno::Reference< css::beans::XPropertySet >& xSource + , const tPropertyNameMap& rMap + , tPropertyNameValueMap const * pOverwriteMap=nullptr ); + /** * Fetch property values from the source object and map it to the * destination container. Only those properties that are explicitly set @@ -94,6 +101,11 @@ public: , const tAnySequence& rValues , const css::uno::Reference< css::beans::XPropertySet >& xTarget ); + static void setMultiProperties( + const tNameSequence& rNames + , const tAnySequence& rValues + , SvxShape& xTarget ); + static const tPropertyNameMap& getPropertyNameMapForCharacterProperties(); static const tPropertyNameMap& getPropertyNameMapForParagraphProperties(); static const tPropertyNameMap& getPropertyNameMapForFillProperties(); diff --git a/chart2/source/view/inc/ShapeFactory.hxx b/chart2/source/view/inc/ShapeFactory.hxx index 523bf48b5922..74a8d5088518 100644 --- a/chart2/source/view/inc/ShapeFactory.hxx +++ b/chart2/source/view/inc/ShapeFactory.hxx @@ -191,7 +191,7 @@ public: , const css::awt::Size& rSize , const css::awt::Point& rPosition ); - css::uno::Reference< css::drawing::XShape > + static rtl::Reference<SvxShapeText> createText( const css::uno::Reference< css::drawing::XShapes >& xTarget2D , const OUString& rText , const tNameSequence& rPropNames @@ -199,14 +199,14 @@ public: , const css::uno::Any& rATransformation ); - css::uno::Reference< css::drawing::XShape > + static rtl::Reference<SvxShapeText> createText(const css::uno::Reference< css::drawing::XShapes >& xTarget , css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >& xFormattedString , const tNameSequence& rPropNames , const tAnySequence& rPropValues , const css::uno::Any& rATransformation); - css::uno::Reference< css::drawing::XShape > + static rtl::Reference<SvxShapeText> createText( const css::uno::Reference< css::drawing::XShapes >& xTarget2D, const css::awt::Size& rSize, const css::awt::Point& rPosition, diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 806132237127..311e1d7a1813 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -313,7 +313,7 @@ protected: * @return * a reference to the created text shape. */ - css::uno::Reference< css::drawing::XShape > + rtl::Reference<SvxShapeText> createDataLabel( const css::uno::Reference< css::drawing::XShapes >& xTarget , VDataSeries& rDataSeries , sal_Int32 nPointIndex diff --git a/chart2/source/view/main/PropertyMapper.cxx b/chart2/source/view/main/PropertyMapper.cxx index dfae6a757a71..6d6df42303c0 100644 --- a/chart2/source/view/main/PropertyMapper.cxx +++ b/chart2/source/view/main/PropertyMapper.cxx @@ -28,6 +28,7 @@ #include <com/sun/star/style/ParagraphAdjust.hpp> #include <comphelper/sequence.hxx> #include <tools/diagnose_ex.h> +#include <svx/unoshape.hxx> namespace chart { @@ -45,6 +46,31 @@ void lcl_overwriteOrAppendValues( } // anonymous namespace +void PropertyMapper::setMappedProperties( + SvxShape& xTarget + , const uno::Reference< beans::XPropertySet >& xSource + , const tPropertyNameMap& rMap + , tPropertyNameValueMap const * pOverwriteMap ) +{ + if( !xSource.is() ) + return; + + tNameSequence aNames; + tAnySequence aValues; + getMultiPropertyLists(aNames, aValues, xSource, rMap ); + if(pOverwriteMap && (aNames.getLength() == aValues.getLength())) + { + tPropertyNameValueMap aNewMap; + for( sal_Int32 nI=0; nI<aNames.getLength(); ++nI ) + aNewMap[ aNames[nI] ] = aValues[nI]; + lcl_overwriteOrAppendValues( aNewMap, *pOverwriteMap ); + aNames = comphelper::mapKeysToSequence( aNewMap ); + aValues = comphelper::mapValuesToSequence( aNewMap ); + } + + PropertyMapper::setMultiProperties( aNames, aValues, xTarget ); +} + void PropertyMapper::setMappedProperties( const uno::Reference< beans::XPropertySet >& xTarget , const uno::Reference< beans::XPropertySet >& xSource @@ -396,6 +422,21 @@ const tPropertyNameMap& PropertyMapper::getPropertyNameMapForFilledSeriesPropert return s_aShapePropertyMapForFilledSeriesProperties; } +void PropertyMapper::setMultiProperties( + const tNameSequence& rNames + , const tAnySequence& rValues + , SvxShape& xTarget ) +{ + try + { + xTarget.setPropertyValues( rNames, rValues ); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("chart2", "" ); //if this occurs more often think of removing the XMultiPropertySet completely for better performance + } +} + void PropertyMapper::setMultiProperties( const tNameSequence& rNames , const tAnySequence& rValues diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx index f58098e128b7..eeb2f28611f8 100644 --- a/chart2/source/view/main/ShapeFactory.cxx +++ b/chart2/source/view/main/ShapeFactory.cxx @@ -2036,7 +2036,7 @@ rtl::Reference<SvxShapeRect> return xShape; } -uno::Reference< drawing::XShape > +rtl::Reference<SvxShapeText> ShapeFactory::createText( const uno::Reference< drawing::XShapes >& xTarget , const OUString& rText , const tNameSequence& rPropNames @@ -2050,41 +2050,34 @@ uno::Reference< drawing::XShape > return nullptr; //create shape and add to page - uno::Reference< drawing::XShape > xShape( - m_xShapeFactory->createInstance( - "com.sun.star.drawing.TextShape" ), uno::UNO_QUERY ); + rtl::Reference<SvxShapeText> xShape = new SvxShapeText(nullptr); + xShape->setShapeKind(OBJ_TEXT); xTarget->add(xShape); //set text - uno::Reference< text::XTextRange > xTextRange( xShape, uno::UNO_QUERY ); - if( xTextRange.is() ) - xTextRange->setString( rText ); + xShape->setString( rText ); - uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY ); - if( xProp.is() ) - { - //set properties - PropertyMapper::setMultiProperties( rPropNames, rPropValues, xProp ); + //set properties + PropertyMapper::setMultiProperties( rPropNames, rPropValues, *xShape ); - //set position matrix - //the matrix needs to be set at the end behind autogrow and such position influencing properties - try - { - if (rATransformation.hasValue()) - xProp->setPropertyValue( "Transformation", rATransformation ); - else - SAL_INFO("chart2", "No rATransformation value is given to ShapeFactory::createText()"); + //set position matrix + //the matrix needs to be set at the end behind autogrow and such position influencing properties + try + { + if (rATransformation.hasValue()) + xShape->SvxShape::setPropertyValue( "Transformation", rATransformation ); + else + SAL_INFO("chart2", "No rATransformation value is given to ShapeFactory::createText()"); - } - catch( const uno::Exception& ) - { - TOOLS_WARN_EXCEPTION("chart2", "" ); - } + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("chart2", "" ); } return xShape; } -uno::Reference< drawing::XShape > +rtl::Reference<SvxShapeText> ShapeFactory::createText( const uno::Reference< drawing::XShapes >& xTarget , uno::Sequence< uno::Reference< chart2::XFormattedString > >& xFormattedString , const tNameSequence& rPropNames @@ -2112,41 +2105,36 @@ uno::Reference< drawing::XShape > return nullptr; //create shape and add to page - uno::Reference< drawing::XShape > xShape( - m_xShapeFactory->createInstance( - "com.sun.star.drawing.TextShape" ), uno::UNO_QUERY ); + rtl::Reference<SvxShapeText> xShape = new SvxShapeText(nullptr); + xShape->setShapeKind(OBJ_TEXT); xTarget->add(xShape); //set paragraph properties bNotEmpty = false; - Reference< text::XText > xText( xShape, uno::UNO_QUERY ); - if( xText.is() ) - { - // the first cursor is used for appending the next paragraph, - // after a new string has been inserted the cursor is moved at the end - // of the inserted string - // the second cursor is used for selecting the paragraph and apply the - // passed text properties - Reference< text::XTextCursor > xInsertCursor = xText->createTextCursor(); - Reference< text::XTextCursor > xSelectionCursor = xText->createTextCursor(); - if( xInsertCursor.is() && xSelectionCursor.is() ) + // the first cursor is used for appending the next paragraph, + // after a new string has been inserted the cursor is moved at the end + // of the inserted string + // the second cursor is used for selecting the paragraph and apply the + // passed text properties + Reference< text::XTextCursor > xInsertCursor = xShape->createTextCursor(); + Reference< text::XTextCursor > xSelectionCursor = xShape->createTextCursor(); + if( xInsertCursor.is() && xSelectionCursor.is() ) + { + uno::Reference< beans::XPropertySet > xSelectionProp( xSelectionCursor, uno::UNO_QUERY ); + if( xSelectionProp.is() ) { - uno::Reference< beans::XPropertySet > xSelectionProp( xSelectionCursor, uno::UNO_QUERY ); - if( xSelectionProp.is() ) + for( sal_Int32 nN = 0; nN < nNumberOfParagraphs; ++nN ) { - for( sal_Int32 nN = 0; nN < nNumberOfParagraphs; ++nN ) + if( !xFormattedString[nN]->getString().isEmpty() ) { - if( !xFormattedString[nN]->getString().isEmpty() ) - { - xInsertCursor->gotoEnd( false ); - xSelectionCursor->gotoEnd( false ); - xText->insertString( xInsertCursor, xFormattedString[nN]->getString(), false ); - bNotEmpty = true; - xSelectionCursor->gotoEnd( true ); // select current paragraph - uno::Reference< beans::XPropertySet > xStringProperties( xFormattedString[nN], uno::UNO_QUERY ); - PropertyMapper::setMappedProperties( xSelectionProp, xStringProperties, - PropertyMapper::getPropertyNameMapForTextShapeProperties() ); - } + xInsertCursor->gotoEnd( false ); + xSelectionCursor->gotoEnd( false ); + xShape->insertString( xInsertCursor, xFormattedString[nN]->getString(), false ); + bNotEmpty = true; + xSelectionCursor->gotoEnd( true ); // select current paragraph + uno::Reference< beans::XPropertySet > xStringProperties( xFormattedString[nN], uno::UNO_QUERY ); + PropertyMapper::setMappedProperties( xSelectionProp, xStringProperties, + PropertyMapper::getPropertyNameMapForTextShapeProperties() ); } } } @@ -2155,30 +2143,26 @@ uno::Reference< drawing::XShape > if( !bNotEmpty ) return nullptr; - uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY ); - if( xProp.is() ) - { - //set whole text shape properties - PropertyMapper::setMultiProperties( rPropNames, rPropValues, xProp ); + //set whole text shape properties + PropertyMapper::setMultiProperties( rPropNames, rPropValues, *xShape ); - if( rATransformation.hasValue() ) + if( rATransformation.hasValue() ) + { + //set position matrix + //the matrix needs to be set at the end behind autogrow and such position influencing properties + try { - //set position matrix - //the matrix needs to be set at the end behind autogrow and such position influencing properties - try - { - xProp->setPropertyValue( "Transformation", rATransformation ); - } - catch( const uno::Exception& ) - { - TOOLS_WARN_EXCEPTION("chart2", "" ); - } + xShape->SvxShape::setPropertyValue( "Transformation", rATransformation ); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("chart2", "" ); } } return xShape; } -uno::Reference< drawing::XShape > +rtl::Reference<SvxShapeText> ShapeFactory::createText( const uno::Reference< drawing::XShapes >& xTarget, const awt::Size& rSize, const awt::Point& rPos, @@ -2188,18 +2172,15 @@ uno::Reference< drawing::XShape > double nRotation, const OUString& aName, sal_Int32 nTextMaxWidth ) { //create shape and add to page - uno::Reference< drawing::XShape > xShape( - m_xShapeFactory->createInstance( - "com.sun.star.drawing.TextShape" ), uno::UNO_QUERY ); + rtl::Reference<SvxShapeText> xShape = new SvxShapeText(nullptr); + xShape->setShapeKind(OBJ_TEXT); try { xTarget->add(xShape); //set text and text properties - uno::Reference< text::XText > xText( xShape, uno::UNO_QUERY ); - uno::Reference< text::XTextCursor > xTextCursor( xText->createTextCursor() ); - uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY ); - if( !xText.is() || !xTextCursor.is() || !xShapeProp.is() || !xTextProperties.is() ) + uno::Reference< text::XTextCursor > xTextCursor( xShape->createTextCursor() ); + if( !xTextCursor.is() ) return xShape; tPropertyNameValueMap aValueMap; @@ -2230,7 +2211,7 @@ uno::Reference< drawing::XShape > tNameSequence aPropNames; tAnySequence aPropValues; PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames, aPropValues, aValueMap ); - PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp ); + PropertyMapper::setMultiProperties( aPropNames, aPropValues, *xShape ); } bool bStackCharacters(false); @@ -2254,19 +2235,18 @@ uno::Reference< drawing::XShape > aLabel = ShapeFactory::getStackedString( aLabel, bStackCharacters ); xTextCursor->gotoEnd(false); - xText->insertString( xTextCursor, aLabel, false ); + xShape->insertString( xTextCursor, aLabel, false ); xTextCursor->gotoEnd(true); - uno::Reference< beans::XPropertySet > xTargetProps( xShape, uno::UNO_QUERY ); uno::Reference< beans::XPropertySet > xSourceProps( xFormattedString[0], uno::UNO_QUERY ); - PropertyMapper::setMappedProperties( xTargetProps, xSourceProps + PropertyMapper::setMappedProperties( *xShape, xSourceProps , PropertyMapper::getPropertyNameMapForCharacterProperties() ); // adapt font size according to page size awt::Size aOldRefSize; if( xTextProperties->getPropertyValue( "ReferencePageSize") >>= aOldRefSize ) { - RelativeSizeHelper::adaptFontSizes( xTargetProps, aOldRefSize, rSize ); + RelativeSizeHelper::adaptFontSizes( *xShape, aOldRefSize, rSize ); } } } @@ -2275,7 +2255,7 @@ uno::Reference< drawing::XShape > for( const uno::Reference< chart2::XFormattedString >& rxFS : std::as_const(xFormattedString) ) { xTextCursor->gotoEnd(false); - xText->insertString( xTextCursor, rxFS->getString(), false ); + xShape->insertString( xTextCursor, rxFS->getString(), false ); xTextCursor->gotoEnd(true); } awt::Size aOldRefSize; @@ -2284,29 +2264,28 @@ uno::Reference< drawing::XShape > if( xFormattedString.hasElements() ) { - uno::Reference< beans::XPropertySet > xTargetProps( xShape, uno::UNO_QUERY ); uno::Reference< beans::XPropertySet > xSourceProps( xFormattedString[0], uno::UNO_QUERY ); - PropertyMapper::setMappedProperties( xTargetProps, xSourceProps, PropertyMapper::getPropertyNameMapForCharacterProperties() ); + PropertyMapper::setMappedProperties( *xShape, xSourceProps, PropertyMapper::getPropertyNameMapForCharacterProperties() ); // adapt font size according to page size if( bHasRefPageSize ) { - RelativeSizeHelper::adaptFontSizes( xTargetProps, aOldRefSize, rSize ); + RelativeSizeHelper::adaptFontSizes( *xShape, aOldRefSize, rSize ); } } } // #i109336# Improve auto positioning in chart float fFontHeight = 0.0; - if ( xShapeProp.is() && ( xShapeProp->getPropertyValue( "CharHeight" ) >>= fFontHeight ) ) + if ( xShape->SvxShape::getPropertyValue( "CharHeight" ) >>= fFontHeight ) { fFontHeight = convertPointToMm100(fFontHeight); sal_Int32 nXDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * 0.18f ) ); sal_Int32 nYDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * 0.30f ) ); - xShapeProp->setPropertyValue( "TextLeftDistance", uno::Any( nXDistance ) ); - xShapeProp->setPropertyValue( "TextRightDistance", uno::Any( nXDistance ) ); - xShapeProp->setPropertyValue( "TextUpperDistance", uno::Any( nYDistance ) ); - xShapeProp->setPropertyValue( "TextLowerDistance", uno::Any( nYDistance ) ); + xShape->SvxShape::setPropertyValue( "TextLeftDistance", uno::Any( nXDistance ) ); + xShape->SvxShape::setPropertyValue( "TextRightDistance", uno::Any( nXDistance ) ); + xShape->SvxShape::setPropertyValue( "TextUpperDistance", uno::Any( nYDistance ) ); + xShape->SvxShape::setPropertyValue( "TextLowerDistance", uno::Any( nYDistance ) ); } sal_Int32 nXPos = rPos.X; sal_Int32 nYPos = rPos.Y; @@ -2316,9 +2295,9 @@ uno::Reference< drawing::XShape > ::basegfx::B2DHomMatrix aM; aM.rotate( -basegfx::deg2rad(nRotation) );//#i78696#->#i80521# aM.translate( nXPos, nYPos ); - xShapeProp->setPropertyValue( "Transformation", uno::Any( B2DHomMatrixToHomogenMatrix3(aM) ) ); + xShape->SvxShape::setPropertyValue( "Transformation", uno::Any( B2DHomMatrixToHomogenMatrix3(aM) ) ); - xShapeProp->setPropertyValue( "ParaAdjust", uno::Any( style::ParagraphAdjust_CENTER ) ); + xShape->SvxShape::setPropertyValue( "ParaAdjust", uno::Any( style::ParagraphAdjust_CENTER ) ); } catch( const uno::Exception& ) { diff --git a/chart2/source/view/main/VButton.cxx b/chart2/source/view/main/VButton.cxx index 6f13a750fead..b28f42d6f52f 100644 --- a/chart2/source/view/main/VButton.cxx +++ b/chart2/source/view/main/VButton.cxx @@ -93,8 +93,6 @@ uno::Reference<drawing::XShape> VButton::createTriangle(awt::Size aSize) void VButton::createShapes(const uno::Reference<beans::XPropertySet>& xTextProp) { - ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory); - tNameSequence aPropNames; tAnySequence aPropValues; @@ -125,8 +123,8 @@ void VButton::createShapes(const uno::Reference<beans::XPropertySet>& xTextProp) PropertyMapper::getMultiPropertyListsFromValueMap(aPropNames, aPropValues, aTextValueMap); - uno::Reference<drawing::XShape> xEntry - = pShapeFactory->createText(xContainer, m_sLabel, aPropNames, aPropValues, uno::Any()); + rtl::Reference<SvxShapeText> xEntry + = ShapeFactory::createText(xContainer, m_sLabel, aPropNames, aPropValues, uno::Any()); if (xEntry.is()) { diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 0837dc0581fa..b9d9baa6d209 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -149,13 +149,11 @@ void lcl_getProperties( awt::Size lcl_createTextShapes( const std::vector<ViewLegendEntry> & rEntries, - const Reference< lang::XMultiServiceFactory > & xShapeFactory, const Reference< drawing::XShapes > & xTarget, - std::vector< Reference< drawing::XShape > > & rOutTextShapes, + std::vector< rtl::Reference<SvxShapeText> > & rOutTextShapes, const tPropertyValues & rTextProperties ) { awt::Size aResult; - ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(xShapeFactory); for (ViewLegendEntry const & rEntry : rEntries) { @@ -175,8 +173,8 @@ awt::Size lcl_createTextShapes( aLabelString = " "; } - Reference< drawing::XShape > xEntry = - pShapeFactory->createText( xTarget, aLabelString, + rtl::Reference<SvxShapeText> xEntry = + ShapeFactory::createText( xTarget, aLabelString, rTextProperties.first, rTextProperties.second, uno::Any() ); // adapt max-extent @@ -196,7 +194,7 @@ awt::Size lcl_createTextShapes( } void lcl_collectColumnWidths( std::vector< sal_Int32 >& rColumnWidths, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns, - const std::vector< Reference< drawing::XShape > >& rTextShapes, sal_Int32 nSymbolPlusDistanceWidth ) + const std::vector< rtl::Reference<SvxShapeText> >& rTextShapes, sal_Int32 nSymbolPlusDistanceWidth ) { rColumnWidths.clear(); sal_Int32 nNumberOfEntries = rTextShapes.size(); @@ -219,7 +217,7 @@ void lcl_collectColumnWidths( std::vector< sal_Int32 >& rColumnWidths, const sal } void lcl_collectRowHeighs( std::vector< sal_Int32 >& rRowHeights, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns, - const std::vector< Reference< drawing::XShape > >& rTextShapes ) + const std::vector< rtl::Reference<SvxShapeText> >& rTextShapes ) { // calculate maximum height for each row // and collect column widths @@ -268,7 +266,6 @@ awt::Size lcl_placeLegendEntries( const awt::Size& rMaxSymbolExtent, tPropertyValues & rTextProperties, const Reference< drawing::XShapes > & xTarget, - const Reference< lang::XMultiServiceFactory > & xShapeFactory, const awt::Size& rRemainingSpace, sal_Int32 nYStartPosition, const awt::Size& rPageSize, @@ -304,8 +301,8 @@ awt::Size lcl_placeLegendEntries( *pFrameWidthAny <<= nMaxTextWidth; } - std::vector< Reference< drawing::XShape > > aTextShapes; - awt::Size aMaxEntryExtent = lcl_createTextShapes( rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); + std::vector< rtl::Reference<SvxShapeText> > aTextShapes; + awt::Size aMaxEntryExtent = lcl_createTextShapes( rEntries, xTarget, aTextShapes, rTextProperties ); OSL_ASSERT( aTextShapes.size() == rEntries.size()); sal_Int32 nMaxEntryWidth = nXOffset + nSymbolPlusDistanceWidth + aMaxEntryExtent.Width; @@ -421,11 +418,10 @@ awt::Size lcl_placeLegendEntries( { OUString aLabelString = rEntries[0].aLabel[0]->getString(); static const OUStringLiteral sDots = u"..."; - ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(xShapeFactory); for (sal_Int32 nNewLen = aLabelString.getLength() - sDots.getLength(); nNewLen > 0; nNewLen--) { OUString aNewLabel = aLabelString.subView(0, nNewLen) + sDots; - Reference<drawing::XShape> xEntry = pShapeFactory->createText( + rtl::Reference<SvxShapeText> xEntry = ShapeFactory::createText( xTarget, aNewLabel, rTextProperties.first, rTextProperties.second, uno::Any()); nSumHeight = xEntry->getSize().Height; nRemainingSpace = rRemainingSpace.Height - nSumHeight; @@ -1025,7 +1021,7 @@ void VLegend::createShapes( // place the legend entries aLegendSize = lcl_placeLegendEntries(aViewEntries, eExpansion, bSymbolsLeftSide, fViewFontSize, aMaxSymbolExtent, aTextProperties, xLegendContainer, - m_xShapeFactory, aLegendSize, nUsedButtonHeight, rPageSize, bIsPivotChart, rDefaultLegendSize); + aLegendSize, nUsedButtonHeight, rPageSize, bIsPivotChart, rDefaultLegendSize); uno::Reference<beans::XPropertySet> xModelPage(mrModel.getPageBackground()); diff --git a/chart2/source/view/main/VTitle.cxx b/chart2/source/view/main/VTitle.cxx index b6ed5866a311..fdcf794156f1 100644 --- a/chart2/source/view/main/VTitle.cxx +++ b/chart2/source/view/main/VTitle.cxx @@ -75,9 +75,6 @@ void VTitle::changePosition( const awt::Point& rPos ) { if(!m_xShape.is()) return; - uno::Reference< beans::XPropertySet > xShapeProp( m_xShape, uno::UNO_QUERY ); - if(!xShapeProp.is()) - return; try { m_nXPos = rPos.X; @@ -88,7 +85,7 @@ void VTitle::changePosition( const awt::Point& rPos ) ::basegfx::B2DHomMatrix aM; aM.rotate( basegfx::deg2rad(-m_fRotationAngleDegree) );//#i78696#->#i80521# aM.translate( m_nXPos, m_nYPos); - xShapeProp->setPropertyValue( "Transformation", uno::Any( B2DHomMatrixToHomogenMatrix3(aM) ) ); + m_xShape->SvxShape::setPropertyValue( "Transformation", uno::Any( B2DHomMatrixToHomogenMatrix3(aM) ) ); } catch( const uno::Exception& ) { @@ -155,8 +152,7 @@ void VTitle::createShapes( else nTextMaxWidth = rTextMaxWidth.Height; - ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory); - m_xShape =pShapeFactory->createText( m_xTarget, rReferenceSize, rPos, aStringList, xTitleProperties, + m_xShape = ShapeFactory::createText( m_xTarget, rReferenceSize, rPos, aStringList, xTitleProperties, m_fRotationAngleDegree, m_aCID, nTextMaxWidth ); } diff --git a/chart2/source/view/main/VTitle.hxx b/chart2/source/view/main/VTitle.hxx index cdfd0a89cdc4..ad3d1d815b88 100644 --- a/chart2/source/view/main/VTitle.hxx +++ b/chart2/source/view/main/VTitle.hxx @@ -21,6 +21,7 @@ #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/uno/Reference.h> #include <rtl/ustring.hxx> +#include <rtl/ref.hxx> #include <sal/types.h> namespace com::sun::star::awt { struct Point; } @@ -28,6 +29,7 @@ namespace com::sun::star::chart2 { class XTitle; } namespace com::sun::star::drawing { class XShape; } namespace com::sun::star::drawing { class XShapes; } namespace com::sun::star::lang { class XMultiServiceFactory; } +class SvxShapeText; namespace chart { @@ -58,7 +60,7 @@ private: css::uno::Reference< css::drawing::XShapes > m_xTarget; css::uno::Reference< css::lang::XMultiServiceFactory> m_xShapeFactory; css::uno::Reference< css::chart2::XTitle > m_xTitle; - css::uno::Reference< css::drawing::XShape > m_xShape; + rtl::Reference<SvxShapeText> m_xShape; OUString m_aCID; double m_fRotationAngleDegree;