sw/source/writerfilter/inc/dmapper/resourcemodel.hxx | 7 sw/source/writerfilter/ooxml/Handler.cxx | 4 sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx | 4 sw/source/writerfilter/ooxml/OOXMLFactory.cxx | 28 sw/source/writerfilter/ooxml/OOXMLFactory.hxx | 2 sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx | 150 ++-- sw/source/writerfilter/ooxml/OOXMLFastContextHandler.hxx | 36 sw/source/writerfilter/ooxml/OOXMLFastHelper.hxx | 9 sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx | 546 ++++----------- sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx | 300 +------- sw/source/writerfilter/ooxml/factory_ns.py | 2 sw/source/writerfilter/ooxml/factoryimpl_ns.py | 49 - sw/source/writerfilter/rtftok/rtfvalue.hxx | 2 13 files changed, 363 insertions(+), 776 deletions(-)
New commits: commit 1f5a6dd3590432f3582bd62f6c896e0c6200113c Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Aug 25 21:10:22 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Aug 29 10:05:23 2024 +0200 flatten ooxml::Value hierarchy into a std::variant. Since it is always one of a very small set of subclasses. Which means we can pass it around by value and avoid allocating it on the heap, which reduces parsing time. Change-Id: Ic83b48cb3fdec17779a2ad59abbc585156f5ffa6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172451 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/writerfilter/inc/dmapper/resourcemodel.hxx b/sw/source/writerfilter/inc/dmapper/resourcemodel.hxx index ea4ecdde03af..bf1b4f65179a 100644 --- a/sw/source/writerfilter/inc/dmapper/resourcemodel.hxx +++ b/sw/source/writerfilter/inc/dmapper/resourcemodel.hxx @@ -330,14 +330,9 @@ protected: makes no sense for a certain value, e.g. the integer value of a string. */ -class Value : public virtual SvRefBase +class Value { public: - /** - Pointer to a value. - */ - typedef tools::SvRef<Value> Pointer_t; - /** Returns integer representation of the value. */ diff --git a/sw/source/writerfilter/ooxml/Handler.cxx b/sw/source/writerfilter/ooxml/Handler.cxx index 103344d2b097..bed1a9b6b866 100644 --- a/sw/source/writerfilter/ooxml/Handler.cxx +++ b/sw/source/writerfilter/ooxml/Handler.cxx @@ -386,7 +386,7 @@ OOXMLHyperlinkURLHandler::OOXMLHyperlinkURLHandler(OOXMLFastContextHandler * pCo OOXMLHyperlinkURLHandler::~OOXMLHyperlinkURLHandler() { mpFastContext->clearProps(); - mpFastContext->newProperty(NS_ooxml::LN_CT_Hyperlink_URL, OOXMLValue::Pointer_t(new OOXMLStringValue(mURL))); + mpFastContext->newProperty(NS_ooxml::LN_CT_Hyperlink_URL, OOXMLValue::createString(mURL)); } void OOXMLHyperlinkURLHandler::attribute(Id name, const Value & val) @@ -414,7 +414,7 @@ OOXMLAltChunkHandler::~OOXMLAltChunkHandler() { mpFastContext->clearProps(); mpFastContext->newProperty(NS_ooxml::LN_CT_AltChunk, - OOXMLValue::Pointer_t(new OOXMLStringValue(m_aStreamName))); + OOXMLValue::createString(m_aStreamName)); } void OOXMLAltChunkHandler::attribute(Id nName, const Value& rValue) diff --git a/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx b/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx index 8321016ffb9e..45ee7e19156e 100644 --- a/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx +++ b/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx @@ -343,13 +343,13 @@ OOXMLPropertySet * OOXMLDocumentImpl::getPicturePropSet writerfilter::Reference<BinaryObj>::Pointer_t xPicture (new OOXMLBinaryObjectReference(std::move(xStream))); - OOXMLValue::Pointer_t pPayloadValue(new OOXMLBinaryValue(std::move(xPicture))); + OOXMLValue pPayloadValue(OOXMLValue::createBinary(std::move(xPicture))); OOXMLPropertySet::Pointer_t pBlipSet(new OOXMLPropertySet); pBlipSet->add(NS_ooxml::LN_payload, pPayloadValue, OOXMLProperty::ATTRIBUTE); - OOXMLValue::Pointer_t pBlipValue(new OOXMLPropertySetValue(std::move(pBlipSet))); + OOXMLValue pBlipValue(OOXMLValue::createPropertySet(std::move(pBlipSet))); OOXMLPropertySet * pProps = new OOXMLPropertySet; diff --git a/sw/source/writerfilter/ooxml/OOXMLFactory.cxx b/sw/source/writerfilter/ooxml/OOXMLFactory.cxx index b11cf07c2900..0d9185ef9601 100644 --- a/sw/source/writerfilter/ooxml/OOXMLFactory.cxx +++ b/sw/source/writerfilter/ooxml/OOXMLFactory.cxx @@ -55,51 +55,51 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, Id nId = pFactory->getResourceId(nDefine, nToken); - OOXMLValue::Pointer_t xValue; + OOXMLValue xValue; switch (pAttr->m_nResource) { case ResourceType::Boolean: - xValue = OOXMLBooleanValue::Create(rAttribs.getAsViewByIndex(nAttrIndex)); + xValue = OOXMLValue::createBoolean(rAttribs.getAsViewByIndex(nAttrIndex)); break; case ResourceType::String: - xValue = new OOXMLStringValue(rAttribs.getValueByIndex(nAttrIndex)); + xValue = OOXMLValue::createString(rAttribs.getValueByIndex(nAttrIndex)); break; case ResourceType::Integer: - xValue = OOXMLIntegerValue::Create(rAttribs.getAsIntegerByIndex(nAttrIndex)); + xValue = OOXMLValue::createInteger(rAttribs.getAsIntegerByIndex(nAttrIndex)); break; case ResourceType::Hex: - xValue = new OOXMLHexValue(rAttribs.getAsViewByIndex(nAttrIndex)); + xValue = OOXMLValue::createHex(rAttribs.getAsViewByIndex(nAttrIndex)); break; case ResourceType::HexColor: - xValue = new OOXMLHexColorValue(rAttribs.getAsViewByIndex(nAttrIndex)); + xValue = OOXMLValue::createHexColor(rAttribs.getAsViewByIndex(nAttrIndex)); break; case ResourceType::TwipsMeasure_asSigned: case ResourceType::TwipsMeasure_asZero: - xValue = new OOXMLTwipsMeasureValue(rAttribs.getAsViewByIndex(nAttrIndex)); - if (xValue->getInt() < 0) + xValue = OOXMLValue::createTwipsMeasure(rAttribs.getAsViewByIndex(nAttrIndex)); + if (xValue.getInt() < 0) { if (pAttr->m_nResource == ResourceType::TwipsMeasure_asZero) - xValue = OOXMLIntegerValue::Create(0); + xValue = OOXMLValue::createInteger(0); } break; case ResourceType::HpsMeasure: - xValue = new OOXMLHpsMeasureValue(rAttribs.getAsViewByIndex(nAttrIndex)); + xValue = OOXMLValue::createHpsMeasure(rAttribs.getAsViewByIndex(nAttrIndex)); break; case ResourceType::MeasurementOrPercent: - xValue = new OOXMLMeasurementOrPercentValue(rAttribs.getAsViewByIndex(nAttrIndex)); + xValue = OOXMLValue::createMeasurementOrPercent(rAttribs.getAsViewByIndex(nAttrIndex)); break; case ResourceType::List: if (sal_uInt32 nValue; pFactory->getListValue(pAttr->m_nRef, rAttribs.getAsViewByIndex(nAttrIndex), nValue)) { - xValue = OOXMLIntegerValue::Create(nValue); + xValue = OOXMLValue::createInteger(nValue); } break; default: break; } - if (xValue) + if (xValue.hasValue()) { pHandler->newProperty(nId, xValue); pFactory->attributeAction(pHandler, nToken, xValue); @@ -170,7 +170,7 @@ void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString { } -void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, const OOXMLValue::Pointer_t&) +void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, const OOXMLValue&) { } diff --git a/sw/source/writerfilter/ooxml/OOXMLFactory.hxx b/sw/source/writerfilter/ooxml/OOXMLFactory.hxx index 146bc5d61631..9d55d919c5f9 100644 --- a/sw/source/writerfilter/ooxml/OOXMLFactory.hxx +++ b/sw/source/writerfilter/ooxml/OOXMLFactory.hxx @@ -68,7 +68,7 @@ public: virtual void startAction(OOXMLFastContextHandler * pHandler); virtual void charactersAction(OOXMLFastContextHandler * pHandler, const OUString & rString); virtual void endAction(OOXMLFastContextHandler * pHandler); - virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue); + virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, const OOXMLValue& pValue); protected: virtual ~OOXMLFactory_ns() override; diff --git a/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx b/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx index 3b4f909e3843..44b13ee9099b 100644 --- a/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx +++ b/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx @@ -297,9 +297,9 @@ void OOXMLFastContextHandler::setStream(Stream * pStream) mpStream = pStream; } -OOXMLValue::Pointer_t OOXMLFastContextHandler::getValue() const +OOXMLValue OOXMLFastContextHandler::getValue() const { - return OOXMLValue::Pointer_t(); + return OOXMLValue(); } void OOXMLFastContextHandler::attributes @@ -351,11 +351,11 @@ void OOXMLFastContextHandler::sendTableDepth() const OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + OOXMLValue pVal = OOXMLValue::createInteger(mnTableDepth); pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); } @@ -437,7 +437,7 @@ void OOXMLFastContextHandler::startParagraphGroup() pPropSet->resolve(aHandler); if (const OUString& sText = aHandler.getString(); !sText.isEmpty()) { - OOXMLStringValue::Pointer_t pVal = new OOXMLStringValue(sText); + OOXMLValue pVal = OOXMLValue::createString(sText); OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySet); pPropertySet->add(NS_ooxml::LN_AG_Parids_paraId, pVal, OOXMLProperty::ATTRIBUTE); mpStream->props(pPropertySet.get()); @@ -463,7 +463,7 @@ void OOXMLFastContextHandler::endParagraphGroup() void OOXMLFastContextHandler::startSdt() { OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_CT_SdtBlock_sdtContent, pVal, OOXMLProperty::ATTRIBUTE); mpStream->props(pProps.get()); } @@ -471,7 +471,7 @@ void OOXMLFastContextHandler::startSdt() void OOXMLFastContextHandler::endSdt() { OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_CT_SdtBlock_sdtEndContent, pVal, OOXMLProperty::ATTRIBUTE); mpStream->props(pProps.get()); } @@ -479,7 +479,7 @@ void OOXMLFastContextHandler::endSdt() void OOXMLFastContextHandler::startSdtRun() { OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_CT_SdtRun_sdtContent, pVal, OOXMLProperty::ATTRIBUTE); mpStream->props(pProps.get()); } @@ -487,7 +487,7 @@ void OOXMLFastContextHandler::startSdtRun() void OOXMLFastContextHandler::endSdtRun() { OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_CT_SdtRun_sdtEndContent, pVal, OOXMLProperty::ATTRIBUTE); mpStream->props(pProps.get()); } @@ -535,7 +535,7 @@ void OOXMLFastContextHandler::setLastSectionGroup() } void OOXMLFastContextHandler::newProperty -(Id /*nId*/, const OOXMLValue::Pointer_t& /*pVal*/) +(Id /*nId*/, const OOXMLValue& /*pVal*/) { } @@ -801,7 +801,7 @@ void OOXMLFastContextHandler::clearTableProps() void OOXMLFastContextHandler::sendPropertiesWithId(Id nId) { - OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet())); + OOXMLValue pValue(OOXMLValue::createPropertySet(getPropertySet())); OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySet); pPropertySet->add(nId, pValue, OOXMLProperty::SPRM); @@ -854,9 +854,9 @@ void OOXMLFastContextHandler::setXNoteId(const sal_Int32 nId) mpParserState->setXNoteId(nId); } -void OOXMLFastContextHandler::setXNoteId(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandler::setXNoteId(const OOXMLValue& pValue) { - mpParserState->setXNoteId(sal_Int32(pValue->getInt())); + mpParserState->setXNoteId(sal_Int32(pValue.getInt())); } sal_Int32 OOXMLFastContextHandler::getXNoteId() const @@ -910,7 +910,7 @@ void OOXMLFastContextHandler::resolveData(const OUString & rId) uno::Reference<io::XInputStream> xInputStream (objDocument->getInputStreamForId(rId)); - OOXMLValue::Pointer_t aValue(new OOXMLInputStreamValue(xInputStream)); + OOXMLValue aValue(OOXMLValue::createInputStream(xInputStream)); newProperty(NS_ooxml::LN_inputstream, aValue); } @@ -948,8 +948,7 @@ void OOXMLFastContextHandler::sendPropertiesToParent() if (pProps) { - OOXMLValue::Pointer_t pValue - (new OOXMLPropertySetValue(getPropertySet())); + OOXMLValue pValue(OOXMLValue::createPropertySet(getPropertySet())); pParentProps->add(getId(), pValue, OOXMLProperty::SPRM); @@ -983,7 +982,7 @@ OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream() } void OOXMLFastContextHandlerStream::newProperty(Id nId, - const OOXMLValue::Pointer_t& pVal) + const OOXMLValue& pVal) { if (nId != 0x0) { @@ -1063,13 +1062,13 @@ void OOXMLFastContextHandlerProperties::lcl_endFastElement } } -OOXMLValue::Pointer_t OOXMLFastContextHandlerProperties::getValue() const +OOXMLValue OOXMLFastContextHandlerProperties::getValue() const { - return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet)); + return OOXMLValue::createPropertySet(mpPropertySet); } void OOXMLFastContextHandlerProperties::newProperty -(Id nId, const OOXMLValue::Pointer_t& pVal) +(Id nId, const OOXMLValue& pVal) { if (nId != 0x0) { @@ -1204,8 +1203,7 @@ OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable() void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement (Token_t /*Element*/) { - OOXMLTable::ValuePointer_t pTmpVal - (new OOXMLPropertySetValue(mpPropertySet->clone())); + OOXMLValue pTmpVal(OOXMLValue::createPropertySet(mpPropertySet->clone())); mTable.add(pTmpVal); @@ -1230,14 +1228,14 @@ OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue() { } -void OOXMLFastContextHandlerValue::setValue(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandlerValue::setValue(const OOXMLValue& pValue) { - mpValue = pValue; + maValue = pValue; } -OOXMLValue::Pointer_t OOXMLFastContextHandlerValue::getValue() const +OOXMLValue OOXMLFastContextHandlerValue::getValue() const { - return mpValue; + return maValue; } void OOXMLFastContextHandlerValue::lcl_endFastElement @@ -1250,36 +1248,36 @@ void OOXMLFastContextHandlerValue::lcl_endFastElement void OOXMLFastContextHandlerValue::setDefaultBooleanValue() { - if (!mpValue) + if (!maValue.hasValue()) { - OOXMLValue::Pointer_t pValue = OOXMLBooleanValue::Create(true); + OOXMLValue pValue = OOXMLValue::createBoolean(true); setValue(pValue); } } void OOXMLFastContextHandlerValue::setDefaultIntegerValue() { - if (!mpValue) + if (!maValue.hasValue()) { - OOXMLValue::Pointer_t pValue = OOXMLIntegerValue::Create(0); + OOXMLValue pValue = OOXMLValue::createInteger(0); setValue(pValue); } } void OOXMLFastContextHandlerValue::setDefaultHexValue() { - if (!mpValue) + if (!maValue.hasValue()) { - OOXMLValue::Pointer_t pValue(new OOXMLHexValue(sal_uInt32(0))); + OOXMLValue pValue(OOXMLValue::createHex(sal_uInt32(0))); setValue(pValue); } } void OOXMLFastContextHandlerValue::setDefaultStringValue() { - if (!mpValue) + if (!maValue.hasValue()) { - OOXMLValue::Pointer_t pValue(new OOXMLStringValue(OUString())); + OOXMLValue pValue(OOXMLValue::createString(OUString())); setValue(pValue); } } @@ -1288,7 +1286,7 @@ void OOXMLFastContextHandlerValue::setDefaultStringValue() void OOXMLFastContextHandlerValue::pushBiDiEmbedLevel() { const bool bRtl - = mpValue && mpValue->getInt() == NS_ooxml::LN_Value_ST_Direction_rtl; + = maValue.hasValue() && maValue.getInt() == NS_ooxml::LN_Value_ST_Direction_rtl; OOXMLFactory::characters(this, bRtl ? u"\u202B"_ustr : u"\u202A"_ustr); // RLE / LRE } @@ -1299,7 +1297,7 @@ void OOXMLFastContextHandlerValue::popBiDiEmbedLevel() void OOXMLFastContextHandlerValue::handleGridAfter() { - if (!getValue()) + if (!getValue().hasValue()) return; if (OOXMLFastContextHandler* pTableRowProperties = getParent()) @@ -1354,12 +1352,11 @@ void OOXMLFastContextHandlerTable::addCurrentChild() OOXMLFastContextHandler * pHandler = dynamic_cast<OOXMLFastContextHandler*>(mCurrentChild.get()); if (pHandler != nullptr) { - OOXMLValue::Pointer_t pValue(pHandler->getValue()); + OOXMLValue pValue(pHandler->getValue()); - if (pValue) + if (pValue.hasValue()) { - OOXMLTable::ValuePointer_t pTmpVal(pValue->clone()); - mTable.add(pTmpVal); + mTable.add(pValue); } } } @@ -1408,15 +1405,15 @@ void OOXMLFastContextHandlerXNote::lcl_endFastElement setForwardEvents(mbForwardEventsSaved); } -void OOXMLFastContextHandlerXNote::checkId(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandlerXNote::checkId(const OOXMLValue& pValue) { - mnMyXNoteId = sal_Int32(pValue->getInt()); + mnMyXNoteId = sal_Int32(pValue.getInt()); mpStream->checkId(mnMyXNoteId); } -void OOXMLFastContextHandlerXNote::checkType(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandlerXNote::checkType(const OOXMLValue& pValue) { - mnMyXNoteType = pValue->getInt(); + mnMyXNoteType = pValue.getInt(); } /* @@ -1439,7 +1436,7 @@ void OOXMLFastContextHandlerTextTableCell::startCell() { OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + OOXMLValue pVal = OOXMLValue::createBoolean(mnTableDepth > 0); pProps->add(NS_ooxml::LN_tcStart, pVal, OOXMLProperty::SPRM); } @@ -1454,19 +1451,19 @@ void OOXMLFastContextHandlerTextTableCell::endCell() OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + OOXMLValue pVal = OOXMLValue::createInteger(mnTableDepth); pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + OOXMLValue pVal = OOXMLValue::createBoolean(mnTableDepth > 0); pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + OOXMLValue pVal = OOXMLValue::createBoolean(mnTableDepth > 0); pProps->add(NS_ooxml::LN_tcEnd, pVal, OOXMLProperty::SPRM); } @@ -1493,12 +1490,12 @@ void OOXMLFastContextHandlerTextTableRow::startRow() void OOXMLFastContextHandlerTextTableRow::endRow() { - if (mpGridAfter) + if (maGridAfter.hasValue()) { // Grid after is the same as grid before, the empty cells are just // inserted after the real ones, not before. - handleGridBefore(mpGridAfter); - mpGridAfter = nullptr; + handleGridBefore(maGridAfter); + maGridAfter = OOXMLValue(); } startParagraphGroup(); @@ -1507,15 +1504,15 @@ void OOXMLFastContextHandlerTextTableRow::endRow() { OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + OOXMLValue pVal = OOXMLValue::createInteger(mnTableDepth); pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_tblRow, pVal, OOXMLProperty::SPRM); } @@ -1532,25 +1529,25 @@ void OOXMLFastContextHandlerTextTableRow::endRow() } namespace { -OOXMLValue::Pointer_t fakeNoBorder() +OOXMLValue fakeNoBorder() { OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(0); + OOXMLValue pVal = OOXMLValue::createInteger(0); pProps->add(NS_ooxml::LN_CT_Border_val, pVal, OOXMLProperty::ATTRIBUTE); - OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue(std::move(pProps))); + OOXMLValue pValue( OOXMLValue::createPropertySet(std::move(pProps))); return pValue; } } // Handle w:gridBefore here by faking necessary input that'll fake cells. I'm apparently // not insane enough to find out how to add cells in dmapper. -void OOXMLFastContextHandlerTextTableRow::handleGridBefore( const OOXMLValue::Pointer_t& val ) +void OOXMLFastContextHandlerTextTableRow::handleGridBefore( const OOXMLValue& val ) { // start removing: disable for w:gridBefore - if (!mpGridAfter) + if (!maGridAfter.hasValue()) return; - int count = val->getInt(); + int count = val.getInt(); for( int i = 0; i < count; ++i ) @@ -1562,15 +1559,15 @@ void OOXMLFastContextHandlerTextTableRow::handleGridBefore( const OOXMLValue::Po // This whole part is OOXMLFastContextHandlerTextTableCell::endCell() . OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + OOXMLValue pVal = OOXMLValue::createInteger(mnTableDepth); pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + OOXMLValue pVal = OOXMLValue::createInteger(1); pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); } { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + OOXMLValue pVal = OOXMLValue::createBoolean(mnTableDepth > 0); pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); } @@ -1584,7 +1581,7 @@ void OOXMLFastContextHandlerTextTableRow::handleGridBefore( const OOXMLValue::Po NS_ooxml::LN_CT_TcBorders_start, NS_ooxml::LN_CT_TcBorders_end }; for(sal_uInt32 border : borders) pBorderProps->add(border, fakeNoBorder(), OOXMLProperty::SPRM); - OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue(std::move(pBorderProps)) ); + OOXMLValue pValue( OOXMLValue::createPropertySet(std::move(pBorderProps)) ); pCellProps->add(NS_ooxml::LN_CT_TcPrBase_tcBorders, pValue, OOXMLProperty::SPRM); mpParserState->setCellProperties(pCellProps); } @@ -1629,7 +1626,7 @@ void OOXMLFastContextHandlerTextTable::lcl_startFastElement OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + OOXMLValue pVal = OOXMLValue::createInteger(mnTableDepth); pProps->add(NS_ooxml::LN_tblStart, pVal, OOXMLProperty::SPRM); } mpParserState->setCharacterProperties(pProps); @@ -1644,7 +1641,7 @@ void OOXMLFastContextHandlerTextTable::lcl_endFastElement OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + OOXMLValue pVal = OOXMLValue::createInteger(mnTableDepth); pProps->add(NS_ooxml::LN_tblEnd, pVal, OOXMLProperty::SPRM); } mpParserState->setCharacterProperties(pProps); @@ -1815,8 +1812,7 @@ void OOXMLFastContextHandlerShape::sendShape( Token_t Element ) if (!xShape.is()) return; - OOXMLValue::Pointer_t - pValue(new OOXMLShapeValue(xShape)); + OOXMLValue pValue(OOXMLValue::createShape(xShape)); newProperty(NS_ooxml::LN_shape, pValue); bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); @@ -2141,7 +2137,7 @@ OOXMLFastContextHandlerWrapper::getFastContextHandler() const } void OOXMLFastContextHandlerWrapper::newProperty -(Id nId, const OOXMLValue::Pointer_t& pVal) +(Id nId, const OOXMLValue& pVal) { if (mxWrappedContext.is()) { @@ -2315,7 +2311,7 @@ void OOXMLFastContextHandlerMath::process() return; OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref )); + OOXMLValue pVal( OOXMLValue::createStarMath( ref )); if (mbIsMathPara) { switch (mnMathJcVal) @@ -2352,20 +2348,20 @@ void OOXMLFastContextHandlerCommentEx::lcl_endFastElement(Token_t /*Element*/) mpStream->commentProps(m_sParaId, { m_bDone, m_sParentId }); } -void OOXMLFastContextHandlerCommentEx::att_paraId(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandlerCommentEx::att_paraId(const OOXMLValue& pValue) { - m_sParaId = pValue->getString(); + m_sParaId = pValue.getString(); } -void OOXMLFastContextHandlerCommentEx::att_done(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandlerCommentEx::att_done(const OOXMLValue& pValue) { - if (pValue->getInt()) + if (pValue.getInt()) m_bDone = true; } -void OOXMLFastContextHandlerCommentEx::att_paraIdParent(const OOXMLValue::Pointer_t& pValue) +void OOXMLFastContextHandlerCommentEx::att_paraIdParent(const OOXMLValue& pValue) { - m_sParentId = pValue->getString(); + m_sParentId = pValue.getString(); } } diff --git a/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.hxx b/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.hxx index 4dfb05d91503..03a4d40e5c2f 100644 --- a/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.hxx +++ b/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.hxx @@ -73,7 +73,7 @@ public: @return the value */ - virtual OOXMLValue::Pointer_t getValue() const; + virtual OOXMLValue getValue() const; /** Returns a string describing the type of the context. @@ -90,7 +90,7 @@ public: /// @throws css::xml::sax::SAXException virtual void attributes(const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs); - virtual void newProperty(Id aId, const OOXMLValue::Pointer_t& pVal); + virtual void newProperty(Id aId, const OOXMLValue& pVal); virtual void setPropertySet(const OOXMLPropertySet::Pointer_t& pPropertySet); virtual OOXMLPropertySet::Pointer_t getPropertySet() const; @@ -111,7 +111,7 @@ public: void setDocument(OOXMLDocumentImpl* pDocument); OOXMLDocumentImpl* getDocument(); - void setXNoteId(const OOXMLValue::Pointer_t& pValue); + void setXNoteId(const OOXMLValue& pValue); void setXNoteId(const sal_Int32 nId); sal_Int32 getXNoteId() const; void setForwardEvents(bool bForwardEvents); @@ -186,7 +186,7 @@ public: void sendPropertyToParent(); OOXMLFastContextHandler* getParent() const { return mpParent; } - void setGridAfter(const OOXMLValue::Pointer_t& pGridAfter) { mpGridAfter = pGridAfter; } + void setGridAfter(const OOXMLValue& pGridAfter) { maGridAfter = pGridAfter; } protected: OOXMLFastContextHandler * mpParent; @@ -235,7 +235,7 @@ protected: bool m_inPositionV; bool mbAllowInCell; // o:allowincell bool mbIsVMLfound; - OOXMLValue::Pointer_t mpGridAfter; + OOXMLValue maGridAfter; private: void operator =(OOXMLFastContextHandler const &) = delete; @@ -263,7 +263,7 @@ public: const OOXMLPropertySet::Pointer_t& getPropertySetAttrs() const { return mpPropertySetAttrs;} - virtual void newProperty(Id aId, const OOXMLValue::Pointer_t& pVal) override; + virtual void newProperty(Id aId, const OOXMLValue& pVal) override; void sendProperty(Id nId); virtual OOXMLPropertySet::Pointer_t getPropertySet() const override; @@ -279,10 +279,10 @@ public: explicit OOXMLFastContextHandlerProperties(OOXMLFastContextHandler * pContext); virtual ~OOXMLFastContextHandlerProperties() override; - virtual OOXMLValue::Pointer_t getValue() const override; + virtual OOXMLValue getValue() const override; virtual ResourceEnum_t getResource() const override { return PROPERTIES; } - virtual void newProperty(Id nId, const OOXMLValue::Pointer_t& pVal) override; + virtual void newProperty(Id nId, const OOXMLValue& pVal) override; void handleXNotes(); void handleHdrFtr(); @@ -329,8 +329,8 @@ public: explicit OOXMLFastContextHandlerValue(OOXMLFastContextHandler * pContext); virtual ~OOXMLFastContextHandlerValue() override; - void setValue(const OOXMLValue::Pointer_t& pValue); - virtual OOXMLValue::Pointer_t getValue() const override; + void setValue(const OOXMLValue& pValue); + virtual OOXMLValue getValue() const override; virtual void lcl_endFastElement(Token_t Element) override; @@ -347,7 +347,7 @@ public: void handleGridAfter(); private: - OOXMLValue::Pointer_t mpValue; + OOXMLValue maValue; }; class OOXMLFastContextHandlerTable : public OOXMLFastContextHandler @@ -379,9 +379,9 @@ public: explicit OOXMLFastContextHandlerXNote(OOXMLFastContextHandler * pContext); virtual ~OOXMLFastContextHandlerXNote() override; - void checkId(const OOXMLValue::Pointer_t& pValue); + void checkId(const OOXMLValue& pValue); - void checkType(const OOXMLValue::Pointer_t& pValue); + void checkType(const OOXMLValue& pValue); virtual std::string getType() const override { return "XNote"; } @@ -419,7 +419,7 @@ public: static void startRow(); void endRow(); - void handleGridBefore( const OOXMLValue::Pointer_t& val ); + void handleGridBefore( const OOXMLValue& val ); }; class OOXMLFastContextHandlerTextTable : public OOXMLFastContextHandler @@ -511,7 +511,7 @@ public: void addNamespace(Id nId); void addToken( Token_t Element ); - virtual void newProperty(Id nId, const OOXMLValue::Pointer_t& pVal) override; + virtual void newProperty(Id nId, const OOXMLValue& pVal) override; virtual void setPropertySet(const OOXMLPropertySet::Pointer_t& pPropertySet) override; virtual OOXMLPropertySet::Pointer_t getPropertySet() const override; @@ -619,9 +619,9 @@ public: virtual std::string getType() const override { return "CommentEx"; } virtual void lcl_endFastElement(Token_t Element) override; - void att_paraId(const OOXMLValue::Pointer_t& pValue); - void att_done(const OOXMLValue::Pointer_t& pValue); - void att_paraIdParent(const OOXMLValue::Pointer_t& pValue); + void att_paraId(const OOXMLValue& pValue); + void att_done(const OOXMLValue& pValue); + void att_paraIdParent(const OOXMLValue& pValue); private: OUString m_sParaId; diff --git a/sw/source/writerfilter/ooxml/OOXMLFastHelper.hxx b/sw/source/writerfilter/ooxml/OOXMLFastHelper.hxx index ecb8b6943b11..610000e6deac 100644 --- a/sw/source/writerfilter/ooxml/OOXMLFastHelper.hxx +++ b/sw/source/writerfilter/ooxml/OOXMLFastHelper.hxx @@ -29,9 +29,6 @@ class OOXMLFastHelper public: static rtl::Reference<OOXMLFastContextHandler> createAndSetParentAndDefine (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine); - - static void newProperty(OOXMLFastContextHandler * pHandler, - Id nId, sal_Int32 nValue); }; template <class T> @@ -46,16 +43,16 @@ rtl::Reference<OOXMLFastContextHandler> OOXMLFastHelper<T>::createAndSetParentAn return pTmp; } -template <class T> -void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler, +inline void newIntegerProperty(OOXMLFastContextHandler * pHandler, Id nId, sal_Int32 nVal) { - OOXMLValue::Pointer_t pVal(T::Create(nVal)); + OOXMLValue pVal(OOXMLValue::createInteger(nVal)); pHandler->newProperty(nId, pVal); } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx b/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx index a59746ccfae9..20099de77811 100644 --- a/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx +++ b/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx @@ -31,9 +31,9 @@ namespace writerfilter::ooxml { using namespace com::sun::star; -OOXMLProperty::OOXMLProperty(Id id, OOXMLValue::Pointer_t pValue, +OOXMLProperty::OOXMLProperty(Id id, const OOXMLValue& pValue, OOXMLProperty::Type_t eType) - : mId(id), mpValue(std::move(pValue)), meType(eType) + : mId(id), maValue(pValue), meType(eType) { } @@ -48,12 +48,9 @@ sal_uInt32 OOXMLProperty::getId() const writerfilter::Reference<Properties>::Pointer_t OOXMLProperty::getProps() { - writerfilter::Reference<Properties>::Pointer_t pResult; - - if (mpValue) - pResult = mpValue->getProperties(); - - return pResult; + if (maValue.hasValue()) + return maValue.getProperties(); + return nullptr; } #ifdef DBG_UTIL @@ -83,8 +80,8 @@ std::string OOXMLProperty::toString() const sResult += getName(); sResult += ", "; - if (mpValue) - sResult += mpValue->toString(); + if (maValue.hasValue()) + sResult += maValue.toString(); else sResult +="(null)"; sResult +=")"; @@ -111,7 +108,7 @@ void OOXMLProperty::resolve(writerfilter::Properties & rProperties) class OOXMLValue */ -OOXMLValue::OOXMLValue() +OOXMLValue::OOXMLValue(VariantType aData) : maData(std::move(aData)) { } @@ -121,191 +118,216 @@ OOXMLValue::~OOXMLValue() int OOXMLValue::getInt() const { + assert(maData.index() != 0 && "this OOXMLValue is empty"); + switch(maData.index()) + { + case 1: return std::get<bool>(maData) ? 1 : 0; // bool + case 2: return std::get<2>(maData); // int + case 3: return std::get<3>(maData); // universal measure + case 4: return std::get<4>(maData); // measure or percent + case 5: return std::get<5>(maData); // hex + } return 0; } OUString OOXMLValue::getString() const { + assert(maData.index() != 0 && "this OOXMLValue is empty"); + if (std::holds_alternative<OUString>(maData)) + return std::get<OUString>(maData); return OUString(); } uno::Any OOXMLValue::getAny() const { + assert(maData.index() != 0 && "this OOXMLValue is empty"); + switch(maData.index()) + { + case 1: return uno::Any(std::get<bool>(maData)); + case 2: return uno::Any(std::get<2>(maData)); // int + case 6: return uno::Any(std::get<OUString>(maData)); + case 9: return uno::Any(std::get<uno::Reference<io::XInputStream>>(maData)); + case 10: return uno::Any(std::get<uno::Reference<drawing::XShape>>(maData)); + case 11: return uno::Any(std::get<uno::Reference<embed::XEmbeddedObject>>(maData)); + default: break; + } return uno::Any(); } writerfilter::Reference<Properties>::Pointer_t OOXMLValue::getProperties() const { + assert(maData.index() != 0 && "this OOXMLValue is empty"); + if (std::holds_alternative<tools::SvRef<OOXMLPropertySet>>(maData)) + return std::get<tools::SvRef<OOXMLPropertySet>>(maData).get(); return writerfilter::Reference<Properties>::Pointer_t(); } writerfilter::Reference<BinaryObj>::Pointer_t OOXMLValue::getBinary() const { + assert(maData.index() != 0 && "this OOXMLValue is empty"); + if (std::holds_alternative<writerfilter::Reference<BinaryObj>::Pointer_t>(maData)) + return std::get<writerfilter::Reference<BinaryObj>::Pointer_t>(maData); return writerfilter::Reference<BinaryObj>::Pointer_t(); } #ifdef DBG_UTIL std::string OOXMLValue::toString() const { - return "OOXMLValue"; -} -#endif - -OOXMLValue * OOXMLValue::clone() const -{ - return new OOXMLValue(*this); -} - -/* - class OOXMLBinaryValue - */ - -OOXMLBinaryValue::OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t pBinaryObj) -: mpBinaryObj(std::move(pBinaryObj)) -{ -} - -OOXMLBinaryValue::~OOXMLBinaryValue() -{ -} - -writerfilter::Reference<BinaryObj>::Pointer_t OOXMLBinaryValue::getBinary() const -{ - return mpBinaryObj; -} - -#ifdef DBG_UTIL -std::string OOXMLBinaryValue::toString() const -{ - return "BinaryObj"; + switch(maData.index()) + { + case 0: return "empty"; + case 1: return std::get<bool>(maData) ? "true" : "false"; + case 2: // int + { + auto i = std::get<2>(maData); + char buffer[256]; + snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, i); + return buffer; + } + case 3: // universal measure + return std::string(OString::number(std::get<3>(maData))); + case 4: // measure or percent + return std::string(OString::number(std::get<4>(maData))); + case 5: // hex + { + auto i = std::get<5>(maData); + char buffer[256]; + snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, i); + return buffer; + } + case 6: // OUString + return std::string(OUStringToOString(std::get<OUString>(maData), RTL_TEXTENCODING_ASCII_US)); + case 7: // Any + return "Any"; + break; + case 8: // PropertySet + { + auto pPropertySet = std::get<tools::SvRef<OOXMLPropertySet>>(maData); + char sBuffer[256]; + snprintf(sBuffer, sizeof(sBuffer), "t:%p, m:%p", this, pPropertySet.get()); + return "OOXMLPropertySet(" + std::string(sBuffer) + ")"; + } + case 9: + return "BinaryObj"; + case 10: + return "InputStream"; + case 11: + return "Shape"; + case 12: + return "StarMath"; + default: + assert(false); + } + return ""; } #endif -OOXMLValue * OOXMLBinaryValue::clone() const -{ - return new OOXMLBinaryValue(mpBinaryObj); -} - -/* - class OOXMLBooleanValue -*/ - -bool GetBooleanValue(std::string_view pValue) -{ - return pValue == "true" - || pValue == "True" - || pValue == "1" - || pValue == "on" - || pValue == "On"; -} - -OOXMLValue::Pointer_t const & OOXMLBooleanValue::Create(bool bValue) +OOXMLValue* OOXMLValue::clone() const { - static OOXMLValue::Pointer_t False(new OOXMLBooleanValue (false)); - static OOXMLValue::Pointer_t True(new OOXMLBooleanValue (true)); - - return bValue ? True : False; + return new OOXMLValue(maData); } -OOXMLValue::Pointer_t const & OOXMLBooleanValue::Create(std::string_view pValue) -{ - return Create (GetBooleanValue(pValue)); -} -OOXMLBooleanValue::OOXMLBooleanValue(bool bValue) -: mbValue(bValue) +// static +OOXMLValue OOXMLValue::createBoolean(bool bValue) { + return OOXMLValue(VariantType(std::in_place_type<bool>, bValue)); } -OOXMLBooleanValue::~OOXMLBooleanValue() +// static +OOXMLValue OOXMLValue::createBoolean(std::string_view bValue) { + return OOXMLValue(VariantType(std::in_place_type<bool>, GetBooleanValue(bValue))); } -int OOXMLBooleanValue::getInt() const +// static +OOXMLValue OOXMLValue::createInteger(int aValue) { - return mbValue ? 1 : 0; + return OOXMLValue(VariantType(std::in_place_index_t<2>(), aValue)); } -uno::Any OOXMLBooleanValue::getAny() const +// static +OOXMLValue OOXMLValue::createHex(sal_uInt32 aValue) { - return uno::Any(mbValue); + return OOXMLValue(VariantType(std::in_place_index_t<5>(), aValue)); } -#ifdef DBG_UTIL -std::string OOXMLBooleanValue::toString() const +// static +OOXMLValue OOXMLValue::createHex(std::string_view pValue) { - return mbValue ? "true" : "false"; + return OOXMLValue(VariantType(std::in_place_index_t<5>(), o3tl::toUInt32(pValue, 16))); } -#endif - -OOXMLValue * OOXMLBooleanValue::clone() const -{ - return new OOXMLBooleanValue(*this); -} - -/* - class OOXMLStringValue -*/ -OOXMLStringValue::OOXMLStringValue(OUString sStr) -: mStr(std::move(sStr)) +// static +OOXMLValue OOXMLValue::createHexColor(std::string_view pValue) { -} + sal_uInt32 aValue(COL_AUTO); + if (pValue == "auto") + return OOXMLValue(VariantType(std::in_place_index_t<5>(), aValue)); -OOXMLStringValue::~OOXMLStringValue() -{ -} + aValue = o3tl::toUInt32(pValue, 16); -uno::Any OOXMLStringValue::getAny() const -{ - return uno::Any(mStr); + // Convert hash-encoded values (like #FF0080) + const sal_Int32 nLen = pValue.size(); + if ( !aValue && nLen > 1 && pValue[0] == '#' ) + { + sal_Int32 nColor(COL_AUTO); + // Word appears to require strict 6 digit length, else it ignores it + if ( nLen == 7 ) + { + const OUString sHashColor(pValue.data(), nLen, RTL_TEXTENCODING_ASCII_US); + sax::Converter::convertColor( nColor, sHashColor ); + } + aValue = nColor; + } + return OOXMLValue(VariantType(std::in_place_index_t<5>(), aValue)); } -OUString OOXMLStringValue::getString() const +// static +OOXMLValue OOXMLValue::createString(const OUString& bValue) { - return mStr; + return OOXMLValue(VariantType(std::in_place_type<OUString>, bValue)); } -#ifdef DBG_UTIL -std::string OOXMLStringValue::toString() const +// static +OOXMLValue OOXMLValue::createShape(const css::uno::Reference<css::drawing::XShape>& xShape) { - return std::string(OUStringToOString(mStr, RTL_TEXTENCODING_ASCII_US)); + return OOXMLValue(VariantType(std::in_place_type<css::uno::Reference<css::drawing::XShape>>, xShape)); } -#endif -OOXMLValue * OOXMLStringValue::clone() const +// static +OOXMLValue OOXMLValue::createBinary(const OOXMLBinaryObjectReference::Pointer_t& pBinaryObj) { - return new OOXMLStringValue(*this); + return OOXMLValue(VariantType(std::in_place_type<OOXMLBinaryObjectReference::Pointer_t>, pBinaryObj)); } -/* - class OOXMLInputStreamValue - */ -OOXMLInputStreamValue::OOXMLInputStreamValue(uno::Reference<io::XInputStream> xInputStream) -: mxInputStream(std::move(xInputStream)) +// static +OOXMLValue OOXMLValue::createInputStream(const uno::Reference<io::XInputStream>& rValue) { + return OOXMLValue(VariantType(std::in_place_type<uno::Reference<io::XInputStream>>, rValue)); } -OOXMLInputStreamValue::~OOXMLInputStreamValue() +// static +OOXMLValue OOXMLValue::createPropertySet(const tools::SvRef<OOXMLPropertySet>& rValue) { + return OOXMLValue(VariantType(std::in_place_type<tools::SvRef<OOXMLPropertySet>>, rValue)); } -uno::Any OOXMLInputStreamValue::getAny() const +// static +OOXMLValue OOXMLValue::createStarMath(const uno::Reference< embed::XEmbeddedObject >& rValue) { - return uno::Any(mxInputStream); + return OOXMLValue(VariantType(std::in_place_type<uno::Reference< embed::XEmbeddedObject >>, rValue)); } -#ifdef DBG_UTIL -std::string OOXMLInputStreamValue::toString() const +bool GetBooleanValue(std::string_view pValue) { - return "InputStream"; + return pValue == "true" + || pValue == "True" + || pValue == "1" + || pValue == "on" + || pValue == "On"; } -#endif -OOXMLValue * OOXMLInputStreamValue::clone() const -{ - return new OOXMLInputStreamValue(mxInputStream); -} /** class OOXMLPropertySet @@ -364,7 +386,7 @@ void OOXMLPropertySet::add(const OOXMLProperty::Pointer_t& pProperty) } } -void OOXMLPropertySet::add(Id id, const OOXMLValue::Pointer_t& pValue, OOXMLProperty::Type_t eType) +void OOXMLPropertySet::add(Id id, const OOXMLValue& pValue, OOXMLProperty::Type_t eType) { OOXMLProperty::Pointer_t pProperty(new OOXMLProperty(id, pValue, eType)); add(pProperty); @@ -414,177 +436,10 @@ std::string OOXMLPropertySet::toString() } #endif -/* - class OOXMLPropertySetValue -*/ - -OOXMLPropertySetValue::OOXMLPropertySetValue(OOXMLPropertySet::Pointer_t pPropertySet) - : mpPropertySet(std::move(pPropertySet)) -{ -} - -OOXMLPropertySetValue::~OOXMLPropertySetValue() -{ -} - -writerfilter::Reference<Properties>::Pointer_t OOXMLPropertySetValue::getProperties() const -{ - return writerfilter::Reference<Properties>::Pointer_t(mpPropertySet.get()); -} - -#ifdef DBG_UTIL -std::string OOXMLPropertySetValue::toString() const -{ - char sBuffer[256]; - - snprintf(sBuffer, sizeof(sBuffer), "t:%p, m:%p", this, mpPropertySet.get()); - - return "OOXMLPropertySetValue(" + std::string(sBuffer) + ")"; -} -#endif - -OOXMLValue * OOXMLPropertySetValue::clone() const -{ - return new OOXMLPropertySetValue(*this); -} - -/* - class OOXMLIntegerValue -*/ - -OOXMLValue::Pointer_t OOXMLIntegerValue::Create(sal_Int32 nValue) -{ - static OOXMLValue::Pointer_t Zero(new OOXMLIntegerValue (0)); - static OOXMLValue::Pointer_t One(new OOXMLIntegerValue (1)); - static OOXMLValue::Pointer_t Two(new OOXMLIntegerValue (2)); - static OOXMLValue::Pointer_t Three(new OOXMLIntegerValue (3)); - static OOXMLValue::Pointer_t Four(new OOXMLIntegerValue (4)); - static OOXMLValue::Pointer_t Five(new OOXMLIntegerValue (5)); - static OOXMLValue::Pointer_t Six(new OOXMLIntegerValue (6)); - static OOXMLValue::Pointer_t Seven(new OOXMLIntegerValue (7)); - static OOXMLValue::Pointer_t Eight(new OOXMLIntegerValue (8)); - static OOXMLValue::Pointer_t Nine(new OOXMLIntegerValue (9)); - - switch (nValue) { - case 0: return Zero; - case 1: return One; - case 2: return Two; - case 3: return Three; - case 4: return Four; - case 5: return Five; - case 6: return Six; - case 7: return Seven; - case 8: return Eight; - case 9: return Nine; - default: break; - } - - OOXMLValue::Pointer_t value(new OOXMLIntegerValue(nValue)); - - return value; -} - -OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue) -: mnValue(nValue) -{ -} - -OOXMLIntegerValue::~OOXMLIntegerValue() -{ -} - -int OOXMLIntegerValue::getInt() const -{ - return mnValue; -} - -uno::Any OOXMLIntegerValue::getAny() const -{ - return uno::Any(mnValue); -} - -OOXMLValue * OOXMLIntegerValue::clone() const -{ - return new OOXMLIntegerValue(*this); -} - -#ifdef DBG_UTIL -std::string OOXMLIntegerValue::toString() const -{ - char buffer[256]; - snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, mnValue); - - return buffer; -} -#endif - -/* - class OOXMLHexValue -*/ - -OOXMLHexValue::OOXMLHexValue(sal_uInt32 nValue) -: mnValue(nValue) -{ -} - -OOXMLHexValue::OOXMLHexValue(std::string_view pValue) -: mnValue(o3tl::toUInt32(pValue, 16)) -{ -} - -OOXMLHexValue::~OOXMLHexValue() -{ -} - -int OOXMLHexValue::getInt() const -{ - return mnValue; -} - -OOXMLValue * OOXMLHexValue::clone() const -{ - return new OOXMLHexValue(*this); -} - -#ifdef DBG_UTIL -std::string OOXMLHexValue::toString() const -{ - char buffer[256]; - snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, mnValue); - - return buffer; -} -#endif - -/* - class OOXMLHexColorValue -*/ -OOXMLHexColorValue::OOXMLHexColorValue(std::string_view pValue) - : OOXMLHexValue(sal_uInt32(COL_AUTO)) -{ - if (pValue == "auto") - return; - - mnValue = o3tl::toUInt32(pValue, 16); - - // Convert hash-encoded values (like #FF0080) - const sal_Int32 nLen = pValue.size(); - if ( !mnValue && nLen > 1 && pValue[0] == '#' ) - { - sal_Int32 nColor(COL_AUTO); - // Word appears to require strict 6 digit length, else it ignores it - if ( nLen == 7 ) - { - const OUString sHashColor(pValue.data(), nLen, RTL_TEXTENCODING_ASCII_US); - sax::Converter::convertColor( nColor, sHashColor ); - } - mnValue = nColor; - } -} - // OOXMLUniversalMeasureValue // ECMA-376 5th ed. Part 1 , 22.9.2.15 -OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(std::string_view pValue, sal_uInt32 npPt) +// static +OOXMLValue OOXMLValue::createUniversalMeasure(std::string_view pValue, sal_uInt32 npPt) { double val = o3tl::toDouble(pValue); // will ignore the trailing unit @@ -609,116 +464,43 @@ OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(std::string_view pValue, val = o3tl::convert(val, o3tl::Length::pc, o3tl::Length::pt) * npPt; } - mnValue = std::round(val); + int nValue = std::round(val); + return OOXMLValue(VariantType(std::in_place_index_t<3>(), nValue)); } -OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue() +// static +OOXMLValue OOXMLValue::createTwipsMeasure(std::string_view pValue) { + return createUniversalMeasure(pValue, 20); } -int OOXMLUniversalMeasureValue::getInt() const +// static +OOXMLValue OOXMLValue::createHpsMeasure(std::string_view pValue) { - return mnValue; + return createUniversalMeasure(pValue, 2); } -#ifdef DBG_UTIL -std::string OOXMLUniversalMeasureValue::toString() const -{ - return std::string(OString::number(mnValue)); -} -#endif - // OOXMLMeasurementOrPercentValue // ECMA-376 5th ed. Part 1 , 17.18.107; 17.18.11 -OOXMLMeasurementOrPercentValue::OOXMLMeasurementOrPercentValue(std::string_view pValue) +// static +OOXMLValue OOXMLValue::createMeasurementOrPercent(std::string_view pValue) { double val = o3tl::toDouble(pValue); // will ignore the trailing unit + int nValue; int nLen = pValue.size(); if (nLen > 1 && pValue[nLen - 1] == '%') { - mnValue = static_cast<int>(val * 50); + nValue = static_cast<int>(val * 50); } else { - mnValue = OOXMLTwipsMeasureValue(pValue).getInt(); + nValue = createTwipsMeasure(pValue).getInt(); } + return OOXMLValue(VariantType(std::in_place_index_t<4>(), nValue)); } -int OOXMLMeasurementOrPercentValue::getInt() const -{ - return mnValue; -} - -#ifdef DBG_UTIL -std::string OOXMLMeasurementOrPercentValue::toString() const -{ - return std::string(OString::number(mnValue)); -} -#endif - -/* - class OOXMLShapeValue - */ - - -OOXMLShapeValue::OOXMLShapeValue(uno::Reference<drawing::XShape> xShape) -: mrShape(std::move(xShape)) -{ -} - -OOXMLShapeValue::~OOXMLShapeValue() -{ -} - -uno::Any OOXMLShapeValue::getAny() const -{ - return uno::Any(mrShape); -} - -#ifdef DBG_UTIL -std::string OOXMLShapeValue::toString() const -{ - return "Shape"; -} -#endif - -OOXMLValue * OOXMLShapeValue::clone() const -{ - return new OOXMLShapeValue(mrShape); -} - -/* - class OOXMLStarMathValue - */ - - -OOXMLStarMathValue::OOXMLStarMathValue( uno::Reference< embed::XEmbeddedObject > c ) -: m_component(std::move(c)) -{ -} - -OOXMLStarMathValue::~OOXMLStarMathValue() -{ -} - -uno::Any OOXMLStarMathValue::getAny() const -{ - return uno::Any(m_component); -} - -#ifdef DBG_UTIL -std::string OOXMLStarMathValue::toString() const -{ - return "StarMath"; -} -#endif - -OOXMLValue * OOXMLStarMathValue::clone() const -{ - return new OOXMLStarMathValue( m_component ); -} /* class OOXMLTableImpl @@ -742,7 +524,7 @@ void OOXMLTable::resolve(Table & rTable) for (const auto& rPropSet : mPropertySets) { writerfilter::Reference<Properties>::Pointer_t pProperties - (rPropSet->getProperties()); + (rPropSet.getProperties()); if (pProperties) pTable->entry(nPos, std::move(pProperties)); @@ -751,9 +533,9 @@ void OOXMLTable::resolve(Table & rTable) } } -void OOXMLTable::add(const ValuePointer_t& pPropertySet) +void OOXMLTable::add(const OOXMLValue& pPropertySet) { - if (pPropertySet) + if (pPropertySet.hasValue()) mPropertySets.push_back(pPropertySet); } diff --git a/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx b/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx index 524d7ff5ae94..0a5868617c9c 100644 --- a/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx +++ b/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx @@ -22,23 +22,48 @@ #include "OOXMLBinaryObjectReference.hxx" #include <com/sun/star/embed/XEmbeddedObject.hpp> #include <dmapper/resourcemodel.hxx> +#include <variant> namespace writerfilter::ooxml { -class OOXMLValue : public Value -{ -public: - typedef tools::SvRef<OOXMLValue> Pointer_t; - OOXMLValue(); - virtual ~OOXMLValue() override; +class OOXMLPropertySet; + +class OOXMLValue final : public Value +{ +public: + OOXMLValue() {} + ~OOXMLValue(); + + static OOXMLValue createBoolean(bool); + static OOXMLValue createBoolean(std::string_view); + static OOXMLValue createInteger(int); + static OOXMLValue createUniversalMeasure(int); + static OOXMLValue createUniversalMeasure(std::string_view pValue, sal_uInt32 npPt); + /// Handles OOXML's ST_TwipsMeasure value. + static OOXMLValue createTwipsMeasure(int); + static OOXMLValue createTwipsMeasure(std::string_view); + /// Handles OOXML's ST_HpsMeasure value. + static OOXMLValue createHpsMeasure(int); + static OOXMLValue createHpsMeasure(std::string_view); + static OOXMLValue createMeasurementOrPercent(int); + static OOXMLValue createMeasurementOrPercent(std::string_view); + static OOXMLValue createHex(sal_uInt32); + static OOXMLValue createHex(std::string_view); + static OOXMLValue createHexColor(std::string_view); + static OOXMLValue createString(const OUString&); + static OOXMLValue createPropertySet(const tools::SvRef<OOXMLPropertySet>&); + static OOXMLValue createBinary(const tools::SvRef<writerfilter::Reference<BinaryObj>>&); + static OOXMLValue createInputStream(const css::uno::Reference<css::io::XInputStream>&); + static OOXMLValue createShape(const css::uno::Reference<css::drawing::XShape>&); + static OOXMLValue createStarMath(const css::uno::Reference<css::embed::XEmbeddedObject>&); OOXMLValue(OOXMLValue const&) = default; OOXMLValue(OOXMLValue&&) = default; OOXMLValue& operator=(OOXMLValue const&) = default; OOXMLValue& operator=(OOXMLValue&&) = default; + bool hasValue() const { return maData.index() != 0; } virtual int getInt() const override; - ; virtual OUString getString() const override; virtual css::uno::Any getAny() const override; virtual writerfilter::Reference<Properties>::Pointer_t getProperties() const override; @@ -47,6 +72,26 @@ public: virtual std::string toString() const override; #endif virtual OOXMLValue* clone() const; + +private: + typedef std::variant<std::monostate, // + bool, // + sal_Int32, // integer + int, // universal measure + int, // measure or percent + sal_uInt32, // hex + OUString, + tools::SvRef<OOXMLPropertySet>, // aka OOXMLPropertySet::Pointer_t + tools::SvRef<writerfilter::Reference<BinaryObj>>, + css::uno::Reference<css::io::XInputStream>, + css::uno::Reference<css::drawing::XShape>, + css::uno::Reference<css::embed::XEmbeddedObject> // StarMath + > + VariantType; + + OOXMLValue(VariantType aData); + + VariantType maData; }; class OOXMLProperty final : public Sprm @@ -61,16 +106,16 @@ public: private: Id mId; - mutable OOXMLValue::Pointer_t mpValue; + mutable OOXMLValue maValue; Type_t meType; public: - OOXMLProperty(Id id, OOXMLValue::Pointer_t pValue, Type_t eType); + OOXMLProperty(Id id, const OOXMLValue& aValue, Type_t eType); OOXMLProperty(const OOXMLProperty& rSprm) = delete; virtual ~OOXMLProperty() override; sal_uInt32 getId() const override; - const OOXMLValue* getValue() const override { return mpValue.get(); } + const OOXMLValue* getValue() const override { return maValue.hasValue() ? &maValue : nullptr; } writerfilter::Reference<Properties>::Pointer_t getProps() override; #ifdef DBG_UTIL std::string getName() const override; @@ -79,83 +124,8 @@ public: void resolve(Properties& rProperties); }; -class OOXMLBinaryValue final : public OOXMLValue -{ - mutable OOXMLBinaryObjectReference::Pointer_t mpBinaryObj; - -public: - explicit OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t pBinaryObj); - virtual ~OOXMLBinaryValue() override; - - virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - bool GetBooleanValue(std::string_view pValue); -class OOXMLBooleanValue final : public OOXMLValue -{ - bool mbValue; - explicit OOXMLBooleanValue(bool bValue); - -public: - static OOXMLValue::Pointer_t const& Create(bool bValue); - static OOXMLValue::Pointer_t const& Create(std::string_view pValue); - - virtual ~OOXMLBooleanValue() override; - - OOXMLBooleanValue(OOXMLBooleanValue const&) = default; - OOXMLBooleanValue(OOXMLBooleanValue&&) = default; - OOXMLBooleanValue& operator=(OOXMLBooleanValue const&) = delete; // due to const mbValue - OOXMLBooleanValue& operator=(OOXMLBooleanValue&&) = delete; // due to const mbValue - - virtual int getInt() const override; - virtual css::uno::Any getAny() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - -class OOXMLStringValue final : public OOXMLValue -{ - OUString mStr; - -public: - explicit OOXMLStringValue(OUString sStr); - virtual ~OOXMLStringValue() override; - - OOXMLStringValue(OOXMLStringValue const&) = default; - OOXMLStringValue(OOXMLStringValue&&) = default; - OOXMLStringValue& operator=(OOXMLStringValue const&) = delete; // due to const mStr - OOXMLStringValue& operator=(OOXMLStringValue&&) = delete; // due to const mStr - - virtual css::uno::Any getAny() const override; - virtual OUString getString() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - -class OOXMLInputStreamValue final : public OOXMLValue -{ - css::uno::Reference<css::io::XInputStream> mxInputStream; - -public: - explicit OOXMLInputStreamValue(css::uno::Reference<css::io::XInputStream> xInputStream); - virtual ~OOXMLInputStreamValue() override; - - virtual css::uno::Any getAny() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - class OOXMLPropertySet final : public writerfilter::Reference<Properties> { public: @@ -176,7 +146,7 @@ public: OOXMLPropertySet& operator=(OOXMLPropertySet&&) = default; void resolve(Properties& rHandler) override; - void add(Id id, const OOXMLValue::Pointer_t& pValue, OOXMLProperty::Type_t eType); + void add(Id id, const OOXMLValue& pValue, OOXMLProperty::Type_t eType); void add(const OOXMLPropertySet::Pointer_t& pPropertySet); OOXMLPropertySet* clone() const; @@ -195,7 +165,6 @@ class OOXMLValue; class OOXMLTable final : public writerfilter::Reference<Table> { public: - typedef tools::SvRef<OOXMLValue> ValuePointer_t; OOXMLTable(); virtual ~OOXMLTable() override; @@ -205,167 +174,14 @@ public: OOXMLTable& operator=(OOXMLTable&&) = default; void resolve(Table& rTable) override; - void add(const ValuePointer_t& pPropertySet); + void add(const OOXMLValue& pPropertySet); OOXMLTable* clone() const; private: - typedef std::vector<ValuePointer_t> PropertySets_t; + typedef std::vector<OOXMLValue> PropertySets_t; PropertySets_t mPropertySets; }; -class OOXMLPropertySetValue final : public OOXMLValue -{ - OOXMLPropertySet::Pointer_t mpPropertySet; - -public: - explicit OOXMLPropertySetValue(OOXMLPropertySet::Pointer_t pPropertySet); - virtual ~OOXMLPropertySetValue() override; - - OOXMLPropertySetValue(OOXMLPropertySetValue const&) = default; - OOXMLPropertySetValue(OOXMLPropertySetValue&&) = default; - OOXMLPropertySetValue& operator=(OOXMLPropertySetValue const&) - = delete; // due to const mpPropertySet - OOXMLPropertySetValue& operator=(OOXMLPropertySetValue&&) - = delete; // due to const mpPropertySet - - virtual writerfilter::Reference<Properties>::Pointer_t getProperties() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - -class OOXMLIntegerValue final : public OOXMLValue -{ - sal_Int32 mnValue; - explicit OOXMLIntegerValue(sal_Int32 nValue); - -public: - static OOXMLValue::Pointer_t Create(sal_Int32 nValue); - virtual ~OOXMLIntegerValue() override; - - OOXMLIntegerValue(OOXMLIntegerValue const&) = default; - OOXMLIntegerValue(OOXMLIntegerValue&&) = default; - OOXMLIntegerValue& operator=(OOXMLIntegerValue const&) = delete; // due to const mnValue - OOXMLIntegerValue& operator=(OOXMLIntegerValue&&) = delete; // due to const mnValue - - virtual int getInt() const override; - virtual css::uno::Any getAny() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - -class OOXMLHexValue : public OOXMLValue -{ -protected: - sal_uInt32 mnValue; - -public: - explicit OOXMLHexValue(sal_uInt32 nValue); - explicit OOXMLHexValue(std::string_view pValue); - virtual ~OOXMLHexValue() override; - - OOXMLHexValue(OOXMLHexValue const&) = default; - OOXMLHexValue(OOXMLHexValue&&) = default; - OOXMLHexValue& operator=(OOXMLHexValue const&) = default; - OOXMLHexValue& operator=(OOXMLHexValue&&) = default; - - virtual int getInt() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - -class OOXMLHexColorValue final : public OOXMLHexValue -{ -public: - explicit OOXMLHexColorValue(std::string_view pValue); -}; - -class OOXMLUniversalMeasureValue : public OOXMLValue -{ -private: - int mnValue; - -public: - OOXMLUniversalMeasureValue(std::string_view pValue, sal_uInt32 npPt); - virtual ~OOXMLUniversalMeasureValue() override; - - OOXMLUniversalMeasureValue(OOXMLUniversalMeasureValue const&) = default; - OOXMLUniversalMeasureValue(OOXMLUniversalMeasureValue&&) = default; - OOXMLUniversalMeasureValue& operator=(OOXMLUniversalMeasureValue const&) = default; - OOXMLUniversalMeasureValue& operator=(OOXMLUniversalMeasureValue&&) = default; - - virtual int getInt() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif -}; - -/// npPt is quotient defining how much units are in 1 pt -template <sal_uInt32 npPt> class OOXMLNthPtMeasureValue final : public OOXMLUniversalMeasureValue -{ -public: - explicit OOXMLNthPtMeasureValue(std::string_view pValue) - : OOXMLUniversalMeasureValue(pValue, npPt) - { - } - virtual OOXMLValue* clone() const override { return new OOXMLNthPtMeasureValue<npPt>(*this); } -}; - -/// Handles OOXML's ST_TwipsMeasure value. -typedef OOXMLNthPtMeasureValue<20> OOXMLTwipsMeasureValue; - -/// Handles OOXML's ST_HpsMeasure value. -typedef OOXMLNthPtMeasureValue<2> OOXMLHpsMeasureValue; - -class OOXMLMeasurementOrPercentValue final : public OOXMLValue -{ - int mnValue; - -public: - explicit OOXMLMeasurementOrPercentValue(std::string_view pValue); - - virtual int getInt() const override; - virtual OOXMLValue* clone() const override { return new OOXMLMeasurementOrPercentValue(*this); } -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif -}; - -class OOXMLShapeValue final : public OOXMLValue -{ - css::uno::Reference<css::drawing::XShape> mrShape; - -public: - explicit OOXMLShapeValue(css::uno::Reference<css::drawing::XShape> xShape); - virtual ~OOXMLShapeValue() override; - - virtual css::uno::Any getAny() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - -class OOXMLStarMathValue final : public OOXMLValue -{ - css::uno::Reference<css::embed::XEmbeddedObject> m_component; - -public: - explicit OOXMLStarMathValue(css::uno::Reference<css::embed::XEmbeddedObject> component); - virtual ~OOXMLStarMathValue() override; - - virtual css::uno::Any getAny() const override; -#ifdef DBG_UTIL - virtual std::string toString() const override; -#endif - virtual OOXMLValue* clone() const override; -}; - class OOXMLPropertySetEntryToString final : public Properties { Id mnId; diff --git a/sw/source/writerfilter/ooxml/factory_ns.py b/sw/source/writerfilter/ooxml/factory_ns.py index 18b07aba1c62..83a4215b6dcd 100644 --- a/sw/source/writerfilter/ooxml/factory_ns.py +++ b/sw/source/writerfilter/ooxml/factory_ns.py @@ -51,7 +51,7 @@ public: print(" void %sAction(OOXMLFastContextHandler* pHandler);" % action) print("""virtual void charactersAction(OOXMLFastContextHandler* pHandler, const OUString & sText); - virtual void attributeAction(OOXMLFastContextHandler* pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue); + virtual void attributeAction(OOXMLFastContextHandler* pHandler, Token_t nToken, const OOXMLValue& pValue); virtual ~OOXMLFactory_%s(); diff --git a/sw/source/writerfilter/ooxml/factoryimpl_ns.py b/sw/source/writerfilter/ooxml/factoryimpl_ns.py index d4d5a2f67dc6..57242d7e870e 100644 --- a/sw/source/writerfilter/ooxml/factoryimpl_ns.py +++ b/sw/source/writerfilter/ooxml/factoryimpl_ns.py @@ -393,7 +393,7 @@ def charactersActionForValues(nsNode, refNode): ret.append(" // %s" % defineNode.getAttribute("name")) for dataNode in getChildrenByName(defineNode, "data"): if dataNode.getAttribute("type") == "int": - ret.append(" OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(sText));") + ret.append(" OOXMLValue pValue(OOXMLValue::createInteger(sText));") ret.append(" pValueHandler->setValue(pValue);") ret.append(" }") @@ -417,34 +417,35 @@ def factoryChooseAction(actionNode): ret.append(" {") extra_space = " " - if actionNode.getAttribute("action") in ("handleXNotes", "handleHdrFtr", "handleComment", "handlePicture", "handleBreak", "handleOutOfOrderBreak", "handleOLE", "handleFontRel", "handleHyperlinkURL", "handleAltChunk"): + act = actionNode.getAttribute("action") + if act in ("handleXNotes", "handleHdrFtr", "handleComment", "handlePicture", "handleBreak", "handleOutOfOrderBreak", "handleOLE", "handleFontRel", "handleHyperlinkURL", "handleAltChunk"): ret.append(" %sif (OOXMLFastContextHandlerProperties* pProperties = dynamic_cast<OOXMLFastContextHandlerProperties*>(pHandler))" % extra_space) ret.append(" %s pProperties->%s();" % (extra_space, actionNode.getAttribute("action"))) - elif actionNode.getAttribute("action") == "propagateCharacterPropertiesAsSet": + elif act == "propagateCharacterPropertiesAsSet": ret.append(" %spHandler->propagateCharacterPropertiesAsSet(%s);" % (extra_space, idToLabel(actionNode.getAttribute("sendtokenid")))) - elif actionNode.getAttribute("action") in ("startCell", "endCell"): + elif act in ("startCell", "endCell"): ret.append(" %sif (OOXMLFastContextHandlerTextTableCell* pTextTableCell = dynamic_cast<OOXMLFastContextHandlerTextTableCell*>(pHandler))" % extra_space) ret.append(" %s pTextTableCell->%s();" % (extra_space, actionNode.getAttribute("action"))) - elif actionNode.getAttribute("action") in ("startRow", "endRow"): + elif act in ("startRow", "endRow"): ret.append(" %sif (OOXMLFastContextHandlerTextTableRow* pTextTableRow = dynamic_cast<OOXMLFastContextHandlerTextTableRow*>(pHandler))" % extra_space) ret.append(" %s pTextTableRow->%s();" % (extra_space, actionNode.getAttribute("action"))) - elif actionNode.getAttribute("action") == "handleGridAfter": + elif act == "handleGridAfter": ret.append(" %sif (OOXMLFastContextHandlerValue* pValueHandler = dynamic_cast<OOXMLFastContextHandlerValue*>(pHandler))" % extra_space) ret.append(" %s pValueHandler->%s();" % (extra_space, actionNode.getAttribute("action"))) # tdf#111550 - elif actionNode.getAttribute("action") in ("start_P_Tbl"): + elif act in ("start_P_Tbl"): ret.append(" %sif (OOXMLFastContextHandlerTextTable* pTextTable = dynamic_cast<OOXMLFastContextHandlerTextTable*>(pHandler))" % extra_space) ret.append(" %s pTextTable->%s();" % (extra_space, actionNode.getAttribute("action"))) - elif actionNode.getAttribute("action") in ("sendProperty", "handleHyperlink"): + elif act in ("sendProperty", "handleHyperlink"): ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler))" % extra_space) ret.append(" %s pStream->%s();" % (extra_space, actionNode.getAttribute("action"))) - elif actionNode.getAttribute("action") == "fieldstart": + elif act == "fieldstart": ret.append(" %spHandler->startField();" % (extra_space)) - elif actionNode.getAttribute("action") == "fieldsep": + elif act == "fieldsep": ret.append(" %spHandler->fieldSeparator();" % (extra_space)) - elif actionNode.getAttribute("action") == "fieldend": + elif act == "fieldend": ret.append(" %spHandler->endField();" % (extra_space)) - elif actionNode.getAttribute("action") == "fieldlock": + elif act == "fieldlock": ret.append(" %s{" % (extra_space)) ret.append(" %sOOXMLPropertySetEntryToBool aHandler(NS_ooxml::LN_CT_FldChar_fldLock);" % (extra_space)) ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler))" % (extra_space)) @@ -452,7 +453,7 @@ def factoryChooseAction(actionNode): ret.append(" %sif (aHandler.getValue())" % (extra_space)) ret.append(" %spHandler->lockField();" % (extra_space)) ret.append(" %s}" % (extra_space)) - elif actionNode.getAttribute("action") == "fieldlock_simple": + elif act == "fieldlock_simple": ret.append(" %s{" % (extra_space)) ret.append(" %sOOXMLPropertySetEntryToBool aHandler(NS_ooxml::LN_CT_SimpleField_fldLock);" % (extra_space)) ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler))" % (extra_space)) @@ -460,23 +461,23 @@ def factoryChooseAction(actionNode): ret.append(" %sif (aHandler.getValue())" % (extra_space)) ret.append(" %spHandler->lockField();" % (extra_space)) ret.append(" %s}" % (extra_space)) - elif actionNode.getAttribute("action") == "printproperty": + elif act == "printproperty": ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler))" % extra_space) ret.append(" %s pStream->sendProperty(%s);" % (extra_space, idToLabel(actionNode.getAttribute("sendtokenid")))) - elif actionNode.getAttribute("action") == "sendPropertiesWithId": + elif act == "sendPropertiesWithId": ret.append(" %spHandler->sendPropertiesWithId(%s);" % (extra_space, idToLabel(actionNode.getAttribute("sendtokenid")))) - elif actionNode.getAttribute("action") == "text": + elif act == "text": ret.append(" %spHandler->text(sText);" % (extra_space)) - elif actionNode.getAttribute("action") == "positionOffset": + elif act == "positionOffset": ret.append(" %spHandler->positionOffset(sText);" % (extra_space)) - elif actionNode.getAttribute("action") == "positivePercentage": + elif act == "positivePercentage": ret.append(" %spHandler->positivePercentage(sText);" % (extra_space)) - elif actionNode.getAttribute("action") == "alignH": + elif act == "alignH": ret.append(" %spHandler->alignH(sText);" % (extra_space)) - elif actionNode.getAttribute("action") == "alignV": + elif act == "alignV": ret.append(" %spHandler->alignV(sText);" % (extra_space)) - elif actionNode.getAttribute("action") == "tokenproperty": - ret.append(" %sOOXMLFastHelper<OOXMLIntegerValue>::newProperty(pHandler, %s, pHandler->getToken());" % (extra_space, idToLabel("ooxml:token"))) + elif act == "tokenproperty": + ret.append(" %snewIntegerProperty(pHandler, %s, pHandler->getToken());" % (extra_space, idToLabel("ooxml:token"))) else: ret.append(" %spHandler->%s();" % (extra_space, actionNode.getAttribute("action"))) @@ -675,7 +676,7 @@ def factoryAttributeAction(nsNode): nsLabel = nsToLabel(nsNode) inner = factoryAttributeActionInner(nsNode) if len(inner): - print("""void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler* _pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue) + print("""void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler* _pHandler, Token_t nToken, const OOXMLValue& pValue) { switch (_pHandler->getDefine()) {""" % nsLabel) @@ -686,7 +687,7 @@ def factoryAttributeAction(nsNode): print("}") print() else: - print("void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler*, Token_t, const OOXMLValue::Pointer_t&)" % nsLabel) + print("void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler*, Token_t, const OOXMLValue&)" % nsLabel) print("{") print("}") print() diff --git a/sw/source/writerfilter/rtftok/rtfvalue.hxx b/sw/source/writerfilter/rtftok/rtfvalue.hxx index 0e232d949088..e708b4d1d9bb 100644 --- a/sw/source/writerfilter/rtftok/rtfvalue.hxx +++ b/sw/source/writerfilter/rtftok/rtfvalue.hxx @@ -33,7 +33,7 @@ class RTFSprms; class RTFShape; class RTFPicture; /// Value of an RTF keyword -class RTFValue : public Value +class RTFValue : public Value, public virtual SvRefBase { RTFValue(int nValue, OUString sValue, const RTFSprms* pAttributes, const RTFSprms* pSprms, css::uno::Reference<css::drawing::XShape> xShape,