diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp index 5cc36ef55b..5b5dbef9ac 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp @@ -1130,8 +1130,17 @@ namespace StarMath { if(pMr->m_arrItems[i]->getType() == OOX::EElementType::et_m_e) { + OOX::Logic::CElement* pElement = dynamic_cast(pMr->m_arrItems[i]); m_pXmlWrite->WriteNodeBegin(L"mtd",false); - ConversionElement(dynamic_cast(pMr->m_arrItems[i])); + if(!pElement->m_arrItems.empty()) + ConversionElement(pElement); + else + { + m_pXmlWrite->WriteNodeBegin(L"mspace",true); + m_pXmlWrite->WriteAttribute(L"width",L"2em"); + m_pXmlWrite->WriteNodeEnd(L"w",true,true); + m_wsAnnotationStarMath += L"~ "; + } if(i+1 < pMr->m_arrItems.size()) m_wsAnnotationStarMath += L"# "; m_pXmlWrite->WriteNodeEnd(L"mtd",false,false); @@ -1707,10 +1716,13 @@ namespace StarMath { return m_enType; } - void COneElement::SetAttribute(StValuePr *stAttribute) + void COneElement::SetBaseAttribute(StValuePr *stAttribute) { if(m_stAttribute == nullptr) + { m_stAttribute = stAttribute; + stAttribute->AddRef(); + } } StValuePr* COneElement::GetAttribute() { @@ -1900,6 +1912,10 @@ namespace StarMath } void CNumberOrLetter::Parse(std::wstring::iterator &itStart, std::wstring::iterator &itEnd, COneElement *&pElement) {} + void CNumberOrLetter::SetAttribute(StValuePr *pAttribute) + { + SetBaseAttribute(pAttribute); + } const std::wstring& CNumberOrLetter::GetString() { return m_wsElement; @@ -1933,21 +1949,18 @@ namespace StarMath { COneElement::ConversionAttribute(GetAttribute(),stStyle,pXmlWrite,wsAnnotation); pXmlWrite->WriteNodeBegin(L"mtext",false); - pXmlWrite->WriteString(m_wsAnnotation); + pXmlWrite->WriteString(m_wsSymbolBinOp); pXmlWrite->WriteNodeEnd(L"mtext",false,false); - wsAnnotation += L"\u0026quot;" + m_wsAnnotation + L"\u0026quot;"; + wsAnnotation += L"\u0026quot;" + m_wsSymbolBinOp + L"\u0026quot;"; COOXml2Odf::StyleClosing(stStyle,pXmlWrite); return; } } pXmlWrite->WriteNodeBegin(L"mrow",false); - if(GetAttribute() != nullptr && m_enTypeBinOp != TypeElement::undefine) + if(m_pLeftArg != nullptr) + m_pLeftArg->Conversion(pXmlWrite,wsAnnotation); + else if(GetAttribute() != nullptr && m_enTypeBinOp != TypeElement::undefine) COneElement::ConversionAttribute(GetAttribute(),stStyle,pXmlWrite,wsAnnotation); - else - { - if(m_pLeftArg != nullptr) - m_pLeftArg->Conversion(pXmlWrite,wsAnnotation); - } COOXml2Odf::RecordingMoNode(m_wsSymbolBinOp,pXmlWrite); wsAnnotation += m_wsAnnotation + L" "; if(m_pRightArg != nullptr) @@ -1955,6 +1968,14 @@ namespace StarMath COOXml2Odf::StyleClosing(stStyle,pXmlWrite); pXmlWrite->WriteNodeEnd(L"mrow",false,false); } + void CBinOperator::SetAttribute(StValuePr *pAttribute) + { + SetBaseAttribute(pAttribute); + if(m_pLeftArg != nullptr) + m_pLeftArg->SetAttribute(pAttribute); + if(m_pRightArg != nullptr) + m_pRightArg->SetAttribute(pAttribute); + } void CBinOperator::SetLeftArg(COneElement *pElement) { m_pLeftArg = pElement; @@ -2134,7 +2155,7 @@ namespace StarMath if(GetAttribute() != nullptr) { GetAttribute()->AddRef(); - m_pLeftArg->SetAttribute(GetAttribute()); + m_pLeftArg->SetBaseAttribute(GetAttribute()); } m_pLeftArg->Conversion(pXmlWrite,wsAnnotation); } @@ -2148,13 +2169,21 @@ namespace StarMath if(GetAttribute() != nullptr) { GetAttribute()->AddRef(); - m_pRightArg->SetAttribute(GetAttribute()); + m_pRightArg->SetBaseAttribute(GetAttribute()); } m_pRightArg->Conversion(pXmlWrite,wsAnnotation); } pXmlWrite->WriteNodeEnd(L"mrow",false,false); } } + void CRelationsAndOperationsOnSets::SetAttribute(StValuePr *pAttribute) + { + SetBaseAttribute(pAttribute); + if(m_pLeftArg != nullptr) + m_pLeftArg->SetAttribute(pAttribute); + if(m_pRightArg != nullptr) + m_pRightArg->SetAttribute(pAttribute); + } void CRelationsAndOperationsOnSets::SetLeftArg(COneElement *pElement) { m_pLeftArg = pElement; @@ -2285,6 +2314,8 @@ namespace StarMath pXmlWrite->WriteNodeEnd(L"w",true,true); wsAnnotation += L"` "; } + void CSpace::SetAttribute(StValuePr *pAttribute) + {} //class CSpecialChar CSpecialChar::~CSpecialChar() {} @@ -2308,6 +2339,10 @@ namespace StarMath COOXml2Odf::MTextRecording(pXmlWrite,wsAnnotation,m_wsSymbol); COOXml2Odf::StyleClosing(stStyle,pXmlWrite); } + void CSpecialChar::SetAttribute(StValuePr *pAttribute) + { + SetBaseAttribute(pAttribute); + } std::wstring CSpecialChar::DefinitionSpecialChar(const std::wstring &wsSymbol) { if(L"\u2205" == wsSymbol) return L"emptyset"; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h index d9212f66d1..fbefb302ca 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h @@ -19,9 +19,7 @@ namespace StarMath struct StValuePr { StValuePr():m_wsTypeName(L""),m_wsChr(L""),m_wsBegBracket(L""),m_wsEndBracket(L""),m_wsColor(L""),m_bSupHide(false),m_bSubHide(false),m_enStyle(SimpleTypes::EStyle::stylePlain),m_iSize(0),m_enPos(SimpleTypes::ETopBot::tbBot),m_enVert(SimpleTypes::ETopBot::tbBot),m_enFont(StarMath::TypeFont::empty),m_iCount(0),m_bStrike(false),m_enUnderLine(SimpleTypes::EUnderline::underlineNone),m_bBaseAttribute(false) - { - AddRef(); - } + {} std::wstring m_wsTypeName,m_wsChr; std::wstring m_wsBegBracket,m_wsEndBracket; std::wstring m_wsColor; @@ -148,10 +146,11 @@ namespace StarMath virtual ~COneElement(); virtual void Parse(std::wstring::iterator& itStart,std::wstring::iterator& itEnd,COneElement*& pElement) = 0; virtual void Conversion(XmlUtils::CXmlWriter* pXmlWrite,std::wstring& wsAnnotation) = 0; + virtual void SetAttribute(StValuePr* pAttribute) = 0; static COneElement* CreateElement(std::wstring& wsOneElement); void SetType(const TypeElement& enType); TypeElement GetType(); - void SetAttribute(StValuePr* stAttribute); + void SetBaseAttribute(StValuePr* stAttribute); StValuePr* GetAttribute(); static void ConversionAttribute(StValuePr* pAttribute, StStyleMenClose & stStyle , XmlUtils::CXmlWriter* pXmlWrite, std::wstring& wsAnnotation, const bool &bDelimiter = false); bool CheckStyle(); @@ -172,6 +171,7 @@ namespace StarMath virtual ~CNumberOrLetter(); void Conversion(XmlUtils::CXmlWriter* pXmlWrite,std::wstring& wsAnnotation) override; void Parse(std::wstring::iterator &itStart, std::wstring::iterator &itEnd,COneElement*& pElement) override; + void SetAttribute(StValuePr* pAttribute) override; const std::wstring& GetString(); void AddingStrings(const std::wstring& wsString); private: @@ -198,6 +198,7 @@ namespace StarMath virtual ~CBinOperator(); void Parse(std::wstring::iterator &itStart, std::wstring::iterator &itEnd, COneElement *&pElement) override; void Conversion(XmlUtils::CXmlWriter* pXmlWrite,std::wstring& wsAnnotation) override; + void SetAttribute(StValuePr* pAttribute) override; bool CheckLeftArg(); void SetLeftArg(COneElement* pElement); bool CheckRightArg(); @@ -225,6 +226,7 @@ namespace StarMath virtual ~CRelationsAndOperationsOnSets(); void Parse(std::wstring::iterator &itStart, std::wstring::iterator &itEnd,COneElement*& pElement) override; void Conversion(XmlUtils::CXmlWriter* pXmlWrite,std::wstring& wsAnnotation) override; + void SetAttribute(StValuePr* pAttribute) override; void SetLeftArg(COneElement* pElement); void SetRightArg(COneElement* pElement); bool CheckRightArg(); @@ -246,6 +248,7 @@ namespace StarMath virtual ~CSpace(); void Parse(std::wstring::iterator&itStart,std::wstring::iterator&itEnd,COneElement*& pElement) override; void Conversion(XmlUtils::CXmlWriter* pXmlWrite,std::wstring& wsAnnotation) override; + void SetAttribute(StValuePr* pAttribute) override; }; class CSpecialChar: public COneElement { @@ -259,6 +262,7 @@ namespace StarMath virtual ~CSpecialChar(); void Parse(std::wstring::iterator&itStart,std::wstring::iterator&itEnd,COneElement*& pElement) override; void Conversion(XmlUtils::CXmlWriter* pXmlWrite,std::wstring& wsAnnotation) override; + void SetAttribute(StValuePr* pAttribute) override; static std::wstring DefinitionSpecialChar(const std::wstring& wsSymbol); private: std::wstring m_wsSymbol,m_wsAnnotation; diff --git a/X2tConverter/test/TestOOOXml2Odf/test.cpp b/X2tConverter/test/TestOOOXml2Odf/test.cpp index 7227ec5a8d..1ea3ecdcaa 100644 --- a/X2tConverter/test/TestOOOXml2Odf/test.cpp +++ b/X2tConverter/test/TestOOOXml2Odf/test.cpp @@ -527,7 +527,7 @@ TEST(OOXml2OdfTest,TextMrPr) pElement->fromXML(oReader); StarMath::COOXml2Odf oTest; oTest.StartConversion(pElement); - std::wstring wsOdf = L"1+3bold ital 1 bold ital + 3 "; + std::wstring wsOdf = L"1+3bold ital 1 bold ital + bold ital 3 "; EXPECT_EQ(oTest.GetOdf(),wsOdf); } TEST(OOXml2OdfTest,ColorByName) @@ -593,7 +593,7 @@ TEST(OOXml2OdfTest,EmptyMatrix) pElement->fromXML(oReader); StarMath::COOXml2Odf oTest; oTest.StartConversion(pElement); - std::wstring wsOdf = L"bold ital matrix{# # ## # # ## # # } "; + std::wstring wsOdf = L"bold ital matrix{~ # ~ # ~ ## ~ # ~ # ~ ## ~ # ~ # ~ } "; EXPECT_EQ(oTest.GetOdf(),wsOdf); } TEST(OOXml2OdfTest,EmptyNary)