diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-08-11 13:29:23 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-08-13 18:13:20 +0200 |
commit | 2bda87fd8758448267c447ba26f1932325a1338d (patch) | |
tree | 8fec2ed4450eff43f2e76d2422121755794f171f /sc/source/filter/oox | |
parent | 1b2219cec9abe0ac77360ca2cc252d11d7f512e3 (diff) |
defer turning xlsx notes into SdrCaptions until activated
to improve import performance
Change-Id: I8dd3483372d20cbbb8694bae02a7d8b062324ff0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155613
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sc/source/filter/oox')
-rw-r--r-- | sc/source/filter/oox/commentsbuffer.cxx | 94 | ||||
-rw-r--r-- | sc/source/filter/oox/richstring.cxx | 14 |
2 files changed, 73 insertions, 35 deletions
diff --git a/sc/source/filter/oox/commentsbuffer.cxx b/sc/source/filter/oox/commentsbuffer.cxx index 9307ad707006..1f1f2dd2540c 100644 --- a/sc/source/filter/oox/commentsbuffer.cxx +++ b/sc/source/filter/oox/commentsbuffer.cxx @@ -147,6 +147,44 @@ RichStringRef const & Comment::createText() return maModel.mxText; } +namespace +{ + struct OOXGenerateNoteCaption : public GenerateNoteCaption + { + css::uno::Sequence<OUString> maPropertyNames; /// import filter Caption object formatting property names + css::uno::Sequence<css::uno::Any> maPropertyValues; /// import filter Caption object formatting property values + std::shared_ptr<RichString> mxText; + + OOXGenerateNoteCaption(std::shared_ptr<RichString>& rText) + : mxText(rText) + { + } + + virtual void Generate(SdrCaptionObj& rCaptionObj) override + { + rtl::Reference<SvxShapeText> xAnnoShape(dynamic_cast<SvxShapeText*>(rCaptionObj.getUnoShape().get())); // SvxShapeText + assert(xAnnoShape && "will not be null"); + + if (maPropertyNames.getLength()) + { + // setting a property triggers expensive process, so set them all at once + static_cast<SvxShape*>(xAnnoShape.get())->setPropertyValues(maPropertyNames, maPropertyValues); + } + + // insert text and convert text formatting + Reference< XText > xAnnoText( xAnnoShape ); + xAnnoShape->addActionLock(); + mxText->convert( xAnnoText ); + xAnnoShape->removeActionLock(); + } + + virtual OUString GetSimpleText() const override + { + return mxText->getStringContent(); + } + }; +} + void Comment::finalizeImport() { // BIFF12 stores cell range instead of cell address, use first cell of this range @@ -160,24 +198,22 @@ void Comment::finalizeImport() ScTableSheetObj* pAnnosSupp = static_cast<ScTableSheetObj*>(getSheet().get()); rtl::Reference<ScAnnotationsObj> xAnnos = static_cast<ScAnnotationsObj*>(pAnnosSupp->getAnnotations().get()); ScDocShell* pDocShell = xAnnos->GetDocShell(); - // non-empty string required by note implementation (real text will be added below) - ScPostIt* pPostIt = pDocShell->GetDocFunc().ImportNote( maModel.maRange.aStart, OUString( ' ' ) ); - SdrCaptionObj* pCaption = pPostIt->GetOrCreateCaption( maModel.maRange.aStart ); - rtl::Reference< SvxShapeText > xAnnoShape( dynamic_cast<SvxShapeText*>(pCaption->getUnoShape().get() ) ); // SvxShapeText - assert(xAnnoShape && "will not be null"); - // setting a property triggers expensive process, so set them all at once + auto xGenerator = std::make_unique<OOXGenerateNoteCaption>(maModel.mxText); // Add shape formatting properties (autoFill, colHidden and rowHidden are dropped) // vvv TODO vvv TextFitToSize should be a drawing::TextFitToSizeType not bool - Sequence<OUString> aPropertyNames{ "TextFitToSize", "MoveProtect", "TextHorizontalAdjust", "TextVerticalAdjust" }; - Sequence<Any> aPropertyValues{ Any(maModel.mbAutoScale), Any(maModel.mbLocked), - Any(lcl_ToHorizAlign( maModel.mnTHA )), Any(lcl_ToVertAlign( maModel.mnTVA )) }; + xGenerator->maPropertyNames = + css::uno::Sequence<OUString>{ "TextFitToSize", "MoveProtect", "TextHorizontalAdjust", "TextVerticalAdjust" }; + xGenerator->maPropertyValues = + css::uno::Sequence<css::uno::Any>{ Any(maModel.mbAutoScale), Any(maModel.mbLocked), + Any(lcl_ToHorizAlign( maModel.mnTHA )), Any(lcl_ToVertAlign( maModel.mnTVA )) }; + tools::Rectangle aCaptionRect; if( maModel.maAnchor.Width > 0 && maModel.maAnchor.Height > 0 ) { - xAnnoShape->setPosition( css::awt::Point( maModel.maAnchor.X, maModel.maAnchor.Y ) ); - xAnnoShape->setSize( css::awt::Size( maModel.maAnchor.Width, maModel.maAnchor.Height ) ); + aCaptionRect = tools::Rectangle(Point(maModel.maAnchor.X, maModel.maAnchor.Y), + Size(maModel.maAnchor.Width, maModel.maAnchor.Height)); } // convert shape formatting and visibility @@ -188,8 +224,8 @@ void Comment::finalizeImport() css::awt::Rectangle aShapeRect = pVmlNoteShape->getShapeRectangle(); if (aShapeRect.Width > 0 || aShapeRect.Height > 0) { - xAnnoShape->setPosition(css::awt::Point(aShapeRect.X, aShapeRect.Y)); - xAnnoShape->setSize(css::awt::Size(aShapeRect.Width, aShapeRect.Height)); + aCaptionRect = tools::Rectangle(Point(aShapeRect.X, aShapeRect.Y), + Size(aShapeRect.Width, aShapeRect.Height)); ::oox::drawingml::ShapePropertyMap aPropMap(pVmlNoteShape->makeShapePropertyMap()); @@ -197,12 +233,12 @@ void Comment::finalizeImport() Sequence<Any> aVMLPropValues; aPropMap.fillSequences(aVMLPropNames, aVMLPropValues); - sal_uInt32 nOldPropLen = aPropertyNames.getLength(); + sal_uInt32 nOldPropLen = xGenerator->maPropertyNames.getLength(); sal_uInt32 nVMLPropLen = aVMLPropNames.getLength(); - aPropertyNames.realloc(nOldPropLen + nVMLPropLen); - aPropertyValues.realloc(nOldPropLen + nVMLPropLen); - OUString* pNames = aPropertyNames.getArray(); - Any* pValues = aPropertyValues.getArray(); + xGenerator->maPropertyNames.realloc(nOldPropLen + nVMLPropLen); + xGenerator->maPropertyValues.realloc(nOldPropLen + nVMLPropLen); + OUString* pNames = xGenerator->maPropertyNames.getArray(); + Any* pValues = xGenerator->maPropertyValues.getArray(); for (sal_uInt32 i = 0; i < nVMLPropLen; ++i) { pNames[nOldPropLen + i] = aVMLPropNames[i]; @@ -215,28 +251,24 @@ void Comment::finalizeImport() // Setting comment text alignment const ::oox::vml::ClientData* xClientData = pVmlNoteShape->getClientData(); - sal_uInt32 nOldPropLen = aPropertyNames.getLength(); - aPropertyNames.realloc(nOldPropLen + 2); - aPropertyValues.realloc(nOldPropLen + 2); - OUString* pNames = aPropertyNames.getArray(); - Any* pValues = aPropertyValues.getArray(); + sal_uInt32 nOldPropLen = xGenerator->maPropertyNames.getLength(); + xGenerator->maPropertyNames.realloc(nOldPropLen + 2); + xGenerator->maPropertyValues.realloc(nOldPropLen + 2); + OUString* pNames = xGenerator->maPropertyNames.getArray(); + Any* pValues = xGenerator->maPropertyValues.getArray(); pNames[nOldPropLen] = "TextVerticalAdjust"; pValues[nOldPropLen] <<= lcl_ToVertAlign(xClientData->mnTextVAlign); pNames[nOldPropLen + 1] = "ParaAdjust"; pValues[nOldPropLen + 1] <<= lcl_ToParaAlign( xClientData->mnTextHAlign); } - static_cast<SvxShape*>(xAnnoShape.get())->setPropertyValues(aPropertyNames, aPropertyValues); + xGenerator->mxText->finalizeImport(*this); + + pDocShell->GetDocFunc().ImportNote(maModel.maRange.aStart, std::move(xGenerator), + aCaptionRect, bVisible); if (bVisible) pDocShell->GetDocFunc().ShowNote( maModel.maRange.aStart, bVisible ); - - // insert text and convert text formatting - maModel.mxText->finalizeImport(*this); - Reference< XText > xAnnoText( xAnnoShape ); - xAnnoShape->addActionLock(); - maModel.mxText->convert( xAnnoText ); - xAnnoShape->removeActionLock(); } catch( Exception& ) { diff --git a/sc/source/filter/oox/richstring.cxx b/sc/source/filter/oox/richstring.cxx index a1345179c19a..06db87e3c733 100644 --- a/sc/source/filter/oox/richstring.cxx +++ b/sc/source/filter/oox/richstring.cxx @@ -398,18 +398,24 @@ void RichString::convert( const Reference< XText >& rxText ) } } -std::unique_ptr<EditTextObject> RichString::convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFirstPortionFont ) +OUString RichString::getStringContent() const { - ESelection aSelection; - OUStringBuffer sString; for( auto& rTextPortion : maTextPortions ) sString.append(rTextPortion.getText()); + return sString.makeStringAndClear(); +} + +std::unique_ptr<EditTextObject> RichString::convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFirstPortionFont ) +{ + ESelection aSelection; + + OUString sString(getStringContent()); // fdo#84370 - diving into editeng is not thread safe. SolarMutexGuard aGuard; - rEE.SetTextCurrentDefaults( sString.makeStringAndClear() ); + rEE.SetTextCurrentDefaults(sString); for( auto& rTextPortion : maTextPortions ) { |