From 8e2d1e2c167d5e7ae2c58d409034863e7dd3da60 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Thu, 17 Apr 2025 22:19:08 +0300 Subject: [PATCH 001/125] parse development --- .../StarMath2OOXML/StarMath2OOXML.pri | 4 +- .../StarMath2OOXML/TestSMConverter/main.cpp | 2 +- .../StarMath2OOXML/cstarmathpars.cpp | 331 ++++++++++++++---- .../Converter/StarMath2OOXML/cstarmathpars.h | 36 +- .../Converter/StarMath2OOXML/typeselements.h | 13 + 5 files changed, 309 insertions(+), 77 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri index bcf64bfd17..9cbd390c47 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri @@ -9,12 +9,12 @@ ADD_DEPENDENCY(UnicodeConverter, kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ - $$PWD/cooxml2odf.cpp \ +# $$PWD/cooxml2odf.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ $$PWD/cconversionsmtoooxml.h \ - $$PWD/cooxml2odf.h \ +# $$PWD/cooxml2odf.h \ $$PWD/cstarmathpars.h \ $$PWD/fontType.h \ $$PWD/typeConversion.h \ diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp index cec1fcfaf8..4e37211d1e 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp @@ -1360,7 +1360,7 @@ TEST(SMConvectorTest,MatrixWithDifferentValues) StarMath::CParserStarMathString oTemp; StarMath::CConversionSMtoOOXML oTest; oTest.StartConversion(oTemp.Parse(wsString)); - std::wstring wsXmlString = L"22"; + std::wstring wsXmlString = L"22"; EXPECT_EQ(oTest.GetOOXML(),wsXmlString); } diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 12e623341a..ed5361cf3b 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -83,7 +83,23 @@ namespace StarMath m_qSize.push(tSize); return m_arEquation; } - + std::vector CParserStarMathString::ParseEQN(std::wstring &wsParseString) + { + std::wstring::iterator itStart = wsParseString.begin(),itEnd = wsParseString.end(); + CStarMathReader* pReader = new CStarMathReader(itStart,itEnd,TypeConversion::docx); + while(pReader->CheckIteratorPosition()) + { + CElement* pTempElement = ParseElementEQN(pReader); + AddingAnElementToAnArray(m_arEquation,pTempElement,pReader); + } + if(!pReader->EmptyString()) + { + CElement* pTempElement = ParseElement(pReader); + if(nullptr != pTempElement) + m_arEquation.push_back(pTempElement); + } + return m_arEquation; + } CElement* CParserStarMathString::ParseElement(CStarMathReader* pReader) { CElement* pElement; @@ -110,6 +126,22 @@ namespace StarMath return pElement; } } + CElement* CParserStarMathString::ParseElementEQN(CStarMathReader *pReader) + { + CElement* pElement = nullptr; + pReader->ReadingTheNextToken(true); + pElement = CElement::CreateElement(pReader); + if(pElement != nullptr) + { + pReader->ClearReader(); + pElement->ParseEQN(pReader); + } + else + { + pReader->ClearReader(); + return pElement; + } + } template bool SetLeft(CElement *pLeftArg, CElement *pElementWhichAdd) { @@ -757,7 +789,7 @@ namespace StarMath CElement::CElement(const TypeElement &enTypeBase,const TypeConversion &enTypeConversion): m_pAttribute(nullptr),m_enBaseType(enTypeBase),m_enTypeConversion(enTypeConversion) { } - CElement* CElement::CreateElement(CStarMathReader* pReader) + CElement* CElement::CreateElement(CStarMathReader* pReader, const bool bEQN) { switch (pReader->GetGlobalType()) { case TypeElement::String: @@ -783,7 +815,7 @@ namespace StarMath case TypeElement::Bracket: { if(pReader->GetLocalType() == TypeElement::left) - return new CElementBracket(pReader->GetLocalType(),pReader->GetTypeConversion(),true); + return new CElementBracket(pReader->GetLocalType(),pReader->GetTypeConversion(),true,bEQN); else return new CElementBracket(pReader->GetLocalType(),pReader->GetTypeConversion()); } @@ -887,6 +919,8 @@ namespace StarMath } pReader->ClearReader(); } + void CElementString::ParseEQN(CStarMathReader *pReader) + {} void CElementString::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) { if(m_wsString !=L"" && m_wsString!=L" ") @@ -894,7 +928,8 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:r",false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); pXmlWrite->WriteNodeBegin(L"m:t",false); - pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); +// pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); + pXmlWrite->WriteString(m_wsString); pXmlWrite->WriteNodeEnd(L"m:t",false,false); pXmlWrite->WriteNodeEnd(L"m:r",false,false); } @@ -985,6 +1020,11 @@ namespace StarMath m_pRightArgument = pTempElement; } } + void CElementBinOperator::ParseEQN(CStarMathReader *pReader) + { + CElement* pTempElement = CParserStarMathString::ParseElementEQN(pReader); + m_pRightArgument = pTempElement; + } void CElementBinOperator::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) { if(m_enTypeBinOp == TypeElement::over || m_enTypeBinOp ==TypeElement::division || TypeElement::frac == m_enTypeBinOp || TypeElement::wideslash == m_enTypeBinOp) @@ -1201,8 +1241,8 @@ namespace StarMath } } //class methods CElementBracket - CElementBracket::CElementBracket(const TypeElement& enType,const TypeConversion &enTypeConversion,const bool& bScalability) - :CElement(TypeElement::Bracket,enTypeConversion),m_enTypeBracket(enType),m_bScalability(bScalability) + CElementBracket::CElementBracket(const TypeElement& enType,const TypeConversion &enTypeConversion,const bool& bScalability,const bool& bEQN) + :CElement(TypeElement::Bracket,enTypeConversion),m_enTypeBracket(enType),m_bScalability(bScalability),m_bEQN(bEQN) { } CElementBracket::~CElementBracket() @@ -1213,36 +1253,56 @@ namespace StarMath { m_arBrecketValue = arValue; } - TypeElement CElementBracket::GetBracketOpen(const std::wstring &wsToken) + TypeElement CElementBracket::GetBracketOpen(const std::wstring &wsToken, const bool bEQN) { - if(L"{" == wsToken) return TypeElement::brace; + if(L"left" == wsToken) return TypeElement::left; else if(L"(" == wsToken) return TypeElement::round; else if(L"[" == wsToken) return TypeElement::square; - else if(L"left" == wsToken) return TypeElement::left; - else if(L"ldbracket" == wsToken) return TypeElement::ldbracket; - else if(L"lbrace" == wsToken) return TypeElement::lbrace; - else if(L"langle" == wsToken) return TypeElement::langle; - else if(L"lceil" == wsToken) return TypeElement::lceil; - else if(L"lfloor" == wsToken) return TypeElement::lfloor; - else if(L"lline" == wsToken) return TypeElement::lline; - else if(L"ldline" == wsToken) return TypeElement::ldline; - else return TypeElement::undefine; + else if(bEQN) + { + if(L"{" == wsToken) return TypeElement::lbrace; + else if(L"\u003C" == wsToken) return TypeElement::langle; + else if(L"\u007C" == wsToken) return TypeElement::lline; + else if(L"\u2225" == wsToken) return TypeElement::ldline; + } + else + { + if(L"{" == wsToken) return TypeElement::brace; + else if(L"ldbracket" == wsToken) return TypeElement::ldbracket; + else if(L"lbrace" == wsToken) return TypeElement::lbrace; + else if(L"langle" == wsToken) return TypeElement::langle; + else if(L"lceil" == wsToken) return TypeElement::lceil; + else if(L"lfloor" == wsToken) return TypeElement::lfloor; + else if(L"lline" == wsToken) return TypeElement::lline; + else if(L"ldline" == wsToken) return TypeElement::ldline; + } + return TypeElement::undefine; } - TypeElement CElementBracket::GetBracketClose(const std::wstring &wsToken) + TypeElement CElementBracket::GetBracketClose(const std::wstring &wsToken, const bool bEQN) { - if(L"}" == wsToken) return TypeElement::rwbrace; + if(L"right" == wsToken) return TypeElement::right; else if(L")" == wsToken) return TypeElement::rround; else if(L"]" == wsToken) return TypeElement::rsquare; - else if(L"rdbracket" == wsToken) return TypeElement::rdbracket; - else if(L"rbrace" == wsToken) return TypeElement::rbrace; - else if(L"rangle" == wsToken) return TypeElement::rangle; - else if(L"rceil" == wsToken) return TypeElement::rceil; - else if(L"rfloor" == wsToken) return TypeElement::rfloor; - else if(L"rline" == wsToken) return TypeElement::rline; - else if(L"rdline" == wsToken) return TypeElement::rdline; - else if(L"right" == wsToken) return TypeElement::right; - else if(L"none" == wsToken) return TypeElement::none; - else return TypeElement::undefine; + else if(bEQN) + { + if(L"}" == wsToken) return TypeElement::rbrace; + else if(L"\u003E" == wsToken) return TypeElement::rangle; + else if(L"\u007C" == wsToken) return TypeElement::rline; + else if(L"\u2225" == wsToken) return TypeElement::rdline; + } + else + { + if(L"}" == wsToken) return TypeElement::rwbrace; + else if(L"rdbracket" == wsToken) return TypeElement::rdbracket; + else if(L"rbrace" == wsToken) return TypeElement::rbrace; + else if(L"rangle" == wsToken) return TypeElement::rangle; + else if(L"rceil" == wsToken) return TypeElement::rceil; + else if(L"rfloor" == wsToken) return TypeElement::rfloor; + else if(L"rline" == wsToken) return TypeElement::rline; + else if(L"rdline" == wsToken) return TypeElement::rdline; + else if(L"none" == wsToken) return TypeElement::none; + } + return TypeElement::undefine; } std::vector CElementBracket::GetBracketValue() { @@ -1253,12 +1313,12 @@ namespace StarMath TypeElement enOpen,enClose; if(m_enTypeBracket == TypeElement::left) { - pReader->ReadingTheNextToken(); - enOpen = GetBracketOpen(pReader->GetLowerCaseString()); - if(pReader->GetLowerCaseString() == L"none") + pReader->ReadingTheNextToken(m_bEQN); + enOpen = GetBracketOpen(pReader->GetLowerCaseString(),m_bEQN); + if(pReader->GetLowerCaseString() == L"none" && !m_bEQN) enOpen = TypeElement::none; else - enClose = GetBracketClose(pReader->GetLowerCaseString()); + enClose = GetBracketClose(pReader->GetLowerCaseString(),m_bEQN); if(enOpen != TypeElement::undefine) { m_enLeftBracket = enOpen; @@ -1270,10 +1330,10 @@ namespace StarMath pReader->ClearReader(); } } - pReader->FindingTheEndOfParentheses(); + pReader->FindingTheEndOfParentheses(m_bEQN); while(pReader->CheckIteratorPosition()) { - pReader->ReadingTheNextToken(); + pReader->ReadingTheNextToken(m_bEQN); if(pReader->GetLowerCaseString() == L"right") { pReader->ClearReader(); @@ -1283,7 +1343,7 @@ namespace StarMath } if(!pReader->EmptyString() && pReader->GetLowerCaseString() != L"right") { - if(pReader->GetLocalType() == TypeElement::newline) + if(pReader->GetLocalType() == TypeElement::newline && !m_bEQN) { m_arBrecketValue.push_back(new CElementSpecialSymbol(pReader->GetLocalType(),pReader->GetTypeConversion())); pReader->ClearReader(); @@ -1297,9 +1357,9 @@ namespace StarMath } pReader->SettingTheIteratorToTheClosingBracket(); pReader->ClearReader(); - pReader->ReadingTheNextToken(); - enOpen = GetBracketOpen(pReader->GetLowerCaseString()); - enClose = GetBracketClose(pReader->GetLowerCaseString()); + pReader->ReadingTheNextToken(m_bEQN); + enOpen = GetBracketOpen(pReader->GetLowerCaseString(),m_bEQN); + enClose = GetBracketClose(pReader->GetLowerCaseString(),m_bEQN); if(enOpen != TypeElement::undefine) { m_enRightBracket = enOpen; @@ -1312,6 +1372,11 @@ namespace StarMath } pReader->IteratorNullification(); } + void CElementBracket::ParseEQN(CStarMathReader *pReader) + { + m_bEQN = true; + Parse(pReader); + } void CElementBracket::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { std::wstring wsOpenBracket,wsCloseBracket; @@ -1533,6 +1598,8 @@ namespace StarMath break; } } + void CElementSpecialSymbol::ParseEQN(CStarMathReader *pReader) + {} void CElementSpecialSymbol::SetValue(CElement* pValue) { m_pValue = pValue; @@ -1709,7 +1776,8 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:r",false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); pXmlWrite->WriteNodeBegin(L"m:t",false); - pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsType)); +// pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsType)); + pXmlWrite->WriteString(m_wsType); pXmlWrite->WriteNodeEnd(L"m:t",false,false); pXmlWrite->WriteNodeEnd(L"m:r",false,false); } @@ -2078,6 +2146,8 @@ namespace StarMath } SetRightArg(pTempElement); } + void CElementSetOperations::ParseEQN(CStarMathReader *pReader) + {} void CElementSetOperations::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { CConversionSMtoOOXML::ElementConversion(pXmlWrite,m_pLeftArgument); @@ -2216,6 +2286,8 @@ namespace StarMath } SetRightArg(pTempElement); } + void CElementConnection::ParseEQN(CStarMathReader *pReader) + {} void CElementConnection::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { CConversionSMtoOOXML::ElementConversion(pXmlWrite,m_pLeftArgument); @@ -2527,6 +2599,8 @@ namespace StarMath }while(GetUpperIndex(pReader->GetLocalType()) || GetLowerIndex(pReader->GetLocalType())); } } + void CElementIndex::ParseEQN(CStarMathReader *pReader) + {} void CElementIndex::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { if(TypeElement::sqrt == m_enTypeIndex || TypeElement::nroot == m_enTypeIndex) @@ -2821,8 +2895,10 @@ namespace StarMath { CParserStarMathString::ReadingElementsWithPriorities(pReader,pTempElement); } - SetValueFunction(pTempElement); + m_pValue = pTempElement; } + void CElementFunction::ParseEQN(CStarMathReader* pReader) + {} void CElementFunction::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { if(m_pIndex !=nullptr) @@ -2949,21 +3025,43 @@ namespace StarMath else if(L"to" == wsToken) return TypeElement::to; else return TypeElement::undefine; } - TypeElement CElementOperator::GetOperator(const std::wstring &wsToken) + TypeElement CElementOperator::GetOperator(const std::wstring &wsToken, const bool bEQN) { - if(L"lim" == wsToken) return TypeElement::lim; - else if(L"sum" == wsToken) return TypeElement::sum; - else if(L"liminf" == wsToken) return TypeElement::liminf; - else if(L"limsup" == wsToken) return TypeElement::limsup; + if(L"sum" == wsToken) return TypeElement::sum; else if(L"prod" == wsToken) return TypeElement::prod; else if(L"coprod" == wsToken) return TypeElement::coprod; - else if(L"int" == wsToken) return TypeElement::Int; - else if(L"iint" == wsToken) return TypeElement::iint; - else if(L"iiint" == wsToken) return TypeElement::iiint; - else if(L"lint" == wsToken) return TypeElement::lint; - else if(L"llint" == wsToken) return TypeElement::llint; - else if(L"lllint" == wsToken) return TypeElement::lllint; - else if(L"oper" == wsToken) return TypeElement::oper; + if(!bEQN) + { + if(L"lim" == wsToken) return TypeElement::lim; + else if(L"liminf" == wsToken) return TypeElement::liminf; + else if(L"limsup" == wsToken) return TypeElement::limsup; + else if(L"int" == wsToken) return TypeElement::Int; + else if(L"iint" == wsToken) return TypeElement::iint; + else if(L"iiint" == wsToken) return TypeElement::iiint; + else if(L"lint" == wsToken) return TypeElement::lint; + else if(L"llint" == wsToken) return TypeElement::llint; + else if(L"lllint" == wsToken) return TypeElement::lllint; + else if(L"oper" == wsToken) return TypeElement::oper; + } + return TypeElement::undefine; + } + TypeElement CElementOperator::GetOperatorEQN(const std::wstring &wsToken) + { + TypeElement enType = CElementOperator::GetOperator(wsToken,true); + if(enType != TypeElement::undefine) + return enType; + if(L"bigsqcap" == wsToken) return TypeElement::bigsqcap; + else if(L"bigsqcup" == wsToken) return TypeElement::bigsqcup; + else if(L"inter" == wsToken) return TypeElement::inter; + else if(L"union" == wsToken) return TypeElement::Union; + else if(L"bigoplus" == wsToken) return TypeElement::bigoplus; + else if(L"bigominus" == wsToken) return TypeElement::bigominus; + else if(L"bigotimes" == wsToken) return TypeElement::bigotimes; + else if(L"bigodiv" == wsToken) return TypeElement::bigodiv; + else if(L"bigodot" == wsToken) return TypeElement::bigodot; + else if(L"bigvee" == wsToken) return TypeElement::bigvee; + else if(L"bigwedge" == wsToken) return TypeElement::bigwedge; + else if(L"biguplus" == wsToken) return TypeElement::biguplus; else return TypeElement::undefine; } void CElementOperator::Parse(CStarMathReader* pReader) @@ -3000,6 +3098,25 @@ namespace StarMath CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pValueOperator); } } + void CElementOperator::ParseEQN(CStarMathReader *pReader) + { + pReader->ReadingTheNextToken(true); + while(pReader->GetLocalType() == TypeElement::upper || pReader->GetLocalType() == TypeElement::lower) + { + if(pReader->GetLocalType() == TypeElement::upper) + { + pReader->ClearReader(); + m_pUpperIndex = CParserStarMathString::ParseElementEQN(pReader); + } + else if(pReader->GetLocalType() == TypeElement::lower) + { + pReader->ClearReader(); + m_pLowerIndex = CParserStarMathString::ParseElementEQN(pReader); + } + pReader->ReadingTheNextToken(true); + } + m_pValueOperator = CParserStarMathString::ReadingWithoutBracket(pReader); + } void CElementOperator::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) { if(m_enTypeOperator == TypeElement::lim || TypeElement::liminf == m_enTypeOperator || TypeElement::limsup == m_enTypeOperator || TypeElement::oper == m_enTypeOperator) @@ -3246,6 +3363,38 @@ namespace StarMath return; } } + void CStarMathReader::SetTypesTokenEQN() + { + if(m_wsLowerCaseToken == L"over") + { + m_enUnderType = TypeElement::over; + m_enGlobalType = TypeElement::BinOperator; + return; + } + else if(m_wsLowerCaseToken == L"left") + { + m_enUnderType = TypeElement::left; + m_enGlobalType = TypeElement::Bracket; + return; + } + m_enUnderType = CElementBracketWithIndex::GetBracketWithIndex(m_wsLowerCaseToken); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::BracketWithIndex; + return; + } + m_enUnderType = CElementOperator::GetOperatorEQN(m_wsLowerCaseToken); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::Operation; + return; + } + if(m_enUnderType == TypeElement::undefine && !m_wsLowerCaseToken.empty()) + { + m_enGlobalType = TypeElement::String; + return; + } + } void CStarMathReader::TokenProcessing(const std::wstring &wsToken) { if(wsToken.empty()) @@ -3394,7 +3543,7 @@ namespace StarMath { m_wsLowerCaseToken = wsToken; } - void CStarMathReader::FindingTheEndOfParentheses() + void CStarMathReader::FindingTheEndOfParentheses(const bool bEQN) { std::wstring::iterator itStart = m_itStart,itStartBracketClose; int inBracketInside = 0; @@ -3406,9 +3555,9 @@ namespace StarMath { break; } - if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken) != TypeElement::undefine) + if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) != TypeElement::undefine) { - if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken) == TypeElement::left) + if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) == TypeElement::left) { if(GetToken() && (m_wsLowerCaseToken == L"none" || (m_wsLowerCaseToken != L"left" && CElementBracket::GetBracketOpen(m_wsLowerCaseToken) != TypeElement::undefine))) { @@ -3419,16 +3568,32 @@ namespace StarMath else inBracketInside +=1; } - else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken) == TypeElement::right) + else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) == TypeElement::right && bEQN) + { + if(!GetToken()) + continue; + if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside == 0) + { + m_stBracket.push(m_itEnd); + m_stCloseBracket.push(m_itStart); + m_itEnd = itStartBracketClose; + break; + } + else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside != 0) + { + inBracketInside -=1; + } + } + else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) == TypeElement::right) continue; - else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken) != TypeElement::undefine && inBracketInside == 0) + else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside == 0) { m_stBracket.push(m_itEnd); m_stCloseBracket.push(m_itStart); m_itEnd = itStartBracketClose; break; } - else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken) != TypeElement::undefine && inBracketInside != 0) + else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside != 0) { inBracketInside -=1; } @@ -3454,12 +3619,15 @@ namespace StarMath } ClearReader(); } - void CStarMathReader::ReadingTheNextToken() + void CStarMathReader::ReadingTheNextToken(bool bEQN) { if(m_wsLowerCaseToken.empty()) { if (GetToken()) - SetTypesToken(); + if(bEQN) + SetTypesTokenEQN(); + else + SetTypesToken(); else { ClearReader(); @@ -3519,8 +3687,8 @@ namespace StarMath return m_enTypeCon; } //class methods CElementBracketWithIndex - CElementBracketWithIndex::CElementBracketWithIndex(const TypeElement &enType,const TypeConversion &enTypeConversion) - :CElement(TypeElement::BracketWithIndex,enTypeConversion),m_pLeftArg(nullptr), m_pValue(nullptr),m_enTypeBracketWithIndex(enType) + CElementBracketWithIndex::CElementBracketWithIndex(const TypeElement &enType,const TypeConversion &enTypeConversion,const bool& bEQN) + :CElement(TypeElement::BracketWithIndex,enTypeConversion),m_pLeftArg(nullptr), m_pValue(nullptr),m_enTypeBracketWithIndex(enType),m_bEQN(bEQN) { } CElementBracketWithIndex::~CElementBracketWithIndex() @@ -3542,13 +3710,38 @@ namespace StarMath } void CElementBracketWithIndex::Parse(CStarMathReader *pReader) { - m_pValue = CParserStarMathString::ParseElement(pReader); - pReader->ReadingTheNextToken(); + if(m_bEQN && m_enTypeBracketWithIndex == TypeElement::underbrace) + m_pLeftArg = CParserStarMathString::ParseElementEQN(pReader); + else if(m_bEQN && m_enTypeBracketWithIndex == TypeElement::overbrace) + m_pValue = CParserStarMathString::ParseElementEQN(pReader); + else + m_pValue = CParserStarMathString::ParseElement(pReader); + pReader->ReadingTheNextToken(m_bEQN); while(pReader->GetGlobalType() == TypeElement::Index) { - CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pValue); + if( m_bEQN && m_enTypeBracketWithIndex == TypeElement::underbrace) + CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pLeftArg); + else + CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pValue); } } + void CElementBracketWithIndex::ParseEQN(CStarMathReader *pReader) + { + if(m_enTypeBracketWithIndex == TypeElement::overbrace) + m_pLeftArg = CParserStarMathString::ParseElementEQN(pReader); + else if(m_enTypeBracketWithIndex == TypeElement::underbrace) + m_pValue = CParserStarMathString::ParseElementEQN(pReader); + pReader->ReadingTheNextToken(m_bEQN); + while(pReader->GetGlobalType() == TypeElement::Index) + { + if(m_enTypeBracketWithIndex == TypeElement::overbrace) + CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pLeftArg); + else if(m_enTypeBracketWithIndex == TypeElement::underbrace) + CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pValue); + } + m_bEQN = true; + Parse(pReader); + } void CElementBracketWithIndex::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { std::wstring wsNameNode; @@ -3658,6 +3851,8 @@ namespace StarMath if(GetAttribute() != nullptr) SetAttribute(GetAttribute()); } + void CElementGrade::ParseEQN(CStarMathReader *pReader) + {} void CElementGrade::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { if(m_pValueFrom == nullptr && m_pValueTo == nullptr) @@ -3767,6 +3962,8 @@ namespace StarMath SetAttribute(GetAttribute()); DimensionCalculation(); } + void CElementMatrix::ParseEQN(CStarMathReader *pReader) + {} void CElementMatrix::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { pXmlWrite->WriteNodeBegin(L"m:m",false); @@ -3962,6 +4159,8 @@ namespace StarMath { SetValueMark(CParserStarMathString::ParseElement(pReader)); } + void CElementDiacriticalMark::ParseEQN(CStarMathReader *pReader) + {} void CElementDiacriticalMark::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { std::wstring wsTypeMark; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 2d947765a3..42342d551a 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -124,6 +124,7 @@ namespace StarMath bool GetToken(); //getting a subtype and setting the global type of a token to variables m_enUnderType and m_enGlobalType void SetTypesToken(); + void SetTypesTokenEQN(); void TokenProcessing(const std::wstring& wsToken = L""); TypeElement GetGlobalType(); TypeElement GetLocalType(); @@ -145,10 +146,10 @@ namespace StarMath //taking a token for a color in rgb form int TakingElementForRGB(); void SetString(const std::wstring& wsToken); - void FindingTheEndOfParentheses(); + void FindingTheEndOfParentheses(const bool bEQN = false); void IteratorNullification(); void SettingTheIteratorToTheClosingBracket(); - void ReadingTheNextToken(); + void ReadingTheNextToken(bool bEQN = false); void SetMarkForUnar(const bool& bMark); bool GetMarkForUnar(); void SetTypeConversion(const TypeConversion &enTypeCon); @@ -173,8 +174,9 @@ namespace StarMath CElement(const TypeElement& enTypeBase, const TypeConversion& enTypeConversion); virtual ~CElement(); virtual void Parse(CStarMathReader* pReader) = 0; + virtual void ParseEQN(CStarMathReader* pReader) = 0; //The function creates the class we need (by determining the class type by a variable m_enGlobalType from the class CStarMathReader) - static CElement* CreateElement(CStarMathReader* pReader); + static CElement* CreateElement(CStarMathReader* pReader,const bool bEQN = false); virtual void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) = 0; virtual void SetAttribute(CAttribute* pAttribute) = 0; virtual TFormulaSize GetSize() = 0; @@ -206,6 +208,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; void ConversionOfIndicesToValue(XmlUtils::CXmlWriter* pXmlWrite); @@ -233,6 +236,7 @@ namespace StarMath void SetAttribute(CAttribute* pAttribute) override; private: void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; std::wstring m_wsString; @@ -257,6 +261,7 @@ namespace StarMath void SetAttribute(CAttribute* pAttribute) override; bool IsBinOperatorLowPrior(); void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* oXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pLeftArgument; @@ -277,11 +282,13 @@ namespace StarMath CElement* GetToValue(); void SetName(const std::wstring& wsNameOp); std::wstring GetName(); - static TypeElement GetOperator(const std::wstring& wsToken); + static TypeElement GetOperator(const std::wstring& wsToken,const bool bEQN = false); + static TypeElement GetOperatorEQN(const std::wstring& wsToken); static TypeElement GetFromOrTo(const std::wstring& wsToken); private: void SetAttribute(CAttribute* pAttribute); void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* oXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pValueOperator; @@ -305,6 +312,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pValueGrade; @@ -315,15 +323,16 @@ namespace StarMath class CElementBracket: public CElement { public: - CElementBracket(const TypeElement& enType,const TypeConversion &enTypeConversion,const bool& bScalability = false); + CElementBracket(const TypeElement& enType, const TypeConversion &enTypeConversion, const bool& bScalability = false, const bool &bEQN = false); virtual ~CElementBracket(); void SetBracketValue(const std::vector& arValue); - static TypeElement GetBracketOpen(const std::wstring& wsToken); - static TypeElement GetBracketClose(const std::wstring& wsToken); + static TypeElement GetBracketOpen(const std::wstring& wsToken, const bool bEQN = false); + static TypeElement GetBracketClose(const std::wstring& wsToken, const bool bEQN = false); std::vector GetBracketValue(); private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; bool CheckMline(CElement* pElement); @@ -331,12 +340,13 @@ namespace StarMath TypeElement m_enTypeBracket,m_enLeftBracket,m_enRightBracket; std::vector m_arBrecketValue; bool m_bScalability; + bool m_bEQN; }; class CElementBracketWithIndex: public CElement { public: - CElementBracketWithIndex(const TypeElement& enType,const TypeConversion &enTypeConversion); + CElementBracketWithIndex(const TypeElement& enType, const TypeConversion &enTypeConversion, const bool &bEQN = false); virtual ~CElementBracketWithIndex(); void SetLeftArg(CElement* pElement); void SetBracketValue(CElement* pElement); @@ -346,11 +356,13 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pLeftArg; CElement* m_pValue; TypeElement m_enTypeBracketWithIndex; + bool m_bEQN; }; class CElementSetOperations: public CElement @@ -367,6 +379,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pLeftArgument; @@ -388,6 +401,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pLeftArgument; @@ -408,6 +422,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pValue; @@ -428,6 +443,7 @@ namespace StarMath void SetTypeSymbol(); void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pValue; @@ -446,6 +462,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader *pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; void DimensionCalculation(); TFormulaSize GetSize() override; @@ -465,6 +482,7 @@ namespace StarMath private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; + void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; TFormulaSize GetSize() override; CElement* m_pValueMark; @@ -477,7 +495,9 @@ namespace StarMath CParserStarMathString(); ~CParserStarMathString(); std::vector Parse(std::wstring& wsParseString,int iTypeConversion = 0); + std::vector ParseEQN(std::wstring& wsParseString); static CElement* ParseElement(CStarMathReader* pReader); + static CElement* ParseElementEQN(CStarMathReader* pReader); //Function for adding a left argument (receives the argument itself and the element to which it needs to be added as input. Works with classes:CElementBinOperator,CElementConnection,CElementSetOperation). static bool AddLeftArgument(CElement* pLeftArg,CElement* pElementWhichAdd,CStarMathReader* pReader); static bool CheckForLeftArgument(const TypeElement& enType, const bool& bConnection = true); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h index fdb08eeb9b..5f638a4245 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h @@ -94,6 +94,19 @@ enum class TypeElement{ llint, lllint, oper, + //op EQN + bigsqcap, + bigsqcup, + inter, + Union, + bigoplus, + bigominus, + bigotimes, + bigodiv, + bigodot, + bigvee, + bigwedge, + biguplus, //brace brace, round, From b1885e5b914e08890f64f75e19e83e3a922925ed Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Tue, 22 Apr 2025 10:55:36 +0300 Subject: [PATCH 002/125] pars oper --- .../StarMath2OOXML/cstarmathpars.cpp | 36 ++++++++++++++----- .../Converter/StarMath2OOXML/cstarmathpars.h | 2 +- .../Converter/StarMath2OOXML/typeselements.h | 7 +++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index ed5361cf3b..50603bd20a 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -135,6 +135,7 @@ namespace StarMath { pReader->ClearReader(); pElement->ParseEQN(pReader); + return pElement; } else { @@ -3030,12 +3031,12 @@ namespace StarMath if(L"sum" == wsToken) return TypeElement::sum; else if(L"prod" == wsToken) return TypeElement::prod; else if(L"coprod" == wsToken) return TypeElement::coprod; + else if(L"int" == wsToken) return TypeElement::Int; if(!bEQN) { if(L"lim" == wsToken) return TypeElement::lim; else if(L"liminf" == wsToken) return TypeElement::liminf; else if(L"limsup" == wsToken) return TypeElement::limsup; - else if(L"int" == wsToken) return TypeElement::Int; else if(L"iint" == wsToken) return TypeElement::iint; else if(L"iiint" == wsToken) return TypeElement::iiint; else if(L"lint" == wsToken) return TypeElement::lint; @@ -3053,7 +3054,7 @@ namespace StarMath if(L"bigsqcap" == wsToken) return TypeElement::bigsqcap; else if(L"bigsqcup" == wsToken) return TypeElement::bigsqcup; else if(L"inter" == wsToken) return TypeElement::inter; - else if(L"union" == wsToken) return TypeElement::Union; + else if(L"union" == wsToken) return TypeElement::UnionOp; else if(L"bigoplus" == wsToken) return TypeElement::bigoplus; else if(L"bigominus" == wsToken) return TypeElement::bigominus; else if(L"bigotimes" == wsToken) return TypeElement::bigotimes; @@ -3062,6 +3063,11 @@ namespace StarMath else if(L"bigvee" == wsToken) return TypeElement::bigvee; else if(L"bigwedge" == wsToken) return TypeElement::bigwedge; else if(L"biguplus" == wsToken) return TypeElement::biguplus; + else if(L"dint" == wsToken) return TypeElement::iint; + else if(L"tint" == wsToken) return TypeElement::iiint; + else if(L"oint" == wsToken) return TypeElement::lint; + else if(L"odint" == wsToken) return TypeElement::llint; + else if(L"otint" == wsToken) return TypeElement::lllint; else return TypeElement::undefine; } void CElementOperator::Parse(CStarMathReader* pReader) @@ -3228,7 +3234,7 @@ namespace StarMath } // class methods CStarMathReader CStarMathReader::CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd,const TypeConversion &enTypeConversion) - : m_enGlobalType(TypeElement::Empty),m_enUnderType(TypeElement::Empty),m_pAttribute(nullptr),m_bMarkForUnar(true),m_enTypeCon(enTypeConversion) + : m_enGlobalType(TypeElement::Empty),m_enUnderType(TypeElement::Empty),m_pAttribute(nullptr),m_bMarkForUnar(true),m_enTypeCon(enTypeConversion),m_pBaseAttribute(nullptr) { m_itStart = itStart; m_itEnd = itEnd; @@ -3940,12 +3946,22 @@ namespace StarMath { m_pSecondArgument = pElement; } - TypeElement CElementMatrix::GetMatrix(const std::wstring &wsToken) + TypeElement CElementMatrix::GetMatrix(const std::wstring &wsToken, const bool bEQN) { - if(L"binom" == wsToken) return TypeElement::binom; - else if(L"stack" == wsToken) return TypeElement::stack; - else if(L"matrix" == wsToken) return TypeElement::matrix; - else return TypeElement::undefine; + if(L"matrix" == wsToken) return TypeElement::matrix; + if(bEQN) + { + if(L"pmatrix" == wsToken) return TypeElement::pmatrix; + else if(L"dmatrix" == wsToken) return TypeElement::dmatrix; + else if(L"bmatrix" == wsToken) return TypeElement::bmatrix; + else if(L"pile" == wsToken) return TypeElement::pile; + } + else + { + if(L"binom" == wsToken) return TypeElement::binom; + else if(L"stack" == wsToken) return TypeElement::stack; + } + return TypeElement::undefine; } void CElementMatrix::Parse(CStarMathReader *pReader) { @@ -3963,7 +3979,9 @@ namespace StarMath DimensionCalculation(); } void CElementMatrix::ParseEQN(CStarMathReader *pReader) - {} + { + Parse(pReader); + } void CElementMatrix::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { pXmlWrite->WriteNodeBegin(L"m:m",false); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 42342d551a..778defa65f 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -458,7 +458,7 @@ namespace StarMath virtual ~CElementMatrix(); void SetFirstArgument(CElement* pElement); void SetSecondArgument(CElement* pElement); - static TypeElement GetMatrix(const std::wstring& wsToken); + static TypeElement GetMatrix(const std::wstring& wsToken, const bool bEQN = false); private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader *pReader) override; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h index 5f638a4245..8bbff27669 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h @@ -182,7 +182,7 @@ enum class TypeElement{ dlgrid, //setopetions intersection, - Union, + UnionOp, setminus, setquotient, subseteq, @@ -361,6 +361,11 @@ enum class TypeElement{ binom, stack, matrix, + //EQN matrix + pmatrix, + dmatrix, + bmatrix, + pile, //bracket close rwbrace, rbrace, From 70412f5f8e2f51b9aec42c0678e3722d8d1c7d21 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Sun, 27 Apr 2025 20:22:26 +0300 Subject: [PATCH 003/125] pars index(without underover) --- .../StarMath2OOXML/cstarmathpars.cpp | 64 ++++++++++++++----- .../Converter/StarMath2OOXML/cstarmathpars.h | 7 +- .../Converter/StarMath2OOXML/typeselements.h | 2 + 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 50603bd20a..0247ff33a8 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -262,17 +262,25 @@ namespace StarMath arrEquation.push_back(pAddElement); } } - void CParserStarMathString::ReadingElementsWithPriorities(CStarMathReader *pReader, CElement *&pLeftElement) + void CParserStarMathString::ReadingElementsWithPriorities(CStarMathReader *pReader, CElement *&pLeftElement,const bool bEQN) { - CElement* pNextElement = ParseElement(pReader); + CElement* pNextElement; + if(bEQN) + pNextElement = ParseElementEQN(pReader); + else + pNextElement = ParseElement(pReader); if(pLeftElement != nullptr) AddLeftArgument(pLeftElement,pNextElement,pReader); pLeftElement = pNextElement; pReader->ReadingTheNextToken(); } - void CParserStarMathString::ReadingElementsWithAttributes(CStarMathReader *pReader, CElement*& pSavingElement) + void CParserStarMathString::ReadingElementsWithAttributes(CStarMathReader *pReader, CElement*& pSavingElement, const bool bEQN) { - CElement* pElement = CParserStarMathString::ParseElement(pReader); + CElement* pElement; + if(bEQN) + pElement = CParserStarMathString::ParseElementEQN(pReader); + else + pElement = CParserStarMathString::ParseElement(pReader); if(pElement->GetAttribute() != pReader->GetBaseAttribute()) { pReader->ReadingTheNextToken(); @@ -280,7 +288,10 @@ namespace StarMath { CElement* pIndex = new CElementIndex(pReader->GetLocalType(),pReader->GetTypeConversion()); pReader->ClearReader(); - pIndex->Parse(pReader); + if(bEQN) + pIndex->ParseEQN(pReader); + else + pIndex->Parse(pReader); AddLeftArgument(pElement,pIndex,pReader); pSavingElement = pIndex; } @@ -1024,6 +1035,9 @@ namespace StarMath void CElementBinOperator::ParseEQN(CStarMathReader *pReader) { CElement* pTempElement = CParserStarMathString::ParseElementEQN(pReader); + pReader->ReadingTheNextToken(true); + if(pReader->GetGlobalType() == TypeElement::Index) + CParserStarMathString::ReadingElementsWithPriorities(pReader,pTempElement,true); m_pRightArgument = pTempElement; } void CElementBinOperator::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) @@ -2468,7 +2482,7 @@ namespace StarMath } //class methods CIndex CElementIndex::CElementIndex(const TypeElement& enType,const TypeConversion &enTypeConversion) - : CElement(TypeElement::Index,enTypeConversion),m_pValueIndex(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_pLsubIndex(nullptr),m_pLsupIndex(nullptr),m_pCsubIndex(nullptr),m_pCsupIndex(nullptr),m_pLeftArg(nullptr),m_enTypeIndex(enType) + : CElement(TypeElement::Index,enTypeConversion),m_pValueIndex(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_pLsubIndex(nullptr),m_pLsupIndex(nullptr),m_pCsubIndex(nullptr),m_pCsupIndex(nullptr),m_pLeftArg(nullptr),m_enTypeIndex(enType),m_bEQN(false) { } CElementIndex::~CElementIndex() @@ -2499,19 +2513,23 @@ namespace StarMath { return m_pLeftArg; } - TypeElement CElementIndex::GetIndex(const std::wstring &wsCheckToken) + TypeElement CElementIndex::GetIndex(const std::wstring &wsCheckToken, const bool bEQN) { if(L"^" == wsCheckToken) return TypeElement::upper; - else if(L"rsup" == wsCheckToken) return TypeElement::upper; - else if(L"rsub" == wsCheckToken) return TypeElement::lower; else if(L"_" == wsCheckToken) return TypeElement::lower; else if(L"lsup" == wsCheckToken) return TypeElement::lsup; else if(L"lsub" == wsCheckToken) return TypeElement::lsub; - else if(L"csup" == wsCheckToken) return TypeElement::csup; - else if(L"csub" == wsCheckToken) return TypeElement::csub; - else if(L"nroot" == wsCheckToken) return TypeElement::nroot; - else if(L"sqrt" == wsCheckToken) return TypeElement::sqrt; - else return TypeElement::undefine; + if(!bEQN) + { + if(L"rsup" == wsCheckToken) return TypeElement::upper; + else if(L"rsub" == wsCheckToken) return TypeElement::lower; + else if(L"csup" == wsCheckToken) return TypeElement::csup; + else if(L"csub" == wsCheckToken) return TypeElement::csub; + else if(L"nroot" == wsCheckToken) return TypeElement::nroot; + else if(L"sqrt" == wsCheckToken) return TypeElement::sqrt; + } + else if(L"underover" == wsCheckToken) return TypeElement::underover; + return TypeElement::undefine; } bool CElementIndex::GetUpperIndex(const TypeElement &enType) { @@ -2601,7 +2619,17 @@ namespace StarMath } } void CElementIndex::ParseEQN(CStarMathReader *pReader) - {} + { + m_bEQN = true; + if(m_enTypeIndex != TypeElement::underover) + Parse(pReader); + else + { + m_pValueIndex = CParserStarMathString::ParseElementEQN(pReader); + pReader->ReadingTheNextToken(true); + if() + } + } void CElementIndex::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { if(TypeElement::sqrt == m_enTypeIndex || TypeElement::nroot == m_enTypeIndex) @@ -3395,6 +3423,12 @@ namespace StarMath m_enGlobalType = TypeElement::Operation; return; } + m_enUnderType = CElementIndex::GetIndex(m_wsLowerCaseToken,true); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::Index; + return; + } if(m_enUnderType == TypeElement::undefine && !m_wsLowerCaseToken.empty()) { m_enGlobalType = TypeElement::String; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 778defa65f..efcff56cc7 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -201,7 +201,7 @@ namespace StarMath void SetLeftArg(CElement* pElement); CElement* GetValueIndex(); CElement* GetLeftArg(); - static TypeElement GetIndex(const std::wstring& wsCheckToken); + static TypeElement GetIndex(const std::wstring& wsCheckToken,const bool bEQN = false); static bool GetUpperIndex(const TypeElement& enType); static bool GetLowerIndex(const TypeElement& enType); const TypeElement& GetType(); @@ -222,6 +222,7 @@ namespace StarMath CElement* m_pCsupIndex; CElement* m_pLeftArg; TypeElement m_enTypeIndex; + bool m_bEQN; }; class CElementString: public CElement @@ -508,9 +509,9 @@ namespace StarMath //adding an element to the array, checking that it is not empty and adding the left element, if there is one. static void AddingAnElementToAnArray(std::vector& arrEquation,CElement* pAddElement,CStarMathReader* pReader); //Receives the left element as input, reads the next one, if the next element has a higher priority and contains the left element, the element received at the input is passed to it. The entire structure is saved and returned. - static void ReadingElementsWithPriorities(CStarMathReader* pReader,CElement*& pLeftElement); + static void ReadingElementsWithPriorities(CStarMathReader* pReader,CElement*& pLeftElement, const bool bEQN = false); //method for parsing indexes with attributes. If there is an attribute present when indexes are read, then all subsequent indexes are applied to the index with the attribute. - static void ReadingElementsWithAttributes(CStarMathReader* pReader,CElement*& pSavingElement); + static void ReadingElementsWithAttributes(CStarMathReader* pReader,CElement*& pSavingElement,const bool bEQN = false); static void ParsElementAddingToArray(CStarMathReader* pReader, std::vector& arElements); void SetAlignment(const unsigned int& iAlignment); const unsigned int& GetAlignment(); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h index 8bbff27669..e6a9282115 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h @@ -357,6 +357,8 @@ enum class TypeElement{ lsub, csup, csub, + //index EQN + underover, // binom, stack, From 2aeec01f1e51ddd42f6aa0eac139f75398a3c863 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Thu, 12 Jun 2025 16:40:26 +0300 Subject: [PATCH 004/125] fix index --- .../StarMath2OOXML/cstarmathpars.cpp | 43 ++++++++++++++----- .../Converter/StarMath2OOXML/cstarmathpars.h | 3 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 0247ff33a8..f97615cf60 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -2482,7 +2482,7 @@ namespace StarMath } //class methods CIndex CElementIndex::CElementIndex(const TypeElement& enType,const TypeConversion &enTypeConversion) - : CElement(TypeElement::Index,enTypeConversion),m_pValueIndex(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_pLsubIndex(nullptr),m_pLsupIndex(nullptr),m_pCsubIndex(nullptr),m_pCsupIndex(nullptr),m_pLeftArg(nullptr),m_enTypeIndex(enType),m_bEQN(false) + : CElement(TypeElement::Index,enTypeConversion),m_pValueIndex(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_pLsubIndex(nullptr),m_pLsupIndex(nullptr),m_pCsubIndex(nullptr),m_pCsupIndex(nullptr),m_pLeftArg(nullptr),m_enTypeIndex(enType),m_enTempTypeIndex(TypeElement::undefine),m_bEQN(false) { } CElementIndex::~CElementIndex() @@ -2595,25 +2595,30 @@ namespace StarMath switch(m_enTypeIndex) { case TypeElement::upper: - CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pUpperIndex); + // CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pUpperIndex,m_bEQN); + ParseIndex(pReader,m_pUpperIndex); break; case TypeElement::lower: - CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pLowerIndex); + // CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pLowerIndex,m_bEQN); + ParseIndex(pReader,m_pLowerIndex); break; case TypeElement::lsub: - CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pLsubIndex); + // CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pLsubIndex,m_bEQN); + ParseIndex(pReader,m_pLsubIndex); break; case TypeElement::lsup: - CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pLsupIndex); + // CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pLsupIndex,m_bEQN); + ParseIndex(pReader,m_pLsupIndex); break; case TypeElement::csub: - CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pCsubIndex); + CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pCsubIndex,m_bEQN); break; case TypeElement::csup: - CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pCsupIndex); + CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pCsupIndex,m_bEQN); break; } pReader->ReadingTheNextToken(); + m_enTempTypeIndex = m_enTypeIndex; m_enTypeIndex = pReader->GetLocalType(); }while(GetUpperIndex(pReader->GetLocalType()) || GetLowerIndex(pReader->GetLocalType())); } @@ -2625,11 +2630,23 @@ namespace StarMath Parse(pReader); else { - m_pValueIndex = CParserStarMathString::ParseElementEQN(pReader); - pReader->ReadingTheNextToken(true); - if() + m_pLeftArg = CParserStarMathString::ParseElementEQN(pReader); + Parse(pReader); + m_enTypeIndex = TypeElement::underover; } } + void CElementIndex::ParseIndex(CStarMathReader *pReader, CElement *&pElement) + { + if(m_bEQN && (m_enTempTypeIndex == m_enTypeIndex ) && pElement != nullptr) + { + CElement* pTempElement = new CElementIndex(m_enTempTypeIndex,GetTypeConversion()); + pTempElement->ParseEQN(pReader); + CParserStarMathString::AddLeftArgument(pElement,pTempElement,pReader); + pElement = pTempElement; + } + else + CParserStarMathString::ReadingElementsWithAttributes(pReader,pElement,m_bEQN); + } void CElementIndex::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { if(TypeElement::sqrt == m_enTypeIndex || TypeElement::nroot == m_enTypeIndex) @@ -3411,6 +3428,12 @@ namespace StarMath m_enGlobalType = TypeElement::Bracket; return; } + m_enUnderType = CElementBracket::GetBracketOpen(m_wsLowerCaseToken,true); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::Bracket; + return; + } m_enUnderType = CElementBracketWithIndex::GetBracketWithIndex(m_wsLowerCaseToken); if(m_enUnderType != TypeElement::undefine) { diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index efcff56cc7..ed8a89da72 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -213,6 +213,7 @@ namespace StarMath TFormulaSize GetSize() override; void ConversionOfIndicesToValue(XmlUtils::CXmlWriter* pXmlWrite); void ConversionOfIndicesAfterValue(XmlUtils::CXmlWriter* pXmlWrite); + void ParseIndex(CStarMathReader* pReader,CElement*& pElement); CElement* m_pValueIndex; CElement* m_pUpperIndex; CElement* m_pLowerIndex; @@ -221,7 +222,7 @@ namespace StarMath CElement* m_pCsubIndex; CElement* m_pCsupIndex; CElement* m_pLeftArg; - TypeElement m_enTypeIndex; + TypeElement m_enTypeIndex,m_enTempTypeIndex; bool m_bEQN; }; From 9b3b6caef9de53a517e2ec5854198e504ff00ba7 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Fri, 27 Jun 2025 13:12:49 +0300 Subject: [PATCH 005/125] pars diacritical marks --- .../StarMath2OOXML/cstarmathpars.cpp | 243 +++++++++++------- .../Converter/StarMath2OOXML/cstarmathpars.h | 2 +- .../Converter/StarMath2OOXML/typeselements.h | 4 + 3 files changed, 152 insertions(+), 97 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index f97615cf60..65c1a8d5f9 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -2519,16 +2519,20 @@ namespace StarMath else if(L"_" == wsCheckToken) return TypeElement::lower; else if(L"lsup" == wsCheckToken) return TypeElement::lsup; else if(L"lsub" == wsCheckToken) return TypeElement::lsub; - if(!bEQN) + else if(L"sqrt" == wsCheckToken) return TypeElement::sqrt; + if(bEQN) + { + if(L"underover" == wsCheckToken) return TypeElement::underover; + else if(L"root" == wsCheckToken) return TypeElement::nroot; + } + else { if(L"rsup" == wsCheckToken) return TypeElement::upper; else if(L"rsub" == wsCheckToken) return TypeElement::lower; else if(L"csup" == wsCheckToken) return TypeElement::csup; else if(L"csub" == wsCheckToken) return TypeElement::csub; else if(L"nroot" == wsCheckToken) return TypeElement::nroot; - else if(L"sqrt" == wsCheckToken) return TypeElement::sqrt; } - else if(L"underover" == wsCheckToken) return TypeElement::underover; return TypeElement::undefine; } bool CElementIndex::GetUpperIndex(const TypeElement &enType) @@ -2560,15 +2564,28 @@ namespace StarMath if(m_enTypeIndex == TypeElement::nroot) { m_pLeftArg = CParserStarMathString::ParseElement(pReader); - pReader->ReadingTheNextToken(); + pReader->ReadingTheNextToken(m_bEQN); if(CElementIndex::GetLowerIndex(pReader->GetLocalType()) || CElementIndex::GetUpperIndex(pReader->GetLocalType())) { CElement* pElement = CParserStarMathString::ParseElement(pReader); CParserStarMathString::AddLeftArgument(m_pLeftArg,pElement,pReader); m_pLeftArg = pElement; } + if(m_bEQN) + { + pReader->ReadingTheNextToken(m_bEQN); + if(pReader->GetLowerCaseString() == L"of") + pReader->ClearReader(); + else + { + m_pValueIndex = m_pLeftArg; + m_pLeftArg = nullptr; + m_enTypeIndex = TypeElement::sqrt; + return; + } + } m_pValueIndex = CParserStarMathString::ParseElement(pReader); - pReader->ReadingTheNextToken(); + pReader->ReadingTheNextToken(m_bEQN); if(CElementIndex::GetLowerIndex(pReader->GetLocalType()) || CElementIndex::GetUpperIndex(pReader->GetLocalType())) { CElement* pElement = CParserStarMathString::ParseElement(pReader); @@ -2579,7 +2596,7 @@ namespace StarMath else if(m_enTypeIndex == TypeElement::sqrt) { m_pValueIndex = CParserStarMathString::ParseElement(pReader); - pReader->ReadingTheNextToken(); + pReader->ReadingTheNextToken(m_bEQN); if(CElementIndex::GetLowerIndex(pReader->GetLocalType()) || CElementIndex::GetUpperIndex(pReader->GetLocalType())) { CElement* pElement = CParserStarMathString::ParseElement(pReader); @@ -2663,9 +2680,9 @@ namespace StarMath pXmlWrite->WriteNodeEnd(L"m:radPr",false,false); if(m_pLeftArg != nullptr && m_enTypeIndex == TypeElement::nroot) { - pXmlWrite->WriteNodeBegin(L"m:deg",false); - m_pLeftArg->ConversionToOOXML(pXmlWrite); - pXmlWrite->WriteNodeEnd(L"m:deg",false,false); + pXmlWrite->WriteNodeBegin(L"m:deg",false); + m_pLeftArg->ConversionToOOXML(pXmlWrite); + pXmlWrite->WriteNodeEnd(L"m:deg",false,false); } else { @@ -3452,6 +3469,12 @@ namespace StarMath m_enGlobalType = TypeElement::Index; return; } + m_enUnderType = CElementDiacriticalMark::GetMark(m_wsLowerCaseToken,true); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::Mark; + return; + } if(m_enUnderType == TypeElement::undefine && !m_wsLowerCaseToken.empty()) { m_enGlobalType = TypeElement::String; @@ -4206,116 +4229,144 @@ namespace StarMath { m_pValueMark = pValue; } - TypeElement CElementDiacriticalMark::GetMark(const std::wstring &wsToken) + TypeElement CElementDiacriticalMark::GetMark(const std::wstring &wsToken, const bool bEQN) { if(L"acute" == wsToken) return TypeElement::acute; else if(L"breve" == wsToken) return TypeElement::breve; else if(L"dot" == wsToken) return TypeElement::dot; - else if(L"dddot" == wsToken) return TypeElement::dddot; else if(L"vec" == wsToken) return TypeElement::vec; - else if(L"tilde" == wsToken) return TypeElement::tilde; - else if(L"check" == wsToken) return TypeElement::check; - else if(L"grave" == wsToken) return TypeElement::grave; - else if(L"circle" == wsToken) return TypeElement::circle; else if(L"ddot" == wsToken) return TypeElement::ddot; else if(L"bar" == wsToken) return TypeElement::bar; - else if(L"harpoon" == wsToken) return TypeElement::harpoon; else if(L"hat" == wsToken) return TypeElement::hat; - else if(L"widevec" == wsToken) return TypeElement::widevec; - else if(L"widetilde" == wsToken) return TypeElement::widetilde; - else if(L"overline" == wsToken) return TypeElement::overline; - else if(L"overstrike" == wsToken) return TypeElement::overstrike; - else if(L"wideharpoon" == wsToken) return TypeElement::wideharpoon; - else if(L"widehat" == wsToken) return TypeElement::widehat; - else if(L"underline" == wsToken) return TypeElement::underline; - else return TypeElement::undefine; + else if(L"check" == wsToken) return TypeElement::check; + else if(L"tilde" == wsToken) return TypeElement::tilde; + if(bEQN) + { + if(L"dyad" == wsToken) return TypeElement::dyad; + else if(L"arch" == wsToken) return TypeElement::undefine; + else if(L"under" == wsToken) return TypeElement::underline; + else if(L"box" == wsToken) return TypeElement::box; + } + else + { + if(L"dddot" == wsToken) return TypeElement::dddot; + else if(L"grave" == wsToken) return TypeElement::grave; + else if(L"circle" == wsToken) return TypeElement::circle; + else if(L"harpoon" == wsToken) return TypeElement::harpoon; + else if(L"widevec" == wsToken) return TypeElement::widevec; + else if(L"widetilde" == wsToken) return TypeElement::widetilde; + else if(L"overline" == wsToken) return TypeElement::overline; + else if(L"overstrike" == wsToken) return TypeElement::overstrike; + else if(L"wideharpoon" == wsToken) return TypeElement::wideharpoon; + else if(L"widehat" == wsToken) return TypeElement::widehat; + else if(L"underline" == wsToken) return TypeElement::underline; + } + return TypeElement::undefine; + } void CElementDiacriticalMark::Parse(CStarMathReader *pReader) { SetValueMark(CParserStarMathString::ParseElement(pReader)); } void CElementDiacriticalMark::ParseEQN(CStarMathReader *pReader) - {} + { + Parse(pReader); + } void CElementDiacriticalMark::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { - std::wstring wsTypeMark; - switch(m_enTypeMark) + if(m_enTypeMark == TypeElement::box) { - case TypeElement::dot: - wsTypeMark = L"\u0307"; - break; - case TypeElement::overline: - wsTypeMark = L"\u0305"; - break; - case TypeElement::vec: - wsTypeMark = L"\u20D7"; - break; - case TypeElement::acute: - wsTypeMark = L"\u0301"; - break; - case TypeElement::grave: - wsTypeMark = L"\u0300"; - break; - case TypeElement::breve: - wsTypeMark = L"\u0306"; - break; - case TypeElement::circle: - wsTypeMark = L"\u030A"; - break; - case TypeElement::ddot: - wsTypeMark = L"\u0308"; - break; - case TypeElement::bar: - wsTypeMark = L"\u0304"; - break; - case TypeElement::dddot: - wsTypeMark = L"\u20DB"; - break; - case TypeElement::harpoon: - wsTypeMark = L"\u20D1"; - break; - case TypeElement::tilde: - wsTypeMark = L"\u0342"; - break; - case TypeElement::hat: - wsTypeMark = L"\u0302"; - break; - case TypeElement::check: - wsTypeMark = L"\u030C"; - break; - case TypeElement::widevec: - wsTypeMark = L"\u20D7"; - break; - case TypeElement::widetilde: - wsTypeMark = L"\u0360"; - break; - case TypeElement::wideharpoon: - wsTypeMark = L"\u20D1"; - break; - case TypeElement::underline: - wsTypeMark = L"\u0332"; - break; - default: - break; + pXmlWrite->WriteNodeBegin(L"m:borderBox",false); + pXmlWrite->WriteNodeBegin(L"m:borderBoxPr",false); + CConversionSMtoOOXML::WriteCtrlPrNode(pXmlWrite,GetAttribute(),GetTypeConversion()); + pXmlWrite->WriteNodeEnd(L"m:borderboxPr",false,false); + CConversionSMtoOOXML::WriteNodeConversion(L"m:e",m_pValueMark,pXmlWrite); + pXmlWrite->WriteNodeEnd(L"m:borderBox",false,false); } - pXmlWrite->WriteNodeBegin(L"m:acc",false); - pXmlWrite->WriteNodeBegin(L"m:accPr",false); - switch(m_enTypeMark) + else { - case TypeElement::widehat: - break; - default: + std::wstring wsTypeMark; + switch(m_enTypeMark) { - pXmlWrite->WriteNodeBegin(L"m:chr",true); - pXmlWrite->WriteAttribute(L"m:val",wsTypeMark); - pXmlWrite->WriteNodeEnd(L"w",true,true); + case TypeElement::dot: + wsTypeMark = L"\u0307"; + break; + case TypeElement::overline: + wsTypeMark = L"\u0305"; + break; + case TypeElement::vec: + wsTypeMark = L"\u20D7"; + break; + case TypeElement::acute: + wsTypeMark = L"\u0301"; + break; + case TypeElement::grave: + wsTypeMark = L"\u0300"; + break; + case TypeElement::breve: + wsTypeMark = L"\u0306"; + break; + case TypeElement::circle: + wsTypeMark = L"\u030A"; + break; + case TypeElement::ddot: + wsTypeMark = L"\u0308"; + break; + case TypeElement::bar: + wsTypeMark = L"\u0304"; + break; + case TypeElement::dddot: + wsTypeMark = L"\u20DB"; + break; + case TypeElement::harpoon: + wsTypeMark = L"\u20D1"; break; + case TypeElement::tilde: + wsTypeMark = L"\u0342"; + break; + case TypeElement::hat: + wsTypeMark = L"\u0302"; + break; + case TypeElement::check: + wsTypeMark = L"\u030C"; + break; + case TypeElement::widevec: + wsTypeMark = L"\u20D7"; + break; + case TypeElement::widetilde: + wsTypeMark = L"\u0360"; + break; + case TypeElement::wideharpoon: + wsTypeMark = L"\u20D1"; + break; + case TypeElement::underline: + wsTypeMark = L"\u0332"; + break; + case TypeElement::dyad: + wsTypeMark = L"\u20E1"; + break; + default: + break; } + pXmlWrite->WriteNodeBegin(L"m:acc",false); + pXmlWrite->WriteNodeBegin(L"m:accPr",false); + switch(m_enTypeMark) + { + case TypeElement::widehat: + break; + default: + { + pXmlWrite->WriteNodeBegin(L"m:chr",true); + pXmlWrite->WriteAttribute(L"m:val",wsTypeMark); + pXmlWrite->WriteNodeEnd(L"w",true,true); + break; + } + } + CConversionSMtoOOXML::WriteCtrlPrNode(pXmlWrite,GetAttribute(),GetTypeConversion()); + pXmlWrite->WriteNodeEnd(L"m:accPr",false,false); + CConversionSMtoOOXML::WriteNodeConversion(L"m:e",m_pValueMark,pXmlWrite); + pXmlWrite->WriteNodeEnd(L"m:acc",false,false); } - CConversionSMtoOOXML::WriteCtrlPrNode(pXmlWrite,GetAttribute(),GetTypeConversion()); - pXmlWrite->WriteNodeEnd(L"m:accPr",false,false); - CConversionSMtoOOXML::WriteNodeConversion(L"m:e",m_pValueMark,pXmlWrite); - pXmlWrite->WriteNodeEnd(L"m:acc",false,false); } void CElementDiacriticalMark::SetAttribute(CAttribute *pAttribute) { diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index ed8a89da72..04411bbb77 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -480,7 +480,7 @@ namespace StarMath CElementDiacriticalMark(const TypeElement& enType,const TypeConversion &enTypeConversion); virtual ~CElementDiacriticalMark(); void SetValueMark(CElement* pValue); - static TypeElement GetMark(const std::wstring& wsToken); + static TypeElement GetMark(const std::wstring& wsToken, const bool bEQN = false); private: void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h index e6a9282115..809b0e3cb9 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h @@ -149,6 +149,10 @@ enum class TypeElement{ wideharpoon, widehat, underline,//top elements + //EQN top elements + dyad, + box, + // color, hex, rgb, From b0e810013d6d7c361b81a7518ffb2519eb25aac4 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Fri, 18 Jul 2025 12:18:27 +0300 Subject: [PATCH 006/125] editing conversion and parsing, fixing bugs, adding tests --- .../StarMath2OOXML/StarMath2OOXML.pri | 4 +- .../TestEQNtoOOXML/TestEQNtoOOXML.pro | 18 + .../StarMath2OOXML/TestEQNtoOOXML/main.cpp | 265 +++ .../StarMath2OOXML/cconversionsmtoooxml.cpp | 19 +- .../StarMath2OOXML/cconversionsmtoooxml.h | 2 +- .../StarMath2OOXML/cstarmathpars.cpp | 1506 +++++++++++++---- .../Converter/StarMath2OOXML/cstarmathpars.h | 40 +- .../Converter/StarMath2OOXML/typeselements.h | 87 + 8 files changed, 1564 insertions(+), 377 deletions(-) create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri index 9cbd390c47..dddb09af70 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri @@ -9,12 +9,12 @@ ADD_DEPENDENCY(UnicodeConverter, kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ -# $$PWD/cooxml2odf.cpp \ + $$PWD/cooxml2odf.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ $$PWD/cconversionsmtoooxml.h \ -# $$PWD/cooxml2odf.h \ + $$PWD/cooxml2odf.h \ $$PWD/cstarmathpars.h \ $$PWD/fontType.h \ $$PWD/typeConversion.h \ diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro new file mode 100644 index 0000000000..788618500b --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro @@ -0,0 +1,18 @@ +QT -= core gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle +TEMPLATE = app + +CORE_ROOT_DIR = $$PWD/../../../../.. +PWD_ROOT_DIR = $$PWD + +include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) +include($$CORE_ROOT_DIR/Common/3dParty/googletest/googletest.pri) + + + +SOURCES += main.cpp + +DESTDIR = $$PWD/build diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp new file mode 100644 index 0000000000..87f87e2237 --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp @@ -0,0 +1,265 @@ +#include "../cstarmathpars.h" +#include "../cconversionsmtoooxml.h" +#include "gtest/gtest.h" + + +TEST(SMConvectorTest,IndexUpperLower) +{ + std::wstring wsString = L"2^{ 1} _{ 3}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"231"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,LsupLsub) +{ + std::wstring wsString = L"{ 1} LSUP { 2} LSUB { 3}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"321"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,UnderOver) +{ + std::wstring wsString = L"UNDEROVER { 5} _{ 6} ^{ 7}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"576"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,VecUnder) +{ + std::wstring wsString = L"vec { 1} under { 2}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"12"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,BarHat) +{ + std::wstring wsString = L"bar { 5} hat { 6}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"56"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,SqrtRoot) +{ + std::wstring wsString = L"sqrt {2} root {5} of {10}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"2510"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Over) +{ + std::wstring wsString = L"{ 5} over {10 }"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"510"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,SumProdCoprod) +{ + std::wstring wsString = L"sum _{ 1} ^{ 2} 3 PROD _{ 4} ^{5 } 6 COPROD _{ 7} ^{ 8} 9"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"123456789"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,BigPlusBigUplus) +{ + std::wstring wsString = L"BIGOPLUS _{ 1} ^{2 } 3 BIGUPLUS _{ 5} ^{10 } 15"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"21310515"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Tint) +{ + std::wstring wsString = L"tint _{{2} over {3}} ^{4} {root {5} of {10}}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"234510"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Otint) +{ + std::wstring wsString = L"otint _{ 1} ^{ 2} { 3}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"123"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,RelAndBuildrelArrow) +{ + std::wstring wsString = L"REL LRARROW { 1} { 2} REL EXARROW { 3} { 4} BUILDREL rarrow { 5} { 6}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"123456"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,LimLimlow) +{ + std::wstring wsString = L"Lim _{ ->inf} { 2} lim _{ ->0} { 5}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"Lim2lim05"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,LfloorSquare) +{ + std::wstring wsString = L"LEFT [ { 1} over { 2} RIGHT ] LFLOOR sum _{ 1} ^{ 2} RFLOOR"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"1212"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Cases) +{ + std::wstring wsString = L"cases{ 1& 2# 3& 4}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"1234"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Lline) +{ + std::wstring wsString = L"LEFT | 1 RIGHT | 2 + 3"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"12+3"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Arrow) +{ + std::wstring wsString = L"larrow UPARROW NWARROW MAPSTO DLINE"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L""; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Overbrace) +{ + std::wstring wsString = L"OVERBRACE { 1} { 2}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"12"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Underbrace) +{ + std::wstring wsString = L"UNDERBRACE { 5} {10 }"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"105"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Pile) +{ + std::wstring wsString = L"pile{ 1 over 2 # 2}"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"122"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Pmatrix) +{ + std::wstring wsString = L"pmatrix { 1& 2#3 &4 }"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"1234"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,Bmatrix) +{ + std::wstring wsString = L"bmatrix { 1&2 &3 # 4& 6&5 # 7& 8&9 }"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"123465789"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,GreekSymbols) +{ + std::wstring wsString = L"ALPHA ETA NU TAU PSI"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"ΑΗΝΤΨ"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,GreekSymbolsSmall) +{ + std::wstring wsString = L"epsilon iota nu rho phi"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"εινρφ"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +TEST(SMConvectorTest,MathOperatorSymbols) +{ + std::wstring wsString = L"+- DEG BECAUSE REIMAGE ASYMP FORALL LNOT DAGGER"; + StarMath::CParserStarMathString oTemp; + StarMath::CConversionSMtoOOXML oTest; + oTest.StartConversion(oTemp.ParseEQN(wsString)); + std::wstring wsXmlString = L"±°¬"; + EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +} + +// TEST(SMConvectorTest,AttributeMatrix) +// { +// std::wstring wsString = L""; +// StarMath::CParserStarMathString oTemp; +// StarMath::CConversionSMtoOOXML oTest; +// oTest.StartConversion(oTemp.ParseEQN(wsString)); +// std::wstring wsXmlString = L""; +// EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +// } + diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp index 39496d6ca4..06eb33ff45 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp @@ -252,7 +252,7 @@ namespace StarMath { WriteCtrlPrNode(pXmlWrite,pAttribute,enTypeConversion); pXmlWrite->WriteNodeEnd(L"m:fPr",false,false); } - void CConversionSMtoOOXML::PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion) + void CConversionSMtoOOXML::PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion,const bool& bEQN) { pXmlWrite->WriteNodeBegin(L"m:naryPr",false); switch(enTypeOp) @@ -283,10 +283,25 @@ namespace StarMath { case TypeElement::lllint: WriteChrNode(L"\u2230",pXmlWrite); break; + case TypeElement::inter: + WriteChrNode(L"\u22C2",pXmlWrite); + break; + case TypeElement::UnionOp: + WriteChrNode(L"\u22C3",pXmlWrite); + break; + case TypeElement::bigvee: + WriteChrNode(L"\u22C1",pXmlWrite); + break; + case TypeElement::bigwedge: + WriteChrNode(L"\u22C0",pXmlWrite); + break; default: break; } - WriteLimLocNode(L"undOvr",pXmlWrite); + if(bEQN && (enTypeOp == TypeElement::Int || enTypeOp == TypeElement::iint || enTypeOp == TypeElement::iiint || enTypeOp == TypeElement::lint || enTypeOp == TypeElement::llint || enTypeOp == TypeElement::lllint)) + WriteLimLocNode(L"subSup",pXmlWrite); + else + WriteLimLocNode(L"undOvr",pXmlWrite); if(bEmptySub) { pXmlWrite->WriteNodeBegin(L"m:subHide",true); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h index f267e04279..19f6afc281 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h @@ -45,7 +45,7 @@ namespace StarMath { void StartConversion(std::vector arPars, const unsigned int& iAlignment = 1); static void StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion& enTypeConversion); static void PropertiesMFPR(const std::wstring& wsType,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); - static void PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); + static void PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion,const bool& bEQN = false); static void PropertiesFuncPr(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); static void WriteNodeConversion(const std::wstring& wsNameBlock,CElement* pValueBlock,XmlUtils::CXmlWriter* pXmlWrite); static void PropertiesDPr(XmlUtils::CXmlWriter* pXmlWrite,const std::wstring& wsOpenBracket,const std::wstring& wsCloseBracket,CAttribute* pAttribute,const TypeConversion &enTypeConversion,const TypeElement& enTypeBracket); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 65c1a8d5f9..04fa26b4df 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -86,7 +86,7 @@ namespace StarMath std::vector CParserStarMathString::ParseEQN(std::wstring &wsParseString) { std::wstring::iterator itStart = wsParseString.begin(),itEnd = wsParseString.end(); - CStarMathReader* pReader = new CStarMathReader(itStart,itEnd,TypeConversion::docx); + CStarMathReader* pReader = new CStarMathReader(itStart,itEnd,TypeConversion::docx,true); while(pReader->CheckIteratorPosition()) { CElement* pTempElement = ParseElementEQN(pReader); @@ -94,7 +94,7 @@ namespace StarMath } if(!pReader->EmptyString()) { - CElement* pTempElement = ParseElement(pReader); + CElement* pTempElement = ParseElementEQN(pReader); if(nullptr != pTempElement) m_arEquation.push_back(pTempElement); } @@ -130,7 +130,7 @@ namespace StarMath { CElement* pElement = nullptr; pReader->ReadingTheNextToken(true); - pElement = CElement::CreateElement(pReader); + pElement = CElement::CreateElement(pReader,true); if(pElement != nullptr) { pReader->ClearReader(); @@ -199,14 +199,19 @@ namespace StarMath } else return false; + return false; } - CElement* CParserStarMathString::ReadingWithoutBracket(CStarMathReader *pReader, const bool& bConnection) + CElement* CParserStarMathString::ReadingWithoutBracket(CStarMathReader *pReader, const bool& bConnection, const bool &bEQN) { - CElement* pFirstTempElement = CParserStarMathString::ParseElement(pReader); - pReader->ReadingTheNextToken(); + CElement* pFirstTempElement; + if(bEQN) + pFirstTempElement = CParserStarMathString::ParseElementEQN(pReader); + else + pFirstTempElement = CParserStarMathString::ParseElement(pReader); + pReader->ReadingTheNextToken(bEQN); while(CheckForLeftArgument(pReader->GetGlobalType(),bConnection) && (pReader->GetLocalType() != TypeElement::neg && pReader->GetLocalType() != TypeElement::frac && pReader->GetLocalType()!=TypeElement::nroot && pReader->GetLocalType()!=TypeElement::sqrt)) { - CParserStarMathString::ReadingElementsWithPriorities(pReader,pFirstTempElement); + CParserStarMathString::ReadingElementsWithPriorities(pReader,pFirstTempElement,bEQN); } return pFirstTempElement; } @@ -343,11 +348,15 @@ namespace StarMath else return wsLowerCase; } - void CParserStarMathString::ParsElementAddingToArray(CStarMathReader *pReader, std::vector &arElements) + void CParserStarMathString::ParsElementAddingToArray(CStarMathReader *pReader, std::vector &arElements, const bool& bEQN) { if(!arElements.empty()) CElementBinOperator::UnaryCheck(pReader,arElements.back()); - CElement* pTempElement = ParseElement(pReader); + CElement* pTempElement; + if(!bEQN) + pTempElement = ParseElement(pReader); + else + pTempElement = ParseElementEQN(pReader); AddingAnElementToAnArray(arElements,pTempElement,pReader); } std::queue CParserStarMathString::GetFormulaSize() @@ -852,8 +861,9 @@ namespace StarMath case TypeElement::Matrix: return new CElementMatrix(pReader->GetLocalType(),pReader->GetTypeConversion()); case TypeElement::SpecialSymbol: - return new CElementSpecialSymbol(pReader->GetLocalType(),pReader->GetTypeConversion()); + return new CElementSpecialSymbol(pReader->GetLocalType(),pReader->GetTypeConversion(),bEQN); case TypeElement::Index: + case TypeElement::IndexOp: return new CElementIndex(pReader->GetLocalType(),pReader->GetTypeConversion()); case TypeElement::Mark: return new CElementDiacriticalMark(pReader->GetLocalType(),pReader->GetTypeConversion()); @@ -940,8 +950,7 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:r",false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); pXmlWrite->WriteNodeBegin(L"m:t",false); -// pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); - pXmlWrite->WriteString(m_wsString); + pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); pXmlWrite->WriteNodeEnd(L"m:t",false,false); pXmlWrite->WriteNodeEnd(L"m:r",false,false); } @@ -1036,7 +1045,7 @@ namespace StarMath { CElement* pTempElement = CParserStarMathString::ParseElementEQN(pReader); pReader->ReadingTheNextToken(true); - if(pReader->GetGlobalType() == TypeElement::Index) + if(pReader->GetGlobalType() == TypeElement::Index && pReader->GetLocalType() != TypeElement::nroot && pReader->GetLocalType() != TypeElement::sqrt) CParserStarMathString::ReadingElementsWithPriorities(pReader,pTempElement,true); m_pRightArgument = pTempElement; } @@ -1057,69 +1066,13 @@ namespace StarMath } else { + std::wstring wsSymbol; CConversionSMtoOOXML::ElementConversion(pXmlWrite,m_pLeftArgument); pXmlWrite->WriteNodeBegin(L"m:r",false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); pXmlWrite->WriteNodeBegin(L"m:t",false); - switch (m_enTypeBinOp) - { - case TypeElement::plus: - pXmlWrite->WriteString(L"+"); - break; - case TypeElement::minus: - pXmlWrite->WriteString(L"-"); - break; - case TypeElement::multipl: - pXmlWrite->WriteString(L"*"); - break; - case TypeElement::cdot: - pXmlWrite->WriteString(L"\u00B7"); - break; - case TypeElement::times: - pXmlWrite->WriteString(L"\u00D7"); - break; - case TypeElement::div: - pXmlWrite->WriteString(L"\u00F7"); - break; - case TypeElement::odivide: - pXmlWrite->WriteString(L"\u2298"); - break; - case TypeElement::oplus: - pXmlWrite->WriteString(L"\u2295"); - break; - case TypeElement::ominus: - pXmlWrite->WriteString(L"\u2296"); - break; - case TypeElement::odot: - pXmlWrite->WriteString(L"\u2299"); - break; - case TypeElement::otimes: - pXmlWrite->WriteString(L"\u2297"); - break; - case TypeElement::plus_minus: - pXmlWrite->WriteString(L"\u00B1"); - break; - case TypeElement::minus_plus: - pXmlWrite->WriteString(L"\u2213"); - break; - case TypeElement::Or: - pXmlWrite->WriteString(L"\u2228"); - break; - case TypeElement::And: - pXmlWrite->WriteString(L"\u2227"); - break; - case TypeElement::neg: - pXmlWrite->WriteString(L"\u00AC"); - break; - case TypeElement::circ: - pXmlWrite->WriteString(L"\u2218"); - break; - case TypeElement::widebslash: - pXmlWrite->WriteString(L"\u2216"); - break; - default: - break; - } + CElementBinOperator::WritingBinOperatorSymbol(wsSymbol,m_enTypeBinOp); + pXmlWrite->WriteString(wsSymbol); if(m_pRightArgument!=nullptr && m_pRightArgument->GetBaseType() == TypeElement::String && GetAttribute() == m_pRightArgument->GetAttribute()) { CElementString* oNumber = dynamic_cast (m_pRightArgument); @@ -1136,36 +1089,106 @@ namespace StarMath } } + void CElementBinOperator::WritingBinOperatorSymbol(std::wstring& wsSymbol,const TypeElement& enType) + { + switch (enType) + { + case TypeElement::plus: + wsSymbol = L"+"; + break; + case TypeElement::minus: + wsSymbol = L"-"; + break; + case TypeElement::multipl: + wsSymbol = L"*" ; + break; + case TypeElement::cdot: + wsSymbol = L"\u00B7"; + break; + case TypeElement::times: + wsSymbol = L"\u00D7"; + break; + case TypeElement::div: + wsSymbol = L"\u00F7"; + break; + case TypeElement::odivide: + wsSymbol = L"\u2298"; + break; + case TypeElement::oplus: + wsSymbol = L"\u2295"; + break; + case TypeElement::ominus: + wsSymbol = L"\u2296"; + break; + case TypeElement::odot: + wsSymbol = L"\u2299"; + break; + case TypeElement::otimes: + wsSymbol = L"\u2297"; + break; + case TypeElement::plus_minus: + wsSymbol = L"\u00B1"; + break; + case TypeElement::minus_plus: + wsSymbol = L"\u2213"; + break; + case TypeElement::Or: + wsSymbol = L"\u2228"; + break; + case TypeElement::And: + wsSymbol = L"\u2227"; + break; + case TypeElement::neg: + wsSymbol = L"\u00AC"; + break; + case TypeElement::circ: + wsSymbol = L"\u2218"; + break; + case TypeElement::widebslash: + wsSymbol = L"\u2216"; + break; + default: + break; + } + } void CElementBinOperator::SetTypeBinOP(const TypeElement &enType) { m_enTypeBinOp = enType; } - TypeElement CElementBinOperator::GetBinOperator(const std::wstring& wsToken) + TypeElement CElementBinOperator::GetBinOperator(const std::wstring& wsToken, const bool &bEQN) { - if(L"cdot" == wsToken) return TypeElement::cdot; - else if(L"+" == wsToken) return TypeElement::plus; - else if(L"-" == wsToken) return TypeElement::minus; - else if(L"oplus" == wsToken) return TypeElement::oplus; + if(L"oplus" == wsToken) return TypeElement::oplus; else if(L"ominus" == wsToken) return TypeElement::ominus; - else if(L"circ" == wsToken) return TypeElement::circ; - else if(L"times" == wsToken) return TypeElement::times; - else if(L"over" == wsToken) return TypeElement::over; - else if(L"frac" == wsToken) return TypeElement::frac; - else if(L"div" == wsToken) return TypeElement::div; - else if(L"*" == wsToken) return TypeElement::multipl; - else if(L"/" == wsToken) return TypeElement::division; else if(L"odot" == wsToken) return TypeElement::odot; else if(L"otimes" == wsToken) return TypeElement::otimes; - else if(L"odivide" == wsToken) return TypeElement::odivide; - else if(L"wideslash" == wsToken) return TypeElement::wideslash; - else if(L"widebslash" == wsToken) return TypeElement::widebslash; else if(L"+-" == wsToken) return TypeElement::plus_minus; else if(L"-+" == wsToken) return TypeElement::minus_plus; - else if(L"neg" == wsToken) return TypeElement::neg; - else if(L"or" == wsToken) return TypeElement::Or; - else if(L"and" == wsToken) return TypeElement::And; - else if(L"&" == wsToken) return TypeElement::And; - else return TypeElement::undefine; + else if(L"circ" == wsToken) return TypeElement::circ; + else if(L"times" == wsToken) return TypeElement::times; + if(bEQN) + { + if(L"odiv" == wsToken) return TypeElement::odivide; + else if(L"divide" == wsToken) return TypeElement::div; + } + else + { + if(L"cdot" == wsToken) return TypeElement::cdot; + else if(L"+" == wsToken) return TypeElement::plus; + else if(L"-" == wsToken) return TypeElement::minus; + else if(L"over" == wsToken) return TypeElement::over; + else if(L"frac" == wsToken) return TypeElement::frac; + else if(L"div" == wsToken) return TypeElement::div; + else if(L"*" == wsToken) return TypeElement::multipl; + else if(L"/" == wsToken) return TypeElement::division; + else if(L"odivide" == wsToken) return TypeElement::odivide; + else if(L"wideslash" == wsToken) return TypeElement::wideslash; + else if(L"widebslash" == wsToken) return TypeElement::widebslash; + else if(L"neg" == wsToken) return TypeElement::neg; + else if(L"or" == wsToken) return TypeElement::Or; + else if(L"and" == wsToken) return TypeElement::And; + else if(L"&" == wsToken) return TypeElement::And; + } + return TypeElement::undefine; } bool CElementBinOperator::MixedOperators(const TypeElement &enType) { @@ -1268,14 +1291,22 @@ namespace StarMath { m_arBrecketValue = arValue; } - TypeElement CElementBracket::GetBracketOpen(const std::wstring &wsToken, const bool bEQN) + TypeElement CElementBracket::GetBracketOpen(const std::wstring &wsToken, const bool bEQN, const bool bLeft) { if(L"left" == wsToken) return TypeElement::left; else if(L"(" == wsToken) return TypeElement::round; else if(L"[" == wsToken) return TypeElement::square; + else if(L"lceil" == wsToken) return TypeElement::lceil; + else if(L"lfloor" == wsToken) return TypeElement::lfloor; else if(bEQN) { - if(L"{" == wsToken) return TypeElement::lbrace; + if(L"{" == wsToken) + { + if(bLeft) + return TypeElement::lbrace; + else + return TypeElement::brace; + } else if(L"\u003C" == wsToken) return TypeElement::langle; else if(L"\u007C" == wsToken) return TypeElement::lline; else if(L"\u2225" == wsToken) return TypeElement::ldline; @@ -1283,24 +1314,32 @@ namespace StarMath else { if(L"{" == wsToken) return TypeElement::brace; - else if(L"ldbracket" == wsToken) return TypeElement::ldbracket; + if(L"ldbracket" == wsToken) return TypeElement::ldbracket; else if(L"lbrace" == wsToken) return TypeElement::lbrace; else if(L"langle" == wsToken) return TypeElement::langle; - else if(L"lceil" == wsToken) return TypeElement::lceil; - else if(L"lfloor" == wsToken) return TypeElement::lfloor; + // else if(L"lceil" == wsToken) return TypeElement::lceil; + // else if(L"lfloor" == wsToken) return TypeElement::lfloor; else if(L"lline" == wsToken) return TypeElement::lline; else if(L"ldline" == wsToken) return TypeElement::ldline; } return TypeElement::undefine; } - TypeElement CElementBracket::GetBracketClose(const std::wstring &wsToken, const bool bEQN) + TypeElement CElementBracket::GetBracketClose(const std::wstring &wsToken, const bool bEQN, const bool bLeft) { if(L"right" == wsToken) return TypeElement::right; else if(L")" == wsToken) return TypeElement::rround; else if(L"]" == wsToken) return TypeElement::rsquare; + else if(L"rceil" == wsToken) return TypeElement::rceil; + else if(L"rfloor" == wsToken) return TypeElement::rfloor; else if(bEQN) { - if(L"}" == wsToken) return TypeElement::rbrace; + if(L"}" == wsToken) + { + if(bLeft) + return TypeElement::rbrace; + else + return TypeElement::rwbrace; + } else if(L"\u003E" == wsToken) return TypeElement::rangle; else if(L"\u007C" == wsToken) return TypeElement::rline; else if(L"\u2225" == wsToken) return TypeElement::rdline; @@ -1311,14 +1350,22 @@ namespace StarMath else if(L"rdbracket" == wsToken) return TypeElement::rdbracket; else if(L"rbrace" == wsToken) return TypeElement::rbrace; else if(L"rangle" == wsToken) return TypeElement::rangle; - else if(L"rceil" == wsToken) return TypeElement::rceil; - else if(L"rfloor" == wsToken) return TypeElement::rfloor; + // else if(L"rceil" == wsToken) return TypeElement::rceil; + // else if(L"rfloor" == wsToken) return TypeElement::rfloor; else if(L"rline" == wsToken) return TypeElement::rline; else if(L"rdline" == wsToken) return TypeElement::rdline; else if(L"none" == wsToken) return TypeElement::none; } return TypeElement::undefine; } + void CElementBracket::SetLeftBracket(const TypeElement& enTypeLeftBracket) + { + m_enLeftBracket = enTypeLeftBracket; + } + void CElementBracket::SetRightBracket(const TypeElement& enTypeRightBracket) + { + m_enRightBracket = enTypeRightBracket; + } std::vector CElementBracket::GetBracketValue() { return m_arBrecketValue; @@ -1329,11 +1376,11 @@ namespace StarMath if(m_enTypeBracket == TypeElement::left) { pReader->ReadingTheNextToken(m_bEQN); - enOpen = GetBracketOpen(pReader->GetLowerCaseString(),m_bEQN); + enOpen = GetBracketOpen(pReader->GetLowerCaseString(),m_bEQN,m_bScalability); if(pReader->GetLowerCaseString() == L"none" && !m_bEQN) enOpen = TypeElement::none; else - enClose = GetBracketClose(pReader->GetLowerCaseString(),m_bEQN); + enClose = GetBracketClose(pReader->GetLowerCaseString(),m_bEQN,m_bScalability); if(enOpen != TypeElement::undefine) { m_enLeftBracket = enOpen; @@ -1354,7 +1401,7 @@ namespace StarMath pReader->ClearReader(); continue; } - CParserStarMathString::ParsElementAddingToArray(pReader,m_arBrecketValue); + CParserStarMathString::ParsElementAddingToArray(pReader,m_arBrecketValue,m_bEQN); } if(!pReader->EmptyString() && pReader->GetLowerCaseString() != L"right") { @@ -1373,8 +1420,8 @@ namespace StarMath pReader->SettingTheIteratorToTheClosingBracket(); pReader->ClearReader(); pReader->ReadingTheNextToken(m_bEQN); - enOpen = GetBracketOpen(pReader->GetLowerCaseString(),m_bEQN); - enClose = GetBracketClose(pReader->GetLowerCaseString(),m_bEQN); + enOpen = GetBracketOpen(pReader->GetLowerCaseString(),m_bEQN,m_bScalability); + enClose = GetBracketClose(pReader->GetLowerCaseString(),m_bEQN,m_bScalability); if(enOpen != TypeElement::undefine) { m_enRightBracket = enOpen; @@ -1585,8 +1632,8 @@ namespace StarMath return tSize; } //class methods CElementSpecialSymbol - CElementSpecialSymbol::CElementSpecialSymbol(const TypeElement &enType,const TypeConversion &enTypeConversion) - :CElement(TypeElement::SpecialSymbol,enTypeConversion),m_pValue(nullptr),m_enTypeSpecial(enType),m_wsType(L"") + CElementSpecialSymbol::CElementSpecialSymbol(const TypeElement &enType, const TypeConversion &enTypeConversion, const bool &bEQN) + :CElement(TypeElement::SpecialSymbol,enTypeConversion),m_pValue(nullptr),m_enTypeSpecial(enType),m_wsType(L""),m_bEQN(bEQN) { } CElementSpecialSymbol::~CElementSpecialSymbol() @@ -1623,125 +1670,514 @@ namespace StarMath { return m_enTypeSpecial; } - TypeElement CElementSpecialSymbol::GetSpecialSymbol(std::wstring &wsToken) + TypeElement CElementSpecialSymbol::GetSpecialSymbol(std::wstring &wsTokenLowerCase, std::wstring &wsTokenUpperCase, const bool &bEQN) { - if(wsToken[0] != L'%') + TypeElement enTypeSpecial = TypeElement::undefine; + std::wstring wsTempToken = wsTokenLowerCase,wsTempTokenUpper = wsTokenUpperCase; + bool bPercent(false); + if(wsTempToken[0] == L'%') { - if(L"#" == wsToken) return TypeElement::grid; - else if(L"" == wsToken) return TypeElement::emptySquare; - else if(L"" == wsToken) return TypeElement::emptySquare; - else if(L"mline" == wsToken) return TypeElement::mline; - else if(L"##" == wsToken) return TypeElement::transition; - else if(L"emptyset" == wsToken) return TypeElement::emptyset; - else if(L"aleph" == wsToken) return TypeElement::aleph; - else if(L"setn" == wsToken) return TypeElement::setN; - else if(L"setz" == wsToken) return TypeElement::setZ; - else if(L"setq" == wsToken) return TypeElement::setQ; - else if(L"setr" == wsToken) return TypeElement::setR; - else if(L"setc" == wsToken) return TypeElement::setC; - else if(L"infinity" == wsToken) return TypeElement::infinity; - else if(L"infty" == wsToken) return TypeElement::infinity; - else if(L"fact" == wsToken) return TypeElement::fact; - else if(L"abs" == wsToken) return TypeElement::abs; - else if(L"`" == wsToken) return TypeElement::interval; - else if(L"~" == wsToken) return TypeElement::emptiness; - else if(L"partial" == wsToken) return TypeElement::partial; - else if(L"nabla" == wsToken) return TypeElement::nabla; - else if(L"exists" == wsToken) return TypeElement::exists; - else if(L"notexists" == wsToken) return TypeElement::notexists; - else if(L"forall" == wsToken) return TypeElement::forall; - else if(L"hbar" == wsToken) return TypeElement::hbar; - else if(L"lambdabar" == wsToken) return TypeElement::lambdabar; - else if(L"re" == wsToken) return TypeElement::Re; - else if(L"im" == wsToken) return TypeElement::Im; - else if(L"wp" == wsToken) return TypeElement::wp; - else if(L"laplace" == wsToken) return TypeElement::laplace; - else if(L"fourier" == wsToken) return TypeElement::fourier; - else if(L"backepsilon" == wsToken) return TypeElement::backepsilon; - else if(L"leftarrow" == wsToken || L"<-" == wsToken) return TypeElement::leftarrow; - else if(L"rightarrow" == wsToken || L"->" == wsToken) return TypeElement::rightarrow; - else if(L"uparrow" == wsToken) return TypeElement::uparrow; - else if(L"downarrow" == wsToken) return TypeElement::downarrow; - else if(L"dotslow" == wsToken) return TypeElement::dotslow; - else if(L"dotsaxis" == wsToken) return TypeElement::dotsaxis; - else if(L"dotsvert" == wsToken) return TypeElement::dotsvert; - else if(L"dotsup" == wsToken) return TypeElement::dotsup; - else if(L"dotsdown" == wsToken) return TypeElement::dotsdown; - else if(L"newline" == wsToken) return TypeElement::newline; - else if(L"\\" == wsToken) return TypeElement::slash; + wsTempToken = wsTempToken.substr(1,wsTempToken.size()-1); + wsTempTokenUpper = wsTempTokenUpper.substr(1,wsTempTokenUpper.size()-1); + bPercent = true; } - else if(wsToken[0] == L'%') + if(bPercent || bEQN) { - wsToken = wsToken.substr(1,wsToken.size()-1); - if(L"ALPHA" == wsToken) return TypeElement::alpha; - else if(L"ZETA" == wsToken) return TypeElement::zeta; - else if(L"LAMBDA" == wsToken) return TypeElement::lambda; - else if(L"PI" == wsToken) return TypeElement::pi; - else if(L"PHI" == wsToken) return TypeElement::phi; - else if(L"alpha" == wsToken) return TypeElement::alpha_small; - else if(L"varepsilon" == wsToken) return TypeElement::varepsilon; - else if(L"iota" == wsToken) return TypeElement::iota_small; - else if(L"xi" == wsToken) return TypeElement::xi_small; - else if(L"varrho" == wsToken) return TypeElement::varrho; - else if(L"phi" == wsToken) return TypeElement::phi_small; - else if(L"BETA" == wsToken) return TypeElement::beta; - else if(L"ETA" == wsToken) return TypeElement::eta; - else if(L"MU" == wsToken) return TypeElement::mu; - else if(L"RHO" == wsToken) return TypeElement::rho; - else if(L"CHI" == wsToken) return TypeElement::chi; - else if(L"beta" == wsToken) return TypeElement::beta_small; - else if(L"zeta" == wsToken) return TypeElement::zeta_small; - else if(L"kappa" == wsToken) return TypeElement::kappa_small; - else if(L"omicron" == wsToken) return TypeElement::omicron_small; - else if(L"sigma" == wsToken) return TypeElement::sigma_small; - else if(L"varphi" == wsToken) return TypeElement::varphi; - else if(L"GAMMA" == wsToken) return TypeElement::gamma; - else if(L"THETA" == wsToken) return TypeElement::theta; - else if(L"NU" == wsToken) return TypeElement::nu; - else if(L"SIGMA" == wsToken) return TypeElement::sigma; - else if(L"PSI" == wsToken) return TypeElement::psi; - else if(L"gamma" == wsToken) return TypeElement::gamma_small; - else if(L"eta" == wsToken) return TypeElement::eta_small; - else if(L"lambda" == wsToken) return TypeElement::lambda_small; - else if(L"pi" == wsToken) return TypeElement::pi_small; - else if(L"varsigma" == wsToken) return TypeElement::varsigma; - else if(L"chi" == wsToken) return TypeElement::chi_small; - else if(L"DELTA" == wsToken) return TypeElement::delta; - else if(L"IOTA" == wsToken) return TypeElement::iota; - else if(L"XI" == wsToken) return TypeElement::xi; - else if(L"TAU" == wsToken) return TypeElement::tau; - else if(L"OMEGA" == wsToken) return TypeElement::omega; - else if(L"delta" == wsToken) return TypeElement::delta_small; - else if(L"theta" == wsToken) return TypeElement::theta_small; - else if(L"mu" == wsToken) return TypeElement::mu_small; - else if(L"varpi" == wsToken) return TypeElement::varpi; - else if(L"tau" == wsToken) return TypeElement::tau_small; - else if(L"psi" == wsToken) return TypeElement::psi_small; - else if(L"EPSILON" == wsToken) return TypeElement::epsilon; - else if(L"KAPPA" == wsToken) return TypeElement::kappa; - else if(L"OMICRON" == wsToken) return TypeElement::omicron; - else if(L"UPSILON" == wsToken) return TypeElement::upsilon; - else if(L"epsilon" == wsToken) return TypeElement::epsilon_small; - else if(L"vartheta" == wsToken) return TypeElement::vartheta; - else if(L"nu" == wsToken) return TypeElement::nu_small; - else if(L"rho" == wsToken) return TypeElement::rho_small; - else if(L"upsilon" == wsToken) return TypeElement::upsilon_small; - else if(L"omega" == wsToken) return TypeElement::omega_small; - else if(L"and" == wsToken) return TypeElement::And; - else if(L"infinite" == wsToken) return TypeElement::infinity; - else if(L"perthousand" == wsToken) return TypeElement::perthousand; - else if(L"angle" == wsToken) return TypeElement::notin; - else if(L"strictlygreaterthan" == wsToken) return TypeElement::dlriarrow; - else if(L"element" == wsToken) return TypeElement::in; - else if(L"notequal" == wsToken) return TypeElement::notequals; - else if(L"strictlylessthan" == wsToken) return TypeElement::dllearrow; - else if(L"identical" == wsToken) return TypeElement::equiv; - else if(L"or" == wsToken) return TypeElement::Or; - else if(L"tendto" == wsToken) return TypeElement::rightarrow; + enTypeSpecial = CElementSpecialSymbol::GetGreekSymbols(wsTempTokenUpper); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + enTypeSpecial = CElementSpecialSymbol::GetGreekSmallSymbols(wsTempToken); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + } + if(L"varepsilon" == wsTempToken) return TypeElement::varepsilon; + else if(L"varphi" == wsTempToken) return TypeElement::varphi; + else if(L"varsigma" == wsTempToken) return TypeElement::varsigma; + else if(L"varpi" == wsTempToken) return TypeElement::varpi; + else if(L"vartheta" == wsTempToken) return TypeElement::vartheta; + else if(L"aleph" == wsTempToken) return TypeElement::aleph; + else if(L"hbar" == wsTempToken) return TypeElement::hbar; + else if(L"wp" == wsTempToken) return TypeElement::wp; + else if(L"emptyset" == wsTempToken) return TypeElement::emptyset; + else if(L"partial" == wsTempToken) return TypeElement::partial; + else if(L"nabla" == wsTempToken) return TypeElement::nabla; + else if(L"laplace" == wsTempToken) return TypeElement::laplace; + else if(L"downarrow" == wsTempToken) return TypeElement::downarrow; + if(bEQN) + { + enTypeSpecial = CElementSpecialSymbol::GetArrowForEQN(wsTokenUpperCase); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + enTypeSpecial = CElementSetOperations::GetSetOperation(wsTempToken,bEQN); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + enTypeSpecial = CElementBinOperator::GetBinOperator(wsTempToken,bEQN); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + enTypeSpecial = CElementSpecialSymbol::GetMathOperatorForEQN(wsTempToken); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + enTypeSpecial = CElementSpecialSymbol::GetOtherMathOperatorForEQN(wsTempToken); + if(enTypeSpecial != TypeElement::undefine) + return enTypeSpecial; + if(L"imag" == wsTempToken) return TypeElement::Im; + else if(L"inf" == wsTempToken) return TypeElement::infinity; + else if(L"&" == wsTempToken) return TypeElement::grid; + else if(L"#" == wsTempToken) return TypeElement::transition; + else if(L"imath" == wsTempToken) return TypeElement::imath; + else if(L"jmath" == wsTempToken) return TypeElement::jmath; + else if(L"ohm" == wsTempToken) return TypeElement::ohm; + else if(L"liter" == wsTempToken) return TypeElement::liter; + else if(L"angstrom" == wsTempToken) return TypeElement::angstrom; + else if(L"varupsilon" == wsTempToken) return TypeElement::varupsilon; + else if(L"leq" == wsTempToken) return TypeElement::leq; + else if(L"geq" == wsTempToken) return TypeElement::geq; + else if(L"sqsubset" == wsTempToken) return TypeElement::sqsubset; + else if(L"sqsupset" == wsTempToken) return TypeElement::sqsupset; + else if(L"sqsubsetq" == wsTempToken) return TypeElement::sqsubsetq; + else if(L"sqsupsetq" == wsTempToken) return TypeElement::sqsupsetq; + else if(L">>" == wsTempToken) return TypeElement::dlriarrow; + else if(L"<<" == wsTempToken) return TypeElement::dllearrow; + else if(L"<<<" == wsTempToken) return TypeElement::triplearrow; + else if(L">>>" == wsTempToken) return TypeElement::tripriarrow; + else if(L"prec" == wsTempToken) return TypeElement::prec; + else if(L"succ" == wsTempToken) return TypeElement::succ; + else if(L"lor" == wsTempToken) return TypeElement::lor;//? + else if(L"wedge" == wsTempToken) return TypeElement::wedge;//? + else if(L"smallsum" == wsTempToken) return TypeElement::sum; + else if(L"smallprod" == wsTempToken) return TypeElement::prod; + else if(L"smcoprod" == wsTempToken) return TypeElement::coprod; + else if(L"smallinter" == wsTempToken) return TypeElement::smallinter; + else if(L"cup" == wsTempToken) return TypeElement::cup; + else if(L"sqcap" == wsTempToken) return TypeElement::sqcap; + else if(L"sqcup" == wsTempToken) return TypeElement::sqcup; + else if(L"uplus" == wsTempToken) return TypeElement::uplus; + else if(L"exist" == wsTempToken) return TypeElement::exists; + else if(L"cdots" == wsTempToken) return TypeElement::dotsaxis; + else if(L"ldots" == wsTempToken) return TypeElement::dotslow; + else if(L"vdots" == wsTempToken) return TypeElement::dotsvert; + else if(L"ddots" == wsTempToken) return TypeElement::dotsdown; + } + else + { + if(L"#" == wsTempToken) return TypeElement::grid; + else if(L"uparrow" == wsTempToken) return TypeElement::uparrow; + else if(L"varrho" == wsTempToken) return TypeElement::varrho; + else if(L"" == wsTempToken) return TypeElement::emptySquare; + else if(L"" == wsTempToken) return TypeElement::emptySquare; + else if(L"mline" == wsTempToken) return TypeElement::mline; + else if(L"##" == wsTempToken) return TypeElement::transition; + else if(L"setn" == wsTempToken) return TypeElement::setN; + else if(L"setz" == wsTempToken) return TypeElement::setZ; + else if(L"setq" == wsTempToken) return TypeElement::setQ; + else if(L"setr" == wsTempToken) return TypeElement::setR; + else if(L"setc" == wsTempToken) return TypeElement::setC; + else if(L"infinity" == wsTempToken) return TypeElement::infinity; + else if(L"infty" == wsTempToken) return TypeElement::infinity; + else if(L"fact" == wsTempToken) return TypeElement::fact; + else if(L"abs" == wsTempToken) return TypeElement::abs; + else if(L"`" == wsTempToken) return TypeElement::interval; + else if(L"~" == wsTempToken) return TypeElement::emptiness; + else if(L"exists" == wsTempToken) return TypeElement::exists; + else if(L"notexists" == wsTempToken) return TypeElement::notexists; + else if(L"forall" == wsTempToken) return TypeElement::forall; + else if(L"lambdabar" == wsTempToken) return TypeElement::lambdabar; + else if(L"re" == wsTempToken) return TypeElement::Re; + else if(L"im" == wsTempToken) return TypeElement::Im; + else if(L"fourier" == wsTempToken) return TypeElement::fourier; + else if(L"backepsilon" == wsTempToken) return TypeElement::backepsilon; + else if(L"leftarrow" == wsTempToken || L"<-" == wsTempToken) return TypeElement::leftarrow; + else if(L"rightarrow" == wsTempToken || L"->" == wsTempToken) return TypeElement::rightarrow; + else if(L"dotslow" == wsTempToken) return TypeElement::dotslow; + else if(L"dotsaxis" == wsTempToken) return TypeElement::dotsaxis; + else if(L"dotsvert" == wsTempToken) return TypeElement::dotsvert; + else if(L"dotsup" == wsTempToken) return TypeElement::dotsup; + else if(L"dotsdown" == wsTempToken) return TypeElement::dotsdown; + else if(L"newline" == wsTempToken) return TypeElement::newline; + else if(L"\\" == wsTempToken) return TypeElement::slash; + else if(L"and" == wsTempToken) return TypeElement::And; + else if(L"infinite" == wsTempToken) return TypeElement::infinity; + else if(L"perthousand" == wsTempToken) return TypeElement::perthousand; + else if(L"angle" == wsTempToken) return TypeElement::notin; + else if(L"strictlygreaterthan" == wsTempToken) return TypeElement::dlriarrow; + else if(L"element" == wsTempToken) return TypeElement::in; + else if(L"notequal" == wsTempToken) return TypeElement::notequals; + else if(L"strictlylessthan" == wsTempToken) return TypeElement::dllearrow; + else if(L"identical" == wsTempToken) return TypeElement::equiv; + // else if(L"or" == wsTempToken) return TypeElement::Or; + else if(L"tendto" == wsTempToken) return TypeElement::rightarrow; } return TypeElement::undefine; } + TypeElement CElementSpecialSymbol::GetGreekSymbols(std::wstring& wsToken) + { + if(L"ALPHA" == wsToken) return TypeElement::alpha; + else if(L"BETA" == wsToken) return TypeElement::beta; + else if(L"GAMMA" == wsToken) return TypeElement::gamma; + else if(L"DELTA" == wsToken) return TypeElement::delta; + else if(L"EPSILON" == wsToken) return TypeElement::epsilon; + else if(L"ZETA" == wsToken) return TypeElement::zeta; + else if(L"ETA" == wsToken) return TypeElement::eta; + else if(L"THETA" == wsToken) return TypeElement::theta; + else if(L"IOTA" == wsToken) return TypeElement::iota; + else if(L"KAPPA" == wsToken) return TypeElement::kappa; + else if(L"LAMBDA" == wsToken) return TypeElement::lambda; + else if(L"MU" == wsToken) return TypeElement::mu; + else if(L"NU" == wsToken) return TypeElement::nu; + else if(L"XI" == wsToken) return TypeElement::xi; + else if(L"OMICRON" == wsToken) return TypeElement::omicron; + else if(L"PI" == wsToken) return TypeElement::pi; + else if(L"RHO" == wsToken) return TypeElement::rho; + else if(L"SIGMA" == wsToken) return TypeElement::sigma; + else if(L"TAU" == wsToken) return TypeElement::tau; + else if(L"UPSILON" == wsToken) return TypeElement::upsilon; + else if(L"PHI" == wsToken) return TypeElement::phi; + else if(L"CHI" == wsToken) return TypeElement::chi; + else if(L"PSI" == wsToken) return TypeElement::psi; + else if(L"OMEGA" == wsToken) return TypeElement::omega; + else return TypeElement::undefine; + } + TypeElement CElementSpecialSymbol::GetGreekSmallSymbols(std::wstring& wsToken) + { + if(L"alpha" == wsToken) return TypeElement::alpha_small; + else if(L"beta" == wsToken) return TypeElement::beta_small; + else if(L"gamma" == wsToken) return TypeElement::gamma_small; + else if(L"delta" == wsToken) return TypeElement::delta_small; + else if(L"epsilon" == wsToken) return TypeElement::epsilon_small; + else if(L"zeta" == wsToken) return TypeElement::zeta_small; + else if(L"eta" == wsToken) return TypeElement::eta_small; + else if(L"theta" == wsToken) return TypeElement::theta_small; + else if(L"iota" == wsToken) return TypeElement::iota_small; + else if(L"kappa" == wsToken) return TypeElement::kappa_small; + else if(L"lambda" == wsToken) return TypeElement::lambda_small; + else if(L"mu" == wsToken) return TypeElement::mu_small; + else if(L"nu" == wsToken) return TypeElement::nu_small; + else if(L"xi" == wsToken) return TypeElement::xi_small; + else if(L"omicron" == wsToken) return TypeElement::omicron_small; + else if(L"pi" == wsToken) return TypeElement::pi_small; + else if(L"rho" == wsToken) return TypeElement::rho_small; + else if(L"sigma" == wsToken) return TypeElement::sigma_small; + else if(L"tau" == wsToken) return TypeElement::tau_small; + else if(L"upsilon" == wsToken) return TypeElement::upsilon_small; + else if(L"phi" == wsToken) return TypeElement::phi_small; + else if(L"chi" == wsToken) return TypeElement::chi_small; + else if(L"psi" == wsToken) return TypeElement::psi_small; + else if(L"omega" == wsToken) return TypeElement::omega_small; + else return TypeElement::undefine; + } + TypeElement CElementSpecialSymbol::GetArrowForEQN(std::wstring& wsToken) + { + if(wsToken == L"LRARROW") return TypeElement::Lrarrow; + else if(wsToken == L"lrarrow") return TypeElement::lrarrow; + else if(wsToken == L"RARROW") return TypeElement::Rarrow; + else if(wsToken == L"rarrow") return TypeElement::rarrow; + else if(wsToken == L"->") return TypeElement::rarrow; + else if(wsToken == L"LARROW") return TypeElement::Larrow; + else if(wsToken == L"larrow") return TypeElement::larrow; + else if(wsToken == L"exarrow") return TypeElement::exarrow; + else if(wsToken == L"EXARROW") return TypeElement::exarrow; + else if(wsToken == L"UPARROW") return TypeElement::UPARROW; + else if(wsToken == L"uparrow") return TypeElement::uparrow; + else if(wsToken == L"DOWNARROW") return TypeElement::DOWNARROW; + else if(wsToken == L"udarrow") return TypeElement::udarrow; + else if(wsToken == L"UDARROW") return TypeElement::UDARROW; + else if(wsToken == L"NWARROW") return TypeElement::NWARROW; + else if(wsToken == L"SEARROW") return TypeElement::SEARROW; + else if(wsToken == L"NEARROW") return TypeElement::NEARROW; + else if(wsToken == L"SWARROW") return TypeElement::SWARROW; + else if(wsToken == L"HOOKLEFT") return TypeElement::HOOKLEFT; + else if(wsToken == L"HOOKRIGHT") return TypeElement::HOOKRIGHT; + else if(wsToken == L"MAPSTO") return TypeElement::MAPSTO; + else if(wsToken == L"vert") return TypeElement::mline; + else if(wsToken == L"DLINE") return TypeElement::DLINE; + else return TypeElement::undefine; + } + TypeElement CElementSpecialSymbol::GetMathOperatorForEQN(std::wstring& wsToken) + { + if(L"bullet" == wsToken) return TypeElement::bullet; + else if(L"deg" == wsToken) return TypeElement::deg; + else if(L"ast" == wsToken) return TypeElement::ast; + else if(L"star" == wsToken) return TypeElement::star; + else if(L"bigcirc" == wsToken) return TypeElement::bigcirc; + else if(L"therefore" == wsToken) return TypeElement::therefore; + else if(L"because" == wsToken) return TypeElement::because; + else if(L"identical" == wsToken) return TypeElement::identical; + else if(L"!=" == wsToken) return TypeElement::notequals;//? + else if(L"doteq" == wsToken) return TypeElement::emptyset; + else if(L"image" == wsToken) return TypeElement::image; + else if(L"reimage" == wsToken) return TypeElement::reimage; + else if(L"sim" == wsToken) return TypeElement::sim; + else if(L"approx" == wsToken) return TypeElement::approx; + else if(L"simeq" == wsToken) return TypeElement::simeq; + else if(L"cong" == wsToken) return TypeElement::cong; + else if(L"equiv" == wsToken) return TypeElement::equiv; + else if(L"==" == wsToken) return TypeElement::equals; + else if(L"asymp" == wsToken) return TypeElement::asymp; + else if(L"iso" == wsToken) return TypeElement::iso; + else if(L"diamond" == wsToken) return TypeElement::diamond; + else if(L"dsum" == wsToken) return TypeElement::dsum; + else if(L"forall" == wsToken) return TypeElement::forall; + else if(L"prime" == wsToken) return TypeElement::prime; + else if(L"inf" == wsToken) return TypeElement::infinity; + else if(L"lnot" == wsToken) return TypeElement::lnot; + else if(L"propto" == wsToken) return TypeElement::propto; + else if(L"xor" == wsToken) return TypeElement::Xor; + else if(L"dagger" == wsToken) return TypeElement::dagger; + else if(L"ddagger" == wsToken) return TypeElement::ddagger; + return TypeElement::undefine; + } + TypeElement CElementSpecialSymbol::GetOtherMathOperatorForEQN(std::wstring& wsToken) + { + if(L"triangle" == wsToken) return TypeElement::triangle; + else if(L"angle" == wsToken) return TypeElement::angle; + else if(L"msangle" == wsToken) return TypeElement::msangle; + else if(L"sangle" == wsToken) return TypeElement::sangle; + else if(L"rtangle" == wsToken) return TypeElement::rtangle; + else if(L"vdash" == wsToken) return TypeElement::vdash; + else if(L"dashv" == wsToken) return TypeElement::dashv; + else if(L"bot" == wsToken) return TypeElement::bot; + else if(L"top" == wsToken) return TypeElement::top; + else if(L"models" == wsToken) return TypeElement::models; + else if(L"centigrade" == wsToken) return TypeElement::centigrade; + else if(L"fahrenheit" == wsToken) return TypeElement::fahrenheit; + else if(L"lslant" == wsToken) return TypeElement::lslant; + else if(L"rslant" == wsToken) return TypeElement::rslant; + else if(L"att" == wsToken) return TypeElement::att; + else if(L"hund" == wsToken) return TypeElement::hund; + else if(L"thou" == wsToken) return TypeElement::thou; + else if(L"well" == wsToken) return TypeElement::well; + else if(L"base" == wsToken) return TypeElement::base; + else if(L"benzene" == wsToken) return TypeElement::benzene; + return TypeElement::undefine; + } + void CElementSpecialSymbol::WritingMathOperatorForEQN(std::wstring& wsToken) + { + switch (m_enTypeSpecial) { + case TypeElement::bullet: + wsToken = L"\u2219"; + break; + case TypeElement::deg: + wsToken = L"\u00B0"; + break; + case TypeElement::ast: + wsToken = L"\u2217"; + break; + case TypeElement::star: + wsToken = L"\u22C6"; + break; + case TypeElement::bigcirc: + wsToken = L"\u25CB"; + break; + case TypeElement::therefore: + wsToken = L"\u2234"; + break; + case TypeElement::because: + wsToken = L"\u2235"; + break; + case TypeElement::identical: + wsToken = L"\u2237"; + break; + case TypeElement::notequals: + wsToken = L"\u2260"; + break; + case TypeElement::doteq: + wsToken = L"\u2250"; + break; + case TypeElement::image: + wsToken = L"\u2252"; + break; + case TypeElement::reimage: + wsToken = L"\u2253"; + break; + case TypeElement::sim: + wsToken = L"\u223C"; + break; + case TypeElement::approx: + wsToken = L"\u2248"; + break; + case TypeElement::simeq: + wsToken = L"\u2243"; + break; + case TypeElement::cong: + wsToken = L"\u2245"; + break; + case TypeElement::equals: + wsToken = L"\u2261"; + break; + case TypeElement::asymp: + wsToken = L"\u224D"; + break; + case TypeElement::iso: + wsToken = L"\u224E"; + break; + case TypeElement::diamond: + wsToken = L"\u22C4"; + break; + case TypeElement::dsum: + wsToken = L"\u2214"; + break; + case TypeElement::forall: + wsToken = L"\u2200"; + break; + case TypeElement::prime://? + wsToken = L"\u00B4"; + break; + case TypeElement::lnot: + wsToken = L"\u00AC"; + break; + case TypeElement::propto: + wsToken = L"\u221D"; + break; + case TypeElement::Xor: + wsToken = L"\u22BB"; + break; + case TypeElement::dagger: + wsToken = L"\u2020"; + break; + case TypeElement::ddagger://? + wsToken = L"\u2E38"; + break; + default: + wsToken = L""; + break; + } + } + void CElementSpecialSymbol::WritingOtherMathOpForEQN(std::wstring& wsToken) + { + switch (m_enTypeSpecial) { + case TypeElement::triangle: + wsToken = L"\u25B3"; + break; + case TypeElement::angle: + wsToken = L"\u2220"; + break; + case TypeElement::msangle: + wsToken = L"\u2221"; + break; + case TypeElement::sangle: + wsToken = L"\u2222"; + break; + case TypeElement::rtangle: + wsToken = L"\u22BE"; + break; + case TypeElement::vdash: + wsToken = L"\u22A2"; + break; + case TypeElement::dashv: + wsToken = L"\u22A3"; + break; + case TypeElement::bot: + wsToken = L"\u22A5"; + break; + case TypeElement::top: + wsToken = L"\u22A4"; + break; + case TypeElement::models: + wsToken = L"\u22A8"; + break; + case TypeElement::centigrade: + wsToken = L"\u2103"; + break; + case TypeElement::fahrenheit: + wsToken = L"\u2109"; + break; + case TypeElement::lslant: + wsToken = L"\u002F"; + break; + case TypeElement::rslant: + wsToken = L"\u005C"; + break; + case TypeElement::att: + wsToken = L"\u22C7"; + break; + case TypeElement::hund: + wsToken = L"\u2030"; + break; + case TypeElement::thou: + wsToken = L"\u2031"; + break; + case TypeElement::well: + wsToken = L"\u2317"; + break; + case TypeElement::base: + wsToken = L"\u2302"; + break; + case TypeElement::benzene: + wsToken = L"\u232C"; + break; + default: + wsToken = L""; + break; + } + } + void CElementSpecialSymbol::WritingArrowForEQN(std::wstring& wsToken) + { + switch (m_enTypeSpecial) { + case TypeElement::larrow: + wsToken = L"\u2190"; + break; + case TypeElement::rarrow: + wsToken = L"\u2192"; + break; + case TypeElement::Larrow: + wsToken = L"\u21D0"; + break; + case TypeElement::Rarrow: + wsToken = L"\u21D2"; + break; + case TypeElement::UPARROW: + wsToken = L"\u21D1"; + break; + case TypeElement::DOWNARROW: + wsToken = L"\u21D3"; + break; + case TypeElement::udarrow: + wsToken = L"\u2195"; + break; + case TypeElement::lrarrow: + wsToken = L"\u21D4"; + break; + case TypeElement::UDARROW: + wsToken = L"\u21D5"; + break; + case TypeElement::Lrarrow: + wsToken = L"\u21D4"; + break; + case TypeElement::NWARROW: + wsToken = L"\u2196"; + break; + case TypeElement::SEARROW: + wsToken = L"\u2198"; + break; + case TypeElement::NEARROW: + wsToken = L"\u2197"; + break; + case TypeElement::SWARROW: + wsToken = L"\u2199"; + break; + case TypeElement::HOOKLEFT: + wsToken = L"\u21A9"; + break; + case TypeElement::HOOKRIGHT: + wsToken = L"\u21AA"; + break; + case TypeElement::MAPSTO: + wsToken = L"\u21A6"; + break; + case TypeElement::DLINE: + wsToken = L"\u2016"; + break; + case TypeElement::mline: + wsToken = L"\u007C"; + break; + case TypeElement::exarrow: + wsToken = L"\u21C4"; + break; + default: + break; + } + } void CElementSpecialSymbol::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { SetTypeSymbol(); @@ -1791,8 +2227,7 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:r",false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); pXmlWrite->WriteNodeBegin(L"m:t",false); -// pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsType)); - pXmlWrite->WriteString(m_wsType); + pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsType)); pXmlWrite->WriteNodeEnd(L"m:t",false,false); pXmlWrite->WriteNodeEnd(L"m:r",false,false); } @@ -1806,6 +2241,137 @@ namespace StarMath } void CElementSpecialSymbol::SetTypeSymbol() { + if(m_bEQN) + { + CElementSetOperations::WritingSetOperationSymbol(m_wsType,m_enTypeSpecial); + if(!m_wsType.empty()) + return; + WritingMathOperatorForEQN(m_wsType); + if(!m_wsType.empty()) + return; + WritingOtherMathOpForEQN(m_wsType); + if(!m_wsType.empty()) + return; + WritingArrowForEQN(m_wsType); + if(!m_wsType.empty()) + return; + switch (m_enTypeSpecial) + { + case TypeElement::imath://? + m_wsType = L"\u0069"; + break; + case TypeElement::jmath://? + m_wsType = L"\u006A"; + break; + case TypeElement::ohm: + m_wsType = L"\u2126"; + break; + case TypeElement::liter: + m_wsType = L"\u2113"; + break; + case TypeElement::angstrom: + m_wsType = L"\u212B"; + break; + case TypeElement::varupsilon://? + m_wsType = L"\u03A5"; + break; + case TypeElement::leq: + m_wsType = L"\u2264"; + break; + case TypeElement::geq: + m_wsType = L"\u2265"; + break; + case TypeElement::sqsubset: + m_wsType = L"\u228F"; + break; + case TypeElement::sqsupset: + m_wsType = L"\u2290"; + break; + case TypeElement::sqsubsetq: + m_wsType = L"\u2291"; + break; + case TypeElement::sqsupsetq: + m_wsType = L"\u2292"; + break; + case TypeElement::dllearrow: + m_wsType = L"\u226A"; + break; + case TypeElement::dlriarrow: + m_wsType = L"\u226B"; + break; + case TypeElement::triplearrow: + m_wsType = L"\u22D8"; + break; + case TypeElement::tripriarrow: + m_wsType = L"\u22D9"; + break; + case TypeElement::prec: + m_wsType = L"\u227A"; + break; + case TypeElement::sum: + m_wsType = L"\u2211"; + break; + case TypeElement::prod: + m_wsType = L"\u220F"; + break; + case TypeElement::coprod: + m_wsType = L"\u2210"; + break; + case TypeElement::smallinter: + m_wsType = L"\u22C2"; + break; + case TypeElement::cup: + m_wsType = L"\u22C3"; + break; + case TypeElement::sqcap: + m_wsType = L"\u2293"; + break; + case TypeElement::sqcup: + m_wsType = L"\u2294"; + break; + case TypeElement::uplus: + m_wsType = L"\u228E"; + break; + case TypeElement::bigsqcap: + m_wsType = L"\u2293"; + break; + case TypeElement::bigsqcup: + m_wsType = L"\u2294"; + break; + case TypeElement::bigoplus: + m_wsType = L"\u2295"; + break; + case TypeElement::bigominus: + m_wsType = L"\u2296"; + break; + case TypeElement::bigotimes: + m_wsType = L"\u2297"; + break; + case TypeElement::bigodiv: + m_wsType = L"\u2298"; + break; + case TypeElement::bigodot: + m_wsType = L"\u2299"; + break; + case TypeElement::biguplus: + m_wsType = L"\u228E"; + break; + case TypeElement::lor: + m_wsType = L"\u2228"; + break; + case TypeElement::succ: + m_wsType = L"\u227B"; + break; + case TypeElement::plus_minus: + m_wsType = L"\u00B1"; + break; + default: + m_wsType = L""; + break; + } + if(!m_wsType.empty()) + return; + } switch(m_enTypeSpecial) { case TypeElement::infinity: @@ -2094,6 +2660,7 @@ namespace StarMath m_wsType = L"\u2751"; break; default: + m_wsType = L""; break; } } @@ -2165,82 +2732,96 @@ namespace StarMath {} void CElementSetOperations::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { + std::wstring wsTempSymbolSetOp; CConversionSMtoOOXML::ElementConversion(pXmlWrite,m_pLeftArgument); pXmlWrite->WriteNodeBegin(L"m:r", false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); pXmlWrite->WriteNodeBegin(L"m:t",false); - switch(m_enTypeSet) - { - case TypeElement::Union: - pXmlWrite->WriteString(L"\u22C3"); - break; - case TypeElement::intersection: - pXmlWrite->WriteString(L"\u22C2"); - break; - case TypeElement::setminus: - pXmlWrite->WriteString(L"\u2216"); - break; - case TypeElement::setquotient: - pXmlWrite->WriteString(L"\u2215"); - break; - case TypeElement::subset: - pXmlWrite->WriteString(L"\u2282"); - break; - case TypeElement::subseteq: - pXmlWrite->WriteString(L"\u2286"); - break; - case TypeElement::supset: - pXmlWrite->WriteString(L"\u2283"); - break; - case TypeElement::supseteq: - pXmlWrite->WriteString(L"\u2287"); - break; - case TypeElement::nsubset: - pXmlWrite->WriteString(L"\u2284"); - break; - case TypeElement::nsubseteq: - pXmlWrite->WriteString(L"\u2288"); - break; - case TypeElement::nsupset: - pXmlWrite->WriteString(L"\u2285"); - break; - case TypeElement::nsupseteq: - pXmlWrite->WriteString(L"\u2289"); - break; - case TypeElement::in: - pXmlWrite->WriteString(L"\u2208"); - break; - case TypeElement::owns: - pXmlWrite->WriteString(L"\u220B"); - break; - case TypeElement::notin: - pXmlWrite->WriteString(L"\u2209"); - break; - default: - break; - } + CElementSetOperations::WritingSetOperationSymbol(wsTempSymbolSetOp,m_enTypeSet); + pXmlWrite->WriteString(wsTempSymbolSetOp); pXmlWrite->WriteNodeEnd(L"m:t",false,false); pXmlWrite->WriteNodeEnd(L"m:r",false,false); CConversionSMtoOOXML::ElementConversion(pXmlWrite,m_pRightArgument); } - TypeElement CElementSetOperations::GetSetOperation(const std::wstring &wsToken) + void CElementSetOperations::WritingSetOperationSymbol(std::wstring& wsSymbol, const TypeElement &enTypeSetOperation) { - if(L"intersection" == wsToken) return TypeElement::intersection; - else if(L"union" == wsToken) return TypeElement::Union; - else if(L"setminus" == wsToken) return TypeElement::setminus; - else if(L"setquotient" == wsToken) return TypeElement::setquotient; + switch(enTypeSetOperation) + { + case TypeElement::Union: + wsSymbol = L"\u22C3"; + break; + case TypeElement::intersection: + wsSymbol = L"\u22C2"; + break; + case TypeElement::setminus: + wsSymbol = L"\u2216"; + break; + case TypeElement::setquotient: + wsSymbol = L"\u2215"; + break; + case TypeElement::subset: + wsSymbol = L"\u2282"; + break; + case TypeElement::subseteq: + wsSymbol = L"\u2286"; + break; + case TypeElement::supset: + wsSymbol = L"\u2283"; + break; + case TypeElement::supseteq: + wsSymbol = L"\u2287"; + break; + case TypeElement::nsubset: + wsSymbol = L"\u2284"; + break; + case TypeElement::nsubseteq: + wsSymbol = L"\u2288"; + break; + case TypeElement::nsupset: + wsSymbol = L"\u2285"; + break; + case TypeElement::nsupseteq: + wsSymbol = L"\u2289"; + break; + case TypeElement::in: + wsSymbol = L"\u2208"; + break; + case TypeElement::owns: + wsSymbol = L"\u220B"; + break; + case TypeElement::notin: + wsSymbol = L"\u2209"; + break; + default: + wsSymbol = L""; + break; + } + } + TypeElement CElementSetOperations::GetSetOperation(const std::wstring &wsToken, const bool &bEQN) + { + if(L"subset" == wsToken) return TypeElement::subset; else if(L"subseteq" == wsToken) return TypeElement::subseteq; - else if(L"subset" == wsToken) return TypeElement::subset; - else if(L"supset" == wsToken) return TypeElement::supset; else if(L"supseteq" == wsToken) return TypeElement::supseteq; - else if(L"nsubset" == wsToken) return TypeElement::nsubset; - else if(L"nsubseteq" == wsToken) return TypeElement::nsubseteq; - else if(L"nsupset" == wsToken) return TypeElement::nsupset; - else if(L"nsupseteq" == wsToken) return TypeElement::nsupseteq; else if(L"in" == wsToken) return TypeElement::in; - else if(L"notin" == wsToken) return TypeElement::notin; else if(L"owns" == wsToken) return TypeElement::owns; - else return TypeElement::undefine; + else if(L"notin" == wsToken) return TypeElement::notin; + if(bEQN) + { + if(L"superset" == wsToken) return TypeElement::supset; + } + else + { + if(L"intersection" == wsToken) return TypeElement::intersection; + else if(L"union" == wsToken) return TypeElement::Union; + else if(L"setminus" == wsToken) return TypeElement::setminus; + else if(L"setquotient" == wsToken) return TypeElement::setquotient; + else if(L"supset" == wsToken) return TypeElement::supset; + else if(L"nsubset" == wsToken) return TypeElement::nsubset; + else if(L"nsubseteq" == wsToken) return TypeElement::nsubseteq; + else if(L"nsupset" == wsToken) return TypeElement::nsupset; + else if(L"nsupseteq" == wsToken) return TypeElement::nsupseteq; + } + return TypeElement::undefine; } void CElementSetOperations::SetAttribute(CAttribute *pAttribute) { @@ -2482,7 +3063,7 @@ namespace StarMath } //class methods CIndex CElementIndex::CElementIndex(const TypeElement& enType,const TypeConversion &enTypeConversion) - : CElement(TypeElement::Index,enTypeConversion),m_pValueIndex(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_pLsubIndex(nullptr),m_pLsupIndex(nullptr),m_pCsubIndex(nullptr),m_pCsupIndex(nullptr),m_pLeftArg(nullptr),m_enTypeIndex(enType),m_enTempTypeIndex(TypeElement::undefine),m_bEQN(false) + : CElement((enType == TypeElement::rel || enType == TypeElement::buildrel || enType == TypeElement::bigsqcap || enType == TypeElement::bigsqcup || enType == TypeElement::bigoplus || enType == TypeElement::bigominus || enType == TypeElement::bigotimes || enType == TypeElement::bigodiv || enType == TypeElement::bigodot || enType == TypeElement::biguplus ? TypeElement::IndexOp:TypeElement::Index),enTypeConversion),m_pValueIndex(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_pLsubIndex(nullptr),m_pLsupIndex(nullptr),m_pCsubIndex(nullptr),m_pCsupIndex(nullptr),m_pLeftArg(nullptr),m_enTypeIndex(enType),m_enTempTypeIndex(TypeElement::undefine),m_bEQN(false) { } CElementIndex::~CElementIndex() @@ -2535,6 +3116,21 @@ namespace StarMath } return TypeElement::undefine; } + TypeElement CElementIndex::GetIndexOp(const std::wstring& wsCheckToken) + { + if(L"rel" == wsCheckToken) return TypeElement::rel; + else if(L"buildrel" == wsCheckToken) return TypeElement::buildrel; + else if(L"bigsqcap" == wsCheckToken) return TypeElement::bigsqcap; + else if(L"bigsqcup" == wsCheckToken) return TypeElement::bigsqcup; + else if(L"bigoplus" == wsCheckToken) return TypeElement::bigoplus; + else if(L"bigominus" == wsCheckToken) return TypeElement::bigominus; + else if(L"bigotimes" == wsCheckToken) return TypeElement::bigotimes; + else if(L"bigodiv" == wsCheckToken) return TypeElement::bigodiv; + else if(L"bigodot" == wsCheckToken) return TypeElement::bigodot; + else if(L"biguplus" == wsCheckToken) return TypeElement::biguplus; + else if(L"lim" == wsCheckToken) return TypeElement::lim; + return TypeElement::undefine; + } bool CElementIndex::GetUpperIndex(const TypeElement &enType) { switch(enType) @@ -2563,11 +3159,18 @@ namespace StarMath { if(m_enTypeIndex == TypeElement::nroot) { - m_pLeftArg = CParserStarMathString::ParseElement(pReader); + if(m_bEQN) + m_pLeftArg = CParserStarMathString::ParseElementEQN(pReader); + else + m_pLeftArg = CParserStarMathString::ParseElement(pReader); pReader->ReadingTheNextToken(m_bEQN); if(CElementIndex::GetLowerIndex(pReader->GetLocalType()) || CElementIndex::GetUpperIndex(pReader->GetLocalType())) { - CElement* pElement = CParserStarMathString::ParseElement(pReader); + CElement* pElement; + if(m_bEQN) + pElement = CParserStarMathString::ParseElementEQN(pReader); + else + pElement = CParserStarMathString::ParseElement(pReader); CParserStarMathString::AddLeftArgument(m_pLeftArg,pElement,pReader); m_pLeftArg = pElement; } @@ -2584,22 +3187,36 @@ namespace StarMath return; } } - m_pValueIndex = CParserStarMathString::ParseElement(pReader); + if(m_bEQN) + m_pValueIndex = CParserStarMathString::ParseElementEQN(pReader); + else + m_pValueIndex = CParserStarMathString::ParseElement(pReader); pReader->ReadingTheNextToken(m_bEQN); if(CElementIndex::GetLowerIndex(pReader->GetLocalType()) || CElementIndex::GetUpperIndex(pReader->GetLocalType())) { - CElement* pElement = CParserStarMathString::ParseElement(pReader); + CElement* pElement; + if(m_bEQN) + pElement = CParserStarMathString::ParseElementEQN(pReader); + else + pElement = CParserStarMathString::ParseElement(pReader); CParserStarMathString::AddLeftArgument(m_pValueIndex,pElement,pReader); m_pValueIndex = pElement; } } else if(m_enTypeIndex == TypeElement::sqrt) { - m_pValueIndex = CParserStarMathString::ParseElement(pReader); + if(m_bEQN) + m_pValueIndex = CParserStarMathString::ParseElementEQN(pReader); + else + m_pValueIndex = CParserStarMathString::ParseElement(pReader); pReader->ReadingTheNextToken(m_bEQN); if(CElementIndex::GetLowerIndex(pReader->GetLocalType()) || CElementIndex::GetUpperIndex(pReader->GetLocalType())) { - CElement* pElement = CParserStarMathString::ParseElement(pReader); + CElement* pElement; + if(m_bEQN) + pElement = CParserStarMathString::ParseElementEQN(pReader); + else + pElement = CParserStarMathString::ParseElement(pReader); CParserStarMathString::AddLeftArgument(m_pValueIndex,pElement,pReader); m_pValueIndex = pElement; } @@ -2634,7 +3251,7 @@ namespace StarMath CParserStarMathString::ReadingElementsWithAttributes(pReader,m_pCsupIndex,m_bEQN); break; } - pReader->ReadingTheNextToken(); + pReader->ReadingTheNextToken(m_bEQN); m_enTempTypeIndex = m_enTypeIndex; m_enTypeIndex = pReader->GetLocalType(); }while(GetUpperIndex(pReader->GetLocalType()) || GetLowerIndex(pReader->GetLocalType())); @@ -2643,23 +3260,116 @@ namespace StarMath void CElementIndex::ParseEQN(CStarMathReader *pReader) { m_bEQN = true; - if(m_enTypeIndex != TypeElement::underover) + if(m_enTypeIndex == TypeElement::rel || m_enTypeIndex == TypeElement::buildrel ||m_enTypeIndex == TypeElement::bigsqcap ||m_enTypeIndex == TypeElement::bigsqcup ||m_enTypeIndex == TypeElement::bigoplus ||m_enTypeIndex == TypeElement::bigominus ||m_enTypeIndex == TypeElement::bigotimes ||m_enTypeIndex == TypeElement::bigodiv ||m_enTypeIndex == TypeElement::bigodot ||m_enTypeIndex == TypeElement::biguplus || m_enTypeIndex == TypeElement::Lim || m_enTypeIndex == TypeElement::lim) + { + TypeElement enTempType; + switch (m_enTypeIndex) { + case TypeElement::rel: + case TypeElement::buildrel: + { + pReader->ReadingTheNextToken(m_bEQN); + std::wstring wsString = pReader->GetOriginalString(); + enTempType = CElementSpecialSymbol::GetArrowForEQN(wsString); + break; + } + default: + enTempType = m_enTypeIndex; + break; + } + if(enTempType != TypeElement::undefine) + { + pReader->ClearReader(); + switch (m_enTypeIndex) + { + case TypeElement::Lim: + { + m_pLeftArg = new CElementString(L"Lim",pReader->GetTypeConversion()); + break; + } + case TypeElement::lim: + { + m_pLeftArg = new CElementString(L"lim",pReader->GetTypeConversion()); + break; + } + default: + { + m_pLeftArg = new CElementSpecialSymbol(enTempType,pReader->GetTypeConversion(),m_bEQN); + break; + } + } + if(m_enTypeIndex == TypeElement::rel || m_enTypeIndex == TypeElement::buildrel) + { + m_pCsupIndex = CParserStarMathString::ReadingWithoutBracket(pReader,true,m_bEQN); + if(m_enTypeIndex != TypeElement::buildrel) + m_pCsubIndex = CParserStarMathString::ReadingWithoutBracket(pReader,true,m_bEQN); + } + else + { + Parse(pReader); + if(m_pUpperIndex != nullptr) + { + m_pCsupIndex = m_pUpperIndex; + m_pUpperIndex = nullptr; + } + if(m_pLowerIndex != nullptr) + { + m_pCsubIndex = m_pLowerIndex; + m_pLowerIndex = nullptr; + } + } + } + else return; + } + else if(m_enTypeIndex != TypeElement::underover) Parse(pReader); else { m_pLeftArg = CParserStarMathString::ParseElementEQN(pReader); Parse(pReader); + if(m_pUpperIndex != nullptr) + { + m_pCsupIndex = m_pUpperIndex; + m_pUpperIndex = nullptr; + } + if(m_pLowerIndex != nullptr) + { + m_pCsubIndex = m_pLowerIndex; + m_pLowerIndex = nullptr; + } m_enTypeIndex = TypeElement::underover; } } void CElementIndex::ParseIndex(CStarMathReader *pReader, CElement *&pElement) { - if(m_bEQN && (m_enTempTypeIndex == m_enTypeIndex ) && pElement != nullptr) + if(m_bEQN && /*(m_enTempTypeIndex == m_enTypeIndex ) &&*/ pElement != nullptr) { - CElement* pTempElement = new CElementIndex(m_enTempTypeIndex,GetTypeConversion()); + CElement* pTempElement = new CElementIndex(m_enTypeIndex,GetTypeConversion()); pTempElement->ParseEQN(pReader); - CParserStarMathString::AddLeftArgument(pElement,pTempElement,pReader); - pElement = pTempElement; + if(m_enTempTypeIndex == TypeElement::upper) + { + CParserStarMathString::AddLeftArgument(m_pUpperIndex,pTempElement,pReader); + m_pUpperIndex = pTempElement; + } + else if(m_enTempTypeIndex == TypeElement::lower) + { + CParserStarMathString::AddLeftArgument(m_pLowerIndex,pTempElement,pReader); + m_pLowerIndex = pTempElement; + } + else if(m_enTempTypeIndex == TypeElement::lsub) + { + CParserStarMathString::AddLeftArgument(m_pLsubIndex,pTempElement,pReader); + m_pLsubIndex = pTempElement; + } + else if(m_enTempTypeIndex == TypeElement::lsup) + { + CParserStarMathString::AddLeftArgument(m_pLsupIndex,pTempElement,pReader); + m_pLsupIndex = pTempElement; + } + else + { + CParserStarMathString::AddLeftArgument(pElement,pTempElement,pReader); + pElement = pTempElement; + } } else CParserStarMathString::ReadingElementsWithAttributes(pReader,pElement,m_bEQN); @@ -3039,7 +3749,7 @@ namespace StarMath } //class methods CElementOperation CElementOperator::CElementOperator(const TypeElement &enType, const TypeConversion &enTypeConversion,const std::wstring& wsNameOp) - :CElement(TypeElement::Operator,enTypeConversion), m_pValueFrom(nullptr), m_pValueTo(nullptr), m_pValueOperator(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_enTypeOperator(enType),m_wsName(wsNameOp) + :CElement(TypeElement::Operator,enTypeConversion), m_pValueFrom(nullptr), m_pValueTo(nullptr), m_pValueOperator(nullptr),m_pUpperIndex(nullptr),m_pLowerIndex(nullptr),m_enTypeOperator(enType),m_wsName(wsNameOp),m_bEQN(false) { } CElementOperator::~CElementOperator() @@ -3094,7 +3804,15 @@ namespace StarMath else if(L"prod" == wsToken) return TypeElement::prod; else if(L"coprod" == wsToken) return TypeElement::coprod; else if(L"int" == wsToken) return TypeElement::Int; - if(!bEQN) + if(bEQN) + { + if(L"dint" == wsToken) return TypeElement::iint; + else if(L"tint" == wsToken) return TypeElement::iiint; + else if(L"oint" == wsToken) return TypeElement::lint; + else if(L"odint" == wsToken) return TypeElement::llint; + else if(L"otint" == wsToken) return TypeElement::lllint; + } + else { if(L"lim" == wsToken) return TypeElement::lim; else if(L"liminf" == wsToken) return TypeElement::liminf; @@ -3113,18 +3831,18 @@ namespace StarMath TypeElement enType = CElementOperator::GetOperator(wsToken,true); if(enType != TypeElement::undefine) return enType; - if(L"bigsqcap" == wsToken) return TypeElement::bigsqcap; - else if(L"bigsqcup" == wsToken) return TypeElement::bigsqcup; - else if(L"inter" == wsToken) return TypeElement::inter; + // if(L"bigsqcap" == wsToken) return TypeElement::bigsqcap; + // else if(L"bigsqcup" == wsToken) return TypeElement::bigsqcup; + if(L"inter" == wsToken) return TypeElement::inter; else if(L"union" == wsToken) return TypeElement::UnionOp; - else if(L"bigoplus" == wsToken) return TypeElement::bigoplus; - else if(L"bigominus" == wsToken) return TypeElement::bigominus; - else if(L"bigotimes" == wsToken) return TypeElement::bigotimes; - else if(L"bigodiv" == wsToken) return TypeElement::bigodiv; - else if(L"bigodot" == wsToken) return TypeElement::bigodot; + // else if(L"bigoplus" == wsToken) return TypeElement::bigoplus; + // else if(L"bigominus" == wsToken) return TypeElement::bigominus; + // else if(L"bigotimes" == wsToken) return TypeElement::bigotimes; + // else if(L"bigodiv" == wsToken) return TypeElement::bigodiv; + // else if(L"bigodot" == wsToken) return TypeElement::bigodot; else if(L"bigvee" == wsToken) return TypeElement::bigvee; else if(L"bigwedge" == wsToken) return TypeElement::bigwedge; - else if(L"biguplus" == wsToken) return TypeElement::biguplus; + // else if(L"biguplus" == wsToken) return TypeElement::biguplus; else if(L"dint" == wsToken) return TypeElement::iint; else if(L"tint" == wsToken) return TypeElement::iiint; else if(L"oint" == wsToken) return TypeElement::lint; @@ -3168,22 +3886,23 @@ namespace StarMath } void CElementOperator::ParseEQN(CStarMathReader *pReader) { + m_bEQN = true; pReader->ReadingTheNextToken(true); - while(pReader->GetLocalType() == TypeElement::upper || pReader->GetLocalType() == TypeElement::lower) + while(pReader->GetGlobalType() == TypeElement::Index) { - if(pReader->GetLocalType() == TypeElement::upper) + if(CElementIndex::GetUpperIndex(pReader->GetLocalType())) { pReader->ClearReader(); - m_pUpperIndex = CParserStarMathString::ParseElementEQN(pReader); + m_pValueTo = CParserStarMathString::ParseElementEQN(pReader); } - else if(pReader->GetLocalType() == TypeElement::lower) + else if(CElementIndex::GetLowerIndex(pReader->GetLocalType())) { pReader->ClearReader(); - m_pLowerIndex = CParserStarMathString::ParseElementEQN(pReader); + m_pValueFrom = CParserStarMathString::ParseElementEQN(pReader); } pReader->ReadingTheNextToken(true); } - m_pValueOperator = CParserStarMathString::ReadingWithoutBracket(pReader); + m_pValueOperator = CParserStarMathString::ReadingWithoutBracket(pReader,false,true); } void CElementOperator::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) { @@ -3222,7 +3941,7 @@ namespace StarMath else { pXmlWrite->WriteNodeBegin(L"m:nary",false); - CConversionSMtoOOXML::PropertiesNaryPr(m_enTypeOperator,(nullptr == m_pValueFrom && nullptr == m_pLowerIndex),(nullptr == m_pValueTo && nullptr == m_pUpperIndex),pXmlWrite,GetAttribute(),GetTypeConversion()); + CConversionSMtoOOXML::PropertiesNaryPr(m_enTypeOperator,(nullptr == m_pValueFrom && nullptr == m_pLowerIndex),(nullptr == m_pValueTo && nullptr == m_pUpperIndex),pXmlWrite,GetAttribute(),GetTypeConversion(),m_bEQN); if(m_pValueFrom != nullptr && m_pLowerIndex != nullptr) { pXmlWrite->WriteNodeBegin(L"m:sub",false); @@ -3295,8 +4014,8 @@ namespace StarMath return tSizeTo; } // class methods CStarMathReader - CStarMathReader::CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd,const TypeConversion &enTypeConversion) - : m_enGlobalType(TypeElement::Empty),m_enUnderType(TypeElement::Empty),m_pAttribute(nullptr),m_bMarkForUnar(true),m_enTypeCon(enTypeConversion),m_pBaseAttribute(nullptr) + CStarMathReader::CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd, const TypeConversion &enTypeConversion, const bool &bEQN) + : m_enGlobalType(TypeElement::Empty),m_enUnderType(TypeElement::Empty),m_pAttribute(nullptr),m_bMarkForUnar(true),m_enTypeCon(enTypeConversion),m_pBaseAttribute(nullptr),m_bEQN(bEQN) { m_itStart = itStart; m_itEnd = itEnd; @@ -3389,18 +4108,18 @@ namespace StarMath m_enGlobalType = TypeElement::String; return; } - m_enUnderType = CElementSpecialSymbol::GetSpecialSymbol(m_wsLowerCaseToken); - if(m_enUnderType != TypeElement::undefine) - { - m_enGlobalType = TypeElement::SpecialSymbol; - return; - } m_enUnderType = CElementBinOperator::GetBinOperator(m_wsLowerCaseToken); if(m_enUnderType != TypeElement::undefine) { m_enGlobalType = TypeElement::BinOperator; return; } + m_enUnderType = CElementSpecialSymbol::GetSpecialSymbol(m_wsLowerCaseToken,m_wsOriginalToken); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::SpecialSymbol; + return; + } m_enUnderType = CElementSetOperations::GetSetOperation(m_wsLowerCaseToken); if(m_enUnderType != TypeElement::undefine) { @@ -3445,8 +4164,14 @@ namespace StarMath m_enGlobalType = TypeElement::Bracket; return; } + if(m_wsOriginalToken == L"Lim") + { + m_enUnderType = TypeElement::Lim; + m_enGlobalType = TypeElement::IndexOp; + return; + } m_enUnderType = CElementBracket::GetBracketOpen(m_wsLowerCaseToken,true); - if(m_enUnderType != TypeElement::undefine) + if(m_enUnderType != TypeElement::undefine && m_enUnderType != TypeElement::lline) { m_enGlobalType = TypeElement::Bracket; return; @@ -3469,12 +4194,30 @@ namespace StarMath m_enGlobalType = TypeElement::Index; return; } + m_enUnderType = CElementIndex::GetIndexOp(m_wsLowerCaseToken); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::IndexOp; + return; + } + m_enUnderType = CElementMatrix::GetMatrix(m_wsLowerCaseToken,true); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::Matrix; + return; + } m_enUnderType = CElementDiacriticalMark::GetMark(m_wsLowerCaseToken,true); if(m_enUnderType != TypeElement::undefine) { m_enGlobalType = TypeElement::Mark; return; } + m_enUnderType = CElementSpecialSymbol::GetSpecialSymbol(m_wsLowerCaseToken,m_wsOriginalToken,true); + if(m_enUnderType != TypeElement::undefine) + { + m_enGlobalType = TypeElement::SpecialSymbol; + return; + } if(m_enUnderType == TypeElement::undefine && !m_wsLowerCaseToken.empty()) { m_enGlobalType = TypeElement::String; @@ -3563,11 +4306,16 @@ namespace StarMath } else if(!m_wsElement.empty() && (CheckTokenForGetElement(*m_itStart) ||(m_wsElement.back() == L'<' && (L'-' != *m_itStart && L'?' != *m_itStart && L'=' != *m_itStart && L'<' != *m_itStart && L'>' != *m_itStart)) || *m_itStart == L'(' || L')' == *m_itStart || L'(' == m_wsElement.back() || L')' == m_wsElement.back() || L'%' == *m_itStart||(L'#' == *m_itStart && L'#' != m_wsElement.back()) ||( L'+' == m_wsElement.back() && L'-' != *m_itStart ) || (L'-' == *m_itStart && L'+' != m_wsElement.back()) || (L'-' == m_wsElement.back() && L'+' != *m_itStart && L'>' != *m_itStart) || (L'+' == *m_itStart && L'-' != m_wsElement.back()) || (L'.' == *m_itStart && !iswdigit(m_wsElement.back())) || (iswdigit(*m_itStart) && !iswdigit(m_wsElement.back()) && L'.' != m_wsElement.back())|| (iswdigit(m_wsElement.back()) && !iswdigit(*m_itStart)) || ((m_wsElement.back() != L'<' && m_wsElement.back() != L'>') && (L'<' == *m_itStart || (L'>' == *m_itStart && L'-' !=m_wsElement.back() && L'?' != m_wsElement.back()) || L'=' == *m_itStart)))) return m_wsElement; - else if((( CheckTokenForGetElement(*m_itStart) || L'=' == *m_itStart) && m_wsElement.empty()) || (!m_wsElement.empty() && ((L'#' == m_wsElement.back() && L'#' == *m_itStart) || (L'-' == *m_itStart && L'+' == m_wsElement.back()) || ((L'+' == *m_itStart || L'>' == *m_itStart) && L'-' == m_wsElement.back()) || (m_wsElement.back() == L'<' && (L'=' == *m_itStart || L'<' == *m_itStart || L'>' == *m_itStart || L'-' == *m_itStart)) ||(L'?' == m_wsElement.back() && L'>' == *m_itStart) || (m_wsElement.back() == L'>' && (L'>' == *m_itStart || L'=' == *m_itStart )) ) ) ) + else if((( CheckTokenForGetElement(*m_itStart) || L'=' == *m_itStart) && m_wsElement.empty()) || (!m_wsElement.empty() && ((m_bEQN && ((m_wsElement == L"<<" && L'<' == *m_itStart) || (m_wsElement == L">>" && L'>' == *m_itStart))) || (L'#' == m_wsElement.back() && L'#' == *m_itStart) || (L'-' == *m_itStart && L'+' == m_wsElement.back()) || ((L'+' == *m_itStart || L'>' == *m_itStart) && L'-' == m_wsElement.back()) || (m_wsElement.back() == L'<' && (L'=' == *m_itStart || L'<' == *m_itStart || L'>' == *m_itStart || L'-' == *m_itStart)) ||(L'?' == m_wsElement.back() && L'>' == *m_itStart) || (m_wsElement.back() == L'>' && (L'>' == *m_itStart || L'=' == *m_itStart )) ) ) ) { m_wsElement.push_back(*m_itStart); - m_itStart++; - return m_wsElement; + if(m_bEQN && (m_wsElement == L"<<" || m_wsElement == L">>")) + continue; + else + { + m_itStart++; + return m_wsElement; + } } else { @@ -3641,35 +4389,19 @@ namespace StarMath { break; } - if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) != TypeElement::undefine) + if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && m_wsLowerCaseToken != L"\u007C") { if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) == TypeElement::left) - { - if(GetToken() && (m_wsLowerCaseToken == L"none" || (m_wsLowerCaseToken != L"left" && CElementBracket::GetBracketOpen(m_wsLowerCaseToken) != TypeElement::undefine))) - { - inBracketInside += 1; - continue; - } - } + { + if(GetToken() && (m_wsLowerCaseToken == L"none" || (m_wsLowerCaseToken != L"left" && CElementBracket::GetBracketOpen(m_wsLowerCaseToken) != TypeElement::undefine))) + { + inBracketInside += 1; + continue; + } + } else inBracketInside +=1; } - else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) == TypeElement::right && bEQN) - { - if(!GetToken()) - continue; - if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside == 0) - { - m_stBracket.push(m_itEnd); - m_stCloseBracket.push(m_itStart); - m_itEnd = itStartBracketClose; - break; - } - else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside != 0) - { - inBracketInside -=1; - } - } else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) == TypeElement::right) continue; else if(CElementBracket::GetBracketClose(m_wsLowerCaseToken,bEQN) != TypeElement::undefine && inBracketInside == 0) @@ -3813,6 +4545,7 @@ namespace StarMath } void CElementBracketWithIndex::ParseEQN(CStarMathReader *pReader) { + m_bEQN = true; if(m_enTypeBracketWithIndex == TypeElement::overbrace) m_pLeftArg = CParserStarMathString::ParseElementEQN(pReader); else if(m_enTypeBracketWithIndex == TypeElement::underbrace) @@ -3825,7 +4558,6 @@ namespace StarMath else if(m_enTypeBracketWithIndex == TypeElement::underbrace) CParserStarMathString::ReadingElementsWithPriorities(pReader,m_pValue); } - m_bEQN = true; Parse(pReader); } void CElementBracketWithIndex::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) @@ -4010,7 +4742,7 @@ namespace StarMath } //class methods CElementMatrix CElementMatrix::CElementMatrix(const TypeElement &enType,const TypeConversion &enTypeConversion) - :CElement(TypeElement::Matrix,enTypeConversion), m_pFirstArgument(nullptr), m_pSecondArgument(nullptr), m_enTypeMatrix(enType),m_iDimension(1) + :CElement(TypeElement::Matrix,enTypeConversion), m_pFirstArgument(nullptr), m_pSecondArgument(nullptr), m_enTypeMatrix(enType),m_iDimension(1),m_bEQN(false) { } CElementMatrix::~CElementMatrix() @@ -4035,6 +4767,7 @@ namespace StarMath else if(L"dmatrix" == wsToken) return TypeElement::dmatrix; else if(L"bmatrix" == wsToken) return TypeElement::bmatrix; else if(L"pile" == wsToken) return TypeElement::pile; + else if(L"cases" == wsToken) return TypeElement::cases; } else { @@ -4047,12 +4780,15 @@ namespace StarMath { if(m_enTypeMatrix == TypeElement::binom) { - SetFirstArgument(CParserStarMathString::ReadingWithoutBracket(pReader,false)); - SetSecondArgument(CParserStarMathString::ReadingWithoutBracket(pReader,false)); + SetFirstArgument(CParserStarMathString::ReadingWithoutBracket(pReader,false,m_bEQN)); + SetSecondArgument(CParserStarMathString::ReadingWithoutBracket(pReader,false,m_bEQN)); } else { - SetFirstArgument(CParserStarMathString::ParseElement(pReader)); + if(m_bEQN) + SetFirstArgument(CParserStarMathString::ParseElementEQN(pReader)); + else + SetFirstArgument(CParserStarMathString::ParseElement(pReader)); } if(GetAttribute() != nullptr) SetAttribute(GetAttribute()); @@ -4060,10 +4796,16 @@ namespace StarMath } void CElementMatrix::ParseEQN(CStarMathReader *pReader) { + m_bEQN = true; Parse(pReader); } void CElementMatrix::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { + if(m_bEQN && m_enTypeMatrix != TypeElement::pile && m_enTypeMatrix != TypeElement::matrix) + { + ConversionMatrixEQN(pXmlWrite); + return; + } pXmlWrite->WriteNodeBegin(L"m:m",false); CConversionSMtoOOXML::PropertiesMPr(pXmlWrite,m_enTypeMatrix,GetAttribute(),GetTypeConversion(),m_iDimension); pXmlWrite->WriteNodeBegin(L"m:mr",false); @@ -4072,6 +4814,7 @@ namespace StarMath { case TypeElement::matrix: case TypeElement::stack: + case TypeElement::pile: { if(m_pFirstArgument != nullptr) { @@ -4094,11 +4837,12 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:mr",false); pXmlWrite->WriteNodeBegin(L"m:e",false); } - else if(pTempSpecial->GetType() == TypeElement::grid) + else if(pTempSpecial->GetType() == TypeElement::grid || (m_bEQN && m_enTypeMatrix == TypeElement::pile && pTempSpecial->GetType() == TypeElement::transition)) { switch(m_enTypeMatrix) { case TypeElement::stack: + case TypeElement::pile: { pXmlWrite->WriteNodeEnd(L"m:e",false,false); pXmlWrite->WriteNodeEnd(L"m:mr",false,false); @@ -4173,6 +4917,45 @@ namespace StarMath pXmlWrite->WriteNodeEnd(L"m:mr",false,false); pXmlWrite->WriteNodeEnd(L"m:m",false,false); } + void CElementMatrix::ConversionMatrixEQN(XmlUtils::CXmlWriter* pXmlWrite) + { + CElementBracket* pBracket = new CElementBracket(TypeElement::undefine,GetTypeConversion(),true,true); + switch (m_enTypeMatrix) + { + case TypeElement::pmatrix: + { + pBracket->SetLeftBracket(TypeElement::round); + pBracket->SetRightBracket(TypeElement::rround); + break; + } + case TypeElement::dmatrix: + { + pBracket->SetLeftBracket(TypeElement::lline); + pBracket->SetRightBracket(TypeElement::rline); + break; + } + case TypeElement::bmatrix: + { + pBracket->SetLeftBracket(TypeElement::square); + pBracket->SetRightBracket(TypeElement::rsquare); + break; + } + case TypeElement::cases: + { + pBracket->SetLeftBracket(TypeElement::lbrace); + pBracket->SetRightBracket(TypeElement::none); + break; + } + default: + break; + } + m_enTypeMatrix = TypeElement::matrix; + std::vector arVecMatrix; + arVecMatrix.push_back(this); + pBracket->SetBracketValue(arVecMatrix); + CElement* pElement = pBracket; + pElement->ConversionToOOXML(pXmlWrite); + } void CElementMatrix::SetAttribute(CAttribute *pAttribute) { SetBaseAttribute(pAttribute); @@ -4232,6 +5015,7 @@ namespace StarMath TypeElement CElementDiacriticalMark::GetMark(const std::wstring &wsToken, const bool bEQN) { if(L"acute" == wsToken) return TypeElement::acute; + else if(L"grave" == wsToken) return TypeElement::grave; else if(L"breve" == wsToken) return TypeElement::breve; else if(L"dot" == wsToken) return TypeElement::dot; else if(L"vec" == wsToken) return TypeElement::vec; @@ -4250,7 +5034,6 @@ namespace StarMath else { if(L"dddot" == wsToken) return TypeElement::dddot; - else if(L"grave" == wsToken) return TypeElement::grave; else if(L"circle" == wsToken) return TypeElement::circle; else if(L"harpoon" == wsToken) return TypeElement::harpoon; else if(L"widevec" == wsToken) return TypeElement::widevec; @@ -4270,7 +5053,8 @@ namespace StarMath } void CElementDiacriticalMark::ParseEQN(CStarMathReader *pReader) { - Parse(pReader); + // Parse(pReader); + m_pValueMark = CParserStarMathString::ParseElementEQN(pReader); } void CElementDiacriticalMark::ConversionToOOXML(XmlUtils::CXmlWriter *pXmlWrite) { @@ -4279,7 +5063,7 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:borderBox",false); pXmlWrite->WriteNodeBegin(L"m:borderBoxPr",false); CConversionSMtoOOXML::WriteCtrlPrNode(pXmlWrite,GetAttribute(),GetTypeConversion()); - pXmlWrite->WriteNodeEnd(L"m:borderboxPr",false,false); + pXmlWrite->WriteNodeEnd(L"m:borderBoxPr",false,false); CConversionSMtoOOXML::WriteNodeConversion(L"m:e",m_pValueMark,pXmlWrite); pXmlWrite->WriteNodeEnd(L"m:borderBox",false,false); } diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 04411bbb77..4f782b7bb2 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -119,7 +119,7 @@ namespace StarMath class CStarMathReader { public: - CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd,const TypeConversion &enTypeConversion); + CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd,const TypeConversion &enTypeConversion,const bool& bEQN = false); ~CStarMathReader(); bool GetToken(); //getting a subtype and setting the global type of a token to variables m_enUnderType and m_enGlobalType @@ -165,6 +165,7 @@ namespace StarMath CAttribute* m_pBaseAttribute; TypeConversion m_enTypeCon; std::stack m_stBracket,m_stCloseBracket; + bool m_bEQN; }; class CElement @@ -202,6 +203,7 @@ namespace StarMath CElement* GetValueIndex(); CElement* GetLeftArg(); static TypeElement GetIndex(const std::wstring& wsCheckToken,const bool bEQN = false); + static TypeElement GetIndexOp(const std::wstring& wsCheckToken); static bool GetUpperIndex(const TypeElement& enType); static bool GetLowerIndex(const TypeElement& enType); const TypeElement& GetType(); @@ -213,7 +215,7 @@ namespace StarMath TFormulaSize GetSize() override; void ConversionOfIndicesToValue(XmlUtils::CXmlWriter* pXmlWrite); void ConversionOfIndicesAfterValue(XmlUtils::CXmlWriter* pXmlWrite); - void ParseIndex(CStarMathReader* pReader,CElement*& pElement); + void ParseIndex(CStarMathReader* pReader, CElement*& pElement); CElement* m_pValueIndex; CElement* m_pUpperIndex; CElement* m_pLowerIndex; @@ -254,7 +256,8 @@ namespace StarMath void SetTypeBinOP(const TypeElement& enType); CElement* GetRightArg(); CElement* GetLeftArg(); - static TypeElement GetBinOperator(const std::wstring& wsToken); + static TypeElement GetBinOperator(const std::wstring& wsToken, const bool& bEQN = false); + static void WritingBinOperatorSymbol(std::wstring& wsSymbol,const TypeElement& enType); static void UnaryCheck(CStarMathReader* pReader,CElement* pLastElement); const TypeElement& GetType(); //checking for signs such as -,+,-+,+-. @@ -288,7 +291,7 @@ namespace StarMath static TypeElement GetOperatorEQN(const std::wstring& wsToken); static TypeElement GetFromOrTo(const std::wstring& wsToken); private: - void SetAttribute(CAttribute* pAttribute); + void SetAttribute(CAttribute* pAttribute) override; void Parse(CStarMathReader* pReader) override; void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* oXmlWrite) override; @@ -300,6 +303,7 @@ namespace StarMath CElement* m_pLowerIndex; TypeElement m_enTypeOperator; std::wstring m_wsName; + bool m_bEQN; }; class CElementGrade: public CElement @@ -328,8 +332,10 @@ namespace StarMath CElementBracket(const TypeElement& enType, const TypeConversion &enTypeConversion, const bool& bScalability = false, const bool &bEQN = false); virtual ~CElementBracket(); void SetBracketValue(const std::vector& arValue); - static TypeElement GetBracketOpen(const std::wstring& wsToken, const bool bEQN = false); - static TypeElement GetBracketClose(const std::wstring& wsToken, const bool bEQN = false); + static TypeElement GetBracketOpen(const std::wstring& wsToken, const bool bEQN = false, const bool bLeft = false); + static TypeElement GetBracketClose(const std::wstring& wsToken, const bool bEQN = false, const bool bLeft = false); + void SetLeftBracket(const TypeElement& enTypeLeftBracket); + void SetRightBracket(const TypeElement& enTypeRightBracket); std::vector GetBracketValue(); private: void SetAttribute(CAttribute* pAttribute) override; @@ -376,7 +382,8 @@ namespace StarMath CElement* GetLeftArg(); void SetRightArg(CElement* pElement); CElement* GetRightArg(); - static TypeElement GetSetOperation(const std::wstring& wsToken); + static TypeElement GetSetOperation(const std::wstring& wsToken,const bool& bEQN = false); + static void WritingSetOperationSymbol(std::wstring& wsSymbol,const TypeElement& enTypeSetOperation); const TypeElement& GetType(); private: void SetAttribute(CAttribute* pAttribute) override; @@ -436,9 +443,14 @@ namespace StarMath class CElementSpecialSymbol: public CElement { public: - CElementSpecialSymbol(const TypeElement& enType,const TypeConversion &enTypeConversion); + CElementSpecialSymbol(const TypeElement& enType,const TypeConversion &enTypeConversion,const bool& bEQN = false); virtual ~CElementSpecialSymbol(); - static TypeElement GetSpecialSymbol(std::wstring& wsToken); + static TypeElement GetSpecialSymbol(std::wstring& wsTokenLowerCase,std::wstring& wsTokenUpperCase,const bool& bEQN = false); + static TypeElement GetGreekSymbols(std::wstring& wsToken); + static TypeElement GetGreekSmallSymbols(std::wstring& wsToken); + static TypeElement GetArrowForEQN(std::wstring& wsToken); + static TypeElement GetMathOperatorForEQN(std::wstring& wsToken); + static TypeElement GetOtherMathOperatorForEQN(std::wstring& wsToken); void SetValue(CElement* pValue); const TypeElement GetType(); private: @@ -447,10 +459,14 @@ namespace StarMath void Parse(CStarMathReader* pReader) override; void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; + void WritingMathOperatorForEQN(std::wstring& wsToken); + void WritingOtherMathOpForEQN(std::wstring& wsToken); + void WritingArrowForEQN(std::wstring& wsToken); TFormulaSize GetSize() override; CElement* m_pValue; TypeElement m_enTypeSpecial; std::wstring m_wsType; + bool m_bEQN; }; class CElementMatrix: public CElement @@ -466,12 +482,14 @@ namespace StarMath void Parse(CStarMathReader *pReader) override; void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; + void ConversionMatrixEQN(XmlUtils::CXmlWriter* pXmlWriter); void DimensionCalculation(); TFormulaSize GetSize() override; CElement* m_pFirstArgument; CElement* m_pSecondArgument; TypeElement m_enTypeMatrix; unsigned int m_iDimension; + bool m_bEQN; }; class CElementDiacriticalMark: public CElement @@ -503,7 +521,7 @@ namespace StarMath //Function for adding a left argument (receives the argument itself and the element to which it needs to be added as input. Works with classes:CElementBinOperator,CElementConnection,CElementSetOperation). static bool AddLeftArgument(CElement* pLeftArg,CElement* pElementWhichAdd,CStarMathReader* pReader); static bool CheckForLeftArgument(const TypeElement& enType, const bool& bConnection = true); - static CElement* ReadingWithoutBracket(CStarMathReader* pReader,const bool& bConnection = true); + static CElement* ReadingWithoutBracket(CStarMathReader* pReader,const bool& bConnection = true,const bool& bEQN = false); //checking the element (true if it is newline) static bool CheckNewline(CElement* pElement); static bool CheckGrid(CElement* pElement); @@ -513,7 +531,7 @@ namespace StarMath static void ReadingElementsWithPriorities(CStarMathReader* pReader,CElement*& pLeftElement, const bool bEQN = false); //method for parsing indexes with attributes. If there is an attribute present when indexes are read, then all subsequent indexes are applied to the index with the attribute. static void ReadingElementsWithAttributes(CStarMathReader* pReader,CElement*& pSavingElement,const bool bEQN = false); - static void ParsElementAddingToArray(CStarMathReader* pReader, std::vector& arElements); + static void ParsElementAddingToArray(CStarMathReader* pReader, std::vector& arElements, const bool &bEQN = false); void SetAlignment(const unsigned int& iAlignment); const unsigned int& GetAlignment(); void SetBaseFont(const std::wstring& wsNameFont); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h index 809b0e3cb9..723515e4be 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/typeselements.h @@ -52,6 +52,7 @@ enum class TypeElement{ Function, Operation, Index, + IndexOp, Matrix, Connection, Empty, @@ -82,6 +83,7 @@ enum class TypeElement{ minus_plus, //op lim, + Lim, sum, liminf, limsup, @@ -329,6 +331,88 @@ enum class TypeElement{ newline, emptySquare, slash, + //special EQN + Lrarrow, + lrarrow, + Rarrow, + rarrow, + Larrow, + larrow, + exarrow, + imath, + jmath, + ohm, + liter, + angstrom, + varupsilon, + leq, + geq, + sqsubset, + sqsupset, + sqsubsetq, + sqsupsetq, + triplearrow, + tripriarrow, + lor, + wedge, + smallinter, + cup, + sqcap, + sqcup, + uplus, + bullet, + deg, + ast, + star, + bigcirc, + therefore, + because, + identical, + doteq, + image, + reimage, + cong, + asymp, + iso, + diamond, + dsum, + prime, + lnot, + propto, + Xor, + dagger, + ddagger, + triangle, + msangle, + sangle, + rtangle, + vdash, + dashv, + bot, + top, + models, + centigrade, + fahrenheit, + lslant, + rslant, + att, + hund, + thou, + well, + base, + benzene, + UPARROW, + DOWNARROW, + udarrow, + UDARROW, + NWARROW, + SEARROW, + NEARROW, + SWARROW, + HOOKLEFT, + HOOKRIGHT, + MAPSTO, + DLINE, //function abs, fact, @@ -363,6 +447,8 @@ enum class TypeElement{ csub, //index EQN underover, + rel, + buildrel, // binom, stack, @@ -372,6 +458,7 @@ enum class TypeElement{ dmatrix, bmatrix, pile, + cases, //bracket close rwbrace, rbrace, From 95bad7b0714ba7a166f9e853d56a933144ad0d42 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Tue, 22 Jul 2025 18:04:52 +0300 Subject: [PATCH 007/125] writing Arabic characters --- .../StarMath2OOXML/StarMath2OOXML.pri | 4 +-- .../Converter/StarMath2OOXML/TypeLanguage.h | 8 +++++ .../StarMath2OOXML/cconversionsmtoooxml.cpp | 19 ++++++++-- .../StarMath2OOXML/cconversionsmtoooxml.h | 3 +- .../StarMath2OOXML/cstarmathpars.cpp | 36 +++++++++++-------- .../Converter/StarMath2OOXML/cstarmathpars.h | 4 ++- 6 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri index dddb09af70..76d5b267bd 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri @@ -9,12 +9,12 @@ ADD_DEPENDENCY(UnicodeConverter, kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ - $$PWD/cooxml2odf.cpp \ + # $$PWD/cooxml2odf.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ $$PWD/cconversionsmtoooxml.h \ - $$PWD/cooxml2odf.h \ + # $$PWD/cooxml2odf.h \ $$PWD/cstarmathpars.h \ $$PWD/fontType.h \ $$PWD/typeConversion.h \ diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h b/OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h new file mode 100644 index 0000000000..6f0f4d6684 --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h @@ -0,0 +1,8 @@ +namespace StarMath +{ +enum class TypeLanguage +{ + Russian, + Arabic, +}; +} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp index 9dd3ef99f9..3d34428884 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp @@ -31,7 +31,6 @@ */ #include "cconversionsmtoooxml.h" #include "../../../../DesktopEditor/common/File.h" -#include namespace StarMath { CConversionSMtoOOXML::CConversionSMtoOOXML(): m_pXmlWrite(nullptr) @@ -106,7 +105,7 @@ namespace StarMath { m_pXmlWrite->WriteNodeEnd(L"m:oMath",false,false); m_pXmlWrite->WriteNodeEnd(L"m:oMathPara",false,false); } - void CConversionSMtoOOXML::StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion) + void CConversionSMtoOOXML::StandartProperties(XmlUtils::CXmlWriter* pXmlWrite, CAttribute* pAttribute, const TypeConversion &enTypeConversion, const TypeLanguage &enTypeLang) { if(TypeConversion::docx == enTypeConversion || TypeConversion::undefine == enTypeConversion) { @@ -189,6 +188,22 @@ namespace StarMath { pXmlWrite->WriteNodeBegin(L"w:strike",true); pXmlWrite->WriteNodeEnd(L"w",true,true); } + if(enTypeLang != TypeLanguage::Russian) + { + switch (enTypeLang) { + case StarMath::TypeLanguage::Arabic: + { + pXmlWrite->WriteNodeBegin(L"w:rtl",true); + pXmlWrite->WriteNodeEnd(L"w",true,true); + pXmlWrite->WriteNodeBegin(L"w:lang",true); + pXmlWrite->WriteAttribute(L"w:bidi",L"ar-SA"); + pXmlWrite->WriteNodeEnd(L"w",true,true); + break; + } + default: + break; + } + } pXmlWrite->WriteNodeEnd(L"w:rPr",false,false); } } diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h index 1c7b06084f..2a500557ae 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h @@ -31,7 +31,6 @@ */ #pragma once #include "cstarmathpars.h" -#include "../../../../DesktopEditor/xml/include/xmlwriter.h" namespace StarMath { //delete XmlWrite @@ -41,7 +40,7 @@ namespace StarMath { CConversionSMtoOOXML(); ~CConversionSMtoOOXML(); void StartConversion(std::vector arPars, const unsigned int& iAlignment = 1); - static void StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion& enTypeConversion); + static void StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion& enTypeConversion, const TypeLanguage& enTypeLang = TypeLanguage::Russian); static void PropertiesMFPR(const std::wstring& wsType,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); static void PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion,const bool& bEQN = false); static void PropertiesFuncPr(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 04fa26b4df..637c594b3f 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -32,6 +32,7 @@ #include "cstarmathpars.h" #include "cconversionsmtoooxml.h" +#include "../../../../OOXML/Base/Unit.h" namespace StarMath { @@ -55,12 +56,13 @@ namespace StarMath if(!pReader->EmptyString()) { if(pReader->GetLocalType() == TypeElement::newline) - { m_arEquation.push_back(new CElementSpecialSymbol(pReader->GetLocalType(),pReader->GetTypeConversion())); + { + m_arEquation.push_back(new CElementSpecialSymbol(pReader->GetLocalType(),pReader->GetTypeConversion())); pReader->ClearReader(); } CElement* pTempElement = ParseElement(pReader); if(nullptr != pTempElement) - m_arEquation.push_back(pTempElement); + m_arEquation.push_back(pTempElement); } TFormulaSize tSize; for(CElement* pElement:m_arEquation) @@ -74,7 +76,7 @@ namespace StarMath tSize.Zeroing(); } else - ComparisonByHeight(tSize,pElement->GetSize()); + ComparisonByHeight(tSize,pElement->GetSize()); } else ComparisonByHeight(tSize,pElement->GetSize()); @@ -915,7 +917,7 @@ namespace StarMath } //class methods CElementString CElementString::CElementString(const std::wstring& wsTokenString,const TypeConversion &enTypeConversion) - :CElement(TypeElement::String,enTypeConversion),m_wsString(wsTokenString) + :CElement(TypeElement::String,enTypeConversion),m_enTypeLang(TypeLanguage::Russian),m_wsString(wsTokenString) { } CElementString::~CElementString() @@ -939,8 +941,18 @@ namespace StarMath break; } } + CheckingForArabicCharacters(); pReader->ClearReader(); } + void CElementString::CheckingForArabicCharacters() + { + for(wchar_t cOneElement:m_wsString) + { + if(cOneElement > 1791 && cOneElement < 1536) + return; + } + m_enTypeLang = TypeLanguage::Arabic; + } void CElementString::ParseEQN(CStarMathReader *pReader) {} void CElementString::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) @@ -948,7 +960,7 @@ namespace StarMath if(m_wsString !=L"" && m_wsString!=L" ") { pXmlWrite->WriteNodeBegin(L"m:r",false); - CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion()); + CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion(),m_enTypeLang); pXmlWrite->WriteNodeBegin(L"m:t",false); pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); pXmlWrite->WriteNodeEnd(L"m:t",false,false); @@ -3822,6 +3834,8 @@ namespace StarMath else if(L"lint" == wsToken) return TypeElement::lint; else if(L"llint" == wsToken) return TypeElement::llint; else if(L"lllint" == wsToken) return TypeElement::lllint; + else if(L"maj" == wsToken) return TypeElement::sum; + else if(L"hadd" == wsToken) return TypeElement::lim; else if(L"oper" == wsToken) return TypeElement::oper; } return TypeElement::undefine; @@ -3831,18 +3845,10 @@ namespace StarMath TypeElement enType = CElementOperator::GetOperator(wsToken,true); if(enType != TypeElement::undefine) return enType; - // if(L"bigsqcap" == wsToken) return TypeElement::bigsqcap; - // else if(L"bigsqcup" == wsToken) return TypeElement::bigsqcup; if(L"inter" == wsToken) return TypeElement::inter; else if(L"union" == wsToken) return TypeElement::UnionOp; - // else if(L"bigoplus" == wsToken) return TypeElement::bigoplus; - // else if(L"bigominus" == wsToken) return TypeElement::bigominus; - // else if(L"bigotimes" == wsToken) return TypeElement::bigotimes; - // else if(L"bigodiv" == wsToken) return TypeElement::bigodiv; - // else if(L"bigodot" == wsToken) return TypeElement::bigodot; else if(L"bigvee" == wsToken) return TypeElement::bigvee; else if(L"bigwedge" == wsToken) return TypeElement::bigwedge; - // else if(L"biguplus" == wsToken) return TypeElement::biguplus; else if(L"dint" == wsToken) return TypeElement::iint; else if(L"tint" == wsToken) return TypeElement::iiint; else if(L"oint" == wsToken) return TypeElement::lint; @@ -3906,7 +3912,7 @@ namespace StarMath } void CElementOperator::ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) { - if(m_enTypeOperator == TypeElement::lim || TypeElement::liminf == m_enTypeOperator || TypeElement::limsup == m_enTypeOperator || TypeElement::oper == m_enTypeOperator) + if(m_enTypeOperator == TypeElement::lim || TypeElement::liminf == m_enTypeOperator || TypeElement::limsup == m_enTypeOperator || TypeElement::oper == m_enTypeOperator ) { pXmlWrite->WriteNodeBegin(L"m:func",false); CConversionSMtoOOXML::PropertiesFuncPr(pXmlWrite,GetAttribute(),GetTypeConversion()); @@ -4393,7 +4399,7 @@ namespace StarMath { if(CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) == TypeElement::left) { - if(GetToken() && (m_wsLowerCaseToken == L"none" || (m_wsLowerCaseToken != L"left" && CElementBracket::GetBracketOpen(m_wsLowerCaseToken) != TypeElement::undefine))) + if(GetToken() && (m_wsLowerCaseToken == L"none" || (m_wsLowerCaseToken != L"left" && CElementBracket::GetBracketOpen(m_wsLowerCaseToken,bEQN) != TypeElement::undefine))) { inBracketInside += 1; continue; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 4f782b7bb2..6769e4c1ae 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -34,6 +34,7 @@ #define CSTARMATHPARS_H #include "typeselements.h" #include "typeConversion.h" +#include "TypeLanguage.h" #include #include #include @@ -42,7 +43,6 @@ #include #include #include "../../../../DesktopEditor/xml/include/xmlwriter.h" -#include "../../../../OOXML/Base/Unit.h" namespace StarMath { @@ -242,7 +242,9 @@ namespace StarMath void Parse(CStarMathReader* pReader) override; void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; + void CheckingForArabicCharacters(); TFormulaSize GetSize() override; + TypeLanguage m_enTypeLang; std::wstring m_wsString; }; From 0f1cb3715317a49e88b0b7cce56b5b5dc92b2f11 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Tue, 22 Jul 2025 18:23:24 +0300 Subject: [PATCH 008/125] edit of the previous comment --- .../Converter/StarMath2OOXML/StarMath2OOXML.pri | 7 +++++-- .../StarMath2OOXML/TestSMConverter/main.cpp | 2 +- .../Converter/StarMath2OOXML/cstarmathpars.cpp | 13 ++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri index 76d5b267bd..427fcf934a 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri @@ -9,12 +9,15 @@ ADD_DEPENDENCY(UnicodeConverter, kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ - # $$PWD/cooxml2odf.cpp \ + $$CORE_ROOT_DIR\OOXML\Base\Unit.cpp \ + $$PWD/cooxml2odf.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ + $$PWD/TypeLanguage.h \ $$PWD/cconversionsmtoooxml.h \ - # $$PWD/cooxml2odf.h \ + $$PWD/cooxml2odf.h \ + $$CORE_ROOT_DIR\OOXML\Base\Unit.h \ $$PWD/cstarmathpars.h \ $$PWD/fontType.h \ $$PWD/typeConversion.h \ diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp index 4e37211d1e..8dad735ff5 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp @@ -1394,7 +1394,7 @@ TEST(SMConvectorTest,LimWithArrow) EXPECT_EQ(oTest.GetOOXML(),wsXmlString); } -TEST(SMConvectorTest,FuctionWithAttributeAndIndex) +TEST(SMConvectorTest,FunctionWithAttributeAndIndex) { std::wstring wsString = L"{%sigma' = %sigma color red bold func e ^ color blue frac 2 3 }"; StarMath::CParserStarMathString oTemp; diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 637c594b3f..a172382182 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -946,12 +946,16 @@ namespace StarMath } void CElementString::CheckingForArabicCharacters() { + bool bArabic; for(wchar_t cOneElement:m_wsString) { - if(cOneElement > 1791 && cOneElement < 1536) + if(cOneElement <= 1791 && cOneElement >= 1536) + bArabic = true; + else return; } - m_enTypeLang = TypeLanguage::Arabic; + if(bArabic) + m_enTypeLang = TypeLanguage::Arabic; } void CElementString::ParseEQN(CStarMathReader *pReader) {} @@ -962,7 +966,10 @@ namespace StarMath pXmlWrite->WriteNodeBegin(L"m:r",false); CConversionSMtoOOXML::StandartProperties(pXmlWrite,GetAttribute(),GetTypeConversion(),m_enTypeLang); pXmlWrite->WriteNodeBegin(L"m:t",false); - pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); + if(m_wsString == L"'") + pXmlWrite->WriteString(m_wsString); + else + pXmlWrite->WriteString(XmlUtils::EncodeXmlString(m_wsString)); pXmlWrite->WriteNodeEnd(L"m:t",false,false); pXmlWrite->WriteNodeEnd(L"m:r",false,false); } From cb68e4389e4f36e43e19011c0a08cca2796d615a Mon Sep 17 00:00:00 2001 From: Green Date: Mon, 4 Aug 2025 20:16:57 +0300 Subject: [PATCH 009/125] EQN conversion added to HWPX --- HwpFile/HWPFile.pro | 3 +++ HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp | 16 ++++++++++++---- .../Converter/StarMath2OOXML/StarMath2OOXML.pri | 6 ++++-- .../TestEQNtoOOXML/TestEQNtoOOXML.pro | 2 ++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/HwpFile/HWPFile.pro b/HwpFile/HWPFile.pro index 89dfe87fae..0c95872c84 100644 --- a/HwpFile/HWPFile.pro +++ b/HwpFile/HWPFile.pro @@ -12,6 +12,9 @@ PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) +CONFIG += startmath_use_only_eqn +include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) + LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib ADD_DEPENDENCY(kernel, UnicodeConverter, graphics) diff --git a/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp b/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp index 6a8a1126b5..1d7bf8f5a1 100644 --- a/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp +++ b/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp @@ -20,6 +20,9 @@ #include "../HWPElements/HWPRecordParaShape.h" #include "../HWPElements/HWPRecordCharShape.h" +//For EQN +#include "../../../OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h" + #include "Transform.h" #define PARA_SPACING_SCALE 0.85 @@ -1169,17 +1172,22 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape void CConverter2OOXML::WriteEqEditShape(const CCtrlEqEdit* pEqEditShape, short shParaShapeID, short shParaStyleID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState) { - //TODO:: добавить конвертацию eqn формулы в ooxml ++m_ushEquationCount; WriteCaption((const CCtrlCommon*)pEqEditShape, oBuilder, oState); OpenParagraph(shParaShapeID, shParaStyleID, oBuilder, oState); - oBuilder.WriteString(L""); + oBuilder.WriteString(L""); - oBuilder.WriteString(L""); - oBuilder.WriteEncodeXmlString(pEqEditShape->GetEqn()); + StarMath::CConversionSMtoOOXML oEQNConverter; + + //TODO:: создаем временную переменную, так как ParseEQN не принимает константный указатель + std::wstring wsEQN{pEqEditShape->GetEqn()}; + + oEQNConverter.StartConversion(StarMath::CParserStarMathString().ParseEQN(wsEQN)); + + oBuilder.WriteString(oEQNConverter.GetOOXML()); oBuilder.WriteString(L""); } diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri index 427fcf934a..a08e235d34 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri @@ -10,16 +10,18 @@ ADD_DEPENDENCY(UnicodeConverter, kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ $$CORE_ROOT_DIR\OOXML\Base\Unit.cpp \ - $$PWD/cooxml2odf.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ $$PWD/TypeLanguage.h \ $$PWD/cconversionsmtoooxml.h \ - $$PWD/cooxml2odf.h \ $$CORE_ROOT_DIR\OOXML\Base\Unit.h \ $$PWD/cstarmathpars.h \ $$PWD/fontType.h \ $$PWD/typeConversion.h \ $$PWD/typeselements.h +!startmath_use_only_eqn{ + SOURCES += $$PWD/cooxml2odf.cpp + HEADERS += $$PWD/cooxml2odf.h +} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro index 788618500b..6e8d36a014 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro @@ -8,6 +8,8 @@ TEMPLATE = app CORE_ROOT_DIR = $$PWD/../../../../.. PWD_ROOT_DIR = $$PWD +CONFIG += startmath_use_only_eqn + include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) include($$CORE_ROOT_DIR/Common/3dParty/googletest/googletest.pri) From 930165a99343a41da3a927e64653b140af6f7870 Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Thu, 14 Aug 2025 14:50:46 +0300 Subject: [PATCH 010/125] fix bugs --- .../TestSMConverter/TestSMConverter.pro | 2 + .../StarMath2OOXML/cstarmathpars.cpp | 50 ++++++++++++++++++- .../Converter/StarMath2OOXML/cstarmathpars.h | 2 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro index 788618500b..6e8d36a014 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro @@ -8,6 +8,8 @@ TEMPLATE = app CORE_ROOT_DIR = $$PWD/../../../../.. PWD_ROOT_DIR = $$PWD +CONFIG += startmath_use_only_eqn + include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) include($$CORE_ROOT_DIR/Common/3dParty/googletest/googletest.pri) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index a172382182..ffe290c33a 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -1558,8 +1558,11 @@ namespace StarMath return L"\u2016"; case TypeElement::none: return L"none"; - default: + case TypeElement::round: + case TypeElement::rround: return L""; + default: + return m_bEQN ? L"none" : L""; } } TFormulaSize CElementBracket::GetSize() @@ -4317,7 +4320,7 @@ namespace StarMath m_itStart++; break; } - else if(!m_wsElement.empty() && (CheckTokenForGetElement(*m_itStart) ||(m_wsElement.back() == L'<' && (L'-' != *m_itStart && L'?' != *m_itStart && L'=' != *m_itStart && L'<' != *m_itStart && L'>' != *m_itStart)) || *m_itStart == L'(' || L')' == *m_itStart || L'(' == m_wsElement.back() || L')' == m_wsElement.back() || L'%' == *m_itStart||(L'#' == *m_itStart && L'#' != m_wsElement.back()) ||( L'+' == m_wsElement.back() && L'-' != *m_itStart ) || (L'-' == *m_itStart && L'+' != m_wsElement.back()) || (L'-' == m_wsElement.back() && L'+' != *m_itStart && L'>' != *m_itStart) || (L'+' == *m_itStart && L'-' != m_wsElement.back()) || (L'.' == *m_itStart && !iswdigit(m_wsElement.back())) || (iswdigit(*m_itStart) && !iswdigit(m_wsElement.back()) && L'.' != m_wsElement.back())|| (iswdigit(m_wsElement.back()) && !iswdigit(*m_itStart)) || ((m_wsElement.back() != L'<' && m_wsElement.back() != L'>') && (L'<' == *m_itStart || (L'>' == *m_itStart && L'-' !=m_wsElement.back() && L'?' != m_wsElement.back()) || L'=' == *m_itStart)))) + else if(!m_wsElement.empty() && (CheckTokenForGetElement(*m_itStart)|| (m_bEQN && L'&' == *m_itStart) ||(m_wsElement.back() == L'<' && (L'-' != *m_itStart && L'?' != *m_itStart && L'=' != *m_itStart && L'<' != *m_itStart && L'>' != *m_itStart)) || *m_itStart == L'(' || L')' == *m_itStart || L'(' == m_wsElement.back() || L')' == m_wsElement.back() || L'%' == *m_itStart||(L'#' == *m_itStart && L'#' != m_wsElement.back()) ||( L'+' == m_wsElement.back() && L'-' != *m_itStart ) || (L'-' == *m_itStart && L'+' != m_wsElement.back()) || (L'-' == m_wsElement.back() && L'+' != *m_itStart && L'>' != *m_itStart) || (L'+' == *m_itStart && L'-' != m_wsElement.back()) || (L'.' == *m_itStart && !iswdigit(m_wsElement.back())) || (iswdigit(*m_itStart) && !iswdigit(m_wsElement.back()) && L'.' != m_wsElement.back())|| (iswdigit(m_wsElement.back()) && !iswdigit(*m_itStart)) || ((m_wsElement.back() != L'<' && m_wsElement.back() != L'>') && (L'<' == *m_itStart || (L'>' == *m_itStart && L'-' !=m_wsElement.back() && L'?' != m_wsElement.back()) || L'=' == *m_itStart)))) return m_wsElement; else if((( CheckTokenForGetElement(*m_itStart) || L'=' == *m_itStart) && m_wsElement.empty()) || (!m_wsElement.empty() && ((m_bEQN && ((m_wsElement == L"<<" && L'<' == *m_itStart) || (m_wsElement == L">>" && L'>' == *m_itStart))) || (L'#' == m_wsElement.back() && L'#' == *m_itStart) || (L'-' == *m_itStart && L'+' == m_wsElement.back()) || ((L'+' == *m_itStart || L'>' == *m_itStart) && L'-' == m_wsElement.back()) || (m_wsElement.back() == L'<' && (L'=' == *m_itStart || L'<' == *m_itStart || L'>' == *m_itStart || L'-' == *m_itStart)) ||(L'?' == m_wsElement.back() && L'>' == *m_itStart) || (m_wsElement.back() == L'>' && (L'>' == *m_itStart || L'=' == *m_itStart )) ) ) ) { @@ -4823,6 +4826,7 @@ namespace StarMath CConversionSMtoOOXML::PropertiesMPr(pXmlWrite,m_enTypeMatrix,GetAttribute(),GetTypeConversion(),m_iDimension); pXmlWrite->WriteNodeBegin(L"m:mr",false); bool bNormal(false); + unsigned int i_ActualNumberColumns(0),i_NumberColumns(0); switch(m_enTypeMatrix) { case TypeElement::matrix: @@ -4835,6 +4839,7 @@ namespace StarMath { CElementBracket* pTempBracket = dynamic_cast(m_pFirstArgument); std::vector pTempValue = pTempBracket->GetBracketValue(); + i_ActualNumberColumns = CalculatingTheNumberOfColumns(pTempValue); pXmlWrite->WriteNodeBegin(L"m:e",false); for(CElement* pOneElement:pTempValue) { @@ -4845,6 +4850,8 @@ namespace StarMath CElementSpecialSymbol* pTempSpecial = dynamic_cast(pOneElement); if(pTempSpecial->GetType() == TypeElement::transition && m_enTypeMatrix == TypeElement::matrix) { + FillingInColumns(pXmlWrite,i_ActualNumberColumns,i_NumberColumns); + i_NumberColumns = 0; pXmlWrite->WriteNodeEnd(L"m:e",false,false); pXmlWrite->WriteNodeEnd(L"m:mr",false,false); pXmlWrite->WriteNodeBegin(L"m:mr",false); @@ -4867,6 +4874,7 @@ namespace StarMath { pXmlWrite->WriteNodeEnd(L"m:e",false,false); pXmlWrite->WriteNodeBegin(L"m:e",false); + i_NumberColumns++; break; } default: @@ -4926,7 +4934,11 @@ namespace StarMath } } if(bNormal) + { + if(m_enTypeMatrix == TypeElement::matrix) + FillingInColumns(pXmlWrite,i_ActualNumberColumns,i_NumberColumns); pXmlWrite->WriteNodeEnd(L"m:e",false,false); + } pXmlWrite->WriteNodeEnd(L"m:mr",false,false); pXmlWrite->WriteNodeEnd(L"m:m",false,false); } @@ -5012,6 +5024,40 @@ namespace StarMath } } } + unsigned int CElementMatrix::CalculatingTheNumberOfColumns(const std::vector& arElements) + { + unsigned int i_ActualNumberColumns(0),i_Temp(0); + for(CElement* pOneElement:arElements) + { + if(pOneElement->GetBaseType() == TypeElement::SpecialSymbol) + { + CElementSpecialSymbol* pSpecial = dynamic_cast(pOneElement); + if(pSpecial->GetType() == TypeElement::grid) + i_Temp++; + if(pSpecial->GetType() == TypeElement::transition) + { + i_Temp++; + if(i_Temp > i_ActualNumberColumns) + i_ActualNumberColumns = i_Temp; + i_Temp = 0; + } + } + } + i_Temp++; + if(i_Temp > i_ActualNumberColumns) + i_ActualNumberColumns = i_Temp; + return i_ActualNumberColumns; + } + void CElementMatrix::FillingInColumns(XmlUtils::CXmlWriter* pXmlWriter, const unsigned int &i_ActualNumberColumns, unsigned int &i_NumberColumns) + { + i_NumberColumns++; + unsigned int i_Temp(0); + for(i_Temp; i_Temp < i_ActualNumberColumns - i_NumberColumns;i_Temp++) + { + pXmlWriter->WriteNodeEnd(L"m:e",false,false); + pXmlWriter->WriteNodeBegin(L"m:e",false); + } + } //class CElementDiacriticalMark CElementDiacriticalMark::CElementDiacriticalMark(const TypeElement& enType,const TypeConversion &enTypeConversion) :CElement(TypeElement::Mark,enTypeConversion),m_pValueMark(nullptr),m_enTypeMark(enType) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 6769e4c1ae..815724a8a7 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -486,6 +486,8 @@ namespace StarMath void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; void ConversionMatrixEQN(XmlUtils::CXmlWriter* pXmlWriter); void DimensionCalculation(); + unsigned int CalculatingTheNumberOfColumns(const std::vector& arElements); + void FillingInColumns(XmlUtils::CXmlWriter* pXmlWriter,const unsigned int& i_ActualNumberColumns, unsigned int& i_NumberColumns); TFormulaSize GetSize() override; CElement* m_pFirstArgument; CElement* m_pSecondArgument; From deb90037d5493eee509be275a2ae41e1fbd6080f Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Thu, 4 Sep 2025 17:12:15 +0300 Subject: [PATCH 011/125] StarMath conversion to a dynamic library --- HwpFile/HWPFile.pro | 5 +- HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp | 11 +- OdfFile/Projects/Linux/OdfFormatLib.pro | 7 +- ...{StarMath2OOXML.pri => StarMath2OOXML.pro} | 23 +- .../Converter/StarMath2OOXML/TFormulaSize.h | 25 + .../TestEQNtoOOXML/TestEQNtoOOXML.pro | 6 +- .../StarMath2OOXML/TestEQNtoOOXML/main.cpp | 161 ++-- .../TestSMConverter/TestSMConverter.pro | 8 +- .../StarMath2OOXML/TestSMConverter/main.cpp | 855 ++++++------------ .../StarMath2OOXML/cconversionsmtoooxml.cpp | 2 +- .../StarMath2OOXML/cconversionsmtoooxml.h | 2 +- .../StarMath2OOXML/conversionmathformula.cpp | 69 ++ .../StarMath2OOXML/conversionmathformula.h | 37 + .../Converter/StarMath2OOXML/cooxml2odf.cpp | 1 - .../Converter/StarMath2OOXML/cooxml2odf.h | 1 + .../StarMath2OOXML/cstarmathpars.cpp | 18 +- .../Converter/StarMath2OOXML/cstarmathpars.h | 20 +- OdfFile/Reader/Format/math_elements.cpp | 25 +- X2tConverter/build/Qt/X2tConverter.pri | 2 +- 19 files changed, 533 insertions(+), 745 deletions(-) rename OdfFile/Reader/Converter/StarMath2OOXML/{StarMath2OOXML.pri => StarMath2OOXML.pro} (59%) create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/TFormulaSize.h create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.cpp create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.h diff --git a/HwpFile/HWPFile.pro b/HwpFile/HWPFile.pro index 0c95872c84..57bdc4e62b 100644 --- a/HwpFile/HWPFile.pro +++ b/HwpFile/HWPFile.pro @@ -12,12 +12,9 @@ PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) -CONFIG += startmath_use_only_eqn -include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) - LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib -ADD_DEPENDENCY(kernel, UnicodeConverter, graphics) +ADD_DEPENDENCY(kernel, UnicodeConverter, graphics, StarMathConverter) DEFINES += HWPFILE_USE_DYNAMIC_LIBRARY \ CRYPTOPP_DISABLE_ASM diff --git a/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp b/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp index 1d7bf8f5a1..011e07580c 100644 --- a/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp +++ b/HwpFile/HwpDoc/Conversion/Converter2OOXML.cpp @@ -21,7 +21,7 @@ #include "../HWPElements/HWPRecordCharShape.h" //For EQN -#include "../../../OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h" +#include "../../../OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.h" #include "Transform.h" @@ -1180,14 +1180,9 @@ void CConverter2OOXML::WriteEqEditShape(const CCtrlEqEdit* pEqEditShape, short s oBuilder.WriteString(L""); - StarMath::CConversionSMtoOOXML oEQNConverter; + StarMath::CStarMathConverter oConverterStarMath; - //TODO:: создаем временную переменную, так как ParseEQN не принимает константный указатель - std::wstring wsEQN{pEqEditShape->GetEqn()}; - - oEQNConverter.StartConversion(StarMath::CParserStarMathString().ParseEQN(wsEQN)); - - oBuilder.WriteString(oEQNConverter.GetOOXML()); + oBuilder.WriteString(oConverterStarMath.ConvertEQNToOOXml(pEqEditShape->GetEqn())); oBuilder.WriteString(L""); } diff --git a/OdfFile/Projects/Linux/OdfFormatLib.pro b/OdfFile/Projects/Linux/OdfFormatLib.pro index 9b9591e235..3c300a2a55 100644 --- a/OdfFile/Projects/Linux/OdfFormatLib.pro +++ b/OdfFile/Projects/Linux/OdfFormatLib.pro @@ -19,7 +19,6 @@ include(../../../Common/base.pri) #BOOST include($$PWD/../../../Common/3dParty/boost/boost.pri) -include($$PWD/../../Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) include($$PWD/../../Reader/Converter/SMCustomShape2OOXML/SMCustomShape2OOXML.pri) DEFINES += UNICODE \ @@ -33,6 +32,8 @@ precompile_header { HEADERS += precompiled.h } +ADD_DEPENDENCY(StarMathConverter) + core_release { SOURCES += \ odf_converter.cpp \ @@ -322,6 +323,7 @@ SOURCES += \ ../../Reader/Converter/xlsx_data_validation.cpp \ ../../Reader/Converter/xlsx_utils.cpp \ ../../Reader/Converter/xlsx_xf.cpp \ + ../../Reader/Converter/StarMath2OOXML/cooxml2odf.cpp \ \ ../../Writer/Format/office_document.cpp \ ../../Writer/Format/office_forms.cpp \ @@ -721,6 +723,7 @@ HEADERS += \ ../../Reader/Converter/xlsx_xf.h \ ../../Reader/Converter/conversionelement.h \ ../../Reader/Converter/ConvertOO2OOX.h \ + ../../Reader/Converter/StarMath2OOXML/cooxml2odf.h \ \ ../../Writer/Format/math_elementaries.h \ ../../Writer/Format/math_elements.h \ @@ -826,5 +829,5 @@ HEADERS += \ ../../Writer/Converter/Oox2OdfConverter.h \ ../../Writer/Converter/VmlShapeTypes2Oox.h \ ../../Writer/Converter/XlsxConverter.h \ - ../../Writer/Converter/PptxConverter.h + ../../Writer/Converter/PptxConverter.h \ diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro similarity index 59% rename from OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri rename to OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro index a08e235d34..152df0ec05 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro @@ -1,27 +1,36 @@ +QT -= core gui + +VERSION = 0.0.0.1 +TARGET = StarMathConverter +TEMPLATE = lib + +CONFIG += shared +CONFIG += plugin CORE_ROOT_DIR = $$PWD/../../../.. PWD_ROOT_DIR = $$PWD +DEFINES += STARMATH_USE_DYNAMIC_LIBRARY + include($$CORE_ROOT_DIR/Common/base.pri) include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri) include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri) -ADD_DEPENDENCY(UnicodeConverter, kernel) +ADD_DEPENDENCY(kernel) SOURCES += $$PWD/cconversionsmtoooxml.cpp \ $$CORE_ROOT_DIR\OOXML\Base\Unit.cpp \ + $$PWD/conversionmathformula.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ - $$PWD/TypeLanguage.h \ + $$PWD/TypeLanguage.h \ $$PWD/cconversionsmtoooxml.h \ $$CORE_ROOT_DIR\OOXML\Base\Unit.h \ + $$PWD/conversionmathformula.h \ $$PWD/cstarmathpars.h \ $$PWD/fontType.h \ $$PWD/typeConversion.h \ - $$PWD/typeselements.h + $$PWD/typeselements.h \ + $$PWD/TFormulaSize.h -!startmath_use_only_eqn{ - SOURCES += $$PWD/cooxml2odf.cpp - HEADERS += $$PWD/cooxml2odf.h -} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TFormulaSize.h b/OdfFile/Reader/Converter/StarMath2OOXML/TFormulaSize.h new file mode 100644 index 0000000000..459bac725a --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TFormulaSize.h @@ -0,0 +1,25 @@ +#ifndef TFORMULASIZE_H +#define TFORMULASIZE_H + +#ifndef STARMATH_USE_DYNAMIC_LIBRARY +#define STARMATH_DECL_EXPORT +#else +#include "../../../../DesktopEditor/common/base_export.h" +#define STARMATH_DECL_EXPORT Q_DECL_EXPORT +#endif +namespace StarMath +{ + struct STARMATH_DECL_EXPORT TFormulaSize + { + TFormulaSize():m_iHeight(0),m_iWidth(0) {}; + TFormulaSize(const unsigned int& iHeight,const unsigned int& iwidth):m_iHeight(iHeight),m_iWidth(iwidth) {}; + float m_iHeight; + float m_iWidth; + void Zeroing() + { + this->m_iHeight = 0; + this->m_iWidth = 0; + } + }; +} +#endif // TFORMULASIZE_H diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro index 6e8d36a014..3181037faf 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/TestEQNtoOOXML.pro @@ -8,9 +8,11 @@ TEMPLATE = app CORE_ROOT_DIR = $$PWD/../../../../.. PWD_ROOT_DIR = $$PWD -CONFIG += startmath_use_only_eqn +include($$CORE_ROOT_DIR/Common/base.pri) +include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri) + +ADD_DEPENDENCY(StarMathConverter) -include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) include($$CORE_ROOT_DIR/Common/3dParty/googletest/googletest.pri) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp index 87f87e2237..ebf60f7a88 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestEQNtoOOXML/main.cpp @@ -1,265 +1,214 @@ -#include "../cstarmathpars.h" -#include "../cconversionsmtoooxml.h" +#include "../conversionmathformula.h" #include "gtest/gtest.h" TEST(SMConvectorTest,IndexUpperLower) { std::wstring wsString = L"2^{ 1} _{ 3}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"231"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,LsupLsub) { std::wstring wsString = L"{ 1} LSUP { 2} LSUB { 3}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"321"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,UnderOver) { std::wstring wsString = L"UNDEROVER { 5} _{ 6} ^{ 7}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"576"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,VecUnder) { std::wstring wsString = L"vec { 1} under { 2}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"12"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BarHat) { std::wstring wsString = L"bar { 5} hat { 6}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"56"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SqrtRoot) { std::wstring wsString = L"sqrt {2} root {5} of {10}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2510"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Over) { std::wstring wsString = L"{ 5} over {10 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"510"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SumProdCoprod) { std::wstring wsString = L"sum _{ 1} ^{ 2} 3 PROD _{ 4} ^{5 } 6 COPROD _{ 7} ^{ 8} 9"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"123456789"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BigPlusBigUplus) { std::wstring wsString = L"BIGOPLUS _{ 1} ^{2 } 3 BIGUPLUS _{ 5} ^{10 } 15"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"21310515"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Tint) { std::wstring wsString = L"tint _{{2} over {3}} ^{4} {root {5} of {10}}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"234510"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Otint) { std::wstring wsString = L"otint _{ 1} ^{ 2} { 3}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"123"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,RelAndBuildrelArrow) { std::wstring wsString = L"REL LRARROW { 1} { 2} REL EXARROW { 3} { 4} BUILDREL rarrow { 5} { 6}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"123456"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,LimLimlow) { std::wstring wsString = L"Lim _{ ->inf} { 2} lim _{ ->0} { 5}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"Lim2lim05"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,LfloorSquare) { std::wstring wsString = L"LEFT [ { 1} over { 2} RIGHT ] LFLOOR sum _{ 1} ^{ 2} RFLOOR"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1212"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Cases) { std::wstring wsString = L"cases{ 1& 2# 3& 4}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1234"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Lline) { std::wstring wsString = L"LEFT | 1 RIGHT | 2 + 3"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"12+3"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Arrow) { std::wstring wsString = L"larrow UPARROW NWARROW MAPSTO DLINE"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L""; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Overbrace) { std::wstring wsString = L"OVERBRACE { 1} { 2}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"12"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Underbrace) { std::wstring wsString = L"UNDERBRACE { 5} {10 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"105"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Pile) { std::wstring wsString = L"pile{ 1 over 2 # 2}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"122"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Pmatrix) { std::wstring wsString = L"pmatrix { 1& 2#3 &4 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1234"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Bmatrix) { std::wstring wsString = L"bmatrix { 1&2 &3 # 4& 6&5 # 7& 8&9 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"123465789"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,GreekSymbols) { std::wstring wsString = L"ALPHA ETA NU TAU PSI"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"ΑΗΝΤΨ"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,GreekSymbolsSmall) { std::wstring wsString = L"epsilon iota nu rho phi"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"εινρφ"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,MathOperatorSymbols) { std::wstring wsString = L"+- DEG BECAUSE REIMAGE ASYMP FORALL LNOT DAGGER"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.ParseEQN(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"±°¬"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); } // TEST(SMConvectorTest,AttributeMatrix) // { // std::wstring wsString = L""; -// StarMath::CParserStarMathString oTemp; -// StarMath::CConversionSMtoOOXML oTest; -// oTest.StartConversion(oTemp.ParseEQN(wsString)); +// StarMath::CStarMathConverter oConverterStarMath; +// +// // std::wstring wsXmlString = L""; -// EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +// EXPECT_EQ(oConverterStarMath.ConvertEQNToOOXml(wsString),wsXmlString); // } diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro index 6e8d36a014..d8fa353a7a 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/TestSMConverter.pro @@ -8,13 +8,13 @@ TEMPLATE = app CORE_ROOT_DIR = $$PWD/../../../../.. PWD_ROOT_DIR = $$PWD -CONFIG += startmath_use_only_eqn +include($$CORE_ROOT_DIR/Common/base.pri) +include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri) + +ADD_DEPENDENCY(StarMathConverter) -include($$CORE_ROOT_DIR/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pri) include($$CORE_ROOT_DIR/Common/3dParty/googletest/googletest.pri) - - SOURCES += main.cpp DESTDIR = $$PWD/build diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp index 8dad735ff5..91985ea1b3 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TestSMConverter/main.cpp @@ -1,5 +1,4 @@ -#include "../cstarmathpars.h" -#include "../cconversionsmtoooxml.h" +#include "../conversionmathformula.h" #include "gtest/gtest.h" @@ -7,1421 +6,1137 @@ TEST(SMConvectorTest, BinOperatorPlus) { std::wstring wsBinOperator = L"2 + 3"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"2+3"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorOver) { std::wstring wsBinOperator = L"2 over 3"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"23"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorCdot) { std::wstring wsBinOperator = L"5 cdot 8"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"5\u00B78"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorTimes) { std::wstring wsBinOperator = L"5 times 8"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"5\u00D78"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorMultipl) { std::wstring wsBinOperator = L"4 * 2"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"4*2"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorDiv) { std::wstring wsBinOperator = L"4div2"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"4\u00F72"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorDivision) { std::wstring wsBinOperator = L"4/2"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"42"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorOplus) { std::wstring wsBinOperator = L"226oplus179"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"226\u2295179"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorOdot) { std::wstring wsBinOperator = L"226 odot 179"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"226\u2299179"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,BinOperatorOtimes) { std::wstring wsBinOperator = L"226 otimes 179"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsBinOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"226\u2297179"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsBinOperator),XmlString); } TEST(SMConvectorTest,OperatorSum) { std::wstring wsOperator = L"sum 5"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"5"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsOperator),XmlString); } TEST(SMConvectorTest,OperatorSumFrom) { std::wstring wsOperator = L"sum from 10 5"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"105"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsOperator),XmlString); } TEST(SMConvectorTest,OperatorSumTo) { std::wstring wsOperator = L"sum to 10 5"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"105"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsOperator),XmlString); } TEST(SMConvectorTest,OperatorSumFromTo) { std::wstring wsOperator = L"sum from 666 to 777 567"; - StarMath::CParserStarMathString m_oTempO; - StarMath::CConversionSMtoOOXML m_oTest; - m_oTest.StartConversion(m_oTempO.Parse(wsOperator)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring XmlString = L"666777567"; - EXPECT_EQ(m_oTest.GetOOXML(),XmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsOperator),XmlString); } TEST(SMConvectorTest,SetOperationUnion) { std::wstring wsString = L"23 union 45"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"23\u22C345"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationIntersection) { std::wstring wsString = L"15 intersection 1234"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"15\u22C21234"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationSetminus) { std::wstring wsString = L"7 setminus 15745"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"7\u221615745"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationSetquotient) { std::wstring wsString = L"91 setquotient 45"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"91\u221545"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationSubset) { std::wstring wsString = L"1 subset 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1\u22822"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationSubseteq) { std::wstring wsString = L"77subseteq66"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"77\u228666"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationSupset) { std::wstring wsString = L"11supset22"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"11\u228322"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationSupseteq) { std::wstring wsString = L"1 supseteq 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1\u22872"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationNsubset) { std::wstring wsString = L"21nsubset2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"21\u22842"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationNsubseteq) { std::wstring wsString = L"782nsubseteq250"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"782\u2288250"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationNsupset) { std::wstring wsString = L"1nsupset2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1\u22852"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationNsupseteq) { std::wstring wsString = L"1nsupseteq2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1\u22892"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationIn) { std::wstring wsString = L"1 in 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1\u22082"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationNotin) { std::wstring wsString = L"3 notin 4"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"3\u22094"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SetOperationOwns) { std::wstring wsString = L"5owns6"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"5\u220B6"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDlarrow) { std::wstring wsString = L"7 dlarrow 8"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"7\u21D08"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDlrarrow) { std::wstring wsString = L"9 dlrarrow 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"9\u21D410"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDrarrow) { std::wstring wsString = L"11drarrow12"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"11\u21D212"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionEquals) { std::wstring wsString = L"13=14"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"13=14"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionNotequals) { std::wstring wsString = L"15 <> 16"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"15\u226016"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionLearrow) { std::wstring wsString = L"17<18"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"17<18"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionLearrowequals) { std::wstring wsString = L"19<= 20"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"19\u226420"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionRiarrow) { std::wstring wsString = L"21 >22"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"21>22"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionRiarrowequals) { std::wstring wsString = L"23 >=24"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"23\u226524"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDllearrow) { std::wstring wsString = L"25 <<26"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"25\u226A26"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDlriarrow) { std::wstring wsString = L"27 >> 28"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"27\u226B28"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionApprox) { std::wstring wsString = L"29 approx30"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"29\u224830"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionSim) { std::wstring wsString = L"31sim 32"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"31\u223C32"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionSimeq) { std::wstring wsString = L"33 simeq 34"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"33\u224334"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionEquiv) { std::wstring wsString = L"35 equiv 36"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"35\u226136"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionProp) { std::wstring wsString = L"37 prop 38"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"37\u221D38"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionParallel) { std::wstring wsString = L"39 parallel 30"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"39\u222530"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionOrtho) { std::wstring wsString = L"41ortho42"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"41\u22A542"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDivides) { std::wstring wsString = L"43 divides 44"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"43\u222344"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionNdivides) { std::wstring wsString = L"45 ndivides 46"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"45\u222446"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionToward) { std::wstring wsString = L"47 toward 48"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"47\u219248"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionTransl) { std::wstring wsString = L"49 transl 50"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"49\u22B750"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionTransr) { std::wstring wsString = L"51 transr 52"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"51\u22B652"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionDef) { std::wstring wsString = L"53def54"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"53\u225D54"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionPrec) { std::wstring wsString = L"55prec56"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"55\u227A56"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionSucc) { std::wstring wsString = L"57 succ 58"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"57\u227B58"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionPreccurlyeq) { std::wstring wsString = L"59 preccurlyeq 60"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"59\u227C60"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionSucccurlyeq) { std::wstring wsString = L"61 succcurlyeq 62"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"61\u227D62"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionPrecsim) { std::wstring wsString = L"63 precsim 64"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"63\u227E64"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionSuccsim) { std::wstring wsString = L"65 succsim 66"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"65\u227F66"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionNprec) { std::wstring wsString = L"67nprec68"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"67\u228068"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,ConnectionNsucc) { std::wstring wsString = L"69nsucc70"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"69\u228170"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketRound) { std::wstring wsString = L"(2+3)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2+3"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketSquare) { std::wstring wsString = L"[4-5]"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"4-5"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLdbracket) { std::wstring wsString = L"ldbracket 6+7 rdbracket"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"6+7"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLbrace) { std::wstring wsString = L"lbrace 8 - 9 rbrace"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"8-9"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLangle) { std::wstring wsString = L"langle 10 over 11 rangle"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1011"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLceil) { std::wstring wsString = L"lceil 12 ominus 13 rceil"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"12\u229613"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLfloor) { std::wstring wsString = L"lfloor 14 union 15 rfloor"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"14\u22C315"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLline) { std::wstring wsString = L"lline 16 / 17 rline"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"1617"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLdline) { std::wstring wsString = L"ldline 18 oplus 19 rdline"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"18\u229519"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionCos) { std::wstring wsString = L"cos{2+3}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"cos2+3"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionSin) { std::wstring wsString = L"sin 4 over 5"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"sin45"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionTan) { std::wstring wsString = L"tan{6 / 7}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"tan67"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionCot) { std::wstring wsString = L"cot(8 over 9)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"cot89"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionSinh) { std::wstring wsString = L"sinh 2 supset 3"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"sinh2\u22833"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionCosh) { std::wstring wsString = L"cosh 2 + 3"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"cosh2+3"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionTanh) { std::wstring wsString = L"tanh(11otimes12)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"tanh11\u229712"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionCoth222) { std::wstring wsString = L"coth222"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"coth222"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArcsin) { std::wstring wsString = L"arcsin{13 ominus 14}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"arcsin13\u229614"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArccos) { std::wstring wsString = L"arccos{15 - 16}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"arccos15-16"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArctan) { std::wstring wsString = L"arctan 17 over 18"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"arctan1718"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArccot) { std::wstring wsString = L"arccot 20 + 30"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"arccot20+30"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArsinh) { std::wstring wsString = L"{arsinh{2/3}} over sum from 1 to 5 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"arsinh231510"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArcosh) { std::wstring wsString = L"35 + 27 over {arcosh binom 23 78}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"35+27arcosh2378"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionArtanhArcoth) { std::wstring wsString = L"arcoth 30 subset {artanh 27}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"arcoth30\u2282artanh27"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,MatrixBinom) { std::wstring wsString = L"binom{2 over 7 supset 277}{arcoth 89}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"27\u2283277arcoth89"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,MatrixMatrix) { std::wstring wsString = L"matrix{2 / 8 -5 # sum from 2 over 10 union 3 to 10*10 100 ## cosh(10) # 2 oplus 10over100 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"28-5210\u22C3310*10100cosh102\u229510100"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,MatrixStack) { std::wstring wsString = L"stack{2 over 10 # binom 2 3 # matrix{1 # 2 ## 3 # 4}}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"210231234"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexLower) { std::wstring wsString = L"25 over 1 _ 2 "; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2512"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexUpper) { std::wstring wsString = L"{binom {cos 5} 2 over 4 }^ 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"cos52410"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexLsup) { std::wstring wsString = L"{2 over 7} lsup binom 2+3 {cos 15}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2+3cos1527"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexLsub) { std::wstring wsString = L"2222^10 lsub 2 over 3"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"22222103"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketWithIndexOverbrace) { std::wstring wsString = L"color red size 16 {2/3} overbrace color navy size 18 stack{10 # 100 # 10 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"231010010"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,OperatorLllint) { std::wstring wsString = L"color red bold lllint from color navy bold 2 over color crimson 10 to color green (2 color orange bold + 3) 100"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2102+3100"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketLdlineAttribute) { std::wstring wsString = L"color green left ldline color navy bold 10 over color purple dot underline 100 color orange bold ital + 3 right rdline + ital bold 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"10100+3+10"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example11) { std::wstring wsString = L"f(x) = sum from { n=0 } to { infinity } { {f^{(n)}(x_0) } over { fact{n} } (x-x_0)^n }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"fx=n=0\u221Efnx0n\u0021x-x0n"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,AttributeGrade) { std::wstring wsString = L"color green bold evaluate {E = color black m c^ color yellow 2} from {color crimson b over color teal a} to color navy overstrike infinity"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"E=mc2ba\u221E"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example2) { std::wstring wsString = L"C = %pi cdot d = 2 cdot %pi cdot r"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"C=\u03C0\u00B7d=2\u00B7\u03C0\u00B7r"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example3) { std::wstring wsString = L"c = sqrt{ a^2 + b^2 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"c=a2+b2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example4) { std::wstring wsString = L"vec F = m times vec a"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"F=m\u00D7a"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example5) { std::wstring wsString = L"E = m c^2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"E=mc2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example6) { std::wstring wsString = L"G_{%mu %nu} + %LAMBDA g_{%mu %nu}= frac{8 %pi G}{c^4} T_{%mu %nu}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"G\u03BC\u03BD+\u039Bg\u03BC\u03BD=8\u03C0Gc4T\u03BC\u03BD"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example8) { std::wstring wsString = L"d over dt left( {partial L}over{partial dot q} right) = {partial L}over{partial q}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"ddt\u2202L\u2202q=\u2202L\u2202q"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example9) { std::wstring wsString = L"int from a to b f'(x) dx = f(b) - f(a)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"abf'xdx=fb-fa"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example10) { std::wstring wsString = L"ldline %delta bold{r}(t) rdline approx e^{%lambda t} ldline %delta { bold{r} }_0 rdline"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"\u03B4rt\u2248e\u03BBt\u03B4r0"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,LimAndCsub) { std::wstring wsString = L"{lim from 2 over 10 to 1 5} csub 244"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"lim21015244"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,LimSupAndCsup) { std::wstring wsString = L"limsup from 10 to 2 csup 10 100"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"lim sup10210100"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,OverWithoutLeft) { std::wstring wsString = L"over +- 2_10 5"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString =L"\u00B12105"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Newline) { std::wstring wsString = L"2 over 3 newline 10 csup 2 "; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"23102"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexAndBinOp) { std::wstring wsString = L"2 union 3^4 over 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2\u22C33410"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example7) { std::wstring wsString = L" %DELTA t' = { %DELTA t } over sqrt{ 1 - v^2 over c^2 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"\u0394t'=\u0394t1-v2c2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,UnarySign) { std::wstring wsString = L"3+6 over 9 newline -+5 over 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"3+69\u2213510"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example13) { std::wstring wsString = L"nroot{3}{x^3-7x^2+14x-8}+sqrt{7/8+4/9+nroot{3}{sqrt{7/8+4/9}}}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"3x3-7x2+14x-8+78+49+378+49"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example14) { std::wstring wsString = L"sum_{i=0}^{infinity} {(-1)^i over (2i+1)} x^{2i+1} = sin(x)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"i=0\u221E-1i2i+1x2i+1=sinx"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example15) { std::wstring wsString = L"lim_{x->0} {sin(x) over x} = 1"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"limx\u27940sinxx=1"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example16) { std::wstring wsString = L"int_0^{infinity} x^2 e^{-x} dx = 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"0\u221Ex2e-xdx=2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example17) { std::wstring wsString = L"{a^{2} over b} + {b^{2} over a} >= 2 sqrt{a b}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"a2b+b2a\u22652ab"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Example18) { std::wstring wsString = L"10^1_2lsub5lsup4"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"541021"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexWithColor) { std::wstring wsString = L"bold 2 ^ 3 _4 lsup color blue 5 csub color red 6 csup 7 lsub 8"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"5867243"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionWithColor) { std::wstring wsString = L"func e^ 7_2 lsup 10 2over3"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"10e2723"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IncorrectSizeAndFontInput) { std::wstring wsString = L"size font bolt ital 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"bolt2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IncorrectRGBColorInput) { std::wstring wsString = L"color rgb 255 0 257 2 color rgb 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2550257210"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IncorrectHexColorInput) { std::wstring wsString = L"color hex 161616FF RGB color hex 66 RGB color hex RGB color hex FFAACCFF RGB color hex 99112288FF0000 RGB "; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"RGBRGBRGBRGBRGB"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,IndexWithoutElement) { std::wstring wsString = L"2^_3 "; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"23"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Neg) { std::wstring wsString = L"-1 neg 10 over 5 or 7"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"-1\u00AC105\u22287"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Frac) { std::wstring wsString = L"sum_{n=1}^{ infty} frac{1}{n^2} + frac{1}{n^3} = frac{ pi^2}{6} + zeta(3)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"n=1\u221E1n2+1n3=pi26+zeta3"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,BracketIndexOnTopAndOperationOnSet) { std::wstring wsString = L"3 + 10 over 5 setminus 1 overbrace 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"3+105\u221612"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,SqrtWithIndex) { std::wstring wsString = L"sqrt{2}^{ log_2{8}} = 4"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2log28=4"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Binom) { std::wstring wsString = L"binom 2 = 4 3 binom 2+1abc 5"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2=432+1abc5"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,UnarySignWithColor) { std::wstring wsString = L"color green [color red 2 color blue + 10 setminus color red 5 over 9 underbrace 3 ]"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2+10\u2216593"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,rSubrSup) { std::wstring wsString = L"2 rSub 20 1 rSup 28"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"220128"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,DifferentRegisters) { std::wstring wsString = L"2 OvEr 10 unION 5"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"210\x22C35"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Quotes) { std::wstring wsString = L"\"2 + 3\" over 10 2 \"+\" 5 over 3"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2 + 3102+53"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,NumberWithDot) { std::wstring wsString = L"goal.25 over 100"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"goal.25100"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,OperatorWithoutValue) { std::wstring wsString = L"lim_{x->5}"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"limx\u27945"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,MatrixWithDifferentValues) { std::wstring wsString = L"matrix{2} matrix 2 matrix"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"22"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,StackWithDifferentValues) { std::wstring wsString = L"stack stack{2} stack 2"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"22"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,Partial) { std::wstring wsString = L"{partial f(x)} over { partial x } = ln(x) + tan^-1(x^2)"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"\u2202fx\u2202x=lnx+tan-1x2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,LimWithArrow) { std::wstring wsString = L"lim from { x->1^-"" }{ {x^{2}-1 } over { x-1 }} = 2 "; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"limx\u27941-x2-1x-1=2"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,FunctionWithAttributeAndIndex) { std::wstring wsString = L"{%sigma' = %sigma color red bold func e ^ color blue frac 2 3 }"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"\u03C3'=\u03C3e23"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } TEST(SMConvectorTest,UnarPlusMinus) { std::wstring wsString = L"2 color red + - 4 over 10"; - StarMath::CParserStarMathString oTemp; - StarMath::CConversionSMtoOOXML oTest; - oTest.StartConversion(oTemp.Parse(wsString)); + StarMath::CStarMathConverter oConverterStarMath; std::wstring wsXmlString = L"2+-410"; - EXPECT_EQ(oTest.GetOOXML(),wsXmlString); + EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); } //TEST(SMConvectorTest,AttributeMatrix) //{ // std::wstring wsString = L""; -// StarMath::CParserStarMathString oTemp; -// StarMath::CConversionSMtoOOXML oTest; -// oTest.StartConversion(oTemp.Parse(wsString)); +// StarMath::CStarMathConverter oConverterStarMath; // std::wstring wsXmlString = L""; -// EXPECT_EQ(oTest.GetOOXML(),wsXmlString); +// EXPECT_EQ(oConverterStarMath.ConvertStarMathToOOXml(wsString),wsXmlString); //} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp index 3d34428884..0b720870f3 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp @@ -42,7 +42,7 @@ namespace StarMath { delete m_pXmlWrite; } //check XMLWrite(if not nullptr == delete) - void CConversionSMtoOOXML::StartConversion(std::vector arPars, const unsigned int& iAlignment) + void CConversionSMtoOOXML::StartConversion(const std::vector arPars, const unsigned int& iAlignment) { m_pXmlWrite = new XmlUtils::CXmlWriter; if(!arPars.empty()) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h index 2a500557ae..cbccf12664 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h @@ -39,7 +39,7 @@ namespace StarMath { public: CConversionSMtoOOXML(); ~CConversionSMtoOOXML(); - void StartConversion(std::vector arPars, const unsigned int& iAlignment = 1); + void StartConversion(const std::vector arPars, const unsigned int& iAlignment = 1); static void StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion& enTypeConversion, const TypeLanguage& enTypeLang = TypeLanguage::Russian); static void PropertiesMFPR(const std::wstring& wsType,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); static void PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion,const bool& bEQN = false); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.cpp new file mode 100644 index 0000000000..e30aeb694b --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.cpp @@ -0,0 +1,69 @@ +#include "conversionmathformula.h" +#include "cconversionsmtoooxml.h" +#include "cstarmathpars.h" +#include "TFormulaSize.h" + +namespace StarMath +{ + + CStarMathConverter::CStarMathConverter():m_pParser(nullptr) + { + m_pParser = new CParserStarMathString; + } + CStarMathConverter::~CStarMathConverter() + { + if(m_pParser != nullptr) + delete m_pParser; + } + + void CStarMathConverter::SetBaseFont(const std::wstring &wsNameFont) + { + if(m_pParser != nullptr) + m_pParser->SetBaseFont(wsNameFont); + } + + void CStarMathConverter::SetBaseSize(const unsigned int &nSize) + { + if(m_pParser != nullptr) + m_pParser->SetBaseSize(nSize); + } + + void CStarMathConverter::SetBaseAlignment(const unsigned int &nAlignment) + { + if(m_pParser != nullptr) + m_pParser->SetBaseAlignment(nAlignment); + } + + void CStarMathConverter::SetBaseItalic(bool bItal) + { + if(m_pParser != nullptr) + m_pParser->SetBaseItalic(bItal); + } + + void CStarMathConverter::SetBaseBold(bool bBold) + { + if(m_pParser != nullptr) + m_pParser->SetBaseBold(bBold); + } + + std::queue CStarMathConverter::GetFormulaSize() + { + if(m_pParser != nullptr) + return m_pParser->GetFormulaSize(); + return std::queue{}; + } + + std::wstring CStarMathConverter::ConvertStarMathToOOXml(const std::wstring &wsFormula, const unsigned int &iTypeConversion) + { + StarMath::CConversionSMtoOOXML oConverterSM; + oConverterSM.StartConversion(m_pParser->Parse(wsFormula,iTypeConversion),m_pParser->GetAlignment()); + return oConverterSM.GetOOXML(); + } + std::wstring CStarMathConverter::ConvertEQNToOOXml(const std::wstring& wsFormula) + { + StarMath::CConversionSMtoOOXML oConverterEQN; + oConverterEQN.StartConversion(StarMath::CParserStarMathString().ParseEQN(wsFormula)); + return oConverterEQN.GetOOXML(); + } + +} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.h b/OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.h new file mode 100644 index 0000000000..e238d0c5ee --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/conversionmathformula.h @@ -0,0 +1,37 @@ +#ifndef CONVERSIONMATHFORMULA_H +#define CONVERSIONMATHFORMULA_H + +#ifndef STARMATH_USE_DYNAMIC_LIBRARY +#define STARMATH_DECL_EXPORT +#else +#include "../../../../DesktopEditor/common/base_export.h" +#define STARMATH_DECL_EXPORT Q_DECL_EXPORT +#endif + +#include "TFormulaSize.h" +#include +#include + +namespace StarMath +{ + class CParserStarMathString; + class STARMATH_DECL_EXPORT CStarMathConverter + { + public: + CStarMathConverter(); + ~CStarMathConverter(); + void SetBaseFont(const std::wstring& wsNameFont); + void SetBaseSize(const unsigned int& nSize); + void SetBaseAlignment(const unsigned int& nAlignment); + void SetBaseItalic(bool bItal); + void SetBaseBold(bool bBold); + std::queue GetFormulaSize(); + std::wstring ConvertStarMathToOOXml(const std::wstring& wsFormula,const unsigned int& iTypeConversion = 0); + std::wstring ConvertEQNToOOXml(const std::wstring& wsFormula); + private: + CParserStarMathString* m_pParser; + }; + +} + +#endif // CONVERSIONMATHFORMULA_H diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp index 93184c69f0..8ab4d3f9a7 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp @@ -1,5 +1,4 @@ #include "cooxml2odf.h" -#include namespace StarMath { diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h index be98268bcf..00d8b6f8ce 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace StarMath { diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index ffe290c33a..7e0e36549a 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -43,11 +43,10 @@ namespace StarMath for(CElement* pElement:m_arEquation) delete pElement; } - std::vector CParserStarMathString::Parse(std::wstring& wsParseString, int iTypeConversion) + std::vector CParserStarMathString::Parse(const std::wstring &wsParseString,const int& iTypeConversion) { TypeConversion enTypeConvers = (TypeConversion)iTypeConversion; - std::wstring::iterator itStart = wsParseString.begin(),itEnd = wsParseString.end(); - CStarMathReader* pReader = new CStarMathReader(itStart,itEnd,enTypeConvers); + CStarMathReader* pReader = new CStarMathReader(wsParseString,enTypeConvers); pReader->SetBaseAttribute(m_stBaseAttribute); while(pReader->CheckIteratorPosition()) { @@ -85,10 +84,9 @@ namespace StarMath m_qSize.push(tSize); return m_arEquation; } - std::vector CParserStarMathString::ParseEQN(std::wstring &wsParseString) + std::vector CParserStarMathString::ParseEQN(const std::wstring &wsParseString) { - std::wstring::iterator itStart = wsParseString.begin(),itEnd = wsParseString.end(); - CStarMathReader* pReader = new CStarMathReader(itStart,itEnd,TypeConversion::docx,true); + CStarMathReader* pReader = new CStarMathReader(wsParseString,TypeConversion::docx,true); while(pReader->CheckIteratorPosition()) { CElement* pTempElement = ParseElementEQN(pReader); @@ -4030,11 +4028,11 @@ namespace StarMath return tSizeTo; } // class methods CStarMathReader - CStarMathReader::CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd, const TypeConversion &enTypeConversion, const bool &bEQN) - : m_enGlobalType(TypeElement::Empty),m_enUnderType(TypeElement::Empty),m_pAttribute(nullptr),m_bMarkForUnar(true),m_enTypeCon(enTypeConversion),m_pBaseAttribute(nullptr),m_bEQN(bEQN) + CStarMathReader::CStarMathReader(const std::wstring &wsFormula, const TypeConversion &enTypeConversion, const bool &bEQN) + : m_wsFormula(wsFormula),m_enGlobalType(TypeElement::Empty),m_enUnderType(TypeElement::Empty),m_pAttribute(nullptr),m_bMarkForUnar(true),m_enTypeCon(enTypeConversion),m_pBaseAttribute(nullptr),m_bEQN(bEQN) { - m_itStart = itStart; - m_itEnd = itEnd; + m_itStart = m_wsFormula.begin(); + m_itEnd = m_wsFormula.end(); } CStarMathReader::~CStarMathReader() { diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 815724a8a7..3dcce5d4dd 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -35,6 +35,7 @@ #include "typeselements.h" #include "typeConversion.h" #include "TypeLanguage.h" +#include "TFormulaSize.h" #include #include #include @@ -58,18 +59,6 @@ namespace StarMath bool base_font_italic; }; - struct TFormulaSize - { - TFormulaSize():m_iHeight(0),m_iWidth(0) {}; - TFormulaSize(const unsigned int& iHeight,const unsigned int& iwidth):m_iHeight(iHeight),m_iWidth(iwidth) {}; - float m_iHeight; - float m_iWidth; - void Zeroing() - { - this->m_iHeight = 0; - this->m_iWidth = 0; - } - }; class CAttribute { public: @@ -119,7 +108,7 @@ namespace StarMath class CStarMathReader { public: - CStarMathReader(std::wstring::iterator& itStart, std::wstring::iterator& itEnd,const TypeConversion &enTypeConversion,const bool& bEQN = false); + CStarMathReader(const std::wstring& wsFormula,const TypeConversion &enTypeConversion,const bool& bEQN = false); ~CStarMathReader(); bool GetToken(); //getting a subtype and setting the global type of a token to variables m_enUnderType and m_enGlobalType @@ -158,6 +147,7 @@ namespace StarMath bool CheckTokenForGetElement(const wchar_t& cToken); bool CheckIsalhpaForGetElement(const wchar_t& cToken,const wchar_t& cLastToken); bool m_bMarkForUnar; + std::wstring m_wsFormula; std::wstring::iterator m_itStart,m_itEnd; TypeElement m_enGlobalType,m_enUnderType; std::wstring m_wsLowerCaseToken,m_wsOriginalToken; @@ -518,8 +508,8 @@ namespace StarMath public: CParserStarMathString(); ~CParserStarMathString(); - std::vector Parse(std::wstring& wsParseString,int iTypeConversion = 0); - std::vector ParseEQN(std::wstring& wsParseString); + std::vector Parse(const std::wstring& wsParseString, const int &iTypeConversion = 0); + std::vector ParseEQN(const std::wstring& wsParseString); static CElement* ParseElement(CStarMathReader* pReader); static CElement* ParseElementEQN(CStarMathReader* pReader); //Function for adding a left argument (receives the argument itself and the element to which it needs to be added as input. Works with classes:CElementBinOperator,CElementConnection,CElementSetOperation). diff --git a/OdfFile/Reader/Format/math_elements.cpp b/OdfFile/Reader/Format/math_elements.cpp index ea93ff98cd..3879deea5a 100644 --- a/OdfFile/Reader/Format/math_elements.cpp +++ b/OdfFile/Reader/Format/math_elements.cpp @@ -31,7 +31,8 @@ */ #include "math_elements.h" -#include "../Converter/StarMath2OOXML/cconversionsmtoooxml.h" +// #include "../Converter/StarMath2OOXML/cconversionsmtoooxml.h" +#include "../Converter/StarMath2OOXML/conversionmathformula.h" namespace cpdoccore { @@ -109,18 +110,16 @@ void math_semantics::oox_convert(oox::math_context &Context, int iTypeConversion if (!annotation_text.empty()) { result = true; - StarMath::CParserStarMathString parser; - StarMath::CConversionSMtoOOXML converter; - - parser.SetBaseFont(Context.base_font_name_); - parser.SetBaseSize(Context.base_font_size_); - parser.SetBaseAlignment(Context.base_alignment_); - parser.SetBaseItalic(Context.base_font_italic_); - parser.SetBaseBold(Context.base_font_bold_); - converter.StartConversion(parser.Parse(annotation_text,iTypeConversion),parser.GetAlignment()); + StarMath::CStarMathConverter oConverterStarMath; - auto sizes = parser.GetFormulaSize(); + oConverterStarMath.SetBaseFont(Context.base_font_name_); + oConverterStarMath.SetBaseSize(Context.base_font_size_); + oConverterStarMath.SetBaseAlignment(Context.base_alignment_); + oConverterStarMath.SetBaseItalic(Context.base_font_italic_); + oConverterStarMath.SetBaseBold(Context.base_font_bold_); + + std::queue sizes = oConverterStarMath.GetFormulaSize(); for (;!sizes.empty(); sizes.pop()) { @@ -129,12 +128,12 @@ void math_semantics::oox_convert(oox::math_context &Context, int iTypeConversion Context.height += sizes.front().m_iHeight; } - Context.output_stream() << converter.GetOOXML(); + Context.output_stream() << oConverterStarMath.ConvertStarMathToOOXml(annotation_text,iTypeConversion); } if (!result) { - Context.output_stream() << L""; + Context.output_stream() << L""; Context.output_stream() << L""; for (size_t i = 0; i < content_.size(); i++) { diff --git a/X2tConverter/build/Qt/X2tConverter.pri b/X2tConverter/build/Qt/X2tConverter.pri index 656d131de3..edfc2423ca 100644 --- a/X2tConverter/build/Qt/X2tConverter.pri +++ b/X2tConverter/build/Qt/X2tConverter.pri @@ -133,7 +133,7 @@ LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib #All dynamic libs -ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network, Fb2File, PdfFile, HtmlFile2, EpubFile, XpsFile, OFDFile, DjVuFile, doctrenderer, DocxRenderer, IWorkFile, HWPFile) +ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network, Fb2File, PdfFile, HtmlFile2, EpubFile, XpsFile, OFDFile, DjVuFile, doctrenderer, DocxRenderer, IWorkFile, HWPFile, StarMathConverter) ##################################################### # внешнее подключение сторонних библиотек From 2931c4b53ec55545726b41e33e0eb2cb84ec9469 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Thu, 25 Sep 2025 13:58:55 +0300 Subject: [PATCH 012/125] Aff offset metafile command --- DesktopEditor/graphics/GraphicsPath.cpp | 27 +++++++++++++ DesktopEditor/graphics/GraphicsPath.h | 1 + DesktopEditor/graphics/GraphicsRenderer.cpp | 26 +++++++++++++ DesktopEditor/graphics/GraphicsRenderer.h | 2 + DesktopEditor/graphics/IRenderer.h | 7 +++- DesktopEditor/graphics/MetafileToRenderer.cpp | 38 +++++++++++++++++-- DesktopEditor/graphics/MetafileToRenderer.h | 1 + 7 files changed, 97 insertions(+), 5 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsPath.cpp b/DesktopEditor/graphics/GraphicsPath.cpp index 4f15063441..6c595af456 100644 --- a/DesktopEditor/graphics/GraphicsPath.cpp +++ b/DesktopEditor/graphics/GraphicsPath.cpp @@ -462,6 +462,33 @@ namespace Aggplus return Ok; } + CGraphicsPath CGraphicsPath::Trsanslate(const double& offsetX, const double& offsetY) + { + CGraphicsPath result; + result.StartFigure(); + + unsigned length = GetPointCount(); + std::vector points = GetPoints(0, length); + + for (unsigned i = 0; i < length; i++) + { + if (IsCurvePoint(i)) + { + result.CurveTo(points[i].X + offsetX, points[i].Y + offsetY, + points[i + 1].X + offsetX, points[i + 1].Y + offsetY, + points[i + 2].X + offsetX, points[i + 2].Y + offsetY); + i += 2; + } + else if (IsMovePoint(i)) + result.MoveTo(points[i].X + offsetX, points[i].Y + offsetY); + else if (IsLinePoint(i)) + result.LineTo(points[i].X + offsetX, points[i].Y + offsetY); + } + result.CloseFigure(); + + return result; + } + bool CGraphicsPath::_MoveTo(double x, double y) { if (NULL != m_internal->m_pTransform) diff --git a/DesktopEditor/graphics/GraphicsPath.h b/DesktopEditor/graphics/GraphicsPath.h index a0fe6bcdeb..4db6117165 100644 --- a/DesktopEditor/graphics/GraphicsPath.h +++ b/DesktopEditor/graphics/GraphicsPath.h @@ -84,6 +84,7 @@ namespace Aggplus void GetBoundsAccurate(double& left, double& top, double& width, double& height) const; Status Transform(const CMatrix* matrix); + CGraphicsPath Trsanslate(const double& offsetX, const double& offsetY); virtual bool _MoveTo(double x, double y); virtual bool _LineTo(double x, double y); virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3); diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 9b0c684e55..0444d5dab2 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -1130,6 +1130,32 @@ HRESULT CGraphicsRenderer::PathCommandTextEx(const std::wstring& bsUnicodeText, return PathCommandText(bsUnicodeText, x, y, w, h); } +HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path) +{ + if (path.GetPointCount() == 0) + return S_FALSE; + + size_t length = path.GetPointCount(); + std::vector points = path.GetPoints(0, length); + + for (size_t i = 0; i < length; i++) + { + if (path.IsCurvePoint(i)) + { + PathCommandCurveTo(points[i].X, points[i].Y, + points[i + 1].X, points[i + 1].Y, + points[i + 2].X, points[i + 2].Y); + i += 2; + } + else if (path.IsMovePoint(i)) + PathCommandMoveTo(points[i].X, points[i].Y); + else + PathCommandLineTo(points[i].X, points[i].Y); + } + + return S_OK; +} + //-------- Функции для вывода изображений --------------------------------------------------- HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) { diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index d5cd633616..b847070872 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -239,6 +239,8 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h); virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h); + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path); + //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h); virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 0f46a733e7..019fc78a61 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -167,7 +167,10 @@ public: AdvancedCommandType GetCommandType() { return m_nCommandType; } }; -namespace Aggplus { class CImage; } +namespace Aggplus { + class CImage; + class CGraphicsPath; +} // IRenderer class IRenderer : public IGrObject @@ -298,6 +301,8 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0; virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0; + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) = 0; + //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0; virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0; diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 4dd5557a2e..5ac2f47317 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -36,6 +36,7 @@ #include "../fontengine/FontManager.h" #include "../raster/BgraFrame.h" #include "../common/StringExt.h" +#include "../GraphicsPath.h" // этот класс нужно переписать. должно работать как и в js // а не просто на каждом символе переключаться, если нужно @@ -352,6 +353,10 @@ namespace NSOnlineOfficeBinToPdf bool bIsEnableBrushRect = false; CBufferReader oReader(pBuffer, lBufferLen); + Aggplus::CGraphicsPath path; + Aggplus::CGraphicsPath clipPath; + bool isClip = false; + bool isClose = false; while (oReader.Check()) { eCommand = (CommandType)(oReader.ReadByte()); @@ -611,6 +616,7 @@ namespace NSOnlineOfficeBinToPdf pRenderer->BeginCommand(c_nPathType); pRenderer->PathCommandStart(); + path.StartFigure(); bIsPathOpened = true; break; @@ -619,14 +625,14 @@ namespace NSOnlineOfficeBinToPdf { double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); - pRenderer->PathCommandMoveTo(m1, m2); + path.MoveTo(m1, m2); break; } case ctPathCommandLineTo: { double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); - pRenderer->PathCommandLineTo(m1, m2); + path.LineTo(m1, m2); break; } case ctPathCommandCurveTo: @@ -637,12 +643,13 @@ namespace NSOnlineOfficeBinToPdf double m4 = oReader.ReadDouble(); double m5 = oReader.ReadDouble(); double m6 = oReader.ReadDouble(); - pRenderer->PathCommandCurveTo(m1, m2, m3, m4, m5, m6); + path.CurveTo(m1, m2, m3, m4, m5, m6); break; } case ctPathCommandClose: { - pRenderer->PathCommandClose(); + path.CloseFigure(); + isClose = true; break; } case ctPathCommandEnd: @@ -655,9 +662,32 @@ namespace NSOnlineOfficeBinToPdf } break; } + case ctPathCommandOffset: + { + double m1 = oReader.ReadDouble(); + double m2 = oReader.ReadDouble(); + isClip = true; + clipPath = path.Trsanslate(m1, m2); + } case ctDrawPath: { + if (isClip) + { + path = Aggplus::CalcBooleanOperation(path, clipPath, Aggplus::Intersection); + clipPath.Reset(); + isClip = false; + } + + pRenderer->AddPath(path); + + if (isClose) + { + pRenderer->PathCommandClose(); + isClose = false; + } + pRenderer->DrawPath(oReader.ReadInt()); + path.Reset(); break; } case ctDrawImageFromFile: diff --git a/DesktopEditor/graphics/MetafileToRenderer.h b/DesktopEditor/graphics/MetafileToRenderer.h index cde5dbd504..cad6f8b4c7 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.h +++ b/DesktopEditor/graphics/MetafileToRenderer.h @@ -153,6 +153,7 @@ namespace NSOnlineOfficeBinToPdf ctPathCommandGetCurrentPoint = 101, ctPathCommandText = 102, ctPathCommandTextEx = 103, + ctPathCommandOffset = 104, // image ctDrawImage = 110, From c8ebcfac8795e926afc87c64b7a342ee8d22d5d4 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Thu, 25 Sep 2025 16:12:07 +0300 Subject: [PATCH 013/125] Add offset for brush rect --- DesktopEditor/graphics/GraphicsRenderer.cpp | 6 ++++++ DesktopEditor/graphics/GraphicsRenderer.h | 1 + DesktopEditor/graphics/IRenderer.h | 1 + DesktopEditor/graphics/MetafileToRenderer.cpp | 13 ++++++++++++- DesktopEditor/graphics/aggplustypes.h | 13 +++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 0444d5dab2..40d535d391 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -622,6 +622,12 @@ HRESULT CGraphicsRenderer::BrushRect(const INT& val, const double& left, const d m_oBrush.Rect.Height = (float)height; return S_OK; } +HRESULT CGraphicsRenderer::get_BrushRect(Aggplus::RectF& rect, bool& rectable) const +{ + rectable = m_oBrush.Rectable; + rect = m_oBrush.Rect; + return S_OK; +} HRESULT CGraphicsRenderer::BrushBounds(const double& left, const double& top, const double& width, const double& height) { m_oBrush.Bounds.left = left; diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index b847070872..37cdc73fb3 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -190,6 +190,7 @@ public: virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix); virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix); virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); + virtual HRESULT get_BrushRect(Aggplus::RectF& rect, bool& rectable) const; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height); virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 019fc78a61..4f9e9fdef5 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -243,6 +243,7 @@ public: virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0; virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0; virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0; + virtual HRESULT get_BrushRect(Aggplus::RectF& rect, bool& rectable) const = 0; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0; virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount) = 0; diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 5ac2f47317..d3b74d631a 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -664,9 +664,20 @@ namespace NSOnlineOfficeBinToPdf } case ctPathCommandOffset: { + isClip = true; + double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); - isClip = true; + + Aggplus::RectF rect; + bool rectable; + pRenderer->get_BrushRect(rect, rectable); + if (rectable) + { + rect.Offset(m1, m2); + pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); + } + clipPath = path.Trsanslate(m1, m2); } case ctDrawPath: diff --git a/DesktopEditor/graphics/aggplustypes.h b/DesktopEditor/graphics/aggplustypes.h index 74b6f83e09..fc10bd1033 100644 --- a/DesktopEditor/graphics/aggplustypes.h +++ b/DesktopEditor/graphics/aggplustypes.h @@ -212,6 +212,19 @@ public: void Offset(const PointF_T& point) { Offset(point.X, point.Y); } void Offset(T dx, T dy) { X += dx; Y += dy; } + RectF_T& operator=(const RectF_T& other) + { + if (this == &other) + return *this; + + X = other.X; + Y = other.Y; + Width = other.Width; + Height = other.Height; + + return *this; + }; + public: T X, Y, Width, Height; }; From dec13334dbacc8ca68a8fdba94e030374312549b Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Mon, 20 Oct 2025 16:57:13 +0300 Subject: [PATCH 014/125] Add not rotation with shape --- DesktopEditor/graphics/MetafileToRenderer.cpp | 42 +++++++++++++------ DesktopEditor/graphics/MetafileToRenderer.h | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index d3b74d631a..2736ae2f86 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -352,10 +352,12 @@ namespace NSOnlineOfficeBinToPdf bool bIsPathOpened = false; bool bIsEnableBrushRect = false; + double old_t1, old_t2, old_t3, old_t4, old_t5, old_t6; + CBufferReader oReader(pBuffer, lBufferLen); Aggplus::CGraphicsPath path; - Aggplus::CGraphicsPath clipPath; - bool isClip = false; + Aggplus::CMatrix transMatrRot; + Aggplus::CMatrix transMatrOff; bool isClose = false; while (oReader.Check()) { @@ -595,6 +597,26 @@ namespace NSOnlineOfficeBinToPdf pRenderer->put_BrushTextureAlpha(lAlpha); break; } + case ctBrushResetRotation: + { + Aggplus::RectF rect; + bool rectable; + pRenderer->get_BrushRect(rect, rectable); + + pRenderer->GetTransform(&old_t1, &old_t2, &old_t3, &old_t4, &old_t5, &old_t6); + Aggplus::CMatrix mtr(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); + + double rot = mtr.rotation(); + mtr.Rotate(-agg::rad2deg(rot)); + mtr.Translate((cos(atan2(rect.Height, rect.Width) + rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Width) / 2.0, + (sin(atan2(rect.Height, rect.Width) + rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Height) / 2.0); + + pRenderer->SetTransform(mtr.sx(), mtr.shy(), mtr.shx(), mtr.sy(), mtr.tx(), mtr.ty()); + transMatrRot.Rotate(rot, Aggplus::MatrixOrderAppend); + transMatrRot.Translate((cos(atan2(rect.Height, rect.Width) - rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Width) / 2.0, + (sin(atan2(rect.Height, rect.Width) - rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Height) / 2.0); + break; + } case ctSetTransform: { double m1 = oReader.ReadDouble(); @@ -664,8 +686,6 @@ namespace NSOnlineOfficeBinToPdf } case ctPathCommandOffset: { - isClip = true; - double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); @@ -678,18 +698,16 @@ namespace NSOnlineOfficeBinToPdf pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); } - clipPath = path.Trsanslate(m1, m2); + transMatrOff.Translate(m1, m2); + break; } case ctDrawPath: { - if (isClip) - { - path = Aggplus::CalcBooleanOperation(path, clipPath, Aggplus::Intersection); - clipPath.Reset(); - isClip = false; - } + Aggplus::CGraphicsPath clipPath1(path), clipPath2(path); + clipPath1.Transform(&transMatrRot); + clipPath2.Transform(&transMatrOff); - pRenderer->AddPath(path); + pRenderer->AddPath(Aggplus::CalcBooleanOperation(clipPath1, clipPath2, Aggplus::Intersection)); if (isClose) { diff --git a/DesktopEditor/graphics/MetafileToRenderer.h b/DesktopEditor/graphics/MetafileToRenderer.h index cad6f8b4c7..9e76355e76 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.h +++ b/DesktopEditor/graphics/MetafileToRenderer.h @@ -108,6 +108,7 @@ namespace NSOnlineOfficeBinToPdf ctBrushRectableEnabled = 30, ctBrushGradient = 31, ctBrushTexturePath = 32, + ctBrushResetRotation = 33, // font ctFontXML = 40, From 5a491aea3ef10d66a4ee9a0208c334462cfde1b8 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 21 Oct 2025 17:04:30 +0300 Subject: [PATCH 015/125] Read Link annots --- .../graphics/pro/js/wasm/js/drawingfile.js | 27 ++ .../pro/js/wasm/src/drawingfile_test.cpp | 38 +++ PdfFile/PdfReader.cpp | 4 +- PdfFile/SrcReader/PdfAnnot.cpp | 257 +++++++++++++----- PdfFile/SrcReader/PdfAnnot.h | 21 +- PdfFile/lib/xpdf/Page.cc | 2 +- 6 files changed, 281 insertions(+), 68 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index ba24184e09..fa99a0ae5b 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -1027,6 +1027,33 @@ function readAnnotType(reader, rec, readDoubleFunc, readDouble2Func, readStringF rec["font"]["style"] = reader.readInt(); } } + // Link + else if (rec["type"] == 1) + { + flags = reader.readInt(); + if (flags & (1 << 0)) + { + rec["A"] = {}; + readAction(reader, rec["A"], readDoubleFunc, readStringFunc); + } + if (flags & (1 << 1)) + { + rec["PA"] = {}; + readAction(reader, rec["PA"], readDoubleFunc, readStringFunc); + } + // Selection mode - H + // 0 - none, 1 - invert, 2 - push, 3 - outline + if (flags & (1 << 2)) + rec["highlight"] = reader.readByte(); + // QuadPoints + if (flags & (1 << 3)) + { + let n = reader.readInt(); + rec["QuadPoints"] = []; + for (let i = 0; i < n; ++i) + rec["QuadPoints"].push(readDoubleFunc.call(reader)); + } + } } function readWidgetType(reader, rec, readDoubleFunc, readDouble2Func, readStringFunc, isRead = false) { diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 1629ee7d95..2a403e4dc6 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -2132,6 +2132,44 @@ int main(int argc, char* argv[]) std::cout << nPathLength << ", "; } } + else if (sType == "Link") + { + nFlags = READ_INT(pAnnots + i); + i += 4; + if (nFlags & (1 << 0)) + { + std::cout << std::endl << "A "; + ReadAction(pAnnots, i); + std::cout << std::endl; + } + if (nFlags & (1 << 1)) + { + std::cout << std::endl << "PA "; + ReadAction(pAnnots, i); + std::cout << std::endl; + } + if (nFlags & (1 << 2)) + { + std::string arrHighlighting[] = {"none", "invert", "push", "outline"}; + nPathLength = READ_BYTE(pAnnots + i); + i += 1; + std::cout << "Highlight " << arrHighlighting[nPathLength] << ", "; + } + if (nFlags & (1 << 3)) + { + std::cout << "QuadPoints"; + int nQuadPointsLength = READ_INT(pAnnots + i); + i += 4; + + for (int j = 0; j < nQuadPointsLength; ++j) + { + nPathLength = READ_INT(pAnnots + i); + i += 4; + std::cout << " " << (double)nPathLength / 100.0; + } + std::cout << ", "; + } + } std::cout << std::endl << "]" << std::endl; } diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 7b30acc4aa..1d23b2204a 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -1221,6 +1221,7 @@ BYTE* CPdfReader::GetLinks(int _nPageIndex) NSWasm::CPageLink oLinks; // Гиперссылка + /* Links* pLinks = pDoc->getLinks(nPageIndex); if (pLinks) { @@ -1298,6 +1299,7 @@ BYTE* CPdfReader::GetLinks(int _nPageIndex) } } RELEASEOBJECT(pLinks); + */ int nRotate = 0; #ifdef BUILDING_WASM_MODULE @@ -2037,7 +2039,7 @@ int GetPageAnnots(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, PdfReader } else if (sType == "Link") { - + pAnnot = new PdfReader::CAnnotLink(pdfDoc, &oAnnotRef, nPageIndex, nStartRefID); } else if (sType == "FreeText") { diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 5da48648f9..9d4bbfd824 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -103,6 +103,91 @@ TextString* getFullFieldName(Object* oField) return sResName; } +CActionGoTo* getGoTo(PDFDoc* pdfDoc, LinkAction* oAct) +{ + if (!oAct || oAct->getKind() != actionGoTo) + return NULL; + + GString* str = ((LinkGoTo*)oAct)->getNamedDest(); + LinkDest* pLinkDest = str ? pdfDoc->findDest(str) : ((LinkGoTo*)oAct)->getDest(); + if (!pLinkDest) + { + RELEASEOBJECT(oAct); + return NULL; + } + CActionGoTo* ppRes = new CActionGoTo(); + if (pLinkDest->isPageRef()) + { + Ref pageRef = pLinkDest->getPageRef(); + ppRes->unPage = pdfDoc->findPage(pageRef.num, pageRef.gen); + } + else + ppRes->unPage = pLinkDest->getPageNum(); + + if (ppRes->unPage > 0) + --ppRes->unPage; + ppRes->nKind = pLinkDest->getKind(); + + PDFRectangle* pCropBox = pdfDoc->getCatalog()->getPage(ppRes->unPage + 1)->getCropBox(); + double dHeight = pCropBox->y2; + double dX = pCropBox->x1; + switch (ppRes->nKind) + { + case destXYZ: + case destFitH: + case destFitBH: + case destFitV: + case destFitBV: + { + ppRes->unKindFlag = 0; + // 0 - left + if (pLinkDest->getChangeLeft()) + { + ppRes->unKindFlag |= (1 << 0); + ppRes->pRect[0] = pLinkDest->getLeft() - dX; + } + // 1 - top + if (pLinkDest->getChangeTop()) + { + ppRes->unKindFlag |= (1 << 1); + ppRes->pRect[1] = dHeight - pLinkDest->getTop(); + } + // 2 - zoom + if (pLinkDest->getChangeZoom() && pLinkDest->getZoom()) + { + ppRes->unKindFlag |= (1 << 2); + ppRes->pRect[2] = pLinkDest->getZoom(); + } + break; + } + case destFitR: + { + ppRes->pRect[0] = pLinkDest->getLeft() - dX; + ppRes->pRect[1] = dHeight - pLinkDest->getTop(); + ppRes->pRect[2] = pLinkDest->getRight() - dX; + ppRes->pRect[3] = dHeight - pLinkDest->getBottom(); + break; + } + case destFit: + case destFitB: + default: + break; + } + if (str) + RELEASEOBJECT(pLinkDest); + return ppRes; +} +CAction* getDest(PDFDoc* pdfDoc, Object* oDest) +{ + LinkAction* oAct = LinkAction::parseDest(oDest); + if (!oAct) + return NULL; + + CAction* pRes = getGoTo(pdfDoc, oAct); + + RELEASEOBJECT(oAct); + return pRes; +} CAction* getAction(PDFDoc* pdfDoc, Object* oAction) { Object oActType; @@ -122,71 +207,7 @@ CAction* getAction(PDFDoc* pdfDoc, Object* oAction) // Переход внутри файла case actionGoTo: { - GString* str = ((LinkGoTo*)oAct)->getNamedDest(); - LinkDest* pLinkDest = str ? pdfDoc->findDest(str) : ((LinkGoTo*)oAct)->getDest(); - if (!pLinkDest) - break; - CActionGoTo* ppRes = new CActionGoTo(); - if (pLinkDest->isPageRef()) - { - Ref pageRef = pLinkDest->getPageRef(); - ppRes->unPage = pdfDoc->findPage(pageRef.num, pageRef.gen); - } - else - ppRes->unPage = pLinkDest->getPageNum(); - - if (ppRes->unPage > 0) - --ppRes->unPage; - ppRes->nKind = pLinkDest->getKind(); - - PDFRectangle* pCropBox = pdfDoc->getCatalog()->getPage(ppRes->unPage + 1)->getCropBox(); - double dHeight = pCropBox->y2; - double dX = pCropBox->x1; - switch (ppRes->nKind) - { - case destXYZ: - case destFitH: - case destFitBH: - case destFitV: - case destFitBV: - { - ppRes->unKindFlag = 0; - // 0 - left - if (pLinkDest->getChangeLeft()) - { - ppRes->unKindFlag |= (1 << 0); - ppRes->pRect[0] = pLinkDest->getLeft() - dX; - } - // 1 - top - if (pLinkDest->getChangeTop()) - { - ppRes->unKindFlag |= (1 << 1); - ppRes->pRect[1] = dHeight - pLinkDest->getTop(); - } - // 2 - zoom - if (pLinkDest->getChangeZoom() && pLinkDest->getZoom()) - { - ppRes->unKindFlag |= (1 << 2); - ppRes->pRect[2] = pLinkDest->getZoom(); - } - break; - } - case destFitR: - { - ppRes->pRect[0] = pLinkDest->getLeft() - dX; - ppRes->pRect[1] = dHeight - pLinkDest->getTop(); - ppRes->pRect[2] = pLinkDest->getRight() - dX; - ppRes->pRect[3] = dHeight - pLinkDest->getBottom(); - break; - } - case destFit: - case destFitB: - default: - break; - } - if (str) - RELEASEOBJECT(pLinkDest); - pRes = ppRes; + pRes = getGoTo(pdfDoc, oAct); break; } // Переход к внешнему файлу @@ -1652,6 +1673,92 @@ CAnnotPopup::CAnnotPopup(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex, int oAnnot.free(); } +//------------------------------------------------------------------------ +// Link +//------------------------------------------------------------------------ + +CAnnotLink::CAnnotLink(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex, int nStartRefID) : CAnnot(pdfDoc, oAnnotRef, nPageIndex, nStartRefID) +{ + m_unFlags = 0; + m_pAction = NULL; + m_pPA = NULL; + + Object oAnnot, oObj, oObj2; + XRef* pXref = pdfDoc->getXRef(); + oAnnotRef->fetch(pXref, &oAnnot); + + // 0 - Action - A + if (oAnnot.dictLookup("A", &oObj)->isDict()) + { + m_pAction = getAction(pdfDoc, &oObj); + if (m_pAction) + { + m_unFlags |= (1 << 0); + m_pAction->sType = "A"; + } + } + oObj.free(); + + // 0 - Action from Dest - Dest + if (!m_pAction && !oAnnot.dictLookup("Dest", &oObj)->isNull()) + { + m_pAction = getDest(pdfDoc, &oObj); + if (m_pAction) + { + m_unFlags |= (1 << 0); + m_pAction->sType = "A"; + } + } + oObj.free(); + + // 1 - Action - PA + if (oAnnot.dictLookup("PA", &oObj)->isDict()) + { + m_pPA = getAction(pdfDoc, &oObj); + if (m_pPA) + { + m_unFlags |= (1 << 1); + m_pPA->sType = "A"; + } + } + oObj.free(); + + // 2 - Режим выделения - H + if (oAnnot.dictLookup("H", &oObj)->isName()) + { + m_unFlags |= (1 << 2); + std::string sName(oObj.getName()); + m_nH = 1; // Default: I + if (sName == "N") + m_nH = 0; + else if (sName == "O") + m_nH = 3; + else if (sName == "P" || sName == "T") + m_nH = 2; + } + oObj.free(); + + // 3 - Координаты - QuadPoints + if (oAnnot.dictLookup("QuadPoints", &oObj)->isArray()) + { + m_unFlags |= (1 << 3); + for (int i = 0; i < oObj.arrayGetLength(); ++i) + { + if (oObj.arrayGet(i, &oObj2)->isNum()) + m_arrQuadPoints.push_back(i % 2 == 0 ? oObj2.getNum() - m_dX : m_dHeight - oObj2.getNum()); + oObj2.free(); + } + } + oObj.free(); + + oAnnot.free(); +} +CAnnotLink::~CAnnotLink() +{ + RELEASEOBJECT(m_pAction); + RELEASEOBJECT(m_pPA); +} + //------------------------------------------------------------------------ // Text //------------------------------------------------------------------------ @@ -4333,6 +4440,26 @@ void CAnnotText::ToWASM(NSWasm::CData& oRes) if (m_unFlags & (1 << 18)) oRes.WriteBYTE(m_nState); } +void CAnnotLink::ToWASM(NSWasm::CData& oRes) +{ + oRes.WriteBYTE(1); // Link + + CAnnot::ToWASM(oRes); + + oRes.AddInt(m_unFlags); + if (m_unFlags & (1 << 0)) + m_pAction->ToWASM(oRes); + if (m_unFlags & (1 << 1)) + m_pPA->ToWASM(oRes); + if (m_unFlags & (1 << 2)) + oRes.WriteBYTE(m_nH); + if (m_unFlags & (1 << 3)) + { + oRes.AddInt((unsigned int)m_arrQuadPoints.size()); + for (int i = 0; i < m_arrQuadPoints.size(); ++i) + oRes.AddDouble(m_arrQuadPoints[i]); + } +} void CAnnotPopup::ToWASM(NSWasm::CData& oRes) { oRes.WriteBYTE(15); // Popup diff --git a/PdfFile/SrcReader/PdfAnnot.h b/PdfFile/SrcReader/PdfAnnot.h index feb3903835..539fc8eeed 100644 --- a/PdfFile/SrcReader/PdfAnnot.h +++ b/PdfFile/SrcReader/PdfAnnot.h @@ -247,7 +247,7 @@ private: std::vector m_arrTC; // Цвет текста - из DA std::vector m_arrBC; // Цвет границ - BC std::vector m_arrBG; // Цвет фона - BG - std::vector m_arrAction; // Действия + std::vector m_arrAction; // Действия - A&AA BYTE m_nQ; // Выравнивание текста - Q BYTE m_nH; // Режим выделения - H std::string m_sTU; // Альтернативное имя поля, используется во всплывающей подсказке и сообщениях об ошибке - TU @@ -335,6 +335,25 @@ private: unsigned int m_unRefNumParent; // Номер ссылки на объект родителя }; +//------------------------------------------------------------------------ +// PdfReader::CLinkAnnot +//------------------------------------------------------------------------ + +class CAnnotLink final : public CAnnot +{ +public: + CAnnotLink(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex, int nStartRefID); + virtual ~CAnnotLink(); + + void ToWASM(NSWasm::CData& oRes) override; + +private: + BYTE m_nH; // Режим выделения - H + std::vector m_arrQuadPoints; // Координаты - QuadPoints + CAction* m_pAction; // Действие - A&Dest + CAction* m_pPA; // URI действие - PA +}; + //------------------------------------------------------------------------ // PdfReader::CAnnotMarkup //------------------------------------------------------------------------ diff --git a/PdfFile/lib/xpdf/Page.cc b/PdfFile/lib/xpdf/Page.cc index df078072c2..61bf979c62 100644 --- a/PdfFile/lib/xpdf/Page.cc +++ b/PdfFile/lib/xpdf/Page.cc @@ -393,7 +393,7 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI, break; } sType = annotList->getAnnot(i)->getType(); - if (globalParams->getDrawAnnotations() || sType->cmp("Link") == 0 || sType->cmp("FileAttachment") == 0 || + if (globalParams->getDrawAnnotations() || sType->cmp("FileAttachment") == 0 || sType->cmp("Sound") == 0 || sType->cmp("Movie") == 0 || sType->cmp("Screen") == 0 || sType->cmp("PrinterMark") == 0 || sType->cmp("TrapNet") == 0 || sType->cmp("Watermark") == 0 || sType->cmp("3D") == 0) annotList->getAnnot(i)->draw(gfx, printing); From 1dd5eb33680628ddde04b26fcd122d492157a9eb Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 22 Oct 2025 16:19:43 +0300 Subject: [PATCH 016/125] Write Link annots --- .../graphics/commands/AnnotField.cpp | 229 +++++++++++------- DesktopEditor/graphics/commands/AnnotField.h | 67 +++-- PdfFile/PdfWriter.cpp | 31 ++- PdfFile/SrcWriter/Annotation.cpp | 52 +++- PdfFile/SrcWriter/Annotation.h | 55 +++-- PdfFile/SrcWriter/Document.cpp | 4 +- 6 files changed, 297 insertions(+), 141 deletions(-) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index d3ce7dfb8d..f031c2e882 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -46,6 +46,92 @@ // void Set(const std::wstring& ws) { m_ws = ws; } // const std::wstring& Get() { return m_ws; } +CAnnotFieldInfo::CActionFieldPr* ReadAction(NSOnlineOfficeBinToPdf::CBufferReader* pReader) +{ + CAnnotFieldInfo::CActionFieldPr* pRes = new CAnnotFieldInfo::CActionFieldPr(); + + pRes->nActionType = pReader->ReadByte(); + switch (pRes->nActionType) + { + case 14: // JavaScript + { + pRes->wsStr1 = pReader->ReadString(); + break; + } + case 1: // GoTo + { + pRes->nInt1 = pReader->ReadInt(); + pRes->nKind = pReader->ReadByte(); + switch (pRes->nKind) + { + case 0: + case 2: + case 3: + case 6: + case 7: + { + pRes->nFlags = pReader->ReadByte(); + if (pRes->nFlags & (1 << 0)) + pRes->dD[0] = pReader->ReadDouble(); + if (pRes->nFlags & (1 << 1)) + pRes->dD[1] = pReader->ReadDouble(); + if (pRes->nFlags & (1 << 2)) + pRes->dD[2] = pReader->ReadDouble(); + break; + } + case 4: + { + pRes->dD[0] = pReader->ReadDouble(); + pRes->dD[1] = pReader->ReadDouble(); + pRes->dD[2] = pReader->ReadDouble(); + pRes->dD[3] = pReader->ReadDouble(); + break; + } + case 1: + case 5: + default: + { + break; + } + } + break; + } + case 10: // Named + { + pRes->wsStr1 = pReader->ReadString(); + break; + } + case 6: // URI + { + pRes->wsStr1 = pReader->ReadString(); + break; + } + case 9: // Hide + { + pRes->nKind = pReader->ReadByte(); + int n = pReader->ReadInt(); + pRes->arrStr.reserve(n); + for (int i = 0; i < n; ++i) + pRes->arrStr.push_back(pReader->ReadString()); + break; + } + case 12: // ResetForm + { + pRes->nInt1 = pReader->ReadInt(); + int n = pReader->ReadInt(); + pRes->arrStr.reserve(n); + for (int i = 0; i < n; ++i) + pRes->arrStr.push_back(pReader->ReadString()); + break; + } + } + + if (pReader->ReadByte()) + pRes->pNext = ReadAction(pReader); + + return pRes; +} + CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annotaion) { m_nType = EAnnotType::Unknown; @@ -77,6 +163,7 @@ CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annot m_pCaretPr = NULL; m_pStampPr = NULL; m_pRedactPr = NULL; + m_pLinkPr = NULL; m_pWidgetPr = NULL; } CAnnotFieldInfo::~CAnnotFieldInfo() @@ -93,6 +180,7 @@ CAnnotFieldInfo::~CAnnotFieldInfo() RELEASEOBJECT(m_pCaretPr); RELEASEOBJECT(m_pStampPr); RELEASEOBJECT(m_pRedactPr); + RELEASEOBJECT(m_pLinkPr); RELEASEOBJECT(m_pWidgetPr); } @@ -113,6 +201,12 @@ void CAnnotFieldInfo::SetType(int nType) m_pTextPr = new CAnnotFieldInfo::CTextAnnotPr(); break; } + case EAnnotType::Link: + { + RELEASEOBJECT(m_pLinkPr); + m_pLinkPr = new CAnnotFieldInfo::CLinkAnnotPr(); + break; + } case EAnnotType::FreeText: { CreateMarkup(); @@ -305,6 +399,10 @@ bool CAnnotFieldInfo::IsRedact() const { return (m_nType == 25); } +bool CAnnotFieldInfo::IsLink() const +{ + return (m_nType == 1); +} CAnnotFieldInfo::CMarkupAnnotPr* CAnnotFieldInfo::GetMarkupAnnotPr() { return m_pMarkupPr; } CAnnotFieldInfo::CTextAnnotPr* CAnnotFieldInfo::GetTextAnnotPr() { return m_pTextPr; } @@ -318,6 +416,7 @@ CAnnotFieldInfo::CFreeTextAnnotPr* CAnnotFieldInfo::GetFreeTextAnnotPr() CAnnotFieldInfo::CCaretAnnotPr* CAnnotFieldInfo::GetCaretAnnotPr() { return m_pCaretPr; } CAnnotFieldInfo::CStampAnnotPr* CAnnotFieldInfo::GetStampAnnotPr() { return m_pStampPr; } CAnnotFieldInfo::CRedactAnnotPr* CAnnotFieldInfo::GetRedactAnnotPr() { return m_pRedactPr; } +CAnnotFieldInfo::CLinkAnnotPr* CAnnotFieldInfo::GetLinkAnnotPr() { return m_pLinkPr; } CAnnotFieldInfo::CWidgetAnnotPr* CAnnotFieldInfo::GetWidgetAnnotPr() { return m_pWidgetPr; } bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector) @@ -412,6 +511,8 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta m_pPopupPr->Read(pReader); else if (IsWidget()) m_pWidgetPr->Read(pReader, nType); + else if (IsLink()) + m_pLinkPr->Read(pReader); return m_nType != -1; } @@ -721,6 +822,39 @@ void CAnnotFieldInfo::CRedactAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader } } +CAnnotFieldInfo::CLinkAnnotPr::CLinkAnnotPr() +{ + m_pAction = NULL; + m_pPA = NULL; +} +CAnnotFieldInfo::CLinkAnnotPr::~CLinkAnnotPr() +{ + RELEASEOBJECT(m_pAction); + RELEASEOBJECT(m_pPA); +} +BYTE CAnnotFieldInfo::CLinkAnnotPr::GetH() const { return m_nH; } +int CAnnotFieldInfo::CLinkAnnotPr::GetFlags() const { return m_nFlags; } +const std::vector& CAnnotFieldInfo::CLinkAnnotPr::GetQuadPoints() { return m_arrQuadPoints; } +CAnnotFieldInfo::CActionFieldPr* CAnnotFieldInfo::CLinkAnnotPr::GetA() { return m_pAction; } +CAnnotFieldInfo::CActionFieldPr* CAnnotFieldInfo::CLinkAnnotPr::GetPA() { return m_pPA; } +void CAnnotFieldInfo::CLinkAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader) +{ + m_nFlags = pReader->ReadInt(); + if (m_nFlags & (1 << 0)) + m_pAction = ReadAction(pReader); + if (m_nFlags & (1 << 1)) + m_pPA = ReadAction(pReader); + if (m_nFlags & (1 << 2)) + m_nH = pReader->ReadByte(); + if (m_nFlags & (1 << 3)) + { + int n = pReader->ReadInt(); + m_arrQuadPoints.reserve(n); + for (int i = 0; i < n; ++i) + m_arrQuadPoints.push_back(pReader->ReadDouble()); + } +} + bool CAnnotFieldInfo::CPopupAnnotPr::IsOpen() const { return m_bOpen; } int CAnnotFieldInfo::CPopupAnnotPr::GetFlag() const { return m_nFlag; } int CAnnotFieldInfo::CPopupAnnotPr::GetParentID() const { return m_nParentID; } @@ -752,7 +886,7 @@ const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetFontKey() { return m_w const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetTC() { return m_arrTC; } const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetBC() { return m_arrBC; } const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetBG() { return m_arrBG; } -const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetActions() { return m_arrAction; } +const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetActions() { return m_arrAction; } CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetButtonWidgetPr() { return m_pButtonPr; } CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetTextWidgetPr() { return m_pTextPr; } CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetChoiceWidgetPr() { return m_pChoicePr; } @@ -812,93 +946,8 @@ CAnnotFieldInfo::CWidgetAnnotPr::~CWidgetAnnotPr() RELEASEOBJECT(m_arrAction[i]); } -CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget::CActionWidget() : pNext(NULL) {} -CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget::~CActionWidget() { RELEASEOBJECT(pNext); } -CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* ReadAction(NSOnlineOfficeBinToPdf::CBufferReader* pReader) -{ - CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pRes = new CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget(); - - pRes->nActionType = pReader->ReadByte(); - switch (pRes->nActionType) - { - case 14: // JavaScript - { - pRes->wsStr1 = pReader->ReadString(); - break; - } - case 1: // GoTo - { - pRes->nInt1 = pReader->ReadInt(); - pRes->nKind = pReader->ReadByte(); - switch (pRes->nKind) - { - case 0: - case 2: - case 3: - case 6: - case 7: - { - pRes->nFlags = pReader->ReadByte(); - if (pRes->nFlags & (1 << 0)) - pRes->dD[0] = pReader->ReadDouble(); - if (pRes->nFlags & (1 << 1)) - pRes->dD[1] = pReader->ReadDouble(); - if (pRes->nFlags & (1 << 2)) - pRes->dD[2] = pReader->ReadDouble(); - break; - } - case 4: - { - pRes->dD[0] = pReader->ReadDouble(); - pRes->dD[1] = pReader->ReadDouble(); - pRes->dD[2] = pReader->ReadDouble(); - pRes->dD[3] = pReader->ReadDouble(); - break; - } - case 1: - case 5: - default: - { - break; - } - } - break; - } - case 10: // Named - { - pRes->wsStr1 = pReader->ReadString(); - break; - } - case 6: // URI - { - pRes->wsStr1 = pReader->ReadString(); - break; - } - case 9: // Hide - { - pRes->nKind = pReader->ReadByte(); - int n = pReader->ReadInt(); - pRes->arrStr.reserve(n); - for (int i = 0; i < n; ++i) - pRes->arrStr.push_back(pReader->ReadString()); - break; - } - case 12: // ResetForm - { - pRes->nInt1 = pReader->ReadInt(); - int n = pReader->ReadInt(); - pRes->arrStr.reserve(n); - for (int i = 0; i < n; ++i) - pRes->arrStr.push_back(pReader->ReadString()); - break; - } - } - - if (pReader->ReadByte()) - pRes->pNext = ReadAction(pReader); - - return pRes; -} +CAnnotFieldInfo::CActionFieldPr::CActionFieldPr() : pNext(NULL) {} +CAnnotFieldInfo::CActionFieldPr::~CActionFieldPr() { RELEASEOBJECT(pNext); } void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType) { m_wsFN = pReader->ReadString(); @@ -957,7 +1006,7 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader for (int i = 0; i < nAction; ++i) { std::wstring wsType = pReader->ReadString(); - CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pA = ReadAction(pReader); + CAnnotFieldInfo::CActionFieldPr* pA = ReadAction(pReader); if (pA) { pA->wsType = wsType; @@ -1192,7 +1241,7 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil for (int i = 0; i < nAction; ++i) { std::wstring wsType = pReader->ReadString(); - CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pA = ReadAction(pReader); + CAnnotFieldInfo::CActionFieldPr* pA = ReadAction(pReader); if (pA) { pA->wsType = wsType; diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index a978e85537..0c2e83bd09 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -70,6 +70,23 @@ public: WidgetSignature = 33 }; + class GRAPHICS_DECL CActionFieldPr + { + public: + CActionFieldPr(); + ~CActionFieldPr(); + + BYTE nKind; + BYTE nFlags; + BYTE nActionType; + int nInt1; + double dD[4]{}; + std::wstring wsType; + std::wstring wsStr1; + std::vector arrStr; + CActionFieldPr* pNext; + }; + class GRAPHICS_DECL CWidgetAnnotPr { public: @@ -159,23 +176,6 @@ public: }; - class GRAPHICS_DECL CActionWidget - { - public: - CActionWidget(); - ~CActionWidget(); - - BYTE nKind; - BYTE nFlags; - BYTE nActionType; - int nInt1; - double dD[4]{}; - std::wstring wsType; - std::wstring wsStr1; - std::vector arrStr; - CActionWidget* pNext; - }; - CWidgetAnnotPr(BYTE nType); ~CWidgetAnnotPr(); @@ -199,7 +199,7 @@ public: const std::vector& GetTC(); const std::vector& GetBC(); const std::vector& GetBG(); - const std::vector& GetActions(); + const std::vector& GetActions(); CButtonWidgetPr* GetButtonWidgetPr(); CTextWidgetPr* GetTextWidgetPr(); @@ -229,7 +229,7 @@ public: std::vector m_arrTC; std::vector m_arrBC; std::vector m_arrBG; - std::vector m_arrAction; + std::vector m_arrAction; CButtonWidgetPr* m_pButtonPr; CTextWidgetPr* m_pTextPr; @@ -389,7 +389,7 @@ public: { public: bool IsOpen() const; - int GetFlag() const; + int GetFlag() const; int GetParentID() const; void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader); @@ -478,6 +478,28 @@ public: std::vector m_arrQuadPoints; }; + class GRAPHICS_DECL CLinkAnnotPr + { + public: + CLinkAnnotPr(); + ~CLinkAnnotPr(); + + BYTE GetH() const; + int GetFlags() const; + const std::vector& GetQuadPoints(); + CActionFieldPr* GetA(); + CActionFieldPr* GetPA(); + + void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader); + + private: + BYTE m_nH; + int m_nFlags; + std::vector m_arrQuadPoints; + CActionFieldPr* m_pAction; + CActionFieldPr* m_pPA; + }; + CAnnotFieldInfo(); virtual ~CAnnotFieldInfo(); @@ -518,6 +540,7 @@ public: bool IsCaret() const; bool IsStamp() const; bool IsRedact() const; + bool IsLink() const; CMarkupAnnotPr* GetMarkupAnnotPr(); CTextAnnotPr* GetTextAnnotPr(); @@ -531,6 +554,7 @@ public: CCaretAnnotPr* GetCaretAnnotPr(); CStampAnnotPr* GetStampAnnotPr(); CRedactAnnotPr* GetRedactAnnotPr(); + CLinkAnnotPr* GetLinkAnnotPr(); CWidgetAnnotPr* GetWidgetAnnotPr(); bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector); @@ -576,6 +600,7 @@ private: CCaretAnnotPr* m_pCaretPr; CStampAnnotPr* m_pStampPr; CRedactAnnotPr* m_pRedactPr; + CLinkAnnotPr* m_pLinkPr; CWidgetAnnotPr* m_pWidgetPr; }; @@ -610,7 +635,7 @@ public: std::wstring sTU; std::vector arrI; std::vector arrV; - std::vector arrAction; + std::vector arrAction; std::vector< std::pair > arrOpt; }; diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 5523a40641..773e567902 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -1736,7 +1736,7 @@ void GetRCSpanStyle(CAnnotFieldInfo::CMarkupAnnotPr::CFontData* pFontData, NSStr oRC.AddDouble(pFontData->dVAlign, 2); } } -PdfWriter::CAction* GetAction(PdfWriter::CDocument* m_pDocument, CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pAction) +PdfWriter::CAction* GetAction(PdfWriter::CDocument* m_pDocument, CAnnotFieldInfo::CActionFieldPr* pAction) { PdfWriter::CAction* pA = m_pDocument->CreateAction(pAction->nActionType); if (!pA) @@ -2367,8 +2367,8 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF else pWidgetAnnot->Remove("MEOptions"); - const std::vector arrActions = pPr->GetActions(); - for (CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pAction : arrActions) + const std::vector arrActions = pPr->GetActions(); + for (CAnnotFieldInfo::CActionFieldPr* pAction : arrActions) { PdfWriter::CAction* pA = GetAction(m_pDocument, pAction); pWidgetAnnot->AddAction(pA); @@ -2639,6 +2639,27 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF PdfWriter::CSignatureWidget* pSignatureWidget = (PdfWriter::CSignatureWidget*)pAnnot; } } + else if (oInfo.IsLink()) + { + CAnnotFieldInfo::CLinkAnnotPr* pPr = oInfo.GetLinkAnnotPr(); + PdfWriter::CLinkAnnotation* pLinkAnnot = (PdfWriter::CLinkAnnotation*)pAnnot; + + nFlags = pPr->GetFlags(); + if (nFlags & (1 << 0)) + { + PdfWriter::CAction* pA = GetAction(m_pDocument, pPr->GetA()); + pLinkAnnot->SetA(pA); + } + if (nFlags & (1 << 1)) + { + PdfWriter::CAction* pA = GetAction(m_pDocument, pPr->GetPA()); + pLinkAnnot->SetPA(pA); + } + if (nFlags & (1 << 2)) + pLinkAnnot->SetH(pPr->GetH()); + if (nFlags & (1 << 3)) + pLinkAnnot->SetQuadPoints(pPr->GetQuadPoints()); + } return S_OK; } @@ -2973,8 +2994,8 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi pParentObj->Add("Ff", pParent->nFieldFlag); if (nFlags & (1 << 8)) { - const std::vector arrActions = pParent->arrAction; - for (CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pAction : arrActions) + const std::vector arrActions = pParent->arrAction; + for (CAnnotFieldInfo::CActionFieldPr* pAction : arrActions) { PdfWriter::CAction* pA = GetAction(m_pDocument, pAction); if (!pA) diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 80af28a25b..900a6b072f 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -420,13 +420,13 @@ namespace PdfWriter Remove("AP"); } //---------------------------------------------------------------------------------------- - // CLinkAnnotation + // CDestLinkAnnotation //---------------------------------------------------------------------------------------- - CLinkAnnotation::CLinkAnnotation(CXref* pXref, CDestination* pDestination) : CAnnotation(pXref, AnnotLink) + CDestLinkAnnotation::CDestLinkAnnotation(CXref* pXref, CDestination* pDestination) : CAnnotation(pXref, AnnotLink) { Add("Dest", (CObjectBase*)pDestination); } - void CLinkAnnotation::SetBorderStyle(float fWidth, unsigned short nDashOn, unsigned short nDashOff) + void CDestLinkAnnotation::SetBorderStyle(float fWidth, unsigned short nDashOn, unsigned short nDashOff) { fWidth = std::max(fWidth, 0.f); @@ -452,7 +452,7 @@ namespace PdfWriter pDash->Add(nDashOff); } } - void CLinkAnnotation::SetHighlightMode(EAnnotHighlightMode eMode) + void CDestLinkAnnotation::SetHighlightMode(EAnnotHighlightMode eMode) { switch (eMode) { @@ -814,6 +814,50 @@ namespace PdfWriter pNormal->DrawLine(); } //---------------------------------------------------------------------------------------- + // CLinkAnnotation + //---------------------------------------------------------------------------------------- + CLinkAnnotation::CLinkAnnotation(CXref* pXref) : CAnnotation(pXref, AnnotLink) + { + } + void CLinkAnnotation::SetH(BYTE nH) + { + std::string sValue; + switch (nH) + { + case 0: + { sValue = "N"; break; } + default: + case 1: + { sValue = "I"; break; } + case 2: + { sValue = "P"; break; } + case 3: + { sValue = "O"; break; } + } + Add("H", sValue.c_str()); + } + void CLinkAnnotation::SetQuadPoints(const std::vector& arrQuadPoints) + { + CArrayObject* pArray = new CArrayObject(); + if (!pArray) + return; + Add("QuadPoints", pArray); + for (int i = 0; i < arrQuadPoints.size(); ++i) + pArray->Add(i % 2 == 0 ? (arrQuadPoints[i] + m_dPageX) : (m_dPageH - arrQuadPoints[i])); + } + void CLinkAnnotation::SetA(CAction* pAction) + { + if (!pAction) + return; + Add("A", pAction); + } + void CLinkAnnotation::SetPA(CAction* pAction) + { + if (!pAction) + return; + Add("PA", pAction); + } + //---------------------------------------------------------------------------------------- // CPopupAnnotation //---------------------------------------------------------------------------------------- CPopupAnnotation::CPopupAnnotation(CXref* pXref) : CAnnotation(pXref, AnnotPopup) diff --git a/PdfFile/SrcWriter/Annotation.h b/PdfFile/SrcWriter/Annotation.h index 3cf363e56a..3c550231ed 100644 --- a/PdfFile/SrcWriter/Annotation.h +++ b/PdfFile/SrcWriter/Annotation.h @@ -224,6 +224,20 @@ namespace PdfWriter void SetParentID(CAnnotation* pAnnot); }; + class CLinkAnnotation : public CAnnotation + { + public: + CLinkAnnotation(CXref* pXref); + EAnnotType GetAnnotationType() const override + { + return AnnotLink; + } + + void SetH(BYTE nH); + void SetQuadPoints(const std::vector& arrQuadPoints); + void SetA(CAction* pAction); + void SetPA(CAction* pAction); + }; class CMarkupAnnotation : public CAnnotation { protected: @@ -246,17 +260,6 @@ namespace PdfWriter void SetIRTID(CAnnotation* pAnnot); CPopupAnnotation* CreatePopup(); }; - class CLinkAnnotation : public CAnnotation - { - public: - CLinkAnnotation(CXref* pXref, CDestination* pDestination); - EAnnotType GetAnnotationType() const override - { - return AnnotLink; - } - void SetBorderStyle (float fWidth, unsigned short nDashOn, unsigned short nDashOff); - void SetHighlightMode(EAnnotHighlightMode eMode); - }; class CTextAnnotation : public CMarkupAnnotation { private: @@ -275,15 +278,6 @@ namespace PdfWriter void SetAP(); }; - class CUriLinkAnnotation : public CAnnotation - { - public: - CUriLinkAnnotation(CXref* pXref, const char* sUri); - EAnnotType GetAnnotationType() const override - { - return AnnotLink; - } - }; class CInkAnnotation : public CMarkupAnnotation { public: @@ -624,5 +618,26 @@ namespace PdfWriter public: CSignatureWidget(CXref* pXref); }; + + class CDestLinkAnnotation : public CAnnotation + { + public: + CDestLinkAnnotation(CXref* pXref, CDestination* pDestination); + EAnnotType GetAnnotationType() const override + { + return AnnotLink; + } + void SetBorderStyle (float fWidth, unsigned short nDashOn, unsigned short nDashOff); + void SetHighlightMode(EAnnotHighlightMode eMode); + }; + class CUriLinkAnnotation : public CAnnotation + { + public: + CUriLinkAnnotation(CXref* pXref, const char* sUri); + EAnnotType GetAnnotationType() const override + { + return AnnotLink; + } + }; } #endif // _PDF_WRITER_SRC_ANNOTATION_H diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 186a7aa9cb..a39016d227 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -657,6 +657,8 @@ namespace PdfWriter pAnnot = new CStampAnnotation(m_pXref); else if (m_nType == 25) pAnnot = new CRedactAnnotation(m_pXref); + else if (m_nType == 1) + pAnnot = new CLinkAnnotation(m_pXref); if (pAnnot) m_pXref->Add(pAnnot); @@ -719,7 +721,7 @@ namespace PdfWriter } CAnnotation* CDocument::CreateLinkAnnot(const TRect& oRect, CDestination* pDest) { - CAnnotation* pAnnot = new CLinkAnnotation(m_pXref, pDest); + CAnnotation* pAnnot = new CDestLinkAnnotation(m_pXref, pDest); pAnnot->SetRect(oRect); m_pXref->Add(pAnnot); return pAnnot; From 5e177412e2e7e93166365662d8a8a68282f1a199 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Thu, 23 Oct 2025 14:37:48 +0300 Subject: [PATCH 017/125] Add scale for brush rect --- DesktopEditor/graphics/MetafileToRenderer.cpp | 31 ++++++++++++++++++- DesktopEditor/graphics/MetafileToRenderer.h | 1 + DesktopEditor/graphics/aggplustypes.h | 3 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 2736ae2f86..4c6f4b4f3f 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -698,7 +698,34 @@ namespace NSOnlineOfficeBinToPdf pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); } - transMatrOff.Translate(m1, m2); + LONG type; + pRenderer->get_BrushType(&type); + if (type == c_BrushTypeTexture) + pRenderer->get_BrushTextureMode(&type); + if (type == c_BrushTextureModeStretch) + transMatrOff.Translate(m1, m2); + break; + } + case ctPathCommandScale: + { + double m1 = oReader.ReadDouble(); + double m2 = oReader.ReadDouble(); + + Aggplus::RectF rect; + bool rectable; + pRenderer->get_BrushRect(rect, rectable); + if (rectable) + { + rect.Scale(m1, m2); + pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); + } + + LONG type; + pRenderer->get_BrushType(&type); + if (type == c_BrushTypeTexture) + pRenderer->get_BrushTextureMode(&type); + if (type == c_BrushTextureModeStretch) + transMatrOff.Scale(m1, m2); break; } case ctDrawPath: @@ -717,6 +744,8 @@ namespace NSOnlineOfficeBinToPdf pRenderer->DrawPath(oReader.ReadInt()); path.Reset(); + transMatrRot.Reset(); + transMatrOff.Reset(); break; } case ctDrawImageFromFile: diff --git a/DesktopEditor/graphics/MetafileToRenderer.h b/DesktopEditor/graphics/MetafileToRenderer.h index 9e76355e76..0653360a52 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.h +++ b/DesktopEditor/graphics/MetafileToRenderer.h @@ -155,6 +155,7 @@ namespace NSOnlineOfficeBinToPdf ctPathCommandText = 102, ctPathCommandTextEx = 103, ctPathCommandOffset = 104, + ctPathCommandScale = 105, // image ctDrawImage = 110, diff --git a/DesktopEditor/graphics/aggplustypes.h b/DesktopEditor/graphics/aggplustypes.h index fc10bd1033..0ff943aac0 100644 --- a/DesktopEditor/graphics/aggplustypes.h +++ b/DesktopEditor/graphics/aggplustypes.h @@ -210,7 +210,8 @@ public: } void Offset(const PointF_T& point) { Offset(point.X, point.Y); } - void Offset(T dx, T dy) { X += dx; Y += dy; } + void Offset(const T& dx, const T& dy) { X += dx; Y += dy; } + void Scale(const T& sx, const T& sy) { Width *= sx; Height *= sy; } RectF_T& operator=(const RectF_T& other) { From 4b335fc796bb7120da32d1bd6126cbe416b29963 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Thu, 23 Oct 2025 14:41:34 +0300 Subject: [PATCH 018/125] Add mirror for tile brush --- DesktopEditor/graphics/GraphicsRenderer.cpp | 11 +++++++++-- DesktopEditor/graphics/structures.h | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 40d535d391..e4076fbe3c 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -952,11 +952,18 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType) switch (m_oBrush.TextureMode) { case c_BrushTextureModeTile: - oMode = Aggplus::WrapModeTile; - break; case c_BrushTextureModeTileCenter: oMode = Aggplus::WrapModeTile; break; + case c_BrushTextureModeTileFlipX: + oMode = Aggplus::WrapModeTileFlipX; + break; + case c_BrushTextureModeTileFlipY: + oMode = Aggplus::WrapModeTileFlipY; + break; + case c_BrushTextureModeTileFlipXY: + oMode = Aggplus::WrapModeTileFlipXY; + break; default: break; } diff --git a/DesktopEditor/graphics/structures.h b/DesktopEditor/graphics/structures.h index 532c27e193..3f3e56140b 100644 --- a/DesktopEditor/graphics/structures.h +++ b/DesktopEditor/graphics/structures.h @@ -114,6 +114,9 @@ const long c_BrushTypeTensorCurveGradient = 6007; const long c_BrushTextureModeStretch = 0; const long c_BrushTextureModeTile = 1; const long c_BrushTextureModeTileCenter = 2; +const long c_BrushTextureModeTileFlipX = 3; +const long c_BrushTextureModeTileFlipY = 4; +const long c_BrushTextureModeTileFlipXY = 5; // -------------------------------------------------------------- namespace Aggplus { class CImage; } From dbd92bfdfa6124ddb1df8240a9ca6c2afc773fa2 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 24 Oct 2025 15:01:51 +0300 Subject: [PATCH 019/125] Fix Link Border --- PdfFile/SrcReader/PdfAnnot.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 9d4bbfd824..902cd08274 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -516,8 +516,6 @@ CAnnot::CBorderType* getBorder(Object* oBorder, bool bBSorBorder) { pBorderType->nType = annotBorderSolid; pBorderType->dWidth = ArrGetNum(oBorder, 2); - if (!pBorderType->dWidth) - pBorderType->dWidth = 1.0; Object oObj; if (oBorder->arrayGetLength() > 3 && oBorder->arrayGet(3, &oObj)->isArray() && oObj.arrayGetLength() > 1) From 250c85c07797db6935cd83f63a65c5067c368ffd Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Fri, 24 Oct 2025 15:26:33 +0300 Subject: [PATCH 020/125] Add meta info in docx-renderer --- DocxRenderer/src/logic/elements/ContText.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index e9fe4b8096..3cfbaf83b2 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -508,6 +508,24 @@ namespace NSDocxRenderer oWriter.WriteBYTE(0); oWriter.WriteStringUtf16(m_oText.ToStdWString()); oWriter.WriteBYTE(kBin_g_nodeAttributeEnd); + // Meta-info + oWriter.StartRecord(111); + oWriter.WriteBYTE(kBin_g_nodeAttributeStart); + oWriter.WriteBYTE(0); oWriter.WriteStringUtf16(m_wsOriginFontName); // Origin font name + oWriter.WriteBYTE(1); oWriter.AddInt(static_cast(m_dLeft * c_dMMToEMU)); // Origin left + oWriter.WriteBYTE(2); oWriter.AddInt(static_cast(m_dBot * c_dMMToEMU)); // Origin bot + + // Origin width string + std::wstring origin_width{}; + for (auto& w : m_arSymWidths) + origin_width += std::to_wstring(static_cast(w * c_dMMToEMU)) + L";"; + + oWriter.WriteBYTE(3); oWriter.AddInt(m_arSymWidths.size()); // Len of sym widths + oWriter.WriteBYTE(4); oWriter.WriteStringUtf16(origin_width); + + oWriter.WriteBYTE(kBin_g_nodeAttributeEnd); + oWriter.EndRecord(); + // WriteRecord WriteRunProperties [&oWriter, this, lCalculatedSpacing] () { oWriter.StartRecord(0); From fe2fb0c08d65d1632ff1136e0b4e6f49ed73d468 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Tue, 28 Oct 2025 13:04:00 +0300 Subject: [PATCH 021/125] Add meta info --- DocxRenderer/src/logic/Page.cpp | 6 +- DocxRenderer/src/logic/elements/ContText.cpp | 173 ++++++++++++++---- DocxRenderer/src/logic/elements/ContText.h | 26 ++- DocxRenderer/src/logic/elements/Paragraph.cpp | 2 +- DocxRenderer/src/logic/elements/TextLine.cpp | 12 +- 5 files changed, 168 insertions(+), 51 deletions(-) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index 279b31cf6f..0b601f3b6f 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -342,7 +342,7 @@ namespace NSDocxRenderer bForcedBold = true; m_oManagers.pParagraphStyleManager->UpdateAvgFontSize(m_oFont.Size); - m_oContBuilder.AddUnicode(top, baseline, left, right, m_oFont, m_oBrush, m_oManagers.pFontManager, oText, bForcedBold, m_bUseDefaultFont, m_bWriteStyleRaw); + m_oContBuilder.AddUnicode(top, baseline, left, right, m_oFont, m_oBrush, m_oManagers.pFontManager, oText, pGids, bForcedBold, m_bUseDefaultFont, m_bWriteStyleRaw); } void CPage::Analyze() @@ -1152,11 +1152,11 @@ namespace NSDocxRenderer if ((bIf1 && bIf6) || (bIf2 && bIf7) || (bIf4 && bIf8) || (bIf5 && bIf7)) { - cont->AddSymBack(d_sym->GetText().at(0), 0); + cont->AddSymBack(d_sym->GetText().at(0), 0, d_sym->m_arGids.at(0), d_sym->m_arOriginLefts.at(0)); } else if (bIf3 && bIf7) { - cont->AddSymFront(d_sym->GetText().at(0), 0); + cont->AddSymFront(d_sym->GetText().at(0), 0, d_sym->m_arGids.at(0), d_sym->m_arOriginLefts.at(0)); } isBreak = true; break; diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 3cfbaf83b2..bbb46675f7 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -78,6 +78,16 @@ namespace NSDocxRenderer for (size_t i = 0; i < rCont.m_arSymWidths.size(); ++i) m_arSymWidths[i] = rCont.m_arSymWidths[i]; + m_arGids.clear(); + m_arGids.resize(rCont.m_arGids.size()); + for (size_t i = 0; i < rCont.m_arGids.size(); ++i) + m_arGids[i] = rCont.m_arGids[i]; + + m_arOriginLefts.clear(); + m_arOriginLefts.resize(rCont.m_arOriginLefts.size()); + for (size_t i = 0; i < rCont.m_arOriginLefts.size(); ++i) + m_arOriginLefts[i] = rCont.m_arOriginLefts[i]; + return *this; } @@ -128,13 +138,23 @@ namespace NSDocxRenderer cont->m_dWidth = cont->m_dRight - cont->m_dLeft; cont->m_arSymWidths.clear(); + cont->m_arOriginLefts.clear(); + cont->m_arGids.clear(); for (size_t i = index + 1; i < len; ++i) + { cont->m_arSymWidths.push_back(m_arSymWidths[i]); + cont->m_arOriginLefts.push_back(m_arOriginLefts[i]); + cont->m_arGids.push_back(m_arGids[i]); + } m_oText = m_oText.substr(0, index + 1); m_dRight = cont->m_dLeft; m_dWidth = m_dRight - m_dLeft; + m_arSymWidths.resize(index + 1); + m_arOriginLefts.resize(index + 1); + m_arGids.resize(index + 1); + m_bPossibleHorSplit = false; return cont; @@ -470,25 +490,37 @@ namespace NSDocxRenderer oWriter.WriteString(L""); if (m_bIsAddBrEnd) oWriter.WriteString(L""); + std::wstring origin_gids{}; + for (auto& gid : m_arGids) + origin_gids += std::to_wstring(gid) + L";"; + + // Origin width string + std::wstring origin_lefts{}; + for (auto& l : m_arOriginLefts) + origin_lefts += std::to_wstring(static_cast(l * c_dMMToEMU)) + L";"; + // meta info for pdf-editor oWriter.WriteString(L"(m_dLeft * c_dMMToEMU)); oWriter.WriteString(L"\" y=\""); - oWriter.AddDouble(m_dBot, 4); - oWriter.WriteString(L"\" widths=\""); - for (auto& w : m_arSymWidths) - { - oWriter.AddDouble(w, 4); - oWriter.WriteString(L","); - } + oWriter.AddInt(static_cast(m_dBot * c_dMMToEMU)); oWriter.WriteString(L"\" />"); oWriter.WriteString(L""); oWriter.WriteString(L""); + + oWriter.WriteString(L""); } void CContText::ToBin(NSWasm::CData& oWriter) const { @@ -512,16 +544,22 @@ namespace NSDocxRenderer oWriter.StartRecord(111); oWriter.WriteBYTE(kBin_g_nodeAttributeStart); oWriter.WriteBYTE(0); oWriter.WriteStringUtf16(m_wsOriginFontName); // Origin font name - oWriter.WriteBYTE(1); oWriter.AddInt(static_cast(m_dLeft * c_dMMToEMU)); // Origin left - oWriter.WriteBYTE(2); oWriter.AddInt(static_cast(m_dBot * c_dMMToEMU)); // Origin bot + oWriter.WriteBYTE(1); oWriter.AddInt(m_nOriginFontFaceIndex); // Origin face index + oWriter.WriteBYTE(2); oWriter.AddSInt(static_cast(m_dLeft * c_dMMToEMU)); // Origin left + oWriter.WriteBYTE(3); oWriter.AddSInt(static_cast(m_dBot * c_dMMToEMU)); // Origin bot + + std::wstring origin_gids{}; + for (auto& gid : m_arGids) + origin_gids += std::to_wstring(gid) + L";"; + + oWriter.WriteBYTE(4); oWriter.WriteStringUtf16(origin_gids); // Origin gids string // Origin width string - std::wstring origin_width{}; - for (auto& w : m_arSymWidths) - origin_width += std::to_wstring(static_cast(w * c_dMMToEMU)) + L";"; + std::wstring origin_lefts{}; + for (auto& l : m_arOriginLefts) + origin_lefts += std::to_wstring(static_cast(l * c_dMMToEMU)) + L";"; - oWriter.WriteBYTE(3); oWriter.AddInt(m_arSymWidths.size()); // Len of sym widths - oWriter.WriteBYTE(4); oWriter.WriteStringUtf16(origin_width); + oWriter.WriteBYTE(5); oWriter.WriteStringUtf16(origin_lefts); // Origin lefts oWriter.WriteBYTE(kBin_g_nodeAttributeEnd); oWriter.EndRecord(); @@ -682,7 +720,10 @@ namespace NSDocxRenderer return text.length() == 1 && CContText::IsUnicodeDiacriticalMark(text.at(0)); } - void CContText::AddTextBack(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths) + void CContText::AddTextBack(const NSStringUtils::CStringUTF32& oText, + const std::vector& arSymWidths, + const std::vector& arGids, + const std::vector& arOriginLefts) { bool is_space_twice = m_oText.at(m_oText.length() - 1) == c_SPACE_SYM && oText.at(0) == c_SPACE_SYM; @@ -699,20 +740,48 @@ namespace NSDocxRenderer m_arSymWidths.push_back(w); m_dWidth += w; m_oText += oText.at(i); + + if (!arGids.empty()) + m_arGids.push_back(arGids[i]); + m_arOriginLefts.push_back(arOriginLefts[i]); } m_dRight = m_dLeft + m_dWidth; } - void CContText::AddTextFront(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths) + void CContText::AddTextFront(const NSStringUtils::CStringUTF32& oText, + const std::vector& arSymWidths, + const std::vector& arGids, + const std::vector& arOriginLefts) { m_oText = oText + m_oText; + double addtitional_width = 0; + for (auto& w : arSymWidths) + addtitional_width += w; + auto ar_sym_w = m_arSymWidths; m_arSymWidths = arSymWidths; - for (auto& w : ar_sym_w) m_arSymWidths.push_back(w); + + m_dWidth += addtitional_width; + m_dLeft = m_dRight - m_dWidth; + + if (!arGids.empty()) + { + auto ar_gids = m_arGids; + m_arGids = arGids; + for (auto& gid : ar_gids) + m_arGids.push_back(gid); + } + auto ar_lefts = m_arOriginLefts; + m_arOriginLefts = arOriginLefts; + for (auto& left : ar_lefts) + m_arOriginLefts.push_back(left); } - void CContText::SetText(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths) + void CContText::SetText(const NSStringUtils::CStringUTF32& oText, + const std::vector& arSymWidths, + const std::vector& arGids, + const std::vector& arOriginLefts) { m_oText = oText; m_arSymWidths.clear(); @@ -723,32 +792,44 @@ namespace NSDocxRenderer m_dWidth += w; } m_dRight = m_dLeft + m_dWidth; + + m_arGids = arGids; + m_arOriginLefts = arOriginLefts; } - void CContText::AddSymBack(uint32_t cSym, double dWidth) + void CContText::AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) { bool is_space_twice = m_oText.at(m_oText.length() - 1) == c_SPACE_SYM && cSym == c_SPACE_SYM; if (is_space_twice) + { m_arSymWidths.back() += dWidth; + } else { m_arSymWidths.push_back(dWidth); m_oText += cSym; + m_arGids.push_back(nGid); + m_arOriginLefts.push_back(dLeft); } m_dWidth += dWidth; m_dRight = m_dLeft + m_dWidth; - } - void CContText::AddSymFront(uint32_t cSym, double dWidth) + void CContText::AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) { NSStringUtils::CStringUTF32 text; text += cSym; text += m_oText; m_oText = text; + + m_dLeft -= dWidth; + m_dWidth = m_dRight - m_dLeft; + m_arSymWidths.insert(m_arSymWidths.begin(), dWidth); + m_arGids.insert(m_arGids.begin(), nGid); + m_arOriginLefts.insert(m_arOriginLefts.begin(), dLeft); } - void CContText::SetSym(uint32_t cSym, double dWidth) + void CContText::SetSym(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) { m_oText = L""; m_oText += cSym; @@ -756,6 +837,15 @@ namespace NSDocxRenderer m_arSymWidths.push_back(dWidth); m_dWidth = dWidth; m_dRight = m_dLeft + m_dWidth; + + m_arSymWidths.clear(); + m_arSymWidths.push_back(dWidth); + + m_arGids.clear(); + m_arGids.push_back(nGid); + + m_arOriginLefts.clear(); + m_arOriginLefts.push_back(dLeft); } void CContText::RemoveLastSym() { @@ -763,6 +853,8 @@ namespace NSDocxRenderer m_dWidth -= m_arSymWidths[m_arSymWidths.size() - 1]; m_dRight = m_dLeft + m_dWidth; m_arSymWidths.resize(m_arSymWidths.size() - 1); + m_arGids.resize(m_arGids.size() - 1); + m_arOriginLefts.resize(m_arOriginLefts.size() - 1); } uint32_t CContText::GetLastSym() const { @@ -779,14 +871,7 @@ namespace NSDocxRenderer } const std::vector CContText::GetSymLefts() const noexcept { - std::vector lefts; - double left = m_dLeft; - for (auto& w : m_arSymWidths) - { - lefts.push_back(left); - left += w; - } - return lefts; + return m_arOriginLefts; } bool CContText::CheckFontEffects @@ -1022,6 +1107,7 @@ namespace NSDocxRenderer const NSStructures::CBrush& oBrush, CFontManager* pFontManager, const NSStringUtils::CStringUTF32& oText, + const PUINT pGids, bool bForcedBold, bool bUseDefaultFont, bool bWriteStyleRaw) @@ -1029,6 +1115,21 @@ namespace NSDocxRenderer double dWidth = dRight - dLeft; double dHeight = dBot - dTop; + std::vector gids; + for (size_t i = 0; i < oText.length(); ++i) + if (pGids) + gids.push_back(pGids[i]); + else + gids.push_back(0); + + std::vector origin_lefts; + double curr_origin_left = dLeft; + for (size_t i = 0; i < oText.length(); ++i) + { + origin_lefts.push_back(curr_origin_left); + curr_origin_left += dWidth / oText.length(); + } + // if new text is close to current cont if (m_pCurrCont != nullptr && fabs(m_pCurrCont->m_dBot - dBot) < c_dTHE_SAME_STRING_Y_PRECISION_MM && @@ -1058,7 +1159,7 @@ namespace NSDocxRenderer for (size_t i = 0; i < oText.length(); ++i) ar_widths.push_back(left_avg_width); - m_pCurrCont->AddTextBack(oText, ar_widths); + m_pCurrCont->AddTextBack(oText, ar_widths, gids, origin_lefts); is_added = true; } @@ -1070,7 +1171,7 @@ namespace NSDocxRenderer for (size_t i = 0; i < oText.length(); ++i) ar_widths.push_back(right_avg_width); - m_pCurrCont->AddTextFront(oText, ar_widths); + m_pCurrCont->AddTextFront(oText, ar_widths, gids, origin_lefts); is_added = true; } @@ -1112,7 +1213,7 @@ namespace NSDocxRenderer ar_widths.push_back(avg_width); } - pCont->SetText(oText, ar_widths); + pCont->SetText(oText, ar_widths, gids, origin_lefts); pCont->m_bIsRtl = CContText::IsUnicodeRtl(oText.at(0)); pCont->m_dWidth = dWidth; @@ -1125,7 +1226,9 @@ namespace NSDocxRenderer pCont->m_dTopWithAscent = pCont->m_dBot - (oMetrics.dAscent * ratio) - oMetrics.dBaselineOffset; pCont->m_dBotWithDescent = pCont->m_dBot + (oMetrics.dDescent * ratio) - oMetrics.dBaselineOffset; pCont->m_dSpaceWidthMM = pFontManager->GetSpaceWidthMM(); + pCont->m_wsOriginFontName = oFont.Name; + pCont->m_nOriginFontFaceIndex = oFont.FaceIndex; if (bUseDefaultFont) { diff --git a/DocxRenderer/src/logic/elements/ContText.h b/DocxRenderer/src/logic/elements/ContText.h index f9420c6c99..72480e46eb 100644 --- a/DocxRenderer/src/logic/elements/ContText.h +++ b/DocxRenderer/src/logic/elements/ContText.h @@ -63,6 +63,7 @@ namespace NSDocxRenderer // origin font std::wstring m_wsOriginFontName{}; + int m_nOriginFontFaceIndex{}; // sizes double m_dSpaceWidthMM{0}; @@ -77,6 +78,9 @@ namespace NSDocxRenderer bool m_bWriteStyleRaw{false}; bool m_bPossibleHorSplit{false}; + std::vector m_arGids{}; + std::vector m_arOriginLefts{}; + CContText() = default; CContText(CFontManager* pManager) : m_pManager(pManager) {} CContText(const CContText& rCont); @@ -92,13 +96,22 @@ namespace NSDocxRenderer void CalcSelected(); size_t GetLength() const noexcept; - void AddTextBack(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths); - void AddTextFront(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths); - void SetText(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths); + void AddTextBack(const NSStringUtils::CStringUTF32& oText, + const std::vector& arSymWidths, + const std::vector& arGids, + const std::vector& arOriginLefts); + void AddTextFront(const NSStringUtils::CStringUTF32& oText, + const std::vector& arSymWidths, + const std::vector& arGids, + const std::vector& arOriginLefts); + void SetText(const NSStringUtils::CStringUTF32& oText, + const std::vector& arSymWidths, + const std::vector& arGids, + const std::vector& arOriginLefts); - void AddSymBack(uint32_t cSym, double dWidth); - void AddSymFront(uint32_t cSym, double dWidth); - void SetSym(uint32_t cSym, double dWidth); + void AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); + void AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); + void SetSym(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); void RemoveLastSym(); uint32_t GetLastSym() const; @@ -172,6 +185,7 @@ namespace NSDocxRenderer const NSStructures::CBrush& oBrush, CFontManager* pFontManager, const NSStringUtils::CStringUTF32& oText, + const PUINT pGids = nullptr, bool bForcedBold = false, bool bUseDefaultFont = false, bool bWriteStyleRaw = false); diff --git a/DocxRenderer/src/logic/elements/Paragraph.cpp b/DocxRenderer/src/logic/elements/Paragraph.cpp index 1fc93141fc..ccf1b493f2 100644 --- a/DocxRenderer/src/logic/elements/Paragraph.cpp +++ b/DocxRenderer/src/logic/elements/Paragraph.cpp @@ -313,7 +313,7 @@ namespace NSDocxRenderer auto last_sym = text[text.length() - 1]; if (last_sym != c_SPACE_SYM && m_arTextLines.size() != 1) - pLastCont->AddSymBack(c_SPACE_SYM, 0); + pLastCont->AddSymBack(c_SPACE_SYM, 0, 0, pLastCont->m_dRight); } } } diff --git a/DocxRenderer/src/logic/elements/TextLine.cpp b/DocxRenderer/src/logic/elements/TextLine.cpp index 83901fa95c..dca9967e74 100644 --- a/DocxRenderer/src/logic/elements/TextLine.cpp +++ b/DocxRenderer/src/logic/elements/TextLine.cpp @@ -112,7 +112,7 @@ namespace NSDocxRenderer wide_space->m_dHeight = pCurrent->m_dHeight; - wide_space->SetSym(c_SPACE_SYM, wide_space->m_dRight - wide_space->m_dLeft); + wide_space->SetSym(c_SPACE_SYM, wide_space->m_dRight - wide_space->m_dLeft, 0, wide_space->m_dLeft); wide_space->m_pFontStyle = pFirst->m_pFontStyle; wide_space->m_pShape = nullptr; wide_space->m_iNumDuplicates = 0; @@ -146,12 +146,12 @@ namespace NSDocxRenderer { if (!bIsSpaceDelta) { - pFirst->AddTextBack(pCurrent->GetText(), pCurrent->GetSymWidths()); + pFirst->AddTextBack(pCurrent->GetText(), pCurrent->GetSymWidths(), pCurrent->m_arGids, pCurrent->m_arOriginLefts); } else { - pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight); - pFirst->AddTextBack(pCurrent->GetText(), pCurrent->GetSymWidths()); + pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, 0, pFirst->m_dRight); + pFirst->AddTextBack(pCurrent->GetText(), pCurrent->GetSymWidths(), pCurrent->m_arGids, pCurrent->m_arOriginLefts); } if (pFirst->m_pCont.expired()) @@ -166,9 +166,9 @@ namespace NSDocxRenderer if (bIsSpaceDelta) { if (pFirst->GetNumberOfFeatures() <= pCurrent->GetNumberOfFeatures()) - pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight); + pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, 0, pFirst->m_dRight); else - pCurrent->AddSymFront(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight); + pCurrent->AddSymFront(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, 0, pFirst->m_dRight); } pFirst = pCurrent; } From 2399ba41e48a25aceade23ca6cdc847678843041 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Tue, 28 Oct 2025 13:07:03 +0300 Subject: [PATCH 022/125] Fix miss place --- DocxRenderer/src/logic/elements/ContText.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index bbb46675f7..afd473da44 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -513,7 +513,6 @@ namespace NSDocxRenderer oWriter.WriteString(L"\" faceindex=\""); oWriter.AddInt(m_nOriginFontFaceIndex); oWriter.WriteString(L"\" />"); - oWriter.WriteString(L""); oWriter.WriteString(L""); + + oWriter.WriteString(L""); } void CContText::ToBin(NSWasm::CData& oWriter) const { From 6cf6ade6e3dd268eba1472b98b949db770c9d2cc Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Tue, 28 Oct 2025 13:11:40 +0300 Subject: [PATCH 023/125] Fix bug --- DocxRenderer/src/logic/elements/ContText.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index afd473da44..6fc76f9088 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -73,6 +73,9 @@ namespace NSDocxRenderer m_bPossibleHorSplit = rCont.m_bPossibleHorSplit; m_bWriteStyleRaw = rCont.m_bWriteStyleRaw; + m_nOriginFontFaceIndex = rCont.m_nOriginFontFaceIndex; + m_wsOriginFontName = rCont.m_nOriginFontFaceIndex; + m_arSymWidths.clear(); m_arSymWidths.resize(rCont.m_arSymWidths.size()); for (size_t i = 0; i < rCont.m_arSymWidths.size(); ++i) From e4c84e2972ece4502261bf114a9fa8de1293b95b Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Fri, 31 Oct 2025 16:50:04 +0300 Subject: [PATCH 024/125] fix text paragraph conversion --- .../Reader/Converter/pptx_text_context.cpp | 49 +++++++++++++++++-- OdfFile/Reader/Converter/pptx_text_context.h | 5 +- OdfFile/Reader/Format/draw_frame_pptx.cpp | 3 ++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/OdfFile/Reader/Converter/pptx_text_context.cpp b/OdfFile/Reader/Converter/pptx_text_context.cpp index 008db1e68e..93a9dc71d8 100644 --- a/OdfFile/Reader/Converter/pptx_text_context.cpp +++ b/OdfFile/Reader/Converter/pptx_text_context.cpp @@ -100,6 +100,11 @@ public: std::wstring get_last_paragraph_style_name(); + void set_predump(const bool& bPredump); + bool get_lasttext(); + + void seroing_predump(); + bool in_list_; bool process_layouts_; @@ -114,6 +119,7 @@ private: bool in_paragraph; bool in_comment; bool is_predump; + bool is_lasttext; odf_reader::styles_container * local_styles_ptr_; @@ -163,7 +169,7 @@ private: pptx_text_context::Impl::Impl(odf_reader::odf_read_context & odf_contxt_, pptx_conversion_context & pptx_contxt_): odf_context_(odf_contxt_), pptx_context_(pptx_contxt_), - paragraphs_cout_(0), in_paragraph(false),in_span(false), in_comment(false), field_type_(none) + paragraphs_cout_(0), in_paragraph(false),in_span(false),is_predump(false),is_lasttext(false), in_comment(false), field_type_(none) { new_list_style_number_=0; local_styles_ptr_ = NULL; @@ -175,7 +181,10 @@ void pptx_text_context::Impl::add_text(const std::wstring & text) if (field_type_) field_value_ << text; else + { + is_lasttext = true; text_ << text; + } } void pptx_text_context::Impl::add_paragraph(const std::wstring & para) { @@ -198,7 +207,6 @@ void pptx_text_context::Impl::start_paragraph(const std::wstring & styleName) //} //else/* (paragraph_style_name_ != styleName)*/ { - is_predump = true; dump_paragraph(); } }else @@ -209,7 +217,6 @@ void pptx_text_context::Impl::start_paragraph(const std::wstring & styleName) last_paragraph_style_name_ = paragraph_style_name_; paragraph_style_name_ = styleName; in_paragraph = true; - is_predump = false; } void pptx_text_context::Impl::end_paragraph() @@ -396,8 +403,14 @@ void pptx_text_context::Impl::write_pPr(std::wostream & strm) get_styles_context().start(); int level = list_style_stack_.size() - 1; - if (is_predump) - level--; + if (is_predump && is_lasttext) + { + seroing_predump(); + level = -1; + } + else + seroing_predump(); + odf_reader::paragraph_format_properties paragraph_properties_; @@ -980,5 +993,31 @@ std::wstring pptx_text_context::get_last_paragraph_style_name() return impl_->get_last_paragraph_style_name(); } +void pptx_text_context::set_predump(const bool &bPreDump) +{ + impl_->set_predump(bPreDump); +} + +bool pptx_text_context::get_lasttext() +{ + return impl_->get_lasttext(); +} + +void pptx_text_context::Impl::set_predump(const bool& bPredump) +{ + is_predump = bPredump; +} + +bool pptx_text_context::Impl::get_lasttext() +{ + return is_lasttext; +} + +void pptx_text_context::Impl::seroing_predump() +{ + is_predump = false; + is_lasttext = false; +} + } } diff --git a/OdfFile/Reader/Converter/pptx_text_context.h b/OdfFile/Reader/Converter/pptx_text_context.h index ffb9d306a2..134ac2c7fc 100644 --- a/OdfFile/Reader/Converter/pptx_text_context.h +++ b/OdfFile/Reader/Converter/pptx_text_context.h @@ -114,6 +114,9 @@ public: std::wstring get_last_paragraph_style_name(); + void set_predump(const bool& bPreDump); + bool get_lasttext(); + private: class Impl; @@ -123,4 +126,4 @@ private: }; } -} \ No newline at end of file +} diff --git a/OdfFile/Reader/Format/draw_frame_pptx.cpp b/OdfFile/Reader/Format/draw_frame_pptx.cpp index b917360343..130f5049e6 100644 --- a/OdfFile/Reader/Format/draw_frame_pptx.cpp +++ b/OdfFile/Reader/Format/draw_frame_pptx.cpp @@ -411,7 +411,10 @@ void draw_text_box::pptx_convert(oox::pptx_conversion_context & Context) for (size_t i = 0; i < content_.size(); i++) { + (i > 0 && Context.get_text_context().get_lasttext() && content_[i-1]->get_type() == cpdoccore::ElementType::typeTextP ? Context.get_text_context().set_predump(true): Context.get_text_context().set_predump(false)); + content_[i]->pptx_convert(Context); + } std::wstring text_content_ = Context.get_text_context().end_object(); From 71e96930c9b535ffefd8662dadac4309c9f03c4e Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Thu, 6 Nov 2025 12:08:23 +0300 Subject: [PATCH 025/125] Fix read Action --- DesktopEditor/graphics/commands/AnnotField.cpp | 6 ++++++ PdfFile/PdfEditor.cpp | 4 ++++ PdfFile/SrcWriter/Annotation.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index f031c2e882..07e56aff32 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -841,9 +841,15 @@ void CAnnotFieldInfo::CLinkAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* { m_nFlags = pReader->ReadInt(); if (m_nFlags & (1 << 0)) + { + pReader->ReadString(); m_pAction = ReadAction(pReader); + } if (m_nFlags & (1 << 1)) + { + pReader->ReadString(); m_pPA = ReadAction(pReader); + } if (m_nFlags & (1 << 2)) m_nH = pReader->ReadByte(); if (m_nFlags & (1 << 3)) diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 545bf15812..a58e084204 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -220,6 +220,8 @@ PdfWriter::CAnnotation* CreateAnnot(Object* oAnnot, Object* oType, PdfWriter::CX pAnnot = new PdfWriter::CRedactAnnotation(pXref); else if (oType->isName("Popup")) pAnnot = new PdfWriter::CPopupAnnotation(pXref); + else if (oType->isName("Link")) + pAnnot = new PdfWriter::CLinkAnnotation(pXref); else if (oType->isName("Widget")) { char* sName = NULL; @@ -2909,6 +2911,8 @@ bool CPdfEditor::EditAnnot(int _nPageIndex, int nID) pAnnot = new PdfWriter::CRedactAnnotation(pXref); else if (oType.isName("Popup")) pAnnot = new PdfWriter::CPopupAnnotation(pXref); + else if (oType.isName("Link")) + pAnnot = new PdfWriter::CLinkAnnotation(pXref); else if (oType.isName("Widget")) { bIsWidget = true; diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 900a6b072f..3054b1c604 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -2564,7 +2564,7 @@ namespace PdfWriter void CActionURI::SetURI(const std::wstring& wsURI) { std::string sValue = U_TO_UTF8(wsURI); - Add("URI", new CStringObject(sValue.c_str(), true)); + Add("URI", new CStringObject(sValue.c_str(), false, true)); } //---------------------------------------------------------------------------------------- CActionHide::CActionHide(CXref* pXref) : CAction(pXref) From 7048f132c6bea6bcbb898a5f642ae76f8d1bb65f Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Mon, 10 Nov 2025 13:13:52 +0300 Subject: [PATCH 026/125] Fix action GoTo FitR --- DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index fa99a0ae5b..8e3a877905 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -413,9 +413,9 @@ function readAction(reader, rec, readDoubleFunc, readStringFunc) case 4: { rec["left"] = readDoubleFunc.call(reader); - rec["bottom"] = readDoubleFunc.call(reader); + rec["top"] = readDoubleFunc.call(reader); rec["right"] = readDoubleFunc.call(reader); - rec["top"] = readDoubleFunc.call(reader); + rec["bottom"] = readDoubleFunc.call(reader); break; } case 1: From 04ccd4fe2764077deff50dd33e82739fe3ec694a Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Fri, 14 Nov 2025 16:56:43 +0300 Subject: [PATCH 027/125] Fix scale for tile --- DesktopEditor/graphics/Graphics.cpp | 1 + DesktopEditor/graphics/MetafileToRenderer.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/DesktopEditor/graphics/Graphics.cpp b/DesktopEditor/graphics/Graphics.cpp index 2ffd835aff..65c0489364 100644 --- a/DesktopEditor/graphics/Graphics.cpp +++ b/DesktopEditor/graphics/Graphics.cpp @@ -847,6 +847,7 @@ namespace Aggplus double dScaleY = m_dDpiY / m_dDpiTile; brushMatrix.Scale(dScaleX, dScaleY, Aggplus::MatrixOrderAppend); + brushMatrix.Scale(r - x, b - y, Aggplus::MatrixOrderAppend); } brushMatrix.Translate(x, y, Aggplus::MatrixOrderAppend); diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 4c6f4b4f3f..1703f4d46a 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -588,6 +588,14 @@ namespace NSOnlineOfficeBinToPdf case ctBrushTextureMode: { LONG lMode = (LONG)oReader.ReadByte(); + if (lMode != c_BrushTextureModeStretch) + { + Aggplus::RectF rect; + bool rectable; + pRenderer->get_BrushRect(rect, rectable); + if (rectable) + pRenderer->BrushRect(true, rect.X, rect.Y, 1.0, 1.0); + } pRenderer->put_BrushTextureMode(lMode); break; } @@ -726,6 +734,8 @@ namespace NSOnlineOfficeBinToPdf pRenderer->get_BrushTextureMode(&type); if (type == c_BrushTextureModeStretch) transMatrOff.Scale(m1, m2); + else if (rectable) + pRenderer->BrushRect(true, rect.X, rect.Y, m1, m2); break; } case ctDrawPath: From 13e03328af08d74f4085353beffbfc037c10860f Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Fri, 14 Nov 2025 16:58:09 +0300 Subject: [PATCH 028/125] Renumbering tile flip --- DesktopEditor/graphics/structures.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DesktopEditor/graphics/structures.h b/DesktopEditor/graphics/structures.h index 3f3e56140b..9ca2a9a014 100644 --- a/DesktopEditor/graphics/structures.h +++ b/DesktopEditor/graphics/structures.h @@ -113,10 +113,10 @@ const long c_BrushTypeTensorCurveGradient = 6007; const long c_BrushTextureModeStretch = 0; const long c_BrushTextureModeTile = 1; -const long c_BrushTextureModeTileCenter = 2; -const long c_BrushTextureModeTileFlipX = 3; -const long c_BrushTextureModeTileFlipY = 4; -const long c_BrushTextureModeTileFlipXY = 5; +const long c_BrushTextureModeTileFlipX = 2; +const long c_BrushTextureModeTileFlipY = 3; +const long c_BrushTextureModeTileFlipXY = 4; +const long c_BrushTextureModeTileCenter = 5; // -------------------------------------------------------------- namespace Aggplus { class CImage; } From 051597a78a46ac621571c4b2efa142e75934d173 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Mon, 17 Nov 2025 10:14:06 +0300 Subject: [PATCH 029/125] Add new commands to CheckBuffer --- DesktopEditor/graphics/MetafileToRenderer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 1703f4d46a..0c12756b7d 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -1228,6 +1228,10 @@ namespace NSOnlineOfficeBinToPdf oReader.Skip(1); break; } + case ctBrushResetRotation: + { + break; + } case ctSetTransform: { oReader.SkipInt(6); @@ -1260,6 +1264,16 @@ namespace NSOnlineOfficeBinToPdf { break; } + case ctPathCommandOffset: + { + oReader.SkipInt(2); + break; + } + case ctPathCommandScale: + { + oReader.SkipInt(2); + break; + } case ctDrawPath: { oReader.SkipInt(); From 16e78d87a4b975a506c68795589030d943ea0210 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Mon, 17 Nov 2025 10:14:35 +0300 Subject: [PATCH 030/125] Add logic for customRect --- DesktopEditor/graphics/MetafileToRenderer.cpp | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 0c12756b7d..b561786392 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -357,8 +357,10 @@ namespace NSOnlineOfficeBinToPdf CBufferReader oReader(pBuffer, lBufferLen); Aggplus::CGraphicsPath path; Aggplus::CMatrix transMatrRot; - Aggplus::CMatrix transMatrOff; + Aggplus::CMatrix transMatrSc; + Aggplus::RectF clipRect; bool isClose = false; + bool isTexture = false; while (oReader.Check()) { eCommand = (CommandType)(oReader.ReadByte()); @@ -478,6 +480,7 @@ namespace NSOnlineOfficeBinToPdf double m2 = oReader.ReadDouble(); double m3 = oReader.ReadDouble(); double m4 = oReader.ReadDouble(); + pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4); break; } @@ -503,6 +506,7 @@ namespace NSOnlineOfficeBinToPdf std::wstring sTempPath = oReader.ReadString16(nLen); std::wstring sImagePath = pCorrector->GetImagePath(sTempPath); pRenderer->put_BrushTexturePath(sImagePath); + isTexture = true; break; } case ctBrushGradient: @@ -702,16 +706,14 @@ namespace NSOnlineOfficeBinToPdf pRenderer->get_BrushRect(rect, rectable); if (rectable) { + clipRect = rect; rect.Offset(m1, m2); pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); - } - - LONG type; - pRenderer->get_BrushType(&type); - if (type == c_BrushTypeTexture) + LONG type; pRenderer->get_BrushTextureMode(&type); - if (type == c_BrushTextureModeStretch) - transMatrOff.Translate(m1, m2); + if (type == c_BrushTextureModeStretch) + clipRect.Offset(m1, m2); + } break; } case ctPathCommandScale: @@ -729,22 +731,29 @@ namespace NSOnlineOfficeBinToPdf } LONG type; - pRenderer->get_BrushType(&type); - if (type == c_BrushTypeTexture) - pRenderer->get_BrushTextureMode(&type); + pRenderer->get_BrushTextureMode(&type); if (type == c_BrushTextureModeStretch) - transMatrOff.Scale(m1, m2); + transMatrSc.Scale(m1, m2); else if (rectable) pRenderer->BrushRect(true, rect.X, rect.Y, m1, m2); break; } case ctDrawPath: { - Aggplus::CGraphicsPath clipPath1(path), clipPath2(path); - clipPath1.Transform(&transMatrRot); - clipPath2.Transform(&transMatrOff); + if (isTexture) + { + Aggplus::CGraphicsPath clipPath1(path); + clipPath1.Transform(&transMatrRot); - pRenderer->AddPath(Aggplus::CalcBooleanOperation(clipPath1, clipPath2, Aggplus::Intersection)); + Aggplus::CGraphicsPath clipPath2; + clipPath2.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); + clipPath2.Transform(&transMatrSc); + + path = Aggplus::CalcBooleanOperation(clipPath1, clipPath2, Aggplus::Intersection); + isTexture = false; + } + + pRenderer->AddPath(path); if (isClose) { @@ -755,7 +764,7 @@ namespace NSOnlineOfficeBinToPdf pRenderer->DrawPath(oReader.ReadInt()); path.Reset(); transMatrRot.Reset(); - transMatrOff.Reset(); + transMatrSc.Reset(); break; } case ctDrawImageFromFile: From 4543bfa6cd5d9615dc37f7c1edd47c79209eea92 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Mon, 17 Nov 2025 11:26:07 +0300 Subject: [PATCH 031/125] Fix add path to renderer --- DesktopEditor/graphics/GraphicsRenderer.cpp | 6 ++++-- DesktopEditor/graphics/MetafileToRenderer.cpp | 8 -------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index e4076fbe3c..d81e212b51 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -1148,7 +1148,7 @@ HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path) if (path.GetPointCount() == 0) return S_FALSE; - size_t length = path.GetPointCount(); + size_t length = path.GetPointCount() + path.GetCloseCount(); std::vector points = path.GetPoints(0, length); for (size_t i = 0; i < length; i++) @@ -1162,8 +1162,10 @@ HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path) } else if (path.IsMovePoint(i)) PathCommandMoveTo(points[i].X, points[i].Y); - else + else if (path.IsLinePoint(i)) PathCommandLineTo(points[i].X, points[i].Y); + else + PathCommandClose(); } return S_OK; diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index b561786392..57d9ea1715 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -592,14 +592,6 @@ namespace NSOnlineOfficeBinToPdf case ctBrushTextureMode: { LONG lMode = (LONG)oReader.ReadByte(); - if (lMode != c_BrushTextureModeStretch) - { - Aggplus::RectF rect; - bool rectable; - pRenderer->get_BrushRect(rect, rectable); - if (rectable) - pRenderer->BrushRect(true, rect.X, rect.Y, 1.0, 1.0); - } pRenderer->put_BrushTextureMode(lMode); break; } From 200c17ee40c8c7fafc6c7fe0279f594f9fb23d36 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Mon, 17 Nov 2025 19:37:30 +0300 Subject: [PATCH 032/125] Fix not rotate --- DesktopEditor/graphics/MetafileToRenderer.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 57d9ea1715..ccfc28945f 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -356,8 +356,8 @@ namespace NSOnlineOfficeBinToPdf CBufferReader oReader(pBuffer, lBufferLen); Aggplus::CGraphicsPath path; - Aggplus::CMatrix transMatrRot; Aggplus::CMatrix transMatrSc; + Aggplus::CMatrix transMatrRot; Aggplus::RectF clipRect; bool isClose = false; bool isTexture = false; @@ -481,6 +481,8 @@ namespace NSOnlineOfficeBinToPdf double m3 = oReader.ReadDouble(); double m4 = oReader.ReadDouble(); + clipRect = Aggplus::RectF(m1, m2, m3, m4); + pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4); break; } @@ -616,7 +618,7 @@ namespace NSOnlineOfficeBinToPdf (sin(atan2(rect.Height, rect.Width) + rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Height) / 2.0); pRenderer->SetTransform(mtr.sx(), mtr.shy(), mtr.shx(), mtr.sy(), mtr.tx(), mtr.ty()); - transMatrRot.Rotate(rot, Aggplus::MatrixOrderAppend); + transMatrRot.Rotate(agg::rad2deg(rot), Aggplus::MatrixOrderPrepend); transMatrRot.Translate((cos(atan2(rect.Height, rect.Width) - rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Width) / 2.0, (sin(atan2(rect.Height, rect.Width) - rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Height) / 2.0); break; @@ -698,7 +700,6 @@ namespace NSOnlineOfficeBinToPdf pRenderer->get_BrushRect(rect, rectable); if (rectable) { - clipRect = rect; rect.Offset(m1, m2); pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); LONG type; @@ -734,14 +735,12 @@ namespace NSOnlineOfficeBinToPdf { if (isTexture) { - Aggplus::CGraphicsPath clipPath1(path); - clipPath1.Transform(&transMatrRot); + Aggplus::CGraphicsPath clipPath; + clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); + clipPath.Transform(&transMatrSc); + clipPath.Transform(&transMatrRot); - Aggplus::CGraphicsPath clipPath2; - clipPath2.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); - clipPath2.Transform(&transMatrSc); - - path = Aggplus::CalcBooleanOperation(clipPath1, clipPath2, Aggplus::Intersection); + path = Aggplus::CalcBooleanOperation(path, clipPath, Aggplus::Intersection); isTexture = false; } @@ -754,6 +753,10 @@ namespace NSOnlineOfficeBinToPdf } pRenderer->DrawPath(oReader.ReadInt()); + + if (!transMatrRot.IsIdentity()) + pRenderer->SetTransform(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); + path.Reset(); transMatrRot.Reset(); transMatrSc.Reset(); From 0019f589bc11692bb0044c17c56f6d33a10f066f Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 18 Nov 2025 10:12:59 +0300 Subject: [PATCH 033/125] Fix scale tile texture --- DesktopEditor/graphics/Brush.cpp | 3 ++ DesktopEditor/graphics/Brush.h | 4 +++ DesktopEditor/graphics/Graphics.cpp | 3 +- DesktopEditor/graphics/GraphicsRenderer.cpp | 21 ++++++++++++ DesktopEditor/graphics/GraphicsRenderer.h | 2 ++ DesktopEditor/graphics/IRenderer.h | 2 ++ DesktopEditor/graphics/MetafileToRenderer.cpp | 32 ++++++++----------- DesktopEditor/graphics/structures.h | 12 +++++++ 8 files changed, 59 insertions(+), 20 deletions(-) diff --git a/DesktopEditor/graphics/Brush.cpp b/DesktopEditor/graphics/Brush.cpp index 558dcd6b43..00bdd19629 100644 --- a/DesktopEditor/graphics/Brush.cpp +++ b/DesktopEditor/graphics/Brush.cpp @@ -419,6 +419,7 @@ namespace Aggplus m_bReleaseImage = FALSE; Alpha = 255; m_bUseBounds = false; + m_bIsScale = false; } CBrushTexture::CBrushTexture(const std::wstring& strName, WrapMode wrapMode) : CBrush(BrushTypeTextureFill), m_wrapMode(wrapMode) @@ -427,6 +428,7 @@ namespace Aggplus m_bReleaseImage = TRUE; Alpha = 255; m_bUseBounds = false; + m_bIsScale = false; } CBrushTexture::CBrushTexture(CImage *pImage, WrapMode wrapMode) : CBrush(BrushTypeTextureFill), m_wrapMode(wrapMode) @@ -435,6 +437,7 @@ namespace Aggplus m_bReleaseImage = FALSE; Alpha = 255; m_bUseBounds = false; + m_bIsScale = false; } CBrushTexture::~CBrushTexture() diff --git a/DesktopEditor/graphics/Brush.h b/DesktopEditor/graphics/Brush.h index 980e7af94d..a0a211ff8e 100644 --- a/DesktopEditor/graphics/Brush.h +++ b/DesktopEditor/graphics/Brush.h @@ -205,6 +205,10 @@ public: bool m_bUseBounds; CDoubleRect m_oBounds; + bool m_bIsScale; + double m_dScaleX; + double m_dScaleY; + BYTE Alpha; }; } diff --git a/DesktopEditor/graphics/Graphics.cpp b/DesktopEditor/graphics/Graphics.cpp index 65c0489364..4762197810 100644 --- a/DesktopEditor/graphics/Graphics.cpp +++ b/DesktopEditor/graphics/Graphics.cpp @@ -847,7 +847,8 @@ namespace Aggplus double dScaleY = m_dDpiY / m_dDpiTile; brushMatrix.Scale(dScaleX, dScaleY, Aggplus::MatrixOrderAppend); - brushMatrix.Scale(r - x, b - y, Aggplus::MatrixOrderAppend); + if (ptxBrush->m_bIsScale) + brushMatrix.Scale(ptxBrush->m_dScaleX, ptxBrush->m_dScaleY, Aggplus::MatrixOrderAppend); } brushMatrix.Translate(x, y, Aggplus::MatrixOrderAppend); diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index d81e212b51..07650c2775 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -613,6 +613,20 @@ HRESULT CGraphicsRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix) m_oBrush.Transform = oMatrix; return S_OK; } +HRESULT CGraphicsRenderer::get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const +{ + isScale = m_oBrush.IsScale; + scaleX = m_oBrush.ScaleX; + scaleY = m_oBrush.ScaleY; + return S_OK; +} +HRESULT CGraphicsRenderer::put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) +{ + m_oBrush.IsScale = isScale; + m_oBrush.ScaleX = scaleX; + m_oBrush.ScaleY = scaleY; + return S_OK; +} HRESULT CGraphicsRenderer::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) { m_oBrush.Rectable = val; @@ -1041,6 +1055,13 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType) pTextureBrush->m_oBounds.right = pTextureBrush->m_oBounds.left + m_oBrush.Rect.Width; pTextureBrush->m_oBounds.bottom = pTextureBrush->m_oBounds.top + m_oBrush.Rect.Height; } + + if (m_oBrush.IsScale == 1) + { + pTextureBrush->m_bIsScale = true; + pTextureBrush->m_dScaleX = m_oBrush.ScaleX; + pTextureBrush->m_dScaleY = m_oBrush.ScaleY; + } } pBrush = pTextureBrush; diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index 37cdc73fb3..d651e90d9e 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -189,6 +189,8 @@ public: virtual HRESULT put_BrushLinearAngle(const double& dAngle); virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix); virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix); + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const; + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY); virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); virtual HRESULT get_BrushRect(Aggplus::RectF& rect, bool& rectable) const; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 4f9e9fdef5..c85cac0ad6 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -242,6 +242,8 @@ public: virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix) = 0; virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0; virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0; + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const = 0; + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) = 0; virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0; virtual HRESULT get_BrushRect(Aggplus::RectF& rect, bool& rectable) const = 0; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0; diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index ccfc28945f..b1b824503c 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -356,7 +356,6 @@ namespace NSOnlineOfficeBinToPdf CBufferReader oReader(pBuffer, lBufferLen); Aggplus::CGraphicsPath path; - Aggplus::CMatrix transMatrSc; Aggplus::CMatrix transMatrRot; Aggplus::RectF clipRect; bool isClose = false; @@ -714,21 +713,7 @@ namespace NSOnlineOfficeBinToPdf double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); - Aggplus::RectF rect; - bool rectable; - pRenderer->get_BrushRect(rect, rectable); - if (rectable) - { - rect.Scale(m1, m2); - pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); - } - - LONG type; - pRenderer->get_BrushTextureMode(&type); - if (type == c_BrushTextureModeStretch) - transMatrSc.Scale(m1, m2); - else if (rectable) - pRenderer->BrushRect(true, rect.X, rect.Y, m1, m2); + pRenderer->put_BrushScale(true, m1, m2); break; } case ctDrawPath: @@ -736,11 +721,21 @@ namespace NSOnlineOfficeBinToPdf if (isTexture) { Aggplus::CGraphicsPath clipPath; + Aggplus::CGraphicsPath drawPath; clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); - clipPath.Transform(&transMatrSc); clipPath.Transform(&transMatrRot); - path = Aggplus::CalcBooleanOperation(path, clipPath, Aggplus::Intersection); + if (!transMatrRot.IsIdentity()) + { + double left, top, width, height; + clipPath.GetBounds(left, top, width, height); + pRenderer->BrushRect(true, left, top, width, height); + drawPath.AddRectangle(left, top, width, height); + } + else + drawPath = path; + + path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection); isTexture = false; } @@ -759,7 +754,6 @@ namespace NSOnlineOfficeBinToPdf path.Reset(); transMatrRot.Reset(); - transMatrSc.Reset(); break; } case ctDrawImageFromFile: diff --git a/DesktopEditor/graphics/structures.h b/DesktopEditor/graphics/structures.h index 9ca2a9a014..2193cda208 100644 --- a/DesktopEditor/graphics/structures.h +++ b/DesktopEditor/graphics/structures.h @@ -287,6 +287,10 @@ namespace NSStructures Aggplus::RectF Rect; Aggplus::CDoubleRect Bounds; + int IsScale; + double ScaleX; + double ScaleY; + double LinearAngle; std::vector m_arrSubColors; NSStructures::GradientInfo m_oGradientInfo; @@ -418,6 +422,10 @@ namespace NSStructures Rect.Width = 0.0F; Rect.Height = 0.0F; + IsScale = FALSE; + ScaleX = 1.0; + ScaleY = 1.0; + Bounds.left = 0; Bounds.top = 0; Bounds.right = 0; @@ -457,6 +465,10 @@ namespace NSStructures Rect = other.Rect; Bounds = other.Bounds; + IsScale = other.IsScale; + ScaleX = other.ScaleX; + ScaleY = other.ScaleY; + LinearAngle = other.LinearAngle; m_arrSubColors = other.m_arrSubColors; m_oGradientInfo = other.m_oGradientInfo; From 8f3e19a5dbd618171ec6ec84c87b9e13f3cc9ae8 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 18 Nov 2025 22:06:42 +0300 Subject: [PATCH 034/125] Fix offset --- DesktopEditor/graphics/GraphicsRenderer.cpp | 16 ++++++++++++++-- DesktopEditor/graphics/GraphicsRenderer.h | 2 ++ DesktopEditor/graphics/IRenderer.h | 2 ++ DesktopEditor/graphics/MetafileToRenderer.cpp | 13 +------------ DesktopEditor/graphics/structures.h | 6 ++++++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 07650c2775..2fc2efdc99 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -613,6 +613,18 @@ HRESULT CGraphicsRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix) m_oBrush.Transform = oMatrix; return S_OK; } +HRESULT CGraphicsRenderer::get_BrushOffset(double& offsetX, double& offsetY) const +{ + offsetX = m_oBrush.OffsetX; + offsetY = m_oBrush.OffsetY; + return S_OK; +} +HRESULT CGraphicsRenderer::put_BrushOffset(const double& offsetX, const double& offsetY) +{ + m_oBrush.OffsetX = offsetX; + m_oBrush.OffsetY = offsetY; + return S_OK; +} HRESULT CGraphicsRenderer::get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { isScale = m_oBrush.IsScale; @@ -1050,8 +1062,8 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType) if (m_oBrush.Rectable == 1) { pTextureBrush->m_bUseBounds = true; - pTextureBrush->m_oBounds.left = m_oBrush.Rect.X; - pTextureBrush->m_oBounds.top = m_oBrush.Rect.Y; + pTextureBrush->m_oBounds.left = m_oBrush.Rect.X + m_oBrush.OffsetX; + pTextureBrush->m_oBounds.top = m_oBrush.Rect.Y + m_oBrush.OffsetY; pTextureBrush->m_oBounds.right = pTextureBrush->m_oBounds.left + m_oBrush.Rect.Width; pTextureBrush->m_oBounds.bottom = pTextureBrush->m_oBounds.top + m_oBrush.Rect.Height; } diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index d651e90d9e..7b01b307f2 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -189,6 +189,8 @@ public: virtual HRESULT put_BrushLinearAngle(const double& dAngle); virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix); virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix); + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const; + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY); virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const; virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY); virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index c85cac0ad6..cbb0dc9338 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -242,6 +242,8 @@ public: virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix) = 0; virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0; virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0; + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const = 0; + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) = 0; virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const = 0; virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) = 0; virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0; diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index b1b824503c..42b1a273a1 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -694,18 +694,7 @@ namespace NSOnlineOfficeBinToPdf double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); - Aggplus::RectF rect; - bool rectable; - pRenderer->get_BrushRect(rect, rectable); - if (rectable) - { - rect.Offset(m1, m2); - pRenderer->BrushRect(true, rect.X, rect.Y, rect.Width, rect.Height); - LONG type; - pRenderer->get_BrushTextureMode(&type); - if (type == c_BrushTextureModeStretch) - clipRect.Offset(m1, m2); - } + pRenderer->put_BrushOffset(m1, m2); break; } case ctPathCommandScale: diff --git a/DesktopEditor/graphics/structures.h b/DesktopEditor/graphics/structures.h index 2193cda208..19bfa9492c 100644 --- a/DesktopEditor/graphics/structures.h +++ b/DesktopEditor/graphics/structures.h @@ -291,6 +291,9 @@ namespace NSStructures double ScaleX; double ScaleY; + double OffsetX; + double OffsetY; + double LinearAngle; std::vector m_arrSubColors; NSStructures::GradientInfo m_oGradientInfo; @@ -426,6 +429,9 @@ namespace NSStructures ScaleX = 1.0; ScaleY = 1.0; + OffsetX = 0.0; + OffsetY = 0.0; + Bounds.left = 0; Bounds.top = 0; Bounds.right = 0; From 74a2b3b06fbe87ceae56e204fb45547f21919c66 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 18 Nov 2025 22:41:23 +0300 Subject: [PATCH 035/125] Fix Not rotate --- DesktopEditor/graphics/MetafileToRenderer.cpp | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 42b1a273a1..c3a93e1243 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -359,7 +359,6 @@ namespace NSOnlineOfficeBinToPdf Aggplus::CMatrix transMatrRot; Aggplus::RectF clipRect; bool isClose = false; - bool isTexture = false; while (oReader.Check()) { eCommand = (CommandType)(oReader.ReadByte()); @@ -507,7 +506,6 @@ namespace NSOnlineOfficeBinToPdf std::wstring sTempPath = oReader.ReadString16(nLen); std::wstring sImagePath = pCorrector->GetImagePath(sTempPath); pRenderer->put_BrushTexturePath(sImagePath); - isTexture = true; break; } case ctBrushGradient: @@ -610,16 +608,9 @@ namespace NSOnlineOfficeBinToPdf pRenderer->GetTransform(&old_t1, &old_t2, &old_t3, &old_t4, &old_t5, &old_t6); Aggplus::CMatrix mtr(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); + transMatrRot = mtr; - double rot = mtr.rotation(); - mtr.Rotate(-agg::rad2deg(rot)); - mtr.Translate((cos(atan2(rect.Height, rect.Width) + rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Width) / 2.0, - (sin(atan2(rect.Height, rect.Width) + rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Height) / 2.0); - - pRenderer->SetTransform(mtr.sx(), mtr.shy(), mtr.shx(), mtr.sy(), mtr.tx(), mtr.ty()); - transMatrRot.Rotate(agg::rad2deg(rot), Aggplus::MatrixOrderPrepend); - transMatrRot.Translate((cos(atan2(rect.Height, rect.Width) - rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Width) / 2.0, - (sin(atan2(rect.Height, rect.Width) - rot) * sqrt(rect.Width * rect.Width + rect.Height * rect.Height) - rect.Height) / 2.0); + pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); break; } case ctSetTransform: @@ -643,6 +634,7 @@ namespace NSOnlineOfficeBinToPdf pRenderer->BeginCommand(c_nPathType); pRenderer->PathCommandStart(); + path.Reset(); path.StartFigure(); bIsPathOpened = true; @@ -707,7 +699,11 @@ namespace NSOnlineOfficeBinToPdf } case ctDrawPath: { - if (isTexture) + long fill = oReader.ReadInt(); + long type; + pRenderer->get_BrushType(&type); + + if (fill != c_nStroke && type == c_BrushTypeTexture) { Aggplus::CGraphicsPath clipPath; Aggplus::CGraphicsPath drawPath; @@ -715,17 +711,39 @@ namespace NSOnlineOfficeBinToPdf clipPath.Transform(&transMatrRot); if (!transMatrRot.IsIdentity()) - { + { double left, top, width, height; clipPath.GetBounds(left, top, width, height); pRenderer->BrushRect(true, left, top, width, height); - drawPath.AddRectangle(left, top, width, height); + + double rot = transMatrRot.rotation(); + Aggplus::CGraphicsPath tmpPath(path); + tmpPath.Transform(&transMatrRot); + + bool isCustomRectRot = false; + size_t length = tmpPath.GetPointCount(); + auto points = tmpPath.GetPoints(0, 2); + auto pointDif = points[0] - points[1]; + if (length == 4 && ((pointDif.X < 0.1 && pointDif.X > -0.1) || (pointDif.Y < 0.1 && pointDif.Y > -0.1))) + isCustomRectRot = true; + + if ((rot < 1e-6 && rot > -1e-6) || isCustomRectRot) + { + drawPath = path; + drawPath.Transform(&transMatrRot); + if (isCustomRectRot) + { + drawPath.GetBounds(left, top, width, height); + pRenderer->BrushRect(true, left, top, width, height); + } + } + else + drawPath.AddRectangle(left, top, width, height); } else drawPath = path; path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection); - isTexture = false; } pRenderer->AddPath(path); @@ -736,13 +754,13 @@ namespace NSOnlineOfficeBinToPdf isClose = false; } - pRenderer->DrawPath(oReader.ReadInt()); + pRenderer->DrawPath(fill); if (!transMatrRot.IsIdentity()) pRenderer->SetTransform(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); - path.Reset(); transMatrRot.Reset(); + break; } case ctDrawImageFromFile: From 6c77718f17c5bef451a185d4aa0fed163e408f76 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Wed, 19 Nov 2025 22:30:47 +0300 Subject: [PATCH 036/125] Fix reset rotation --- DesktopEditor/graphics/MetafileToRenderer.cpp | 89 +++++++++++-------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index c3a93e1243..760a99dd82 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -359,6 +359,7 @@ namespace NSOnlineOfficeBinToPdf Aggplus::CMatrix transMatrRot; Aggplus::RectF clipRect; bool isClose = false; + bool isResetRot = false; while (oReader.Check()) { eCommand = (CommandType)(oReader.ReadByte()); @@ -479,8 +480,15 @@ namespace NSOnlineOfficeBinToPdf double m3 = oReader.ReadDouble(); double m4 = oReader.ReadDouble(); - clipRect = Aggplus::RectF(m1, m2, m3, m4); + long type; + pRenderer->get_BrushTextureMode(&type); + if (type != c_BrushTextureModeStretch) + { + m1 = 0.0; + m2 = 0.0; + } + clipRect = Aggplus::RectF(m1, m2, m3, m4); pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4); break; } @@ -602,15 +610,12 @@ namespace NSOnlineOfficeBinToPdf } case ctBrushResetRotation: { - Aggplus::RectF rect; - bool rectable; - pRenderer->get_BrushRect(rect, rectable); - pRenderer->GetTransform(&old_t1, &old_t2, &old_t3, &old_t4, &old_t5, &old_t6); - Aggplus::CMatrix mtr(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); - transMatrRot = mtr; - pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + Aggplus::CMatrix mtr(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); + double rot = mtr.rotation(); + transMatrRot.Rotate(agg::rad2deg(rot)); + isResetRot = true; break; } case ctSetTransform: @@ -642,6 +647,7 @@ namespace NSOnlineOfficeBinToPdf } case ctPathCommandMoveTo: { + if (isClose) isClose = false; double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); path.MoveTo(m1, m2); @@ -706,43 +712,43 @@ namespace NSOnlineOfficeBinToPdf if (fill != c_nStroke && type == c_BrushTypeTexture) { Aggplus::CGraphicsPath clipPath; - Aggplus::CGraphicsPath drawPath; - clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); - clipPath.Transform(&transMatrRot); + Aggplus::CGraphicsPath drawPath(path); + + if (isResetRot) + { + pRenderer->get_BrushTextureMode(&type); - if (!transMatrRot.IsIdentity()) - { double left, top, width, height; - clipPath.GetBounds(left, top, width, height); - pRenderer->BrushRect(true, left, top, width, height); + drawPath.GetBounds(left, top, width, height); double rot = transMatrRot.rotation(); - Aggplus::CGraphicsPath tmpPath(path); - tmpPath.Transform(&transMatrRot); + double cX = left + width / 2.0; + double cY = top + height / 2.0; - bool isCustomRectRot = false; - size_t length = tmpPath.GetPointCount(); - auto points = tmpPath.GetPoints(0, 2); - auto pointDif = points[0] - points[1]; - if (length == 4 && ((pointDif.X < 0.1 && pointDif.X > -0.1) || (pointDif.Y < 0.1 && pointDif.Y > -0.1))) - isCustomRectRot = true; + transMatrRot.Reset(); + transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend); + drawPath.Transform(&transMatrRot); - if ((rot < 1e-6 && rot > -1e-6) || isCustomRectRot) - { - drawPath = path; - drawPath.Transform(&transMatrRot); - if (isCustomRectRot) - { - drawPath.GetBounds(left, top, width, height); - pRenderer->BrushRect(true, left, top, width, height); - } - } + if (clipRect.X == 0.0 && clipRect.Y == 0.0 && type == c_BrushTextureModeStretch && rot != 0.0) + drawPath.GetBounds(left, top, width, height); else - drawPath.AddRectangle(left, top, width, height); - } - else - drawPath = path; + { + Aggplus::CGraphicsPath tmpPath; + tmpPath.AddRectangle(left, top, width, height); + tmpPath.Transform(&transMatrRot); + tmpPath.GetBounds(left, top, width, height); + } + pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, old_t5 - transMatrRot.tx(), old_t6 - transMatrRot.ty()); + + if ((clipRect.X == 0.0 && clipRect.Y == 0.0) || type != c_BrushTextureModeStretch) + clipRect = Aggplus::RectF(left, top, width, height); + + if (type == c_BrushTextureModeStretch) + pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); + } + + clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection); } @@ -756,11 +762,16 @@ namespace NSOnlineOfficeBinToPdf pRenderer->DrawPath(fill); - if (!transMatrRot.IsIdentity()) + if (isResetRot) + { pRenderer->SetTransform(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); + isResetRot = false; + } transMatrRot.Reset(); - + pRenderer->put_BrushScale(false, 1.0, 1.0); + pRenderer->put_BrushOffset(0.0, 0.0); + clipRect = Aggplus::RectF(); break; } case ctDrawImageFromFile: From b98b808cda736c7d8781ab27047e11ea82ae049f Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Wed, 19 Nov 2025 22:40:25 +0300 Subject: [PATCH 037/125] Delete unused methods --- DesktopEditor/graphics/GraphicsPath.cpp | 27 --------------------- DesktopEditor/graphics/GraphicsPath.h | 1 - DesktopEditor/graphics/GraphicsRenderer.cpp | 6 ----- DesktopEditor/graphics/GraphicsRenderer.h | 1 - DesktopEditor/graphics/IRenderer.h | 1 - DesktopEditor/graphics/aggplustypes.h | 3 +-- 6 files changed, 1 insertion(+), 38 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsPath.cpp b/DesktopEditor/graphics/GraphicsPath.cpp index 6c595af456..4f15063441 100644 --- a/DesktopEditor/graphics/GraphicsPath.cpp +++ b/DesktopEditor/graphics/GraphicsPath.cpp @@ -462,33 +462,6 @@ namespace Aggplus return Ok; } - CGraphicsPath CGraphicsPath::Trsanslate(const double& offsetX, const double& offsetY) - { - CGraphicsPath result; - result.StartFigure(); - - unsigned length = GetPointCount(); - std::vector points = GetPoints(0, length); - - for (unsigned i = 0; i < length; i++) - { - if (IsCurvePoint(i)) - { - result.CurveTo(points[i].X + offsetX, points[i].Y + offsetY, - points[i + 1].X + offsetX, points[i + 1].Y + offsetY, - points[i + 2].X + offsetX, points[i + 2].Y + offsetY); - i += 2; - } - else if (IsMovePoint(i)) - result.MoveTo(points[i].X + offsetX, points[i].Y + offsetY); - else if (IsLinePoint(i)) - result.LineTo(points[i].X + offsetX, points[i].Y + offsetY); - } - result.CloseFigure(); - - return result; - } - bool CGraphicsPath::_MoveTo(double x, double y) { if (NULL != m_internal->m_pTransform) diff --git a/DesktopEditor/graphics/GraphicsPath.h b/DesktopEditor/graphics/GraphicsPath.h index 4db6117165..a0fe6bcdeb 100644 --- a/DesktopEditor/graphics/GraphicsPath.h +++ b/DesktopEditor/graphics/GraphicsPath.h @@ -84,7 +84,6 @@ namespace Aggplus void GetBoundsAccurate(double& left, double& top, double& width, double& height) const; Status Transform(const CMatrix* matrix); - CGraphicsPath Trsanslate(const double& offsetX, const double& offsetY); virtual bool _MoveTo(double x, double y); virtual bool _LineTo(double x, double y); virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3); diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 2fc2efdc99..25439758e9 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -648,12 +648,6 @@ HRESULT CGraphicsRenderer::BrushRect(const INT& val, const double& left, const d m_oBrush.Rect.Height = (float)height; return S_OK; } -HRESULT CGraphicsRenderer::get_BrushRect(Aggplus::RectF& rect, bool& rectable) const -{ - rectable = m_oBrush.Rectable; - rect = m_oBrush.Rect; - return S_OK; -} HRESULT CGraphicsRenderer::BrushBounds(const double& left, const double& top, const double& width, const double& height) { m_oBrush.Bounds.left = left; diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index 7b01b307f2..2b3185bd5f 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -194,7 +194,6 @@ public: virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const; virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY); virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); - virtual HRESULT get_BrushRect(Aggplus::RectF& rect, bool& rectable) const; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height); virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index cbb0dc9338..f3bfa594db 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -247,7 +247,6 @@ public: virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const = 0; virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) = 0; virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0; - virtual HRESULT get_BrushRect(Aggplus::RectF& rect, bool& rectable) const = 0; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0; virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount) = 0; diff --git a/DesktopEditor/graphics/aggplustypes.h b/DesktopEditor/graphics/aggplustypes.h index 0ff943aac0..fc10bd1033 100644 --- a/DesktopEditor/graphics/aggplustypes.h +++ b/DesktopEditor/graphics/aggplustypes.h @@ -210,8 +210,7 @@ public: } void Offset(const PointF_T& point) { Offset(point.X, point.Y); } - void Offset(const T& dx, const T& dy) { X += dx; Y += dy; } - void Scale(const T& sx, const T& sy) { Width *= sx; Height *= sy; } + void Offset(T dx, T dy) { X += dx; Y += dy; } RectF_T& operator=(const RectF_T& other) { From 490281dda016ea9b175fe1cf5498169bcef14c1e Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Wed, 19 Nov 2025 23:14:28 +0300 Subject: [PATCH 038/125] Fix compare double --- DesktopEditor/graphics/MetafileToRenderer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 760a99dd82..640f7d19f9 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -357,7 +357,7 @@ namespace NSOnlineOfficeBinToPdf CBufferReader oReader(pBuffer, lBufferLen); Aggplus::CGraphicsPath path; Aggplus::CMatrix transMatrRot; - Aggplus::RectF clipRect; + Aggplus::RectF_T clipRect; bool isClose = false; bool isResetRot = false; while (oReader.Check()) @@ -488,7 +488,7 @@ namespace NSOnlineOfficeBinToPdf m2 = 0.0; } - clipRect = Aggplus::RectF(m1, m2, m3, m4); + clipRect = Aggplus::RectF_T(m1, m2, m3, m4); pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4); break; } @@ -717,6 +717,7 @@ namespace NSOnlineOfficeBinToPdf if (isResetRot) { pRenderer->get_BrushTextureMode(&type); + bool isStretch = type == c_BrushTextureModeStretch; double left, top, width, height; drawPath.GetBounds(left, top, width, height); @@ -729,7 +730,10 @@ namespace NSOnlineOfficeBinToPdf transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend); drawPath.Transform(&transMatrRot); - if (clipRect.X == 0.0 && clipRect.Y == 0.0 && type == c_BrushTextureModeStretch && rot != 0.0) + bool isZeroPt = clipRect.X < 0.1 && clipRect.X > -0.1 && clipRect.Y < 0.1 && clipRect.Y > -0.1; + bool isZeroRot = rot < 1e-6 && rot > -1e-6; + + if (isZeroPt && !isZeroRot && isStretch) drawPath.GetBounds(left, top, width, height); else { @@ -741,8 +745,8 @@ namespace NSOnlineOfficeBinToPdf pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, old_t5 - transMatrRot.tx(), old_t6 - transMatrRot.ty()); - if ((clipRect.X == 0.0 && clipRect.Y == 0.0) || type != c_BrushTextureModeStretch) - clipRect = Aggplus::RectF(left, top, width, height); + if (isZeroPt || !isStretch) + clipRect = Aggplus::RectF_T(left, top, width, height); if (type == c_BrushTextureModeStretch) pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); @@ -771,7 +775,7 @@ namespace NSOnlineOfficeBinToPdf transMatrRot.Reset(); pRenderer->put_BrushScale(false, 1.0, 1.0); pRenderer->put_BrushOffset(0.0, 0.0); - clipRect = Aggplus::RectF(); + clipRect = Aggplus::RectF_T(); break; } case ctDrawImageFromFile: From f0b266793f7d32dab7ff5b46c6cc7d800199c1b7 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Wed, 19 Nov 2025 23:24:05 +0300 Subject: [PATCH 039/125] Refactoring --- DesktopEditor/graphics/MetafileToRenderer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 640f7d19f9..f1974018f1 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -726,13 +726,14 @@ namespace NSOnlineOfficeBinToPdf double cX = left + width / 2.0; double cY = top + height / 2.0; - transMatrRot.Reset(); - transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend); - drawPath.Transform(&transMatrRot); - bool isZeroPt = clipRect.X < 0.1 && clipRect.X > -0.1 && clipRect.Y < 0.1 && clipRect.Y > -0.1; bool isZeroRot = rot < 1e-6 && rot > -1e-6; + transMatrRot.Reset(); + transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend); + + drawPath.Transform(&transMatrRot); + if (isZeroPt && !isZeroRot && isStretch) drawPath.GetBounds(left, top, width, height); else @@ -748,7 +749,7 @@ namespace NSOnlineOfficeBinToPdf if (isZeroPt || !isStretch) clipRect = Aggplus::RectF_T(left, top, width, height); - if (type == c_BrushTextureModeStretch) + if (isStretch) pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); } From 6e496705137c1ded70fd6c753bcc74fa1b7c105e Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Mon, 1 Dec 2025 16:13:49 +0300 Subject: [PATCH 040/125] Implemented support for the BaselineShift property in svg --- .../3dParty/html/css/src/StyleProperties.cpp | 52 ++++++- Common/3dParty/html/css/src/StyleProperties.h | 39 ++++- .../raster/Metafile/svg/SvgObjects/CText.cpp | 143 +++++++++++++----- .../raster/Metafile/svg/SvgObjects/CText.h | 4 +- 4 files changed, 196 insertions(+), 42 deletions(-) diff --git a/Common/3dParty/html/css/src/StyleProperties.cpp b/Common/3dParty/html/css/src/StyleProperties.cpp index 94ac55edea..a1a1b6e5c3 100644 --- a/Common/3dParty/html/css/src/StyleProperties.cpp +++ b/Common/3dParty/html/css/src/StyleProperties.cpp @@ -2255,6 +2255,11 @@ namespace NSCSS return m_oHighlight.SetValue(wsValue, unLevel, bHardMode); } + bool CText::SetBaselineShift(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) + { + return m_oBaselineShift.SetValue(wsValue, unLevel, bHardMode); + } + const CDigit& CText::GetIndent() const { return m_oIndent; @@ -2280,10 +2285,21 @@ namespace NSCSS return m_oHighlight; } + EBaselineShift CText::GetBaselineShiftType() const + { + return m_oBaselineShift.GetType(); + } + + double CText::GetBaselineShiftValue() const + { + return m_oBaselineShift.GetValue(); + } + bool CText::Empty() const { return m_oIndent.Empty() && m_oAlign.Empty() && - m_oDecoration.m_oLine.Empty() && m_oColor.Empty(); + m_oDecoration.m_oLine.Empty() && m_oColor.Empty() && + m_oBaselineShift.Empty(); } bool CText::Underline() const @@ -2617,6 +2633,40 @@ namespace NSCSS m_oColor == oTextDecoration.m_oColor; } + CBaselineShift::CBaselineShift() + { + m_eType.SetMapping({{L"baseline", EBaselineShift::Baseline}, {L"sub", EBaselineShift::Sub}, {L"super", EBaselineShift::Super}}, EBaselineShift::Baseline); + } + + bool CBaselineShift::Empty() const + { + return m_eType.Empty() && m_oValue.Empty(); + } + + EBaselineShift CBaselineShift::GetType() const + { + if (m_oValue.Empty()) + return (EBaselineShift)m_eType.ToInt(); + + if (UnitMeasure::Percent == m_oValue.GetUnitMeasure()) + return EBaselineShift::Percentage; + + return EBaselineShift::Length; + } + + double CBaselineShift::GetValue() const + { + if (UnitMeasure::Percent == m_oValue.GetUnitMeasure()) + return m_oValue.ToDouble(); + + return m_oValue.ToDouble(NSCSS::Pixel); + } + + bool CBaselineShift::SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) + { + return m_eType.SetValue(wsValue, unLevel, bHardMode) || m_oValue.SetValue(wsValue, unLevel, bHardMode); + } + CFont::CFont() {} diff --git a/Common/3dParty/html/css/src/StyleProperties.h b/Common/3dParty/html/css/src/StyleProperties.h index 7198ef4aa8..bcd6e2f7d3 100644 --- a/Common/3dParty/html/css/src/StyleProperties.h +++ b/Common/3dParty/html/css/src/StyleProperties.h @@ -619,6 +619,30 @@ namespace NSCSS bool operator==(const TTextDecoration& oTextDecoration) const; }; + typedef enum + { + Baseline, + Sub, + Super, + Percentage, + Length + } EBaselineShift; + + class CBaselineShift + { + CEnum m_eType; + CDigit m_oValue; + public: + CBaselineShift(); + + bool Empty() const; + + EBaselineShift GetType() const; + double GetValue() const; + + bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + }; + class CText { public: @@ -626,11 +650,12 @@ namespace NSCSS static void Equation(CText &oFirstText, CText &oSecondText); - bool SetIndent (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); - bool SetAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); - bool SetDecoration(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); - bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); - bool SetHighlight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + bool SetIndent (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + bool SetAlign (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + bool SetDecoration (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + bool SetColor (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + bool SetHighlight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); + bool SetBaselineShift (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); const CDigit& GetIndent() const; const CString& GetAlign() const; @@ -638,6 +663,9 @@ namespace NSCSS const CColor& GetColor() const; const CColor& GetHighlight() const; + EBaselineShift GetBaselineShiftType() const; + double GetBaselineShiftValue() const; + bool Empty() const; bool Underline() const; @@ -647,6 +675,7 @@ namespace NSCSS CText& operator+=(const CText& oText); bool operator==(const CText& oText) const; private: + CBaselineShift m_oBaselineShift; TTextDecoration m_oDecoration; CDigit m_oIndent; CString m_oAlign; diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp index 7d84b5fae0..b5a1b5d9bf 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp @@ -110,6 +110,9 @@ namespace SVG if (mAttributes.end() != mAttributes.find(L"text-decoration")) m_oText.SetDecoration(mAttributes.at(L"text-decoration"), ushLevel, bHardMode); + if (mAttributes.end() != mAttributes.find(L"baseline-shift")) + m_oText.SetBaselineShift(mAttributes.at(L"baseline-shift"), ushLevel, bHardMode); + //POSITION if (mAttributes.end() != mAttributes.find(L"rotate")) { @@ -241,7 +244,27 @@ namespace SVG std::wstring wsFontFamily = DefaultFontFamily; double dFontSize = ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE) * 72. / 25.4; - Normalize(pRenderer, dX, dY, dFontSize, oOldMatrix); + double dScaleX = 1., dScaleY = 1.; + + NormalizeFontSize(dFontSize, dScaleX, dScaleY); + + if (!Equals(1., dScaleX) || !Equals(1., dScaleY)) + { + dX /= dScaleX; + dY /= dScaleY; + + double dM11, dM12, dM21, dM22, dDx, dDy; + + pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy); + + oOldMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy); + + Aggplus::CMatrix oMatrix(dM11, dM12, dM21, dM22, dDx, dDy); + + oMatrix.Scale(dScaleX, dScaleY); + + pRenderer->SetTransform(oMatrix.sx(), oMatrix.shy(), oMatrix.shx(), oMatrix.sy(), oMatrix.tx(), oMatrix.ty()); + } if (!m_oFont.GetFamily().Empty()) { @@ -271,12 +294,12 @@ namespace SVG m_pFontManager->LoadFontByName(wsFontFamily, dFontSize, nStyle, 72., 72.); m_pFontManager->SetCharSpacing(0); - double dKoef = 25.4 / 72.; + const double dKoef = 25.4 / 72.; NSFonts::IFontFile* pFontFile = m_pFontManager->GetFile(); if (pFontFile) - dFHeight *= pFontFile->GetHeight() / pFontFile->Units_Per_Em() * dKoef; + dFHeight *= pFontFile->GetHeight() / pFontFile->Units_Per_Em() * dKoef; m_pFontManager->LoadString1(m_wsText, 0, 0); TBBox oBox = m_pFontManager->MeasureString2(); @@ -299,6 +322,45 @@ namespace SVG else if (L"center" == m_oText.GetAlign().ToWString()) dX += -fW / 2; + if (NSCSS::NSProperties::EBaselineShift::Baseline != m_oText.GetBaselineShiftType()) + { + switch(m_oText.GetBaselineShiftType()) + { + case NSCSS::NSProperties::Sub: + { + dY += dFHeight / 2.; + break; + } + case NSCSS::NSProperties::Super: + { + double dParentHeight{dFHeight}; + + if (nullptr != m_pParent) + dParentHeight = ((CTSpan*)m_pParent)->GetFontHeight() / dScaleY; + + dY -= dParentHeight - dFHeight / 2.; + break; + } + case NSCSS::NSProperties::Percentage: + { + double dParentHeight{dFHeight}; + + if (nullptr != m_pParent) + dParentHeight = ((CTSpan*)m_pParent)->GetFontHeight() / dScaleY; + + dY -= dParentHeight * (m_oText.GetBaselineShiftValue() / 100.); + break; + } + case NSCSS::NSProperties::Length: + { + dY -= m_oText.GetBaselineShiftValue() / dScaleY; + break; + } + default: + break; + } + } + if (m_oText.Underline() || m_oText.LineThrough() || m_oText.Overline()) { pRenderer->put_PenSize((double)fUndSize); @@ -389,7 +451,7 @@ namespace SVG oBounds.m_dRight = oBounds.m_dLeft + GetWidth(); oBounds.m_dBottom = m_oY.ToDouble(NSCSS::Pixel); - oBounds.m_dTop = oBounds.m_dBottom + ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE); + oBounds.m_dTop = oBounds.m_dBottom - ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE); if (nullptr != pTransform) { @@ -484,56 +546,33 @@ namespace SVG dY = m_oY.ToDouble(NSCSS::Pixel, oBounds.m_dBottom - oBounds.m_dTop); } - void CTSpan::Normalize(IRenderer *pRenderer, double &dX, double &dY, double &dFontHeight, Aggplus::CMatrix& oOldMatrix) const + void CTSpan::NormalizeFontSize(double& dFontHeight, double& dScaleX, double& dScaleY) const { - if (NULL == pRenderer) - return; - Aggplus::CMatrix oCurrentMatrix(m_oTransformation.m_oTransform.GetMatrix().GetFinalValue()); - double dXScale = 1., dYScale = 1.; - const double dModuleM11 = std::abs(oCurrentMatrix.sx()); const double dModuleM22 = std::abs(oCurrentMatrix.sy()); if (!ISZERO(dModuleM11) && (dModuleM11 < MIN_SCALE || dModuleM11 > MAX_SCALE)) - dXScale /= dModuleM11; + dScaleX /= dModuleM11; if (!ISZERO(dModuleM22) && (dModuleM22 < MIN_SCALE || dModuleM22 > MAX_SCALE)) - dYScale /= dModuleM22; + dScaleY /= dModuleM22; - dFontHeight *= dYScale; + dFontHeight *= dScaleY; if (!Equals(0., dFontHeight) && dFontHeight < MIN_FONT_SIZE) { - dXScale *= MIN_FONT_SIZE / dFontHeight; - dYScale *= MIN_FONT_SIZE / dFontHeight; + dScaleX *= MIN_FONT_SIZE / dFontHeight; + dScaleY *= MIN_FONT_SIZE / dFontHeight; dFontHeight = MIN_FONT_SIZE; } else if (!Equals(0., dFontHeight) && dFontHeight > MAX_FONT_SIZE) { - dXScale *= dFontHeight / MAX_FONT_SIZE; - dYScale *= dFontHeight / MAX_FONT_SIZE; + dScaleX *= dFontHeight / MAX_FONT_SIZE; + dScaleY *= dFontHeight / MAX_FONT_SIZE; dFontHeight = MAX_FONT_SIZE; } - - if (Equals(1., dXScale) && Equals(1., dYScale)) - return; - - dX /= dXScale; - dY /= dYScale; - - double dM11, dM12, dM21, dM22, dDx, dDy; - - pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy); - - oOldMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy); - - Aggplus::CMatrix oMatrix(dM11, dM12, dM21, dM22, dDx, dDy); - - oMatrix.Scale(dXScale, dYScale); - - pRenderer->SetTransform(oMatrix.sx(), oMatrix.shy(), oMatrix.shx(), oMatrix.sy(), oMatrix.tx(), oMatrix.ty()); } void CTSpan::SetPosition(const Point &oPosition) @@ -569,6 +608,40 @@ namespace SVG } + double CTSpan::GetFontHeight() const + { + + if (NULL == m_pFontManager) + return ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE) * 72. / 25.4; + + std::wstring wsFontFamily = DefaultFontFamily; + double dFontSize = ((!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Pixel) : DEFAULT_FONT_SIZE) * 72. / 25.4; + + if (!m_oFont.GetFamily().Empty()) + { + wsFontFamily = m_oFont.GetFamily().ToWString(); + CorrectFontFamily(wsFontFamily); + } + + int nStyle = 0; + + if (m_oFont.GetWeight().ToWString() == L"bold") + nStyle |= 0x01; + if (m_oFont.GetStyle() .ToWString() == L"italic") + nStyle |= 0x02; + if (m_oText.Underline()) + nStyle |= (1 << 2); + + // Вычиления размеров текста + m_pFontManager->LoadFontByName(wsFontFamily, dFontSize, nStyle, 72., 72.); + m_pFontManager->SetCharSpacing(0); + + m_pFontManager->LoadString1(m_wsText, 0, 0); + TBBox oBox = m_pFontManager->MeasureString2(); + + return (double)(25.4f / 72.f * (oBox.fMaxY - oBox.fMinY)); + } + std::vector CTSpan::Split() const { std::vector arGlyphs; diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h index 1c5e135d4d..1fd1b75093 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h @@ -44,11 +44,13 @@ namespace SVG void CalculatePosition(double& dX, double& dY) const; - void Normalize(IRenderer* pRenderer, double& dX, double& dY, double& dFontHeight, Aggplus::CMatrix& oOldMatrix) const; + void NormalizeFontSize(double& dFontHeight, double& dScaleX, double& dScaleY) const; void SetPosition(const Point& oPosition); void SetPositionFromParent(CRenderedObject* pParent); + double GetFontHeight() const; + std::vector Split() const; NSFonts::IFontManager* m_pFontManager; From cd80bca5532096e9dde8c12fa36516dfc5a599d2 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Mon, 1 Dec 2025 16:34:21 +0300 Subject: [PATCH 041/125] Fix fill with context color in svg --- .../raster/Metafile/svg/SvgObjects/CObjectBase.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp index d5ea746b17..1524a382bf 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp @@ -426,9 +426,15 @@ namespace SVG } } else if (NSCSS::NSProperties::ColorType::ColorContextFill == pFill->GetType() && NULL != pContextObject) - pRenderer->put_BrushColor1(pContextObject->m_oStyles.m_oFill.ToInt()); + { + if (!ApplyFill(pRenderer, &pContextObject->m_oStyles.m_oFill, pFile, bUseDefault, pContextObject)) + return false; + } else if (NSCSS::NSProperties::ColorType::ColorContextStroke == pFill->GetType() && NULL != pContextObject) - pRenderer->put_BrushColor1(pContextObject->m_oStyles.m_oStroke.m_oColor.ToInt()); + { + if (!ApplyFill(pRenderer, &pContextObject->m_oStyles.m_oStroke.m_oColor, pFile, bUseDefault, pContextObject)) + return false; + } else if (bUseDefault) { pRenderer->put_BrushColor1(0); From fe6c5614d4ba6e1de06c6a9be2b260704e2a7858 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 2 Dec 2025 01:24:49 +0300 Subject: [PATCH 042/125] Add pdf methods for test --- PdfFile/PdfFile.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 717b9a7607..b83361a5d9 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -222,6 +222,11 @@ public: virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const { return S_OK; } + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) { return S_OK; } virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount); From ed939ebd1d04ea4c4b6cea35e37c0fbdc280ea56 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 2 Dec 2025 01:37:30 +0300 Subject: [PATCH 043/125] Add html methods for test --- DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h b/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h index 79a4d144f9..15c1ec1308 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h @@ -113,6 +113,10 @@ namespace NSHtmlRenderer virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const { return S_OK; } + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height); From 8464d3aeb7f475b68598858d9bb0dd0b29062dcc Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 2 Dec 2025 01:41:15 +0300 Subject: [PATCH 044/125] Add AddPath method for test --- DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h | 1 + 1 file changed, 1 insertion(+) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h b/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h index 15c1ec1308..22be1a88ac 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h @@ -117,6 +117,7 @@ namespace NSHtmlRenderer virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) { return S_OK; } virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height); From 1c8ad7a5c4543ddff1525f2af820254cdf24441b Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 2 Dec 2025 01:44:07 +0300 Subject: [PATCH 045/125] Add docxmethods for test --- DocxRenderer/DocxRenderer.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DocxRenderer/DocxRenderer.h b/DocxRenderer/DocxRenderer.h index 0903f78acc..f1faca6a30 100644 --- a/DocxRenderer/DocxRenderer.h +++ b/DocxRenderer/DocxRenderer.h @@ -107,7 +107,11 @@ public: virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); - + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const { return S_OK; } + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) { return S_OK; } virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); From 3f6a800dd8a5241b0b818ad0ab9c3a3d3484ea5c Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 2 Dec 2025 02:06:17 +0300 Subject: [PATCH 046/125] Rollback --- DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h | 5 ----- DocxRenderer/DocxRenderer.h | 5 ----- PdfFile/PdfFile.h | 5 ----- 3 files changed, 15 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h b/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h index 22be1a88ac..79a4d144f9 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/HTMLRendererText.h @@ -113,11 +113,6 @@ namespace NSHtmlRenderer virtual HRESULT put_BrushTextureAlpha(const LONG& lTxAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); - virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const { return S_OK; } - virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } - virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } - virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) { return S_OK; } virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height); virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height); diff --git a/DocxRenderer/DocxRenderer.h b/DocxRenderer/DocxRenderer.h index f1faca6a30..109859782f 100644 --- a/DocxRenderer/DocxRenderer.h +++ b/DocxRenderer/DocxRenderer.h @@ -107,11 +107,6 @@ public: virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); - virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const { return S_OK; } - virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } - virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } - virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) { return S_OK; } virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index b83361a5d9..717b9a7607 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -222,11 +222,6 @@ public: virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); - virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const { return S_OK; } - virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) { return S_OK; } - virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const { return S_OK; } - virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) { return S_OK; } - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) { return S_OK; } virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount); From b5f0b39258e3618328ec799fa24b13baa3bad0db Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 2 Dec 2025 11:22:12 +0300 Subject: [PATCH 047/125] Remove pure virtual functions --- DesktopEditor/graphics/IRenderer.h | 36 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index f3bfa594db..1026c584cf 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -242,10 +242,32 @@ public: virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix) = 0; virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0; virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0; - virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const = 0; - virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) = 0; - virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const = 0; - virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) = 0; + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const + { + UNUSED_VARIABLE(offsetX); + UNUSED_VARIABLE(offsetY); + return S_OK; + } + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY) + { + UNUSED_VARIABLE(offsetX); + UNUSED_VARIABLE(offsetY); + return S_OK; + } + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const + { + UNUSED_VARIABLE(isScale); + UNUSED_VARIABLE(scaleX); + UNUSED_VARIABLE(scaleY); + return S_OK; + } + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) + { + UNUSED_VARIABLE(isScale); + UNUSED_VARIABLE(scaleX); + UNUSED_VARIABLE(scaleY); + return S_OK; + } virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0; virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0; @@ -305,7 +327,11 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0; virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0; - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) = 0; + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) + { + UNUSED_VARIABLE(path); + return S_OK; + } //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0; From fa532edad6726706b771170bd9391f38aab77656 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 2 Dec 2025 15:10:49 +0300 Subject: [PATCH 048/125] Deferred Link resolution --- PdfFile/PdfEditor.cpp | 2 ++ PdfFile/PdfWriter.cpp | 36 ++++++++++++++++++++++++------- PdfFile/PdfWriter.h | 1 + PdfFile/SrcWriter/Annotation.cpp | 8 +++---- PdfFile/SrcWriter/Annotation.h | 3 ++- PdfFile/SrcWriter/Destination.cpp | 6 ++++++ PdfFile/SrcWriter/Destination.h | 1 + PdfFile/SrcWriter/States.h | 9 ++++++++ PdfFile/lib/xpdf/Annot.cc | 1 + 9 files changed, 54 insertions(+), 13 deletions(-) diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index b380e1ed55..4684577f95 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -1246,6 +1246,7 @@ void CPdfEditor::Close() } if (m_nMode == Mode::Split) { + m_pWriter->EditClose(); m_pWriter->SaveToFile(m_wsDstFile); return; } @@ -1512,6 +1513,7 @@ void CPdfEditor::Close() pEncryptDict->UpdateKey(nCryptAlgorithm); } + m_pWriter->EditClose(); m_pWriter->SaveToFile(m_wsDstFile); return; } diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index dbe6cda189..ceddd132d6 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -1736,7 +1736,7 @@ void GetRCSpanStyle(CAnnotFieldInfo::CMarkupAnnotPr::CFontData* pFontData, NSStr oRC.AddDouble(pFontData->dVAlign, 2); } } -PdfWriter::CAction* GetAction(PdfWriter::CDocument* m_pDocument, CAnnotFieldInfo::CActionFieldPr* pAction) +PdfWriter::CAction* CPdfWriter::GetAction(CAnnotFieldInfo::CActionFieldPr* pAction, bool bDeferred) { PdfWriter::CAction* pA = m_pDocument->CreateAction(pAction->nActionType); if (!pA) @@ -1748,7 +1748,7 @@ PdfWriter::CAction* GetAction(PdfWriter::CDocument* m_pDocument, CAnnotFieldInfo case 1: { PdfWriter::CActionGoTo* ppA = (PdfWriter::CActionGoTo*)pA; - PdfWriter::CPage* pPageD = m_pDocument->GetPage(pAction->nInt1); + PdfWriter::CPage* pPageD = bDeferred ? m_pDocument->GetCurPage() : m_pDocument->GetPage(pAction->nInt1); PdfWriter::CDestination* pDest = m_pDocument->CreateDestination(pPageD); if (!pDest) break; @@ -1807,6 +1807,12 @@ PdfWriter::CAction* GetAction(PdfWriter::CDocument* m_pDocument, CAnnotFieldInfo break; } } + + if (bDeferred) + { + pPageD = m_pDocument->GetCurPage(); + m_vDestinations.push_back(TDestinationInfo(pDest, pAction->nInt1)); + } break; } case 6: @@ -1845,7 +1851,7 @@ PdfWriter::CAction* GetAction(PdfWriter::CDocument* m_pDocument, CAnnotFieldInfo if (pAction->pNext) { - PdfWriter::CAction* pANext = GetAction(m_pDocument, pAction->pNext); + PdfWriter::CAction* pANext = GetAction(pAction->pNext, bDeferred); pA->SetNext(pANext); } @@ -2371,7 +2377,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF const std::vector arrActions = pPr->GetActions(); for (CAnnotFieldInfo::CActionFieldPr* pAction : arrActions) { - PdfWriter::CAction* pA = GetAction(m_pDocument, pAction); + PdfWriter::CAction* pA = GetAction(pAction); pWidgetAnnot->AddAction(pA); } @@ -2656,18 +2662,26 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF nFlags = pPr->GetFlags(); if (nFlags & (1 << 0)) { - PdfWriter::CAction* pA = GetAction(m_pDocument, pPr->GetA()); + PdfWriter::CAction* pA = GetAction(pPr->GetA(), true); pLinkAnnot->SetA(pA); } if (nFlags & (1 << 1)) { - PdfWriter::CAction* pA = GetAction(m_pDocument, pPr->GetPA()); + PdfWriter::CAction* pA = GetAction(pPr->GetPA(), true); pLinkAnnot->SetPA(pA); } if (nFlags & (1 << 2)) pLinkAnnot->SetH(pPr->GetH()); if (nFlags & (1 << 3)) pLinkAnnot->SetQuadPoints(pPr->GetQuadPoints()); + + if (bRender) + { + pLinkAnnot->RemoveAP(); + LONG nLen = 0; + BYTE* pRender = oInfo.GetRender(nLen); + DrawAP(pAnnot, pRender, nLen); + } } return S_OK; @@ -3006,7 +3020,7 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi const std::vector arrActions = pParent->arrAction; for (CAnnotFieldInfo::CActionFieldPr* pAction : arrActions) { - PdfWriter::CAction* pA = GetAction(m_pDocument, pAction); + PdfWriter::CAction* pA = GetAction(pAction); if (!pA) continue; @@ -3189,7 +3203,13 @@ bool CPdfWriter::EditClose() TDestinationInfo& oInfo = m_vDestinations.at(nIndex); if (nPagesCount > oInfo.unDestPage) { - AddLink(oInfo.pPage, oInfo.dX, oInfo.dY, oInfo.dW, oInfo.dH, oInfo.dDestX, oInfo.dDestY, oInfo.unDestPage); + if (oInfo.pDest) + { + PdfWriter::CPage* pDestPage = m_pDocument->GetPage(oInfo.unDestPage); + oInfo.pDest->ChangePage(pDestPage); + } + else + AddLink(oInfo.pPage, oInfo.dX, oInfo.dY, oInfo.dW, oInfo.dH, oInfo.dDestX, oInfo.dDestY, oInfo.unDestPage); m_vDestinations.erase(m_vDestinations.begin() + nIndex); nIndex--; nCount--; diff --git a/PdfFile/PdfWriter.h b/PdfFile/PdfWriter.h index f6d0a3ad13..65d58babc7 100644 --- a/PdfFile/PdfWriter.h +++ b/PdfFile/PdfWriter.h @@ -229,6 +229,7 @@ public: void SetSplit(bool bSplit) { m_bSplit = bSplit; } private: + PdfWriter::CAction* GetAction(CAnnotFieldInfo::CActionFieldPr* pAction, bool bDeferred = false); bool SkipRedact(const double& dX, const double& dY, const double& dW, const double& dH); bool SkipRedact(const double& dX, const double& dY); PdfWriter::CImageDict* LoadImage(Aggplus::CImage* pImage, BYTE nAlpha); diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 3054b1c604..cb71cf244b 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -358,6 +358,10 @@ namespace PdfWriter pNormal->AddBBox(GetRect().fLeft, GetRect().fBottom, GetRect().fRight, GetRect().fTop); pNormal->AddMatrix(1, 0, 0, 1, -GetRect().fLeft, -GetRect().fBottom); } + void CAnnotation::RemoveAP() + { + Remove("AP"); + } //---------------------------------------------------------------------------------------- // CMarkupAnnotation //---------------------------------------------------------------------------------------- @@ -415,10 +419,6 @@ namespace PdfWriter { Add("IRT", pAnnot); } - void CMarkupAnnotation::RemoveAP() - { - Remove("AP"); - } //---------------------------------------------------------------------------------------- // CDestLinkAnnotation //---------------------------------------------------------------------------------------- diff --git a/PdfFile/SrcWriter/Annotation.h b/PdfFile/SrcWriter/Annotation.h index 3c550231ed..aa3640171d 100644 --- a/PdfFile/SrcWriter/Annotation.h +++ b/PdfFile/SrcWriter/Annotation.h @@ -194,6 +194,7 @@ namespace PdfWriter void SetOMetadata(const std::wstring& wsOMetadata); void SetC(const std::vector& arrC); + void RemoveAP(); void APFromFakePage(); virtual CAnnotAppearanceObject* StartAP(int nRotate); TRect& GetRect() { return m_oRect; } @@ -256,7 +257,7 @@ namespace PdfWriter void SetCD(const std::wstring& wsCD); void SetSubj(const std::wstring& wsSubj); - void RemoveAP(); + void SetIRTID(CAnnotation* pAnnot); CPopupAnnotation* CreatePopup(); }; diff --git a/PdfFile/SrcWriter/Destination.cpp b/PdfFile/SrcWriter/Destination.cpp index bd63c6709f..c65a3b5bda 100644 --- a/PdfFile/SrcWriter/Destination.cpp +++ b/PdfFile/SrcWriter/Destination.cpp @@ -58,6 +58,12 @@ namespace PdfWriter return true; } + void CDestination::ChangePage(CObjectBase* pPage) + { + if (!pPage) + return; + Insert(Get(0, false), pPage, true); + } void CDestination::PrepareArray() { if (m_arrList.size() > 1) diff --git a/PdfFile/SrcWriter/Destination.h b/PdfFile/SrcWriter/Destination.h index ea5bfec429..9f37fe380d 100644 --- a/PdfFile/SrcWriter/Destination.h +++ b/PdfFile/SrcWriter/Destination.h @@ -41,6 +41,7 @@ namespace PdfWriter public: CDestination(CObjectBase* pPage, CXref* pXref, bool bInline = false); bool IsValid() const; + void ChangePage(CObjectBase* pPage); void SetXYZ (float fLeft, float fTop, float fZoom); void SetFit (); void SetFitH (float fTop); diff --git a/PdfFile/SrcWriter/States.h b/PdfFile/SrcWriter/States.h index de49508ba5..073a0a58d1 100644 --- a/PdfFile/SrcWriter/States.h +++ b/PdfFile/SrcWriter/States.h @@ -47,6 +47,7 @@ namespace PdfWriter class CFontDict; class CShading; class CExtGrState; + class CDestination; } class CPdfWriter; @@ -1636,6 +1637,7 @@ struct TDestinationInfo { TDestinationInfo(PdfWriter::CPage* page, const double& x, const double& y, const double& w, const double& h, const double& dx, const double& dy, const unsigned int& undpage) { + pDest = NULL; pPage = page; dX = x; dY = y; @@ -1645,7 +1647,14 @@ struct TDestinationInfo dDestY = dy; unDestPage = undpage; } + TDestinationInfo(PdfWriter::CDestination* dest, const unsigned int& undpage) + { + pDest = dest; + pPage = NULL; + unDestPage = undpage; + } + PdfWriter::CDestination* pDest; PdfWriter::CPage* pPage; double dX; double dY; diff --git a/PdfFile/lib/xpdf/Annot.cc b/PdfFile/lib/xpdf/Annot.cc index 8576453067..7d71aea2d2 100644 --- a/PdfFile/lib/xpdf/Annot.cc +++ b/PdfFile/lib/xpdf/Annot.cc @@ -1691,6 +1691,7 @@ void Annot::draw(Gfx *gfx, GBool printing) { // draw the appearance stream isLink = type && !type->cmp("Link"); #ifdef BUILDING_WASM_MODULE + isLink = gFalse; if (type && !type->cmp("Stamp")) { gfx->drawStamp(&appearance); From eab6d5530bb5b58622dee77a7f53aae268230c75 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Thu, 4 Dec 2025 11:43:56 +0300 Subject: [PATCH 049/125] Fix build --- DocxRenderer/src/logic/Page.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index 0b601f3b6f..1aa33a4034 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -2239,6 +2239,7 @@ namespace NSDocxRenderer if (direction == eLineDirection::ldLeft) return crossing->p.x - p.x; if (direction == eLineDirection::ldBot) return p.y - crossing->p.y; if (direction == eLineDirection::ldTop) return crossing->p.y - p.y; + return 0; }; while (diff() > c_dMAX_TABLE_LINE_WIDTH_MM) From 84847f1e74f9a103bdc2eb8f658107365fa4425c Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Thu, 4 Dec 2025 21:19:39 +0600 Subject: [PATCH 050/125] fix bug #78953 --- MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp index dadb527760..488b74af4d 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp @@ -80,10 +80,11 @@ const bool LD::loadContent(BinProcessor& proc) elements_.pop_back(); } - proc.mandatory(); - - m_ATTACHEDLABEL = elements_.back(); - elements_.pop_back(); + if(proc.mandatory()) + { + m_ATTACHEDLABEL = elements_.back(); + elements_.pop_back(); + } if (proc.optional()) { @@ -102,7 +103,8 @@ const bool LD::loadContent(BinProcessor& proc) elements_.pop_back(); } proc.optional(); - proc.mandatory(); elements_.pop_back(); + if(proc.mandatory()) + elements_.pop_back(); return true; } From d1d94f481de6265130e481fc5293842924bf300f Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 4 Dec 2025 18:49:57 +0300 Subject: [PATCH 051/125] . --- MsBinaryFile/DocFile/DocumentMapping.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/MsBinaryFile/DocFile/DocumentMapping.cpp b/MsBinaryFile/DocFile/DocumentMapping.cpp index 5842d8b1e4..cf9e2f6d62 100644 --- a/MsBinaryFile/DocFile/DocumentMapping.cpp +++ b/MsBinaryFile/DocFile/DocumentMapping.cpp @@ -713,12 +713,13 @@ namespace DocFileFormat } else { - for (size_t i = 1; i < arField.size(); i++) + //for (size_t i = 1; i < arField.size(); i++) + if (arField.size() > 1) { std::wstring f1 = arField[1]; - int d = (int)f1.find(PAGEREF); + size_t d = f1.find(PAGEREF); - if (d > 0) + if (d != std::wstring::npos) { _writeWebHidden = true; std::wstring _writeTocLink =f1.substr(d + 9); @@ -729,10 +730,8 @@ namespace DocFileFormat _writeAfterRun += XmlUtils::EncodeXmlString(_writeTocLink); _writeAfterRun += std::wstring (L"\" w:history=\"1\">"); - break; - //cp = cpFieldSep1; + //break; } - //cpFieldSep1 = cpFieldSep2; } _skipRuns = 5; //with separator } From 6ea64599bd3125f9cad42fc2ad8ff3413e1bb362 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Fri, 5 Dec 2025 16:09:45 +0600 Subject: [PATCH 052/125] fix bug #78955 --- .../XlsFile/Format/Logic/Biff_records/AutoFilter.cpp | 9 ++++++++- .../Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp index 6fa427b376..5c2b3b7610 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp @@ -72,7 +72,14 @@ void AutoFilter::readFields(CFRecord& record) { size_t pos_record = record.getRdPtr(); - if (size == 0xffffffff) size = record.getDataSize() - pos_record; + + if (size == 0xffffffff) + size = record.getDataSize() - pos_record; + else if(record.getDataSize() < pos_record + size) + { + //size error + return; + } if (size > 0) { diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp index bb67d16fe6..2fd514269d 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp @@ -53,7 +53,7 @@ void Feat11FdaAutoFilter::load(CFRecord& record) } record.skipNunBytes(2); - if (cbAutoFilter > 0 && cbAutoFilter < 2080) + if (cbAutoFilter > 0 && cbAutoFilter < 2080 && (record.getDataSize() - record.getRdPtr()) >= cbAutoFilter) { recAutoFilter.size = cbAutoFilter; recAutoFilter.readFields(record); From f2023f626b8cee6c287d0448fe8a7a2c2bcee838 Mon Sep 17 00:00:00 2001 From: Timofey Derevyankin Date: Fri, 5 Dec 2025 13:57:34 +0300 Subject: [PATCH 053/125] fix/bug59965 fix bug #59965 --- OdfFile/Reader/Converter/oox_data_labels.cpp | 2 +- PdfFile/SrcWriter/Types.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/OdfFile/Reader/Converter/oox_data_labels.cpp b/OdfFile/Reader/Converter/oox_data_labels.cpp index 8d883b84d0..e2599f9590 100644 --- a/OdfFile/Reader/Converter/oox_data_labels.cpp +++ b/OdfFile/Reader/Converter/oox_data_labels.cpp @@ -80,7 +80,7 @@ void oox_data_labels::oox_serialize(std::wostream & _Wostream) case 6: CP_XML_ATTR(L"val", L"l"); break; case 7: CP_XML_ATTR(L"val", L"inBase"); break; case 9: CP_XML_ATTR(L"val", L"r"); break; - case 10: CP_XML_ATTR(L"val", L"outEnd");break; + case 10: CP_XML_ATTR(L"val", L"t"); break; case 11: CP_XML_ATTR(L"val", L"t"); break; case 12: CP_XML_ATTR(L"val", L"t"); break; case 5: //CP_XML_ATTR(L"val", L"inEnd"); break; diff --git a/PdfFile/SrcWriter/Types.h b/PdfFile/SrcWriter/Types.h index 0ee86625dd..3ada87c29e 100644 --- a/PdfFile/SrcWriter/Types.h +++ b/PdfFile/SrcWriter/Types.h @@ -51,6 +51,7 @@ #ifdef __linux__ #include +#include #endif namespace PdfWriter From 31f7136f70881dd9dd419f39ae9dc4200117b908 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Fri, 5 Dec 2025 14:05:19 +0300 Subject: [PATCH 054/125] Fix bug #78915 --- HtmlFile2/htmlfile2.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp index 86776eb3ef..dceb98cb3e 100644 --- a/HtmlFile2/htmlfile2.cpp +++ b/HtmlFile2/htmlfile2.cpp @@ -3912,9 +3912,6 @@ private: bool ReadListElement(NSStringUtils::CStringBuilder* oXml, std::vector& arSelectors, CTextSettings& oTS) { - if (OpenP(oXml)) - wrP(oXml, arSelectors, oTS); - const bool bResult{readStream(oXml, arSelectors, oTS)}; CloseP(oXml, arSelectors); From 6422ce7f780e6ef7afb2707c719ab62a6577fd58 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Fri, 5 Dec 2025 15:55:23 +0300 Subject: [PATCH 055/125] Fix bugs in html --- .../3dParty/html/css/src/StyleProperties.cpp | 622 +++++++----------- Common/3dParty/html/css/src/StyleProperties.h | 179 +++-- HtmlFile2/htmlfile2.cpp | 16 +- 3 files changed, 355 insertions(+), 462 deletions(-) diff --git a/Common/3dParty/html/css/src/StyleProperties.cpp b/Common/3dParty/html/css/src/StyleProperties.cpp index a1a1b6e5c3..d3851e389b 100644 --- a/Common/3dParty/html/css/src/StyleProperties.cpp +++ b/Common/3dParty/html/css/src/StyleProperties.cpp @@ -4,6 +4,7 @@ #include "ConstValues.h" #include #include +#include #include namespace NSCSS @@ -25,11 +26,10 @@ namespace NSCSS } CString::CString() - : CValue(L"", 0, false) {} CString::CString(const std::wstring &wsValue, unsigned int unLevel, bool bImportant) - : CValue(wsValue, unLevel, bImportant) + : CValueOptional(wsValue, unLevel, bImportant) {} bool CString::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode) @@ -115,89 +115,97 @@ namespace NSCSS bool CString::Empty() const { - return m_oValue.empty(); - } - - void CString::Clear() - { - m_oValue.clear(); - m_unLevel = 0; - m_bImportant = false; + return CValueOptional::Empty() || m_oValue.value().empty(); } int CString::ToInt() const { - return std::stoi(m_oValue); + if (CValueOptional::Empty()) + return 0; + + return std::stoi(m_oValue.value()); } double CString::ToDouble() const { - return std::stod(m_oValue); + if (CValueOptional::Empty()) + return 0.; + + return std::stod(m_oValue.value()); } std::wstring CString::ToWString() const { - return m_oValue; - } + if (CValueOptional::Empty()) + return std::wstring(); - CString &CString::operator+=(const CString &oString) - { - if (m_unLevel > oString.m_unLevel || (m_bImportant && !oString.m_bImportant) || oString.m_oValue.empty()) - return *this; - - m_oValue = oString.m_oValue; - m_unLevel = oString.m_unLevel; - m_bImportant = oString.m_bImportant; - - return *this; + return m_oValue.value(); } double CDigit::ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const { + if (CValueOptional::Empty()) + return 0.; + switch(m_enUnitMeasure) { - case Percent: return dPrevValue * m_oValue / 100.; - case Pixel: return CUnitMeasureConverter::ConvertPx(m_oValue, enUnitMeasure, 96); - case Point: return CUnitMeasureConverter::ConvertPt(m_oValue, enUnitMeasure, 96); - case Cantimeter: return CUnitMeasureConverter::ConvertCm(m_oValue, enUnitMeasure, 96); - case Millimeter: return CUnitMeasureConverter::ConvertMm(m_oValue, enUnitMeasure, 96); - case Inch: return CUnitMeasureConverter::ConvertIn(m_oValue, enUnitMeasure, 96); - case Peak: return CUnitMeasureConverter::ConvertPc(m_oValue, enUnitMeasure, 96); - case Twips: return CUnitMeasureConverter::ConvertTw(m_oValue, enUnitMeasure, 96); + case Percent: return dPrevValue * m_oValue.value() / 100.; + case Pixel: return CUnitMeasureConverter::ConvertPx(m_oValue.value(), enUnitMeasure, 96); + case Point: return CUnitMeasureConverter::ConvertPt(m_oValue.value(), enUnitMeasure, 96); + case Cantimeter: return CUnitMeasureConverter::ConvertCm(m_oValue.value(), enUnitMeasure, 96); + case Millimeter: return CUnitMeasureConverter::ConvertMm(m_oValue.value(), enUnitMeasure, 96); + case Inch: return CUnitMeasureConverter::ConvertIn(m_oValue.value(), enUnitMeasure, 96); + case Peak: return CUnitMeasureConverter::ConvertPc(m_oValue.value(), enUnitMeasure, 96); + case Twips: return CUnitMeasureConverter::ConvertTw(m_oValue.value(), enUnitMeasure, 96); case Em: - case Rem: return m_oValue * dPrevValue; - case None: return m_oValue; + case Rem: return m_oValue.value() * dPrevValue; + case None: return m_oValue.value(); } } - CDigit::CDigit() - : CValue(DBL_MAX, 0, false), m_enUnitMeasure(None) - {} - - CDigit::CDigit(double dValue) - : CValue(dValue, 0, false), m_enUnitMeasure(None) - {} - - CDigit::CDigit(double dValue, unsigned int unLevel, bool bImportant) - : CValue(dValue, unLevel, bImportant), m_enUnitMeasure(None) - {} - - bool CDigit::Empty() const + template + CDigit CDigit::ApplyOperation(const CDigit& oDigit, Operation operation) const { - return DBL_MAX == m_oValue; + if (!Empty() && oDigit.Empty()) + return *this; + + if (Empty() && !oDigit.Empty()) + return oDigit; + + CDigit oTemp; + + oTemp.SetValue(operation(m_oValue.value(), oDigit.m_oValue.value())); + + oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel); + oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant); + + return oTemp; } + CDigit::CDigit() + : m_enUnitMeasure(None) + {} + + CDigit::CDigit(const double& dValue) + : CValueOptional(dValue, 0, false), m_enUnitMeasure(None) + {} + + CDigit::CDigit(const double& dValue, unsigned int unLevel, bool bImportant) + : CValueOptional(dValue, unLevel, bImportant), m_enUnitMeasure(None) + {} + bool CDigit::Zero() const { - return (std::abs(0. - m_oValue) <= DBL_EPSILON); + if (CValueOptional::Empty()) + return false; + + return (std::abs(0. - m_oValue.value()) <= DBL_EPSILON); } void CDigit::Clear() { - m_oValue = DBL_MAX; - m_unLevel = 0; + CValueOptional::Clear(); m_enUnitMeasure = None; - m_bImportant = false; } void CDigit::ConvertTo(UnitMeasure enUnitMeasure, double dPrevValue) @@ -208,31 +216,28 @@ namespace NSCSS int CDigit::ToInt() const { - if (Empty()) + if (CValueOptional::Empty()) return 0; - return static_cast(m_oValue + 0.5); + return static_cast(m_oValue.value() + 0.5); } double CDigit::ToDouble() const { - if (Empty()) - return 0.; - - return m_oValue; + return m_oValue.value_or(0.); } std::wstring CDigit::ToWString() const { - if (DBL_MAX == m_oValue) + if (CValueOptional::Empty()) return std::wstring(); - return std::to_wstring(m_oValue); + return std::to_wstring(m_oValue.value()); } int CDigit::ToInt(UnitMeasure enUnitMeasure, double dPrevValue) const { - if (DBL_MAX == m_oValue) + if (CValueOptional::Empty()) return 0; return static_cast(ConvertValue(dPrevValue, enUnitMeasure) + 0.5); @@ -240,15 +245,15 @@ namespace NSCSS double CDigit::ToDouble(UnitMeasure enUnitMeasure, double dPrevValue) const { - if (DBL_MAX == m_oValue) - return 0; + if (CValueOptional::Empty()) + return 0.; return ConvertValue(dPrevValue, enUnitMeasure); } std::wstring CDigit::ToWString(UnitMeasure enUnitMeasure, double dPrevValue) const { - if (DBL_MAX == m_oValue) + if (CValueOptional::Empty()) return std::wstring(); return std::to_wstring(ConvertValue(dPrevValue, enUnitMeasure)); @@ -259,77 +264,62 @@ namespace NSCSS return m_enUnitMeasure; } - bool CDigit::operator==(const double &oValue) const + bool CDigit::operator==(const double &dValue) const { - return (std::abs(oValue - m_oValue) <= DBL_EPSILON); + return (!CValueOptional::Empty()) && (std::fabs(dValue - m_oValue.value() <= DBL_EPSILON)); } bool CDigit::operator==(const CDigit &oDigit) const { - return (Empty() && oDigit.Empty()) || - ((std::abs(oDigit.m_oValue - m_oValue) <= DBL_EPSILON) && - m_enUnitMeasure == oDigit.m_enUnitMeasure); + if (Empty() && oDigit.Empty()) + return true; + + if ((!Empty() && oDigit.Empty()) || + (Empty() && !oDigit.Empty())) + return false; + + return (m_enUnitMeasure == oDigit.m_enUnitMeasure && + (std::fabs(oDigit.m_oValue.value() - m_oValue.value()) <= DBL_EPSILON)); } bool CDigit::operator!=(const double &oValue) const { - return (std::abs(oValue - m_oValue) > DBL_EPSILON); + return (CValueOptional::Empty()) || (std::fabs(oValue - m_oValue.value()) > DBL_EPSILON); } bool CDigit::operator!=(const CDigit &oDigit) const { - return (std::abs(oDigit.m_oValue - m_oValue) > DBL_EPSILON); + return !(*this == oDigit); } CDigit CDigit::operator+(const CDigit &oDigit) const { - CDigit oTemp; - - oTemp.m_oValue = m_oValue + oDigit.m_oValue; - oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel); - oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant); - - return oTemp; + return ApplyOperation(oDigit, std::plus()); } CDigit CDigit::operator-(const CDigit &oDigit) const { - CDigit oTemp; - - oTemp.m_oValue = m_oValue - oDigit.m_oValue; - oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel); - oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant); - - return oTemp; + return ApplyOperation(oDigit, std::minus()); } CDigit CDigit::operator*(const CDigit &oDigit) const { - CDigit oTemp; - - oTemp.m_oValue = m_oValue * oDigit.m_oValue; - oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel); - oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant); - - return oTemp; + return ApplyOperation(oDigit, std::multiplies()); } CDigit CDigit::operator/(const CDigit &oDigit) const { - CDigit oTemp; - - oTemp.m_oValue = m_oValue / oDigit.m_oValue; - oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel); - oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant); - - return oTemp; + return ApplyOperation(oDigit, std::divides()); } CDigit CDigit::operator*(double dValue) const { + if (CValueOptional::Empty()) + return *this; + CDigit oTemp(*this); - oTemp.m_oValue *= dValue; + oTemp *= dValue; return oTemp; } @@ -345,9 +335,9 @@ namespace NSCSS return *this; } else if (NSCSS::Percent == oDigit.m_enUnitMeasure && !Empty()) - m_oValue *= oDigit.m_oValue / 100.; + *this *= oDigit.m_oValue.value() / 100.; else - m_oValue += oDigit.ToDouble(m_enUnitMeasure); + m_oValue.value() += oDigit.ToDouble(m_enUnitMeasure); m_unLevel = oDigit.m_unLevel; m_bImportant = oDigit.m_bImportant; @@ -357,25 +347,37 @@ namespace NSCSS CDigit &CDigit::operator+=(double dValue) { - m_oValue += dValue; + if (Empty()) + m_oValue = dValue; + else + m_oValue.value() += dValue; + return *this; } CDigit &CDigit::operator-=(double dValue) { - m_oValue -= dValue; + if (Empty()) + m_oValue = -dValue; + else + m_oValue.value() -= dValue; + return *this; } CDigit &CDigit::operator*=(double dValue) { - m_oValue *= dValue; + if (!Empty()) + m_oValue.value() *= dValue; + return *this; } CDigit &CDigit::operator/=(double dValue) { - m_oValue /= dValue; + if (!Empty()) + m_oValue.value() /= dValue; + return *this; } @@ -397,9 +399,13 @@ namespace NSCSS if (m_bImportant && !bImportant) return false; - if (!CUnitMeasureConverter::GetValue(wsValue, m_oValue, m_enUnitMeasure)) + double dValue; + + if (!CUnitMeasureConverter::GetValue(wsValue, dValue, m_enUnitMeasure)) return false; + m_oValue = dValue; + if (UINT_MAX == unLevel) m_unLevel++; else @@ -423,9 +429,9 @@ namespace NSCSS else if (NSCSS::Percent == oValue.m_enUnitMeasure) { if (m_unLevel == oValue.m_unLevel) - m_oValue = oValue.m_oValue; + m_oValue = oValue.m_oValue; else - m_oValue *= oValue.m_oValue / 100.; + m_oValue.value() *= oValue.m_oValue.value() / 100.; } else m_oValue = oValue.ToDouble(m_enUnitMeasure); @@ -441,8 +447,8 @@ namespace NSCSS if (CHECK_CONDITIONS && !bHardMode) return false; - m_enUnitMeasure = enUnitMeasure; m_oValue = dValue; + m_enUnitMeasure = enUnitMeasure; if (UINT_MAX == unLevel) m_unLevel++; @@ -457,6 +463,11 @@ namespace NSCSS return 0 == uchRed && 0 == uchGreen && 0 == uchBlue; } + int TRGB::ToInt() const + { + return RGB_TO_INT(uchRed, uchGreen, uchBlue); + } + bool TRGB::operator==(const TRGB &oRGB) const { return uchRed == oRGB.uchRed && @@ -471,6 +482,46 @@ namespace NSCSS uchBlue != oRGB.uchBlue; } + CColorValue::CColorValue() + : m_eType(EColorType::ColorNone), m_oValue(std::monostate()) + {} + + CColorValue::CColorValue(const CColorValue& oValue) + : m_eType(oValue.m_eType), m_oValue(oValue.m_oValue) + {} + + CColorValue::CColorValue(const std::wstring& wsValue) + : m_eType(EColorType::ColorHEX), m_oValue(wsValue) + {} + + CColorValue::CColorValue(const TRGB& oValue) + : m_eType(EColorType::ColorRGB), m_oValue(oValue) + {} + + CColorValue::CColorValue(const CURL& oValue) + : m_eType(EColorType::ColorUrl), m_oValue(oValue) + {} + + EColorType CColorValue::GetType() const + { + return m_eType; + } + + bool CColorValue::operator==(const CColorValue& oValue) const + { + return m_eType == oValue.m_eType && m_oValue == oValue.m_oValue; + } + + CColorValueContextStroke::CColorValueContextStroke() + { + m_eType = EColorType::ColorContextStroke; + } + + CColorValueContextFill::CColorValueContextFill() + { + m_eType = EColorType::ColorContextFill; + } + TRGB CColor::ConvertHEXtoRGB(const std::wstring &wsValue) { TRGB oRGB; @@ -498,161 +549,28 @@ namespace NSCSS return std::wstring(arTemp, 6); } - bool CColor::operator==(const CColor& oColor) const - { - if (m_enType != oColor.m_enType || m_oOpacity != oColor.m_oOpacity) - return false; - - switch(m_enType) - { - case ColorEmpty: - case ColorNone: - return true; - case ColorRGB: - return (*static_cast(m_oValue)) == (*static_cast(oColor.m_oValue)); - case ColorHEX: - return (*static_cast(m_oValue)) == (*static_cast(oColor.m_oValue)); - case ColorUrl: - return (*static_cast(m_oValue)) == (*static_cast(oColor.m_oValue)); - case ColorContextStroke: - case ColorContextFill: - return false; - } - } - - bool CColor::operator!=(const CColor& oColor) const - { - if (m_enType != oColor.m_enType || m_oOpacity != oColor.m_oOpacity) - return true; - - switch(m_enType) - { - case ColorEmpty: - case ColorNone: - return false; - case ColorRGB: - return (*static_cast(m_oValue)) != (*static_cast(oColor.m_oValue)); - case ColorHEX: - return (*static_cast(m_oValue)) != (*static_cast(oColor.m_oValue)); - case ColorUrl: - return (*static_cast(m_oValue)) != (*static_cast(oColor.m_oValue)); - case ColorContextStroke: - case ColorContextFill: - return false; - } - } - - CColor& CColor::operator =(const CColor& oColor) - { - m_enType = oColor.m_enType; - m_oOpacity = oColor.m_oOpacity; - m_unLevel = oColor.m_unLevel; - - switch(m_enType) - { - case ColorEmpty: - case ColorNone: - break; - case ColorRGB: - { - m_oValue = new TRGB{(*static_cast(oColor.m_oValue))}; - break; - } - case ColorHEX: - { - m_oValue = new std::wstring(*static_cast(oColor.m_oValue)); - break; - } - case ColorUrl: - { - m_oValue = new CURL(*static_cast(oColor.m_oValue)); - break; - } - case ColorContextStroke: - case ColorContextFill: - break; - } - - return *this; - } - - CColor& CColor::operator+=(const CColor& oColor) - { - if (m_unLevel > oColor.m_unLevel || (m_bImportant && !oColor.m_bImportant) || oColor.Empty()) - return *this; - - *this = oColor; - - return *this; - } - CColor::CColor() - : CValue(NULL, 0, false), m_oOpacity(1.), m_enType(ColorEmpty) + : m_oOpacity(1.) {} - CColor::CColor(const CColor& oColor) - : CValue(NULL, 0, false), m_oOpacity(oColor.m_oOpacity), m_enType(oColor.m_enType) - { - switch (m_enType) - { - case ColorRGB: - { - TRGB *pRGB = static_cast(oColor.m_oValue); - m_oValue = new TRGB(*pRGB); - break; - } - case ColorHEX: - { - std::wstring* pValue = static_cast(oColor.m_oValue); - m_oValue = new std::wstring(*pValue); - break; - } - case ColorUrl: - { - CURL *pURL = static_cast(oColor.m_oValue); - m_oValue = new CURL(*pURL); - break; - } - default: - break; - } - } - - CColor::~CColor() - { - Clear(); - } - void CColor::SetEmpty(unsigned int unLevel) { Clear(); - m_enType = ColorEmpty; - m_unLevel = unLevel; - m_bImportant = false; + m_unLevel = unLevel; } void CColor::SetRGB(unsigned char uchR, unsigned char uchG, unsigned char uchB) { Clear(); - m_oValue = new TRGB{uchR, uchG, uchB}; - - if (NULL == m_oValue) - return; - - m_enType = ColorRGB; + m_oValue = CColorValue(TRGB{uchR, uchG, uchB}); } void CColor::SetRGB(const TRGB &oRGB) { Clear(); - m_oValue = new TRGB{oRGB}; - - if (NULL == m_oValue) - return; - - m_enType = ColorRGB; + m_oValue = CColorValue(oRGB); } void CColor::SetHEX(const std::wstring &wsValue) @@ -663,43 +581,32 @@ namespace NSCSS Clear(); if (6 == wsValue.length()) - m_oValue = new std::wstring(wsValue); + m_oValue = CColorValue(std::wstring(wsValue)); else - m_oValue = new std::wstring({wsValue[0], wsValue[0], wsValue[1], wsValue[1], wsValue[2], wsValue[2]}); - - if (NULL == m_oValue) - return; - - m_enType = ColorHEX; + m_oValue = CColorValue(std::wstring({wsValue[0], wsValue[0], wsValue[1], wsValue[1], wsValue[2], wsValue[2]})); } - void CColor::SetUrl(const std::wstring &wsValue) + bool CColor::SetUrl(const std::wstring &wsValue) { if (wsValue.empty()) - return; + return false; - CURL *pURL = new CURL(); + CURL oURL; - if (NULL == pURL) - return; - - if (!pURL->SetValue(wsValue)) - { - delete pURL; - return; - } + if (!oURL.SetValue(wsValue)) + return false; Clear(); - m_oValue = pURL; - m_enType = ColorUrl; + m_oValue = CColorValue(oURL); + + return true; } void CColor::SetNone() { Clear(); - - m_enType = ColorNone; + m_oValue = CColorValue(); } char NormalizeNegativeColorValue(INT nValue) @@ -748,12 +655,12 @@ namespace NSCSS else if (L"context-stroke" == wsNewValue) { Clear(); - m_enType = ColorContextStroke; + m_oValue = CColorValueContextStroke(); } else if (L"context-fill" == wsNewValue) { Clear(); - m_enType = ColorContextFill; + m_oValue = CColorValueContextFill(); } else if (10 <= wsNewValue.length() && wsNewValue.substr(0, 3) == L"rgb") { @@ -778,15 +685,9 @@ namespace NSCSS bResult = true; } - else if (5 <= wsNewValue.length()) - { - SetUrl(wsValue); - - if (m_enType == ColorUrl) - bResult = true; - } - - if (!bResult) + else if (5 <= wsNewValue.length() && SetUrl(wsValue)) + bResult = true; + else { const std::map::const_iterator oHEX = NSConstValues::COLORS.find(wsNewValue); if (oHEX != NSConstValues::COLORS.end()) @@ -811,61 +712,31 @@ namespace NSCSS bool CColor::SetOpacity(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode) { - if (wsValue.empty() || (m_oOpacity.m_bImportant && !bHardMode)) - return false; - return m_oOpacity.SetValue(wsValue, unLevel, bHardMode); } - bool CColor::Empty() const - { - return ColorEmpty == m_enType; - } - bool CColor::None() const { - return ColorNone == m_enType; + return !Empty() && ColorNone == m_oValue->GetType(); } bool CColor::Url() const { - return ColorUrl == m_enType; + return !Empty() && ColorUrl == m_oValue->GetType(); } void CColor::Clear() { - switch (m_enType) - { - case ColorRGB: - { - TRGB *pRGB = static_cast(m_oValue); - RELEASEOBJECT(pRGB); - break; - } - case ColorHEX: - { - std::wstring* pValue = static_cast(m_oValue); - RELEASEOBJECT(pValue); - break; - } - case ColorUrl: - { - CURL *pURL = static_cast(m_oValue); - RELEASEOBJECT(pURL); - break; - } - default: - break; - } - - m_enType = ColorEmpty; - m_unLevel = NULL; - m_bImportant = false; + m_oOpacity.Clear(); + CValueOptional::Clear(); } - ColorType CColor::GetType() const + EColorType CColor::GetType() const { - return m_enType; + if (Empty()) + return EColorType::ColorNone; + + return m_oValue->GetType(); } double CColor::GetOpacity() const @@ -884,19 +755,15 @@ namespace NSCSS int CColor::ToInt() const { - switch(m_enType) + if (Empty()) + return 0; + + switch(m_oValue->GetType()) { case ColorRGB: - { - TRGB* pRGB = static_cast(m_oValue); - return RGB_TO_INT(pRGB->uchRed, pRGB->uchGreen, pRGB->uchBlue); - } + return std::get(m_oValue->m_oValue).ToInt(); case ColorHEX: - { - std::wstring *pValue = static_cast(m_oValue); - TRGB oRGB = ConvertHEXtoRGB(*pValue); - return RGB_TO_INT(oRGB.uchRed, oRGB.uchGreen, oRGB.uchBlue); - } + return ConvertHEXtoRGB(std::get(m_oValue->m_oValue)).ToInt(); default: return 0; } @@ -909,29 +776,29 @@ namespace NSCSS std::wstring CColor::ToWString() const { - switch(m_enType) + if (Empty()) + return std::wstring(); + + switch(m_oValue->GetType()) { - case ColorRGB: return ConvertRGBtoHEX(*static_cast(m_oValue)); - case ColorHEX: return *static_cast(m_oValue); - case ColorUrl: return static_cast(m_oValue)->GetValue(); + case ColorRGB: return ConvertRGBtoHEX(std::get(m_oValue->m_oValue)); + case ColorHEX: return std::get(m_oValue->m_oValue); + case ColorUrl: return std::get(m_oValue->m_oValue).GetValue(); default: return std::wstring(); } } std::wstring CColor::ToHEX() const { - switch(m_enType) + if (Empty()) + return std::wstring(); + + switch(m_oValue->GetType()) { case ColorRGB: - { - TRGB* pRGB = static_cast(m_oValue); - return ConvertRGBtoHEX(*pRGB); - } + return ConvertRGBtoHEX(std::get(m_oValue->m_oValue)); case ColorHEX: - { - std::wstring *pValue = static_cast(m_oValue); - return *pValue; - } + return std::get(m_oValue->m_oValue); default: return std::wstring(); } @@ -939,15 +806,15 @@ namespace NSCSS std::wstring CColor::EquateToColor(const std::vector> &arColors) const { - if (arColors.empty()) + if (arColors.empty() || Empty()) return L"none"; TRGB oCurrentColor; - switch(m_enType) + switch(m_oValue->GetType()) { - case ColorRGB: oCurrentColor = *static_cast(m_oValue); break; - case ColorHEX: oCurrentColor = ConvertHEXtoRGB(*static_cast(m_oValue)); break; + case ColorRGB: oCurrentColor = std::get(m_oValue->m_oValue); break; + case ColorHEX: oCurrentColor = ConvertHEXtoRGB(std::get(m_oValue->m_oValue)); break; default: return L"none"; } @@ -971,10 +838,13 @@ namespace NSCSS TRGB CColor::ToRGB() const { - switch(m_enType) + if (Empty()) + return TRGB(); + + switch(m_oValue->GetType()) { - case ColorRGB: return *static_cast(m_oValue); - case ColorHEX: return ConvertHEXtoRGB(*static_cast(m_oValue)); + case ColorRGB: return std::get(m_oValue->m_oValue); + case ColorHEX: return ConvertHEXtoRGB(std::get(m_oValue->m_oValue)); default: return TRGB(); } } @@ -1003,11 +873,10 @@ namespace NSCSS } CMatrix::CMatrix() - : CValue({}, 0, false) {} CMatrix::CMatrix(const MatrixValues &oValue, unsigned int unLevel, bool bImportant) - : CValue(oValue, unLevel, bImportant) + : CValueBase(oValue, unLevel, bImportant) {} bool CMatrix::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode) @@ -1617,7 +1486,7 @@ namespace NSCSS bool CBackground::IsNone() const { - return ColorType::ColorNone == m_oColor.GetType(); + return EColorType::ColorNone == m_oColor.GetType(); } CBackground &CBackground::operator=(const CBackground &oBackground) @@ -2979,7 +2848,8 @@ namespace NSCSS } CEnum::CEnum() - : CValue(INT_MAX, 0, false){} + : m_nDefaultValue(0) + {} bool CEnum::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode) { @@ -3010,45 +2880,25 @@ namespace NSCSS m_mMap = mMap; if (-1 != nDefaulvalue) - m_oValue = nDefaulvalue; - } - - bool CEnum::Empty() const - { - return m_mMap.empty() || INT_MAX == m_oValue; - } - - void CEnum::Clear() - { - m_oValue = INT_MAX; - m_unLevel = NULL; - m_bImportant = false; - } - - CEnum &CEnum::operator =(int nValue) - { - m_oValue = nValue; - return *this; - } - - bool CEnum::operator==(int nValue) const - { - return m_oValue == nValue; - } - - bool CEnum::operator!=(int nValue) const - { - return m_oValue != nValue; + m_nDefaultValue = nDefaulvalue; + else if (!mMap.empty()) + m_nDefaultValue = mMap.begin()->second; } int CEnum::ToInt() const { - return m_oValue; + if (Empty()) + return m_nDefaultValue; + + return m_oValue.value(); } double CEnum::ToDouble() const { - return (double)m_oValue; + if (Empty()) + return m_nDefaultValue; + + return (double)m_oValue.value(); } std::wstring CEnum::ToWString() const @@ -3056,6 +2906,9 @@ namespace NSCSS if (m_mMap.empty()) return std::wstring(); + if (Empty()) + return std::find_if(m_mMap.begin(), m_mMap.end(), [this](const std::pair& oValue){ return m_nDefaultValue == oValue.second; })->first; + return std::find_if(m_mMap.begin(), m_mMap.end(), [this](const std::pair& oValue){ return m_oValue == oValue.second; })->first; } @@ -3141,6 +2994,5 @@ namespace NSCSS { return m_oHeader; } - } } diff --git a/Common/3dParty/html/css/src/StyleProperties.h b/Common/3dParty/html/css/src/StyleProperties.h index bcd6e2f7d3..661752d877 100644 --- a/Common/3dParty/html/css/src/StyleProperties.h +++ b/Common/3dParty/html/css/src/StyleProperties.h @@ -2,9 +2,10 @@ #define STYLEPROPERTIES_H #include +#include #include +#include #include -#include #include "../../../../DesktopEditor/graphics/Matrix.h" #include "CUnitMeasureConverter.h" @@ -16,33 +17,34 @@ namespace NSCSS #define NEXT_LEVEL UINT_MAX, true template - class CValue + class CValueBase { - friend class CString; - friend class CMatrix; - friend class CDigit; - friend class CColor; - friend class CEnum; - friend class CURL; + protected: + CValueBase() + : m_unLevel(0), m_bImportant(false) + {} + CValueBase(const CValueBase& oValue) + : m_oValue(oValue.m_oValue), m_unLevel(oValue.m_unLevel), m_bImportant(oValue.m_bImportant) + {} + + CValueBase(const T& oValue, unsigned int unLevel, bool bImportant) + : m_oValue(oValue), m_unLevel(unLevel), m_bImportant(bImportant) + {} T m_oValue; unsigned int m_unLevel; bool m_bImportant; public: - CValue(const T& oValue, unsigned int unLevel, bool bImportant) : - m_oValue(oValue), m_unLevel(unLevel), m_bImportant(bImportant) - { - } + virtual bool Empty() const = 0; + virtual void Clear() = 0; virtual bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) = 0; - virtual bool Empty() const = 0; - virtual void Clear() = 0; virtual int ToInt() const = 0; virtual double ToDouble() const = 0; virtual std::wstring ToWString() const = 0; - static void Equation(CValue &oFirstValue, CValue &oSecondValue) + static void Equation(CValueBase &oFirstValue, CValueBase &oSecondValue) { if (oFirstValue.m_bImportant && !oSecondValue.m_bImportant && oFirstValue.Empty()) oSecondValue.Clear(); @@ -57,18 +59,22 @@ namespace NSCSS } } - static bool LevelIsSame(const CValue& oFirstValue, const CValue& oSecondValue) + static bool LevelIsSame(const CValueBase& oFirstValue, const CValueBase& oSecondValue) { return oFirstValue.m_unLevel == oSecondValue.m_unLevel; } - bool operator==(const T& oValue) const { return m_oValue == oValue; } - bool operator>=(const T& oValue) const { return m_oValue >= oValue; } - bool operator<=(const T& oValue) const { return m_oValue <= oValue; } - bool operator> (const T& oValue) const { return m_oValue > oValue; } - bool operator< (const T& oValue) const { return m_oValue < oValue; } + bool operator==(const T& oValue) const + { + return m_oValue == oValue; + } - virtual CValue& operator =(const CValue& oValue) + bool operator!=(const T& oValue) const + { + return m_oValue != oValue; + } + + virtual CValueBase& operator =(const CValueBase& oValue) { m_oValue = oValue.m_oValue; m_unLevel = oValue.m_unLevel; @@ -77,36 +83,53 @@ namespace NSCSS return *this; } - virtual CValue& operator =(const T& oValue) + virtual CValueBase& operator+=(const CValueBase& oValue) { - //m_oValue = oValue.m_oValue; - return *this; - } - - virtual CValue& operator+=(const CValue& oValue) - { - if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || oValue.Empty()) + if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || Empty()) return *this; - m_oValue = oValue.m_oValue; - m_unLevel = oValue.m_unLevel; - m_bImportant = oValue.m_bImportant; + *this = oValue; return *this; } - virtual bool operator==(const CValue& oValue) const + virtual bool operator==(const CValueBase& oValue) const { return m_oValue == oValue.m_oValue; } - virtual bool operator!=(const CValue& oValue) const + virtual bool operator!=(const CValueBase& oValue) const { - return m_oValue != oValue.m_oValue; + return !(*this == oValue); } }; - class CString : public CValue + template + class CValueOptional : public CValueBase> + { + protected: + CValueOptional() + : CValueBase>() + {} + + CValueOptional(const T& oValue, unsigned int unLevel, bool bImportant) + : CValueBase>(oValue, unLevel, bImportant) + {} + + public: + virtual bool Empty() const override + { + return !this->m_oValue.has_value(); + } + void Clear() override + { + this->m_oValue.reset(); + this->m_unLevel = 0; + this->m_bImportant = false; + } + }; + + class CString : public CValueOptional { public: CString(); @@ -117,30 +140,29 @@ namespace NSCSS bool SetValue(const std::wstring& wsValue, const std::map& arValiableValues, unsigned int unLevel, bool bHardMode); bool Empty() const override; - void Clear() override; int ToInt() const override; double ToDouble() const override; std::wstring ToWString() const override; - - CString& operator+=(const CString& oString); }; - class CDigit : public CValue + class CDigit : public CValueOptional { UnitMeasure m_enUnitMeasure; double ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const; + + template + CDigit ApplyOperation(const CDigit& oDigit, Operation operation) const; public: CDigit(); - CDigit(double dValue); - CDigit(double dValue, unsigned int unLevel, bool bImportant = false); + CDigit(const double& dValue); + CDigit(const double& dValue, unsigned int unLevel, bool bImportant = false); bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override; bool SetValue(const CDigit& oValue); bool SetValue(const double& dValue, UnitMeasure enUnitMeasure, unsigned int unLevel = 0, bool bHardMode = true); - bool Empty() const override; bool Zero() const; void Clear() override; @@ -156,7 +178,7 @@ namespace NSCSS UnitMeasure GetUnitMeasure() const; - bool operator==(const double& oValue) const; + bool operator==(const double& dValue) const; bool operator==(const CDigit& oDigit) const; bool operator!=(const double& oValue) const; @@ -186,6 +208,8 @@ namespace NSCSS bool Empty() const; + int ToInt() const; + bool operator==(const TRGB& oRGB) const; bool operator!=(const TRGB& oRGB) const; }; @@ -211,31 +235,58 @@ namespace NSCSS typedef enum { - ColorEmpty, ColorNone, ColorRGB, ColorHEX, ColorUrl, ColorContextStroke, ColorContextFill - } ColorType; + } EColorType; - class CColor : public CValue + class CColorValue + { + using color_value = std::variant; + protected: + EColorType m_eType; + public: + CColorValue(); + CColorValue(const CColorValue& oValue); + CColorValue(const std::wstring& wsValue); + CColorValue(const TRGB& oValue); + CColorValue(const CURL& oValue); + + EColorType GetType() const; + + bool operator==(const CColorValue& oValue) const; + + color_value m_oValue; + }; + + class CColorValueContextStroke : public CColorValue + { + public: + CColorValueContextStroke(); + }; + + class CColorValueContextFill : public CColorValue + { + public: + CColorValueContextFill(); + }; + + class CColor : public CValueOptional { public: CColor(); - CColor(const CColor& oColor); - ~CColor(); bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override; bool SetOpacity(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true); - bool Empty() const override; bool None() const; bool Url() const; void Clear() override; - ColorType GetType() const; + EColorType GetType() const; double GetOpacity() const; @@ -248,21 +299,14 @@ namespace NSCSS static TRGB ConvertHEXtoRGB(const std::wstring& wsValue); static std::wstring ConvertRGBtoHEX(const TRGB& oValue); - - bool operator==(const CColor& oColor) const; - bool operator!=(const CColor& oColor) const; - - CColor& operator =(const CColor& oColor); - CColor& operator+=(const CColor& oColor); private: - CDigit m_oOpacity; - ColorType m_enType; + CDigit m_oOpacity; void SetEmpty(unsigned int unLevel = 0); void SetRGB(unsigned char uchR, unsigned char uchG, unsigned char uchB); void SetRGB(const TRGB& oRGB); void SetHEX(const std::wstring& wsValue); - void SetUrl(const std::wstring& wsValue); + bool SetUrl(const std::wstring& wsValue); void SetNone(); }; @@ -279,7 +323,7 @@ namespace NSCSS typedef std::vector, TransformType>> MatrixValues; - class CMatrix : public CValue + class CMatrix : public CValueBase { std::vector CutTransforms(const std::wstring& wsValue) const; public: @@ -306,8 +350,9 @@ namespace NSCSS CMatrix& operator-=(const CMatrix& oMatrix); }; - class CEnum : public CValue + class CEnum : public CValueOptional { + int m_nDefaultValue; std::map m_mMap; public: CEnum(); @@ -315,14 +360,6 @@ namespace NSCSS bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override; void SetMapping(const std::map& mMap, int nDefaulvalue = -1); - bool Empty() const override; - void Clear() override; - - CEnum &operator =(int nValue); - - bool operator==(int nValue) const; - bool operator!=(int nValue) const; - int ToInt() const override; private: double ToDouble() const override; diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp index dceb98cb3e..3adbeae38e 100644 --- a/HtmlFile2/htmlfile2.cpp +++ b/HtmlFile2/htmlfile2.cpp @@ -288,7 +288,8 @@ struct CTextSettings CTextSettings(const CTextSettings& oTS) : bBdo(oTS.bBdo), bPre(oTS.bPre), bQ(oTS.bQ), bAddSpaces(oTS.bAddSpaces), bMergeText(oTS.bMergeText), - nLi(oTS.nLi), bNumberingLi(oTS.bNumberingLi), sPStyle(oTS.sPStyle), eTextMode(oTS.eTextMode) + nLi(oTS.nLi), bNumberingLi(oTS.bNumberingLi), sPStyle(oTS.sPStyle), eTextMode(oTS.eTextMode), + oAdditionalStyle(oTS.oAdditionalStyle) {} void AddPStyle(const std::wstring& wsStyle) @@ -1445,6 +1446,11 @@ bool CanUseThisPath(const std::wstring& wsPath, const std::wstring& wsSrcPath, c return true; } + bool UnreadableNode(const std::wstring& wsNodeName) +{ + return L"head" == wsNodeName || L"meta" == wsNodeName || L"style" == wsNodeName; +} + class CHtmlFile2_Private { public: @@ -3066,11 +3072,10 @@ private: bool readInside (NSStringUtils::CStringBuilder* oXml, std::vector& sSelectors, CTextSettings& oTS, const std::wstring& sName) { //TODO:: обработать все варианты return'а - if(sName == L"#text") return ReadText(oXml, sSelectors, oTS); - if (TagIsUnprocessed(sName)) + if (UnreadableNode(sName) || TagIsUnprocessed(sName)) return false; std::wstring sNote = GetSubClass(oXml, sSelectors); @@ -3924,8 +3929,6 @@ private: if(m_oLightReader.IsEmptyNode()) return false; - GetSubClass(oXml, arSelectors); - CloseP(oXml, arSelectors); CTextSettings oTSLi(oTS); @@ -3966,6 +3969,8 @@ private: m_oNumberXml.WriteString(wsStart); m_oNumberXml.WriteString(L"\"/>"); } + else + oTSLi.bNumberingLi = false; CTextSettings oTSList{oTSLi}; @@ -3987,7 +3992,6 @@ private: } CloseP(oXml, arSelectors); - arSelectors.pop_back(); return true; } From bebb39a6199c435498352361988ee503cefb12eb Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Fri, 5 Dec 2025 20:10:56 +0600 Subject: [PATCH 056/125] fix bug #78960 --- .../XlsFile/Format/Logic/Biff_records/DataFormat.cpp | 2 ++ .../XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp | 4 ++-- MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp index 7baa3dc932..1f9959676b 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp @@ -55,6 +55,8 @@ void DataFormat::readFields(CFRecord& record) unsigned short flags; record >> xi >> yi >> iss >> flags; fUnknown = GETBIT(flags, 0); + if(iss > 1000) + iss = 0; } void DataFormat::writeFields(CFRecord& record) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp index 51e0900d63..91d1dcd093 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp @@ -148,7 +148,7 @@ int MarkerFormat::serialize(std::wostream & _stream, int index, BaseObjectPtr _G { CP_XML_NODE(L"a:srgbClr") { - CP_XML_ATTR(L"val", (false == fAuto || index < 0) ? rgbBack.strRGB : default_marker_color[index]); + CP_XML_ATTR(L"val", (false == fAuto || index < 0 || index > default_marker_color->size()) ? rgbBack.strRGB : default_marker_color[index]); } } } @@ -158,7 +158,7 @@ int MarkerFormat::serialize(std::wostream & _stream, int index, BaseObjectPtr _G { CP_XML_NODE(L"a:srgbClr") { - CP_XML_ATTR(L"val", (false == fAuto || index < 0) ? rgbFore.strRGB : default_marker_color[index]); + CP_XML_ATTR(L"val", (false == fAuto || index < 0 || index > default_marker_color->size()) ? rgbFore.strRGB : default_marker_color[index]); } } CP_XML_NODE(L"a:prstDash") { CP_XML_ATTR(L"val", L"solid"); } diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp index 72249f59a4..a4ee62db98 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp @@ -305,7 +305,7 @@ int SS::serialize_default(std::wostream & _stream, int series_type, int ind ) if ((line) && (line->lns == (_UINT16)5)) ind = -1; } - if (ind >= 0 && m_isAutoLine) + if (ind >= 0 && default_series_line_color->size() > ind && m_isAutoLine) { CP_XML_NODE(L"a:ln") { @@ -444,7 +444,8 @@ int SS::serialize(std::wostream & _stream, int series_type, int indPt) { CP_XML_NODE(L"a:srgbClr") { - CP_XML_ATTR(L"val", default_series_line_color[ind]); + if(default_series_line_color->size() > ind) + CP_XML_ATTR(L"val", default_series_line_color[ind]); } } CP_XML_NODE(L"a:prstDash") From 2534d2b5c9b5add27deea1a8b429185e1511ef90 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Mon, 8 Dec 2025 11:20:59 +0300 Subject: [PATCH 057/125] Fix swap rectangle --- PdfFile/SrcReader/PdfAnnot.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 1af910b829..788dec0b90 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -3428,6 +3428,10 @@ CAnnot::CAnnot(PDFDoc* pdfDoc, AcroFormField* pField, int nStartRefID) m_pRect[1] = m_dHeight - m_pRect[3]; m_pRect[2] = m_pRect[2] - m_dX; m_pRect[3] = m_dHeight - dTemp; + if (m_pRect[0] > m_pRect[2]) + std::swap(m_pRect[0], m_pRect[2]); + if (m_pRect[1] > m_pRect[3]) + std::swap(m_pRect[1], m_pRect[3]); // 0 - Уникальное имя - NM if (pField->fieldLookup("NM", &oObj)->isString()) @@ -3563,6 +3567,11 @@ CAnnot::CAnnot(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex, int nStartRefI m_pRect[1] = m_dHeight - ArrGetNum(&oObj, 3); m_pRect[2] = ArrGetNum(&oObj, 2) - m_dX; m_pRect[3] = m_dHeight - ArrGetNum(&oObj, 1); + + if (m_pRect[0] > m_pRect[2]) + std::swap(m_pRect[0], m_pRect[2]); + if (m_pRect[1] > m_pRect[3]) + std::swap(m_pRect[1], m_pRect[3]); } oObj.free(); From 5c7ef5a6eb8b7cbb39250faceb340951234fa2b7 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Mon, 8 Dec 2025 23:42:44 +0300 Subject: [PATCH 058/125] add rdValueData --- .../Sheets/Common/BinReaderWriterDefines.h | 34 +- OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp | 218 +++++ OOXML/Binary/Sheets/Reader/BinaryWriterS.h | 21 + OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp | 245 +++++ OOXML/Binary/Sheets/Writer/BinaryReaderS.h | 18 +- OOXML/Common/SimpleTypes_Spreadsheet.cpp | 59 ++ OOXML/Common/SimpleTypes_Spreadsheet.h | 16 + OOXML/DocxFormat/WritingElement.h | 14 + .../Linux/DocxFormatLib/DocxFormatLib.pro | 2 +- .../Linux/DocxFormatLib/xlsx_format_logic.cpp | 2 +- .../DocxFormatLib/DocxFormatLib.vcxproj | 4 +- .../DocxFormatLib.vcxproj.filters | 14 +- OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp | 2 +- OOXML/XlsxFormat/RichData/RdRichData.cpp | 891 ++++++++++++++++++ OOXML/XlsxFormat/RichData/RdRichData.h | 383 ++++++++ OOXML/XlsxFormat/RichData/RdRichValue.cpp | 233 ----- OOXML/XlsxFormat/RichData/RdRichValue.h | 108 --- OOXML/XlsxFormat/Timelines/Timeline.cpp | 42 +- 18 files changed, 1938 insertions(+), 368 deletions(-) create mode 100644 OOXML/XlsxFormat/RichData/RdRichData.cpp create mode 100644 OOXML/XlsxFormat/RichData/RdRichData.h delete mode 100644 OOXML/XlsxFormat/RichData/RdRichValue.cpp delete mode 100644 OOXML/XlsxFormat/RichData/RdRichValue.h diff --git a/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h b/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h index 0e725b2d45..9076dc7d03 100644 --- a/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h +++ b/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h @@ -251,8 +251,38 @@ namespace BinXlsxRW LockStructure = 4, LockWindows = 5, Password = 6 - }; } - + }; } + + namespace c_oSer_RichValue {enum c_oSer_RichValue { + RichValue = 0, + StructureIdx = 1, + Value = 2, + Fallback = 3, + FallbackValue = 4, + FallbackType = 5 + };} + + namespace c_oSer_RichStructures {enum c_oSer_RichStructures { + Structure = 0, + Type = 1, + ValueKey = 2, + ValueKeyType = 3, + ValueKeyName = 4 + };} + namespace c_oSer_RichValueTypesInfo {enum c_oSer_RichValueTypesInfo { + Global = 0, + KeyFlags = 1, + Types = 2, + Type = 3, + Name = 4, + KeyFlagName = 5, + ReservedKey = 6, + ReservedKeyName = 7, + ReservedKeyFlags = 8, + FlagName = 9, + FlagValue = 10 + + };} namespace c_oSerFileSharing {enum c_oSerFileSharing{ AlgorithmName = 0, SpinCount = 1, diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp b/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp index 4d48d40110..f73e5fbf81 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp +++ b/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp @@ -74,6 +74,7 @@ #include "../../../XlsxFormat/Workbook/Metadata.h" #include "../../../XlsxFormat/Table/Table.h" #include "../../../XlsxFormat/Workbook/CustomsXml.h" +#include "../../../XlsxFormat/RichData/RdRichData.h" #include "../../../../DesktopEditor/common/Directory.h" #include "../../../../Common/OfficeFileFormatChecker.h" @@ -2336,7 +2337,224 @@ void BinaryWorkbookTableWriter::WriteWorkbook(OOX::Spreadsheet::CWorkbook& workb m_oBcw.m_oStream.EndRecord(); m_oBcw.WriteItemWithLengthEnd(nCurPos); } + pFile = workbook.Find(OOX::Spreadsheet::FileTypes::RdRichValue); + OOX::Spreadsheet::CRdRichValueFile* pRichValue = dynamic_cast(pFile.GetPointer()); + if ((pRichValue) && (pRichValue->m_oRvData.IsInit())) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::RdRichValue); + WriteRichValueData(pRichValue->m_oRvData.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + pFile = workbook.Find(OOX::Spreadsheet::FileTypes::RdRichValueStructure); + OOX::Spreadsheet::CRdRichValueStructureFile* pRichValueStructure = dynamic_cast(pFile.GetPointer()); + if ((pRichValueStructure) && (pRichValueStructure->m_oRvStructures.IsInit())) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::RdRichValueStructure); + WriteRichValueStructures(pRichValueStructure->m_oRvStructures.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + pFile = workbook.Find(OOX::Spreadsheet::FileTypes::RdRichValueTypes); + OOX::Spreadsheet::CRdRichValueTypesFile* pRichValueTypes = dynamic_cast(pFile.GetPointer()); + if ((pRichValueTypes) && (pRichValueTypes->m_oRvTypesInfo.IsInit())) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::RdRichValueTypes); + WriteRichValueTypes(pRichValueTypes->m_oRvTypesInfo.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } } +void BinaryWorkbookTableWriter::WriteRichValueData(OOX::Spreadsheet::CRichValueData* pData) +{ + if (!pData) return; + + int nCurPos = 0; + + for (size_t i = 0; i < pData->m_arrItems.size(); ++i) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValue::RichValue); + WriteRichValue(pData->m_arrItems[i]); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValue(OOX::Spreadsheet::CRichValue* pValues) +{ + if (!pValues) return; + + int nCurPos = 0; + + if (pValues->m_oS.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValue::StructureIdx); + m_oBcw.m_oStream.WriteULONG(*pValues->m_oS); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + for (size_t i = 0; i < pValues->m_arrV.size(); ++i) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValue::Value); + m_oBcw.m_oStream.WriteStringW3(pValues->m_arrV[i]); // todooo ... + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + if (pValues->m_oFb.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValue::Fallback); + WriteRichValueFallback(pValues->m_oFb.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValueFallback(OOX::Spreadsheet::CRichValueFallback* pFallback) +{ + if (!pFallback) return; + + int nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValue::FallbackValue); + m_oBcw.m_oStream.WriteStringW3(pFallback->m_sContent); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + + if (pFallback->m_oT.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValue::FallbackType); + m_oBcw.m_oStream.WriteBYTE(pFallback->m_oT->GetValue()); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValueStructures(OOX::Spreadsheet::CRichValueStructures* pStructures) +{ + if (!pStructures) return; + + int nCurPos = 0; + + for (size_t i = 0; i < pStructures->m_arrItems.size(); ++i) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichStructures::Structure); + WriteRichValueStructure(pStructures->m_arrItems[i]); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValueStructure(OOX::Spreadsheet::CRichValueStructure* pStructure) +{ + if (!pStructure) return; + + int nCurPos = 0; + + if (pStructure->m_oT.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichStructures::Type); + m_oBcw.m_oStream.WriteStringW3(*pStructure->m_oT); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + for (size_t i = 0; i < pStructure->m_arrItems.size(); ++i) + { + if (!pStructure->m_arrItems[i]) continue; + + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichStructures::ValueKey); + if (pStructure->m_arrItems[i]->m_oT.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_RichStructures::ValueKeyType); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteBYTE(pStructure->m_arrItems[i]->m_oT->GetValue()); + } + if (pStructure->m_arrItems[i]->m_oN.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_RichStructures::ValueKeyName); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); + m_oBcw.m_oStream.WriteStringW(*pStructure->m_arrItems[i]->m_oN); + } + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValueTypes(OOX::Spreadsheet::CRichValueTypesInfo* pTypesInfo) +{ + if (!pTypesInfo) return; + + int nCurPos = 0; + + if (pTypesInfo->m_oGlobal.IsInit() && pTypesInfo->m_oGlobal->m_oKeyFlags.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::Global); + + int nCurPos3 = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::KeyFlags); + WriteRichValueTypeKeyFlags(pTypesInfo->m_oGlobal->m_oKeyFlags.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos3); + + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + if (pTypesInfo->m_oTypes.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::Types); + + for (size_t i = 0; i < pTypesInfo->m_oTypes->m_arrItems.size(); ++i) + { + int nCurPos3 = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::Type); + WriteRichValueType(pTypesInfo->m_oTypes->m_arrItems[i]); + m_oBcw.WriteItemWithLengthEnd(nCurPos3); + } + + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValueTypeKeyFlags(OOX::Spreadsheet::CRichValueTypeKeyFlags* pKeyFlags) +{ + if (!pKeyFlags) return; + + for (size_t i = 0; i < pKeyFlags->m_arrItems.size(); ++i) + { + int nCurPos3 = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::ReservedKey); + WriteRichValueTypeReservedKey(pKeyFlags->m_arrItems[i]); + m_oBcw.WriteItemWithLengthEnd(nCurPos3); + } +} +void BinaryWorkbookTableWriter::WriteRichValueTypeReservedKey(OOX::Spreadsheet::CRichValueTypeReservedKey* pReservedKey) +{ + if (!pReservedKey) return; + + int nCurPos = 0; + + if (pReservedKey->m_oName.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::ReservedKeyName); + m_oBcw.m_oStream.WriteStringW3(*pReservedKey->m_oName); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + for (size_t i = 0; i < pReservedKey->m_arrItems.size(); ++i) + { + if (!pReservedKey->m_arrItems[i]) continue; + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::ReservedKeyFlags); + { + if (pReservedKey->m_arrItems[i]->m_oName.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_RichValueTypesInfo::FlagName); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); + m_oBcw.m_oStream.WriteStringW(*pReservedKey->m_arrItems[i]->m_oName); + + } + if (pReservedKey->m_arrItems[i]->m_oValue.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_RichValueTypesInfo::FlagValue); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteBOOL(*pReservedKey->m_arrItems[i]->m_oValue); + } + } + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} +void BinaryWorkbookTableWriter::WriteRichValueType(OOX::Spreadsheet::CRichValueType* pTypeInfo) +{ + if (!pTypeInfo) return; + + int nCurPos = 0; + + if (pTypeInfo->m_oName.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::Name); + m_oBcw.m_oStream.WriteStringW3(*pTypeInfo->m_oName); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } + if (pTypeInfo->m_oKeyFlags.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_RichValueTypesInfo::KeyFlags); + WriteRichValueTypeKeyFlags(pTypeInfo->m_oKeyFlags.GetPointer()); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } +} + void BinaryWorkbookTableWriter::WriteFileSharing(const OOX::Spreadsheet::CFileSharing& fileSharing) { if (fileSharing.m_oAlgorithmName.IsInit()) diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriterS.h b/OOXML/Binary/Sheets/Reader/BinaryWriterS.h index 26b7f9d1e2..c7b209e701 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriterS.h +++ b/OOXML/Binary/Sheets/Reader/BinaryWriterS.h @@ -102,6 +102,17 @@ namespace OOX class CMdxSet; class CMetadataStrings; class CMetadataStringIndex; + + class CRichValueData; + class CRichValue; + class CRichValueFallback; + class CRichValueStructures; + class CRichValueStructure; + class CRichValueTypesInfo; + class CRichValueTypeReservedKey; + class CRichValueType; + class CRichValueTypeReservedKey; + class CRichValueTypeKeyFlags; } } @@ -265,6 +276,16 @@ namespace BinXlsxRW void WriteMdxKPI(OOX::Spreadsheet::CMdxKPI* pMdxKPI); void WriteMdxMemeberProp(OOX::Spreadsheet::CMdxMemeberProp* pMdxMemeberProp); void WriteMetadataStringIndex(OOX::Spreadsheet::CMetadataStringIndex* pStringIndex); + + void WriteRichValueData(OOX::Spreadsheet::CRichValueData* pData); + void WriteRichValue(OOX::Spreadsheet::CRichValue* pData); + void WriteRichValueFallback(OOX::Spreadsheet::CRichValueFallback* pData); + void WriteRichValueStructures(OOX::Spreadsheet::CRichValueStructures* pStructures); + void WriteRichValueStructure(OOX::Spreadsheet::CRichValueStructure* pStructure); + void WriteRichValueTypes(OOX::Spreadsheet::CRichValueTypesInfo* pTypesInfo); + void WriteRichValueType(OOX::Spreadsheet::CRichValueType* pTypeInfo); + void WriteRichValueTypeKeyFlags(OOX::Spreadsheet::CRichValueTypeKeyFlags* pKeyFlags); + void WriteRichValueTypeReservedKey(OOX::Spreadsheet::CRichValueTypeReservedKey* pReservedKey); }; class BinaryPersonTableWriter { diff --git a/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp b/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp index 65c871dae7..61cc2a58df 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp +++ b/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp @@ -73,6 +73,7 @@ #include "../../../XlsxFormat/Timelines/Timeline.h" #include "../../../XlsxFormat/Workbook/Metadata.h" #include "../../../XlsxFormat/Workbook/CustomsXml.h" +#include "../../../XlsxFormat/RichData/RdRichData.h" #include "../../../DocxFormat/Media/VbaProject.h" #include "../../../DocxFormat/Media/JsaProject.h" @@ -2461,6 +2462,39 @@ int BinaryWorkbookTableReader::ReadWorkbookTableContent(BYTE type, long length, smart_ptr oFile = oXmlMapFile.smart_dynamic_cast(); m_oWorkbook.Add(oFile); } + else if (c_oSerWorkbookTypes::RdRichValue == type) + { + smart_ptr oRichValueFile(new OOX::Spreadsheet::CRdRichValueFile(NULL)); + if (m_oWorkbook.OOX::File::m_pMainDocument) + oRichValueFile->OOX::File::m_pMainDocument = m_oWorkbook.OOX::File::m_pMainDocument; + oRichValueFile->m_oRvData.Init(); + READ1_DEF(length, res, this->ReadRichValueData, oRichValueFile->m_oRvData.GetPointer()); + + smart_ptr oFile = oRichValueFile.smart_dynamic_cast(); + m_oWorkbook.Add(oFile); + } + else if (c_oSerWorkbookTypes::RdRichValueStructure== type) + { + smart_ptr oRichStructureFile(new OOX::Spreadsheet::CRdRichValueStructureFile(NULL)); + if (m_oWorkbook.OOX::File::m_pMainDocument) + oRichStructureFile->OOX::File::m_pMainDocument = m_oWorkbook.OOX::File::m_pMainDocument; + oRichStructureFile->m_oRvStructures.Init(); + READ1_DEF(length, res, this->ReadRichValueStructures, oRichStructureFile->m_oRvStructures.GetPointer()); + + smart_ptr oFile = oRichStructureFile.smart_dynamic_cast(); + m_oWorkbook.Add(oFile); + } + else if (c_oSerWorkbookTypes::RdRichValueTypes == type) + { + smart_ptr oRichValueTypesFile(new OOX::Spreadsheet::CRdRichValueTypesFile(NULL)); + if (m_oWorkbook.OOX::File::m_pMainDocument) + oRichValueTypesFile->OOX::File::m_pMainDocument = m_oWorkbook.OOX::File::m_pMainDocument; + oRichValueTypesFile->m_oRvTypesInfo.Init(); + READ1_DEF(length, res, this->ReadRichValueTypesInfo, oRichValueTypesFile->m_oRvTypesInfo.GetPointer()); + + smart_ptr oFile = oRichValueTypesFile.smart_dynamic_cast(); + m_oWorkbook.Add(oFile); + } else res = c_oSerConstants::ReadUnknown; return res; @@ -8735,6 +8769,217 @@ int BinaryCustomsReader::ReadCustomContent(BYTE type, long length, void* poResul res = c_oSerConstants::ReadUnknown; return res; } +int BinaryWorkbookTableReader::ReadRichValueData(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueData* pData = static_cast(poResult); + + if (c_oSer_RichValue::RichValue == type) + { + OOX::Spreadsheet::CRichValue* pRichValue = new OOX::Spreadsheet::CRichValue(); + READ1_DEF(length, res, this->ReadRichValue, pRichValue); + pData->m_arrItems.push_back(pRichValue); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueFallback(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + + return res; +} +int BinaryWorkbookTableReader::ReadRichValue(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValue* pValue = static_cast(poResult); + + if (c_oSer_RichValue::StructureIdx == type) + { + pValue->m_oS = m_oBufferedStream.GetULong(); + } + else if (c_oSer_RichValue::Value == type) + { + std::wstring s = m_oBufferedStream.GetString3(length); + pValue->m_arrV.push_back(s); + } + else if (c_oSer_RichValue::Fallback == type) + { + pValue->m_oFb.Init(); + READ1_DEF(length, res, this->ReadRichValueFallback, pValue->m_oFb.GetPointer()); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueStructures(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueStructures* pStructures = static_cast(poResult); + + if (c_oSer_RichStructures::Structure == type) + { + OOX::Spreadsheet::CRichValueStructure* pStructure = new OOX::Spreadsheet::CRichValueStructure(); + READ1_DEF(length, res, this->ReadRichValueStructure, pStructure); + pStructures->m_arrItems.push_back(pStructure); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueStructure(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueStructure* pStructure = static_cast(poResult); + + if (c_oSer_RichStructures::Type == type) + { + pStructure->m_oT = m_oBufferedStream.GetString3(length); + } + else if (c_oSer_RichStructures::ValueKey == type) + { + OOX::Spreadsheet::CRichValueKey* pValueKey = new OOX::Spreadsheet::CRichValueKey(); + READ2_DEF_SPREADSHEET(length, res, this->ReadRichValueStructureValueKey, pValueKey); + pStructure->m_arrItems.push_back(pValueKey); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueStructureValueKey(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueKey* pValueKey = static_cast(poResult); + + if (c_oSer_RichStructures::ValueKeyName == type) + { + pValueKey->m_oN = m_oBufferedStream.GetString3(length); + } + else if (c_oSer_RichStructures::ValueKeyType == type) + { + pValueKey->m_oT.Init(); + pValueKey->m_oT->SetValueFromByte(m_oBufferedStream.GetUChar()); + } + return res; +} +int BinaryWorkbookTableReader::ReadRichValueTypesInfo(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueTypesInfo* pTypesInfo = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::Global == type) + { + pTypesInfo->m_oGlobal.Init(); + READ1_DEF(length, res, this->ReadRichValueGlobal, pTypesInfo->m_oGlobal.GetPointer()); + } + else if (c_oSer_RichValueTypesInfo::Types) + { + pTypesInfo->m_oTypes.Init(); + READ1_DEF(length, res, this->ReadRichValueTypes, pTypesInfo->m_oTypes.GetPointer()); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueGlobal(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueGlobalType* pGlobalType = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::KeyFlags == type) + { + pGlobalType->m_oKeyFlags.Init(); + READ1_DEF(length, res, this->ReadRichValueTypeKeyFlags, pGlobalType->m_oKeyFlags.GetPointer()); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueTypes(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueTypes* pTypes = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::Type == type) + { + OOX::Spreadsheet::CRichValueType* pType = new OOX::Spreadsheet::CRichValueType(); + READ1_DEF(length, res, this->ReadRichValueType, pType); + pTypes->m_arrItems.push_back(pType); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueType(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueType* pType = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::Name == type) + { + pType->m_oName = m_oBufferedStream.GetString3(length); + } + else if (c_oSer_RichValueTypesInfo::KeyFlags == type) + { + pType->m_oKeyFlags.Init(); + READ1_DEF(length, res, this->ReadRichValueTypeKeyFlags, pType->m_oKeyFlags.GetPointer()); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueTypeKeyFlags(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueTypeKeyFlags* pKeyFlags = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::ReservedKey == type) + { + OOX::Spreadsheet::CRichValueTypeReservedKey* pKey = new OOX::Spreadsheet::CRichValueTypeReservedKey(); + READ1_DEF(length, res, this->ReadRichValueReservedKey, pKey); + pKeyFlags->m_arrItems.push_back(pKey); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueReservedKey(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueTypeReservedKey* pReservedKey = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::ReservedKeyName == type) + { + pReservedKey->m_oName = m_oBufferedStream.GetString3(length); + } + else if (c_oSer_RichValueTypesInfo::ReservedKeyFlags == type) + { + OOX::Spreadsheet::CRichValueTypeReservedKeyFlag* pFlag = new OOX::Spreadsheet::CRichValueTypeReservedKeyFlag(); + READ2_DEF_SPREADSHEET(length, res, this->ReadRichValueReservedKeyFlags, pFlag); + pReservedKey->m_arrItems.push_back(pFlag); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} +int BinaryWorkbookTableReader::ReadRichValueReservedKeyFlags(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CRichValueTypeReservedKeyFlag* pFlag = static_cast(poResult); + + if (c_oSer_RichValueTypesInfo::FlagName == type) + { + pFlag->m_oName = m_oBufferedStream.GetString3(length); + } + else if (c_oSer_RichValueTypesInfo::FlagValue == type) + { + pFlag->m_oValue = m_oBufferedStream.GetBool(); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} int BinaryWorkbookTableReader::ReadMetadata(BYTE type, long length, void* poResult) { OOX::Spreadsheet::CMetadata* pMetadata = static_cast(poResult); diff --git a/OOXML/Binary/Sheets/Writer/BinaryReaderS.h b/OOXML/Binary/Sheets/Writer/BinaryReaderS.h index 33c028d419..7983fe14b8 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReaderS.h +++ b/OOXML/Binary/Sheets/Writer/BinaryReaderS.h @@ -280,7 +280,23 @@ namespace BinXlsxRW int ReadMdxMemeberProp(BYTE type, long length, void* poResult); int ReadMetadataStringIndex(BYTE type, long length, void* poResult); int ReadDynamicArrayProperties(BYTE type, long length, void* poResult); - OOX::Spreadsheet::CXlsb* m_pXlsb = NULL; + + int ReadRichValueData(BYTE type, long length, void* poResult); + int ReadRichValueFallback(BYTE type, long length, void* poResult); + int ReadRichValue(BYTE type, long length, void* poResult); + int ReadRichValueStructures(BYTE type, long length, void* poResult); + int ReadRichValueStructure(BYTE type, long length, void* poResult); + int ReadRichValueStructureValueKey(BYTE type, long length, void* poResult); + int ReadRichValueTypesInfo(BYTE type, long length, void* poResult); + int ReadRichValueTypes(BYTE type, long length, void* poResult); + int ReadRichValueType(BYTE type, long length, void* poResult); + int ReadRichValueGlobal(BYTE type, long length, void* poResult); + int ReadRichValueTypeKeyFlags(BYTE type, long length, void* poResult); + int ReadRichValueReservedKey(BYTE type, long length, void* poResult); + int ReadRichValueReservedKeyFlags(BYTE type, long length, void* poResult); + +//-------------------------------------------------------------------------------------------------- + OOX::Spreadsheet::CXlsb* m_pXlsb = NULL; }; class BinaryCommentReader : public Binary_CommonReader { diff --git a/OOXML/Common/SimpleTypes_Spreadsheet.cpp b/OOXML/Common/SimpleTypes_Spreadsheet.cpp index 41a0838946..3d0e5e5b02 100644 --- a/OOXML/Common/SimpleTypes_Spreadsheet.cpp +++ b/OOXML/Common/SimpleTypes_Spreadsheet.cpp @@ -3448,5 +3448,64 @@ namespace SimpleTypes } return L"edit"; } + ERichValueValueType CRichValueFallbackType::FromString(const std::wstring& sValue) + { + if (L"b" == sValue) + this->m_eValue = typeBoolean; + else if (L"n" == sValue) + this->m_eValue = typeNumber; + else if (L"e" == sValue) + this->m_eValue = typeError; + else + this->m_eValue = typeText; + return this->m_eValue; + } + std::wstring CRichValueFallbackType::ToString() const + { + switch (this->m_eValue) + { + case typeBoolean: return L"b"; break; + case typeNumber: return L"n"; break; + case typeError: return L"e"; break; + } + return L"s"; + } + ERichValueValueType CRichValueValueType::FromString(const std::wstring& sValue) + { + if (L"b" == sValue) + this->m_eValue = typeBoolean; + else if (L"n" == sValue) + this->m_eValue = typeNumber; + else if (L"e" == sValue) + this->m_eValue = typeError; + else if (L"r" == sValue) + this->m_eValue = typeRichValue; + else if (L"a" == sValue) + this->m_eValue = typeRichArray; + else if (L"spb" == sValue) + this->m_eValue = typePropertyBag; + else if (L"s" == sValue) + this->m_eValue = typeText; + else if (L"i" == sValue) + this->m_eValue = typeInteger; + else + this->m_eValue = typeNumber; + return this->m_eValue; + } + std::wstring CRichValueValueType::ToString() const + { + switch (this->m_eValue) + { + case typeBoolean: return L"b"; break; + case typeNumber: return L"d"; break; + case typeError: return L"e"; break; + case typeInteger: return L"i"; break; + case typeRichArray: return L"a"; break; + case typeRichValue: return L"r"; break; + case typePropertyBag: return L"spb"; break; + case typeText: return L"s"; break; + } + return L"d"; + } }// Spreadsheet } // SimpleTypes diff --git a/OOXML/Common/SimpleTypes_Spreadsheet.h b/OOXML/Common/SimpleTypes_Spreadsheet.h index 2eacc32f8b..e04b86268f 100644 --- a/OOXML/Common/SimpleTypes_Spreadsheet.h +++ b/OOXML/Common/SimpleTypes_Spreadsheet.h @@ -1457,5 +1457,21 @@ namespace SimpleTypes typeFloat = 2 //... }; DEFINE_SIMPLE_TYPE(CXmlDataType, EXmlDataType, typeString) + + enum ERichValueValueType + { + typeBoolean = 0, + typeNumber = 1, + typeError = 2, + typeText = 3, + typeInteger = 4, + typeRichValue = 5, + typeRichArray = 6, + typePropertyBag = 7 + }; + DEFINE_SIMPLE_TYPE(CRichValueFallbackType, ERichValueValueType, typeText) + + DEFINE_SIMPLE_TYPE(CRichValueValueType, ERichValueValueType, typeNumber) + }// Spreadsheet } // SimpleTypes diff --git a/OOXML/DocxFormat/WritingElement.h b/OOXML/DocxFormat/WritingElement.h index 54356493da..264e5e6509 100644 --- a/OOXML/DocxFormat/WritingElement.h +++ b/OOXML/DocxFormat/WritingElement.h @@ -1563,6 +1563,20 @@ namespace OOX et_x_xmlCellPr, et_x_xmlPr, + et_x_RichValueData, + et_x_RichValue, + et_x_RichValueFallback, + et_x_RichValueStructures, + et_x_RichValueStructure, + et_x_RichValueKey, + et_x_RichValueTypesInfo, + et_x_RichValueTypes, + et_x_RichValueType, + et_x_RichValueGlobalType, + et_x_RichValueTypeKeyFlags, + et_x_RichValueTypeReservedKey, + et_x_RichValueTypeReservedKeyFlag, + et_dr_Masters, et_dr_Pages, et_dr_DocumentSettings, diff --git a/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro b/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro index cc1f191263..dbd6222ff3 100644 --- a/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro +++ b/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro @@ -188,7 +188,7 @@ SOURCES += \ ../../../XlsxFormat/ExternalLinks/ExternalLinkPath.cpp \ ../../../XlsxFormat/ExternalLinks/ExternalLinks.cpp \ ../../../XlsxFormat/Workbook/Metadata.cpp \ - ../../../XlsxFormat/RichData/RdRichValue.cpp \ + ../../../XlsxFormat/RichData/RdRichData.cpp \ ../../../XlsxFormat/Ole/OleObjects.cpp \ ../../../VsdxFormat/Vsdx.cpp \ ../../../VsdxFormat/VisioPages.cpp \ diff --git a/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp b/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp index b8b2abbe0f..6f4963cee7 100644 --- a/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp +++ b/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp @@ -97,6 +97,6 @@ #include "../../../XlsxFormat/SharedStrings/SharedStrings.cpp" #include "../../../XlsxFormat/Timelines/Timeline.cpp" #include "../../../XlsxFormat/Workbook/Metadata.cpp" -#include "../../../XlsxFormat/RichData/RdRichValue.cpp" +#include "../../../XlsxFormat/RichData/RdRichData.cpp" #include "../../../XlsxFormat/Pivot/PivotCacheChildOther.cpp" #include "../../../XlsxFormat/Pivot/PivotHierarchies.cpp" diff --git a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj index a097e79f1f..590c28f5d9 100644 --- a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj +++ b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj @@ -365,7 +365,7 @@ - + @@ -538,7 +538,7 @@ - + diff --git a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters index af6da32519..dc2d4ae433 100644 --- a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters +++ b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters @@ -544,9 +544,6 @@ XlsxFormat\Timelines - - XlsxFormat\RichData - XlsxFormat\Workbook @@ -582,10 +579,13 @@ VsdxFormat - + XlsxFormat\Workbook + + XlsxFormat\RichData + @@ -996,9 +996,6 @@ XlsxFormat\Timelines - - XlsxFormat\RichData - XlsxFormat\Workbook @@ -1038,5 +1035,8 @@ XlsxFormat\Workbook + + XlsxFormat\RichData + \ No newline at end of file diff --git a/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp b/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp index 89475757ba..a62674d1ea 100644 --- a/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp +++ b/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp @@ -59,7 +59,7 @@ #include "Slicer/Slicer.h" #include "NamedSheetViews/NamedSheetViews.h" #include "Timelines/Timeline.h" -#include "RichData/RdRichValue.h" +#include "RichData/RdRichData.h" #include "Workbook/Metadata.h" #include "Table/Table.h" diff --git a/OOXML/XlsxFormat/RichData/RdRichData.cpp b/OOXML/XlsxFormat/RichData/RdRichData.cpp new file mode 100644 index 0000000000..6ad8c3f3db --- /dev/null +++ b/OOXML/XlsxFormat/RichData/RdRichData.cpp @@ -0,0 +1,891 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#include "RdRichData.h" + +#include "../FileTypes_Spreadsheet.h" + +#include "../../Common/SimpleTypes_Shared.h" +#include "../../Common/SimpleTypes_Spreadsheet.h" + +#include "../../DocxFormat/Drawing/DrawingExt.h" +#include "../../../DesktopEditor/common/File.h" + +#include "../../Binary/Presentation/XmlWriter.h" +#include "../../Binary/Presentation/BinaryFileReaderWriter.h" + +namespace OOX +{ +namespace Spreadsheet +{ + CRdRichValueFile::CRdRichValueFile(OOX::Document* pMain) : OOX::File(pMain) + { + } + CRdRichValueFile::CRdRichValueFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) + { + read(oRootPath, oPath); + } + CRdRichValueFile::~CRdRichValueFile() + { + } + void CRdRichValueFile::read(const CPath& oPath) + { + //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) + CPath oRootPath; + read(oRootPath, oPath); + } + const OOX::FileType CRdRichValueFile::type() const + { + return OOX::Spreadsheet::FileTypes::RdRichValue; + } + const CPath CRdRichValueFile::DefaultDirectory() const + { + return type().DefaultDirectory(); + } + const CPath CRdRichValueFile::DefaultFileName() const + { + return type().DefaultFileName(); + } + const CPath& CRdRichValueFile::GetReadPath() + { + return m_oReadPath; + } + void CRdRichValueFile::read(const CPath& oRootPath, const CPath& oPath) + { + m_oReadPath = oPath; + + XmlUtils::CXmlLiteReader oReader; + + if (!oReader.FromFile(oPath.GetPath())) + return; + + if (!oReader.ReadNextNode()) + return; + + m_oRvData = oReader; + } + void CRdRichValueFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const + { + if (false == m_oRvData.IsInit()) return; + + NSStringUtils::CStringBuilder sXml; + + sXml.WriteString(L""); + + m_oRvData->toXML(sXml); + + std::wstring sPath = oPath.GetPath(); + NSFile::CFileBinary::SaveToFile(sPath, sXml.GetData()); + + oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename()); + } +//--------------------------------------------------------------------------------------------------------------------------- + CRdRichValueStructureFile::CRdRichValueStructureFile(OOX::Document* pMain) : OOX::File(pMain) + { + } + CRdRichValueStructureFile::CRdRichValueStructureFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) + { + read(oRootPath, oPath); + } + CRdRichValueStructureFile::~CRdRichValueStructureFile() + { + } + void CRdRichValueStructureFile::read(const CPath& oPath) + { + //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) + CPath oRootPath; + read(oRootPath, oPath); + } + const OOX::FileType CRdRichValueStructureFile::type() const + { + return OOX::Spreadsheet::FileTypes::RdRichValueStructure; + } + const CPath CRdRichValueStructureFile::DefaultDirectory() const + { + return type().DefaultDirectory(); + } + const CPath CRdRichValueStructureFile::DefaultFileName() const + { + return type().DefaultFileName(); + } + const CPath& CRdRichValueStructureFile::GetReadPath() + { + return m_oReadPath; + } + void CRdRichValueStructureFile::read(const CPath& oRootPath, const CPath& oPath) + { + m_oReadPath = oPath; + + XmlUtils::CXmlLiteReader oReader; + + if (!oReader.FromFile(oPath.GetPath())) + return; + + if (!oReader.ReadNextNode()) + return; + + m_oRvStructures = oReader; + } + void CRdRichValueStructureFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const + { + if (false == m_oRvStructures.IsInit()) return; + + NSStringUtils::CStringBuilder sXml; + + sXml.WriteString(L""); + m_oRvStructures->toXML(sXml); + + std::wstring sPath = oPath.GetPath(); + NSFile::CFileBinary::SaveToFile(sPath, sXml.GetData()); + + oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename()); + } +//--------------------------------------------------------------------------------------------------------------------------- + CRdRichValueTypesFile::CRdRichValueTypesFile(OOX::Document* pMain) : OOX::File(pMain) + { + } + CRdRichValueTypesFile::CRdRichValueTypesFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) + { + read(oRootPath, oPath); + } + CRdRichValueTypesFile::~CRdRichValueTypesFile() + { + } + void CRdRichValueTypesFile::read(const CPath& oPath) + { + //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) + CPath oRootPath; + read(oRootPath, oPath); + } + const OOX::FileType CRdRichValueTypesFile::type() const + { + return OOX::Spreadsheet::FileTypes::RdRichValueTypes; + } + const CPath CRdRichValueTypesFile::DefaultDirectory() const + { + return type().DefaultDirectory(); + } + const CPath CRdRichValueTypesFile::DefaultFileName() const + { + return type().DefaultFileName(); + } + const CPath& CRdRichValueTypesFile::GetReadPath() + { + return m_oReadPath; + } + void CRdRichValueTypesFile::read(const CPath& oRootPath, const CPath& oPath) + { + m_oReadPath = oPath; + + XmlUtils::CXmlLiteReader oReader; + + if (!oReader.FromFile(oPath.GetPath())) + return; + + if (!oReader.ReadNextNode()) + return; + + m_oRvTypesInfo = oReader; + } + void CRdRichValueTypesFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const + { + if (false == m_oRvTypesInfo.IsInit()) return; + + NSStringUtils::CStringBuilder sXml; + + sXml.WriteString(L""); + m_oRvTypesInfo->toXML(sXml); + + std::wstring sPath = oPath.GetPath(); + NSFile::CFileBinary::SaveToFile(sPath, sXml.GetData()); + + oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename()); + } +//----------------------------------------------------------------------------------- + CRichValueData::CRichValueData() {} + CRichValueData::~CRichValueData() {} + void CRichValueData::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueData::toXML() const + { + return L""; + } + EElementType CRichValueData::getType() const + { + return et_x_RichValueData; + } + void CRichValueData::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"rv" == sName) + { + CRichValue* pRichValue = new CRichValue(); + if (pRichValue) + { + pRichValue->fromXML(oReader); + m_arrItems.push_back(pRichValue); + } + } + else if (L"extLst" == sName) + { + m_oExtLst = oReader; + } + } + } + void CRichValueData::toXML(NSStringUtils::CStringBuilder& writer) const + { + if (m_arrItems.empty()) return; + + writer.WriteString(L""); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + if (m_arrItems[i]) + { + m_arrItems[i]->toXML(writer); + } + } + writer.WriteString(L""); + } +//----------------------------------------------------------------------------------- + CRichValueFallback::CRichValueFallback() {} + CRichValueFallback::~CRichValueFallback() {} + void CRichValueFallback::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueFallback::toXML() const + { + return L""; + } + EElementType CRichValueFallback::getType() const + { + return et_x_RichValueFallback; + } + void CRichValueFallback::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L"ToString()); + + if (m_sContent.empty()) + writer.WriteString(L"/>"); + else + { + writer.WriteString(L">"); + writer.WriteString(m_sContent); + writer.WriteString(L""); + } + } + void CRichValueFallback::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + m_sContent = oReader.GetText2(); + } + void CRichValueFallback::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_ReadSingle(oReader, L"t", m_oT) + WritingElement_ReadAttributes_End(oReader) + } +//------------------------------------------------------------------------------------- + CRichValue::CRichValue() {} + CRichValue::~CRichValue() {} + void CRichValue::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValue::toXML() const + { + return L""; + } + EElementType CRichValue::getType() const + { + return et_x_RichValue; + } + void CRichValue::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L""); + else + { + writer.WriteString(L">"); + for (auto v : m_arrV) + { + writer.WriteString(L"" + v + L""); + } + if (m_oFb.IsInit()) + m_oFb->toXML(); + writer.WriteString(L""); + } + } + void CRichValue::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"v" == sName) + { + m_arrV.push_back(oReader.GetText2()); + } + else if (L"fb" == sName) + { + m_oFb = oReader; + } + } + } + void CRichValue::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_ReadSingle(oReader, L"s", m_oS) + WritingElement_ReadAttributes_End(oReader) + } +//------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------- + CRichValueStructures::CRichValueStructures() {} + CRichValueStructures::~CRichValueStructures() {} + void CRichValueStructures::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueStructures::toXML() const + { + return L""; + } + EElementType CRichValueStructures::getType() const + { + return et_x_RichValueStructures; + } + void CRichValueStructures::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"s" == sName) + { + CRichValueStructure* pStructure = new CRichValueStructure(); + if (pStructure) + { + pStructure->fromXML(oReader); + m_arrItems.push_back(pStructure); + } + } + else if (L"extLst" == sName) + { + m_oExtLst = oReader; + } + } + } + void CRichValueStructures::toXML(NSStringUtils::CStringBuilder& writer) const + { + if (m_arrItems.empty()) return; + + writer.WriteString(L""); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + if (m_arrItems[i]) + { + m_arrItems[i]->toXML(writer); + } + } + writer.WriteString(L""); + } +//----------------------------------------------------------------------------------- + CRichValueStructure::CRichValueStructure() {} + CRichValueStructure::~CRichValueStructure() {} + void CRichValueStructure::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueStructure::toXML() const + { + return L""; + } + EElementType CRichValueStructure::getType() const + { + return et_x_RichValueStructure; + } + void CRichValueStructure::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L""); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + if (m_arrItems[i]) + { + m_arrItems[i]->toXML(writer); + } + } + writer.WriteString(L""); + } + void CRichValueStructure::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"k" == sName) + { + CRichValueKey* pKey = new CRichValueKey(); + if (pKey) + { + pKey->fromXML(oReader); + m_arrItems.push_back(pKey); + } + } + } + } + void CRichValueStructure::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_ReadSingle(oReader, L"t", m_oT) + WritingElement_ReadAttributes_End(oReader) + } +//------------------------------------------------------------------------------------- + CRichValueKey::CRichValueKey() {} + CRichValueKey::~CRichValueKey() {} + void CRichValueKey::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueKey::toXML() const + { + return L""; + } + EElementType CRichValueKey::getType() const + { + return et_x_RichValueKey; + } + void CRichValueKey::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L"ToString()); + writer.WriteString(L"/>"); + } + void CRichValueKey::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (!oReader.IsEmptyNode()) + oReader.ReadTillEnd(); + } + void CRichValueKey::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_Read_if(oReader, L"n", m_oN) + WritingElement_ReadAttributes_Read_else_if(oReader, L"t", m_oT) + WritingElement_ReadAttributes_End(oReader) + } +//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------- + CRichValueTypesInfo::CRichValueTypesInfo() {} + CRichValueTypesInfo::~CRichValueTypesInfo() {} + void CRichValueTypesInfo::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueTypesInfo::toXML() const + { + return L""; + } + EElementType CRichValueTypesInfo::getType() const + { + return et_x_RichValueTypesInfo; + } + void CRichValueTypesInfo::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"global" == sName) + { + m_oGlobal = oReader; + } + else if (L"types" == sName) + { + m_oTypes = oReader; + } + else if (L"extLst" == sName) + { + m_oExtLst = oReader; + } + } + } + void CRichValueTypesInfo::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L""); + if (m_oGlobal.IsInit()) + m_oGlobal->toXML(writer); + + if (m_oTypes.IsInit()) + m_oTypes->toXML(writer); + + writer.WriteString(L""); + } +//----------------------------------------------------------------------------------- + CRichValueTypes::CRichValueTypes() {} + CRichValueTypes::~CRichValueTypes() {} + void CRichValueTypes::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueTypes::toXML() const + { + return L""; + } + EElementType CRichValueTypes::getType() const + { + return et_x_RichValueTypes; + } + void CRichValueTypes::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"types" == sName) + { + CRichValueType* pType = new CRichValueType(); + if (pType) + { + pType->fromXML(oReader); + m_arrItems.push_back(pType); + } + } + } + } + void CRichValueTypes::toXML(NSStringUtils::CStringBuilder& writer) const + { + if (m_arrItems.empty()) return; + + writer.WriteString(L""); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + if (m_arrItems[i]) + { + m_arrItems[i]->toXML(writer); + } + } + writer.WriteString(L""); + } +//----------------------------------------------------------------------------------- + CRichValueType::CRichValueType() {} + CRichValueType::~CRichValueType() {} + void CRichValueType::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueType::toXML() const + { + return L""; + } + EElementType CRichValueType::getType() const + { + return et_x_RichValueType; + } + void CRichValueType::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"keyFlags" == sName) + { + m_oKeyFlags = oReader; + } + else if (L"extLst" == sName) + { + m_oExtLst = oReader; + } + } + } + void CRichValueType::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L""); + + if (m_oKeyFlags.IsInit()) + m_oKeyFlags->toXML(writer); + + writer.WriteString(L""); + } + void CRichValueType::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_Read_if(oReader, L"name", m_oName) + WritingElement_ReadAttributes_End(oReader) + } +//----------------------------------------------------------------------------------- + void CRichValueTypeKeyFlags::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueTypeKeyFlags::toXML() const + { + return L""; + } + EElementType CRichValueTypeKeyFlags::getType() const + { + return et_x_RichValueTypeKeyFlags; + } + void CRichValueTypeKeyFlags::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"key" == sName) + { + CRichValueTypeReservedKey* pType = new CRichValueTypeReservedKey(); + if (pType) + { + pType->fromXML(oReader); + m_arrItems.push_back(pType); + } + } + } + } + void CRichValueTypeKeyFlags::toXML(NSStringUtils::CStringBuilder& writer) const + { + if (m_arrItems.empty()) return; + + writer.WriteString(L""); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + if (m_arrItems[i]) + { + m_arrItems[i]->toXML(writer); + } + } + writer.WriteString(L""); + } +//----------------------------------------------------------------------------------- + CRichValueTypeReservedKey::CRichValueTypeReservedKey() {} + CRichValueTypeReservedKey::~CRichValueTypeReservedKey() {} + void CRichValueTypeReservedKey::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueTypeReservedKey::toXML() const + { + return L""; + } + EElementType CRichValueTypeReservedKey::getType() const + { + return et_x_RichValueTypeReservedKey; + } + void CRichValueTypeReservedKey::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"flag" == sName) + { + CRichValueTypeReservedKeyFlag* pFlag = new CRichValueTypeReservedKeyFlag(); + if (pFlag) + { + pFlag->fromXML(oReader); + m_arrItems.push_back(pFlag); + } + } + } + } + void CRichValueTypeReservedKey::toXML(NSStringUtils::CStringBuilder& writer) const + { + if (m_arrItems.empty()) return; + + writer.WriteString(L""); + else + { + writer.WriteString(L">"); + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + if (m_arrItems[i]) + { + m_arrItems[i]->toXML(writer); + } + } + writer.WriteString(L""); + } + } + void CRichValueTypeReservedKey::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_ReadSingle(oReader, L"name", m_oName) + WritingElement_ReadAttributes_End(oReader) + } +//------------------------------------------------------------------------------------- + CRichValueTypeReservedKeyFlag::CRichValueTypeReservedKeyFlag() {} + CRichValueTypeReservedKeyFlag::~CRichValueTypeReservedKeyFlag() {} + void CRichValueTypeReservedKeyFlag::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueTypeReservedKeyFlag::toXML() const + { + return L""; + } + EElementType CRichValueTypeReservedKeyFlag::getType() const + { + return et_x_RichValueTypeReservedKeyFlag; + } + void CRichValueTypeReservedKeyFlag::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L""); + } + void CRichValueTypeReservedKeyFlag::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (!oReader.IsEmptyNode()) + oReader.ReadTillEnd(); + } + void CRichValueTypeReservedKeyFlag::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_Start(oReader) + WritingElement_ReadAttributes_Read_if(oReader, L"name", m_oName) + WritingElement_ReadAttributes_Read_else_if(oReader, L"value", m_oValue) + WritingElement_ReadAttributes_End(oReader) + } +//----------------------------------------------------------------------------------- + CRichValueGlobalType::CRichValueGlobalType() {} + CRichValueGlobalType::~CRichValueGlobalType() {} + void CRichValueGlobalType::fromXML(XmlUtils::CXmlNode& node) + { + } + std::wstring CRichValueGlobalType::toXML() const + { + return L""; + } + EElementType CRichValueGlobalType::getType() const + { + return et_x_RichValueGlobalType; + } + void CRichValueGlobalType::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if (L"keyFlags" == sName) + { + m_oKeyFlags = oReader; + } + else if (L"extLst" == sName) + { + m_oExtLst = oReader; + } + } + } + void CRichValueGlobalType::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L""); + + if (m_oKeyFlags.IsInit()) + m_oKeyFlags->toXML(writer); + + writer.WriteString(L""); + } + +} +} + diff --git a/OOXML/XlsxFormat/RichData/RdRichData.h b/OOXML/XlsxFormat/RichData/RdRichData.h new file mode 100644 index 0000000000..23cb265ea0 --- /dev/null +++ b/OOXML/XlsxFormat/RichData/RdRichData.h @@ -0,0 +1,383 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#pragma once + +#include "../Table/Autofilter.h" +#include "../../DocxFormat/IFileContainer.h" +#include "../../Common/SimpleTypes_Spreadsheet.h" + +namespace OOX +{ + namespace Drawing + { + class COfficeArtExtensionList; + } + + namespace Spreadsheet + { +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueTypeReservedKeyFlag : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValueTypeReservedKeyFlag) + CRichValueTypeReservedKeyFlag(); + virtual ~CRichValueTypeReservedKeyFlag(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + public: + nullable_bool m_oValue; + nullable_string m_oName; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueTypeReservedKey : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CRichValueTypeReservedKey) + CRichValueTypeReservedKey(); + virtual ~CRichValueTypeReservedKey(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + nullable_string m_oName; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueTypeKeyFlags : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CRichValueTypeKeyFlags) + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueType : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValueType) + CRichValueType(); + virtual ~CRichValueType(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + nullable_string m_oName; + nullable m_oKeyFlags; + nullable m_oExtLst; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueTypes : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CRichValueTypes) + CRichValueTypes(); + virtual ~CRichValueTypes(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueGlobalType : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValueGlobalType) + CRichValueGlobalType(); + virtual ~CRichValueGlobalType(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + nullable m_oKeyFlags; + nullable m_oExtLst; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueTypesInfo : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValueTypesInfo) + CRichValueTypesInfo(); + virtual ~CRichValueTypesInfo(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + nullable m_oGlobal; + nullable m_oTypes; + nullable m_oExtLst; + }; +//------------------------------------------------------------------------------------------------------------------------ +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueKey : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValueKey) + CRichValueKey(); + virtual ~CRichValueKey(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + public: + nullable m_oT; + nullable_string m_oN; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueStructure : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CRichValueStructure) + CRichValueStructure(); + virtual ~CRichValueStructure(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + public: + nullable_string m_oT; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueStructures : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CRichValueStructures) + CRichValueStructures(); + virtual ~CRichValueStructures(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + nullable_uint m_oCount; + nullable m_oExtLst; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueFallback : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValueFallback) + CRichValueFallback(); + virtual ~CRichValueFallback(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + public: + nullable m_oT; + std::wstring m_sContent; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValue : public WritingElement + { + public: + WritingElement_AdditionMethods(CRichValue) + CRichValue(); + virtual ~CRichValue(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + public: + nullable_uint m_oS; + + nullable m_oFb; + std::vector m_arrV; //todooo types ... + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRichValueData : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CRichValueData) + CRichValueData(); + virtual ~CRichValueData(); + + virtual void fromXML(XmlUtils::CXmlNode& node); + virtual std::wstring toXML() const; + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + + virtual EElementType getType() const; + + nullable_uint m_oCount; + nullable m_oExtLst; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRdRichValueFile : public OOX::File + { + public: + CRdRichValueFile(OOX::Document* pMain); + CRdRichValueFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); + virtual ~CRdRichValueFile(); + + virtual void read(const CPath& oPath); + virtual void read(const CPath& oRootPath, const CPath& oPath); + + virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; + virtual const OOX::FileType type() const; + + virtual const CPath DefaultDirectory() const; + virtual const CPath DefaultFileName() const; + + const CPath& GetReadPath(); + + nullable m_oRvData; + private: + CPath m_oReadPath; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRdRichValueStructureFile : public OOX::File + { + public: + CRdRichValueStructureFile(OOX::Document* pMain); + CRdRichValueStructureFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); + virtual ~CRdRichValueStructureFile(); + + virtual void read(const CPath& oPath); + virtual void read(const CPath& oRootPath, const CPath& oPath); + + virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; + virtual const OOX::FileType type() const; + + virtual const CPath DefaultDirectory() const; + virtual const CPath DefaultFileName() const; + + const CPath& GetReadPath(); + + nullable m_oRvStructures; + + private: + CPath m_oReadPath; + }; +//------------------------------------------------------------------------------------------------------------------------ + class CRdRichValueTypesFile : public OOX::File + { + public: + CRdRichValueTypesFile(OOX::Document* pMain); + CRdRichValueTypesFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); + virtual ~CRdRichValueTypesFile(); + + virtual void read(const CPath& oPath); + virtual void read(const CPath& oRootPath, const CPath& oPath); + + virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; + virtual const OOX::FileType type() const; + + virtual const CPath DefaultDirectory() const; + virtual const CPath DefaultFileName() const; + + const CPath& GetReadPath(); + + nullable m_oRvTypesInfo; + private: + CPath m_oReadPath; + }; + } //Spreadsheet +} // namespace OOX diff --git a/OOXML/XlsxFormat/RichData/RdRichValue.cpp b/OOXML/XlsxFormat/RichData/RdRichValue.cpp deleted file mode 100644 index c0a1148493..0000000000 --- a/OOXML/XlsxFormat/RichData/RdRichValue.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * (c) Copyright Ascensio System SIA 2010-2023 - * - * This program is a free software product. You can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License (AGPL) - * version 3 as published by the Free Software Foundation. In accordance with - * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect - * that Ascensio System SIA expressly excludes the warranty of non-infringement - * of any third-party rights. - * - * This program is distributed WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For - * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html - * - * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish - * street, Riga, Latvia, EU, LV-1050. - * - * The interactive user interfaces in modified source and object code versions - * of the Program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU AGPL version 3. - * - * Pursuant to Section 7(b) of the License you must retain the original Product - * logo when distributing the program. Pursuant to Section 7(e) we decline to - * grant you any rights under trademark law for use of our trademarks. - * - * All the Product's GUI elements, including illustrations and icon sets, as - * well as technical writing content are licensed under the terms of the - * Creative Commons Attribution-ShareAlike 4.0 International. See the License - * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - * - */ -#include "RdRichValue.h" - -#include "../FileTypes_Spreadsheet.h" - -#include "../../Common/SimpleTypes_Shared.h" -#include "../../Common/SimpleTypes_Spreadsheet.h" - -#include "../../DocxFormat/Drawing/DrawingExt.h" -#include "../../../DesktopEditor/common/File.h" - -#include "../../Binary/Presentation/XmlWriter.h" -#include "../../Binary/Presentation/BinaryFileReaderWriter.h" - -namespace OOX -{ -namespace Spreadsheet -{ - CRdRichValueFile::CRdRichValueFile(OOX::Document* pMain) : OOX::File(pMain) - { - } - CRdRichValueFile::CRdRichValueFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) - { - read(oRootPath, oPath); - } - CRdRichValueFile::~CRdRichValueFile() - { - } - void CRdRichValueFile::read(const CPath& oPath) - { - //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) - CPath oRootPath; - read(oRootPath, oPath); - } - const OOX::FileType CRdRichValueFile::type() const - { - return OOX::Spreadsheet::FileTypes::RdRichValue; - } - const CPath CRdRichValueFile::DefaultDirectory() const - { - return type().DefaultDirectory(); - } - const CPath CRdRichValueFile::DefaultFileName() const - { - return type().DefaultFileName(); - } - const CPath& CRdRichValueFile::GetReadPath() - { - return m_oReadPath; - } - void CRdRichValueFile::read(const CPath& oRootPath, const CPath& oPath) - { - m_oReadPath = oPath; - - XmlUtils::CXmlLiteReader oReader; - - if (!oReader.FromFile(oPath.GetPath())) - return; - - if (!oReader.ReadNextNode()) - return; - - //m_oMetadata = oReader; - } - void CRdRichValueFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const - { - //if (false == m_oMetadata.IsInit()) return; - - NSStringUtils::CStringBuilder sXml; - - sXml.WriteString(L""); - //m_oMetadata->toXML(sXml); - - std::wstring sPath = oPath.GetPath(); - NSFile::CFileBinary::SaveToFile(sPath, sXml.GetData()); - - oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename()); - } -//--------------------------------------------------------------------------------------------------------------------------- - CRdRichValueStructureFile::CRdRichValueStructureFile(OOX::Document* pMain) : OOX::File(pMain) - { - } - CRdRichValueStructureFile::CRdRichValueStructureFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) - { - read(oRootPath, oPath); - } - CRdRichValueStructureFile::~CRdRichValueStructureFile() - { - } - void CRdRichValueStructureFile::read(const CPath& oPath) - { - //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) - CPath oRootPath; - read(oRootPath, oPath); - } - const OOX::FileType CRdRichValueStructureFile::type() const - { - return OOX::Spreadsheet::FileTypes::RdRichValueStructure; - } - const CPath CRdRichValueStructureFile::DefaultDirectory() const - { - return type().DefaultDirectory(); - } - const CPath CRdRichValueStructureFile::DefaultFileName() const - { - return type().DefaultFileName(); - } - const CPath& CRdRichValueStructureFile::GetReadPath() - { - return m_oReadPath; - } - void CRdRichValueStructureFile::read(const CPath& oRootPath, const CPath& oPath) - { - m_oReadPath = oPath; - - XmlUtils::CXmlLiteReader oReader; - - if (!oReader.FromFile(oPath.GetPath())) - return; - - if (!oReader.ReadNextNode()) - return; - - //m_oMetadata = oReader; - } - void CRdRichValueStructureFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const - { - //if (false == m_oMetadata.IsInit()) return; - - NSStringUtils::CStringBuilder sXml; - - sXml.WriteString(L""); - //m_oMetadata->toXML(sXml); - - std::wstring sPath = oPath.GetPath(); - NSFile::CFileBinary::SaveToFile(sPath, sXml.GetData()); - - oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename()); - } -//--------------------------------------------------------------------------------------------------------------------------- - CRdRichValueTypesFile::CRdRichValueTypesFile(OOX::Document* pMain) : OOX::File(pMain) - { - } - CRdRichValueTypesFile::CRdRichValueTypesFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) - { - read(oRootPath, oPath); - } - CRdRichValueTypesFile::~CRdRichValueTypesFile() - { - } - void CRdRichValueTypesFile::read(const CPath& oPath) - { - //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) - CPath oRootPath; - read(oRootPath, oPath); - } - const OOX::FileType CRdRichValueTypesFile::type() const - { - return OOX::Spreadsheet::FileTypes::RdRichValueTypes; - } - const CPath CRdRichValueTypesFile::DefaultDirectory() const - { - return type().DefaultDirectory(); - } - const CPath CRdRichValueTypesFile::DefaultFileName() const - { - return type().DefaultFileName(); - } - const CPath& CRdRichValueTypesFile::GetReadPath() - { - return m_oReadPath; - } - void CRdRichValueTypesFile::read(const CPath& oRootPath, const CPath& oPath) - { - m_oReadPath = oPath; - - XmlUtils::CXmlLiteReader oReader; - - if (!oReader.FromFile(oPath.GetPath())) - return; - - if (!oReader.ReadNextNode()) - return; - - //m_oMetadata = oReader; - } - void CRdRichValueTypesFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const - { - //if (false == m_oMetadata.IsInit()) return; - - NSStringUtils::CStringBuilder sXml; - - sXml.WriteString(L""); - //m_oMetadata->toXML(sXml); - - std::wstring sPath = oPath.GetPath(); - NSFile::CFileBinary::SaveToFile(sPath, sXml.GetData()); - - oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename()); - } -} -} - diff --git a/OOXML/XlsxFormat/RichData/RdRichValue.h b/OOXML/XlsxFormat/RichData/RdRichValue.h deleted file mode 100644 index 1b94966a35..0000000000 --- a/OOXML/XlsxFormat/RichData/RdRichValue.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * (c) Copyright Ascensio System SIA 2010-2023 - * - * This program is a free software product. You can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License (AGPL) - * version 3 as published by the Free Software Foundation. In accordance with - * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect - * that Ascensio System SIA expressly excludes the warranty of non-infringement - * of any third-party rights. - * - * This program is distributed WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For - * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html - * - * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish - * street, Riga, Latvia, EU, LV-1050. - * - * The interactive user interfaces in modified source and object code versions - * of the Program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU AGPL version 3. - * - * Pursuant to Section 7(b) of the License you must retain the original Product - * logo when distributing the program. Pursuant to Section 7(e) we decline to - * grant you any rights under trademark law for use of our trademarks. - * - * All the Product's GUI elements, including illustrations and icon sets, as - * well as technical writing content are licensed under the terms of the - * Creative Commons Attribution-ShareAlike 4.0 International. See the License - * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - * - */ -#pragma once - -#include "../Table/Autofilter.h" -#include "../../DocxFormat/IFileContainer.h" -#include "../../Common/SimpleTypes_Spreadsheet.h" - -namespace OOX -{ - namespace Spreadsheet - { - class CRdRichValueFile : public OOX::File - { - public: - CRdRichValueFile(OOX::Document* pMain); - CRdRichValueFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); - virtual ~CRdRichValueFile(); - - virtual void read(const CPath& oPath); - virtual void read(const CPath& oRootPath, const CPath& oPath); - - virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; - virtual const OOX::FileType type() const; - - virtual const CPath DefaultDirectory() const; - virtual const CPath DefaultFileName() const; - - const CPath& GetReadPath(); - - //nullable m_oTimelines; - private: - CPath m_oReadPath; - }; -//------------------------------------------------------------------------------------------------------------------------ - class CRdRichValueStructureFile : public OOX::File - { - public: - CRdRichValueStructureFile(OOX::Document* pMain); - CRdRichValueStructureFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); - virtual ~CRdRichValueStructureFile(); - - virtual void read(const CPath& oPath); - virtual void read(const CPath& oRootPath, const CPath& oPath); - - virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; - virtual const OOX::FileType type() const; - - virtual const CPath DefaultDirectory() const; - virtual const CPath DefaultFileName() const; - - const CPath& GetReadPath(); - - private: - CPath m_oReadPath; - }; -//------------------------------------------------------------------------------------------------------------------------ - class CRdRichValueTypesFile : public OOX::File - { - public: - CRdRichValueTypesFile(OOX::Document* pMain); - CRdRichValueTypesFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); - virtual ~CRdRichValueTypesFile(); - - virtual void read(const CPath& oPath); - virtual void read(const CPath& oRootPath, const CPath& oPath); - - virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; - virtual const OOX::FileType type() const; - - virtual const CPath DefaultDirectory() const; - virtual const CPath DefaultFileName() const; - - const CPath& GetReadPath(); - private: - CPath m_oReadPath; - }; - } //Spreadsheet -} // namespace OOX diff --git a/OOXML/XlsxFormat/Timelines/Timeline.cpp b/OOXML/XlsxFormat/Timelines/Timeline.cpp index 9049901f06..000dea6f98 100644 --- a/OOXML/XlsxFormat/Timelines/Timeline.cpp +++ b/OOXML/XlsxFormat/Timelines/Timeline.cpp @@ -144,8 +144,11 @@ namespace OOX if (L"pivotTable" == sName) { CTimelineCachePivotTable* pPivotTable = new CTimelineCachePivotTable(); - *pPivotTable = oReader; - m_arrItems.push_back(pPivotTable); + if (pPivotTable) + { + pPivotTable->fromXML(oReader); + m_arrItems.push_back(pPivotTable); + } } } } @@ -255,8 +258,11 @@ namespace OOX if (L"timeline" == sName) { CTimeline* pTimeline = new CTimeline(); - *pTimeline = oReader; - m_arrItems.push_back(pTimeline); + if (pTimeline) + { + pTimeline->fromXML(oReader); + m_arrItems.push_back(pTimeline); + } } } } @@ -649,8 +655,11 @@ xmlns:xr10=\"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10\" if (L"timelineRef" == sName) { CTimelineRef* pTimelineRef = new CTimelineRef(); - *pTimelineRef = oReader; - m_arrItems.push_back(pTimelineRef); + if (pTimelineRef) + { + pTimelineRef->fromXML(oReader); + m_arrItems.push_back(pTimelineRef); + } } } } @@ -726,8 +735,11 @@ xmlns:xr10=\"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10\" if (L"timelineCacheRef" == sName) { CTimelineCacheRef* pTimelineCacheRef = new CTimelineCacheRef(); - *pTimelineCacheRef = oReader; - m_arrItems.push_back(pTimelineCacheRef); + if (pTimelineCacheRef) + { + pTimelineCacheRef->fromXML(oReader); + m_arrItems.push_back(pTimelineCacheRef); + } } } } @@ -811,8 +823,11 @@ xmlns:xr10=\"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10\" if (L"timelineStyle" == sName) { CTimelineStyle* pStyle = new CTimelineStyle(); - *pStyle = oReader; - m_arrItems.push_back(pStyle); + if (pStyle) + { + pStyle->fromXML(oReader); + m_arrItems.push_back(pStyle); + } } } } @@ -873,8 +888,11 @@ xmlns:xr10=\"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10\" if (L"timelineStyleElement" == sName) { CTimelineStyleElement* pStyle = new CTimelineStyleElement(); - *pStyle = oReader; - m_arrItems.push_back(pStyle); + if (pStyle) + { + pStyle->fromXML(oReader); + m_arrItems.push_back(pStyle); + } } } } From e31e02d993b85d01be64c79550cb3869db30e700 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 9 Dec 2025 10:42:13 +0300 Subject: [PATCH 059/125] Font substitution info --- DesktopEditor/doctrenderer/drawingfile.h | 3 +++ DesktopEditor/graphics/IRenderer.h | 1 + .../pro/js/wasm/src/drawingfile_test.cpp | 23 +++++++++++-------- PdfFile/PdfFile.cpp | 5 ++++ PdfFile/PdfFile.h | 1 + PdfFile/PdfReader.cpp | 18 +++++++++++++++ PdfFile/PdfReader.h | 1 + PdfFile/SrcReader/RendererOutputDev.cpp | 22 +++++++++++++----- PdfFile/SrcReader/RendererOutputDev.h | 5 ++-- 9 files changed, 61 insertions(+), 18 deletions(-) diff --git a/DesktopEditor/doctrenderer/drawingfile.h b/DesktopEditor/doctrenderer/drawingfile.h index 24bd1fd258..47bf314044 100644 --- a/DesktopEditor/doctrenderer/drawingfile.h +++ b/DesktopEditor/doctrenderer/drawingfile.h @@ -479,6 +479,9 @@ public: return NULL; } + if (m_nType == 0) + ((CPdfFile*)m_pFile)->SetPageFonts(nPageIndex); + BYTE* res = oRes.GetBuffer(); oRes.ClearWithoutAttack(); return res; diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 90d6273819..a6bad0f876 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -117,6 +117,7 @@ const long c_nDarkMode = 0x0008; const long c_nUseDictionaryFonts = 0x0010; const long c_nPenWidth0As1px = 0x0020; const long c_nSupportPathTextAsText = 0x0040; +const long c_nFontSubstitution = 0x0080; // типы рендерера const long c_nUnknownRenderer = 0x0000; diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 1629ee7d95..82fd656dca 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -1134,17 +1134,17 @@ int main(int argc, char* argv[]) std::cout << "Redact false" << std::endl; } - int i = nTestPage; - //for (int i = 0; i < nPagesCount; ++i) + // RASTER + if (false) { - // RASTER - if (true) + int i = nTestPage; + //for (int i = 0; i < nPagesCount; ++i) { nWidth = READ_INT(pInfo + i * 16 + 12); nHeight = READ_INT(pInfo + i * 16 + 16); - //nWidth *= 3; - //nHeight *= 3; + //nWidth *= 2; + //nHeight *= 2; BYTE* res = NULL; res = GetPixmap(pGrFile, i, nWidth, nHeight, 0xFFFFFF); @@ -1164,7 +1164,7 @@ int main(int argc, char* argv[]) free(pInfo); // LINKS - if (true && nPagesCount > 0) + if (false && nPagesCount > 0) { BYTE* pLinks = GetLinks(pGrFile, nTestPage); nLength = READ_INT(pLinks); @@ -1200,7 +1200,7 @@ int main(int argc, char* argv[]) } // STRUCTURE - if (true) + if (false) { BYTE* pStructure = GetStructure(pGrFile); nLength = READ_INT(pStructure); @@ -2155,11 +2155,14 @@ int main(int argc, char* argv[]) } // SCAN PAGE - if (false) + if (true) { - BYTE* pScan = ScanPage(pGrFile, nTestPage, 1); + BYTE* pScan = ScanPage(pGrFile, nTestPage, 2); if (pScan) free(pScan); + + ReadInteractiveFormsFonts(pGrFile, 1); + ReadInteractiveFormsFonts(pGrFile, 2); } Close(pGrFile); diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 3d8024c432..a5dac89843 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -428,6 +428,11 @@ BYTE* CPdfFile::GetWidgets() return NULL; return m_pInternal->pReader->GetWidgets(); } +void CPdfFile::SetPageFonts(int nPageIndex) +{ + if (m_pInternal->pReader) + m_pInternal->pReader->SetFonts(nPageIndex); +} BYTE* CPdfFile::GetAnnotEmbeddedFonts() { if (!m_pInternal->pReader) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 711e5b1426..9c89debeb5 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -135,6 +135,7 @@ public: bool UndoRedact(); int GetRotate(int nPageIndex); int GetMaxRefID(); + void SetPageFonts(int nPageIndex); BYTE* GetWidgets(); BYTE* GetAnnotEmbeddedFonts(); BYTE* GetAnnotStandardFonts(); diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 96e05af7da..733998c52d 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -1387,6 +1387,24 @@ BYTE* CPdfReader::GetWidgets() oRes.ClearWithoutAttack(); return bRes; } +void CPdfReader::SetFonts(int _nPageIndex) +{ + if (m_vPDFContext.empty()) + return; + + PDFDoc* pDoc = NULL; + PdfReader::CPdfFontList* pFontList = NULL; + GetPageIndex(_nPageIndex, &pDoc, &pFontList); + + const std::map& mapFonts = pFontList->GetFonts(); + for (std::map::const_iterator it = mapFonts.begin(); it != mapFonts.end(); ++it) + { + PdfReader::TFontEntry* pEntry = it->second; + if (!pEntry) + continue; + m_mFonts.insert(std::make_pair(pEntry->wsFontName, pEntry->wsFilePath)); + } +} BYTE* CPdfReader::GetFonts(bool bStandart) { NSWasm::CData oRes; diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 8e2ae637c3..4a35f79963 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -111,6 +111,7 @@ public: int FindRefNum(int nObjID, PDFDoc** pDoc = NULL, int* nStartRefID = NULL); int GetPageIndex(int nPageIndex, PDFDoc** pDoc = NULL, PdfReader::CPdfFontList** pFontList = NULL, int* nStartRefID = NULL); + void SetFonts(int nPageIndex); BYTE* GetStructure(); BYTE* GetLinks(int nPageIndex); BYTE* GetWidgets(); diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index 13660c88a5..1ce592cd3e 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -347,7 +347,7 @@ namespace PdfReader } void CPdfFontList::Remove(Ref oRef) { - CRefFontMap::iterator oPos = m_oFontMap.find(oRef); + std::map::iterator oPos = m_oFontMap.find(oRef); if (m_oFontMap.end() != oPos) { TFontEntry* pEntry = oPos->second; @@ -385,7 +385,7 @@ namespace PdfReader } TFontEntry* CPdfFontList::Lookup(Ref& oRef) { - CRefFontMap::const_iterator oPos = m_oFontMap.find(oRef); + std::map::const_iterator oPos = m_oFontMap.find(oRef); return m_oFontMap.end() == oPos ? NULL : oPos->second; } void CPdfFontList::Add(Ref& oRef, TFontEntry* pFontEntry) @@ -393,6 +393,10 @@ namespace PdfReader // До вызова данной функции надо проверять есть ли элемент с данным ключом m_oFontMap.insert(std::pair(oRef, pFontEntry)); } + const std::map& CPdfFontList::GetFonts() + { + return m_oFontMap; + } //-------------------------------------------------------------------------------------- // RendererOutputDev //-------------------------------------------------------------------------------------- @@ -1562,6 +1566,7 @@ namespace PdfReader pEntry->unLenGID = (unsigned int)nLen; pEntry->unLenUnicode = (unsigned int)nToUnicodeLen; pEntry->bAvailable = true; + pEntry->bFontSubstitution = bFontSubstitution; } else if (NULL != pEntry) { @@ -1589,6 +1594,14 @@ namespace PdfReader { m_pRenderer->put_FontPath(wsFileName); m_pRenderer->put_FontName(wsFontName); + if (c_nDocxWriter == m_lRendererType) + { + TFontEntry oEntry; + if (!m_pFontList->GetFont(pFont->getID(), &oEntry)) + return; + if (oEntry.bFontSubstitution) + m_pRenderer->CommandLong(c_nFontSubstitution, 0); + } } } void RendererOutputDev::stroke(GfxState* pGState) @@ -2562,11 +2575,8 @@ namespace PdfReader m_pRenderer->put_FontPath(sFontPath); } - LONG lRendererType = 0; - m_pRenderer->get_Type(&lRendererType); - bool bIsEmulateBold = false; - if (c_nDocxWriter == lRendererType && 2 == nRenderMode) + if (c_nDocxWriter == m_lRendererType && 2 == nRenderMode) bIsEmulateBold = (S_OK == m_pRenderer->CommandLong(c_nSupportPathTextAsText, 0)) ? true : false; if (bIsEmulateBold) diff --git a/PdfFile/SrcReader/RendererOutputDev.h b/PdfFile/SrcReader/RendererOutputDev.h index 359008925b..8a5851728f 100644 --- a/PdfFile/SrcReader/RendererOutputDev.h +++ b/PdfFile/SrcReader/RendererOutputDev.h @@ -55,6 +55,7 @@ namespace PdfReader unsigned int unLenGID; unsigned int unLenUnicode; bool bAvailable; // Доступен ли шрифт. Сделано для многопотоковости + bool bFontSubstitution = false; }; @@ -69,13 +70,13 @@ namespace PdfReader TFontEntry* Add(Ref oRef, const std::wstring& wsFileName, int* pCodeToGID, int* pCodeToUnicode, unsigned int unLenGID, unsigned int unLenUnicode); void Clear(); bool GetFont(Ref* pRef, TFontEntry* pEntry); + const std::map& GetFonts(); private: TFontEntry* Lookup(Ref& oRef); void Add(Ref& oRef, TFontEntry* pFontEntry); private: - typedef std::map CRefFontMap; - CRefFontMap m_oFontMap; + std::map m_oFontMap; NSCriticalSection::CRITICAL_SECTION m_oCS; // Критическая секция }; From fefeb483e511919af31b7e6e5c4719deb95fd748 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 9 Dec 2025 12:56:53 +0300 Subject: [PATCH 060/125] Fix bug 78932 --- DesktopEditor/graphics/BooleanOperations.cpp | 20 +++++++++++++------- DesktopEditor/graphics/BooleanOperations.h | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/DesktopEditor/graphics/BooleanOperations.cpp b/DesktopEditor/graphics/BooleanOperations.cpp index 2695a638f8..3e59f42b75 100644 --- a/DesktopEditor/graphics/BooleanOperations.cpp +++ b/DesktopEditor/graphics/BooleanOperations.cpp @@ -737,11 +737,13 @@ CBooleanOperations::CBooleanOperations(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op, long fillType, - bool isLuminosity) : + bool isLuminosity, + bool isSelf) : Op(op), Close1(path1.Is_poly_closed()), Close2(path2.Is_poly_closed()), IsLuminosity(isLuminosity), + IsSelf(isSelf), FillType(fillType), Path1(path1), Path2(path2) @@ -784,10 +786,9 @@ bool CBooleanOperations::IsSelfInters(const CGraphicsPath& p) void CBooleanOperations::TraceBoolean() { bool reverse = false; - bool self = Path1 == Path2; if (((Op == Subtraction || Op == Exclusion) ^ Path1.IsClockwise() ^ - Path2.IsClockwise()) && !self) + Path2.IsClockwise()) && !IsSelf) reverse = true; PreparePath(Path1, 1, Segments1, Curves1); @@ -798,7 +799,7 @@ void CBooleanOperations::TraceBoolean() GetIntersection(); - if (self) + if (IsSelf) { if (Op == Subtraction) return; @@ -823,6 +824,11 @@ void CBooleanOperations::TraceBoolean() CreateNewPath(adj_matr); return; } + else if (Path1 == Path2) + { + Result = std::move(Path1); + return; + } if (!Locations.empty()) { @@ -2355,7 +2361,7 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1, CBooleanOperations o; if (i > skip_end2 && o.IsSelfInters(paths2[i])) { - CBooleanOperations operation(paths2[i], paths2[i], Intersection, fillType, isLuminosity); + CBooleanOperations operation(paths2[i], paths2[i], Intersection, fillType, isLuminosity, true); CGraphicsPath p = std::move(operation.GetResult()); std::vector tmp_paths = p.GetSubPaths(); @@ -2370,7 +2376,7 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1, CBooleanOperations o2; if (j > skip_end1 && o2.IsSelfInters(paths1[j])) { - CBooleanOperations operation(paths1[j], paths1[j], Intersection, fillType, isLuminosity); + CBooleanOperations operation(paths1[j], paths1[j], Intersection, fillType, isLuminosity, true); CGraphicsPath p = std::move(operation.GetResult()); std::vector tmp_paths = p.GetSubPaths(); @@ -2380,7 +2386,7 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1, paths1.insert(paths1.begin() + i + k, tmp_paths[k]); } - CBooleanOperations operation(paths1[j], paths2[i], op, fillType, isLuminosity); + CBooleanOperations operation(paths1[j], paths2[i], op, fillType, isLuminosity, false); paths.push_back(operation.GetResult()); } diff --git a/DesktopEditor/graphics/BooleanOperations.h b/DesktopEditor/graphics/BooleanOperations.h index 8420f538da..c18fc2fe20 100644 --- a/DesktopEditor/graphics/BooleanOperations.h +++ b/DesktopEditor/graphics/BooleanOperations.h @@ -108,7 +108,7 @@ namespace Aggplus { public: CBooleanOperations() {}; - CBooleanOperations(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op, long fillType, bool isLuminosity); + CBooleanOperations(const CGraphicsPath& path1, const CGraphicsPath& path2, BooleanOpType op, long fillType, bool isLuminosity, bool isSelf); ~CBooleanOperations(); CGraphicsPath&& GetResult(); bool IsSelfInters(const CGraphicsPath& p); @@ -166,6 +166,7 @@ namespace Aggplus bool Close1 = true; bool Close2 = true; bool IsLuminosity = false; + bool IsSelf = false; // c_nStroke, c_nWindingFillMode, c_nEvenOddFillMode long FillType = c_nWindingFillMode; From e15391ea35727368ddd46b55df2c5fc1ed130361 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Tue, 9 Dec 2025 16:43:05 +0600 Subject: [PATCH 061/125] fix bug #78958 --- .../XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp index 6b8014ff31..446086413d 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp @@ -153,7 +153,8 @@ const bool ATTACHEDLABEL::loadContent(BinProcessor& proc) proc.optional(); - proc.mandatory(); elements_.pop_back(); + if(proc.mandatory()) + elements_.pop_back(); return true; } From 44e217cf7c870f61d1fa4a8313b03a6d4ecfabbb Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 9 Dec 2025 15:53:54 +0300 Subject: [PATCH 062/125] Move AddPath to IRenderer --- DesktopEditor/graphics/GraphicsPath.cpp | 28 +++++++++++++++++++++ DesktopEditor/graphics/GraphicsRenderer.cpp | 28 --------------------- DesktopEditor/graphics/GraphicsRenderer.h | 2 -- DesktopEditor/graphics/IRenderer.h | 6 +---- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsPath.cpp b/DesktopEditor/graphics/GraphicsPath.cpp index 4f15063441..14ac2b159b 100644 --- a/DesktopEditor/graphics/GraphicsPath.cpp +++ b/DesktopEditor/graphics/GraphicsPath.cpp @@ -1515,3 +1515,31 @@ namespace Aggplus return false; } } + +HRESULT IRenderer::AddPath(const Aggplus::CGraphicsPath& path) +{ + if (path.GetPointCount() == 0) + return S_FALSE; + + unsigned length = path.GetPointCount() + path.GetCloseCount(); + auto points = path.GetPoints(0, length); + + for (unsigned i = 0; i < length; i++) + { + if (path.IsCurvePoint(i)) + { + PathCommandCurveTo(points[i].X, points[i].Y, + points[i + 1].X, points[i + 1].Y, + points[i + 2].X, points[i + 2].Y); + i += 2; + } + else if (path.IsMovePoint(i)) + PathCommandMoveTo(points[i].X, points[i].Y); + else if (path.IsLinePoint(i)) + PathCommandLineTo(points[i].X, points[i].Y); + else + PathCommandClose(); + } + + return S_OK; +} diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 25439758e9..934709d9bb 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -1170,34 +1170,6 @@ HRESULT CGraphicsRenderer::PathCommandTextEx(const std::wstring& bsUnicodeText, return PathCommandText(bsUnicodeText, x, y, w, h); } -HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path) -{ - if (path.GetPointCount() == 0) - return S_FALSE; - - size_t length = path.GetPointCount() + path.GetCloseCount(); - std::vector points = path.GetPoints(0, length); - - for (size_t i = 0; i < length; i++) - { - if (path.IsCurvePoint(i)) - { - PathCommandCurveTo(points[i].X, points[i].Y, - points[i + 1].X, points[i + 1].Y, - points[i + 2].X, points[i + 2].Y); - i += 2; - } - else if (path.IsMovePoint(i)) - PathCommandMoveTo(points[i].X, points[i].Y); - else if (path.IsLinePoint(i)) - PathCommandLineTo(points[i].X, points[i].Y); - else - PathCommandClose(); - } - - return S_OK; -} - //-------- Функции для вывода изображений --------------------------------------------------- HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) { diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index 2b3185bd5f..4366d5298d 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -243,8 +243,6 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h); virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h); - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path); - //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h); virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 1026c584cf..6bc4bf4a93 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -327,11 +327,7 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0; virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0; - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) - { - UNUSED_VARIABLE(path); - return S_OK; - } + HRESULT AddPath(const Aggplus::CGraphicsPath& path); //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0; From 81b4ba349353efccddd107bf2e1fc8db2c42f027 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 9 Dec 2025 16:28:15 +0300 Subject: [PATCH 063/125] Rollback --- DesktopEditor/graphics/GraphicsPath.cpp | 28 --------------------- DesktopEditor/graphics/GraphicsRenderer.cpp | 28 +++++++++++++++++++++ DesktopEditor/graphics/GraphicsRenderer.h | 2 ++ DesktopEditor/graphics/IRenderer.h | 6 ++++- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsPath.cpp b/DesktopEditor/graphics/GraphicsPath.cpp index 14ac2b159b..4f15063441 100644 --- a/DesktopEditor/graphics/GraphicsPath.cpp +++ b/DesktopEditor/graphics/GraphicsPath.cpp @@ -1515,31 +1515,3 @@ namespace Aggplus return false; } } - -HRESULT IRenderer::AddPath(const Aggplus::CGraphicsPath& path) -{ - if (path.GetPointCount() == 0) - return S_FALSE; - - unsigned length = path.GetPointCount() + path.GetCloseCount(); - auto points = path.GetPoints(0, length); - - for (unsigned i = 0; i < length; i++) - { - if (path.IsCurvePoint(i)) - { - PathCommandCurveTo(points[i].X, points[i].Y, - points[i + 1].X, points[i + 1].Y, - points[i + 2].X, points[i + 2].Y); - i += 2; - } - else if (path.IsMovePoint(i)) - PathCommandMoveTo(points[i].X, points[i].Y); - else if (path.IsLinePoint(i)) - PathCommandLineTo(points[i].X, points[i].Y); - else - PathCommandClose(); - } - - return S_OK; -} diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 934709d9bb..25439758e9 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -1170,6 +1170,34 @@ HRESULT CGraphicsRenderer::PathCommandTextEx(const std::wstring& bsUnicodeText, return PathCommandText(bsUnicodeText, x, y, w, h); } +HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path) +{ + if (path.GetPointCount() == 0) + return S_FALSE; + + size_t length = path.GetPointCount() + path.GetCloseCount(); + std::vector points = path.GetPoints(0, length); + + for (size_t i = 0; i < length; i++) + { + if (path.IsCurvePoint(i)) + { + PathCommandCurveTo(points[i].X, points[i].Y, + points[i + 1].X, points[i + 1].Y, + points[i + 2].X, points[i + 2].Y); + i += 2; + } + else if (path.IsMovePoint(i)) + PathCommandMoveTo(points[i].X, points[i].Y); + else if (path.IsLinePoint(i)) + PathCommandLineTo(points[i].X, points[i].Y); + else + PathCommandClose(); + } + + return S_OK; +} + //-------- Функции для вывода изображений --------------------------------------------------- HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) { diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index 4366d5298d..2b3185bd5f 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -243,6 +243,8 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h); virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h); + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path); + //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h); virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 6bc4bf4a93..1026c584cf 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -327,7 +327,11 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0; virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0; - HRESULT AddPath(const Aggplus::CGraphicsPath& path); + virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) + { + UNUSED_VARIABLE(path); + return S_OK; + } //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0; From d2527e5707c72b2a4eb712580f4c10d8f41b8e5f Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 9 Dec 2025 19:46:05 +0300 Subject: [PATCH 064/125] Fix stretch not rotate --- DesktopEditor/graphics/MetafileToRenderer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index f1974018f1..069a3acf88 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -750,7 +750,10 @@ namespace NSOnlineOfficeBinToPdf clipRect = Aggplus::RectF_T(left, top, width, height); if (isStretch) + { + clipRect.Offset(transMatrRot.tx() - old_t5, transMatrRot.ty() - old_t6); pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); + } } clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); From 39235f7fd6e3955b26dcb394d841bae21c9bb17e Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 11:10:22 +0300 Subject: [PATCH 065/125] Add ignoring meta-info in covertion and add bFontSubstitution --- DocxRenderer/DocxRenderer.cpp | 6 ++++ DocxRenderer/src/logic/Document.cpp | 1 + DocxRenderer/src/logic/Page.cpp | 16 ++++++++- DocxRenderer/src/logic/Page.h | 2 ++ DocxRenderer/src/logic/elements/ContText.cpp | 35 +++++++++++++------- DocxRenderer/src/logic/elements/ContText.h | 9 +++-- 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/DocxRenderer/DocxRenderer.cpp b/DocxRenderer/DocxRenderer.cpp index d6fa60366b..b9c4663c9f 100644 --- a/DocxRenderer/DocxRenderer.cpp +++ b/DocxRenderer/DocxRenderer.cpp @@ -144,6 +144,7 @@ std::vector CDocxRenderer::ScanPagePptx(IOfficeDrawingFile* pFile, m_pInternal->m_oDocument.Init(false); m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true; m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true; + m_pInternal->m_oDocument.m_oCurrentPage.m_bCollectMetaInfo = true; m_pInternal->m_bIsSupportShapeCommands = true; m_pInternal->m_eShapeSerializeType = ShapeSerializeType::sstXml; @@ -160,6 +161,7 @@ NSWasm::CData CDocxRenderer::ScanPageBin(IOfficeDrawingFile* pFile, size_t nPage m_pInternal->m_oDocument.Init(false); m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true; m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true; + m_pInternal->m_oDocument.m_oCurrentPage.m_bCollectMetaInfo = true; m_pInternal->m_bIsSupportShapeCommands = true; DrawPage(pFile, nPage); @@ -732,6 +734,10 @@ HRESULT CDocxRenderer::CommandLong(const LONG& lType, const LONG& lCommand) return S_OK; } + if (c_nFontSubstitution == lType) + { + m_pInternal->m_oDocument.m_oCurrentPage.m_bFontSubstitution = true; + } return S_OK; } HRESULT CDocxRenderer::CommandDouble(const LONG& lType, const double& dCommand) diff --git a/DocxRenderer/src/logic/Document.cpp b/DocxRenderer/src/logic/Document.cpp index ff3b0bf0df..36adda8b90 100644 --- a/DocxRenderer/src/logic/Document.cpp +++ b/DocxRenderer/src/logic/Document.cpp @@ -322,6 +322,7 @@ namespace NSDocxRenderer HRESULT CDocument::put_FontName(std::wstring sName) { m_oCurrentPage.m_oFont.Name = sName; + m_oCurrentPage.m_bFontSubstitution = false; return S_OK; } HRESULT CDocument::get_FontPath(std::wstring* sPath) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index 1aa33a4034..ee209d6f17 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -342,7 +342,21 @@ namespace NSDocxRenderer bForcedBold = true; m_oManagers.pParagraphStyleManager->UpdateAvgFontSize(m_oFont.Size); - m_oContBuilder.AddUnicode(top, baseline, left, right, m_oFont, m_oBrush, m_oManagers.pFontManager, oText, pGids, bForcedBold, m_bUseDefaultFont, m_bWriteStyleRaw); + m_oContBuilder.AddUnicode( + top, + baseline, + left, + right, + m_oFont, + m_oBrush, + m_oManagers.pFontManager, + oText, + pGids, + bForcedBold, + m_bUseDefaultFont, + m_bWriteStyleRaw, + m_bCollectMetaInfo + ); } void CPage::Analyze() diff --git a/DocxRenderer/src/logic/Page.h b/DocxRenderer/src/logic/Page.h index c425923f90..7b0f1a44e9 100644 --- a/DocxRenderer/src/logic/Page.h +++ b/DocxRenderer/src/logic/Page.h @@ -46,8 +46,10 @@ namespace NSDocxRenderer bool m_bIsGradient {false}; bool m_bUseDefaultFont {false}; bool m_bWriteStyleRaw {false}; + bool m_bCollectMetaInfo {false}; bool m_bIsBuildTables {false}; bool m_bIsLuminosityShapesFiled{false}; + bool m_bFontSubstitution {false}; CPage(NSFonts::IApplicationFonts* pAppFonts, const CManagers& oManagers); ~CPage(); diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 6fc76f9088..679b2936e7 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -564,6 +564,7 @@ namespace NSDocxRenderer origin_lefts += std::to_wstring(static_cast(l * c_dMMToEMU)) + L";"; oWriter.WriteBYTE(5); oWriter.WriteStringUtf16(origin_lefts); // Origin lefts + oWriter.WriteBYTE(6); oWriter.WriteBool(m_bFontSubstitution); // Origin lefts oWriter.WriteBYTE(kBin_g_nodeAttributeEnd); oWriter.EndRecord(); @@ -784,8 +785,8 @@ namespace NSDocxRenderer } void CContText::SetText(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths, - const std::vector& arGids, - const std::vector& arOriginLefts) + std::vector&& arGids, + std::vector&& arOriginLefts) { m_oText = oText; m_arSymWidths.clear(); @@ -797,8 +798,8 @@ namespace NSDocxRenderer } m_dRight = m_dLeft + m_dWidth; - m_arGids = arGids; - m_arOriginLefts = arOriginLefts; + m_arGids = std::move(arGids); + m_arOriginLefts = std::move(arOriginLefts); } void CContText::AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) @@ -1114,24 +1115,32 @@ namespace NSDocxRenderer const PUINT pGids, bool bForcedBold, bool bUseDefaultFont, - bool bWriteStyleRaw) + bool bWriteStyleRaw, + bool bCollectMetaInfo, + bool bFontSubstitution) { double dWidth = dRight - dLeft; double dHeight = dBot - dTop; std::vector gids; - for (size_t i = 0; i < oText.length(); ++i) + if (bCollectMetaInfo) + { + for (size_t i = 0; i < oText.length(); ++i) if (pGids) gids.push_back(pGids[i]); else gids.push_back(0); + } std::vector origin_lefts; - double curr_origin_left = dLeft; - for (size_t i = 0; i < oText.length(); ++i) + if (bCollectMetaInfo) { - origin_lefts.push_back(curr_origin_left); - curr_origin_left += dWidth / oText.length(); + double curr_origin_left = dLeft; + for (size_t i = 0; i < oText.length(); ++i) + { + origin_lefts.push_back(curr_origin_left); + curr_origin_left += dWidth / oText.length(); + } } // if new text is close to current cont @@ -1139,7 +1148,8 @@ namespace NSDocxRenderer fabs(m_pCurrCont->m_dBot - dBot) < c_dTHE_SAME_STRING_Y_PRECISION_MM && m_oPrevFont.IsEqual2(&oFont) && m_oPrevBrush.IsEqual(&oBrush) && !( - oText.length() == 1 && CContText::IsUnicodeDiacriticalMark(oText.at(0)))) + oText.length() == 1 && CContText::IsUnicodeDiacriticalMark(oText.at(0))) && + bFontSubstitution == m_pCurrCont->m_bFontSubstitution) { double avg_width = dWidth / oText.length(); @@ -1217,7 +1227,7 @@ namespace NSDocxRenderer ar_widths.push_back(avg_width); } - pCont->SetText(oText, ar_widths, gids, origin_lefts); + pCont->SetText(oText, ar_widths, std::move(gids), std::move(origin_lefts)); pCont->m_bIsRtl = CContText::IsUnicodeRtl(oText.at(0)); pCont->m_dWidth = dWidth; @@ -1249,6 +1259,7 @@ namespace NSDocxRenderer pCont->m_oSelectedFont.Italic = m_pFontSelector->IsSelectedItalic(); } pCont->m_bWriteStyleRaw = bWriteStyleRaw; + pCont->m_bFontSubstitution = bFontSubstitution; if (pCont->IsDiacritical()) { diff --git a/DocxRenderer/src/logic/elements/ContText.h b/DocxRenderer/src/logic/elements/ContText.h index 72480e46eb..59b33c9d95 100644 --- a/DocxRenderer/src/logic/elements/ContText.h +++ b/DocxRenderer/src/logic/elements/ContText.h @@ -80,6 +80,7 @@ namespace NSDocxRenderer std::vector m_arGids{}; std::vector m_arOriginLefts{}; + bool m_bFontSubstitution = false; CContText() = default; CContText(CFontManager* pManager) : m_pManager(pManager) {} @@ -106,8 +107,8 @@ namespace NSDocxRenderer const std::vector& arOriginLefts); void SetText(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths, - const std::vector& arGids, - const std::vector& arOriginLefts); + std::vector&& arGids, + std::vector&& arOriginLefts); void AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); void AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); @@ -188,7 +189,9 @@ namespace NSDocxRenderer const PUINT pGids = nullptr, bool bForcedBold = false, bool bUseDefaultFont = false, - bool bWriteStyleRaw = false); + bool bWriteStyleRaw = false, + bool bCollectMetaInfo = false, + bool bFontSubstitution = false); void NullCurrCont(); void Clear(); From 50b2656c4425309f56d3057835888a69bf6e1ca4 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 11:12:29 +0300 Subject: [PATCH 066/125] Change comment --- DocxRenderer/src/logic/elements/ContText.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 679b2936e7..e44c585663 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -524,6 +524,11 @@ namespace NSDocxRenderer oWriter.WriteString(origin_gids); oWriter.WriteString(L"\" />"); + oWriter.WriteString(L""); + oWriter.WriteString(L""); } void CContText::ToBin(NSWasm::CData& oWriter) const @@ -564,7 +569,7 @@ namespace NSDocxRenderer origin_lefts += std::to_wstring(static_cast(l * c_dMMToEMU)) + L";"; oWriter.WriteBYTE(5); oWriter.WriteStringUtf16(origin_lefts); // Origin lefts - oWriter.WriteBYTE(6); oWriter.WriteBool(m_bFontSubstitution); // Origin lefts + oWriter.WriteBYTE(6); oWriter.WriteBool(m_bFontSubstitution); // Font Substitution (just pass from pdf) oWriter.WriteBYTE(kBin_g_nodeAttributeEnd); oWriter.EndRecord(); From 11914f8dc2ceec90a1a02d0e8dc2257d726583cc Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 11:30:22 +0300 Subject: [PATCH 067/125] Fix non-collecting meta-info --- DocxRenderer/src/logic/elements/ContText.cpp | 60 ++++++++++++++------ DocxRenderer/src/logic/elements/ContText.h | 2 + 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index e44c585663..aaa78208e1 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -751,8 +751,10 @@ namespace NSDocxRenderer m_dWidth += w; m_oText += oText.at(i); - if (!arGids.empty()) + if (!arGids.empty() && m_bCollectMetaInfo) m_arGids.push_back(arGids[i]); + + if (!m_arOriginLefts.empty() && m_bCollectMetaInfo) m_arOriginLefts.push_back(arOriginLefts[i]); } m_dRight = m_dLeft + m_dWidth; @@ -776,17 +778,21 @@ namespace NSDocxRenderer m_dWidth += addtitional_width; m_dLeft = m_dRight - m_dWidth; - if (!arGids.empty()) + if (!arGids.empty() && m_bCollectMetaInfo) { auto ar_gids = m_arGids; m_arGids = arGids; for (auto& gid : ar_gids) m_arGids.push_back(gid); } - auto ar_lefts = m_arOriginLefts; - m_arOriginLefts = arOriginLefts; - for (auto& left : ar_lefts) - m_arOriginLefts.push_back(left); + + if (!arOriginLefts.empty() && m_bCollectMetaInfo) + { + auto ar_lefts = m_arOriginLefts; + m_arOriginLefts = arOriginLefts; + for (auto& left : ar_lefts) + m_arOriginLefts.push_back(left); + } } void CContText::SetText(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths, @@ -803,8 +809,11 @@ namespace NSDocxRenderer } m_dRight = m_dLeft + m_dWidth; - m_arGids = std::move(arGids); - m_arOriginLefts = std::move(arOriginLefts); + if (m_bCollectMetaInfo) + { + m_arGids = std::move(arGids); + m_arOriginLefts = std::move(arOriginLefts); + } } void CContText::AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) @@ -819,8 +828,11 @@ namespace NSDocxRenderer { m_arSymWidths.push_back(dWidth); m_oText += cSym; - m_arGids.push_back(nGid); - m_arOriginLefts.push_back(dLeft); + if (m_bCollectMetaInfo) + { + m_arGids.push_back(nGid); + m_arOriginLefts.push_back(dLeft); + } } m_dWidth += dWidth; m_dRight = m_dLeft + m_dWidth; @@ -836,8 +848,11 @@ namespace NSDocxRenderer m_dWidth = m_dRight - m_dLeft; m_arSymWidths.insert(m_arSymWidths.begin(), dWidth); - m_arGids.insert(m_arGids.begin(), nGid); - m_arOriginLefts.insert(m_arOriginLefts.begin(), dLeft); + if (m_bCollectMetaInfo) + { + m_arGids.insert(m_arGids.begin(), nGid); + m_arOriginLefts.insert(m_arOriginLefts.begin(), dLeft); + } } void CContText::SetSym(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) { @@ -851,11 +866,14 @@ namespace NSDocxRenderer m_arSymWidths.clear(); m_arSymWidths.push_back(dWidth); - m_arGids.clear(); - m_arGids.push_back(nGid); + if (m_bCollectMetaInfo) + { + m_arGids.clear(); + m_arGids.push_back(nGid); - m_arOriginLefts.clear(); - m_arOriginLefts.push_back(dLeft); + m_arOriginLefts.clear(); + m_arOriginLefts.push_back(dLeft); + } } void CContText::RemoveLastSym() { @@ -863,8 +881,13 @@ namespace NSDocxRenderer m_dWidth -= m_arSymWidths[m_arSymWidths.size() - 1]; m_dRight = m_dLeft + m_dWidth; m_arSymWidths.resize(m_arSymWidths.size() - 1); - m_arGids.resize(m_arGids.size() - 1); - m_arOriginLefts.resize(m_arOriginLefts.size() - 1); + + + if (!m_arGids.empty() && m_bCollectMetaInfo) + m_arGids.resize(m_arGids.size() - 1); + + if (!m_arOriginLefts.empty() && m_bCollectMetaInfo) + m_arOriginLefts.resize(m_arOriginLefts.size() - 1); } uint32_t CContText::GetLastSym() const { @@ -1265,6 +1288,7 @@ namespace NSDocxRenderer } pCont->m_bWriteStyleRaw = bWriteStyleRaw; pCont->m_bFontSubstitution = bFontSubstitution; + pCont->m_bCollectMetaInfo = bCollectMetaInfo; if (pCont->IsDiacritical()) { diff --git a/DocxRenderer/src/logic/elements/ContText.h b/DocxRenderer/src/logic/elements/ContText.h index 59b33c9d95..e95910d6bd 100644 --- a/DocxRenderer/src/logic/elements/ContText.h +++ b/DocxRenderer/src/logic/elements/ContText.h @@ -77,6 +77,7 @@ namespace NSDocxRenderer bool m_bIsAddBrEnd{false}; bool m_bWriteStyleRaw{false}; bool m_bPossibleHorSplit{false}; + bool m_bCollectMetaInfo{false}; std::vector m_arGids{}; std::vector m_arOriginLefts{}; @@ -113,6 +114,7 @@ namespace NSDocxRenderer void AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); void AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); void SetSym(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); + void RemoveLastSym(); uint32_t GetLastSym() const; From ad6113cf21eafce981aebdb517421c352438b25f Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 11:50:57 +0300 Subject: [PATCH 068/125] Fix bugs --- DocxRenderer/src/logic/Page.cpp | 10 ++- DocxRenderer/src/logic/elements/ContText.cpp | 62 +++++++++---------- DocxRenderer/src/logic/elements/ContText.h | 6 +- DocxRenderer/src/logic/elements/Paragraph.cpp | 2 +- DocxRenderer/src/logic/elements/TextLine.cpp | 8 +-- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index ee209d6f17..527792c9d0 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -1166,11 +1166,17 @@ namespace NSDocxRenderer if ((bIf1 && bIf6) || (bIf2 && bIf7) || (bIf4 && bIf8) || (bIf5 && bIf7)) { - cont->AddSymBack(d_sym->GetText().at(0), 0, d_sym->m_arGids.at(0), d_sym->m_arOriginLefts.at(0)); + if (m_bCollectMetaInfo) + cont->AddSymBack(d_sym->GetText().at(0), 0, d_sym->m_arOriginLefts.at(0), d_sym->m_arGids.at(0)); + else + cont->AddSymBack(d_sym->GetText().at(0), 0, d_sym->m_arOriginLefts.at(0)); } else if (bIf3 && bIf7) { - cont->AddSymFront(d_sym->GetText().at(0), 0, d_sym->m_arGids.at(0), d_sym->m_arOriginLefts.at(0)); + if (m_bCollectMetaInfo) + cont->AddSymFront(d_sym->GetText().at(0), 0, d_sym->m_arOriginLefts.at(0), d_sym->m_arGids.at(0)); + else + cont->AddSymFront(d_sym->GetText().at(0), 0, d_sym->m_arOriginLefts.at(0)); } isBreak = true; break; diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index aaa78208e1..138aba1014 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -91,6 +91,8 @@ namespace NSDocxRenderer for (size_t i = 0; i < rCont.m_arOriginLefts.size(); ++i) m_arOriginLefts[i] = rCont.m_arOriginLefts[i]; + m_bFontSubstitution = rCont.m_bFontSubstitution; + return *this; } @@ -147,7 +149,9 @@ namespace NSDocxRenderer { cont->m_arSymWidths.push_back(m_arSymWidths[i]); cont->m_arOriginLefts.push_back(m_arOriginLefts[i]); - cont->m_arGids.push_back(m_arGids[i]); + + if (!m_arGids.empty()) + cont->m_arGids.push_back(m_arGids[i]); } m_oText = m_oText.substr(0, index + 1); @@ -156,7 +160,9 @@ namespace NSDocxRenderer m_arSymWidths.resize(index + 1); m_arOriginLefts.resize(index + 1); - m_arGids.resize(index + 1); + + if (!m_arGids.empty()) + m_arGids.resize(index + 1); m_bPossibleHorSplit = false; @@ -750,12 +756,10 @@ namespace NSDocxRenderer m_arSymWidths.push_back(w); m_dWidth += w; m_oText += oText.at(i); + m_arOriginLefts.push_back(arOriginLefts[i]); if (!arGids.empty() && m_bCollectMetaInfo) m_arGids.push_back(arGids[i]); - - if (!m_arOriginLefts.empty() && m_bCollectMetaInfo) - m_arOriginLefts.push_back(arOriginLefts[i]); } m_dRight = m_dLeft + m_dWidth; } @@ -786,13 +790,10 @@ namespace NSDocxRenderer m_arGids.push_back(gid); } - if (!arOriginLefts.empty() && m_bCollectMetaInfo) - { - auto ar_lefts = m_arOriginLefts; - m_arOriginLefts = arOriginLefts; - for (auto& left : ar_lefts) - m_arOriginLefts.push_back(left); - } + auto ar_lefts = m_arOriginLefts; + m_arOriginLefts = arOriginLefts; + for (auto& left : ar_lefts) + m_arOriginLefts.push_back(left); } void CContText::SetText(const NSStringUtils::CStringUTF32& oText, const std::vector& arSymWidths, @@ -808,15 +809,13 @@ namespace NSDocxRenderer m_dWidth += w; } m_dRight = m_dLeft + m_dWidth; + m_arOriginLefts = std::move(arOriginLefts); if (m_bCollectMetaInfo) - { m_arGids = std::move(arGids); - m_arOriginLefts = std::move(arOriginLefts); - } } - void CContText::AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) + void CContText::AddSymBack(uint32_t cSym, double dWidth, double dLeft, unsigned int nGid) { bool is_space_twice = m_oText.at(m_oText.length() - 1) == c_SPACE_SYM && cSym == c_SPACE_SYM; @@ -828,16 +827,17 @@ namespace NSDocxRenderer { m_arSymWidths.push_back(dWidth); m_oText += cSym; + m_arOriginLefts.push_back(dLeft); + if (m_bCollectMetaInfo) { m_arGids.push_back(nGid); - m_arOriginLefts.push_back(dLeft); } } m_dWidth += dWidth; m_dRight = m_dLeft + m_dWidth; } - void CContText::AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) + void CContText::AddSymFront(uint32_t cSym, double dWidth, double dLeft, unsigned int nGid) { NSStringUtils::CStringUTF32 text; text += cSym; @@ -848,13 +848,13 @@ namespace NSDocxRenderer m_dWidth = m_dRight - m_dLeft; m_arSymWidths.insert(m_arSymWidths.begin(), dWidth); + m_arOriginLefts.insert(m_arOriginLefts.begin(), dLeft); if (m_bCollectMetaInfo) { m_arGids.insert(m_arGids.begin(), nGid); - m_arOriginLefts.insert(m_arOriginLefts.begin(), dLeft); } } - void CContText::SetSym(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft) + void CContText::SetSym(uint32_t cSym, double dWidth, double dLeft, unsigned int nGid) { m_oText = L""; m_oText += cSym; @@ -866,13 +866,13 @@ namespace NSDocxRenderer m_arSymWidths.clear(); m_arSymWidths.push_back(dWidth); + m_arOriginLefts.clear(); + m_arOriginLefts.push_back(dLeft); + if (m_bCollectMetaInfo) { m_arGids.clear(); m_arGids.push_back(nGid); - - m_arOriginLefts.clear(); - m_arOriginLefts.push_back(dLeft); } } void CContText::RemoveLastSym() @@ -881,13 +881,10 @@ namespace NSDocxRenderer m_dWidth -= m_arSymWidths[m_arSymWidths.size() - 1]; m_dRight = m_dLeft + m_dWidth; m_arSymWidths.resize(m_arSymWidths.size() - 1); - + m_arOriginLefts.resize(m_arOriginLefts.size() - 1); if (!m_arGids.empty() && m_bCollectMetaInfo) m_arGids.resize(m_arGids.size() - 1); - - if (!m_arOriginLefts.empty() && m_bCollectMetaInfo) - m_arOriginLefts.resize(m_arOriginLefts.size() - 1); } uint32_t CContText::GetLastSym() const { @@ -1161,14 +1158,11 @@ namespace NSDocxRenderer } std::vector origin_lefts; - if (bCollectMetaInfo) + double curr_origin_left = dLeft; + for (size_t i = 0; i < oText.length(); ++i) { - double curr_origin_left = dLeft; - for (size_t i = 0; i < oText.length(); ++i) - { - origin_lefts.push_back(curr_origin_left); - curr_origin_left += dWidth / oText.length(); - } + origin_lefts.push_back(curr_origin_left); + curr_origin_left += dWidth / oText.length(); } // if new text is close to current cont diff --git a/DocxRenderer/src/logic/elements/ContText.h b/DocxRenderer/src/logic/elements/ContText.h index e95910d6bd..0423bc86dd 100644 --- a/DocxRenderer/src/logic/elements/ContText.h +++ b/DocxRenderer/src/logic/elements/ContText.h @@ -111,9 +111,9 @@ namespace NSDocxRenderer std::vector&& arGids, std::vector&& arOriginLefts); - void AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); - void AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); - void SetSym(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft); + void AddSymBack(uint32_t cSym, double dWidth, double dLeft, unsigned int nGid = 0); + void AddSymFront(uint32_t cSym, double dWidth, double dLeft, unsigned int nGid = 0); + void SetSym(uint32_t cSym, double dWidth, double dLeft, unsigned int nGid = 0); void RemoveLastSym(); diff --git a/DocxRenderer/src/logic/elements/Paragraph.cpp b/DocxRenderer/src/logic/elements/Paragraph.cpp index ccf1b493f2..0f4476d2f9 100644 --- a/DocxRenderer/src/logic/elements/Paragraph.cpp +++ b/DocxRenderer/src/logic/elements/Paragraph.cpp @@ -313,7 +313,7 @@ namespace NSDocxRenderer auto last_sym = text[text.length() - 1]; if (last_sym != c_SPACE_SYM && m_arTextLines.size() != 1) - pLastCont->AddSymBack(c_SPACE_SYM, 0, 0, pLastCont->m_dRight); + pLastCont->AddSymBack(c_SPACE_SYM, 0, pLastCont->m_dRight, 0); } } } diff --git a/DocxRenderer/src/logic/elements/TextLine.cpp b/DocxRenderer/src/logic/elements/TextLine.cpp index dca9967e74..eee3568ce9 100644 --- a/DocxRenderer/src/logic/elements/TextLine.cpp +++ b/DocxRenderer/src/logic/elements/TextLine.cpp @@ -112,7 +112,7 @@ namespace NSDocxRenderer wide_space->m_dHeight = pCurrent->m_dHeight; - wide_space->SetSym(c_SPACE_SYM, wide_space->m_dRight - wide_space->m_dLeft, 0, wide_space->m_dLeft); + wide_space->SetSym(c_SPACE_SYM, wide_space->m_dRight - wide_space->m_dLeft, wide_space->m_dLeft, 0); wide_space->m_pFontStyle = pFirst->m_pFontStyle; wide_space->m_pShape = nullptr; wide_space->m_iNumDuplicates = 0; @@ -150,7 +150,7 @@ namespace NSDocxRenderer } else { - pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, 0, pFirst->m_dRight); + pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, pFirst->m_dRight, 0); pFirst->AddTextBack(pCurrent->GetText(), pCurrent->GetSymWidths(), pCurrent->m_arGids, pCurrent->m_arOriginLefts); } @@ -166,9 +166,9 @@ namespace NSDocxRenderer if (bIsSpaceDelta) { if (pFirst->GetNumberOfFeatures() <= pCurrent->GetNumberOfFeatures()) - pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, 0, pFirst->m_dRight); + pFirst->AddSymBack(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, pFirst->m_dRight, 0); else - pCurrent->AddSymFront(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, 0, pFirst->m_dRight); + pCurrent->AddSymFront(c_SPACE_SYM, pCurrent->m_dLeft - pFirst->m_dRight, pFirst->m_dRight, 0); } pFirst = pCurrent; } From fb8a72cd6b9852d5d09ce736e02ab7f9f6501b3f Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Wed, 10 Dec 2025 15:01:52 +0600 Subject: [PATCH 069/125] fix bug #54521 --- Common/3dParty/pole/pole.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/3dParty/pole/pole.h b/Common/3dParty/pole/pole.h index 742ce61889..41102099bd 100644 --- a/Common/3dParty/pole/pole.h +++ b/Common/3dParty/pole/pole.h @@ -90,7 +90,7 @@ static std::wstring convertUtf16ToWString(const UTF16 * Data, int nLength) return std::wstring(); } - std::wstring wstr ((wchar_t *) pStrUtf32); + std::wstring wstr ((wchar_t *) pStrUtf32, nLength); delete [] pStrUtf32; return wstr; From e815f39905c7106a562f370743779b364afa6541 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 12:04:57 +0300 Subject: [PATCH 070/125] Fix bug --- DocxRenderer/src/logic/elements/ContText.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 138aba1014..1bd13c2477 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -150,7 +150,7 @@ namespace NSDocxRenderer cont->m_arSymWidths.push_back(m_arSymWidths[i]); cont->m_arOriginLefts.push_back(m_arOriginLefts[i]); - if (!m_arGids.empty()) + if (!m_arGids.empty() && cont->m_bCollectMetaInfo) cont->m_arGids.push_back(m_arGids[i]); } @@ -1249,6 +1249,7 @@ namespace NSDocxRenderer ar_widths.push_back(avg_width); } + pCont->m_bCollectMetaInfo = bCollectMetaInfo; pCont->SetText(oText, ar_widths, std::move(gids), std::move(origin_lefts)); pCont->m_bIsRtl = CContText::IsUnicodeRtl(oText.at(0)); @@ -1282,7 +1283,6 @@ namespace NSDocxRenderer } pCont->m_bWriteStyleRaw = bWriteStyleRaw; pCont->m_bFontSubstitution = bFontSubstitution; - pCont->m_bCollectMetaInfo = bCollectMetaInfo; if (pCont->IsDiacritical()) { From fa46455e7408d38ac173356cdfe8274d663c0b80 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 10 Dec 2025 12:19:26 +0300 Subject: [PATCH 071/125] Fix Opt radiobutton at child --- .../graphics/pro/js/wasm/js/drawingfile.js | 14 +++++ .../pro/js/wasm/src/drawingfile_test.cpp | 17 ++++++ PdfFile/SrcReader/PdfAnnot.cpp | 58 ++++++++++++++++++- PdfFile/SrcReader/PdfAnnot.h | 1 + 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index 2df9f95163..e28f4428de 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -1206,6 +1206,20 @@ function readWidgetType(reader, rec, readDoubleFunc, readDouble2Func, readString rec["value"] = readStringFunc.call(reader); // 0 - check, 1 - cross, 2 - diamond, 3 - circle, 4 - star, 5 - square rec["style"] = reader.readByte(); + if (flags & (1 << 10)) + { + let n = reader.readInt(); + rec["opt"] = []; + for (let i = 0; i < n; ++i) + { + let opt1 = readStringFunc.call(reader); + let opt2 = readStringFunc.call(reader); + if (opt1 == "") + rec["opt"].push(opt2); + else + rec["opt"].push([opt2, opt1]); + } + } if (flags & (1 << 14)) rec["ExportValue"] = readStringFunc.call(reader); // 12.7.4.2.1 diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 9b4a07b927..4fd1bcf237 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -704,6 +704,23 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i) i += 1; std::cout << "Style " << arrStyle[nPathLength] << ", "; + if (nFlags & (1 << 10)) + { + int nOptLength = READ_INT(pWidgets + i); + i += 4; + for (int j = 0; j < nOptLength; ++j) + { + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << std::to_string(j) << " Opt1 " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + i += nPathLength; + + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << std::to_string(j) << " Opt2 " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + i += nPathLength; + } + } if (nFlags & (1 << 14)) { nPathLength = READ_INT(pWidgets + i); diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 788dec0b90..10f39ceeb7 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -1164,8 +1164,54 @@ CAnnotWidgetBtn::CAnnotWidgetBtn(PDFDoc* pdfDoc, AcroFormField* pField, int nSta } oObj.free(); - Object oMK; AcroFormFieldType oType = pField->getAcroFormFieldType(); + Object oOpt; + // 10 - Список значений + if (oType != acroFormFieldPushbutton && oField.dictLookup("Opt", &oOpt)->isArray()) + { + m_unFlags |= (1 << 10); + int nOptLength = oOpt.arrayGetLength(); + for (int j = 0; j < nOptLength; ++j) + { + Object oOptJ; + if (!oOpt.arrayGet(j, &oOptJ) || !(oOptJ.isString() || oOptJ.isArray())) + { + oOptJ.free(); + continue; + } + + std::string sOpt1, sOpt2; + if (oOptJ.isArray() && oOptJ.arrayGetLength() > 1) + { + Object oOptJ2; + if (oOptJ.arrayGet(0, &oOptJ2)->isString()) + { + TextString* s = new TextString(oOptJ2.getString()); + sOpt1 = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()); + delete s; + } + oOptJ2.free(); + if (oOptJ.arrayGet(1, &oOptJ2)->isString()) + { + TextString* s = new TextString(oOptJ2.getString()); + sOpt2 = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()); + delete s; + } + oOptJ2.free(); + } + else if (oOptJ.isString()) + { + TextString* s = new TextString(oOptJ.getString()); + sOpt2 = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()); + delete s; + } + m_arrOpt.push_back(std::make_pair(sOpt1, sOpt2)); + oOptJ.free(); + } + } + oOpt.free(); + + Object oMK; m_nStyle = (oType == acroFormFieldRadioButton ? 3 : 0); if (pField->fieldLookup("MK", &oMK)->isDict()) { @@ -1255,7 +1301,6 @@ CAnnotWidgetBtn::CAnnotWidgetBtn(PDFDoc* pdfDoc, AcroFormField* pField, int nSta } oMK.free(); - Object oOpt; pField->fieldLookup("Opt", &oOpt); // 14 - Имя вкл состояния - AP - N - Yes @@ -4386,6 +4431,15 @@ void CAnnotWidgetBtn::ToWASM(NSWasm::CData& oRes) else { oRes.WriteBYTE(m_nStyle); + if (m_unFlags & (1 << 10)) + { + oRes.AddInt(m_arrOpt.size()); + for (int i = 0; i < m_arrOpt.size(); ++i) + { + oRes.WriteString(m_arrOpt[i].first); + oRes.WriteString(m_arrOpt[i].second); + } + } if (m_unFlags & (1 << 14)) oRes.WriteString(m_sAP_N_Yes); } diff --git a/PdfFile/SrcReader/PdfAnnot.h b/PdfFile/SrcReader/PdfAnnot.h index 539fc8eeed..4a9e567b6c 100644 --- a/PdfFile/SrcReader/PdfAnnot.h +++ b/PdfFile/SrcReader/PdfAnnot.h @@ -280,6 +280,7 @@ private: std::string m_sAC; std::string m_sAP_N_Yes; double m_dA1, m_dA2; + std::vector< std::pair > m_arrOpt; }; class CAnnotWidgetTx final : public CAnnotWidget From 9fedabc0e25a06e9e401249de2e0f748f51dd411 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 10 Dec 2025 12:46:52 +0300 Subject: [PATCH 072/125] Fix write Opt radiobutton at child --- .../graphics/commands/AnnotField.cpp | 12 +++++++ DesktopEditor/graphics/commands/AnnotField.h | 2 ++ PdfFile/PdfWriter.cpp | 2 ++ PdfFile/SrcWriter/Annotation.cpp | 34 +++++++++++++++++++ PdfFile/SrcWriter/Annotation.h | 1 + 5 files changed, 51 insertions(+) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index 07e56aff32..73fdf8881a 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -1042,6 +1042,7 @@ const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetCA() { const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetRC() { return m_wsRC; } const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetAC() { return m_wsAC; } const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetAP_N_Yes() { return m_wsAP_N_Yes; } +const std::vector< std::pair >& CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::GetOpt() { return m_arrOpt; } void CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType, int nFlags) { if (nType == 27) @@ -1082,6 +1083,17 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::Read(NSOnlineOfficeBinToP if (nFlags & (1 << 9)) m_wsV = pReader->ReadString(); m_nStyle = pReader->ReadByte(); + if (nFlags & (1 << 10)) + { + int n = pReader->ReadInt(); + m_arrOpt.reserve(n); + for (int i = 0; i < n; ++i) + { + std::wstring s1 = pReader->ReadString(); + std::wstring s2 = pReader->ReadString(); + m_arrOpt.push_back(std::make_pair(s1, s2)); + } + } if (nFlags & (1 << 14)) m_wsAP_N_Yes = pReader->ReadString(); } diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index 0c2e83bd09..ee74ea2d5f 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -107,6 +107,7 @@ public: const std::wstring& GetRC(); const std::wstring& GetAC(); const std::wstring& GetAP_N_Yes(); + const std::vector< std::pair >& GetOpt(); void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType, int nFlags); @@ -125,6 +126,7 @@ public: std::wstring m_wsRC; std::wstring m_wsAC; std::wstring m_wsAP_N_Yes; + std::vector< std::pair > m_arrOpt; }; class GRAPHICS_DECL CTextWidgetPr diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index ceddd132d6..442a5587e4 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -2503,6 +2503,8 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF else pButtonWidget->Off(); } + if (nFlags & (1 << 10)) + pButtonWidget->SetOpt(pPrB->GetOpt()); } } else if (oInfo.IsTextWidget()) diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index cb71cf244b..449f1f186d 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -2272,6 +2272,40 @@ namespace PdfWriter sDA += "\012"; return sDA; } + void CCheckBoxWidget::SetOpt(const std::vector< std::pair >& arrOpt) + { + if (arrOpt.empty()) + return; + + CArrayObject* pArray = new CArrayObject(); + if (!pArray) + return; + + CDictObject* pOwner = GetObjOwnValue("Opt"); + if (!pOwner) + pOwner = this; + pOwner->Add("Opt", pArray); + + for (const std::pair& PV : arrOpt) + { + if (PV.first.empty()) + { + std::string sValue = U_TO_UTF8(PV.second); + pArray->Add(new CStringObject(sValue.c_str(), true)); + } + else + { + CArrayObject* pArray2 = new CArrayObject(); + pArray->Add(pArray2); + + std::string sValue = U_TO_UTF8(PV.first); + pArray2->Add(new CStringObject(sValue.c_str(), true)); + + sValue = U_TO_UTF8(PV.second); + pArray2->Add(new CStringObject(sValue.c_str(), true)); + } + } + } //---------------------------------------------------------------------------------------- // CTextWidget //---------------------------------------------------------------------------------------- diff --git a/PdfFile/SrcWriter/Annotation.h b/PdfFile/SrcWriter/Annotation.h index aa3640171d..0b281c65af 100644 --- a/PdfFile/SrcWriter/Annotation.h +++ b/PdfFile/SrcWriter/Annotation.h @@ -555,6 +555,7 @@ namespace PdfWriter CCheckBoxWidget(CXref* pXref, EWidgetType nSubtype = WidgetCheckbox); void SetV(const std::wstring& wsV); + void SetOpt(const std::vector< std::pair >& arrOpt); void SetStyle(BYTE nStyle); ECheckBoxStyle GetStyle() { return m_nStyle; } void SetAP_N_Yes(const std::wstring& wsAP_N_Yes); From 7ecab52601f1680910fdf1b80899019b9564998e Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 12:54:01 +0300 Subject: [PATCH 073/125] Add Ascent/Descent bot and top in shape form --- DocxRenderer/src/logic/Page.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index 527792c9d0..b13ae5ce46 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -1606,8 +1606,8 @@ namespace NSDocxRenderer // lamda to setup and add paragpraph auto add_paragraph = [this, &max_right, &min_left, &ar_paragraphs] (paragraph_ptr_t& paragraph) { - paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBot; - paragraph->m_dTop = paragraph->m_arTextLines.front()->m_dTop; + paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBotWithMaxDescent; + paragraph->m_dTop = paragraph->m_arTextLines.front()->m_dTopWithMaxAscent; paragraph->m_dRight = max_right; paragraph->m_dLeft = min_left; @@ -2539,8 +2539,8 @@ namespace NSDocxRenderer pParagraph->m_arTextLines.push_back(pLine); pParagraph->m_dLeft = pLine->m_dLeft; - pParagraph->m_dTop = pLine->m_dTop; - pParagraph->m_dBot = pLine->m_dBot; + pParagraph->m_dTop = pLine->m_dTopWithMaxAscent; + pParagraph->m_dBot = pLine->m_dBotWithMaxDescent; pParagraph->m_dWidth = pLine->m_dWidth; pParagraph->m_dHeight = pLine->m_dHeight; pParagraph->m_dRight = pLine->m_dRight; From 10ab7009a1ddfa23216e6de94be5bbc5ccbdc9fa Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 10 Dec 2025 15:23:22 +0300 Subject: [PATCH 074/125] Refactoring --- Common/3dParty/html/css/CssCalculator.pri | 2 + .../3dParty/html/css/src/StyleProperties.cpp | 28 +++++------ Common/3dParty/html/css/src/StyleProperties.h | 49 +++++++++++++------ 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/Common/3dParty/html/css/CssCalculator.pri b/Common/3dParty/html/css/CssCalculator.pri index 2bad0cf3ae..abf5419853 100644 --- a/Common/3dParty/html/css/CssCalculator.pri +++ b/Common/3dParty/html/css/CssCalculator.pri @@ -3,6 +3,8 @@ DEPENDPATH += $$PWD CORE_ROOT_DIR = $$PWD/../../../.. +include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri) + css_calculator_without_xhtml { HEADERS += \ $$PWD/src/CCssCalculator_Private.h \ diff --git a/Common/3dParty/html/css/src/StyleProperties.cpp b/Common/3dParty/html/css/src/StyleProperties.cpp index d3851e389b..b6446d04d1 100644 --- a/Common/3dParty/html/css/src/StyleProperties.cpp +++ b/Common/3dParty/html/css/src/StyleProperties.cpp @@ -483,7 +483,7 @@ namespace NSCSS } CColorValue::CColorValue() - : m_eType(EColorType::ColorNone), m_oValue(std::monostate()) + : m_eType(EColorType::ColorNone) {} CColorValue::CColorValue(const CColorValue& oValue) @@ -606,7 +606,7 @@ namespace NSCSS void CColor::SetNone() { Clear(); - m_oValue = CColorValue(); + m_oValue.reset(); } char NormalizeNegativeColorValue(INT nValue) @@ -761,9 +761,9 @@ namespace NSCSS switch(m_oValue->GetType()) { case ColorRGB: - return std::get(m_oValue->m_oValue).ToInt(); + return boost::variant2::get(m_oValue->m_oValue).ToInt(); case ColorHEX: - return ConvertHEXtoRGB(std::get(m_oValue->m_oValue)).ToInt(); + return ConvertHEXtoRGB(boost::variant2::get(m_oValue->m_oValue)).ToInt(); default: return 0; } @@ -781,9 +781,9 @@ namespace NSCSS switch(m_oValue->GetType()) { - case ColorRGB: return ConvertRGBtoHEX(std::get(m_oValue->m_oValue)); - case ColorHEX: return std::get(m_oValue->m_oValue); - case ColorUrl: return std::get(m_oValue->m_oValue).GetValue(); + case ColorRGB: return ConvertRGBtoHEX(boost::variant2::get(m_oValue->m_oValue)); + case ColorHEX: return boost::variant2::get(m_oValue->m_oValue); + case ColorUrl: return boost::variant2::get(m_oValue->m_oValue).GetValue(); default: return std::wstring(); } } @@ -796,9 +796,9 @@ namespace NSCSS switch(m_oValue->GetType()) { case ColorRGB: - return ConvertRGBtoHEX(std::get(m_oValue->m_oValue)); + return ConvertRGBtoHEX(boost::variant2::get(m_oValue->m_oValue)); case ColorHEX: - return std::get(m_oValue->m_oValue); + return boost::variant2::get(m_oValue->m_oValue); default: return std::wstring(); } @@ -813,8 +813,8 @@ namespace NSCSS switch(m_oValue->GetType()) { - case ColorRGB: oCurrentColor = std::get(m_oValue->m_oValue); break; - case ColorHEX: oCurrentColor = ConvertHEXtoRGB(std::get(m_oValue->m_oValue)); break; + case ColorRGB: oCurrentColor = boost::variant2::get(m_oValue->m_oValue); break; + case ColorHEX: oCurrentColor = ConvertHEXtoRGB(boost::variant2::get(m_oValue->m_oValue)); break; default: return L"none"; } @@ -843,8 +843,8 @@ namespace NSCSS switch(m_oValue->GetType()) { - case ColorRGB: return std::get(m_oValue->m_oValue); - case ColorHEX: return ConvertHEXtoRGB(std::get(m_oValue->m_oValue)); + case ColorRGB: return boost::variant2::get(m_oValue->m_oValue); + case ColorHEX: return ConvertHEXtoRGB(boost::variant2::get(m_oValue->m_oValue)); default: return TRGB(); } } @@ -1390,7 +1390,7 @@ namespace NSCSS m_oHAlign == oDisplay.m_oHAlign && m_oVAlign == oDisplay.m_oVAlign && m_oDisplay == oDisplay.m_oDisplay && - m_eWhiteSpace == oDisplay.m_eWhiteSpace.ToInt(); + m_eWhiteSpace == oDisplay.m_eWhiteSpace; } // STROKE diff --git a/Common/3dParty/html/css/src/StyleProperties.h b/Common/3dParty/html/css/src/StyleProperties.h index 661752d877..3aa98429ea 100644 --- a/Common/3dParty/html/css/src/StyleProperties.h +++ b/Common/3dParty/html/css/src/StyleProperties.h @@ -2,14 +2,16 @@ #define STYLEPROPERTIES_H #include -#include #include -#include #include #include "../../../../DesktopEditor/graphics/Matrix.h" #include "CUnitMeasureConverter.h" +#include +#include "boost/blank.hpp" +#include + namespace NSCSS { namespace NSProperties @@ -64,6 +66,23 @@ namespace NSCSS return oFirstValue.m_unLevel == oSecondValue.m_unLevel; } + friend bool operator==(const CValueBase& oLeftValue, const CValueBase& oRightValue) + { + if (oLeftValue.Empty() && oRightValue.Empty()) + return true; + + if (( oLeftValue.Empty() && !oRightValue.Empty()) || + (!oLeftValue.Empty() && oRightValue.Empty())) + return false; + + return oLeftValue.m_oValue == oRightValue.m_oValue; + } + + friend bool operator!=(const CValueBase& oLeftValue, const CValueBase& oRightValue) + { + return !(oLeftValue == oRightValue); + } + bool operator==(const T& oValue) const { return m_oValue == oValue; @@ -92,28 +111,18 @@ namespace NSCSS return *this; } - - virtual bool operator==(const CValueBase& oValue) const - { - return m_oValue == oValue.m_oValue; - } - - virtual bool operator!=(const CValueBase& oValue) const - { - return !(*this == oValue); - } }; template - class CValueOptional : public CValueBase> + class CValueOptional : public CValueBase> { protected: CValueOptional() - : CValueBase>() + : CValueBase>() {} CValueOptional(const T& oValue, unsigned int unLevel, bool bImportant) - : CValueBase>(oValue, unLevel, bImportant) + : CValueBase>(oValue, unLevel, bImportant) {} public: @@ -127,6 +136,14 @@ namespace NSCSS this->m_unLevel = 0; this->m_bImportant = false; } + + bool operator==(const T& oValue) const + { + if (!this->m_oValue.has_value()) + return false; + + return this->m_oValue.value() == oValue; + } }; class CString : public CValueOptional @@ -245,7 +262,7 @@ namespace NSCSS class CColorValue { - using color_value = std::variant; + using color_value = boost::variant2::variant; protected: EColorType m_eType; public: From 47258d9c30448dc0b3f0f47a375cdfa61dd2a262 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 10 Dec 2025 15:23:29 +0300 Subject: [PATCH 075/125] Fix typo --- OFDFile/src/Utils/Utils.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/OFDFile/src/Utils/Utils.h b/OFDFile/src/Utils/Utils.h index 4d5b74eca5..5ca390ca04 100644 --- a/OFDFile/src/Utils/Utils.h +++ b/OFDFile/src/Utils/Utils.h @@ -147,8 +147,6 @@ inline std::wstring CombinePaths(const std::wstring& wsFirstPath, const std::wst inline bool GetStatusUsingExternalLocalFiles() { - return false; - if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP)) return NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP); From cec10b705800380bdddf5d130c5545d954002451 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Wed, 10 Dec 2025 15:58:50 +0300 Subject: [PATCH 076/125] Fix problem with shape top and height --- DocxRenderer/src/logic/Page.cpp | 5 +++-- DocxRenderer/src/logic/elements/ContText.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index b13ae5ce46..82aee2ab1b 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -1606,7 +1606,8 @@ namespace NSDocxRenderer // lamda to setup and add paragpraph auto add_paragraph = [this, &max_right, &min_left, &ar_paragraphs] (paragraph_ptr_t& paragraph) { - paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBotWithMaxDescent; + double additional_bottom = m_arTextLines.front()->m_dTopWithMaxAscent - m_arTextLines.front()->m_dTop; + paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBot + additional_bottom; paragraph->m_dTop = paragraph->m_arTextLines.front()->m_dTopWithMaxAscent; paragraph->m_dRight = max_right; paragraph->m_dLeft = min_left; @@ -2540,7 +2541,7 @@ namespace NSDocxRenderer pParagraph->m_arTextLines.push_back(pLine); pParagraph->m_dLeft = pLine->m_dLeft; pParagraph->m_dTop = pLine->m_dTopWithMaxAscent; - pParagraph->m_dBot = pLine->m_dBotWithMaxDescent; + pParagraph->m_dBot = pLine->m_dBot + (pLine->m_dTopWithMaxAscent - pLine->m_dTop); pParagraph->m_dWidth = pLine->m_dWidth; pParagraph->m_dHeight = pLine->m_dHeight; pParagraph->m_dRight = pLine->m_dRight; diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 1bd13c2477..139f07a022 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -1260,8 +1260,8 @@ namespace NSDocxRenderer double em_height = oMetrics.dEmHeight; double ratio = font_size / em_height * c_dPtToMM; - pCont->m_dTopWithAscent = pCont->m_dBot - (oMetrics.dAscent * ratio) - oMetrics.dBaselineOffset; - pCont->m_dBotWithDescent = pCont->m_dBot + (oMetrics.dDescent * ratio) - oMetrics.dBaselineOffset; + pCont->m_dTopWithAscent = pCont->m_dBot - (oMetrics.dAscent * ratio); + pCont->m_dBotWithDescent = pCont->m_dBot + (oMetrics.dDescent * ratio); pCont->m_dSpaceWidthMM = pFontManager->GetSpaceWidthMM(); pCont->m_wsOriginFontName = oFont.Name; From 05d7d88481f220ab6727dd6a162c80360420a0ca Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Wed, 10 Dec 2025 17:17:51 +0400 Subject: [PATCH 077/125] Add logs during snapshot creation --- DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp | 10 ++++++++-- DesktopEditor/doctrenderer/js_internal/v8/v8_base.h | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp index bacd5dedac..a5c6dc5527 100644 --- a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp +++ b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp @@ -461,6 +461,8 @@ namespace NSJSBase v8::SnapshotCreator snapshotCreator; v8::Isolate* isolate = snapshotCreator.GetIsolate(); { + CV8TryCatch try_catch(isolate); + v8::HandleScope handle_scope(isolate); // Create a new context v8::Local context = v8::Context::New(isolate); @@ -472,11 +474,15 @@ namespace NSJSBase global->Set(context, v8::String::NewFromUtf8Literal(isolate, "self"), global).Check(); global->Set(context, v8::String::NewFromUtf8Literal(isolate, "native"), v8::Undefined(isolate)).Check(); - // Compile and run + LOGD("compiling and running snapshot code..."); + // Compile v8::Local source = v8::String::NewFromUtf8(isolate, script.c_str()).ToLocalChecked(); v8::Local script = v8::Script::Compile(context, source).ToLocalChecked(); - + LOGD("compile status: %d", try_catch.Check()); + // Run script->Run(context).IsEmpty(); + LOGD("run status: %d", try_catch.Check()); + snapshotCreator.SetDefaultContext(context); } v8::StartupData data = snapshotCreator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep); diff --git a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h index f6a424bca6..367904b2e2 100644 --- a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h +++ b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.h @@ -62,7 +62,13 @@ v8::Local CreateV8String(v8::Isolate* i, const std::string& str); #include #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, "js", __VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "js", __VA_ARGS__) -#endif +#ifdef _DEBUG +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "js", __VA_ARGS__) +#else +// should be disabled for release builds +#define LOGD(...) +#endif // _DEBUG +#endif // ANDROID_LOGS #endif @@ -799,6 +805,9 @@ namespace NSJSBase CV8TryCatch() : CJSTryCatch(), try_catch(V8IsolateOneArg) { } + CV8TryCatch(v8::Isolate* isolate) : CJSTryCatch(), try_catch(isolate) + { + } virtual ~CV8TryCatch() { } From d0dfd6737c847578d8ba0fc3f887ee3924c91c4d Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Wed, 10 Dec 2025 16:50:43 +0300 Subject: [PATCH 078/125] [x2t] Add m_sSigningKeyStorePath to params.xml and SIGNING_KEYSTORE_PASSPHRASE to env for pdf --- DesktopEditor/common/SystemUtils.h | 1 + X2tConverter/src/cextracttools.h | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/DesktopEditor/common/SystemUtils.h b/DesktopEditor/common/SystemUtils.h index 8cf6e66207..e88b8c4e34 100644 --- a/DesktopEditor/common/SystemUtils.h +++ b/DesktopEditor/common/SystemUtils.h @@ -60,6 +60,7 @@ namespace NSSystemUtils static const wchar_t* gc_EnvModified = L"MODIFIED"; static const wchar_t* gc_EnvMemoryLimit = L"X2T_MEMORY_LIMIT"; static const wchar_t* gc_EnvMemoryLimitDefault = L"4GiB"; + static const wchar_t* gc_EnvSigningKeystorePassphrase = L"SIGNING_KEYSTORE_PASSPHRASE"; KERNEL_DECL std::string GetEnvVariableA(const std::wstring& strName); KERNEL_DECL std::wstring GetEnvVariable(const std::wstring& strName); diff --git a/X2tConverter/src/cextracttools.h b/X2tConverter/src/cextracttools.h index 299803d933..a759dab285 100644 --- a/X2tConverter/src/cextracttools.h +++ b/X2tConverter/src/cextracttools.h @@ -525,6 +525,7 @@ namespace NExtractTools boost::unordered_map> m_mapInputLimits; bool* m_bIsPDFA; std::wstring* m_sConvertToOrigin; + std::wstring* m_sSigningKeyStorePath; // output params mutable bool m_bOutputConvertCorrupted; mutable bool m_bMacro; @@ -561,6 +562,7 @@ namespace NExtractTools m_bIsNoBase64 = NULL; m_bIsPDFA = NULL; m_sConvertToOrigin = NULL; + m_sSigningKeyStorePath = NULL; m_bOutputConvertCorrupted = false; m_bMacro = false; @@ -596,6 +598,7 @@ namespace NExtractTools RELEASEOBJECT(m_bIsNoBase64); RELEASEOBJECT(m_bIsPDFA); RELEASEOBJECT(m_sConvertToOrigin); + RELEASEOBJECT(m_sSigningKeyStorePath); } bool FromXmlFile(const std::wstring& sFilename) @@ -794,6 +797,11 @@ namespace NExtractTools RELEASEOBJECT(m_sConvertToOrigin); m_sConvertToOrigin = new std::wstring(sValue); } + else if (_T("m_sSigningKeyStorePath") == sName) + { + RELEASEOBJECT(m_sSigningKeyStorePath); + m_sSigningKeyStorePath = new std::wstring(sValue); + } } else if (_T("m_nCsvDelimiterChar") == sName) { @@ -882,6 +890,10 @@ namespace NExtractTools { return (NULL != m_sConvertToOrigin) ? (*m_sConvertToOrigin) : L""; } + std::wstring getSigningKeyStorePath() const + { + return (NULL != m_sSigningKeyStorePath) ? (*m_sSigningKeyStorePath) : L""; + } bool needConvertToOrigin(long nFormatFrom) const { COfficeFileFormatChecker FileFormatChecker; From d74899a11624e008a608352f5a96d87bd305c0ff Mon Sep 17 00:00:00 2001 From: Daria Ermakova Date: Wed, 10 Dec 2025 18:08:20 +0300 Subject: [PATCH 079/125] Fix bug 79005 --- RtfFile/Format/RtfProperty.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/RtfFile/Format/RtfProperty.cpp b/RtfFile/Format/RtfProperty.cpp index 85eb810cea..cbe266f97d 100644 --- a/RtfFile/Format/RtfProperty.cpp +++ b/RtfFile/Format/RtfProperty.cpp @@ -1038,7 +1038,13 @@ std::wstring RtfShading::RenderToOOX(RenderParameter oRenderParameter) { switch (m_eType) { - case st_clshdrawnil: sShading += L" w:val=\"nil\""; break; + case st_clshdrawnil: + { + if (PROP_DEF != m_nBackColor) + sShading += L" w:val=\"clear\""; + else + sShading += L" w:val=\"nil\""; + }break; case st_chbghoriz: sShading += L" w:val=\"thinHorzStripehorzStripe\""; break; case st_chbgvert: sShading += L" w:val=\"thinVertStripe\""; break; case st_chbgfdiag: sShading += L" w:val=\"thinReverseDiagStripe\""; break; From 0d6d27357377bd3f311a55ecf72624632ad19cb7 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 10 Dec 2025 19:07:26 +0300 Subject: [PATCH 080/125] Fix bug #74628 --- HtmlFile2/htmlfile2.cpp | 190 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 181 insertions(+), 9 deletions(-) diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp index 3adbeae38e..577cbb852e 100644 --- a/HtmlFile2/htmlfile2.cpp +++ b/HtmlFile2/htmlfile2.cpp @@ -1405,6 +1405,123 @@ void ReplaceSpaces(std::wstring& wsValue) } } +std::wstring StandardizeHeaderId(const std::wstring& header) +{ + if (header.empty()) + return std::wstring(); + + std::wstring result; + result.reserve(header.size()); + + // Флаг, указывающий, был ли предыдущий символ дефисом + bool prevWasHyphen = false; + bool inWhitespaceSequence = false; + wchar_t lowerC; + + for (wchar_t c : header) + { + // Приведение к нижнему регистру + lowerC = std::tolower(c); + + // Проверяем, является ли символ буквой или цифрой + if (std::iswalnum(lowerC)) + { + result.push_back(lowerC); + prevWasHyphen = false; + inWhitespaceSequence = false; + } + // Проверяем, является ли символ пробельным (пробел, табуляция и т.д.) + else if (std::iswspace(lowerC)) + { + // Заменяем последовательности пробельных символов на один дефис + if (!inWhitespaceSequence && !result.empty()) + { + result.push_back(L'-'); + inWhitespaceSequence = true; + } + } + // Проверяем, является ли символ дефисом или подчеркиванием + else if (c == L'-' || c == L'_') + { + // Добавляем дефис, если предыдущий символ не был дефисом + if (!prevWasHyphen && !result.empty()) + { + result.push_back(L'-'); + prevWasHyphen = true; + } + inWhitespaceSequence = false; + } + // Все остальные символы (знаки препинания) пропускаем + // Но если это буква в Unicode, мы можем её обработать + else if (std::iswalpha(lowerC)) + { + // Для Unicode-символов, которые являются буквами + result.push_back(lowerC); + prevWasHyphen = false; + inWhitespaceSequence = false; + } + // Остальные символы игнорируем + } + + // Удаляем дефисы в начале и конце + size_t start = 0; + size_t end = result.length(); + + while (start < end && result[start] == L'-') + ++start; + + while (end > start && result[end - 1] == L'-') + --end; + + // Удаляем последовательные дефисы + std::wstring finalResult; + finalResult.reserve(end - start); + + bool lastWasHyphen = false; + for (size_t i = start; i < end; i++) + { + if (result[i] == L'-') + { + if (!lastWasHyphen) + { + finalResult.push_back(L'-'); + lastWasHyphen = true; + } + } + else + { + finalResult.push_back(result[i]); + lastWasHyphen = false; + } + } + + return finalResult; +} + +bool ElementInHeader(const std::vector arSelsectors) +{ + for (const NSCSS::CNode& oNode : arSelsectors) + { + if (2 != oNode.m_wsName.length() && L'h' != oNode.m_wsName[0]) + continue; + + switch (GetHtmlTag(oNode.m_wsName)) + { + case HTML_TAG(H1): + case HTML_TAG(H2): + case HTML_TAG(H3): + case HTML_TAG(H4): + case HTML_TAG(H5): + case HTML_TAG(H6): + return true; + default: + continue; + } + } + + return false; +} + std::wstring EncodeXmlString(const std::wstring& s) { std::wstring sRes = s; @@ -1473,6 +1590,9 @@ private: int m_nId; // ID остальные элементы int m_nShapeId; // Id shape's + using anchors_map = std::map; + anchors_map m_mAnchors; // Map якорей с индивидуальными id + NSStringUtils::CStringBuilder m_oStylesXml; // styles.xml NSStringUtils::CStringBuilder m_oDocXmlRels; // document.xml.rels NSStringUtils::CStringBuilder m_oNoteXmlRels; // footnotes.xml.rels @@ -2184,10 +2304,18 @@ private: m_oState.m_bWasSpace = true; } - void WriteBookmark(NSStringUtils::CStringBuilder* pXml, const std::wstring& wsId) + std::wstring AddAnchor(const std::wstring& wsAnchorValue) + { + const std::wstring wsAnchorId{L"anchor-" + std::to_wstring(m_mAnchors.size() + 1)}; + m_mAnchors[wsAnchorValue] = wsAnchorId; + + return wsAnchorId; + } + + std::wstring WriteBookmark(NSStringUtils::CStringBuilder* pXml, const std::wstring& wsId) { if (NULL == pXml) - return; + return std::wstring(); const std::wstring sCrossId = std::to_wstring(m_mBookmarks.size() + 1); std::wstring sName; @@ -2196,7 +2324,13 @@ private: sName = wsId + L"_" + std::to_wstring(++m_mBookmarks[wsId]); else { - sName = wsId; + const anchors_map::const_iterator itFound{m_mAnchors.find(wsId)}; + + if (m_mAnchors.end() != itFound) + sName = itFound->second; + else + sName = AddAnchor(wsId); + m_mBookmarks.insert({wsId, 1}); } @@ -2204,8 +2338,20 @@ private: pXml->WriteString(sCrossId); pXml->WriteString(L"\" w:name=\""); pXml->WriteEncodeXmlString(sName); - pXml->WriteString(L"\"/>WriteString(sCrossId); + pXml->WriteString(L"\"/>"); + + return sCrossId; + } + + void WriteEmptyBookmark(NSStringUtils::CStringBuilder* pXml, const std::wstring& wsId) + { + const std::wstring wsCrossId{WriteBookmark(pXml, wsId)}; + + if (wsCrossId.empty()) + return; + + pXml->WriteString(L"WriteString(wsCrossId); pXml->WriteString(L"\"/>"); } @@ -2285,7 +2431,7 @@ private: else if(sName == L"id") { oNode.m_wsId = EncodeXmlString(m_oLightReader.GetText()); - WriteBookmark(oXml, oNode.m_wsId); + WriteEmptyBookmark(oXml, oNode.m_wsId); if (!m_oStylesCalculator.HaveStylesById(oNode.m_wsId)) oNode.m_wsId.clear(); @@ -2408,6 +2554,11 @@ private: if (!bPre && sText.end() == std::find_if_not(sText.begin(), sText.end(), [](wchar_t wchChar){ return iswspace(wchChar) && 0xa0 != wchChar;})) return false; + std::wstring wsHeaderId; + + if (ElementInHeader(arSelectors)) + wsHeaderId = StandardizeHeaderId(sText); + if(oTS.bBdo) std::reverse(sText.begin(), sText.end()); @@ -2424,6 +2575,11 @@ private: WriteToStringBuilder(oPPr, *pXml); + std::wstring wsCrossId; + + if (!wsHeaderId.empty()) + WriteEmptyBookmark(pXml, wsHeaderId); + NSStringUtils::CStringBuilder oRPr; std::wstring sRStyle; @@ -4159,12 +4315,28 @@ private: if(bCross) { m_oState.m_bInHyperlink = true; - oXml->WriteString(L"WriteString(L"WriteString(NSFile::GetFileName(sRef)); + wsAnchorValue = NSFile::GetFileName(sRef); else - oXml->WriteEncodeXmlString(sRef.c_str() + nSharp + 1); + wsAnchorValue = (sRef.c_str() + nSharp + 1); + + if (!wsAnchorValue.empty()) + { + const anchors_map::iterator itFound = m_mAnchors.find(wsAnchorValue); + std::wstring wsAnchorId; + + if (m_mAnchors.end() != itFound) + wsAnchorId = itFound->second; + else + wsAnchorId = AddAnchor(wsAnchorValue); + + oXml->WriteEncodeXmlString(wsAnchorId); + } } // Внешняя ссылка else From f75df05824d21e7962b00865148cc9f92f5dc758 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 10 Dec 2025 15:23:40 +0300 Subject: [PATCH 081/125] Fix SetDV for radiobutton --- PdfFile/SrcWriter/Annotation.cpp | 8 ++++++++ PdfFile/SrcWriter/Annotation.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 449f1f186d..b4698ed026 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -2046,6 +2046,14 @@ namespace PdfWriter else pOwner->Add("V", new CStringObject(sV.c_str(), true)); } + void CCheckBoxWidget::SetDV(const std::wstring& wsDV) + { + std::string sValue = U_TO_UTF8(wsDV); + CDictObject* pOwner = GetObjOwnValue("DV"); + if (!pOwner) + pOwner = this; + pOwner->Add("DV", sValue.c_str()); + } void CCheckBoxWidget::SetStyle(BYTE nStyle) { m_nStyle = ECheckBoxStyle(nStyle); diff --git a/PdfFile/SrcWriter/Annotation.h b/PdfFile/SrcWriter/Annotation.h index 0b281c65af..7ac59e482c 100644 --- a/PdfFile/SrcWriter/Annotation.h +++ b/PdfFile/SrcWriter/Annotation.h @@ -476,7 +476,7 @@ namespace PdfWriter void SetMEOptions(const int& nMEOptions); void SetTU(const std::wstring& wsTU); void SetDS(const std::wstring& wsDS); - void SetDV(const std::wstring& wsDV); + virtual void SetDV(const std::wstring& wsDV); void SetT (const std::wstring& wsT); void SetBC(const std::vector& arrBC); void SetBG(const std::vector& arrBG); @@ -555,6 +555,7 @@ namespace PdfWriter CCheckBoxWidget(CXref* pXref, EWidgetType nSubtype = WidgetCheckbox); void SetV(const std::wstring& wsV); + virtual void SetDV(const std::wstring& wsDV) override; void SetOpt(const std::vector< std::pair >& arrOpt); void SetStyle(BYTE nStyle); ECheckBoxStyle GetStyle() { return m_nStyle; } From b09d4419877b31898414e50fb3540f96c3cf3e9f Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Tue, 9 Dec 2025 16:43:05 +0600 Subject: [PATCH 082/125] fix bug #78958 (cherry picked from commit e15391ea35727368ddd46b55df2c5fc1ed130361) --- .../XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp index 6b8014ff31..446086413d 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/ATTACHEDLABEL_bu.cpp @@ -153,7 +153,8 @@ const bool ATTACHEDLABEL::loadContent(BinProcessor& proc) proc.optional(); - proc.mandatory(); elements_.pop_back(); + if(proc.mandatory()) + elements_.pop_back(); return true; } From 13e2efe7240cfc18d25b6dd99bfc5501017e3842 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Fri, 5 Dec 2025 16:09:45 +0600 Subject: [PATCH 083/125] fix bug #78955 (cherry picked from commit 6ea64599bd3125f9cad42fc2ad8ff3413e1bb362) --- .../XlsFile/Format/Logic/Biff_records/AutoFilter.cpp | 9 ++++++++- .../Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp index 6fa427b376..5c2b3b7610 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/AutoFilter.cpp @@ -72,7 +72,14 @@ void AutoFilter::readFields(CFRecord& record) { size_t pos_record = record.getRdPtr(); - if (size == 0xffffffff) size = record.getDataSize() - pos_record; + + if (size == 0xffffffff) + size = record.getDataSize() - pos_record; + else if(record.getDataSize() < pos_record + size) + { + //size error + return; + } if (size > 0) { diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp index 4f56ec0e1e..b19f624915 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/Feat11FdaAutoFilter.cpp @@ -53,7 +53,7 @@ void Feat11FdaAutoFilter::load(CFRecord& record) } record.skipNunBytes(2); - if (cbAutoFilter > 0 && cbAutoFilter < 2080) + if (cbAutoFilter > 0 && cbAutoFilter < 2080 && (record.getDataSize() - record.getRdPtr()) >= cbAutoFilter) { recAutoFilter.size = cbAutoFilter; recAutoFilter.readFields(record); From d373a8cc4caaddeec06089bc703747d3bd099790 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Thu, 4 Dec 2025 21:19:39 +0600 Subject: [PATCH 084/125] fix bug #78953 (cherry picked from commit 84847f1e74f9a103bdc2eb8f658107365fa4425c) --- MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp index dadb527760..488b74af4d 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/LD.cpp @@ -80,10 +80,11 @@ const bool LD::loadContent(BinProcessor& proc) elements_.pop_back(); } - proc.mandatory(); - - m_ATTACHEDLABEL = elements_.back(); - elements_.pop_back(); + if(proc.mandatory()) + { + m_ATTACHEDLABEL = elements_.back(); + elements_.pop_back(); + } if (proc.optional()) { @@ -102,7 +103,8 @@ const bool LD::loadContent(BinProcessor& proc) elements_.pop_back(); } proc.optional(); - proc.mandatory(); elements_.pop_back(); + if(proc.mandatory()) + elements_.pop_back(); return true; } From 037057ea7a6c59e10fffe2edbf6818eb1a9dea5e Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Fri, 5 Dec 2025 20:10:56 +0600 Subject: [PATCH 085/125] fix bug #78960 (cherry picked from commit bebb39a6199c435498352361988ee503cefb12eb) --- .../XlsFile/Format/Logic/Biff_records/DataFormat.cpp | 2 ++ .../XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp | 4 ++-- MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp index 7baa3dc932..1f9959676b 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/DataFormat.cpp @@ -55,6 +55,8 @@ void DataFormat::readFields(CFRecord& record) unsigned short flags; record >> xi >> yi >> iss >> flags; fUnknown = GETBIT(flags, 0); + if(iss > 1000) + iss = 0; } void DataFormat::writeFields(CFRecord& record) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp index 51e0900d63..91d1dcd093 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/MarkerFormat.cpp @@ -148,7 +148,7 @@ int MarkerFormat::serialize(std::wostream & _stream, int index, BaseObjectPtr _G { CP_XML_NODE(L"a:srgbClr") { - CP_XML_ATTR(L"val", (false == fAuto || index < 0) ? rgbBack.strRGB : default_marker_color[index]); + CP_XML_ATTR(L"val", (false == fAuto || index < 0 || index > default_marker_color->size()) ? rgbBack.strRGB : default_marker_color[index]); } } } @@ -158,7 +158,7 @@ int MarkerFormat::serialize(std::wostream & _stream, int index, BaseObjectPtr _G { CP_XML_NODE(L"a:srgbClr") { - CP_XML_ATTR(L"val", (false == fAuto || index < 0) ? rgbFore.strRGB : default_marker_color[index]); + CP_XML_ATTR(L"val", (false == fAuto || index < 0 || index > default_marker_color->size()) ? rgbFore.strRGB : default_marker_color[index]); } } CP_XML_NODE(L"a:prstDash") { CP_XML_ATTR(L"val", L"solid"); } diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp index 72249f59a4..a4ee62db98 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SS.cpp @@ -305,7 +305,7 @@ int SS::serialize_default(std::wostream & _stream, int series_type, int ind ) if ((line) && (line->lns == (_UINT16)5)) ind = -1; } - if (ind >= 0 && m_isAutoLine) + if (ind >= 0 && default_series_line_color->size() > ind && m_isAutoLine) { CP_XML_NODE(L"a:ln") { @@ -444,7 +444,8 @@ int SS::serialize(std::wostream & _stream, int series_type, int indPt) { CP_XML_NODE(L"a:srgbClr") { - CP_XML_ATTR(L"val", default_series_line_color[ind]); + if(default_series_line_color->size() > ind) + CP_XML_ATTR(L"val", default_series_line_color[ind]); } } CP_XML_NODE(L"a:prstDash") From 3870d23511952b347966629fa868978eb647157e Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Thu, 11 Dec 2025 15:58:40 +0300 Subject: [PATCH 086/125] Realize AddPath in IRenderer --- DesktopEditor/graphics/GraphicsPath.cpp | 28 +++++++++++++++++++++ DesktopEditor/graphics/GraphicsRenderer.cpp | 28 --------------------- DesktopEditor/graphics/GraphicsRenderer.h | 2 -- DesktopEditor/graphics/IRenderer.h | 6 +---- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsPath.cpp b/DesktopEditor/graphics/GraphicsPath.cpp index 4f15063441..f5b7d13002 100644 --- a/DesktopEditor/graphics/GraphicsPath.cpp +++ b/DesktopEditor/graphics/GraphicsPath.cpp @@ -1515,3 +1515,31 @@ namespace Aggplus return false; } } + +HRESULT IRenderer::AddPath(const Aggplus::CGraphicsPath& path) +{ + if (path.GetPointCount() == 0) + return S_FALSE; + + size_t length = path.GetPointCount() + path.GetCloseCount(); + std::vector points = path.GetPoints(0, length); + + for (size_t i = 0; i < length; i++) + { + if (path.IsCurvePoint(i)) + { + PathCommandCurveTo(points[i].X, points[i].Y, + points[i + 1].X, points[i + 1].Y, + points[i + 2].X, points[i + 2].Y); + i += 2; + } + else if (path.IsMovePoint(i)) + PathCommandMoveTo(points[i].X, points[i].Y); + else if (path.IsLinePoint(i)) + PathCommandLineTo(points[i].X, points[i].Y); + else + PathCommandClose(); + } + + return S_OK; +} diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 25439758e9..934709d9bb 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -1170,34 +1170,6 @@ HRESULT CGraphicsRenderer::PathCommandTextEx(const std::wstring& bsUnicodeText, return PathCommandText(bsUnicodeText, x, y, w, h); } -HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path) -{ - if (path.GetPointCount() == 0) - return S_FALSE; - - size_t length = path.GetPointCount() + path.GetCloseCount(); - std::vector points = path.GetPoints(0, length); - - for (size_t i = 0; i < length; i++) - { - if (path.IsCurvePoint(i)) - { - PathCommandCurveTo(points[i].X, points[i].Y, - points[i + 1].X, points[i + 1].Y, - points[i + 2].X, points[i + 2].Y); - i += 2; - } - else if (path.IsMovePoint(i)) - PathCommandMoveTo(points[i].X, points[i].Y); - else if (path.IsLinePoint(i)) - PathCommandLineTo(points[i].X, points[i].Y); - else - PathCommandClose(); - } - - return S_OK; -} - //-------- Функции для вывода изображений --------------------------------------------------- HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) { diff --git a/DesktopEditor/graphics/GraphicsRenderer.h b/DesktopEditor/graphics/GraphicsRenderer.h index 2b3185bd5f..4366d5298d 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.h +++ b/DesktopEditor/graphics/GraphicsRenderer.h @@ -243,8 +243,6 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h); virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h); - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path); - //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h); virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255); diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 1026c584cf..6bc4bf4a93 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -327,11 +327,7 @@ public: virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0; virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0; - virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) - { - UNUSED_VARIABLE(path); - return S_OK; - } + HRESULT AddPath(const Aggplus::CGraphicsPath& path); //-------- Функции для вывода изображений --------------------------------------------------- virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0; From 40a4fa1a9264201117416a7cd8bd1dee2d56220c Mon Sep 17 00:00:00 2001 From: Daria Ermakova Date: Thu, 11 Dec 2025 17:02:56 +0300 Subject: [PATCH 087/125] Fix bug 65734 --- MsBinaryFile/DocFile/DocumentMapping.cpp | 138 ++++++++++++----------- MsBinaryFile/DocFile/DocumentMapping.h | 1 + 2 files changed, 73 insertions(+), 66 deletions(-) diff --git a/MsBinaryFile/DocFile/DocumentMapping.cpp b/MsBinaryFile/DocFile/DocumentMapping.cpp index cf9e2f6d62..9d57310354 100644 --- a/MsBinaryFile/DocFile/DocumentMapping.cpp +++ b/MsBinaryFile/DocFile/DocumentMapping.cpp @@ -783,6 +783,7 @@ namespace DocFileFormat else { PictureDescriptor pic(chpxObj, m_document->DataStream, 0x7fffffff, m_document->nWordVersion); + bPict = false; oleWriter.WriteNodeBegin (L"w:object", true); oleWriter.WriteAttribute( L"w:dxaOrig", FormatUtils::IntToWideString( ( pic.dxaGoal + pic.dxaOrigin ) ) ); @@ -1068,85 +1069,90 @@ namespace DocFileFormat } else if (TextMark::Picture == code && fSpec) { - PictureDescriptor oPicture (chpx, m_document->nWordVersion > 0 ? m_document->WordDocumentStream : m_document->DataStream, 0x7fffffff, m_document->nWordVersion); + if (bPict) + { + PictureDescriptor oPicture (chpx, m_document->nWordVersion > 0 ? m_document->WordDocumentStream : m_document->DataStream, 0x7fffffff, m_document->nWordVersion); - bool isInline = _isTextBoxContent; + bool isInline = _isTextBoxContent; - if (oPicture.embeddedData && oPicture.embeddedDataSize > 0) - { - m_pXmlWriter->WriteNodeBegin (L"w:pict"); + if (oPicture.embeddedData && oPicture.embeddedDataSize > 0) + { + m_pXmlWriter->WriteNodeBegin (L"w:pict"); - VMLPictureMapping oVmlMapper(m_context, m_pXmlWriter, false, _caller, isInline); - oPicture.Convert (&oVmlMapper); + VMLPictureMapping oVmlMapper(m_context, m_pXmlWriter, false, _caller, isInline); + oPicture.Convert (&oVmlMapper); - m_pXmlWriter->WriteNodeEnd (L"w:pict"); - } - else if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer)/* && (false == oPicture.shapeContainer->isLastIdentify())*/) - { - bool bPicture = true; - bool m_bSkip = false; + m_pXmlWriter->WriteNodeEnd (L"w:pict"); + } + else if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer)/* && (false == oPicture.shapeContainer->isLastIdentify())*/) + { + bool bPicture = true; + bool m_bSkip = false; - if (oPicture.shapeContainer) - { - if (oPicture.shapeContainer->m_nShapeType != msosptPictureFrame) - bPicture = false;//шаблон 1.doc картинка в колонтитуле + if (oPicture.shapeContainer) + { + if (oPicture.shapeContainer->m_nShapeType != msosptPictureFrame) + bPicture = false;//шаблон 1.doc картинка в колонтитуле - m_bSkip = oPicture.shapeContainer->m_bSkip; - } - if (!m_bSkip) - { - bool bFormula = false; - XMLTools::CStringXmlWriter pictWriter; - pictWriter.WriteNodeBegin (L"w:pict"); + m_bSkip = oPicture.shapeContainer->m_bSkip; + } + if (!m_bSkip) + { + bool bFormula = false; + XMLTools::CStringXmlWriter pictWriter; + pictWriter.WriteNodeBegin (L"w:pict"); - if (bPicture) - { - VMLPictureMapping oVmlMapper(m_context, &pictWriter, false, _caller, isInline); - oPicture.Convert (&oVmlMapper); + if (bPicture) + { + VMLPictureMapping oVmlMapper(m_context, &pictWriter, false, _caller, isInline); + oPicture.Convert (&oVmlMapper); - if (oVmlMapper.m_isEmbedded) - { - OleObject ole ( chpx, m_document); - OleObjectMapping oleObjectMapping( &pictWriter, m_context, &oPicture, _caller, oVmlMapper.m_shapeId ); + if (oVmlMapper.m_isEmbedded) + { + OleObject ole ( chpx, m_document); + OleObjectMapping oleObjectMapping( &pictWriter, m_context, &oPicture, _caller, oVmlMapper.m_shapeId ); - ole.isEquation = oVmlMapper.m_isEquation; - ole.isEmbedded = oVmlMapper.m_isEmbedded; - ole.embeddedData = oVmlMapper.m_embeddedData; + ole.isEquation = oVmlMapper.m_isEquation; + ole.isEmbedded = oVmlMapper.m_isEmbedded; + ole.embeddedData = oVmlMapper.m_embeddedData; - ole.Convert( &oleObjectMapping ); - } - else if (oVmlMapper.m_isEquation) - { - //нельзя в Run писать oMath - //m_pXmlWriter->WriteString(oVmlMapper.m_equationXml); - _writeAfterRun = oVmlMapper.m_equationXml; - bFormula = true; - } - else if (oVmlMapper.m_isBlob) - { - _writeAfterRun = oVmlMapper.m_blobXml; - bFormula = true; - } - } - else - { - VMLShapeMapping oVmlMapper(m_context, &pictWriter, NULL, &oPicture, _caller, isInline, false); - oPicture.shapeContainer->Convert(&oVmlMapper); - } + ole.Convert( &oleObjectMapping ); + } + else if (oVmlMapper.m_isEquation) + { + //нельзя в Run писать oMath + //m_pXmlWriter->WriteString(oVmlMapper.m_equationXml); + _writeAfterRun = oVmlMapper.m_equationXml; + bFormula = true; + } + else if (oVmlMapper.m_isBlob) + { + _writeAfterRun = oVmlMapper.m_blobXml; + bFormula = true; + } + } + else + { + VMLShapeMapping oVmlMapper(m_context, &pictWriter, NULL, &oPicture, _caller, isInline, false); + oPicture.shapeContainer->Convert(&oVmlMapper); + } - pictWriter.WriteNodeEnd (L"w:pict"); + pictWriter.WriteNodeEnd (L"w:pict"); - if (!bFormula) - { - m_pXmlWriter->WriteString(pictWriter.GetXmlString()); + if (!bFormula) + { + m_pXmlWriter->WriteString(pictWriter.GetXmlString()); - if ((false == _fieldLevels.empty()) && (_fieldLevels.back().bSeparate && !_fieldLevels.back().bResult)) //ege15.doc - { - _fieldLevels.back().bResult = true; - }//imrtemplate(endnotes).doc - } - } - } + if ((false == _fieldLevels.empty()) && (_fieldLevels.back().bSeparate && !_fieldLevels.back().bResult)) //ege15.doc + { + _fieldLevels.back().bResult = true; + }//imrtemplate(endnotes).doc + } + } + } + } + else + bPict = true; } else if ((TextMark::AutoNumberedFootnoteReference == code) && fSpec) { diff --git a/MsBinaryFile/DocFile/DocumentMapping.h b/MsBinaryFile/DocFile/DocumentMapping.h index 33c4e02ad5..6678542dca 100644 --- a/MsBinaryFile/DocFile/DocumentMapping.h +++ b/MsBinaryFile/DocFile/DocumentMapping.h @@ -84,6 +84,7 @@ namespace DocFileFormat std::wstring m_shapeIdOwner; std::wstring getOLEObject() { return _lastOLEObject; } bool m_bOleInPicture = false; + bool bPict = true; protected: int getListNumCache (int fc, int fc_end); From b369c32e9ed8453bc8ec5306084a33a06ff6dabf Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 11 Dec 2025 17:03:42 +0300 Subject: [PATCH 088/125] fix value array xlsx --- OOXML/XlsxFormat/Worksheets/SheetData.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/OOXML/XlsxFormat/Worksheets/SheetData.cpp b/OOXML/XlsxFormat/Worksheets/SheetData.cpp index d952a9e0c8..e94a31de6d 100644 --- a/OOXML/XlsxFormat/Worksheets/SheetData.cpp +++ b/OOXML/XlsxFormat/Worksheets/SheetData.cpp @@ -577,6 +577,7 @@ namespace OOX m_oType.SetValue(SimpleTypes::Spreadsheet::celltypeNumber); m_oShowPhonetic.FromBool(false); + m_oValueMetadata.reset(); m_oCellMetadata.reset(); m_oValue.Clean(); m_oFormula.Clean(); From 964a44ed932e78b73d6ff40cbfb9c0fead1f1618 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 11 Dec 2025 19:51:50 +0300 Subject: [PATCH 089/125] . --- OOXML/PPTXFormat/Logic/TxBody.cpp | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/OOXML/PPTXFormat/Logic/TxBody.cpp b/OOXML/PPTXFormat/Logic/TxBody.cpp index 6739744954..1a0f7c0fbe 100644 --- a/OOXML/PPTXFormat/Logic/TxBody.cpp +++ b/OOXML/PPTXFormat/Logic/TxBody.cpp @@ -115,14 +115,37 @@ namespace PPTX { Paragrs.clear(); - m_name = node.GetName(); + m_name = node.GetName(); - bodyPr = node.ReadNode(L"a:bodyPr"); - lstStyle = node.ReadNode(L"a:lstStyle"); - sp3d = node.ReadNode(L"a:sp3d"); + std::vector oNodes; + if (node.GetNodes(_T("*"), oNodes)) + { + size_t count = oNodes.size(); + for (size_t i = 0; i < count; ++i) + { + XmlUtils::CXmlNode& oNode = oNodes[i]; - XmlMacroLoadArray(node, L"a:p", Paragrs, Paragraph); + std::wstring strName = XmlUtils::GetNameNoNS(oNode.GetName()); + if (L"bodyPr" == strName) + { + bodyPr = oNode; + } + else if (L"lstStyle" == strName) + { + lstStyle = oNode; + } + else if (L"sp3d" == strName) + { + sp3d = oNode; + } + else if (L"p" == strName) + { + Paragrs.emplace_back(); + Paragrs.back().fromXML(oNode); + } + } + } FillParentPointersForChilds(); } std::wstring TxBody::toXML() const From 67f287f30f5c5c6a1e33d44a48ab6d8cc62e6f80 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Fri, 12 Dec 2025 14:34:03 +0600 Subject: [PATCH 090/125] fix xls record size check --- MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp | 11 +++++++++++ MsBinaryFile/XlsFile/Format/Binary/CFRecord.h | 12 ++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp index a2b710532c..9764079ca2 100644 --- a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp +++ b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp @@ -49,6 +49,17 @@ CFRecord::CFRecord(CFStreamPtr stream, GlobalWorkbookInfoPtr global_info) unsigned short size_short; *stream >> size_short; size_ = size_short; + const auto maxRecordSize = 8224; + if(size_ > maxRecordSize) + { + type_id_ = -1; + } + auto streamSize = stream->getStreamSize(); + if(stream->getStreamPointer() + size_ > streamSize) + { + size_ = streamSize - stream->getStreamPointer(); + type_id_ = -1; + } data_ = new char[size_]; unsigned long rec_data_pos = stream->getStreamPointer(); diff --git a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h index f899a8a379..c76e9e2c00 100644 --- a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h +++ b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h @@ -175,12 +175,12 @@ private: CFStream::ReceiverItems receiver_items; CFStream::SourceItems source_items; - unsigned int file_ptr; - CFRecordType::TypeId type_id_; - size_t size_; - char* data_; - BYTE sizeOfRecordTypeRecordLength; //размер RecordType и RecordLength - size_t rdPtr; + unsigned int file_ptr = 0; + CFRecordType::TypeId type_id_ = 0; + size_t size_ = 0; + char* data_ = 0; + BYTE sizeOfRecordTypeRecordLength = 0; //размер RecordType и RecordLength + size_t rdPtr = 0; static char intData[MAX_RECORD_SIZE_XLSB]; GlobalWorkbookInfoPtr global_info_; From cb0e3614909af96c450ae87a2d5f43942f66dcdf Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 12 Dec 2025 14:08:52 +0300 Subject: [PATCH 091/125] Fix bug 78919 --- DesktopEditor/graphics/Graphics.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/DesktopEditor/graphics/Graphics.cpp b/DesktopEditor/graphics/Graphics.cpp index 2ffd835aff..96b3e3591d 100644 --- a/DesktopEditor/graphics/Graphics.cpp +++ b/DesktopEditor/graphics/Graphics.cpp @@ -2142,7 +2142,12 @@ namespace Aggplus agg::trans_affine* full_trans = &m_oFullTransform.m_internal->m_agg_mtx; double dDet = full_trans->determinant(); - if (fabs(dDet) < 0.0001) + double sx = sqrt(full_trans->sx * full_trans->sx + full_trans->shx * full_trans->shx); + double sy = sqrt(full_trans->shy * full_trans->shy + full_trans->sy * full_trans->sy); + double scale = std::max(sx, sy); + double adaptive_threshold = 1.0 / (scale * scale * 10000.0); + + if (fabs(dDet) < std::max(0.0001, adaptive_threshold)) { path_copy.transform_all_paths(m_oFullTransform.m_internal->m_agg_mtx); dWidth *= sqrt(fabs(dDet)); @@ -2240,6 +2245,8 @@ namespace Aggplus LONG lCount2 = lCount / 2; double dKoef = 1.0; + if (bIsUseIdentity) + dKoef = sqrt(fabs(m_oFullTransform.m_internal->m_agg_mtx.determinant())); for (LONG i = 0; i < lCount2; ++i) { From 0223b1beabb24f5e307de683c29e4e3f197c8482 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Fri, 12 Dec 2025 16:20:42 +0300 Subject: [PATCH 092/125] Fix missprint --- DocxRenderer/src/logic/Page.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index 82aee2ab1b..dee6eac6c6 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -1606,7 +1606,7 @@ namespace NSDocxRenderer // lamda to setup and add paragpraph auto add_paragraph = [this, &max_right, &min_left, &ar_paragraphs] (paragraph_ptr_t& paragraph) { - double additional_bottom = m_arTextLines.front()->m_dTopWithMaxAscent - m_arTextLines.front()->m_dTop; + double additional_bottom = paragraph->m_arTextLines.front()->m_dTopWithMaxAscent - paragraph->m_arTextLines.front()->m_dTop; paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBot + additional_bottom; paragraph->m_dTop = paragraph->m_arTextLines.front()->m_dTopWithMaxAscent; paragraph->m_dRight = max_right; From 00c24f9d68fb5899a2f952cbf4e24999ee7ce203 Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Mon, 15 Dec 2025 12:10:43 +0300 Subject: [PATCH 093/125] Add fix with two lines in paragraph --- DocxRenderer/src/logic/Page.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index dee6eac6c6..3370016e69 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -1846,6 +1846,19 @@ namespace NSDocxRenderer } } + // 2 lines in paragraph fix + for (size_t index = 0; index < ar_positions.size() - 1; ++index) + { + auto& line_top = text_lines[index]; + auto& line_bot = text_lines[index + 1]; + + bool is_start = index == 0 || ar_delims[index - 1] == true; + bool is_end = index == ar_positions.size() - 1 || ar_delims[index + 1] == true; + bool is_diff = fabs(line_top->m_dHeight - line_bot->m_dHeight) > (line_top->m_dHeight + line_bot->m_dHeight) / 4; + if (is_start && is_end && is_diff) + ar_delims[index] = true; + } + // gap check // // bla-bla-bla From 9ece4889a11b0614d952376720dd9fb2aed8193a Mon Sep 17 00:00:00 2001 From: Alexey Nagaev Date: Mon, 15 Dec 2025 13:28:16 +0300 Subject: [PATCH 094/125] Add ordering for any object --- DocxRenderer/src/logic/Page.cpp | 10 +++++++--- DocxRenderer/src/logic/Page.h | 2 +- DocxRenderer/src/logic/elements/BaseItem.h | 2 ++ DocxRenderer/src/logic/elements/ContText.cpp | 3 +++ DocxRenderer/src/logic/elements/ContText.h | 1 + DocxRenderer/src/logic/elements/Shape.h | 1 - DocxRenderer/src/logic/elements/TextLine.cpp | 1 + 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/DocxRenderer/src/logic/Page.cpp b/DocxRenderer/src/logic/Page.cpp index 3370016e69..62e6df424f 100644 --- a/DocxRenderer/src/logic/Page.cpp +++ b/DocxRenderer/src/logic/Page.cpp @@ -268,7 +268,7 @@ namespace NSDocxRenderer if (!skip_shape) { - shape->m_nOrder = ++m_nShapeOrder; + shape->m_nOrder = ++m_nCurrentOrder; m_arShapes.push_back(shape); } } @@ -342,6 +342,7 @@ namespace NSDocxRenderer bForcedBold = true; m_oManagers.pParagraphStyleManager->UpdateAvgFontSize(m_oFont.Size); + m_nCurrentOrder++; m_oContBuilder.AddUnicode( top, baseline, @@ -351,6 +352,7 @@ namespace NSDocxRenderer m_oBrush, m_oManagers.pFontManager, oText, + m_nCurrentOrder, pGids, bForcedBold, m_bUseDefaultFont, @@ -483,8 +485,6 @@ namespace NSDocxRenderer m_arShapes.erase(right, m_arShapes.end()); std::sort(m_arShapes.begin(), m_arShapes.end(), [] (const shape_ptr_t& s1, const shape_ptr_t& s2) { - if (s1->m_bIsBehindDoc && !s2->m_bIsBehindDoc) return true; - if (!s1->m_bIsBehindDoc && s2->m_bIsBehindDoc) return false; return s1->m_nOrder < s2->m_nOrder; }); } @@ -1686,6 +1686,7 @@ namespace NSDocxRenderer min_left = std::min(min_left, curr_line->m_dLeft); max_right = std::max(max_right, curr_line->m_dRight); paragraph->m_arTextLines.push_back(curr_line); + paragraph->m_nOrder = std::max(paragraph->m_nOrder, curr_line->m_nOrder); }; auto build_paragraphs = [this, add_line, add_paragraph] (const std::vector& text_lines) { @@ -2559,6 +2560,7 @@ namespace NSDocxRenderer pParagraph->m_dHeight = pLine->m_dHeight; pParagraph->m_dRight = pLine->m_dRight; pParagraph->m_dLineHeight = pParagraph->m_dHeight; + pParagraph->m_nOrder = pLine->m_nOrder; if (pLine->m_pDominantShape) { @@ -2577,6 +2579,7 @@ namespace NSDocxRenderer pShape->m_dWidth = pParagraph->m_dWidth; pShape->m_dHeight = pParagraph->m_dHeight; pShape->m_dRight = pParagraph->m_dRight; + pShape->m_nOrder = pParagraph->m_nOrder; pShape->m_bIsBehindDoc = false; return pShape; @@ -2592,6 +2595,7 @@ namespace NSDocxRenderer pShape->m_dBot = pParagraph->m_dBot; pShape->m_dHeight = pParagraph->m_dHeight; pShape->m_dWidth = pParagraph->m_dWidth; + pShape->m_nOrder = pParagraph->m_nOrder; if (pParagraph->m_bIsNeedFirstLineIndent && pParagraph->m_dFirstLine < 0) pParagraph->m_dLeftBorder = -pParagraph->m_dFirstLine; diff --git a/DocxRenderer/src/logic/Page.h b/DocxRenderer/src/logic/Page.h index 7b0f1a44e9..44f1cbc3e0 100644 --- a/DocxRenderer/src/logic/Page.h +++ b/DocxRenderer/src/logic/Page.h @@ -231,6 +231,6 @@ namespace NSDocxRenderer std::vector m_arLuminosityShapes; std::vector m_arOneColorGradientShape; - size_t m_nShapeOrder = 0; + size_t m_nCurrentOrder = 0; }; } diff --git a/DocxRenderer/src/logic/elements/BaseItem.h b/DocxRenderer/src/logic/elements/BaseItem.h index 5a96d133f9..4f352d9578 100644 --- a/DocxRenderer/src/logic/elements/BaseItem.h +++ b/DocxRenderer/src/logic/elements/BaseItem.h @@ -50,6 +50,8 @@ namespace NSDocxRenderer double m_dHeight {0.0}; double m_dWidth {0.0}; + size_t m_nOrder = 0; + CBaseItem(); CBaseItem(const CBaseItem& other); CBaseItem(CBaseItem&& other); diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 139f07a022..ddbad8e188 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -1137,6 +1137,7 @@ namespace NSDocxRenderer const NSStructures::CBrush& oBrush, CFontManager* pFontManager, const NSStringUtils::CStringUTF32& oText, + size_t nOrder, const PUINT pGids, bool bForcedBold, bool bUseDefaultFont, @@ -1217,6 +1218,7 @@ namespace NSDocxRenderer m_pCurrCont->m_dBot = std::max(m_pCurrCont->m_dBot, dBot); m_pCurrCont->m_dHeight = m_pCurrCont->m_dBot - m_pCurrCont->m_dTop; m_pCurrCont->m_dWidth = m_pCurrCont->m_dRight - m_pCurrCont->m_dLeft; + m_pCurrCont->m_nOrder = nOrder; return; } } @@ -1283,6 +1285,7 @@ namespace NSDocxRenderer } pCont->m_bWriteStyleRaw = bWriteStyleRaw; pCont->m_bFontSubstitution = bFontSubstitution; + pCont->m_nOrder = nOrder; if (pCont->IsDiacritical()) { diff --git a/DocxRenderer/src/logic/elements/ContText.h b/DocxRenderer/src/logic/elements/ContText.h index 0423bc86dd..7686281092 100644 --- a/DocxRenderer/src/logic/elements/ContText.h +++ b/DocxRenderer/src/logic/elements/ContText.h @@ -188,6 +188,7 @@ namespace NSDocxRenderer const NSStructures::CBrush& oBrush, CFontManager* pFontManager, const NSStringUtils::CStringUTF32& oText, + size_t nOrder = 0, const PUINT pGids = nullptr, bool bForcedBold = false, bool bUseDefaultFont = false, diff --git a/DocxRenderer/src/logic/elements/Shape.h b/DocxRenderer/src/logic/elements/Shape.h index c3ae1384e8..01b5535c94 100644 --- a/DocxRenderer/src/logic/elements/Shape.h +++ b/DocxRenderer/src/logic/elements/Shape.h @@ -46,7 +46,6 @@ namespace NSDocxRenderer std::wstring m_strDstMedia {}; double m_dRotation {0.0}; - size_t m_nOrder {0}; bool m_bIsNoFill {true}; bool m_bIsNoStroke {true}; diff --git a/DocxRenderer/src/logic/elements/TextLine.cpp b/DocxRenderer/src/logic/elements/TextLine.cpp index eee3568ce9..6f4f3746ee 100644 --- a/DocxRenderer/src/logic/elements/TextLine.cpp +++ b/DocxRenderer/src/logic/elements/TextLine.cpp @@ -21,6 +21,7 @@ namespace NSDocxRenderer { RecalcWithNewItem(oCont.get()); m_arConts.push_back(oCont); + m_nOrder = std::max(m_nOrder, oCont->m_nOrder); } void CTextLine::AddConts(const std::vector>& arConts) { From 4c9a24bf71799966ef838f8e85ef65e660c6b2a2 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Mon, 15 Dec 2025 21:07:19 +0300 Subject: [PATCH 095/125] fix bug #78986 --- MsBinaryFile/PptFile/Drawing/Attributes.h | 2 ++ MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp | 13 +++++++------ .../PptFile/Records/Drawing/ShapeContainer.cpp | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/MsBinaryFile/PptFile/Drawing/Attributes.h b/MsBinaryFile/PptFile/Drawing/Attributes.h index 7029dedc8d..be84015200 100644 --- a/MsBinaryFile/PptFile/Drawing/Attributes.h +++ b/MsBinaryFile/PptFile/Drawing/Attributes.h @@ -730,6 +730,7 @@ namespace ODRAW Gdiplus::RectF Rect; double LinearAngle; + int Focus; std::vector> ColorsPosition; @@ -815,6 +816,7 @@ namespace ODRAW TextureMode = c_BrushTextureModeStretch; LinearAngle = 0; + Focus = 0; TexturePath = L""; diff --git a/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp b/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp index c22e19b8f0..a933d28545 100644 --- a/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp +++ b/MsBinaryFile/PptFile/PPTXWriter/ShapeWriter.cpp @@ -349,17 +349,18 @@ std::wstring PPT::CShapeWriter::ConvertBrush(CBrush & brush) brush_writer.WriteString(L""); brush_writer.WriteString(L" 180) brush.LinearAngle -= 180; + double val = 360 - brush.LinearAngle; + val += 90; - double val = (90 - brush.LinearAngle) ; - if (val < 0) val = 0; - if (val > 360) val -= 360; + if (val < 0) val += 360; + if (val >= 360) val -= 360; std::wstring str = std::to_wstring((int)(val * 60000)); brush_writer.WriteString(str); } - brush_writer.WriteString(L"\" scaled=\"1\"/>"); + brush_writer.WriteString(L"\""); + //brush_writer.WriteString(L" scaled = \"1\""); + brush_writer.WriteString(L"/>"); brush_writer.WriteString(L""); } else if(brush.Type == c_BrushTypePattern) diff --git a/MsBinaryFile/PptFile/Records/Drawing/ShapeContainer.cpp b/MsBinaryFile/PptFile/Records/Drawing/ShapeContainer.cpp index 943c00f334..8922864748 100644 --- a/MsBinaryFile/PptFile/Records/Drawing/ShapeContainer.cpp +++ b/MsBinaryFile/PptFile/Records/Drawing/ShapeContainer.cpp @@ -513,6 +513,7 @@ void CPPTElement::SetUpProperty(CElementPtr pElement, CTheme* pTheme, CSlideInfo }break; case fillFocus://relative position of the last color in the shaded fill { + pElement->m_oBrush.Focus = pProperty->m_lValue; }break; case fillShadePreset: {//value (int) from 0x00000088 through 0x0000009F or complex From 03199188272ccb4e8c103dad9ce881882be1c769 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Tue, 16 Dec 2025 13:33:30 +0600 Subject: [PATCH 096/125] fix xls conversion --- .../XlsFile/Format/Logic/Biff_records/SST.cpp | 6 +- .../Logic/Biff_unions/SHAREDSTRINGS.cpp | 6 +- OOXML/XlsxFormat/Styles/NumFmts.cpp | 3 + OOXML/XlsxFormat/Styles/XlsxStyles.cpp | 125 +++++++++++------- OOXML/XlsxFormat/Worksheets/SheetData.cpp | 2 +- 5 files changed, 85 insertions(+), 57 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/SST.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/SST.cpp index 0262344c17..0dc3ba851d 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_records/SST.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_records/SST.cpp @@ -84,7 +84,7 @@ void SST::readFields(CFRecord& record) void SST::writeFields(CFRecord& record) { - const auto MaxRecordSize = 8224; + const auto MaxRecordSize = 8000; cstUnique = rgb.size(); if(cstTotal == 0 && cstTotal < cstUnique) cstTotal = cstUnique; @@ -92,8 +92,8 @@ void SST::writeFields(CFRecord& record) while(!rgb.empty()) { auto oldPose = record.getRdPtr(); - record << *rgb.at(0); - if(record.getRdPtr() > MaxRecordSize) + rgb.at(0)->save(record); + if(record.getRdPtr() >= MaxRecordSize) { record.RollRdPtrBack(record.getRdPtr() - oldPose); break; diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SHAREDSTRINGS.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SHAREDSTRINGS.cpp index 70123c2fe8..9d52eb81b5 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SHAREDSTRINGS.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/SHAREDSTRINGS.cpp @@ -78,7 +78,7 @@ const bool SHAREDSTRINGS::saveContent(BinProcessor& proc) auto castedSst = static_cast(sstPtr.get()); if(!castedSst->rgb.empty()) { - const auto MaxRecordSize = 8224; + const auto MaxRecordSize = 8000; while(!castedSst->rgb.empty()) { CFRecordPtr tempRecord(new CFRecord(rt_Continue, proc.getGlobalWorkbookInfo())); @@ -86,8 +86,8 @@ const bool SHAREDSTRINGS::saveContent(BinProcessor& proc) while(!castedSst->rgb.empty()) { auto oldPose = tempRecord->getRdPtr(); - *tempRecord << castedSst->rgb.at(0); - if(tempRecord->getRdPtr() > MaxRecordSize) + castedSst->rgb.at(0)->save(*tempRecord); + if(tempRecord->getRdPtr() >= MaxRecordSize) { tempRecord->RollRdPtrBack(tempRecord->getRdPtr() - oldPose); break; diff --git a/OOXML/XlsxFormat/Styles/NumFmts.cpp b/OOXML/XlsxFormat/Styles/NumFmts.cpp index fe485a5828..0a2ed8dad7 100644 --- a/OOXML/XlsxFormat/Styles/NumFmts.cpp +++ b/OOXML/XlsxFormat/Styles/NumFmts.cpp @@ -232,11 +232,14 @@ namespace OOX std::vector CNumFmts::toXLS() { std::vector fmtVector; + auto numFmt = 164; for(auto i:m_arrItems) { + i->m_oNumFmtId->m_eValue = numFmt; if(i->m_oNumFmtId.IsInit() && i->m_oNumFmtId->m_eValue < 164) continue; fmtVector.push_back(i->toXLS()); + numFmt++; } return fmtVector; } diff --git a/OOXML/XlsxFormat/Styles/XlsxStyles.cpp b/OOXML/XlsxFormat/Styles/XlsxStyles.cpp index a5b7027056..019a890e7e 100644 --- a/OOXML/XlsxFormat/Styles/XlsxStyles.cpp +++ b/OOXML/XlsxFormat/Styles/XlsxStyles.cpp @@ -348,68 +348,70 @@ namespace OOX auto workbookPtr = static_cast(globalsStreamPtr.get()); auto FormatPtr = new XLS::FORMATTING; workbookPtr->m_Formating = XLS::BaseObjectPtr(FormatPtr); - - //prepare colors - m_oColors = OOX::Spreadsheet::CColors(); - m_oColors->m_oIndexedColors.Init(); - m_oColors->m_oMruColors.Init(); auto globalInfo = workbookPtr->global_info_; + //prepare colors + if(!m_oColors.IsInit()) { - for(auto i : globalInfo->colors_palette) + m_oColors = OOX::Spreadsheet::CColors(); + m_oColors->m_oIndexedColors.Init(); + m_oColors->m_oMruColors.Init(); { - nullable tempColor; - tempColor.Init(); - tempColor->m_oRgb.Init(); - tempColor->m_oRgb->FromString(i.second); - SetColor(m_oColors.get(), tempColor); - } - - } - if (m_oFonts.IsInit()) - { - for(auto i : m_oFonts->m_arrItems) - { - SetColor(m_oColors.get(), i->m_oColor); - } - } - if(m_oFills.IsInit()) - { - for(auto i : m_oFills->m_arrItems) - { - if(i->m_oPatternFill.IsInit()) + for(auto i : globalInfo->colors_palette) { - auto pattern = &i->m_oPatternFill; - SetColor(m_oColors.get(), (*pattern)->m_oBgColor); - SetColor(m_oColors.get(), (*pattern)->m_oFgColor); + nullable tempColor; + tempColor.Init(); + tempColor->m_oRgb.Init(); + tempColor->m_oRgb->FromString(i.second); + SetColor(m_oColors.get(), tempColor); + } + + } + if (m_oFonts.IsInit()) + { + for(auto i : m_oFonts->m_arrItems) + { + SetColor(m_oColors.get(), i->m_oColor); } } - } - for(auto i : m_oBorders->m_arrItems) - { - if(i->m_oTop.IsInit()) + if(m_oFills.IsInit()) { - SetColor(m_oColors.get(), i->m_oTop->m_oColor); + for(auto i : m_oFills->m_arrItems) + { + if(i->m_oPatternFill.IsInit()) + { + auto pattern = &i->m_oPatternFill; + SetColor(m_oColors.get(), (*pattern)->m_oBgColor); + SetColor(m_oColors.get(), (*pattern)->m_oFgColor); + } + } } - if(i->m_oBottom.IsInit()) + for(auto i : m_oBorders->m_arrItems) { - SetColor(m_oColors.get(), i->m_oBottom->m_oColor); - } - if(i->m_oStart.IsInit()) - { - SetColor(m_oColors.get(), i->m_oStart->m_oColor); - } - if(i->m_oEnd.IsInit()) - { - SetColor(m_oColors.get(), i->m_oEnd->m_oColor); - } - if(i->m_oDiagonal.IsInit()) - { - SetColor(m_oColors.get(), i->m_oDiagonal->m_oColor); + if(i->m_oTop.IsInit()) + { + SetColor(m_oColors.get(), i->m_oTop->m_oColor); + } + if(i->m_oBottom.IsInit()) + { + SetColor(m_oColors.get(), i->m_oBottom->m_oColor); + } + if(i->m_oStart.IsInit()) + { + SetColor(m_oColors.get(), i->m_oStart->m_oColor); + } + if(i->m_oEnd.IsInit()) + { + SetColor(m_oColors.get(), i->m_oEnd->m_oColor); + } + if(i->m_oDiagonal.IsInit()) + { + SetColor(m_oColors.get(), i->m_oDiagonal->m_oColor); + } + } + MapColors(m_oColors.get()); } - - MapColors(m_oColors.get()); FormatPtr->m_Palette = m_oColors->toXLS(); if (m_oFonts.IsInit()) { @@ -432,7 +434,30 @@ namespace OOX FormatPtr->m_arFonts = m_oFonts->toXLS(); } if (m_oNumFmts.IsInit()) + { + auto remap = [&](auto& xf) + { + if (xf->m_oNumFmtId.IsInit()) + { + auto val = xf->m_oNumFmtId->GetValue(); + if (val) + { + auto it = m_oNumFmts->m_mapNumFmtIndex.find(val); + if (it != m_oNumFmts->m_mapNumFmtIndex.end()) + { + xf->m_oNumFmtId = static_cast(it->second + 164); + } + } + } + }; + + for (auto& cellStyleXF : m_oCellStyleXfs->m_arrItems) + remap(cellStyleXF); + + for (auto& cellXF : m_oCellXfs->m_arrItems) + remap(cellXF); FormatPtr->m_arFormats = m_oNumFmts->toXLS(); + } if(m_oCellStyleXfs.IsInit() || m_oCellXfs.IsInit()) { auto xfs = new XLS::XFS; diff --git a/OOXML/XlsxFormat/Worksheets/SheetData.cpp b/OOXML/XlsxFormat/Worksheets/SheetData.cpp index 61a8ed11ed..723a683cdc 100644 --- a/OOXML/XlsxFormat/Worksheets/SheetData.cpp +++ b/OOXML/XlsxFormat/Worksheets/SheetData.cpp @@ -4320,7 +4320,7 @@ namespace OOX auto rowPtr = new XLS::Row; auto basePtr = XLS::BaseObjectPtr(rowPtr); if(m_oR.IsInit()) - rowPtr->rw = m_oR->GetValue(); + rowPtr->rw = m_oR->GetValue() -1; if(m_oOutlineLevel.IsInit()) rowPtr->iOutLevel = m_oOutlineLevel->GetValue(); if(m_oHidden.IsInit()) From aec1220bff1bb91af0b416d92be9f7ec8fd4c8a9 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 16 Dec 2025 15:41:14 +0300 Subject: [PATCH 097/125] Create GetGIDByUnicode --- DesktopEditor/doctrenderer/drawingfile.h | 7 +++ DesktopEditor/fontengine/FontFile.cpp | 4 +- .../graphics/pro/js/wasm/js/drawingfile.js | 5 ++ .../pro/js/wasm/js/drawingfile_native.js | 6 ++ .../pro/js/wasm/js/drawingfile_wasm.js | 28 +++++++++ .../graphics/pro/js/wasm/src/drawingfile.cpp | 4 ++ .../pro/js/wasm/src/drawingfile_test.cpp | 30 ++++++++++ PdfFile/PdfFile.cpp | 6 ++ PdfFile/PdfFile.h | 1 + PdfFile/PdfReader.cpp | 58 +++++++++++++++++++ PdfFile/PdfReader.h | 1 + 11 files changed, 148 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/doctrenderer/drawingfile.h b/DesktopEditor/doctrenderer/drawingfile.h index 47bf314044..6b10dc9393 100644 --- a/DesktopEditor/doctrenderer/drawingfile.h +++ b/DesktopEditor/doctrenderer/drawingfile.h @@ -570,6 +570,13 @@ public: } return NULL; } + BYTE* GetGIDByUnicode(const std::string& sPathA) + { + if (m_nType != 0) + return NULL; + std::wstring sFontName = UTF8_TO_U(sPathA); + return ((CPdfFile*)m_pFile)->GetGIDByUnicode(sFontName); + } std::wstring GetFontBinaryNative(const std::wstring& sName) { diff --git a/DesktopEditor/fontengine/FontFile.cpp b/DesktopEditor/fontengine/FontFile.cpp index e3840f70b7..4d843a2cd8 100644 --- a/DesktopEditor/fontengine/FontFile.cpp +++ b/DesktopEditor/fontengine/FontFile.cpp @@ -731,10 +731,10 @@ void CFontFile::CheckHintsSupport() int CFontFile::SetCMapForCharCode(long lUnicode, int *pnCMapIndex) { *pnCMapIndex = -1; - if (!m_pFace) + if (!m_pFace || !m_pFace->num_charmaps) return 0; - if ( m_bStringGID || 0 == m_pFace->num_charmaps ) + if ( m_bStringGID ) return lUnicode; int nCharIndex = 0; diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index ba24184e09..2d226c1c35 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -354,6 +354,11 @@ CFile.prototype["getFontByID"] = function(ID) return this._getFontByID(ID); }; +CFile.prototype["getGIDByUnicode"] = function(ID) +{ + return this._getGIDByUnicode(ID); +}; + CFile.prototype["setCMap"] = function(memoryBuffer) { if (!this.nativeFile) diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js index fb8f660041..ab71ce4199 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js @@ -162,6 +162,12 @@ CFile.prototype._getFontByID = function(ID) return g_native_drawing_file["GetFontBinary"](ID); }; +CFile.prototype._getGIDByUnicode = function(ID) +{ + g_module_pointer.ptr = g_native_drawing_file["GetGIDByUnicode"](ID); + return g_module_pointer; +} + CFile.prototype._getInteractiveFormsFonts = function(type) { g_module_pointer.ptr = g_native_drawing_file["GetInteractiveFormsFonts"](type); diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js index be1c6a32d4..f54acfa4b1 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js @@ -263,6 +263,34 @@ CFile.prototype._getFontByID = function(ID) return res; }; +CFile.prototype._getGIDByUnicode = function(ID) +{ + if (ID === undefined) + return null; + + let idBuffer = ID.toUtf8(); + let idPointer = Module["_malloc"](idBuffer.length); + Module["HEAP8"].set(idBuffer, idPointer); + g_module_pointer.ptr = Module["_GetGIDByUnicode"](this.nativeFile, idPointer); + Module["_free"](idPointer); + + let reader = g_module_pointer.getReader(); + if (!reader) + return null; + + let res = {}; + let nFontLength = reader.readInt(); + for (let i = 0; i < nFontLength; i++) + { + let np1 = reader.readInt(); + let np2 = reader.readInt(); + res[np2] = np1; + } + + g_module_pointer.free(); + return res; +} + CFile.prototype._getInteractiveFormsFonts = function(type) { g_module_pointer.ptr = Module["_GetInteractiveFormsFonts"](this.nativeFile, type); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index e73a0557b8..3fa678bbf2 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -150,6 +150,10 @@ WASM_EXPORT BYTE* GetFontBinary(CDrawingFile* pFile, char* path) { return pFile->GetFontBinary(std::string(path)); } +WASM_EXPORT BYTE* GetGIDByUnicode(CDrawingFile* pFile, char* path) +{ + return pFile->GetGIDByUnicode(std::string(path)); +} WASM_EXPORT void DestroyTextInfo(CDrawingFile* pFile) { return pFile->DestroyTextInfo(); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 82fd656dca..0fbb058f35 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -938,6 +938,36 @@ void ReadInteractiveFormsFonts(CDrawingFile* pGrFile, int nType) std::cout << "font" << j << ".txt"; } + if (pFont) + free(pFont); + + if (false) + continue; + + pFont = GetGIDByUnicode(pGrFile, (char*)sFontName.c_str()); + nLength2 = READ_INT(pFont); + i2 = 4; + nLength2 -= 4; + + while (i2 < nLength2) + { + int nFontLength = READ_INT(pFont + i2); + i2 += 4; + + std::cout << std::endl << "CIDtoUnicode" << std::endl; + + for (int j = 0; j < nFontLength; ++j) + { + unsigned int code = READ_INT(pFont + i2); + i2 += 4; + unsigned int unicode = READ_INT(pFont + i2); + i2 += 4; + std::cout << "cid\t" << code << "\tunicode\t" << unicode << std::endl; + } + + std::cout << std::endl; + } + if (pFont) free(pFont); } diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index a5dac89843..2d0aa9558e 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -445,6 +445,12 @@ BYTE* CPdfFile::GetAnnotStandardFonts() return NULL; return m_pInternal->pReader->GetFonts(true); } +BYTE* CPdfFile::GetGIDByUnicode(const std::wstring& wsFontName) +{ + if (!m_pInternal->pReader) + return NULL; + return m_pInternal->pReader->GetGIDByUnicode(wsFontName); +} std::wstring CPdfFile::GetFontPath(const std::wstring& wsFontName) { if (!m_pInternal->pReader) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 9c89debeb5..4e9b5ae288 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -145,6 +145,7 @@ public: BYTE* GetAPWidget (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget = -1, const char* sView = NULL, const char* sBView = NULL); BYTE* GetAPAnnots (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot = -1, const char* sView = NULL); BYTE* GetButtonIcon(int nBackgroundColor, int nPageIndex, bool bBase64 = false, int nBWidget = -1, const char* sIView = NULL); + BYTE* GetGIDByUnicode(const std::wstring& wsFontName); std::wstring GetFontPath(const std::wstring& wsFontName); std::wstring GetEmbeddedFontPath(const std::wstring& wsFontName); diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 733998c52d..b14b1a0eb1 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -779,7 +779,10 @@ bool CPdfReader::RedactPage(int _nPageIndex, double* arrRedactBox, int nLengthX8 PDFDoc* pDoc = NULL; int nPageIndex = GetPageIndex(_nPageIndex, &pDoc); if (nPageIndex < 0 || !pDoc) + { + free(pChanges); return false; + } Page* pPage = pDoc->getCatalog()->getPage(nPageIndex); PDFRectangle* cropBox = pPage->getCropBox(); @@ -1099,6 +1102,61 @@ std::wstring CPdfReader::GetInfo() return sRes; } +BYTE* CPdfReader::GetGIDByUnicode(const std::wstring& wsFontName) +{ + std::map::const_iterator oIter = m_mFonts.find(wsFontName); + if (oIter == m_mFonts.end()) + return NULL; + + NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage(); + if (!pStorage) + return NULL; + NSFonts::IFontStream* pStream = pStorage->Get(oIter->second); + if (!pStream) + return NULL; + + std::map mGIDbyUnicode; + bool bFind = false; + for (CPdfReaderContext* pPDFContext : m_vPDFContext) + { + PdfReader::CPdfFontList* pFontList = pPDFContext->m_pFontList; + + const std::map& mapFonts = pFontList->GetFonts(); + for (std::map::const_iterator it = mapFonts.begin(); it != mapFonts.end(); ++it) + { + PdfReader::TFontEntry* pEntry = it->second; + if (!pEntry || pEntry->wsFilePath != oIter->second) + continue; + bFind = true; + + for (int i = 0; i < pEntry->unLenUnicode; ++i) + { + if (pEntry->pCodeToUnicode[i]) + mGIDbyUnicode[i] = pEntry->pCodeToUnicode[i]; + } + + break; + } + + if (bFind) + break; + } + + NSWasm::CData oRes; + oRes.SkipLen(); + oRes.AddInt(mGIDbyUnicode.size()); + + for (std::map::const_iterator it = mGIDbyUnicode.begin(); it != mGIDbyUnicode.end(); ++it) + { + oRes.AddInt(it->first); + oRes.AddInt(it->second); + } + + oRes.WriteLen(); + BYTE* bRes = oRes.GetBuffer(); + oRes.ClearWithoutAttack(); + return bRes; +} std::wstring CPdfReader::GetFontPath(const std::wstring& wsFontName, bool bSave) { std::map::const_iterator oIter = m_mFonts.find(wsFontName); diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 4a35f79963..e60a11695c 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -98,6 +98,7 @@ public: void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY); void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak); std::wstring GetInfo(); + BYTE* GetGIDByUnicode(const std::wstring& wsFontName); std::wstring GetFontPath(const std::wstring& wsFontName, bool bSave = true); std::wstring ToXml(const std::wstring& wsXmlPath, bool isPrintStreams = false); void ChangeLength(DWORD nLength) { m_nFileLength = nLength; } From 8144f98bb8976ba0cf3b8cfc0a0825181703e748 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Tue, 16 Dec 2025 16:08:23 +0300 Subject: [PATCH 098/125] fix rotWithShape --- OOXML/PPTXFormat/Logic/UniFill.cpp | 34 ++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/OOXML/PPTXFormat/Logic/UniFill.cpp b/OOXML/PPTXFormat/Logic/UniFill.cpp index 2da1711814..7e4b16b8c9 100644 --- a/OOXML/PPTXFormat/Logic/UniFill.cpp +++ b/OOXML/PPTXFormat/Logic/UniFill.cpp @@ -213,10 +213,10 @@ namespace PPTX switch (_at) { case 0: - pReader->Skip(4); // dpi + pFill->dpi = pReader->GetLong(); break; case 1: - pReader->Skip(1); // rotWithShape + pFill->rotWithShape = pReader->GetBool(); break; default: break; @@ -448,9 +448,8 @@ namespace PPTX } m_type = blipFill; - Fill = pFill; - break; - } + Fill = pFill; + }break; case FILL_TYPE_GRAD: { pReader->Skip(1); @@ -535,9 +534,8 @@ namespace PPTX } m_type = gradFill; - Fill = pFill; - break; - } + Fill = pFill; + }break; case FILL_TYPE_PATT: { pReader->Skip(1); @@ -587,8 +585,8 @@ namespace PPTX m_type = pattFill; Fill = pFill; - break; - } + + }break; case FILL_TYPE_SOLID: { pReader->Skip(1); // type + len @@ -599,24 +597,20 @@ namespace PPTX pFill->Color.fromPPTY(pReader); m_type = solidFill; - Fill = pFill; - break; - } + Fill = pFill; + }break; case FILL_TYPE_NOFILL: { m_type = noFill; - Fill = new PPTX::Logic::NoFill(); - break; - } + Fill = new PPTX::Logic::NoFill(); + }break; case FILL_TYPE_GRP: { m_type = grpFill; - Fill = new PPTX::Logic::GrpFill(); - break; - } + Fill = new PPTX::Logic::GrpFill(); + }break; } } - pReader->Seek(read_end); } std::wstring UniFill::toXML() const From ac5c7d6d7649bdf6fe27b36920ea4597ab6ffaf8 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Tue, 16 Dec 2025 17:09:33 +0300 Subject: [PATCH 099/125] refactoring --- OOXML/PPTXFormat/Logic/Fills/GradFill.cpp | 86 +++++ OOXML/PPTXFormat/Logic/Fills/GradFill.h | 1 + OOXML/PPTXFormat/Logic/Fills/PattFill.cpp | 46 +++ OOXML/PPTXFormat/Logic/Fills/PattFill.h | 4 +- OOXML/PPTXFormat/Logic/Fills/SolidFill.cpp | 11 + OOXML/PPTXFormat/Logic/Fills/SolidFill.h | 3 +- OOXML/PPTXFormat/Logic/UniFill.cpp | 382 +-------------------- 7 files changed, 156 insertions(+), 377 deletions(-) diff --git a/OOXML/PPTXFormat/Logic/Fills/GradFill.cpp b/OOXML/PPTXFormat/Logic/Fills/GradFill.cpp index 0e8013c2a2..9a47cd54cc 100644 --- a/OOXML/PPTXFormat/Logic/Fills/GradFill.cpp +++ b/OOXML/PPTXFormat/Logic/Fills/GradFill.cpp @@ -216,6 +216,92 @@ namespace PPTX pWriter->EndRecord(); } + + void GradFill::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + pReader->Skip(4); // len + BYTE _type = pReader->GetUChar(); // FILL_TYPE_GRAD + LONG _e = pReader->GetPos() + pReader->GetRecordSize() + 4; + + pReader->Skip(1); + + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + + switch (_at) + { + case 0: + flip = pReader->GetUChar(); + break; + case 1: + rotWithShape = pReader->GetBool(); + break; + default: + break; + } + } + + while (pReader->GetPos() < _e) + { + BYTE rec = pReader->GetUChar(); + + switch (rec) + { + case 0: + { + LONG _s1 = pReader->GetPos(); + LONG _e1 = _s1 + pReader->GetLong() + 4; + + ULONG _count = pReader->GetULong(); + for (ULONG i = 0; i < _count; ++i) + { + if (pReader->GetPos() >= _e1) + break; + + pReader->Skip(1); // type + pReader->Skip(4); // len + + size_t _countGs = GsLst.size(); + GsLst.push_back(Gs()); + + pReader->Skip(1); // start attr + pReader->Skip(1); // pos type + GsLst[_countGs].pos = pReader->GetLong(); + pReader->Skip(1); // end attr + + pReader->Skip(1); + GsLst[_countGs].color.fromPPTY(pReader); + } + + pReader->Seek(_e1); + }break; + case 1: + { + lin = new PPTX::Logic::Lin(); + lin->fromPPTY(pReader); + }break; + case 2: + { + path = new PPTX::Logic::Path(); + path->fromPPTY(pReader); + }break; + case 3: + { + tileRect = new PPTX::Logic::Rect(); + tileRect->m_name = L"a:tileRect"; + tileRect->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + } + } + } + pReader->Seek(_e); + } void GradFill::Merge(GradFill& fill)const { if(flip.IsInit()) diff --git a/OOXML/PPTXFormat/Logic/Fills/GradFill.h b/OOXML/PPTXFormat/Logic/Fills/GradFill.h index f7160a2dd5..7c149cd5e8 100644 --- a/OOXML/PPTXFormat/Logic/Fills/GradFill.h +++ b/OOXML/PPTXFormat/Logic/Fills/GradFill.h @@ -62,6 +62,7 @@ namespace PPTX virtual std::wstring toXML() const; virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); void Merge(GradFill& fill) const; UniColor GetFrontColor() const; diff --git a/OOXML/PPTXFormat/Logic/Fills/PattFill.cpp b/OOXML/PPTXFormat/Logic/Fills/PattFill.cpp index c5405f4587..1a38749e37 100644 --- a/OOXML/PPTXFormat/Logic/Fills/PattFill.cpp +++ b/OOXML/PPTXFormat/Logic/Fills/PattFill.cpp @@ -159,6 +159,52 @@ namespace PPTX pWriter->EndRecord(); } + void PattFill::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + pReader->Skip(4); // len + BYTE _type = pReader->GetUChar(); // FILL_TYPE_PATT + LONG _e = pReader->GetPos() + pReader->GetRecordSize() + 4; + + pReader->Skip(1); + + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + + switch (_at) + { + case 0: + prst = pReader->GetUChar(); + break; + default: + break; + } + } + + while (pReader->GetPos() < _e) + { + BYTE rec = pReader->GetUChar(); + + switch (rec) + { + case 0: + { + fgClr.fromPPTY(pReader); + }break; + case 1: + { + bgClr.fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + } + } + } + pReader->Seek(_e); + } void PattFill::FillParentPointersForChilds() { fgClr.SetParentPointer(this); diff --git a/OOXML/PPTXFormat/Logic/Fills/PattFill.h b/OOXML/PPTXFormat/Logic/Fills/PattFill.h index 7a1807ef9c..881f858a52 100644 --- a/OOXML/PPTXFormat/Logic/Fills/PattFill.h +++ b/OOXML/PPTXFormat/Logic/Fills/PattFill.h @@ -56,11 +56,11 @@ namespace PPTX virtual void fromXML(XmlUtils::CXmlNode& node); virtual std::wstring toXML() const; - virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); - public: nullable_limit prst; UniColor fgClr; diff --git a/OOXML/PPTXFormat/Logic/Fills/SolidFill.cpp b/OOXML/PPTXFormat/Logic/Fills/SolidFill.cpp index f9ae685662..f22ac498a6 100644 --- a/OOXML/PPTXFormat/Logic/Fills/SolidFill.cpp +++ b/OOXML/PPTXFormat/Logic/Fills/SolidFill.cpp @@ -109,6 +109,17 @@ namespace PPTX pWriter->EndRecord(); } + void SolidFill::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + pReader->Skip(4); // len + BYTE _type = pReader->GetUChar(); // FILL_TYPE_SOLID + LONG _e = pReader->GetPos() + pReader->GetRecordSize() + 4; + + pReader->Skip(1); + + Color.fromPPTY(pReader); + pReader->Seek(_e); + } void SolidFill::Merge(SolidFill& fill)const { if(Color.is_init()) diff --git a/OOXML/PPTXFormat/Logic/Fills/SolidFill.h b/OOXML/PPTXFormat/Logic/Fills/SolidFill.h index bcee6b08c1..4efe29c865 100644 --- a/OOXML/PPTXFormat/Logic/Fills/SolidFill.h +++ b/OOXML/PPTXFormat/Logic/Fills/SolidFill.h @@ -53,9 +53,10 @@ namespace PPTX virtual void fromXML(XmlUtils::CXmlNode& node); virtual std::wstring toXML() const; - virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); void Merge(SolidFill& fill) const; diff --git a/OOXML/PPTXFormat/Logic/UniFill.cpp b/OOXML/PPTXFormat/Logic/UniFill.cpp index 7e4b16b8c9..4b40eaa49b 100644 --- a/OOXML/PPTXFormat/Logic/UniFill.cpp +++ b/OOXML/PPTXFormat/Logic/UniFill.cpp @@ -186,415 +186,49 @@ namespace PPTX void UniFill::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) { LONG read_start = pReader->GetPos(); - LONG read_end = read_start + pReader->GetLong() + 4; + LONG read_end = read_start + pReader->GetRecordSize() + 4; m_type = notInit; if (pReader->GetPos() < read_end) { BYTE _type = pReader->GetUChar(); - LONG _e = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Seek(read_start); switch (_type) { case FILL_TYPE_BLIP: { - pReader->Skip(1); - PPTX::Logic::BlipFill* pFill = new PPTX::Logic::BlipFill(); pFill->m_namespace = _T("a"); - - while (true) - { - BYTE _at = pReader->GetUChar_TypeNode(); - if (_at == NSBinPptxRW::g_nodeAttributeEnd) - break; - - switch (_at) - { - case 0: - pFill->dpi = pReader->GetLong(); - break; - case 1: - pFill->rotWithShape = pReader->GetBool(); - break; - default: - break; - } - } - - while (pReader->GetPos() < _e) - { - BYTE rec = pReader->GetUChar(); - - switch (rec) - { - case 0: - { - LONG _s2 = pReader->GetPos(); - LONG _e2 = _s2 + pReader->GetLong() + 4; - - pReader->Skip(1); - - while (true) - { - BYTE _at = pReader->GetUChar_TypeNode(); - if (NSBinPptxRW::g_nodeAttributeEnd == _at) - break; - - if (_at == 0) - pReader->Skip(1); - } - - while (pReader->GetPos() < _e2) - { - BYTE _t = pReader->GetUChar(); - - switch (_t) - { - case 0: - case 1: - { - // id. embed / link - pReader->Skip(4); - }break; - case 10: - case 11: - { - // id. embed / link - pReader->GetString2(); - }break; - case 2: - { - if (!pFill->blip.is_init()) - pFill->blip = new PPTX::Logic::Blip(); - - pReader->Skip(4); - ULONG count_effects = pReader->GetULong(); - for (ULONG _eff = 0; _eff < count_effects; ++_eff) - { - pReader->Skip(1); // type - - pFill->blip->Effects.push_back(UniEffect()); - pFill->blip->Effects.back().fromPPTY(pReader); - - if (false == pFill->blip->Effects.back().is_init()) - { - pFill->blip->Effects.pop_back(); - } - } - }break; - case 3: - { - pReader->Skip(6); // len + start attributes + type - - // ------------------- - std::wstring strUrl = pReader->GetString2(true); - std::wstring strTempFile; - std::wstring strOrigBase64; - - - if (0 == strUrl.find(_T("data:"))) - { - bool bBase64 = false; - - strOrigBase64 = strUrl; - int nFind = (int)strUrl.find(_T(",")); - - std::wstring sImageExtension; - - std::wstring sFormatDataString = XmlUtils::GetLower(strUrl.substr(5, nFind - 5)); - { - int nFind1 = (int)sFormatDataString.find(_T("base64")); - if (nFind1 >=0 ) bBase64 = true; - - nFind1 = (int)sFormatDataString.find(_T("image/")); - if (nFind1>=0) - { - int nFind2 = (int)sFormatDataString.find(_T(";")); - if (nFind2 < 0) nFind2 = (int)sFormatDataString.length(); - - sImageExtension = sFormatDataString.substr(nFind1 + 6, nFind2 - 6 - nFind1); - } - } - strUrl.erase(0, nFind + 1); - - std::string __s = std::string(strUrl.begin(), strUrl.end()); - int len =(int)__s.length(); - BYTE* pDstBuffer = NULL; - int dstLen = 0; - - if (true)//(bBase64) - { - bBase64 = true; - int dstLenTemp = Base64::Base64DecodeGetRequiredLength(len); - - pDstBuffer = new BYTE[dstLenTemp]; - dstLen = dstLenTemp; - Base64::Base64Decode(__s.c_str(), len, pDstBuffer, &dstLen); - } - else - { - pDstBuffer = (BYTE*) __s.c_str(); - dstLen = len; - } - CImageFileFormatChecker checker; - std::wstring detectImageExtension = checker.DetectFormatByData(pDstBuffer, dstLen); - - if (false == detectImageExtension.empty()) - { - sImageExtension = detectImageExtension; - - //папки media может не быть в случае, когда все картинки base64(поскольку файл временный, папку media не создаем) - std::wstring tempFilePath = pReader->m_strFolder + FILE_SEPARATOR_STR; - - OOX::CPath pathTemp = NSFile::CFileBinary::CreateTempFileWithUniqueName(tempFilePath, _T("img")) + _T(".") + sImageExtension; - - NSFile::CFileBinary oTempFile; - oTempFile.CreateFile(pathTemp.GetPath()); - oTempFile.WriteFile((void*)pDstBuffer, (DWORD)dstLen); - oTempFile.CloseFile(); - - strUrl = strTempFile =pathTemp.GetPath(); // strTempFile для удаления - if (bBase64) - { - RELEASEARRAYOBJECTS(pDstBuffer); - } - } - else - {// бяка - strUrl.clear(); - } - } - else - { - if (0 != strUrl.find(_T("http:")) && - 0 != strUrl.find(_T("https:")) && - 0 != strUrl.find(_T("ftp:")) && - 0 != strUrl.find(_T("file:"))) - { - if (0 == strUrl.find(_T("theme"))) - { - strUrl = pReader->m_strFolderExternalThemes + FILE_SEPARATOR_STR + strUrl; - } - else - { - strUrl = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + strUrl; - } - } - } - // ------------------- - - NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = pReader->m_pRels->WriteImage(strUrl, pFill->additionalFiles, pFill->oleData, strOrigBase64); - - // ------------------- - if (!strTempFile.empty()) - { - CDirectory::DeleteFile(strTempFile); - } - // ------------------- - - if (!pFill->blip.is_init()) - pFill->blip = new PPTX::Logic::Blip(); - - pFill->blip->embed = new OOX::RId(oRelsGeneratorInfo.nImageRId); - pFill->blip->imageFilepath = oRelsGeneratorInfo.sFilepathImage; - - if (pFill->blip.is_init()) - pFill->blip->m_namespace = _T("a"); - - if(oRelsGeneratorInfo.nOleRId > 0) - { - pFill->blip->oleRid = OOX::RId((size_t)oRelsGeneratorInfo.nOleRId).get(); - pFill->blip->oleFilepathBin = oRelsGeneratorInfo.sFilepathOle; - } - if(oRelsGeneratorInfo.nMediaRId > 0) - { - pFill->blip->mediaRid = OOX::RId((size_t)oRelsGeneratorInfo.nMediaRId).get(); - pFill->blip->mediaFilepath = oRelsGeneratorInfo.sFilepathMedia; - } - pReader->Skip(1); // end attribute - }break; - default: - { - pReader->SkipRecord(); - }break; - } - } - - pReader->Seek(_e2); - }break; - case 1: - { - pFill->srcRect = new PPTX::Logic::Rect(); - pFill->srcRect->m_name = L"a:srcRect"; - pFill->srcRect->fromPPTY(pReader); - }break; - case 2: - { - pFill->tile = new PPTX::Logic::Tile(); - pFill->tile->fromPPTY(pReader); - }break; - case 3: - { - pFill->stretch = new PPTX::Logic::Stretch(); - pFill->stretch->fromPPTY(pReader); - }break; - default: - { - pReader->SkipRecord(); - } - } - } + pFill->fromPPTY(pReader); m_type = blipFill; Fill = pFill; }break; case FILL_TYPE_GRAD: { - pReader->Skip(1); - PPTX::Logic::GradFill* pFill = new PPTX::Logic::GradFill(); pFill->m_namespace = _T("a"); - - while (true) - { - BYTE _at = pReader->GetUChar_TypeNode(); - if (_at == NSBinPptxRW::g_nodeAttributeEnd) - break; - - switch (_at) - { - case 0: - pFill->flip = pReader->GetUChar(); - break; - case 1: - pFill->rotWithShape = pReader->GetBool(); - break; - default: - break; - } - } - - while (pReader->GetPos() < _e) - { - BYTE rec = pReader->GetUChar(); - - switch (rec) - { - case 0: - { - LONG _s1 = pReader->GetPos(); - LONG _e1 = _s1 + pReader->GetLong() + 4; - - ULONG _count = pReader->GetULong(); - for (ULONG i = 0; i < _count; ++i) - { - if (pReader->GetPos() >= _e1) - break; - - pReader->Skip(1); // type - pReader->Skip(4); // len - - size_t _countGs = pFill->GsLst.size(); - pFill->GsLst.push_back(Gs()); - - pReader->Skip(1); // start attr - pReader->Skip(1); // pos type - pFill->GsLst[_countGs].pos = pReader->GetLong(); - pReader->Skip(1); // end attr - - pReader->Skip(1); - pFill->GsLst[_countGs].color.fromPPTY(pReader); - } - - pReader->Seek(_e1); - }break; - case 1: - { - pFill->lin = new PPTX::Logic::Lin(); - pFill->lin->fromPPTY(pReader); - }break; - case 2: - { - pFill->path = new PPTX::Logic::Path(); - pFill->path->fromPPTY(pReader); - }break; - case 3: - { - pFill->tileRect = new PPTX::Logic::Rect(); - pFill->tileRect->m_name = L"a:tileRect"; - pFill->tileRect->fromPPTY(pReader); - }break; - default: - { - pReader->SkipRecord(); - } - } - } + pFill->fromPPTY(pReader); m_type = gradFill; Fill = pFill; }break; case FILL_TYPE_PATT: { - pReader->Skip(1); PPTX::Logic::PattFill* pFill = new PPTX::Logic::PattFill(); - - while (true) - { - BYTE _at = pReader->GetUChar_TypeNode(); - if (_at == NSBinPptxRW::g_nodeAttributeEnd) - break; - - switch (_at) - { - case 0: - pFill->prst = pReader->GetUChar(); - break; - default: - break; - } - } - - while (pReader->GetPos() < _e) - { - BYTE rec = pReader->GetUChar(); - - switch (rec) - { - case 0: - { - pFill->fgClr.fromPPTY(pReader); - break; - } - case 1: - { - pFill->bgClr.fromPPTY(pReader); - break; - } - default: - { - // пока никаких настроек градиента нет - pReader->SkipRecord(); - } - } - } - pFill->m_namespace = _T("a"); + pFill->fromPPTY(pReader); m_type = pattFill; - Fill = pFill; - + Fill = pFill; }break; case FILL_TYPE_SOLID: { - pReader->Skip(1); // type + len - PPTX::Logic::SolidFill* pFill = new PPTX::Logic::SolidFill(); pFill->m_namespace = _T("a"); - - pFill->Color.fromPPTY(pReader); + pFill->fromPPTY(pReader); m_type = solidFill; Fill = pFill; @@ -602,7 +236,7 @@ namespace PPTX case FILL_TYPE_NOFILL: { m_type = noFill; - Fill = new PPTX::Logic::NoFill(); + Fill = new PPTX::Logic::NoFill(); }break; case FILL_TYPE_GRP: { From a8678c5d10e6274779c0569ab0ae1f728d28a9bb Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 17 Dec 2025 11:10:22 +0300 Subject: [PATCH 100/125] Add _GetGIDByUnicode --- DesktopEditor/graphics/pro/js/drawingfile.json | 1 + 1 file changed, 1 insertion(+) diff --git a/DesktopEditor/graphics/pro/js/drawingfile.json b/DesktopEditor/graphics/pro/js/drawingfile.json index 98efabcb3c..5d6382aaf2 100644 --- a/DesktopEditor/graphics/pro/js/drawingfile.json +++ b/DesktopEditor/graphics/pro/js/drawingfile.json @@ -46,6 +46,7 @@ "_InitializeFontsRanges", "_SetFontBinary", "_GetFontBinary", + "_GetGIDByUnicode", "_IsFontBinaryExist", "_DestroyTextInfo", "_IsNeedCMap", From 8611c5f7813b0b72cbce9234c16c01df0e1fc200 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Wed, 17 Dec 2025 12:39:12 +0300 Subject: [PATCH 101/125] Fix build --- DesktopEditor/fontengine/js/libfont.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DesktopEditor/fontengine/js/libfont.json b/DesktopEditor/fontengine/js/libfont.json index 7585d300a1..83a2b561d8 100644 --- a/DesktopEditor/fontengine/js/libfont.json +++ b/DesktopEditor/fontengine/js/libfont.json @@ -265,15 +265,15 @@ }, { "folder": "../../", - "files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp", "graphics/Matrix.cpp"] + "files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp", "graphics/Matrix.cpp", "graphics/GraphicsPath.cpp"] }, { "folder": "../../agg-2.4/src/", - "files": ["agg_trans_affine.cpp"] + "files": ["agg_trans_affine.cpp", "agg_bezier_arc.cpp"] }, { "folder": "../../raster/", - "files": ["PICT/PICFile.cpp", "PICT/pic.cpp"] + "files": ["PICT/PICFile.cpp"] }, { "folder": "../../graphics/pro/js/qt/raster", From 0da5ad2f4869c4a6439502395370be0c647175d2 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 17 Dec 2025 14:19:57 +0300 Subject: [PATCH 102/125] Fix libfont --- DesktopEditor/fontengine/js/cpp/text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DesktopEditor/fontengine/js/cpp/text.cpp b/DesktopEditor/fontengine/js/cpp/text.cpp index 63503a3dea..a2db6d3b41 100644 --- a/DesktopEditor/fontengine/js/cpp/text.cpp +++ b/DesktopEditor/fontengine/js/cpp/text.cpp @@ -117,7 +117,7 @@ WASM_EXPORT unsigned int ASC_FT_SetCMapForCharCode(FT_Face face, unsigned int un return 0; if ( 0 == face->num_charmaps ) - return unicode; + return 0; unsigned int nCharIndex = 0; From 554d3d0dfdda5b6f34047c972ff7b6de78c01331 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 17 Dec 2025 14:48:15 +0300 Subject: [PATCH 103/125] Fix bug in html --- Common/3dParty/html/css/src/StyleProperties.h | 2 +- HtmlFile2/htmlfile2.cpp | 39 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Common/3dParty/html/css/src/StyleProperties.h b/Common/3dParty/html/css/src/StyleProperties.h index 3aa98429ea..8f55e26d30 100644 --- a/Common/3dParty/html/css/src/StyleProperties.h +++ b/Common/3dParty/html/css/src/StyleProperties.h @@ -104,7 +104,7 @@ namespace NSCSS virtual CValueBase& operator+=(const CValueBase& oValue) { - if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || Empty()) + if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || oValue.Empty()) return *this; *this = oValue; diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp index 577cbb852e..25f752ec87 100644 --- a/HtmlFile2/htmlfile2.cpp +++ b/HtmlFile2/htmlfile2.cpp @@ -332,12 +332,12 @@ void WriteEmptyParagraph(NSStringUtils::CStringBuilder* pXml, bool bVahish = fal if (!bInP) pXml->WriteString(L""); - pXml->WriteString(L""); + pXml->WriteString(L""); if (bVahish) - pXml->WriteString(L""); + pXml->WriteString(L""); - pXml->WriteString(L""); + pXml->WriteString(L""); if (!bInP) pXml->WriteString(L""); @@ -1612,8 +1612,10 @@ private: bool m_bBanUpdatePageData; // Запретить обновление данных о странице? + HtmlTag m_eLastElement; + TState() - : m_bInP(false), m_bInR(false), m_bInT(false), m_bWasPStyle(false), m_bWasSpace(true), m_bInHyperlink(false), m_bBanUpdatePageData(false) + : m_bInP(false), m_bInR(false), m_bInT(false), m_bWasPStyle(false), m_bWasSpace(true), m_bInHyperlink(false), m_bBanUpdatePageData(false), m_eLastElement(HTML_TAG(UNKNOWN)) {} } m_oState; @@ -3539,7 +3541,12 @@ private: } if (HTML_TAG(DIV) != eHtmlTag && HTML_TAG(ASIDE) != eHtmlTag) + { + if (bResult) + m_oState.m_eLastElement = eHtmlTag; + m_oState.m_bBanUpdatePageData = true; + } readNote(oXml, sSelectors, sNote); sSelectors.pop_back(); @@ -3916,6 +3923,9 @@ private: if(m_oLightReader.IsEmptyNode()) return false; + if (HTML_TAG(TABLE) == m_oState.m_eLastElement) + WriteEmptyParagraph(oXml, true); + CTable oTable; CTextSettings oTextSettings{oTS}; oTextSettings.sPStyle.clear(); @@ -4032,7 +4042,6 @@ private: oTable.Shorten(); oTable.CompleteTable(); oTable.ConvertToOOXML(*oXml); - WriteEmptyParagraph(oXml, true); return true; } @@ -4735,11 +4744,21 @@ private: if (!m_oState.m_bInP) return L""; - std::wstring sRStyle = GetStyle(*sSelectors.back().m_pCompiledStyle, false); + NSCSS::CCompiledStyle oMainStyle{*sSelectors.back().m_pCompiledStyle}; + std::wstring sRSettings; - m_oXmlStyle.WriteLiteRStyle(oTS.oAdditionalStyle); - const std::wstring sRSettings = m_oXmlStyle.GetStyle(); - m_oXmlStyle.Clear(); + std::wstring sRStyle = GetStyle(oMainStyle, false); + + if (!oTS.oAdditionalStyle.Empty()) + { + NSCSS::CCompiledStyle oSettingStyle{oTS.oAdditionalStyle}; + + NSCSS::CCompiledStyle::StyleEquation(oMainStyle, oSettingStyle); + + m_oXmlStyle.WriteLiteRStyle(oSettingStyle); + sRSettings = m_oXmlStyle.GetStyle(); + m_oXmlStyle.Clear(); + } std::wstring wsFontSize; @@ -4747,7 +4766,7 @@ private: if (0 != nCalculatedFontChange) { - int nFontSizeLevel{static_cast((sSelectors.back().m_pCompiledStyle->m_oFont.Empty()) ? 3 : GetFontSizeLevel(sSelectors.back().m_pCompiledStyle->m_oFont.GetSize().ToInt(NSCSS::Point) * 2))}; + int nFontSizeLevel{static_cast((oMainStyle.m_oFont.Empty()) ? 3 : GetFontSizeLevel(oMainStyle.m_oFont.GetSize().ToInt(NSCSS::Point) * 2))}; nFontSizeLevel += nCalculatedFontChange; From 52e47745dea3cb3b078e6539a0382eb1fab282e3 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 17 Dec 2025 14:49:11 +0300 Subject: [PATCH 104/125] Added the latex formula processing flag in md --- Common/3dParty/md/md2html.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/3dParty/md/md2html.cpp b/Common/3dParty/md/md2html.cpp index 2257d13b61..068d123fd6 100644 --- a/Common/3dParty/md/md2html.cpp +++ b/Common/3dParty/md/md2html.cpp @@ -5,7 +5,7 @@ namespace Md { -#define MD_PARSER_FLAGS MD_DIALECT_GITHUB | MD_FLAG_NOINDENTEDCODEBLOCKS | MD_HTML_FLAG_SKIP_UTF8_BOM | MD_FLAG_HARD_SOFT_BREAKS | MD_HTML_FLAG_XHTML +#define MD_PARSER_FLAGS MD_DIALECT_GITHUB | MD_FLAG_NOINDENTEDCODEBLOCKS | MD_HTML_FLAG_SKIP_UTF8_BOM | MD_FLAG_HARD_SOFT_BREAKS | MD_HTML_FLAG_XHTML | MD_FLAG_LATEXMATHSPANS #define MD_RENDERER_FLAGS MD_HTML_FLAG_XHTML void ToHtml(const MD_CHAR* pValue, MD_SIZE uSize, void* pData) From f38759d07187cfdd4623f9a7512a7527344cf45f Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 17 Dec 2025 16:34:56 +0300 Subject: [PATCH 105/125] Refactoring --- .../3dParty/html/css/src/StyleProperties.cpp | 54 +++++++------- Common/3dParty/html/css/src/StyleProperties.h | 70 +++++++++++++------ .../Metafile/svg/SvgObjects/CMarker.cpp | 4 +- .../Metafile/svg/SvgObjects/CObjectBase.cpp | 24 +++---- .../raster/Metafile/svg/SvgObjects/CPath.cpp | 6 +- 5 files changed, 90 insertions(+), 68 deletions(-) diff --git a/Common/3dParty/html/css/src/StyleProperties.cpp b/Common/3dParty/html/css/src/StyleProperties.cpp index b6446d04d1..7d5727e253 100644 --- a/Common/3dParty/html/css/src/StyleProperties.cpp +++ b/Common/3dParty/html/css/src/StyleProperties.cpp @@ -25,11 +25,8 @@ namespace NSCSS return true; } - CString::CString() - {} - - CString::CString(const std::wstring &wsValue, unsigned int unLevel, bool bImportant) - : CValueOptional(wsValue, unLevel, bImportant) + CString::CString(const std::wstring& wsValue, unsigned int unLevel, bool bImportant) + : CValueOptional(wsValue, unLevel, bImportant) {} bool CString::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode) @@ -142,6 +139,19 @@ namespace NSCSS return m_oValue.value(); } + bool CString::operator==(const wchar_t* pValue) const + { + if (!m_oValue.has_value()) + return (nullptr == pValue); + + return m_oValue.value() == pValue; + } + + bool CString::operator!=(const wchar_t* pValue) const + { + return !(operator==(pValue)); + } + double CDigit::ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const { if (CValueOptional::Empty()) @@ -172,9 +182,7 @@ namespace NSCSS if (Empty() && !oDigit.Empty()) return oDigit; - CDigit oTemp; - - oTemp.SetValue(operation(m_oValue.value(), oDigit.m_oValue.value())); + CDigit oTemp{operation(m_oValue.value(), oDigit.m_oValue.value()), 0, false}; oTemp.m_unLevel = std::max(m_unLevel, oDigit.m_unLevel); oTemp.m_bImportant = std::max(m_bImportant, oDigit.m_bImportant); @@ -183,15 +191,11 @@ namespace NSCSS } CDigit::CDigit() - : m_enUnitMeasure(None) - {} - - CDigit::CDigit(const double& dValue) - : CValueOptional(dValue, 0, false), m_enUnitMeasure(None) + : m_enUnitMeasure(UnitMeasure::None) {} CDigit::CDigit(const double& dValue, unsigned int unLevel, bool bImportant) - : CValueOptional(dValue, unLevel, bImportant), m_enUnitMeasure(None) + : CValueOptional(dValue, unLevel, bImportant), m_enUnitMeasure(UnitMeasure::None) {} bool CDigit::Zero() const @@ -205,7 +209,7 @@ namespace NSCSS void CDigit::Clear() { CValueOptional::Clear(); - m_enUnitMeasure = None; + m_enUnitMeasure = UnitMeasure::None; } void CDigit::ConvertTo(UnitMeasure enUnitMeasure, double dPrevValue) @@ -289,7 +293,7 @@ namespace NSCSS bool CDigit::operator!=(const CDigit &oDigit) const { - return !(*this == oDigit); + return !(operator==(oDigit)); } CDigit CDigit::operator+(const CDigit &oDigit) const @@ -331,11 +335,11 @@ namespace NSCSS if (Empty()) { - *this = oDigit; + operator=(oDigit); return *this; } else if (NSCSS::Percent == oDigit.m_enUnitMeasure && !Empty()) - *this *= oDigit.m_oValue.value() / 100.; + operator*=(oDigit.m_oValue.value() / 100.); else m_oValue.value() += oDigit.ToDouble(m_enUnitMeasure); @@ -345,7 +349,7 @@ namespace NSCSS return *this; } - CDigit &CDigit::operator+=(double dValue) + CDigit &CDigit::operator+=(const double& dValue) { if (Empty()) m_oValue = dValue; @@ -355,7 +359,7 @@ namespace NSCSS return *this; } - CDigit &CDigit::operator-=(double dValue) + CDigit &CDigit::operator-=(const double& dValue) { if (Empty()) m_oValue = -dValue; @@ -365,7 +369,7 @@ namespace NSCSS return *this; } - CDigit &CDigit::operator*=(double dValue) + CDigit &CDigit::operator*=(const double& dValue) { if (!Empty()) m_oValue.value() *= dValue; @@ -373,7 +377,7 @@ namespace NSCSS return *this; } - CDigit &CDigit::operator/=(double dValue) + CDigit &CDigit::operator/=(const double& dValue) { if (!Empty()) m_oValue.value() /= dValue; @@ -381,12 +385,6 @@ namespace NSCSS return *this; } - CDigit &CDigit::operator =(double dValue) - { - m_oValue = dValue; - return *this; - } - bool CDigit::SetValue(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode) { if (wsValue.empty() || (CHECK_CONDITIONS && !bHardMode)) diff --git a/Common/3dParty/html/css/src/StyleProperties.h b/Common/3dParty/html/css/src/StyleProperties.h index 8f55e26d30..61181ef8e7 100644 --- a/Common/3dParty/html/css/src/StyleProperties.h +++ b/Common/3dParty/html/css/src/StyleProperties.h @@ -102,6 +102,13 @@ namespace NSCSS return *this; } + virtual CValueBase& operator =(const T& oValue) + { + m_oValue = oValue; + + return *this; + } + virtual CValueBase& operator+=(const CValueBase& oValue) { if (m_unLevel > oValue.m_unLevel || (m_bImportant && !oValue.m_bImportant) || oValue.Empty()) @@ -117,14 +124,11 @@ namespace NSCSS class CValueOptional : public CValueBase> { protected: - CValueOptional() - : CValueBase>() - {} + CValueOptional() = default; - CValueOptional(const T& oValue, unsigned int unLevel, bool bImportant) - : CValueBase>(oValue, unLevel, bImportant) + CValueOptional(const T& oValue, unsigned int unLevel = 0, bool bImportant = false) + : CValueBase>(oValue, unLevel, bImportant) {} - public: virtual bool Empty() const override { @@ -144,13 +148,20 @@ namespace NSCSS return this->m_oValue.value() == oValue; } + + virtual CValueOptional& operator=(const T& oValue) + { + this->m_oValue = oValue; + + return *this; + } }; class CString : public CValueOptional { public: - CString(); - CString(const std::wstring& wsValue, unsigned int unLevel, bool bImportant = false); + CString() = default; + CString(const std::wstring& wsValue, unsigned int unLevel = 0, bool bImportant = false); bool SetValue(const std::wstring& wsValue, unsigned int unLevel, bool bHardMode) override; bool SetValue(const std::wstring& wsValue, const std::vector& arValiableValues, unsigned int unLevel, bool bHardMode); @@ -161,20 +172,18 @@ namespace NSCSS int ToInt() const override; double ToDouble() const override; std::wstring ToWString() const override; + + bool operator==(const wchar_t* pValue) const; + bool operator!=(const wchar_t* pValue) const; + + using CValueOptional::operator=; }; class CDigit : public CValueOptional { - UnitMeasure m_enUnitMeasure; - - double ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const; - - template - CDigit ApplyOperation(const CDigit& oDigit, Operation operation) const; public: CDigit(); - CDigit(const double& dValue); - CDigit(const double& dValue, unsigned int unLevel, bool bImportant = false); + CDigit(const double& dValue, unsigned int unLevel = 0, bool bImportant = false); bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override; bool SetValue(const CDigit& oValue); @@ -210,11 +219,19 @@ namespace NSCSS CDigit& operator+=(const CDigit& oDigit); CDigit& operator-=(const CDigit& oDigit); - CDigit& operator+=(double dValue); - CDigit& operator-=(double dValue); - CDigit& operator*=(double dValue); - CDigit& operator/=(double dValue); - CDigit& operator =(double dValue); + CDigit& operator+=(const double& dValue); + CDigit& operator-=(const double& dValue); + CDigit& operator*=(const double& dValue); + CDigit& operator/=(const double& dValue); + + using CValueOptional::operator=; + private: + UnitMeasure m_enUnitMeasure; + + double ConvertValue(double dPrevValue, UnitMeasure enUnitMeasure) const; + + template + CDigit ApplyOperation(const CDigit& oDigit, Operation operation) const; }; struct TRGB @@ -316,6 +333,8 @@ namespace NSCSS static TRGB ConvertHEXtoRGB(const std::wstring& wsValue); static std::wstring ConvertRGBtoHEX(const TRGB& oValue); + + using CValueOptional::operator=; private: CDigit m_oOpacity; @@ -365,12 +384,12 @@ namespace NSCSS bool operator==(const CMatrix& oMatrix) const; CMatrix& operator+=(const CMatrix& oMatrix); CMatrix& operator-=(const CMatrix& oMatrix); + + using CValueBase::operator=; }; class CEnum : public CValueOptional { - int m_nDefaultValue; - std::map m_mMap; public: CEnum(); @@ -378,9 +397,14 @@ namespace NSCSS void SetMapping(const std::map& mMap, int nDefaulvalue = -1); int ToInt() const override; + + using CValueOptional::operator=; private: double ToDouble() const override; std::wstring ToWString() const override; + + int m_nDefaultValue; + std::map m_mMap; }; // PROPERTIES diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp index 0f9b225c53..ecd99ba8b5 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CMarker.cpp @@ -8,8 +8,8 @@ namespace SVG : CObject(oReader), m_enUnits{EMarkerUnits::StrokeWidth}, m_enOrient{EMarkerOrient::Angle}, m_dAngle(0.), m_oBounds{0., 0., 0., 0.} { - m_oWindow.m_oWidth.SetValue(3); - m_oWindow.m_oHeight.SetValue(3); + m_oWindow.m_oWidth.SetValue(3, NSCSS::Pixel); + m_oWindow.m_oHeight.SetValue(3, NSCSS::Pixel); } ObjectType CMarker::GetType() const diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp index 1524a382bf..4538464abb 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CObjectBase.cpp @@ -153,7 +153,7 @@ namespace SVG bool CObject::ApplyClip(IRenderer *pRenderer, const TClip *pClip, const CSvgFile *pFile, const TBounds &oBounds) const { - if (NULL == pRenderer || NULL == pClip || NULL == pFile || pClip->m_oHref.Empty() || NSCSS::NSProperties::ColorType::ColorUrl != pClip->m_oHref.GetType()) + if (NULL == pRenderer || NULL == pClip || NULL == pFile || pClip->m_oHref.Empty() || NSCSS::NSProperties::EColorType::ColorUrl != pClip->m_oHref.GetType()) return false; if (pClip->m_oRule == L"evenodd") @@ -169,7 +169,7 @@ namespace SVG bool CObject::ApplyMask(IRenderer *pRenderer, const NSCSS::NSProperties::CColor *pMask, const CSvgFile *pFile, const TBounds &oBounds) const { - if (NULL == pRenderer || NULL == pMask || NULL == pFile || NSCSS::NSProperties::ColorType::ColorUrl != pMask->GetType()) + if (NULL == pRenderer || NULL == pMask || NULL == pFile || NSCSS::NSProperties::EColorType::ColorUrl != pMask->GetType()) return false; return ApplyDef(pRenderer, pFile, pMask->ToWString(), oBounds); @@ -358,7 +358,7 @@ namespace SVG bool CRenderedObject::ApplyStroke(IRenderer *pRenderer, const TStroke *pStroke, bool bUseDefault, const CRenderedObject* pContextObject) const { - if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty()))) + if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::EColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty()))) { pRenderer->put_PenSize(0); return false; @@ -369,12 +369,12 @@ namespace SVG if (Equals(0., dStrokeWidth)) dStrokeWidth = 1.; - if (NSCSS::NSProperties::ColorType::ColorContextFill == pStroke->m_oColor.GetType() && NULL != pContextObject) + if (NSCSS::NSProperties::EColorType::ColorContextFill == pStroke->m_oColor.GetType() && NULL != pContextObject) pRenderer->put_PenColor(pContextObject->m_oStyles.m_oFill.ToInt()); - else if (NSCSS::NSProperties::ColorType::ColorContextStroke == pStroke->m_oColor.GetType() && NULL != pContextObject) + else if (NSCSS::NSProperties::EColorType::ColorContextStroke == pStroke->m_oColor.GetType() && NULL != pContextObject) pRenderer->put_PenColor(pContextObject->m_oStyles.m_oStroke.m_oColor.ToInt()); else - pRenderer->put_PenColor((pStroke->m_oColor.Empty() || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType()) ? 0 : pStroke->m_oColor.ToInt()); + pRenderer->put_PenColor((pStroke->m_oColor.Empty() || NSCSS::NSProperties::EColorType::ColorNone == pStroke->m_oColor.GetType()) ? 0 : pStroke->m_oColor.ToInt()); pRenderer->put_PenSize(dStrokeWidth); pRenderer->put_PenAlpha(255. * pStroke->m_oColor.GetOpacity()); @@ -401,18 +401,18 @@ namespace SVG bool CRenderedObject::ApplyFill(IRenderer *pRenderer, const NSCSS::NSProperties::CColor *pFill, const CSvgFile *pFile, bool bUseDefault, const CRenderedObject* pContextObject) const { - if (NULL == pRenderer || NULL == pFill || NSCSS::NSProperties::ColorType::ColorNone == pFill->GetType() || (!bUseDefault && pFill->Empty())) + if (NULL == pRenderer || NULL == pFill || NSCSS::NSProperties::EColorType::ColorNone == pFill->GetType() || (!bUseDefault && pFill->Empty())) { pRenderer->put_BrushType(c_BrushTypeNoFill); return false; } - else if (NSCSS::NSProperties::ColorType::ColorHEX == pFill->GetType() || - NSCSS::NSProperties::ColorType::ColorRGB == pFill->GetType()) + else if (NSCSS::NSProperties::EColorType::ColorHEX == pFill->GetType() || + NSCSS::NSProperties::EColorType::ColorRGB == pFill->GetType()) { pRenderer->put_BrushColor1((pFill->Empty() && bUseDefault) ? 0 : pFill->ToInt()); pRenderer->put_BrushType(c_BrushTypeSolid); } - else if (NSCSS::NSProperties::ColorType::ColorUrl == pFill->GetType()) + else if (NSCSS::NSProperties::EColorType::ColorUrl == pFill->GetType()) { if (!ApplyDef(pRenderer, pFile, pFill->ToWString(), GetBounds())) { @@ -425,12 +425,12 @@ namespace SVG return false; } } - else if (NSCSS::NSProperties::ColorType::ColorContextFill == pFill->GetType() && NULL != pContextObject) + else if (NSCSS::NSProperties::EColorType::ColorContextFill == pFill->GetType() && NULL != pContextObject) { if (!ApplyFill(pRenderer, &pContextObject->m_oStyles.m_oFill, pFile, bUseDefault, pContextObject)) return false; } - else if (NSCSS::NSProperties::ColorType::ColorContextStroke == pFill->GetType() && NULL != pContextObject) + else if (NSCSS::NSProperties::EColorType::ColorContextStroke == pFill->GetType() && NULL != pContextObject) { if (!ApplyFill(pRenderer, &pContextObject->m_oStyles.m_oStroke.m_oColor, pFile, bUseDefault, pContextObject)) return false; diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CPath.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CPath.cpp index bfdd74d6bf..c3153a5270 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CPath.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CPath.cpp @@ -566,7 +566,7 @@ namespace SVG #define CALCULATE_ANGLE(firstPoint, secondPoint) std::atan2(secondPoint.dY - firstPoint.dY, secondPoint.dX - firstPoint.dX) * 180. / M_PI - if (!m_oMarkers.m_oStart.Empty() && NSCSS::NSProperties::ColorType::ColorUrl == m_oMarkers.m_oStart.GetType()) + if (!m_oMarkers.m_oStart.Empty() && NSCSS::NSProperties::EColorType::ColorUrl == m_oMarkers.m_oStart.GetType()) { CMarker *pStartMarker = dynamic_cast(pFile->GetMarkedObject(m_oMarkers.m_oStart.ToWString())); @@ -610,7 +610,7 @@ namespace SVG } } - if (!m_oMarkers.m_oMid.Empty() && NSCSS::NSProperties::ColorType::ColorUrl == m_oMarkers.m_oMid.GetType()) + if (!m_oMarkers.m_oMid.Empty() && NSCSS::NSProperties::EColorType::ColorUrl == m_oMarkers.m_oMid.GetType()) { CMarker *pMidMarker = dynamic_cast(pFile->GetMarkedObject(m_oMarkers.m_oMid.ToWString())); @@ -638,7 +638,7 @@ namespace SVG } } - if (!m_oMarkers.m_oEnd.Empty() && NSCSS::NSProperties::ColorType::ColorUrl == m_oMarkers.m_oEnd.GetType()) + if (!m_oMarkers.m_oEnd.Empty() && NSCSS::NSProperties::EColorType::ColorUrl == m_oMarkers.m_oEnd.GetType()) { CMarker *pEndMarker = dynamic_cast(pFile->GetMarkedObject(m_oMarkers.m_oEnd.ToWString())); From 43ba8fca2124702535b7c2d1c00e4b1ffe9cc9b3 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Wed, 17 Dec 2025 17:30:51 +0300 Subject: [PATCH 106/125] fix bug #71085 --- OdfFile/Reader/Format/table_xlsx.cpp | 356 +++++++++++++-------------- 1 file changed, 178 insertions(+), 178 deletions(-) diff --git a/OdfFile/Reader/Format/table_xlsx.cpp b/OdfFile/Reader/Format/table_xlsx.cpp index a441aa0eeb..994d07bd71 100644 --- a/OdfFile/Reader/Format/table_xlsx.cpp +++ b/OdfFile/Reader/Format/table_xlsx.cpp @@ -723,143 +723,69 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context) const common_value_and_type_attlist & attr = attlist_.common_value_and_type_attlist_; std::wstring formula = attlist_.table_formula_.get_value_or(L""); - -// вычислить стиль для ячейки + - std::wstring cellStyleName = attlist_.table_style_name_.get_value_or(L""); - std::wstring columnStyleName = Context.get_table_context().default_column_cell_style(); - std::wstring rowStyleName = Context.get_table_context().default_row_cell_style(); + if (attlist_.table_number_columns_repeated_ < 199 && last_cell_) last_cell_ = false; - if (attlist_.table_number_columns_repeated_ > 1) - columnStyleName.clear(); // могут быть разные стили колонок Book 24.ods + unsigned int cell_repeated_max = Context.current_table_column() + attlist_.table_number_columns_repeated_ + 1; - odf_read_context & odfContext = Context.root()->odf_context(); + std::wstring rowStyleName = Context.get_table_context().default_row_cell_style(); + std::wstring cellStyleName = attlist_.table_style_name_.get_value_or(L""); - style_instance *defaultCellStyle = NULL, *defaultColumnCellStyle = NULL, *defaultRowCellStyle = NULL, *cellStyle = NULL; - try - { - if (is_present_hyperlink_) - { - defaultCellStyle = odfContext.styleContainer().style_by_name(L"Hyperlink", style_family::TableCell, true); - } - if (!defaultCellStyle) - { - defaultCellStyle = odfContext.styleContainer().style_default_by_type(style_family::TableCell); - } - - defaultColumnCellStyle = odfContext.styleContainer().style_by_name(columnStyleName, style_family::TableCell, false); - defaultRowCellStyle = odfContext.styleContainer().style_by_name(rowStyleName, style_family::TableCell, false); - cellStyle = odfContext.styleContainer().style_by_name(cellStyleName, style_family::TableCell, false); - } - catch(...) - { - _CP_LOG << L"[error]: style wrong\n"; - } - - std::wstring data_style = CalcCellDataStyle(Context, columnStyleName, rowStyleName, cellStyleName); - - // стили не наследуются - std::vector instances; - instances.push_back(defaultCellStyle); - - if (defaultColumnCellStyle) - instances.push_back(defaultColumnCellStyle); - - if (defaultRowCellStyle) - { - if (instances.size() > 1) - instances[1] = defaultRowCellStyle; - else - instances.push_back(defaultRowCellStyle); - } - - if (cellStyle) - { - if (instances.size() > 1) - instances[1] = cellStyle; - else - instances.push_back(cellStyle); - } - - text_format_properties_ptr textFormatProperties = calc_text_properties_content (instances); - paragraph_format_properties parFormatProperties = calc_paragraph_properties_content (instances); - style_table_cell_properties_attlist cellFormatProperties = calc_table_cell_properties (instances); -//------------------------------------------------------------------------------------------------------------------------------- std::wstring num_format; office_value_type::type num_format_type = office_value_type::Custom; - if (false == data_style.empty()) - { - num_format = Context.get_num_format_context().find_complex_format(data_style, num_format_type); - - if (num_format.empty()) - { - office_element_ptr elm = odfContext.numberStyles().find_by_style_name(data_style); - number_style_base *num_style = dynamic_cast(elm.get()); - - if (num_style) - { - Context.get_num_format_context().start_complex_format(data_style); - num_style->oox_convert(Context.get_num_format_context()); - Context.get_num_format_context().end_complex_format(); - - num_format = Context.get_num_format_context().get_last_format(); - num_format_type = Context.get_num_format_context().type(); - } - } - } -//------------------------------------------------------------------------ std::wstring number_val; - _CP_OPT(bool) bool_val; + _CP_OPT(bool) bool_val; _CP_OPT(std::wstring) str_val; oox::XlsxCellType::type xlsx_value_type = oox::XlsxCellType::s; - office_value_type::type odf_value_type = office_value_type::Custom; + office_value_type::type odf_value_type = office_value_type::Custom; if (attr.office_value_type_) odf_value_type = attr.office_value_type_->get_type(); - - if ((odf_value_type == office_value_type::Float) || + + if ((odf_value_type == office_value_type::Float) || (odf_value_type == office_value_type::Custom && attr.office_value_))// ?? - { - xlsx_value_type = oox::XlsxCellType::n; - number_val = attr.office_value_.get_value_or(L""); + { + xlsx_value_type = oox::XlsxCellType::n; + number_val = attr.office_value_.get_value_or(L""); if (num_format_type == office_value_type::Time || num_format_type == office_value_type::Date || num_format_type == office_value_type::Currency) {//тип формата данных из стиля не соответствует формату анных ячейки - num_format.clear(); - num_format_type = office_value_type::Custom; + num_format.clear(); + num_format_type = office_value_type::Custom; } - } - else if (odf_value_type == office_value_type::Percentage) - { - xlsx_value_type = oox::XlsxCellType::n; - number_val = attr.office_value_.get_value_or(L""); - + } + else if (odf_value_type == office_value_type::Percentage) + { + xlsx_value_type = oox::XlsxCellType::n; + number_val = attr.office_value_.get_value_or(L""); + if (num_format_type == office_value_type::Time || num_format_type == office_value_type::Date || num_format_type == office_value_type::Currency) {//тип формата данных из стиля не соответствует формату анных ячейки - num_format.clear(); - num_format_type = office_value_type::Percentage; + num_format.clear(); + num_format_type = office_value_type::Percentage; } - } - else if (odf_value_type == office_value_type::Currency) - { - xlsx_value_type = oox::XlsxCellType::n; - number_val = attr.office_value_.get_value_or(L""); - } - else if ((odf_value_type == office_value_type::Date) || - (odf_value_type == office_value_type::Custom && attr.office_date_value_)) - { - if (attr.office_date_value_) - { - int y, m, d; + } + else if (odf_value_type == office_value_type::Currency) + { + xlsx_value_type = oox::XlsxCellType::n; + number_val = attr.office_value_.get_value_or(L""); + } + else if ((odf_value_type == office_value_type::Date) || + (odf_value_type == office_value_type::Custom && attr.office_date_value_)) + { + if (attr.office_date_value_) + { + int y, m, d; _CP_OPT(int) h, min, sec; - if (oox::parseDateTime(attr.office_date_value_.get(), y, m, d, h, min, sec)) - { + if (oox::parseDateTime(attr.office_date_value_.get(), y, m, d, h, min, sec)) + { boost::int64_t intDate = oox::convertDate(y, m, d); _CP_OPT(double) dTime; if (h && min) @@ -876,108 +802,85 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context) { number_val = boost::lexical_cast(intDate); } - xlsx_value_type = oox::XlsxCellType::n; + xlsx_value_type = oox::XlsxCellType::n; if (num_format_type == office_value_type::Currency) {//тип формата данных из стиля не соответствует формату данных ячейки num_format.clear(); num_format_type = office_value_type::Date; } - - if (num_format.empty()) + + if (num_format.empty()) num_format = Context.get_num_format_context().get_last_date_format(); } else { str_val = attr.office_date_value_.get(); } - } - } - } - else if ((odf_value_type == office_value_type::Time) || - (odf_value_type == office_value_type::Custom && attr.office_time_value_)) - { - if (attr.office_time_value_) - { - const std::wstring tv = attr.office_time_value_.get(); - int h, m; - double s; - if (oox::parseTime(tv, h, m, s)) - { + } + } + } + else if ((odf_value_type == office_value_type::Time) || + (odf_value_type == office_value_type::Custom && attr.office_time_value_)) + { + if (attr.office_time_value_) + { + const std::wstring tv = attr.office_time_value_.get(); + int h, m; + double s; + if (oox::parseTime(tv, h, m, s)) + { double dTime = oox::convertTime(h, m, s); if (dTime >= 0) { number_val = boost::lexical_cast(dTime); - xlsx_value_type = oox::XlsxCellType::n; - + xlsx_value_type = oox::XlsxCellType::n; + if (num_format_type == office_value_type::Currency) {//тип формата данных из стиля не соответствует формату анных ячейки num_format.clear(); num_format_type = office_value_type::Time; } - if (num_format.empty()) + if (num_format.empty()) num_format = Context.get_num_format_context().get_last_time_format(); } else { str_val = tv; } - } - } - } - else if ((odf_value_type == office_value_type::Boolean) || - (odf_value_type == office_value_type::Custom && attr.office_boolean_value_)) - { - xlsx_value_type = oox::XlsxCellType::b; - if (attr.office_boolean_value_) bool_val = oox::parseBoolVal(attr.office_boolean_value_.get()); - + } + } + } + else if ((odf_value_type == office_value_type::Boolean) || + (odf_value_type == office_value_type::Custom && attr.office_boolean_value_)) + { + xlsx_value_type = oox::XlsxCellType::b; + if (attr.office_boolean_value_) bool_val = oox::parseBoolVal(attr.office_boolean_value_.get()); + num_format.clear(); num_format_type = office_value_type::Boolean; - } - else if ((odf_value_type == office_value_type::String) || - (odf_value_type == office_value_type::Custom && attr.office_string_value_)) - { - xlsx_value_type = oox::XlsxCellType::str; + } + else if ((odf_value_type == office_value_type::String) || + (odf_value_type == office_value_type::Custom && attr.office_string_value_)) + { + xlsx_value_type = oox::XlsxCellType::str; if (attr.office_string_value_) str_val = attr.office_string_value_.get(); - + num_format.clear(); num_format_type = office_value_type::String; - } - //---------------------------------------------------------------------------------------------------------------------------------- - bool is_style_visible = (!cellStyleName.empty() || defaultColumnCellStyle || !num_format.empty()) ? true : false; - - if (count_paragraph > 1) - { - is_style_visible = true; - cellFormatProperties.fo_wrap_option_ = odf_types::wrap_option::Wrap; } - if (bExternalTable) - { - is_style_visible = false; - xlsx_value_type = oox::XlsxCellType::str; - } - oox::xlsx_cell_format cellFormat; - cellFormat.set_cell_type(xlsx_value_type); - cellFormat.set_num_format(oox::odf_string_to_build_in(odf_value_type)); - bool is_data_visible = ( false == content_.elements_.empty() || - attlist_.table_content_validation_name_ || !formula.empty() || !number_val.empty() || str_val || bool_val ); - - if (attlist_.table_number_columns_repeated_ < 199 && last_cell_) last_cell_ = false; - - unsigned int cell_repeated_max = Context.current_table_column() + attlist_.table_number_columns_repeated_ + 1; + bool is_data_visible = (false == content_.elements_.empty() || + attlist_.table_content_validation_name_ || !formula.empty() || !number_val.empty() || str_val || bool_val); if (cell_repeated_max >= 1024 && cellStyleName.empty() && last_cell_ && !is_data_visible) {//Book 24.ods return; - } - size_t xfId_last_set = 0; - if (is_style_visible) - { - xfId_last_set = Context.get_style_manager().xfId(textFormatProperties, &parFormatProperties, &cellFormatProperties, - &cellFormat, num_format, num_format_type, false, is_style_visible); } + int sharedStringId = -1; + int empty_cell_count = 0; + bool skip_next_cell = false; bool need_cache_convert = false; if (number_val.empty() && !bool_val) @@ -988,14 +891,111 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context) { need_cache_convert = true; } - } -//--------------------------------------------------------------------------------------------------------- - int sharedStringId = -1; - int empty_cell_count = 0; - bool skip_next_cell = false; + } for (unsigned int r = 0; r < attlist_.table_number_columns_repeated_; ++r) - { + { +// вычислить стиль для ячейки +//--------------------------------------------------------------------------------------------------------- + std::wstring columnStyleName = Context.get_table_context().default_column_cell_style(); // могут быть разные стили колонок при repeated (Book 24.ods) + + odf_read_context& odfContext = Context.root()->odf_context(); + + style_instance* defaultCellStyle = NULL, * defaultColumnCellStyle = NULL, * defaultRowCellStyle = NULL, * cellStyle = NULL; + try + { + if (is_present_hyperlink_) + { + defaultCellStyle = odfContext.styleContainer().style_by_name(L"Hyperlink", style_family::TableCell, true); + } + if (!defaultCellStyle) + { + defaultCellStyle = odfContext.styleContainer().style_default_by_type(style_family::TableCell); + } + + defaultColumnCellStyle = odfContext.styleContainer().style_by_name(columnStyleName, style_family::TableCell, false); + defaultRowCellStyle = odfContext.styleContainer().style_by_name(rowStyleName, style_family::TableCell, false); + cellStyle = odfContext.styleContainer().style_by_name(cellStyleName, style_family::TableCell, false); + } + catch (...) + { + _CP_LOG << L"[error]: style wrong\n"; + } + + std::wstring data_style = CalcCellDataStyle(Context, columnStyleName, rowStyleName, cellStyleName); + + // стили не наследуются + std::vector instances; + instances.push_back(defaultCellStyle); + + if (defaultColumnCellStyle) + instances.push_back(defaultColumnCellStyle); + + if (defaultRowCellStyle) + { + if (instances.size() > 1) + instances[1] = defaultRowCellStyle; + else + instances.push_back(defaultRowCellStyle); + } + + if (cellStyle) + { + if (instances.size() > 1) + instances[1] = cellStyle; + else + instances.push_back(cellStyle); + } + + text_format_properties_ptr textFormatProperties = calc_text_properties_content(instances); + paragraph_format_properties parFormatProperties = calc_paragraph_properties_content(instances); + style_table_cell_properties_attlist cellFormatProperties = calc_table_cell_properties(instances); +//------------------------------------------------------------------------------------------------------------------------------- + + if (false == data_style.empty()) + { + num_format = Context.get_num_format_context().find_complex_format(data_style, num_format_type); + + if (num_format.empty()) + { + office_element_ptr elm = odfContext.numberStyles().find_by_style_name(data_style); + number_style_base* num_style = dynamic_cast(elm.get()); + + if (num_style) + { + Context.get_num_format_context().start_complex_format(data_style); + num_style->oox_convert(Context.get_num_format_context()); + Context.get_num_format_context().end_complex_format(); + + num_format = Context.get_num_format_context().get_last_format(); + num_format_type = Context.get_num_format_context().type(); + } + } + } +//---------------------------------------------------------------------------------------------------------------------------------- + bool is_style_visible = (!cellStyleName.empty() || defaultColumnCellStyle || !num_format.empty()) ? true : false; + + if (count_paragraph > 1) + { + is_style_visible = true; + cellFormatProperties.fo_wrap_option_ = odf_types::wrap_option::Wrap; + } + if (bExternalTable) + { + is_style_visible = false; + xlsx_value_type = oox::XlsxCellType::str; + } + oox::xlsx_cell_format cellFormat; + cellFormat.set_cell_type(xlsx_value_type); + cellFormat.set_num_format(oox::odf_string_to_build_in(odf_value_type)); + + size_t xfId_last_set = 0; + if (is_style_visible) + { + xfId_last_set = Context.get_style_manager().xfId(textFormatProperties, &parFormatProperties, &cellFormatProperties, + &cellFormat, num_format, num_format_type, false, is_style_visible); + } + Context.start_table_cell ( attlist_extra_.table_number_columns_spanned_ - 1 , attlist_extra_.table_number_rows_spanned_ - 1 ); if (is_style_visible) From 94edfff84620b3e02799bb228241c194a0566498 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Thu, 18 Dec 2025 14:02:42 +0600 Subject: [PATCH 107/125] fix linux build --- OOXML/XlsxFormat/Styles/XlsxStyles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OOXML/XlsxFormat/Styles/XlsxStyles.cpp b/OOXML/XlsxFormat/Styles/XlsxStyles.cpp index 019a890e7e..2df38ea3ed 100644 --- a/OOXML/XlsxFormat/Styles/XlsxStyles.cpp +++ b/OOXML/XlsxFormat/Styles/XlsxStyles.cpp @@ -435,7 +435,7 @@ namespace OOX } if (m_oNumFmts.IsInit()) { - auto remap = [&](auto& xf) + auto remap = [&](OOX::Spreadsheet::CXfs* xf) { if (xf->m_oNumFmtId.IsInit()) { From 7b8eae26c1211a53be8bc68f58548440a7403d98 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Thu, 18 Dec 2025 14:51:55 +0600 Subject: [PATCH 108/125] add tsv conversion support --- Common/OfficeFileFormatChecker2.cpp | 2 +- X2tConverter/src/cextracttools.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Common/OfficeFileFormatChecker2.cpp b/Common/OfficeFileFormatChecker2.cpp index be48e7b0dc..3b2c94fd90 100644 --- a/Common/OfficeFileFormatChecker2.cpp +++ b/Common/OfficeFileFormatChecker2.cpp @@ -967,7 +967,7 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName) nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT; else if (0 == sExt.compare(L".md")) nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_MD; - else if (0 == sExt.compare(L".csv") || 0 == sExt.compare(L".xls") || 0 == sExt.compare(L".xlsx") || 0 == sExt.compare(L".xlsb")) + else if (0 == sExt.compare(L".csv") || 0 == sExt.compare(L".tsv") || 0 == sExt.compare(L".xls") || 0 == sExt.compare(L".xlsx") || 0 == sExt.compare(L".xlsb")) nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV; else if (0 == sExt.compare(L".html") || 0 == sExt.compare(L".htm")) nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; diff --git a/X2tConverter/src/cextracttools.h b/X2tConverter/src/cextracttools.h index a759dab285..908a50ce57 100644 --- a/X2tConverter/src/cextracttools.h +++ b/X2tConverter/src/cextracttools.h @@ -910,6 +910,10 @@ namespace NExtractTools if (NULL != m_nCsvTxtEncoding) nCsvEncoding = *m_nCsvTxtEncoding; + if(NSFile::GetFileExtention(*m_sFileFrom) == L"tsv") + { + cDelimiter = L"\t"; + } if (NULL != m_nCsvDelimiter) { switch (*m_nCsvDelimiter) From 707aab41f38d189b3b9555eb0e86988e53a0148d Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 18 Dec 2025 14:42:44 +0300 Subject: [PATCH 109/125] refactoring --- .../Presentation/BinaryFileReaderWriter.cpp | 14 - .../Presentation/BinaryFileReaderWriter.h | 6 - OOXML/Binary/Presentation/imagemanager.cpp | 78 +- OOXML/Binary/Presentation/imagemanager.h | 8 +- OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp | 6 +- .../ASCOfficeDrawingConverter.cpp | 713 +----------------- .../ASCOfficeDrawingConverter.h | 9 - OOXML/PPTXFormat/Logic/Fills/Blip.cpp | 11 +- 8 files changed, 15 insertions(+), 830 deletions(-) diff --git a/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp b/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp index 992bb53c09..869e672171 100644 --- a/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp +++ b/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp @@ -731,19 +731,8 @@ namespace NSBinPptxRW return -1; return m_dCxCurShape / 36000; } - double CBinaryFileWriter::GetShapeY() - { - return m_dYCurShape / 36000; - } - double CBinaryFileWriter::GetShapeX() - { - return m_dXCurShape / 36000; //mm - } void CBinaryFileWriter::ClearCurShapePositionAndSizes() { - m_dXCurShape = 0; - m_dYCurShape = 0; - m_dCxCurShape = 0; m_dCyCurShape = 0; @@ -763,9 +752,6 @@ namespace NSBinPptxRW m_dCxCurShape = 0; m_dCyCurShape = 0; - m_dXCurShape = 0; - m_dYCurShape = 0; - m_bInGroup = false; } diff --git a/OOXML/Binary/Presentation/BinaryFileReaderWriter.h b/OOXML/Binary/Presentation/BinaryFileReaderWriter.h index b0292106e2..45a17bdfcc 100644 --- a/OOXML/Binary/Presentation/BinaryFileReaderWriter.h +++ b/OOXML/Binary/Presentation/BinaryFileReaderWriter.h @@ -244,7 +244,6 @@ namespace NSBinPptxRW _INT32 Type; _INT32 SeekPos; - public: CSeekTableEntry(); }; @@ -276,9 +275,6 @@ namespace NSBinPptxRW double m_dCxCurShape; //emu double m_dCyCurShape; - double m_dXCurShape; - double m_dYCurShape; - bool m_bInGroup = false; BYTE* GetBuffer(); @@ -288,8 +284,6 @@ namespace NSBinPptxRW double GetShapeWidth(); double GetShapeHeight(); - double GetShapeX(); - double GetShapeY(); void ClearCurShapePositionAndSizes(); diff --git a/OOXML/Binary/Presentation/imagemanager.cpp b/OOXML/Binary/Presentation/imagemanager.cpp index 31d38e7989..ad221cbbea 100644 --- a/OOXML/Binary/Presentation/imagemanager.cpp +++ b/OOXML/Binary/Presentation/imagemanager.cpp @@ -63,27 +63,18 @@ namespace NSShapeImageGen m_pFontManager = NULL; } - CMediaInfo CMediaManager::WriteImage(CBgraFrame& oImage, double& x, double& y, double& width, double& height) + CMediaInfo CMediaManager::WriteImage(CBgraFrame& oImage, double& width, double& height) { - CMediaInfo info; - - if (height < 0) - { - FlipY(oImage); - height = -height; - y -= height; - } - return GenerateImageID(oImage, (std::max)(1.0, width), (std::max)(1.0, height)); } - CMediaInfo CMediaManager::WriteImage(const std::string& strFile, double& x, double& y, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile) + CMediaInfo CMediaManager::WriteImage(const std::string& strFile, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile) { if (width < 0 && height < 0) return GenerateImageID(strFile, L"", -1, -1, strAdditionalFile, typeAdditionalFile); return GenerateImageID(strFile, L"", (std::max)(1.0, width), (std::max)(1.0, height), strAdditionalFile, typeAdditionalFile); } - CMediaInfo CMediaManager::WriteImage(const std::wstring& strFile, double& x, double& y, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile) + CMediaInfo CMediaManager::WriteImage(const std::wstring& strFile, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile) { bool bIsDownload = false; int n1 = (int)strFile.find(L"www"); @@ -623,67 +614,4 @@ namespace NSShapeImageGen } return itJPG; } - void CMediaManager::FlipY(CBgraFrame& punkImage) - { - BYTE* pBuffer = punkImage.get_Data(); - LONG lWidth = punkImage.get_Width(); - LONG lHeight = punkImage.get_Height(); - LONG lStride = punkImage.get_Stride(); - - if (lStride < 0) - lStride = -lStride; - - if ((lWidth * 4) != lStride) - return; - - BYTE* pBufferMem = new BYTE[lStride]; - - BYTE* pBufferEnd = pBuffer + lStride * (lHeight - 1); - - LONG lCountV = lHeight / 2; - - for (LONG lIndexV = 0; lIndexV < lCountV; ++lIndexV) - { - memcpy(pBufferMem, pBuffer, lStride); - memcpy(pBuffer, pBufferEnd, lStride); - memcpy(pBufferEnd, pBufferMem, lStride); - - pBuffer += lStride; - pBufferEnd -= lStride; - } - - RELEASEARRAYOBJECTS(pBufferMem); - } - void CMediaManager::FlipX(CBgraFrame& punkImage) - { - BYTE* pBuffer = punkImage.get_Data(); - LONG lWidth = punkImage.get_Width(); - LONG lHeight = punkImage.get_Height(); - LONG lStride = punkImage.get_Stride(); - - if (lStride < 0) - lStride = -lStride; - - if ((lWidth * 4) != lStride) - { - return; - } - - DWORD* pBufferDWORD = (DWORD*)pBuffer; - - LONG lW2 = lWidth / 2; - for (LONG lIndexV = 0; lIndexV < lHeight; ++lIndexV) - { - DWORD* pMem1 = pBufferDWORD; - DWORD* pMem2 = pBufferDWORD + lWidth - 1; - - LONG lI = 0; - while (lI < lW2) - { - DWORD dwMem = *pMem1; - *pMem1++ = *pMem2; - *pMem2-- = dwMem; - } - } - } } diff --git a/OOXML/Binary/Presentation/imagemanager.h b/OOXML/Binary/Presentation/imagemanager.h index d757b0c449..af802c1a2b 100644 --- a/OOXML/Binary/Presentation/imagemanager.h +++ b/OOXML/Binary/Presentation/imagemanager.h @@ -175,9 +175,9 @@ namespace NSShapeImageGen m_mapMediaFiles.clear(); } - CMediaInfo WriteImage(CBgraFrame& punkImage, double& x, double& y, double& width, double& height); - CMediaInfo WriteImage(const std::string& strFile, double& x, double& y, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile); - CMediaInfo WriteImage(const std::wstring& strFile, double& x, double& y, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile); + CMediaInfo WriteImage(CBgraFrame& punkImage, double& width, double& height); + CMediaInfo WriteImage(const std::string& strFile, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile); + CMediaInfo WriteImage(const std::wstring& strFile, double& width, double& height, const std::wstring& strAdditionalFile, int typeAdditionalFile); CMediaInfo WriteMedia(const std::wstring& strFile); void SetFontManager(NSFonts::IFontManager* pFontManager); protected: @@ -193,7 +193,5 @@ namespace NSShapeImageGen CMediaInfo GenerateMediaID(const std::wstring& strFileName, const std::wstring & strUrl); CMediaInfo GenerateImageID(std::string strFileName, const std::wstring & strUrl, double dWidth, double dHeight, const std::wstring& strAdditionalFile, int typeAdditionalFile); MediaType GetImageType(CBgraFrame& pFrame); - void FlipY(CBgraFrame& punkImage); - void FlipX(CBgraFrame& punkImage); }; } diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp b/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp index f73e5fbf81..8497738e81 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp +++ b/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp @@ -5012,11 +5012,11 @@ void BinaryWorksheetTableWriter::WriteWorksheet(OOX::Spreadsheet::CSheet* pSheet OOX::CPath pathImage = pImageFileCache->filename(); std::wstring additionalPath; int additionalType = 0; - double dX = -1.0; //mm - double dY = -1.0; + double dW = -1.0; //mm double dH = -1.0; - NSShapeImageGen::CMediaInfo oId = m_pOfficeDrawingConverter->m_pBinaryWriter->m_pCommon->m_pMediaManager->WriteImage(pathImage.GetPath(), dX, dY, dW, dH, additionalPath, additionalType); + + NSShapeImageGen::CMediaInfo oId = m_pOfficeDrawingConverter->m_pBinaryWriter->m_pCommon->m_pMediaManager->WriteImage(pathImage.GetPath(), dW, dH, additionalPath, additionalType); nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::Picture); m_oBcw.m_oStream.WriteStringW3(oId.GetPath2()); m_oBcw.WriteItemEnd(nCurPos); diff --git a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp index 0203e311c1..83f07aadd2 100644 --- a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp +++ b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp @@ -1391,376 +1391,6 @@ HRESULT CDrawingConverter::AddShapeType(const std::wstring& bsXml) return S_OK; } -PPTX::Logic::SpTreeElem CDrawingConverter::ObjectFromXml(const std::wstring& sXml, std::wstring** ppMainProps) -{ - PPTX::Logic::SpTreeElem oElem; - std::wstring sBegin(L"
"); - - std::wstring sEnd(L"
"); - std::wstring strXml = sBegin + sXml + sEnd; - - XmlUtils::CXmlNode oMainNode; - if (!oMainNode.FromXmlString(strXml)) - return oElem; - - std::vector oNodes; - if (!oMainNode.GetNodes(L"*", oNodes)) - return oElem; - - for (size_t i = 0; i < oNodes.size(); ++i) - { - XmlUtils::CXmlNode & oParseNode = oNodes[i]; - - std::wstring strFullName = oParseNode.GetName(); - std::wstring strNS = XmlUtils::GetNamespace(strFullName); - std::wstring strName = XmlUtils::GetNameNoNS(strFullName); - - while (true) - { - if (strName == L"drawing") - { - ConvertDrawing(&oElem, oParseNode, ppMainProps, true); - break; - } - else if (strName == L"background") - { - ConvertShape(&oElem, oParseNode, ppMainProps, false); - break; - } - else if (strName == L"pict" || strName == L"object") - { - //сначала shape type - XmlUtils::CXmlNode oNodeST; - if (oParseNode.GetNode(L"v:shapetype", oNodeST)) - { - AddShapeType(oNodeST); - } - - std::vector oChilds; - if (oParseNode.GetNodes(L"*", oChilds)) - { - size_t lChildsCount = oChilds.size(); - bool bIsFound = false; - PPTX::Logic::SpTreeElem* pElem = NULL; - PPTX::Logic::COLEObject* pOle = NULL; - for (size_t k = 0; k < oChilds.size(); k++) - { - XmlUtils::CXmlNode & oNodeP = oChilds[k]; - - std::wstring strNameP = XmlUtils::GetNameNoNS(oNodeP.GetName()); - if (L"shape" == strNameP || - L"rect" == strNameP || - L"oval" == strNameP || - L"line" == strNameP || - L"background"== strNameP || - L"roundrect" == strNameP || - L"polyline" == strNameP) - { - - if(NULL == pElem) - { - pElem = new PPTX::Logic::SpTreeElem; - ConvertShape(pElem, oNodeP, ppMainProps, true); - -#ifdef AVS_OFFICE_DRAWING_DUMP_XML_TEST - NSBinPptxRW::CXmlWriter oXmlW(m_pReader->m_nDocumentType); - pElem->toXmlWriter(&oXmlW); - std::wstring strXmlTemp = oXmlW.GetXmlString(); -#endif - } - } - else if (L"binData" == strNameP) - { - AddBinData(oNodeP); - } - else if (L"OLEObject" == strNameP || L"objectEmbed" == strNameP) - { - pOle = new PPTX::Logic::COLEObject(); - pOle->fromXML(oNodeP); - } - else if (L"group" == strNameP) - { - if(NULL == pElem) - { - pElem = new PPTX::Logic::SpTreeElem; - ConvertGroup(pElem, oNodeP, ppMainProps, true); - -#ifdef AVS_OFFICE_DRAWING_DUMP_XML_TEST - NSBinPptxRW::CXmlWriter oXmlW(m_pReader->m_nDocumentType); - pElem->toXmlWriter(&oXmlW); - std::wstring strXmlTemp = oXmlW.GetXmlString(); -#endif - } - } - else if (L"drawing" == strNameP) - { - ConvertDrawing(pElem, oNodeP, ppMainProps, true); - } - else - { - continue; - } - - if (bIsFound) - break; - } - if(NULL != pElem) - { - if(NULL != pOle && pOle->m_sProgId.IsInit() && (pOle->m_oId.IsInit() || pOle->m_OleObjectFile.IsInit())) - { - PPTX::Logic::Shape* pShape = dynamic_cast(pElem->GetElem().operator ->()); - if(NULL != pShape && pShape->spPr.Fill.Fill.IsInit()) - { - bool bImageOle = false; - - if (pShape->spPr.Fill.m_type == PPTX::Logic::UniFill::blipFill) bImageOle = true; - - PPTX::Logic::BlipFill oBlipFillNew; - - if (!bImageOle) - oBlipFillNew.blip = new PPTX::Logic::Blip(); - - const PPTX::Logic::BlipFill& oBlipFill = bImageOle ? pShape->spPr.Fill.Fill.as() : oBlipFillNew; - - if(oBlipFill.blip.IsInit()) - { - if (pOle->m_OleObjectFile.IsInit()) - { - oBlipFill.blip->oleFilepathBin = pOle->m_OleObjectFile->filename().GetPath(); - } - else if (pOle->m_oId.IsInit()) - { - oBlipFill.blip->oleRid = pOle->m_oId.get().ToString(); - } - if(strName == L"object") - { - int nDxaOrig = oParseNode.ReadAttributeInt(L"w:dxaOrig"); - int nDyaOrig = oParseNode.ReadAttributeInt(L"w:dyaOrig"); - if (nDxaOrig > 0 && nDyaOrig > 0) - { - pOle->m_oDxaOrig = nDxaOrig; - pOle->m_oDyaOrig = nDyaOrig; - } - } - - PPTX::Logic::Pic *newElem = new PPTX::Logic::Pic(); - - newElem->blipFill = oBlipFill; - newElem->spPr = pShape->spPr; - newElem->style = pShape->style; - newElem->oleObject.reset(pOle); - pOle = NULL; - - pElem->InitElem(newElem); - } - } - } - m_pBinaryWriter->WriteRecord1(1, *pElem); - } - RELEASEOBJECT(pElem) - RELEASEOBJECT(pOle) - } - - break; - } - else if (strName == L"oleObj") - { - nullable pic = oParseNode.ReadNode(_T("p:pic")); - if (pic.is_init()) - { - pic->fromXMLOle(oParseNode); // todooo сделать норальный объект - - m_pBinaryWriter->WriteRecord2(1, pic); - } - break; - } - else if (strName == L"AlternateContent") - { - XmlUtils::CXmlNode oNodeDr; - if (oParseNode.GetNode(L"w:drawing", oNodeDr)) - { - strName = L"drawing"; - oParseNode = oNodeDr; - continue; - } - - if (oParseNode.GetNode(L"mc:Choice", oNodeDr)) - { - oParseNode = oNodeDr; - continue; - } - - if (oParseNode.GetNode(L"w:pict", oNodeDr)) - { - strName = L"pict"; - oParseNode = oNodeDr; - continue; - } - - if (oParseNode.GetNode(L"w:object", oNodeDr)) - { - strName = L"object"; - oParseNode = oNodeDr; - continue; - } - - if (oParseNode.GetNode(L"xdr:sp", oNodeDr)) - { - strName = L"sp"; - oParseNode = oNodeDr; - continue; - } - - if (oParseNode.GetNode(L"mc:Fallback", oNodeDr)) - { - oParseNode = oNodeDr; - continue; - } - - break; - } - else - { - oElem = oParseNode; - break; - } - } - } - return oElem; -} - -std::wstring CDrawingConverter::ObjectToDrawingML(const std::wstring& sXml, int nDocType) -{ - std::wstring *pMainProps = new std::wstring(); - - PPTX::Logic::SpTreeElem oElem = ObjectFromXml(sXml, &pMainProps); - - if (oElem.is_init() == false) return L""; - - NSBinPptxRW::CXmlWriter oXmlWriter(nDocType); - oXmlWriter.m_bIsUseOffice2007 = false; - - oXmlWriter.m_bIsTop = true; - - oXmlWriter.WriteString(L""); - - bool bIsInline = false; - - std::wstring strMainProps = *pMainProps; - std::wstring strMainPropsTail; - - int nIndexF = (int)strMainProps.find(L""); - if (-1 != nIndexF) - { - bIsInline = true; - strMainProps = strMainProps.substr(0, nIndexF); - } - else - { - nIndexF = (int)strMainProps.find(L""); - strMainProps = strMainProps.substr(0, nIndexF); - } - - if (-1 == nIndexF) - { - oElem.toXmlWriter(&oXmlWriter); - return oXmlWriter.GetXmlString(); - } - - int nIndexTail = (int)strMainProps.find(L"()) - { - oXmlWriter.WriteString(L"\ -"); - } - else if (oElem.is()) - { - oXmlWriter.WriteString(L"\ -"); - } - else - { - oXmlWriter.WriteString(L"\ -"); - } - oElem.toXmlWriter(&oXmlWriter); - oXmlWriter.WriteString(L""); - - oXmlWriter.WriteString(strMainPropsTail); - oXmlWriter.WriteString(bIsInline ? L"" : L""); - - oXmlWriter.WriteString(L""); - - delete pMainProps; - - return oXmlWriter.GetXmlString(); -} - -std::wstring CDrawingConverter::ObjectToVML (const std::wstring& sXml) -{ - std::wstring *pMainProps = new std::wstring(); - - PPTX::Logic::SpTreeElem oElem = ObjectFromXml(sXml, &pMainProps); - - if (oElem.is_init() == false) return L""; - - NSBinPptxRW::CXmlWriter oXmlWriter(m_pReader->m_nDocumentType); - oXmlWriter.m_bIsUseOffice2007 = true; - - oXmlWriter.m_bIsTop = true; - - if (NULL == m_pOOXToVMLRenderer) - m_pOOXToVMLRenderer = new COOXToVMLGeometry(); - oXmlWriter.m_pOOXToVMLRenderer = m_pOOXToVMLRenderer; - - oXmlWriter.WriteString(L""); - - if (oElem.is()) - { - ConvertGroupVML(oElem, *pMainProps, oXmlWriter); - } - else if (oElem.is()) - { - ConvertShapeVML(oElem, *pMainProps, oXmlWriter); - } - - oXmlWriter.WriteString(L""); - - delete pMainProps; - - return oXmlWriter.GetXmlString(); -} - HRESULT CDrawingConverter::AddObject(const std::wstring& bsXml, std::wstring** pMainProps) { std::wstring strXml = _start_xml_object + bsXml + _end_xml_object; @@ -2139,104 +1769,6 @@ bool CDrawingConverter::ParceObject(const std::wstring& strXml, std::wstring** p return true; } -void CDrawingConverter::ConvertDiagram(PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop) -{ - if (!result) return; - - nullable id_data; - nullable id_drawing; - - smart_ptr oFileData; - smart_ptr oFileDrawing; - - OOX::CDiagramData* pDiagramData = NULL; - OOX::CDiagramDrawing* pDiagramDrawing = NULL; - - XmlMacroReadAttributeBase(oNode, L"r:dm", id_data); - - if (id_data.IsInit() && m_pBinaryWriter->GetRelsPtr()) - { - oFileData = m_pBinaryWriter->GetRelsPtr()->Find(*id_data); - - if (oFileData.is_init()) - { - pDiagramData = dynamic_cast(oFileData.GetPointer()); - if ((pDiagramData) && (pDiagramData->m_oDataModel.IsInit())) - { - for (size_t i = 0; (pDiagramData->m_oDataModel->m_oExtLst.IsInit()) && i < pDiagramData->m_oDataModel->m_oExtLst->m_arrExt.size(); i++) - { - if (pDiagramData->m_oDataModel->m_oExtLst->m_arrExt[i]->m_oDataModelExt.IsInit()) - { - id_drawing = pDiagramData->m_oDataModel->m_oExtLst->m_arrExt[i]->m_oDataModelExt->m_oRelId; - break; - } - } - } - } - if (id_drawing.is_init() && m_pBinaryWriter->GetRelsPtr()) - { - oFileDrawing = m_pBinaryWriter->GetRelsPtr()->Find(*id_drawing); - pDiagramDrawing = dynamic_cast(oFileDrawing.GetPointer()); - } - if (!pDiagramDrawing && pDiagramData) - { - OOX::CPath pathDiagramData = pDiagramData->m_strFilename; - - int a1 = (int)pathDiagramData.GetFilename().find(L"."); - std::wstring strId = pathDiagramData.GetFilename().substr(4, pathDiagramData.GetFilename().length() - 8); - - OOX::CPath pathDiagramDrawing = pathDiagramData.GetDirectory() + FILE_SEPARATOR_STR + L"drawing" + strId + L".xml"; - - if (NSFile::CFileBinary::Exists(pathDiagramDrawing.GetPath())) - { - oFileDrawing = smart_ptr(dynamic_cast(new OOX::CDiagramDrawing(NULL, pathDiagramDrawing))); - if (oFileDrawing.IsInit()) - pDiagramDrawing = dynamic_cast(oFileDrawing.GetPointer()); - } - } - } - - if ((pDiagramDrawing) && (pDiagramDrawing->m_oShapeTree.IsInit())) - { - result->InitElem(new PPTX::Logic::SpTree(*pDiagramDrawing->m_oShapeTree)); - //to correct write blipFill rId to binary - SetRelsPtr(pDiagramDrawing); - } - else - {//BG-FSC1.docx - //parse pDiagramData !! - } - if (result->is()) - { - PPTX::Logic::SpTree& _pElem = result->as(); - if (!_pElem.grpSpPr.xfrm.is_init()) - { - _pElem.grpSpPr.xfrm = new PPTX::Logic::Xfrm(); - - _pElem.grpSpPr.xfrm->offX = m_pBinaryWriter->m_dXCurShape; - _pElem.grpSpPr.xfrm->offY = m_pBinaryWriter->m_dYCurShape; - _pElem.grpSpPr.xfrm->extX = m_pBinaryWriter->m_dCxCurShape; - _pElem.grpSpPr.xfrm->extY = m_pBinaryWriter->m_dCyCurShape; - _pElem.grpSpPr.xfrm->chOffX = (int)0; - _pElem.grpSpPr.xfrm->chOffY = (int)0; - _pElem.grpSpPr.xfrm->chExtX = m_pBinaryWriter->m_dCxCurShape; - _pElem.grpSpPr.xfrm->chExtY = m_pBinaryWriter->m_dCyCurShape; - } - else - { - if (!_pElem.grpSpPr.xfrm->offX.is_init()) _pElem.grpSpPr.xfrm->offX = m_pBinaryWriter->m_dXCurShape; - if (!_pElem.grpSpPr.xfrm->offY.is_init()) _pElem.grpSpPr.xfrm->offY = m_pBinaryWriter->m_dYCurShape; - if (!_pElem.grpSpPr.xfrm->extX.is_init()) _pElem.grpSpPr.xfrm->extX = m_pBinaryWriter->m_dCxCurShape; - if (!_pElem.grpSpPr.xfrm->extY.is_init()) _pElem.grpSpPr.xfrm->extY = m_pBinaryWriter->m_dCyCurShape; - - if (!_pElem.grpSpPr.xfrm->chOffX.is_init()) _pElem.grpSpPr.xfrm->chOffX = (int)0; - if (!_pElem.grpSpPr.xfrm->chOffY.is_init()) _pElem.grpSpPr.xfrm->chOffY = (int)0; - if (!_pElem.grpSpPr.xfrm->chExtX.is_init()) _pElem.grpSpPr.xfrm->chExtX = m_pBinaryWriter->m_dCxCurShape; - if (!_pElem.grpSpPr.xfrm->chExtY.is_init()) _pElem.grpSpPr.xfrm->chExtY = m_pBinaryWriter->m_dCyCurShape; - } - - } -} void CDrawingConverter::ConvertDrawing(PPTX::Logic::SpTreeElem *elem, XmlUtils::CXmlNode& oNodeShape, std::wstring**& pMainProps, bool bIsTop) { if (!elem) return; @@ -2251,9 +1783,6 @@ void CDrawingConverter::ConvertDrawing(PPTX::Logic::SpTreeElem *elem, XmlUtils:: { XmlUtils::CXmlNode oNodeExt; - m_pBinaryWriter->m_dXCurShape = 0; - m_pBinaryWriter->m_dYCurShape = 0; - if (oNodeAnchorInline.GetNode(L"wp:extent", oNodeExt)) { m_pBinaryWriter->m_dCxCurShape = oNodeExt.ReadAttributeInt(L"cx"); @@ -2279,17 +1808,12 @@ void CDrawingConverter::ConvertDrawing(PPTX::Logic::SpTreeElem *elem, XmlUtils:: { XmlUtils::CXmlNode &oNodeContent = oChilds[0]; -/* if (L"dgm:relIds" == oNodeContent.GetName() && m_pBinaryWriter->m_pCurrentContainer->is_init()) - { - ConvertDiagram(elem, oNodeContent, pMainProps, true); - } - else */if (L"wpc:wpc" == oNodeContent.GetName()) + if (L"wpc:wpc" == oNodeContent.GetName()) { PPTX::Logic::SpTree* pTree = new PPTX::Logic::SpTree(); pTree->grpSpPr.xfrm = new PPTX::Logic::Xfrm(); - pTree->grpSpPr.xfrm->offX = m_pBinaryWriter->m_dXCurShape; - pTree->grpSpPr.xfrm->offY = m_pBinaryWriter->m_dYCurShape; + pTree->grpSpPr.xfrm->extX = m_pBinaryWriter->m_dCxCurShape; pTree->grpSpPr.xfrm->extY = m_pBinaryWriter->m_dCyCurShape; @@ -2973,9 +2497,6 @@ void CDrawingConverter::ConvertShape(PPTX::Logic::SpTreeElem *elem, XmlUtils::CX } else { - m_pBinaryWriter->m_dXCurShape = 0; - m_pBinaryWriter->m_dYCurShape = 0; - m_pBinaryWriter->m_dCxCurShape = 0; m_pBinaryWriter->m_dCyCurShape = 0; @@ -4176,9 +3697,6 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P oProps.Width = width; oProps.Height = height; - m_pBinaryWriter->m_dXCurShape = left; - m_pBinaryWriter->m_dYCurShape = top; - m_pBinaryWriter->m_dCxCurShape = width; m_pBinaryWriter->m_dCyCurShape = height; @@ -4616,233 +4134,6 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P return oWriter.GetXmlString(); } - -std::wstring CDrawingConverter::GetVMLShapeXml(PPTX::Logic::SpTreeElem& oElem) -{ - CPPTXShape* pShapePPTX = NULL; - if (oElem.is()) - { - const PPTX::Logic::Shape& lpOriginShape = oElem.as(); - - if (lpOriginShape.spPr.Geometry.is()) - { - const PPTX::Logic::PrstGeom lpGeom = lpOriginShape.spPr.Geometry.as(); - - OOXMLShapes::ShapeType _lspt = PPTX2EditorAdvanced::GetShapeTypeFromStr(lpGeom.prst.get()); - if(_lspt != OOXMLShapes::sptNil) - { - pShapePPTX = new CPPTXShape(); - pShapePPTX->SetType(NSBaseShape::pptx, _lspt); - - std::wstring strAdjustValues = lpGeom.GetODString(); - pShapePPTX->LoadAdjustValuesList(strAdjustValues); - } - } - else if(lpOriginShape.spPr.Geometry.is()) - { - const PPTX::Logic::CustGeom lpGeom = lpOriginShape.spPr.Geometry.as(); - std::wstring strShape = lpGeom.GetODString(); - pShapePPTX = new CPPTXShape(); - pShapePPTX->LoadFromXML(strShape); - } - else - { - pShapePPTX = new CPPTXShape(); - pShapePPTX->SetType(NSBaseShape::pptx, (int)OOXMLShapes::sptCRect); - } - } - - if (NULL != pShapePPTX) - { - NSGuidesVML::CConverterPPTXPPT oConverterPPTX_2_PPT; - oConverterPPTX_2_PPT.Convert(pShapePPTX); - - std::wstring sDumpXml = GetVMLShapeXml(oConverterPPTX_2_PPT.GetConvertedShape()); - - return sDumpXml; - } - - return L""; -} - -std::wstring CDrawingConverter::GetVMLShapeXml(CPPTShape* pPPTShape) -{ - NSBinPptxRW::CXmlWriter oXmlWriter; - oXmlWriter.StartNode(L"v:shape"); - oXmlWriter.StartAttributes(); - - std::wstring strCoordSize; - LONG lCoordW = 21600; - LONG lCoordH = 21600; - if (0 < pPPTShape->m_oPath.m_arParts.size()) - { - lCoordW = pPPTShape->m_oPath.m_arParts[0].width; - lCoordH = pPPTShape->m_oPath.m_arParts[0].height; - } - strCoordSize = std::to_wstring(lCoordW) + L"," + std::to_wstring(lCoordH); - oXmlWriter.WriteAttribute(L"coordsize", strCoordSize); - - int nAdjCount = (int)pPPTShape->m_arAdjustments.size(); - if (nAdjCount > 0) - { - oXmlWriter.WriteString(L" adj=\""); - - for (int i = 0; i < nAdjCount; ++i) - { - if (0 != i) - { - std::wstring s = L"," + std::to_wstring(pPPTShape->m_arAdjustments[i]); - oXmlWriter.WriteString(s); - } - else - { - oXmlWriter.WriteString(std::to_wstring(pPPTShape->m_arAdjustments[i])); - } - } - - oXmlWriter.WriteString(L"\""); - } - - oXmlWriter.WriteAttribute(L"path", pPPTShape->m_strPath); - oXmlWriter.EndAttributes(); - - std::vector& arGuides = pPPTShape->m_oManager.m_arFormulas; - int nGuides = (int)arGuides.size(); - if (nGuides != 0) - { - oXmlWriter.StartNode(L"v:formulas"); - oXmlWriter.StartAttributes(); - oXmlWriter.EndAttributes(); - - for (int i = 0; i < nGuides; ++i) - { - CFormula& oGuide = arGuides[i]; - if ((int)oGuide.m_eFormulaType >= VML_GUIDE_COUNT) - break; - - oXmlWriter.WriteString(L" 0) - { - std::wstring str; - if (oGuide.m_eType1 == ptAdjust) - { - str = L" #"; - } - else if (oGuide.m_eType1 == ptFormula) - { - str = L" @"; - } - else - { - str = L" "; - } - str += std::to_wstring(oGuide.m_lParam1); - oXmlWriter.WriteString(str); - } - if (nParams > 1) - { - std::wstring str; - if (oGuide.m_eType2 == ptAdjust) - { - str = L" #"; - } - else if (oGuide.m_eType2 == ptFormula) - { - str = L" @"; - } - else - { - str = L" "; - } - str += std::to_wstring(oGuide.m_lParam2); - oXmlWriter.WriteString(str); - } - if (nParams > 2) - { - std::wstring str ; - if (oGuide.m_eType3 == ptAdjust) - { - str = L" #"; - } - else if (oGuide.m_eType3 == ptFormula) - { - str = L" @"; - } - else - { - str = L" "; - } - str += std::to_wstring(oGuide.m_lParam3); - oXmlWriter.WriteString(str); - } - - oXmlWriter.WriteString(L"\"/>"); - } - - oXmlWriter.EndNode(L"v:formulas"); - - size_t nTextRectCount = pPPTShape->m_arStringTextRects.size(); - if (0 < nTextRectCount) - { - oXmlWriter.WriteString(L"m_arStringTextRects[i]); - } - - oXmlWriter.WriteString(L"\"/>"); - } - - int nHandles = (int)pPPTShape->m_arHandles.size(); - if (0 < nHandles) - { - oXmlWriter.StartNode(L"v:handles"); - oXmlWriter.StartAttributes(); - oXmlWriter.EndAttributes(); - - for (int i = 0; i < nHandles; ++i) - { - oXmlWriter.StartNode(L"v:h"); - - CHandle_& oH = pPPTShape->m_arHandles[i]; - - if (oH.position != L"") - oXmlWriter.WriteAttribute(L"position", oH.position); - - if (oH.xrange != L"") - oXmlWriter.WriteAttribute(L"xrange", oH.xrange); - - if (oH.yrange != L"") - oXmlWriter.WriteAttribute(L"yrange", oH.yrange); - - if (oH.polar != L"") - oXmlWriter.WriteAttribute(L"polar", oH.polar); - - if (oH.radiusrange != L"") - oXmlWriter.WriteAttribute(L"radiusrange", oH.radiusrange); - - if (oH.switchHandle != L"") - oXmlWriter.WriteAttribute(L"switch", oH.switchHandle); - - oXmlWriter.WriteString(L"/>"); - } - - oXmlWriter.EndNode(L"v:handles"); - } - } - - oXmlWriter.EndNode(L"v:shape"); - return oXmlWriter.GetXmlString(); -} - void CDrawingConverter::SendMainProps(const std::wstring& strMainProps, std::wstring**& pMainProps) { if (((m_pBinaryWriter) && (m_pBinaryWriter->m_pMainDocument)) || !m_pBinaryWriter || m_bNeedMainProps) diff --git a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h index 3fb23c0942..672ed744e4 100644 --- a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h +++ b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h @@ -197,7 +197,6 @@ namespace NSBinPptxRW CElement(const CElement& oSrc); }; - std::map m_mapShapeTypes; std::map> m_mapBinDatas; @@ -252,10 +251,6 @@ namespace NSBinPptxRW void SaveObjectExWriterInit (NSBinPptxRW::CXmlWriter& oXmlWriter, int lDocType); void SaveObjectExWriterRelease (NSBinPptxRW::CXmlWriter& oXmlWriter); - PPTX::Logic::SpTreeElem ObjectFromXml(const std::wstring& sXml, std::wstring** pMainProps); - std::wstring ObjectToVML (const std::wstring& sXml); - std::wstring ObjectToDrawingML (const std::wstring& sXml, int nDocType); - std::wstring SaveObjectBackground(LONG lStart, LONG lLength); HRESULT GetRecordBinary (long lRecordType, const std::wstring& sXml); @@ -286,15 +281,11 @@ namespace NSBinPptxRW bool ParceObject (const std::wstring& strXml, std::wstring** pMainProps); void SendMainProps (const std::wstring& strMainProps, std::wstring**& pMainProps); - void ConvertDiagram (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); void ConvertShape (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); void ConvertGroup (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); void ConvertDrawing (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); void ConvertWordArtShape(PPTX::Logic::SpTreeElem* result, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); - std::wstring GetVMLShapeXml (CPPTShape* pPPTShape); - std::wstring GetVMLShapeXml (PPTX::Logic::SpTreeElem& oElem); - void CheckBrushShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); void CheckPenShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); void CheckBorderShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); diff --git a/OOXML/PPTXFormat/Logic/Fills/Blip.cpp b/OOXML/PPTXFormat/Logic/Fills/Blip.cpp index b2a96ee82e..e9c310fbc3 100644 --- a/OOXML/PPTXFormat/Logic/Fills/Blip.cpp +++ b/OOXML/PPTXFormat/Logic/Fills/Blip.cpp @@ -302,9 +302,6 @@ namespace PPTX pWriter->EndRecord(); - double dX = pWriter->GetShapeX(); //mm - double dY = pWriter->GetShapeY(); - double dW = pWriter->GetShapeWidth(); //mm double dH = pWriter->GetShapeHeight(); @@ -335,21 +332,21 @@ namespace PPTX NSShapeImageGen::CMediaInfo oId; if (!dataFilepathImageA.empty()) { - oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(dataFilepathImageA, dX, dY, dW, dH, additionalPath, additionalType); + oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(dataFilepathImageA, dW, dH, additionalPath, additionalType); } else if (!dataFilepathImage.empty()) { - oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(dataFilepathImage, dX, dY, dW, dH, additionalPath, additionalType); + oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(dataFilepathImage, dW, dH, additionalPath, additionalType); } else if (!oleFilepathImage.empty()) { std::wstring imagePath = oleFilepathImage; - oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(imagePath, dX, dY, dW, dH, additionalPath, additionalType); + oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(imagePath, dW, dH, additionalPath, additionalType); } else { std::wstring imagePath = this->GetFullPicName(pRels); - oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(imagePath, dX, dY, dW, dH, additionalPath, additionalType); + oId = pWriter->m_pCommon->m_pMediaManager->WriteImage(imagePath, dW, dH, additionalPath, additionalType); } std::wstring s = oId.GetPath2(); From dc6ca55b57d272a64c0ca9108061a797b873993e Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Thu, 18 Dec 2025 16:07:37 +0300 Subject: [PATCH 110/125] For bug 79141 --- PdfFile/SrcReader/RendererOutputDev.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index 989c8b8bf7..c5947315d4 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -1709,7 +1709,6 @@ namespace PdfReader m_pRendererOut->NewPDF(gfx->getDoc()->getXRef()); Gfx* m_gfx = new Gfx(gfx->getDoc(), m_pRendererOut, -1, pResourcesDict, dDpiX, dDpiY, &box, NULL, 0); - m_gfx->takeContentStreamStack(gfx); m_gfx->display(pStream); pFrame->ClearNoAttack(); @@ -1744,6 +1743,7 @@ namespace PdfReader m_pRenderer->put_BrushTextureImage(oImage); m_pRenderer->put_BrushTextureMode(c_BrushTextureModeTile); m_pRenderer->put_BrushTextureAlpha(alpha); + m_pRenderer->put_BrushTransform({ pMatrix[0], pMatrix[1], pMatrix[2], pMatrix[3], pMatrix[4], pMatrix[5] }); m_pRenderer->BeginCommand(c_nImageType); m_pRenderer->DrawPath(c_nWindingFillMode); From 14dd41a2a28f5991a1ca5d57dad3b21b4b921eb1 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 19 Dec 2025 10:24:42 +0300 Subject: [PATCH 111/125] Fix bug 79141 --- PdfFile/SrcReader/RendererOutputDev.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index c5947315d4..217d6a2ac4 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -1727,6 +1727,7 @@ namespace PdfReader yMax = nY1 * dYStep + pBBox[1]; Transform(pMatrix, xMin, yMin, &xMin, &yMin); Transform(pMatrix, xMax, yMax, &xMax, &yMax); + pGState->clearPath(); pGState->moveTo(xMin, yMin); pGState->lineTo(xMax, yMin); pGState->lineTo(xMax, yMax); @@ -1743,7 +1744,7 @@ namespace PdfReader m_pRenderer->put_BrushTextureImage(oImage); m_pRenderer->put_BrushTextureMode(c_BrushTextureModeTile); m_pRenderer->put_BrushTextureAlpha(alpha); - m_pRenderer->put_BrushTransform({ pMatrix[0], pMatrix[1], pMatrix[2], pMatrix[3], pMatrix[4], pMatrix[5] }); + m_pRenderer->put_BrushTransform({ pMatrix[0], pMatrix[1], pMatrix[2], pMatrix[3], 0, 0 }); m_pRenderer->BeginCommand(c_nImageType); m_pRenderer->DrawPath(c_nWindingFillMode); From 8f108582b9a30e705f7891d2fc9f6fab0afe4bb9 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 19 Dec 2025 12:42:44 +0300 Subject: [PATCH 112/125] Fix bug 79082 --- PdfFile/SrcReader/RendererOutputDev.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index 217d6a2ac4..9e64ba47a0 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -2470,7 +2470,8 @@ namespace PdfReader std::wstring wsUnicodeText; - bool isCIDFont = pFont->isCIDFont(); + bool isCIDFont = pFont->isCIDFont() == gTrue; + bool isIdentity = isCIDFont ? ((GfxCIDFont*)pFont)->usesIdentityEncoding() || ((GfxCIDFont*)pFont)->usesIdentityCIDToGID() || ((GfxCIDFont*)pFont)->ctuUsesCharCodeToUnicode() || pFont->getType() == fontCIDType0C : false; if (NULL != oEntry.pCodeToUnicode && nCode < oEntry.unLenUnicode) { @@ -2496,20 +2497,20 @@ namespace PdfReader unsigned int unGidsCount = 0; unsigned int unGid = 0; - if (NULL != oEntry.pCodeToGID && nCode < oEntry.unLenGID) + if (NULL != oEntry.pCodeToGID && nCode < oEntry.unLenGID && oEntry.pCodeToGID[nCode]) { - if (0 == (unGid = oEntry.pCodeToGID[nCode])) - unGidsCount = 0; - else - unGidsCount = 1; + unGid = oEntry.pCodeToGID[nCode]; + unGidsCount = 1; + + if (pFont->getType() == fontCIDType0COT && isCIDFont && isIdentity && oEntry.pCodeToUnicode && nCode < oEntry.unLenUnicode && !oEntry.pCodeToUnicode[nCode]) + unGid = nCode; } else { - if ((isCIDFont && (((GfxCIDFont*)pFont)->usesIdentityEncoding() || ((GfxCIDFont*)pFont)->usesIdentityCIDToGID() || ((GfxCIDFont*)pFont)->ctuUsesCharCodeToUnicode() || pFont->getType() == fontCIDType0C)) - || (!isCIDFont && wsUnicodeText.empty())) + if ((isCIDFont && isIdentity) || (!isCIDFont && wsUnicodeText.empty())) { - int nCurCode = (0 == nCode ? 65534 : nCode); - unGid = (unsigned int)nCurCode; + unsigned int nCurCode = (0 == nCode ? 65534 : nCode); + unGid = nCurCode; unGidsCount = 1; } } From 2330f1dae8261193e63666694e6a44fd442618b0 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 19 Dec 2025 13:02:53 +0300 Subject: [PATCH 113/125] Fix unicode=code when isCIDFont --- PdfFile/SrcReader/RendererOutputDev.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index 9e64ba47a0..878e8bbc23 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -2473,7 +2473,7 @@ namespace PdfReader bool isCIDFont = pFont->isCIDFont() == gTrue; bool isIdentity = isCIDFont ? ((GfxCIDFont*)pFont)->usesIdentityEncoding() || ((GfxCIDFont*)pFont)->usesIdentityCIDToGID() || ((GfxCIDFont*)pFont)->ctuUsesCharCodeToUnicode() || pFont->getType() == fontCIDType0C : false; - if (NULL != oEntry.pCodeToUnicode && nCode < oEntry.unLenUnicode) + if (NULL != oEntry.pCodeToUnicode && nCode < oEntry.unLenUnicode && oEntry.pCodeToUnicode[nCode]) { int unUnicode = oEntry.pCodeToUnicode[nCode]; wsUnicodeText = NSStringExt::CConverter::GetUnicodeFromUTF32((const unsigned int*)(&unUnicode), 1); @@ -2483,7 +2483,7 @@ namespace PdfReader if (isCIDFont) { // Значит кодировка была Identity-H или Identity-V, что означает, что исходные коды и есть юникодные значения - wsUnicodeText = (wchar_t(nCode)); + wsUnicodeText = NSStringExt::CConverter::GetUnicodeFromUTF32((const unsigned int*)(&nCode), 1); } else { From a8fe05fb6aee0671cdc0c322805585f6d8a61cff Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Mon, 22 Dec 2025 12:15:15 +0300 Subject: [PATCH 114/125] Fix bug 79153 --- .../pro/js/wasm/src/drawingfile_test.cpp | 4 +- PdfFile/PdfEditor.cpp | 42 +++++++++++++++++++ PdfFile/SrcReader/PdfAnnot.cpp | 3 -- PdfFile/SrcWriter/Document.cpp | 32 ++++++++++++++ PdfFile/SrcWriter/Document.h | 4 +- PdfFile/test/test.cpp | 17 ++++++++ 6 files changed, 96 insertions(+), 6 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 15753b56ac..94181c7537 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -1194,7 +1194,7 @@ int main(int argc, char* argv[]) } // RASTER - if (false) + if (true) { int i = nTestPage; //for (int i = 0; i < nPagesCount; ++i) @@ -2252,7 +2252,7 @@ int main(int argc, char* argv[]) } // SCAN PAGE - if (true) + if (false) { BYTE* pScan = ScanPage(pGrFile, nTestPage, 2); if (pScan) diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 3f1b3c60f2..e418495924 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -1569,6 +1569,48 @@ void CPdfEditor::Close() pEncryptDict->UpdateKey(nCryptAlgorithm); } + Object* pNameTree = pPDFDocument->getCatalog()->getNameTree(); + Object oNames, oName, oDest; + if (pNameTree && pNameTree->isDict() && pNameTree->dictLookup("Names", &oNames)->isArray()) + { + for (int i = 0; i < oNames.arrayGetLength(); i += 2) + { + if (oNames.arrayGet(i, &oName)->isString() && oNames.arrayGet(i + 1, &oDest)->isArray()) + { + TextString* s = new TextString(oName.getString()); + std::string sName = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()); + PdfWriter::CStringObject* pName = new PdfWriter::CStringObject(sName.c_str(), !s->isPDFDocEncoding()); + delete s; + + PdfWriter::CDestination* pDest = NULL; + LinkDest* pLinkDest = new LinkDest(oDest.getArray()); + if (pLinkDest && pLinkDest->isOk()) + { + int nPage = 0; + if (pLinkDest->isPageRef()) + { + Ref pageRef = pLinkDest->getPageRef(); + nPage = pPDFDocument->findPage(pageRef.num, pageRef.gen); + } + else + nPage = pLinkDest->getPageNum(); + pDest = pDoc->CreateDestination(pDoc->GetEditPage(nPage - 1), true); + } + delete pLinkDest; + + if (pName && pDest) + pDoc->AddNameTree(pName, pDest); + else + { + delete pName; + delete pDest; + } + } + oName.free(); oDest.free(); + } + } + oNames.free(); + m_pWriter->EditClose(); m_pWriter->SaveToFile(m_wsDstFile); return; diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 10f39ceeb7..7ee7952e8d 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -111,10 +111,7 @@ CActionGoTo* getGoTo(PDFDoc* pdfDoc, LinkAction* oAct) GString* str = ((LinkGoTo*)oAct)->getNamedDest(); LinkDest* pLinkDest = str ? pdfDoc->findDest(str) : ((LinkGoTo*)oAct)->getDest(); if (!pLinkDest) - { - RELEASEOBJECT(oAct); return NULL; - } CActionGoTo* ppRes = new CActionGoTo(); if (pLinkDest->isPageRef()) { diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 92646ffc83..1a020fa259 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -329,6 +329,38 @@ namespace PdfWriter for (int i = 0; i < m_vMetaOForms.size(); ++i) m_vMetaOForms[i]->Add("ID", new CBinaryObject(arrId, 16)); } + void CDocument::AddNameTree(CStringObject* pName, CDestination* pDest) + { + if (!m_pCatalog || !m_pXref) + return; + + CDictObject* pDNames = dynamic_cast(m_pCatalog->Get("Names")); + if (!pDNames) + { + pDNames = new CDictObject(); + m_pXref->Add(pDNames); + m_pCatalog->Add("Names", pDNames); + } + + CDictObject* pDests = dynamic_cast(pDNames->Get("Dests")); + if (!pDests) + { + pDests = new CDictObject(); + m_pXref->Add(pDests); + pDNames->Add("Dests", pDests); + } + + CArrayObject* pANames = dynamic_cast(pDests->Get("Names")); + if (!pANames) + { + pANames = new CArrayObject(); + m_pXref->Add(pANames); + pDests->Add("Names", pANames); + } + + pANames->Add(pName); + pANames->Add(pDest); + } void CDocument::PrepareEncryption() { CEncrypt* pEncrypt = m_pEncryptDict->GetEncrypt(); diff --git a/PdfFile/SrcWriter/Document.h b/PdfFile/SrcWriter/Document.h index c9b12b13bf..1282d91f6e 100644 --- a/PdfFile/SrcWriter/Document.h +++ b/PdfFile/SrcWriter/Document.h @@ -93,6 +93,7 @@ namespace PdfWriter class CStreamData; class CXObject; class CObjectBase; + class CStringObject; //---------------------------------------------------------------------------------------- // CDocument //---------------------------------------------------------------------------------------- @@ -217,7 +218,8 @@ namespace PdfWriter CDictObject* GetAcroForm() { return m_pAcroForm; } CResourcesDict* CreateResourcesDict(bool bInline, bool bProcSet); void RemoveObj(CObjectBase* pObj); - void SetEncryption(CEncryptDict* pEncrypt, PdfWriter::CObjectBase* pID); + void SetEncryption(CEncryptDict* pEncrypt, CObjectBase* pID); + void AddNameTree(CStringObject* pName, CDestination* pDest); private: char* GetTTFontTag(); diff --git a/PdfFile/test/test.cpp b/PdfFile/test/test.cpp index e01cf8608f..e849131420 100644 --- a/PdfFile/test/test.cpp +++ b/PdfFile/test/test.cpp @@ -420,6 +420,23 @@ TEST_F(CPdfFileTest, MergePdf) pdfFile->Close(); } +TEST_F(CPdfFileTest, RedactPdf) +{ + GTEST_SKIP(); + + LoadFromFile(); + ASSERT_TRUE(pdfFile->EditPdf(wsDstFile)); + + pdfFile->SetEditType(1); + + EXPECT_TRUE(pdfFile->EditPage(0)); + { + DrawSmth(); + } + + pdfFile->Close(); +} + TEST_F(CPdfFileTest, EditPdf) { GTEST_SKIP(); From 078ec02efd10fbdb3c3822427e34e550be2c594d Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 23 Dec 2025 16:23:42 +0300 Subject: [PATCH 115/125] For bug 79199 --- DesktopEditor/doctrenderer/drawingfile.h | 14 ++++++++++++++ DesktopEditor/graphics/pro/js/drawingfile.json | 1 + .../graphics/pro/js/wasm/js/drawingfile.js | 5 +++++ .../graphics/pro/js/wasm/js/drawingfile_native.js | 5 +++++ .../graphics/pro/js/wasm/js/drawingfile_wasm.js | 5 +++++ .../graphics/pro/js/wasm/src/drawingfile.cpp | 4 ++++ .../graphics/pro/js/wasm/src/drawingfile_test.cpp | 10 ++++------ 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/DesktopEditor/doctrenderer/drawingfile.h b/DesktopEditor/doctrenderer/drawingfile.h index 12e4ce1c25..73b4e9e65e 100644 --- a/DesktopEditor/doctrenderer/drawingfile.h +++ b/DesktopEditor/doctrenderer/drawingfile.h @@ -454,6 +454,20 @@ public: if (m_nType == 0) ((CPdfFile*)m_pFile)->SetCMapMemory(data, size); } + void SetScanPageFonts(int nPageIndex) + { + if (NULL == m_pImageStorage) + m_pImageStorage = NSDocxRenderer::CreateWasmImageStorage(); + + CDocxRenderer oRenderer(m_pApplicationFonts); + oRenderer.SetExternalImageStorage(m_pImageStorage); + oRenderer.SetTextAssociationType(NSDocxRenderer::TextAssociationType::tatParagraphToShape); + + oRenderer.ScanPageBin(m_pFile, nPageIndex); + + if (m_nType == 0) + ((CPdfFile*)m_pFile)->SetPageFonts(nPageIndex); + } BYTE* ScanPage(int nPageIndex, int mode) { if (NULL == m_pImageStorage) diff --git a/DesktopEditor/graphics/pro/js/drawingfile.json b/DesktopEditor/graphics/pro/js/drawingfile.json index 36eb62288c..27ce31a7d2 100644 --- a/DesktopEditor/graphics/pro/js/drawingfile.json +++ b/DesktopEditor/graphics/pro/js/drawingfile.json @@ -51,6 +51,7 @@ "_DestroyTextInfo", "_IsNeedCMap", "_SetCMapData", + "_SetScanPageFonts", "_ScanPage", "_SplitPages", "_MergePages", diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index 22322fa758..afea84df01 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -1702,6 +1702,11 @@ CFile.prototype["readAnnotationsInfoFromBinary"] = function(AnnotInfo) }; // SCAN PAGES +CFile.prototype["scanPageFonts"] = function(page) +{ + this._setScanPageFonts(page); +}; + CFile.prototype["scanPage"] = function(page, mode) { let ptr = this._scanPage(page, mode); diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js index de646e0238..7c06639ba1 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_native.js @@ -252,6 +252,11 @@ CFile.prototype._getInteractiveFormsAP = function(width, height, backgroundColor }; // SCAN PAGES +CFile.prototype._setScanPageFonts = function(page) +{ + g_native_drawing_file["SetScanPageFonts"](page); +}; + CFile.prototype._scanPage = function(page, mode) { g_module_pointer.ptr = g_native_drawing_file["ScanPage"](page, (mode === undefined) ? 0 : mode); diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js index cda24706b4..177ae32ddc 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_wasm.js @@ -388,6 +388,11 @@ CFile.prototype._getInteractiveFormsAP = function(width, height, backgroundColor }; // SCAN PAGES +CFile.prototype._setScanPageFonts = function(page) +{ + Module["_SetScanPageFonts"](this.nativeFile, page); +}; + CFile.prototype._scanPage = function(page, mode) { g_module_pointer.ptr = Module["_ScanPage"](this.nativeFile, page, (mode === undefined) ? 0 : mode); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index c0e0218254..26ece8265b 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -166,6 +166,10 @@ WASM_EXPORT void SetCMapData(CDrawingFile* pFile, BYTE* data, int size) { pFile->SetCMapData(data, size); } +WASM_EXPORT void SetScanPageFonts(CDrawingFile* pFile, int nPageIndex) +{ + return pFile->SetScanPageFonts(nPageIndex); +} WASM_EXPORT BYTE* ScanPage(CDrawingFile* pFile, int nPageIndex, int mode) { return pFile->ScanPage(nPageIndex, mode); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 94181c7537..18613c4894 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -1184,10 +1184,10 @@ int main(int argc, char* argv[]) std::cout << "CheckPerm 4 Print " << CheckPerm(pGrFile, 3) << std::endl; } - BYTE* pColor = new BYTE[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // REDACT if (false) { + BYTE* pColor = new BYTE[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int pRect[8] = { 307499, 217499, 307499, 1124999, 1799999, 1124999, 1799999, 217499 }; if (!RedactPage(pGrFile, nTestPage, pRect, 1, pColor, 12)) std::cout << "Redact false" << std::endl; @@ -2251,12 +2251,10 @@ int main(int argc, char* argv[]) free(pAnnotAP); } - // SCAN PAGE - if (false) + // SCAN PAGE Fonts + if (true) { - BYTE* pScan = ScanPage(pGrFile, nTestPage, 2); - if (pScan) - free(pScan); + SetScanPageFonts(pGrFile, nTestPage); ReadInteractiveFormsFonts(pGrFile, 1); ReadInteractiveFormsFonts(pGrFile, 2); From b6f024b73fba7feb5e38d7ed6f34e6232d30f778 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 23 Dec 2025 16:43:29 +0300 Subject: [PATCH 116/125] Refactoring --- DesktopEditor/graphics/MetafileToRenderer.cpp | 29 +++++++++---------- DocxRenderer/DocxRenderer.h | 1 + 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 069a3acf88..4244ff1711 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -358,7 +358,6 @@ namespace NSOnlineOfficeBinToPdf Aggplus::CGraphicsPath path; Aggplus::CMatrix transMatrRot; Aggplus::RectF_T clipRect; - bool isClose = false; bool isResetRot = false; while (oReader.Check()) { @@ -647,7 +646,6 @@ namespace NSOnlineOfficeBinToPdf } case ctPathCommandMoveTo: { - if (isClose) isClose = false; double m1 = oReader.ReadDouble(); double m2 = oReader.ReadDouble(); path.MoveTo(m1, m2); @@ -674,7 +672,6 @@ namespace NSOnlineOfficeBinToPdf case ctPathCommandClose: { path.CloseFigure(); - isClose = true; break; } case ctPathCommandEnd: @@ -732,7 +729,11 @@ namespace NSOnlineOfficeBinToPdf transMatrRot.Reset(); transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend); + double offX = old_t5 - transMatrRot.tx(); + double offY = old_t6 - transMatrRot.ty(); + drawPath.Transform(&transMatrRot); + pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, offX, offY); if (isZeroPt && !isZeroRot && isStretch) drawPath.GetBounds(left, top, width, height); @@ -744,42 +745,40 @@ namespace NSOnlineOfficeBinToPdf tmpPath.GetBounds(left, top, width, height); } - pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, old_t5 - transMatrRot.tx(), old_t6 - transMatrRot.ty()); - if (isZeroPt || !isStretch) clipRect = Aggplus::RectF_T(left, top, width, height); if (isStretch) { - clipRect.Offset(transMatrRot.tx() - old_t5, transMatrRot.ty() - old_t6); + if (!isZeroPt) + clipRect.Offset(-offX, -offY); pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); } + else + { + double tileOffX, tileOffY; + pRenderer->get_BrushOffset(tileOffX, tileOffY); + pRenderer->put_BrushOffset(tileOffX - offX, tileOffY - offY); + } } clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height); path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection); + clipRect = Aggplus::RectF_T(); } pRenderer->AddPath(path); - - if (isClose) - { - pRenderer->PathCommandClose(); - isClose = false; - } - pRenderer->DrawPath(fill); if (isResetRot) { pRenderer->SetTransform(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6); + transMatrRot.Reset(); isResetRot = false; } - transMatrRot.Reset(); pRenderer->put_BrushScale(false, 1.0, 1.0); pRenderer->put_BrushOffset(0.0, 0.0); - clipRect = Aggplus::RectF_T(); break; } case ctDrawImageFromFile: diff --git a/DocxRenderer/DocxRenderer.h b/DocxRenderer/DocxRenderer.h index 109859782f..0903f78acc 100644 --- a/DocxRenderer/DocxRenderer.h +++ b/DocxRenderer/DocxRenderer.h @@ -107,6 +107,7 @@ public: virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha); virtual HRESULT get_BrushLinearAngle(double* dAngle); virtual HRESULT put_BrushLinearAngle(const double& dAngle); + virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight); From a2fc927b39bff24014fbdbf96571d203a2b26eca Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Tue, 23 Dec 2025 17:58:22 +0300 Subject: [PATCH 117/125] Resolve merge conflict --- DesktopEditor/graphics/aggplustypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DesktopEditor/graphics/aggplustypes.h b/DesktopEditor/graphics/aggplustypes.h index fc10bd1033..12752c19d1 100644 --- a/DesktopEditor/graphics/aggplustypes.h +++ b/DesktopEditor/graphics/aggplustypes.h @@ -212,6 +212,8 @@ public: void Offset(const PointF_T& point) { Offset(point.X, point.Y); } void Offset(T dx, T dy) { X += dx; Y += dy; } + inline bool IsPositive() { return Width > 0 && Height > 0; } + RectF_T& operator=(const RectF_T& other) { if (this == &other) From 8250b59558f87628a5ff58fd7b49fff6ddb02c5c Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 24 Dec 2025 11:10:19 +0300 Subject: [PATCH 118/125] Test ConvertToRasterBase64 --- DesktopEditor/graphics/MetafileToRenderer.cpp | 2 +- PdfFile/test/test.cpp | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 9baa8c570e..2ca48d0d95 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -36,7 +36,7 @@ #include "../fontengine/FontManager.h" #include "../raster/BgraFrame.h" #include "../common/StringExt.h" -#include "../GraphicsPath.h" +#include "GraphicsPath.h" // этот класс нужно переписать. должно работать как и в js // а не просто на каждом символе переключаться, если нужно diff --git a/PdfFile/test/test.cpp b/PdfFile/test/test.cpp index e849131420..01bcf0515d 100644 --- a/PdfFile/test/test.cpp +++ b/PdfFile/test/test.cpp @@ -340,6 +340,41 @@ TEST_F(CPdfFileTest, ConvertToRaster) } } +TEST_F(CPdfFileTest, ConvertToRasterBase64) +{ + //GTEST_SKIP(); + + // чтение и конвертации бинарника + NSFile::CFileBinary oFile; + ASSERT_TRUE(oFile.OpenFile(NSFile::GetProcessDirectory() + L"/base64.txt")); + + DWORD dwFileSize = oFile.GetFileSize(); + BYTE* pFileContent = new BYTE[dwFileSize]; + if (!pFileContent) + { + oFile.CloseFile(); + FAIL(); + } + + DWORD dwReaded; + oFile.ReadFile(pFileContent, dwFileSize, dwReaded); + oFile.CloseFile(); + + int nBufferLen = NSBase64::Base64DecodeGetRequiredLength(dwFileSize); + BYTE* pBuffer = new BYTE[nBufferLen]; + + NSBase64::Base64Decode((const char*)pFileContent, dwFileSize, pBuffer, &nBufferLen); + + NSOnlineOfficeBinToPdf::CMetafileToRenderterRaster imageWriter(NULL); + imageWriter.SetIsOnlyFirst(false); + imageWriter.SetMediaDirectory(NSFile::GetProcessDirectory()); + imageWriter.SetApplication(pApplicationFonts); + imageWriter.SetRasterFormat(4); + imageWriter.SetFileName(NSFile::GetProcessDirectory() + L"/resO/res.png"); + + imageWriter.ConvertBuffer(pBuffer, nBufferLen); +} + TEST_F(CPdfFileTest, VerifySign) { GTEST_SKIP(); @@ -459,7 +494,7 @@ TEST_F(CPdfFileTest, EditPdf) TEST_F(CPdfFileTest, EditPdfFromBase64) { - //GTEST_SKIP(); + GTEST_SKIP(); NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NSFonts::NSApplicationFontStream::CreateDefaultGlobalMemoryStorage()); From 1237991ffbc82cc4deb4167d855ce1171cfbc669 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Wed, 24 Dec 2025 13:11:47 +0300 Subject: [PATCH 119/125] Fix typo --- DesktopEditor/graphics/GraphicsPath.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/GraphicsPath.cpp b/DesktopEditor/graphics/GraphicsPath.cpp index 329ad784b1..39b407669b 100644 --- a/DesktopEditor/graphics/GraphicsPath.cpp +++ b/DesktopEditor/graphics/GraphicsPath.cpp @@ -886,12 +886,12 @@ namespace Aggplus if (isCurve) { std::vector points = GetPoints(idx, 4); - area = 3.0 * (points[3].Y - points[0].Y) * (points[1].X + points[2].X) + area = 3.0 * ((points[3].Y - points[0].Y) * (points[1].X + points[2].X) - (points[3].X - points[0].X) * (points[1].Y + points[2].Y) + points[1].Y * (points[0].X - points[2].X) - points[1].X * (points[0].Y - points[2].Y) + points[3].Y * (points[2].X + points[0].X / 3.0) - - points[3].X * (points[2].Y + points[0].Y / 3.0) / 20.0; + - points[3].X * (points[2].Y + points[0].Y / 3.0)) / 20.0; } else { From f760d0328123b0b99ef43a58724d0efc50238212 Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Wed, 24 Dec 2025 22:57:52 +0400 Subject: [PATCH 120/125] Remove LOGD in platform-common code --- DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp index a5c6dc5527..5192bda717 100644 --- a/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp +++ b/DesktopEditor/doctrenderer/js_internal/v8/v8_base.cpp @@ -474,14 +474,11 @@ namespace NSJSBase global->Set(context, v8::String::NewFromUtf8Literal(isolate, "self"), global).Check(); global->Set(context, v8::String::NewFromUtf8Literal(isolate, "native"), v8::Undefined(isolate)).Check(); - LOGD("compiling and running snapshot code..."); // Compile v8::Local source = v8::String::NewFromUtf8(isolate, script.c_str()).ToLocalChecked(); v8::Local script = v8::Script::Compile(context, source).ToLocalChecked(); - LOGD("compile status: %d", try_catch.Check()); // Run script->Run(context).IsEmpty(); - LOGD("run status: %d", try_catch.Check()); snapshotCreator.SetDefaultContext(context); } From f4cb421b49fe95b7860f1c5a6dd31c85f49c4dd5 Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 25 Dec 2025 11:51:44 +0300 Subject: [PATCH 121/125] refactoring --- .../Document/BinReader/BinaryReaderD.cpp | 2 +- .../Document/BinWriter/BinaryWriterD.cpp | 10 +- .../Document/DocWrapper/DocxSerializer.cpp | 6 +- OOXML/Binary/Draw/BinaryReaderV.cpp | 2 +- .../Presentation/BinaryFileReaderWriter.cpp | 34 +- .../Presentation/BinaryFileReaderWriter.h | 65 ++- OOXML/Binary/Presentation/imagemanager.cpp | 4 +- OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp | 8 +- .../Sheets/Reader/ChartFromToBinary.cpp | 18 +- OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp | 10 +- .../ASCOfficeDrawingConverter.cpp | 395 ++++-------------- .../ASCOfficeDrawingConverter.h | 135 +++--- OOXML/PPTXFormat/Logic/CSld.cpp | 3 +- OOXML/PPTXFormat/Logic/Fills/Blip.cpp | 4 +- OOXML/PPTXFormat/Logic/GrpSpPr.cpp | 3 - OOXML/PPTXFormat/Logic/Pic.cpp | 30 +- .../PPTXFormat/Logic/Runs/MathParaWrapper.cpp | 10 +- OOXML/PPTXFormat/Logic/Shape.cpp | 12 +- OOXML/PPTXFormat/Logic/SmartArt.cpp | 20 +- OOXML/PPTXFormat/Logic/SpTree.cpp | 20 +- OOXML/PPTXFormat/Logic/Xfrm.cpp | 20 +- .../NamedSheetViews/NamedSheetViews.cpp | 44 +- .../NamedSheetViews/NamedSheetViews.h | 21 +- 23 files changed, 303 insertions(+), 573 deletions(-) diff --git a/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp b/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp index 2b944aee17..e46157551b 100644 --- a/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp +++ b/OOXML/Binary/Document/BinReader/BinaryReaderD.cpp @@ -8928,7 +8928,7 @@ int Binary_DocumentTableReader::Read_Background(BYTE type, long length, void* po if (oCDrawingProperty.bDataPos && oCDrawingProperty.bDataLength) { - m_oFileWriter.m_pDrawingConverter->m_pReader->m_nDocumentType = m_oFileWriter.m_bGlossaryMode ? XMLWRITER_DOC_TYPE_DOCX_GLOSSARY : XMLWRITER_DOC_TYPE_DOCX; + m_oFileWriter.m_pDrawingConverter->m_pBinaryReader->m_nDocumentType = m_oFileWriter.m_bGlossaryMode ? XMLWRITER_DOC_TYPE_DOCX_GLOSSARY : XMLWRITER_DOC_TYPE_DOCX; long nCurPos = m_oBufferedStream.GetPos(); pBackground->sObject = m_oFileWriter.m_pDrawingConverter->SaveObjectBackground(oCDrawingProperty.DataPos, oCDrawingProperty.DataLength); diff --git a/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp b/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp index 7b5ea0e849..571e0b6549 100644 --- a/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp +++ b/OOXML/Binary/Document/BinWriter/BinaryWriterD.cpp @@ -6805,7 +6805,7 @@ bool BinaryDocumentTableWriter::WriteDrawingPptx(OOX::WritingElement* item) OOX::Logic::CDrawing* pGraphicDrawing = NULL; PPTX::Logic::GraphicFrame* pGraphic = NULL; - m_oBcw.m_oStream.ClearCurShapePositionAndSizes(); + m_oBcw.m_oStream.ClearCurShapeSize(); bool res = true; @@ -6886,7 +6886,7 @@ void BinaryDocumentTableWriter::WriteDrawing(std::wstring* pXml, OOX::Logic::CDr int nCurPos = 0; bool bDeleteDrawing = false; - m_oBcw.m_oStream.m_dCxCurShape = m_oBcw.m_oStream.m_dCyCurShape = 0; + m_oBcw.m_oStream.ClearCurShapeSize(); //pptxdata if (pXml) { @@ -6927,8 +6927,7 @@ void BinaryDocumentTableWriter::WriteDrawing(std::wstring* pXml, OOX::Logic::CDr const OOX::Drawing::CInline& pInline = img.m_oInline.get(); if (pInline.m_oExtent.IsInit()) { - m_oBcw.m_oStream.m_dCxCurShape = pInline.m_oExtent->m_oCx.GetValue(); - m_oBcw.m_oStream.m_dCyCurShape = pInline.m_oExtent->m_oCy.GetValue(); + m_oBcw.m_oStream.SetCurShapeSize(pInline.m_oExtent->m_oCx.GetValue(), pInline.m_oExtent->m_oCy.GetValue()); } } else if (img.m_oAnchor.IsInit()) @@ -6936,8 +6935,7 @@ void BinaryDocumentTableWriter::WriteDrawing(std::wstring* pXml, OOX::Logic::CDr const OOX::Drawing::CAnchor& pAnchor = img.m_oAnchor.get(); if (pAnchor.m_oExtent.IsInit()) { - m_oBcw.m_oStream.m_dCxCurShape = pAnchor.m_oExtent->m_oCx.GetValue(); - m_oBcw.m_oStream.m_dCyCurShape = pAnchor.m_oExtent->m_oCy.GetValue(); + m_oBcw.m_oStream.SetCurShapeSize(pAnchor.m_oExtent->m_oCx.GetValue(), pAnchor.m_oExtent->m_oCy.GetValue()); } } } diff --git a/OOXML/Binary/Document/DocWrapper/DocxSerializer.cpp b/OOXML/Binary/Document/DocWrapper/DocxSerializer.cpp index 7f28384ea2..4fd76d71ce 100644 --- a/OOXML/Binary/Document/DocWrapper/DocxSerializer.cpp +++ b/OOXML/Binary/Document/DocWrapper/DocxSerializer.cpp @@ -235,7 +235,7 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const std::wstring& sDstFileName, co oDrawingConverter.SetFontDir(m_sFontDir); oDrawingConverter.SetFontPicker(pFontPicker); - oDrawingConverter.SetMainDocument(this); + oDrawingConverter.SetDocxSerializer(this); oDrawingConverter.SetDstPath(pathMain.GetDirectory() + FILE_SEPARATOR_STR + L"word"); oDrawingConverter.SetMediaDstPath(pathMedia.GetPath()); @@ -383,7 +383,7 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const std::wstring& sSrcFileName, bool bIsNoBase64 = nVersion == g_nFormatVersionNoBase64; NSBinPptxRW::CDrawingConverter oDrawingConverter; - NSBinPptxRW::CBinaryFileReader& oBufferedStream = *oDrawingConverter.m_pReader; + NSBinPptxRW::CBinaryFileReader& oBufferedStream = *oDrawingConverter.m_pBinaryReader; int nDataSize = 0; BYTE* pData = NULL; if (!bIsNoBase64) @@ -409,7 +409,7 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const std::wstring& sSrcFileName, if (NULL != pData) { - oDrawingConverter.SetMainDocument(this); + oDrawingConverter.SetDocxSerializer(this); oDrawingConverter.SetDstPath(sDstPath + FILE_SEPARATOR_STR + L"word"); oDrawingConverter.SetMediaDstPath(sMediaPath); diff --git a/OOXML/Binary/Draw/BinaryReaderV.cpp b/OOXML/Binary/Draw/BinaryReaderV.cpp index f38f6d0aa2..be6f7fba99 100644 --- a/OOXML/Binary/Draw/BinaryReaderV.cpp +++ b/OOXML/Binary/Draw/BinaryReaderV.cpp @@ -69,7 +69,7 @@ namespace BinVsdxRW if (false == oFile.OpenFile(sSrcFileName)) return AVS_FILEUTILS_ERROR_CONVERT; - NSBinPptxRW::CBinaryFileReader& oBufferedStream = *pOfficeDrawingConverter->m_pReader; + NSBinPptxRW::CBinaryFileReader& oBufferedStream = *pOfficeDrawingConverter->m_pBinaryReader; DWORD nBase64DataSize = 0; BYTE* pBase64Data = new BYTE[oFile.GetFileSize()]; diff --git a/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp b/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp index 869e672171..cff9deff4f 100644 --- a/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp +++ b/OOXML/Binary/Presentation/BinaryFileReaderWriter.cpp @@ -722,21 +722,25 @@ namespace NSBinPptxRW double CBinaryFileWriter::GetShapeHeight() { if (m_dCyCurShape < 0.001) - return -1; - return m_dCyCurShape / 36000; //mm + return 0; + return m_dCyCurShape; //emu } double CBinaryFileWriter::GetShapeWidth() { if (m_dCxCurShape < 0.001) - return -1; - return m_dCxCurShape / 36000; + return 0; + return m_dCxCurShape;//emu } - void CBinaryFileWriter::ClearCurShapePositionAndSizes() + void CBinaryFileWriter::SetCurShapeSize(double Width, double Height) + { + m_dCxCurShape = Width; //emu + m_dCyCurShape = Height; //emu + } + + void CBinaryFileWriter::ClearCurShapeSize() { m_dCxCurShape = 0; m_dCyCurShape = 0; - - m_bInGroup = false; } void CBinaryFileWriter::Clear() { @@ -751,13 +755,6 @@ namespace NSBinPptxRW m_dCxCurShape = 0; m_dCyCurShape = 0; - - m_bInGroup = false; - } - - void CBinaryFileWriter::SetMainDocument(BinDocxRW::CDocxSerializer* pMainDoc) - { - m_pMainDocument = pMainDoc; } void CBinaryFileWriter::ClearNoAttack() @@ -981,7 +978,7 @@ namespace NSBinPptxRW } CBinaryFileWriter::CBinaryFileWriter() { - m_pMainDocument = NULL; + m_pDocxSerializer = NULL; m_pCurrentContainer = NULL; m_pCommon = new CCommonWriter(); @@ -1918,7 +1915,7 @@ namespace NSBinPptxRW CBinaryFileReader::CBinaryFileReader() { - m_pMainDocument = NULL; + m_pDocxSerializer = NULL; m_lNextId = 0; m_nDocumentType = XMLWRITER_DOC_TYPE_PPTX; @@ -1947,11 +1944,6 @@ namespace NSBinPptxRW { return m_pCurrentContainer; } - void CBinaryFileReader::SetMainDocument(BinDocxRW::CDocxSerializer* pMainDoc) - { - m_pMainDocument = pMainDoc; - } - void CBinaryFileReader::Init(BYTE* pData, _INT32 lStart, _INT32 lSize) { m_pData = pData; diff --git a/OOXML/Binary/Presentation/BinaryFileReaderWriter.h b/OOXML/Binary/Presentation/BinaryFileReaderWriter.h index 45a17bdfcc..e71919a189 100644 --- a/OOXML/Binary/Presentation/BinaryFileReaderWriter.h +++ b/OOXML/Binary/Presentation/BinaryFileReaderWriter.h @@ -250,7 +250,7 @@ namespace NSBinPptxRW CCommonWriter* m_pCommon; std::wstring m_strMainFolder; - BinDocxRW::CDocxSerializer* m_pMainDocument; + BinDocxRW::CDocxSerializer* m_pDocxSerializer = NULL; NSCommon::smart_ptr* m_pTheme; NSCommon::smart_ptr* m_pClrMap; @@ -271,13 +271,12 @@ namespace NSBinPptxRW std::vector m_arMainTables; - public: double m_dCxCurShape; //emu double m_dCyCurShape; - bool m_bInGroup = false; + public: - BYTE* GetBuffer(); + BYTE* GetBuffer(); virtual _UINT32 GetPosition(); void SetPosition(const _UINT32& lPosition); void Skip(const _UINT32& lSize); @@ -285,41 +284,39 @@ namespace NSBinPptxRW double GetShapeWidth(); double GetShapeHeight(); - void ClearCurShapePositionAndSizes(); + void ClearCurShapeSize(); + void SetCurShapeSize(double Width, double Height); void Clear(); - void SetMainDocument(BinDocxRW::CDocxSerializer* pMainDoc); - void ClearNoAttack(); virtual void CheckBufferSize(_UINT32 lPlus); - - void WriteBYTE (const BYTE& lValue); - void WriteSBYTE (const signed char& lValue); - void WriteBOOL (const bool& bValue); + + void WriteBYTE(const BYTE& lValue); + void WriteSBYTE(const signed char& lValue); + void WriteBOOL(const bool& bValue); void WriteUSHORT(const _UINT16& lValue); void WriteSHORT(const _INT16& lValue); - - void WriteULONG (const _UINT32& lValue); - void WriteLONG (const _INT32& lValue); - void WriteINT (const _INT32& lValue); - - void WriteDouble (const double& dValue); - void WriteDoubleReal(const double& dValue); - - void WriteBYTEArray (const BYTE* pBuffer, size_t len); - - void WriteStringW (const std::wstring& sBuffer); - void WriteStringW2 (const std::wstring& sBuffer); - void WriteStringW3 (const std::wstring& sBuffer); - - void WriteStringW4 (const std::wstring& sBuffer); - void WriteStringUtf8(const std::wstring& sBuffer); - // -------------------------------------------------------- - void WriteLONG64 (const _INT64& lValue); - // -------------------------------------------------------- + void WriteULONG(const _UINT32& lValue); + void WriteLONG(const _INT32& lValue); + void WriteINT(const _INT32& lValue); + + void WriteDouble(const double& dValue); + void WriteDoubleReal(const double& dValue); + + void WriteBYTEArray(const BYTE* pBuffer, size_t len); + + void WriteStringW(const std::wstring& sBuffer); + void WriteStringW2(const std::wstring& sBuffer); + void WriteStringW3(const std::wstring& sBuffer); + + void WriteStringW4(const std::wstring& sBuffer); + void WriteStringUtf8(const std::wstring& sBuffer); + void WriteLONG64(const _INT64& lValue); + +// -------------------------------------------------------- CBinaryFileWriter(); virtual ~CBinaryFileWriter(); @@ -477,8 +474,8 @@ namespace NSBinPptxRW std::map m_mapRelsImages; std::map m_mapLinks; public: - unsigned int m_lNextRelsID; - CImageManager2* m_pManager; + unsigned int m_lNextRelsID; + CImageManager2* m_pManager; CRelsGenerator(CImageManager2* pManager = NULL); ~CRelsGenerator(); @@ -543,14 +540,12 @@ namespace NSBinPptxRW _INT32 m_nCountActiveX = 1; _INT32 m_nThemeOverrideCount = 1; - BinDocxRW::CDocxSerializer* m_pMainDocument = NULL; + BinDocxRW::CDocxSerializer* m_pDocxSerializer = NULL; int m_nDocumentType; CBinaryFileReader(); ~CBinaryFileReader(); - void SetMainDocument(BinDocxRW::CDocxSerializer* pMainDoc); - void Init(BYTE* pData, _INT32 lStart, _INT32 lSize); _INT32 GenerateNextId(); diff --git a/OOXML/Binary/Presentation/imagemanager.cpp b/OOXML/Binary/Presentation/imagemanager.cpp index ad221cbbea..0c175ebdab 100644 --- a/OOXML/Binary/Presentation/imagemanager.cpp +++ b/OOXML/Binary/Presentation/imagemanager.cpp @@ -468,8 +468,8 @@ namespace NSShapeImageGen CMediaInfo oInfo; std::map::iterator pPair = m_mapMediaFiles.find(sMapKey); - LONG lWidth = (LONG)(dWidth * 96 / 25.4); - LONG lHeight = (LONG)(dHeight * 96 / 25.4); + LONG lWidth = (LONG)(dWidth * 4 / 3); + LONG lHeight = (LONG)(dHeight * 4 / 3);// px if (m_mapMediaFiles.end() == pPair) { diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp b/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp index 8497738e81..95064bbbab 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp +++ b/OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp @@ -7029,14 +7029,16 @@ void BinaryWorksheetTableWriter::WriteDrawing(const OOX::Spreadsheet::CWorksheet if (pCellAnchor->m_oElement.IsInit() == false && pCellAnchor->m_sVmlSpId.IsInit() == false) return; - m_oBcw.m_oStream.ClearCurShapePositionAndSizes(); + m_oBcw.m_oStream.ClearCurShapeSize(); WriteCellAnchor(pCellAnchor); if (pCellAnchor->m_oExt.IsInit()) { - m_oBcw.m_oStream.m_dCxCurShape = pCellAnchor->m_oExt->m_oCx.IsInit() ? pCellAnchor->m_oExt->m_oCx->GetValue() : 0; - m_oBcw.m_oStream.m_dCyCurShape = pCellAnchor->m_oExt->m_oCy.IsInit() ? pCellAnchor->m_oExt->m_oCy->GetValue() : 0; + double cx = pCellAnchor->m_oExt->m_oCx.IsInit() ? pCellAnchor->m_oExt->m_oCx->GetValue() : 0; + double cy = pCellAnchor->m_oExt->m_oCy.IsInit() ? pCellAnchor->m_oExt->m_oCy->GetValue() : 0; + + m_oBcw.m_oStream.SetCurShapeSize(cx, cy); } if (pCellAnchor->m_sVmlSpId.IsInit() && pVmlDrawing) { diff --git a/OOXML/Binary/Sheets/Reader/ChartFromToBinary.cpp b/OOXML/Binary/Sheets/Reader/ChartFromToBinary.cpp index 97409b68db..a5a8fc2833 100644 --- a/OOXML/Binary/Sheets/Reader/ChartFromToBinary.cpp +++ b/OOXML/Binary/Sheets/Reader/ChartFromToBinary.cpp @@ -1286,9 +1286,9 @@ namespace BinXlsxRW if (length < 1 || !pData) return c_oSerConstants::ReadUnknown; - fileOut = new OOX::OleObject(NULL, true, m_pOfficeDrawingConverter->m_pReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX); + fileOut = new OOX::OleObject(NULL, true, m_pOfficeDrawingConverter->m_pBinaryReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX); - int id = m_pOfficeDrawingConverter->m_pReader->m_nCountEmbedded++; + int id = m_pOfficeDrawingConverter->m_pBinaryReader->m_nCountEmbedded++; bool bMacroEnabled = false; std::wstring sXlsxFilename = L"Microsoft_Excel_Worksheet" + std::to_wstring(id) + (bMacroEnabled ? L".xlsm" : L".xlsx"); @@ -1301,7 +1301,7 @@ namespace BinXlsxRW } fileOut->set_filename(m_oSaveParams.sEmbeddingsPath + FILE_SEPARATOR_STR + sXlsxFilename, false); - m_pOfficeDrawingConverter->m_pReader->m_pRels->m_pManager->m_pContentTypes->AddDefault(bMacroEnabled ? L"xlsm" : L"xlsx"); + m_pOfficeDrawingConverter->m_pBinaryReader->m_pRels->m_pManager->m_pContentTypes->AddDefault(bMacroEnabled ? L"xlsm" : L"xlsx"); } int BinaryChartReader::ReadCT_XlsxBin(BYTE *pData, long length, NSCommon::smart_ptr & file) { @@ -1314,9 +1314,9 @@ namespace BinXlsxRW if (false == sDstEmbeddedTemp.empty()) { - file = new OOX::OleObject(NULL, true, m_pOfficeDrawingConverter->m_pReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX); + file = new OOX::OleObject(NULL, true, m_pOfficeDrawingConverter->m_pBinaryReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX); - int id = m_pOfficeDrawingConverter->m_pReader->m_nCountEmbedded++; + int id = m_pOfficeDrawingConverter->m_pBinaryReader->m_nCountEmbedded++; OOX::Spreadsheet::CXlsx oXlsx; BinXlsxRW::BinaryFileReader oEmbeddedReader; @@ -1335,15 +1335,15 @@ namespace BinXlsxRW oXlsx.m_mapEnumeratedGlobal.clear(); - oDrawingConverter.m_pReader->Init(pData, 0, length); + oDrawingConverter.m_pBinaryReader->Init(pData, 0, length); oDrawingConverter.SetDstPath(sDstEmbeddedTemp + FILE_SEPARATOR_STR + L"xl"); - oDrawingConverter.SetSrcPath(m_pOfficeDrawingConverter->m_pReader->m_strFolder, XMLWRITER_DOC_TYPE_XLSX); + oDrawingConverter.SetSrcPath(m_pOfficeDrawingConverter->m_pBinaryReader->m_strFolder, XMLWRITER_DOC_TYPE_XLSX); oDrawingConverter.SetMediaDstPath(sMediaPath); oDrawingConverter.SetEmbedDstPath(sEmbedPath); - oEmbeddedReader.ReadMainTable(oXlsx, *oDrawingConverter.m_pReader, m_pOfficeDrawingConverter->m_pReader->m_strFolder, sDstEmbeddedTemp, oSaveParams, &oDrawingConverter); + oEmbeddedReader.ReadMainTable(oXlsx, *oDrawingConverter.m_pBinaryReader, m_pOfficeDrawingConverter->m_pBinaryReader->m_strFolder, sDstEmbeddedTemp, oSaveParams, &oDrawingConverter); oXlsx.PrepareToWrite(); @@ -1357,7 +1357,7 @@ namespace BinXlsxRW file->set_filename(sDstEmbedded + FILE_SEPARATOR_STR + sXlsxFilename, false); - m_pOfficeDrawingConverter->m_pReader->m_pRels->m_pManager->m_pContentTypes->AddDefault(oSaveParams.bMacroEnabled ? L"xlsm" : L"xlsx"); + m_pOfficeDrawingConverter->m_pBinaryReader->m_pRels->m_pManager->m_pContentTypes->AddDefault(oSaveParams.bMacroEnabled ? L"xlsm" : L"xlsx"); NSDirectory::DeleteDirectory(sDstEmbeddedTemp); } diff --git a/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp b/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp index 61cc2a58df..029401f3f4 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp +++ b/OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp @@ -4726,9 +4726,9 @@ int BinaryWorksheetsTableReader::ReadWorksheet(boost::unordered_mapm_pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + m_oBufferedStream.GetString4(length); + std::wstring sPicture = m_pOfficeDrawingConverter->m_pBinaryReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + m_oBufferedStream.GetString4(length); std::vector> additionalFiles; - NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = m_pOfficeDrawingConverter->m_pReader->m_pRels->WriteImage(sPicture, additionalFiles, L"", L""); + NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = m_pOfficeDrawingConverter->m_pBinaryReader->m_pRels->WriteImage(sPicture, additionalFiles, L"", L""); NSCommon::smart_ptr pImageFileWorksheet(new OOX::Image(NULL, false)); pImageFileWorksheet->set_filename(oRelsGeneratorInfo.sFilepathImage, false); @@ -5100,9 +5100,9 @@ int BinaryWorksheetsTableReader::ReadWorksheet(boost::unordered_mapm_pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + m_oBufferedStream.GetString4(length); + std::wstring sPicture = m_pOfficeDrawingConverter->m_pBinaryReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + m_oBufferedStream.GetString4(length); std::vector> additionalFiles; - NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = m_pOfficeDrawingConverter->m_pReader->m_pRels->WriteImage(sPicture, additionalFiles, L"", L""); + NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = m_pOfficeDrawingConverter->m_pBinaryReader->m_pRels->WriteImage(sPicture, additionalFiles, L"", L""); NSCommon::smart_ptr pImageFileWorksheet(new OOX::Image(NULL, false)); pImageFileWorksheet->set_filename(oRelsGeneratorInfo.sFilepathImage, false); @@ -9651,7 +9651,7 @@ int BinaryFileReader::ReadFile(const std::wstring& sSrcFileName, std::wstring sD } bool bIsNoBase64 = nVersion == g_nFormatVersionNoBase64; - NSBinPptxRW::CBinaryFileReader& oBufferedStream = *pOfficeDrawingConverter->m_pReader; + NSBinPptxRW::CBinaryFileReader& oBufferedStream = *pOfficeDrawingConverter->m_pBinaryReader; int nDataSize = 0; BYTE* pData = NULL; diff --git a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp index 83f07aadd2..9631e22911 100644 --- a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp +++ b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.cpp @@ -1243,7 +1243,7 @@ CDrawingConverter::CDrawingConverter() m_bIsUseConvertion2007 = true; m_bNeedMainProps = false; m_pBinaryWriter = new NSBinPptxRW::CBinaryFileWriter(); - m_pReader = new NSBinPptxRW::CBinaryFileReader(); + m_pBinaryReader = new NSBinPptxRW::CBinaryFileReader(); m_pImageManager = new NSBinPptxRW::CImageManager2(); m_pXmlWriter = new NSBinPptxRW::CXmlWriter(); @@ -1255,30 +1255,30 @@ CDrawingConverter::~CDrawingConverter() Clear(); RELEASEOBJECT(m_pOOXToVMLRenderer); RELEASEOBJECT(m_pBinaryWriter); - RELEASEOBJECT(m_pReader); + RELEASEOBJECT(m_pBinaryReader); RELEASEOBJECT(m_pImageManager); RELEASEOBJECT(m_pXmlWriter); RELEASEOBJECT(m_pTheme); RELEASEOBJECT(m_pClrMap); } -void CDrawingConverter::SetMainDocument(BinDocxRW::CDocxSerializer* pDocument) +void CDrawingConverter::SetDocxSerializer(BinDocxRW::CDocxSerializer* pDocxSerializer) { m_pBinaryWriter->ClearNoAttack(); m_pBinaryWriter->m_pCommon->m_pMediaManager->Clear(); - m_pBinaryWriter->SetMainDocument(pDocument); - m_pReader->SetMainDocument(pDocument); + m_pBinaryWriter->m_pDocxSerializer = pDocxSerializer; + m_pBinaryReader->m_pDocxSerializer = pDocxSerializer; m_lNextId = 1; - m_pImageManager->m_nDocumentType = m_pReader->m_nDocumentType = XMLWRITER_DOC_TYPE_DOCX; + m_pImageManager->m_nDocumentType = m_pBinaryReader->m_nDocumentType = XMLWRITER_DOC_TYPE_DOCX; } void CDrawingConverter::SetSrcPath(const std::wstring& sPath, int nDocType) { OOX::CPath path(sPath); - m_pReader->m_pRels->m_pManager = m_pImageManager; - m_pReader->m_strFolder = path.GetPath(); + m_pBinaryReader->m_pRels->m_pManager = m_pImageManager; + m_pBinaryReader->m_strFolder = path.GetPath(); m_pImageManager->m_nDocumentType = nDocType; } @@ -1346,7 +1346,7 @@ void CDrawingConverter::AddShapeType(XmlUtils::CXmlNode& oNode) m_mapShapeTypes.insert(std::make_pair(strId, pS)); } } -HRESULT CDrawingConverter::AddShapeType(const std::wstring& bsXml) +void CDrawingConverter::AddShapeType(const std::wstring& bsXml) { std::wstring strXml = L"
StartRecord(0); - m_pBinaryWriter->ClearCurShapePositionAndSizes(); + m_pBinaryWriter->ClearCurShapeSize(); size_t lCount = oNodes.size(); for (size_t i = 0; i < lCount; ++i) @@ -1712,11 +1710,6 @@ bool CDrawingConverter::ParceObject(const std::wstring& strXml, std::wstring** p } if ((pPicture) && (pPicture->blipFill.blip.IsInit())) { - if (pPicture->spPr.xfrm.IsInit()) - {// for bad replacemant image for ole - m_pBinaryWriter->m_dCxCurShape = pPicture->spPr.xfrm->extX.get_value_or(0); - m_pBinaryWriter->m_dCyCurShape = pPicture->spPr.xfrm->extY.get_value_or(0); - } if (pOle->m_OleObjectFile.IsInit()) { pPicture->blipFill.blip->oleFilepathBin = pOle->m_OleObjectFile->filename().GetPath(); @@ -1766,7 +1759,6 @@ bool CDrawingConverter::ParceObject(const std::wstring& strXml, std::wstring** p } m_pBinaryWriter->EndRecord(); - return true; } void CDrawingConverter::ConvertDrawing(PPTX::Logic::SpTreeElem *elem, XmlUtils::CXmlNode& oNodeShape, std::wstring**& pMainProps, bool bIsTop) @@ -1785,8 +1777,10 @@ void CDrawingConverter::ConvertDrawing(PPTX::Logic::SpTreeElem *elem, XmlUtils:: if (oNodeAnchorInline.GetNode(L"wp:extent", oNodeExt)) { - m_pBinaryWriter->m_dCxCurShape = oNodeExt.ReadAttributeInt(L"cx"); - m_pBinaryWriter->m_dCyCurShape = oNodeExt.ReadAttributeInt(L"cy"); + double cx = oNodeExt.ReadAttributeInt(L"cx"); + double cy = oNodeExt.ReadAttributeInt(L"cy"); + + m_pBinaryWriter->SetCurShapeSize(cx, cy); } XmlUtils::CXmlNode oNodeDocPr; if (oNodeAnchorInline.GetNode(L"wp:docPr", oNodeDocPr)) @@ -1812,11 +1806,6 @@ void CDrawingConverter::ConvertDrawing(PPTX::Logic::SpTreeElem *elem, XmlUtils:: { PPTX::Logic::SpTree* pTree = new PPTX::Logic::SpTree(); - pTree->grpSpPr.xfrm = new PPTX::Logic::Xfrm(); - - pTree->grpSpPr.xfrm->extX = m_pBinaryWriter->m_dCxCurShape; - pTree->grpSpPr.xfrm->extY = m_pBinaryWriter->m_dCyCurShape; - pTree->fromXML(oNodeContent); elem->InitElem(pTree); } @@ -2497,9 +2486,6 @@ void CDrawingConverter::ConvertShape(PPTX::Logic::SpTreeElem *elem, XmlUtils::CX } else { - m_pBinaryWriter->m_dCxCurShape = 0; - m_pBinaryWriter->m_dCyCurShape = 0; - pSpPr->xfrm = new PPTX::Logic::Xfrm(); pSpPr->xfrm->offX = oProps.X; pSpPr->xfrm->offY = oProps.Y; @@ -3258,7 +3244,15 @@ void CDrawingConverter::ConvertGroup(PPTX::Logic::SpTreeElem *result, XmlUtils:: } } } - + std::wstring strStyle = oNode.GetAttribute(L"style"); + + PPTX::CCSS oCSSParser; + oCSSParser.LoadFromString2(strStyle); + + CSpTreeElemProps oProps; + oProps.IsTop = bIsTop; + std::wstring strMainPos = GetDrawingMainProps(oNode, oCSSParser, oProps); + if (oNode.GetNodes(L"*", oNodes)) { size_t nCount = oNodes.size(); @@ -3299,15 +3293,6 @@ void CDrawingConverter::ConvertGroup(PPTX::Logic::SpTreeElem *result, XmlUtils:: } } - std::wstring strStyle = oNode.GetAttribute(L"style"); - - PPTX::CCSS oCSSParser; - oCSSParser.LoadFromString2(strStyle); - - CSpTreeElemProps oProps; - oProps.IsTop = bIsTop; - std::wstring strMainPos = GetDrawingMainProps(oNode, oCSSParser, oProps); - LONG lCoordOriginX = 0; LONG lCoordOriginY = 0; LONG lCoordSizeW = oProps.Width; @@ -3583,11 +3568,6 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P LONG width = 0; LONG height = 0; - pFind = oCssStyles.m_mapSettings.find(L"polyline_correct"); - bool bIsPolyCorrect = (oCssStyles.m_mapSettings.end() != pFind) ? true : false; - if (bIsPolyCorrect) - dKoefSize = 1; - if (!bIsInline) { pFind = oCssStyles.m_mapSettings.find(L"margin-left"); @@ -3697,8 +3677,10 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P oProps.Width = width; oProps.Height = height; - m_pBinaryWriter->m_dCxCurShape = width; - m_pBinaryWriter->m_dCyCurShape = height; + if (oProps.IsTop) + { + m_pBinaryWriter->SetCurShapeSize(width, height); + } bool bExtendedSize = false; XmlUtils::CXmlNode oNodeShadow = oNode.ReadNode(L"v:shadow"); @@ -4136,7 +4118,7 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P void CDrawingConverter::SendMainProps(const std::wstring& strMainProps, std::wstring**& pMainProps) { - if (((m_pBinaryWriter) && (m_pBinaryWriter->m_pMainDocument)) || !m_pBinaryWriter || m_bNeedMainProps) + if (((m_pBinaryWriter) && (m_pBinaryWriter->m_pDocxSerializer)) || !m_pBinaryWriter || m_bNeedMainProps) { *pMainProps = new std::wstring(); **pMainProps = strMainProps; @@ -5193,7 +5175,7 @@ HRESULT CDrawingConverter::LoadClrMap(const std::wstring& bsXml) return S_OK; } -HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstring& bsMainProps, std::wstring & sXml) +void CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstring& bsMainProps, std::wstring & sXml) { bool bIsInline = false; std::wstring strMainProps = bsMainProps; @@ -5211,7 +5193,7 @@ HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstr } if (-1 == nIndexF) - return S_FALSE; + return; int nIndexTail = (int)strMainProps.find(L""), m_pReader->GenerateNextId()); + strId.Format(L""), m_pBinaryReader->GenerateNextId()); strMainProps += strId; */ //strMainProps += L""); - m_pReader->Seek(lStart); + m_pBinaryReader->Seek(lStart); ++m_nCurrentIndexObject; - BYTE typeRec1 = m_pReader->GetUChar(); // must be 0; - LONG szRec1 = m_pReader->GetRecordSize(); - LONG _e = m_pReader->GetPos() + szRec1 + 4; + BYTE typeRec1 = m_pBinaryReader->GetUChar(); // must be 0; + LONG szRec1 = m_pBinaryReader->GetRecordSize(); + LONG _e = m_pBinaryReader->GetPos() + szRec1 + 4; if (typeRec1 == 0 && szRec1 > 0) { - BYTE typeRec2 = m_pReader->GetUChar(); // must be 1; - LONG szRec2 = m_pReader->GetLong(); + BYTE typeRec2 = m_pBinaryReader->GetUChar(); // must be 1; + LONG szRec2 = m_pBinaryReader->GetLong(); if (typeRec2 == 1 && szRec2 > 0) { PPTX::Logic::SpTreeElem oElem; - if (m_pReader->m_nDocumentType == 0) - m_pReader->m_nDocumentType = XMLWRITER_DOC_TYPE_DOCX; + if (m_pBinaryReader->m_nDocumentType == 0) + m_pBinaryReader->m_nDocumentType = XMLWRITER_DOC_TYPE_DOCX; - oElem.fromPPTY(m_pReader); + oElem.fromPPTY(m_pBinaryReader); bool bOle = false; if (oElem.is()) { @@ -5275,7 +5257,7 @@ HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstr bSignatureLine = true; } } - NSBinPptxRW::CXmlWriter oXmlWriter(m_pReader->m_nDocumentType); + NSBinPptxRW::CXmlWriter oXmlWriter(m_pBinaryReader->m_nDocumentType); oXmlWriter.m_lObjectIdVML = m_pXmlWriter->m_lObjectIdVML; oXmlWriter.m_lObjectIdOle = m_pXmlWriter->m_lObjectIdOle; @@ -5342,7 +5324,7 @@ HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstr "); } - if (m_pReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX) + if (m_pBinaryReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX) { PPTX::Logic::Xfrm *pXfrm = NULL; if (oElem.getType() == OOX::et_pic) @@ -5432,8 +5414,7 @@ HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstr } } - m_pReader->Seek(_e); - return S_OK; + m_pBinaryReader->Seek(_e); } void CDrawingConverter::SaveObjectExWriterInit(NSBinPptxRW::CXmlWriter& oXmlWriter, int nDocType) { @@ -5453,33 +5434,33 @@ void CDrawingConverter::SaveObjectExWriterRelease(NSBinPptxRW::CXmlWriter& oXmlW m_pXmlWriter->m_lObjectIdVML = oXmlWriter.m_lObjectIdVML; m_pXmlWriter->m_lObjectIdOle = oXmlWriter.m_lObjectIdOle; } -HRESULT CDrawingConverter::SaveObjectEx(LONG lStart, LONG lLength, const std::wstring& bsMainProps, int nDocType, std::wstring & sXml) +void CDrawingConverter::SaveObjectEx(long lStart, long lLength, const std::wstring& sMainProps, int nDocType, std::wstring& sXml) { m_pImageManager->m_nDocumentType = nDocType; if (XMLWRITER_DOC_TYPE_DOCX == nDocType || XMLWRITER_DOC_TYPE_DOCX_GLOSSARY == nDocType) //docx { - m_pReader->m_nDocumentType = nDocType; - return SaveObject(lStart, lLength, bsMainProps, sXml); + m_pBinaryReader->m_nDocumentType = nDocType; + return SaveObject(lStart, lLength, sMainProps, sXml); } else { PPTX::Logic::SpTreeElem oElem; - m_pReader->Seek(lStart); + m_pBinaryReader->Seek(lStart); - m_pReader->m_nDocumentType = nDocType; + m_pBinaryReader->m_nDocumentType = nDocType; ++m_nCurrentIndexObject; - BYTE typeRec1 = m_pReader->GetUChar(); // must be 0; - LONG _e = m_pReader->GetPos() + m_pReader->GetLong() + 4; - + BYTE typeRec1 = m_pBinaryReader->GetUChar(); // must be 0; + LONG _e = m_pBinaryReader->GetPos() + m_pBinaryReader->GetLong() + 4; + try { - m_pReader->Skip(5); // type record (must be 1) + 4 byte - len record + m_pBinaryReader->Skip(5); // type record (must be 1) + 4 byte - len record - oElem.fromPPTY(m_pReader); + oElem.fromPPTY(m_pBinaryReader); } catch(...) { @@ -5496,14 +5477,14 @@ HRESULT CDrawingConverter::SaveObjectEx(LONG lStart, LONG lLength, const std::ws } } - m_pReader->m_nDocumentType = XMLWRITER_DOC_TYPE_PPTX; + m_pBinaryReader->m_nDocumentType = XMLWRITER_DOC_TYPE_PPTX; NSBinPptxRW::CXmlWriter oXmlWriter; SaveObjectExWriterInit(oXmlWriter, nDocType); if(bOle) { - ConvertPicVML(oElem, bsMainProps, oXmlWriter); + ConvertPicVML(oElem, sMainProps, oXmlWriter); } else { @@ -5515,26 +5496,25 @@ HRESULT CDrawingConverter::SaveObjectEx(LONG lStart, LONG lLength, const std::ws SaveObjectExWriterRelease(oXmlWriter); sXml = oXmlWriter.GetXmlString(); - m_pReader->Seek(_e); + m_pBinaryReader->Seek(_e); } - return S_OK; } std::wstring CDrawingConverter::SaveObjectBackground(LONG lStart, LONG lLength) { if (lLength < 1) return L""; - m_pReader->Seek(lStart); + m_pBinaryReader->Seek(lStart); ++m_nCurrentIndexObject; - BYTE typeRec1 = m_pReader->GetUChar(); // must be 0; - LONG _e = m_pReader->GetPos() + m_pReader->GetRecordSize() + 4; + BYTE typeRec1 = m_pBinaryReader->GetUChar(); // must be 0; + LONG _e = m_pBinaryReader->GetPos() + m_pBinaryReader->GetRecordSize() + 4; PPTX::Logic::SpTreeElem oElem; try { - m_pReader->Skip(5); // type record (must be 1) + 4 byte - len record + m_pBinaryReader->Skip(5); // type record (must be 1) + 4 byte - len record - oElem.fromPPTY(m_pReader); + oElem.fromPPTY(m_pBinaryReader); } catch(...) { @@ -5542,9 +5522,9 @@ std::wstring CDrawingConverter::SaveObjectBackground(LONG lStart, LONG lLength) } NSBinPptxRW::CXmlWriter oXmlWriter; - SaveObjectExWriterInit(oXmlWriter, m_pReader->m_nDocumentType); + SaveObjectExWriterInit(oXmlWriter, m_pBinaryReader->m_nDocumentType); - m_pReader->m_nDocumentType = XMLWRITER_DOC_TYPE_PPTX; + m_pBinaryReader->m_nDocumentType = XMLWRITER_DOC_TYPE_PPTX; if (oElem.is()) { @@ -5558,7 +5538,7 @@ std::wstring CDrawingConverter::SaveObjectBackground(LONG lStart, LONG lLength) SaveObjectExWriterRelease(oXmlWriter); - m_pReader->Seek(_e); + m_pBinaryReader->Seek(_e); return oXmlWriter.GetXmlString(); } @@ -5992,236 +5972,26 @@ void CDrawingConverter::ConvertMainPropsToVML(const std::wstring& bsMainProps, N outWriter.m_strStyleMain = oWriter.GetXmlString(); } -//HRESULT CDrawingConverter::GetTxBodyBinary(const std::wstring& bsXml) -//{ -// XmlUtils::CXmlNode oNode; -// if (!oNode.FromXmlString((std::wstring)bsXml)) -// return S_FALSE; -// -// PPTX::Logic::TxBody oTxBody(oNode); -// -// //m_pBinaryWriter->ClearNoAttack(); -// //ULONG lOldPos = m_pBinaryWriter->GetPosition(); -// m_pBinaryWriter->m_pCommon->CheckFontPicker(); -// //m_pBinaryWriter->m_pCommon->m_pNativePicker->Init(m_strFontDirectory); -// -// m_pBinaryWriter->WriteRecord1(0, oTxBody); -// -// //m_pBinaryWriter->SetPosition(lOldPos); -// -// //m_pBinaryWriter->ClearNoAttack(); -// return S_OK; -//} - -//HRESULT CDrawingConverter::GetTxBodyXml(LONG lStart, std::wstring& sXml) -//{ -// m_pReader->Seek(lStart); -// -// BYTE type = m_pReader->GetUChar(); -// if (0 != type) -// return S_FALSE; -// -// PPTX::Logic::TxBody oTxBody; -// oTxBody.fromPPTY(m_pReader); -// -// NSBinPptxRW::CXmlWriter oWriter; -// oTxBody.toXmlWriterExcel(&oWriter); -// -// sXml = oWriter.GetXmlString(); -// -// return S_OK; -//} - -HRESULT CDrawingConverter::SetFontDir(const std::wstring& bsFontDir) +void CDrawingConverter::SetFontDir(const std::wstring& bsFontDir) { m_strFontDirectory = bsFontDir; - return S_OK; -} - -HRESULT CDrawingConverter::GetRecordBinary(LONG lRecordType, const std::wstring& sXml) -{ - if (sXml.empty()) - return S_FALSE; - - std::wstring strXml = L"
"; - strXml += sXml; - strXml += L"
"; - - XmlUtils::CXmlNode oNodeMain; - if (!oNodeMain.FromXmlString(strXml)) - return S_FALSE; - - std::vector oNodes; - if (!oNodeMain.GetNodes(L"*", oNodes)) - return S_FALSE; - - if (1 != oNodes.size()) - return S_FALSE; - - XmlUtils::CXmlNode & oNode = oNodes[0]; - - PPTX::WrapperWritingElement* pWritingElem = NULL; - switch (lRecordType) - { - case XMLWRITER_RECORD_TYPE_SPPR: - { - PPTX::Logic::SpPr* pSpPr = new PPTX::Logic::SpPr(); - *pSpPr = oNode; - - pWritingElem = (PPTX::WrapperWritingElement*)pSpPr; - break; - } - case XMLWRITER_RECORD_TYPE_CLRMAPOVR: - { - PPTX::Logic::ClrMap* pClrMap = new PPTX::Logic::ClrMap(); - *pClrMap = oNode; - - pWritingElem = (PPTX::WrapperWritingElement*)pClrMap; - break; - } - case XMLWRITER_RECORD_TYPE_TEXT_OUTLINE: - { - PPTX::Logic::Ln* pLn = new PPTX::Logic::Ln(); - *pLn = oNode; - - pWritingElem = (PPTX::WrapperWritingElement*)pLn; - break; - } - case XMLWRITER_RECORD_TYPE_TEXT_FILL: - { - PPTX::Logic::UniFill* pUniFill = new PPTX::Logic::UniFill(); - pUniFill->GetFillFrom(oNode); - - pWritingElem = (PPTX::WrapperWritingElement*)pUniFill; - break; - } - default: - break; - } - - if (NULL == pWritingElem) - return S_FALSE; - - //m_pBinaryWriter->ClearNoAttack(); - m_pBinaryWriter->m_pCommon->CheckFontPicker(); - - //ULONG lOldPos = m_pBinaryWriter->GetPosition(); - - m_pBinaryWriter->WriteRecord1(0, *pWritingElem); - - - RELEASEOBJECT(pWritingElem); - - //m_pBinaryWriter->SetPosition(lOldPos); - - return S_OK; -} - -HRESULT CDrawingConverter::GetRecordXml(LONG lStart, LONG lLength, LONG lRecType, int nDocType, std::wstring & sXml) -{ - if (NULL == m_pReader) - return S_FALSE; - - m_pReader->m_pRels->m_pManager->m_nDocumentType = nDocType; - - m_pReader->Seek(lStart); - - BYTE typeRec1 = m_pReader->GetUChar(); - - PPTX::WrapperWritingElement* pWritingElem = NULL; - - switch (lRecType) - { - case XMLWRITER_RECORD_TYPE_SPPR: - { - pWritingElem = (PPTX::WrapperWritingElement*)(new PPTX::Logic::SpPr()); - pWritingElem->fromPPTY(m_pReader); - break; - } - case XMLWRITER_RECORD_TYPE_CLRMAPOVR: - { - PPTX::Logic::ClrMap* pClrMap = new PPTX::Logic::ClrMap(); - pClrMap->m_name = L"a:clrMapOvr"; - pWritingElem = (PPTX::WrapperWritingElement*)(pClrMap); - pWritingElem->fromPPTY(m_pReader); - break; - } - case XMLWRITER_RECORD_TYPE_TEXT_OUTLINE: - { - PPTX::Logic::Ln* pLn = new PPTX::Logic::Ln(); - pWritingElem = (PPTX::WrapperWritingElement*)(pLn); - pWritingElem->fromPPTY(m_pReader); - break; - } - case XMLWRITER_RECORD_TYPE_TEXT_FILL: - { - PPTX::Logic::UniFill* pUniFill = new PPTX::Logic::UniFill(); - pWritingElem = (PPTX::WrapperWritingElement*)(pUniFill); - pWritingElem->fromPPTY(m_pReader); - break; - } - default: - break; - } - - if (NULL == pWritingElem) - return S_FALSE; - - NSBinPptxRW::CXmlWriter oXmlWriter; - oXmlWriter.m_lDocType = (BYTE)nDocType; - oXmlWriter.m_bIsUseOffice2007 = false; - oXmlWriter.m_bIsTop = true; - - pWritingElem->toXmlWriter(&oXmlWriter); - - sXml = oXmlWriter.GetXmlString(); - - RELEASEOBJECT(pWritingElem); - - return S_OK; } void CDrawingConverter::SetDstContentRels() { - m_pReader->SetDstContentRels(); + m_pBinaryReader->SetDstContentRels(); } void CDrawingConverter::SaveDstContentRels(const std::wstring& bsRelsPath) { - m_pReader->SaveDstContentRels(bsRelsPath); + m_pBinaryReader->SaveDstContentRels(bsRelsPath); } void CDrawingConverter::WriteRels (const std::wstring& bsType, const std::wstring& bsTarget, const std::wstring& bsTargetMode, unsigned int* lId) { if (NULL == lId) return; - if (NULL == m_pReader) return; - if (NULL == m_pReader->m_pRels) return; + if (NULL == m_pBinaryReader) return; + if (NULL == m_pBinaryReader->m_pRels) return; - *lId = m_pReader->m_pRels->WriteRels(bsType, bsTarget, bsTargetMode); + *lId = m_pBinaryReader->m_pRels->WriteRels(bsType, bsTarget, bsTargetMode); } void CDrawingConverter::Registration (const std::wstring& sType, const std::wstring& oDirectory, const std::wstring& oFilename) { @@ -6231,13 +6001,12 @@ void CDrawingConverter::Registration (const std::wstring& sType, const std::wstr m_pImageManager->m_pContentTypes->Registration(sType, OOX::CPath(oDirectory), OOX::CPath(oFilename)); } -HRESULT CDrawingConverter::SetFontPicker(COfficeFontPicker* pFontPicker) +void CDrawingConverter::SetFontPicker(COfficeFontPicker* pFontPicker) { m_pBinaryWriter->m_pCommon->CreateFontPicker(pFontPicker); - return S_OK; } -HRESULT CDrawingConverter::SetAdditionalParam(const std::wstring& ParamName, BYTE *pArray, size_t szCount) +void CDrawingConverter::SetAdditionalParam(const std::wstring& ParamName, BYTE *pArray, size_t szCount) { std::wstring name = ParamName; if (name == L"xfrm_override" && pArray) @@ -6246,27 +6015,7 @@ HRESULT CDrawingConverter::SetAdditionalParam(const std::wstring& ParamName, BYT m_oxfrm_override = new PPTX::Logic::Xfrm(*pXfrm); } - return S_OK; - } -HRESULT CDrawingConverter::GetAdditionalParam(const std::wstring& ParamName, BYTE **pArray, size_t& szCount) -{ - //std::wstring name = ParamName; - //if (name == L"SerializeImageManager") - //{ - // NSBinPptxRW::CBinaryFileWriter oWriter; - - // return oWriter.Serialize(m_pBinaryWriter->m_pCommon->m_pImageManager, pArray, szCount) ? S_OK : S_FALSE; - //} - //else if (name == L"SerializeImageManager2") - //{ - // NSBinPptxRW::CBinaryFileWriter oWriter; - - // return oWriter.Serialize(m_pImageManager, pArray, szCount) ? S_OK : S_FALSE; - //} - return S_OK; -} - OOX::CContentTypes* CDrawingConverter::GetContentTypes() { return m_pImageManager->m_pContentTypes; diff --git a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h index 672ed744e4..f536cca376 100644 --- a/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h +++ b/OOXML/PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h @@ -197,47 +197,26 @@ namespace NSBinPptxRW CElement(const CElement& oSrc); }; - std::map m_mapShapeTypes; - std::map> m_mapBinDatas; - - NSBinPptxRW::CBinaryFileWriter* m_pBinaryWriter; - int m_lNextId; - unsigned int m_nDrawingMaxZIndex = 0; // для смешанных записей pict & Drawing - - int m_lCurrentObjectTop; - - NSBinPptxRW::CBinaryFileReader* m_pReader; - NSBinPptxRW::CImageManager2* m_pImageManager; - NSBinPptxRW::CXmlWriter* m_pXmlWriter; - int m_nCurrentIndexObject; - IRenderer* m_pOOXToVMLRenderer; - bool m_bIsUseConvertion2007; - bool m_bNeedMainProps; - - NSCommon::smart_ptr* m_pTheme; - NSCommon::smart_ptr* m_pClrMap; - - std::wstring m_strFontDirectory; - CDrawingConverter(); ~CDrawingConverter(); void SetRelsPtr(OOX::IFileContainer *container); OOX::IFileContainer* GetRelsPtr(); - void SetMainDocument (BinDocxRW::CDocxSerializer* pDocument); + void SetDocxSerializer(BinDocxRW::CDocxSerializer* pDocument); - void SetSrcPath (const std::wstring& sPath, int nDocType = 1/*XMLWRITER_DOC_TYPE_DOCX*/); - void SetDstPath (const std::wstring& sPath); - - void SetTempPath (const std::wstring& sPath); + void SetSrcPath(const std::wstring& sPath, int nDocType = 1/*XMLWRITER_DOC_TYPE_DOCX*/); + void SetDstPath(const std::wstring& sPath); + + void SetTempPath (const std::wstring& sPath); std::wstring GetTempPath(); - void SetMediaDstPath (const std::wstring& sMediaPath); - void SetEmbedDstPath (const std::wstring& sEmbedPath); + void SetMediaDstPath(const std::wstring& sMediaPath); + void SetEmbedDstPath(const std::wstring& sEmbedPath); void Clear(); - HRESULT AddShapeType(const std::wstring& sXml); + + void AddShapeType(const std::wstring& sXml); void AddShapeType(XmlUtils::CXmlNode& oNode); void AddBinData(XmlUtils::CXmlNode& oNode); @@ -245,66 +224,84 @@ namespace NSBinPptxRW void ConvertVml(const std::wstring& sXml, std::vector> &elements, NSCommon::nullable &anchor); - HRESULT SaveObject(long lStart, long lLength, const std::wstring& sMainProps, std::wstring & sXml); - HRESULT SaveObjectEx(long lStart, long lLength, const std::wstring& sMainProps, int nDocType, std::wstring & sXml); + void SaveObjectEx(long lStart, long lLength, const std::wstring& sMainProps, int nDocType, std::wstring & sXml); void SaveObjectExWriterInit (NSBinPptxRW::CXmlWriter& oXmlWriter, int lDocType); void SaveObjectExWriterRelease (NSBinPptxRW::CXmlWriter& oXmlWriter); std::wstring SaveObjectBackground(LONG lStart, LONG lLength); - - HRESULT GetRecordBinary (long lRecordType, const std::wstring& sXml); - HRESULT GetRecordXml (long lStart, long lLength, long lRecType, int lDocType, std::wstring & sXml); - - void SetDstContentRels (); - void SaveDstContentRels (const std::wstring& sRelsPath); - HRESULT LoadClrMap (const std::wstring& sXml); + HRESULT LoadClrMap(const std::wstring& sXml); - HRESULT(SetFontDir) (const std::wstring& sFontDir); + void SetFontDir (const std::wstring& sFontDir); + void SetFontPicker (COfficeFontPicker* pFontPicker); + void SetFontManager(NSFonts::IFontManager* pFontManager); - HRESULT SetFontPicker (COfficeFontPicker* pFontPicker); + void SetAdditionalParam(const std::wstring& ParamName, BYTE *pArray, size_t szCount); + void GetAdditionalParam(const std::wstring& ParamName, BYTE** pArray, size_t& szCount) {} - HRESULT SetAdditionalParam(const std::wstring& ParamName, BYTE *pArray, size_t szCount); - HRESULT GetAdditionalParam(const std::wstring& ParamName, BYTE **pArray, size_t& szCount); - - void WriteRels (const std::wstring& sType, const std::wstring& sTarget, const std::wstring& sTargetMode, unsigned int* lId); - void Registration (const std::wstring& sType, const std::wstring& oDirectory, const std::wstring& oFilename); - - void SetFontManager (NSFonts::IFontManager* pFontManager); + void SetDstContentRels(); + void SaveDstContentRels(const std::wstring& sRelsPath); + void WriteRels(const std::wstring& sType, const std::wstring& sTarget, const std::wstring& sTargetMode, unsigned int* lId); + void Registration(const std::wstring& sType, const std::wstring& oDirectory, const std::wstring& oFilename); OOX::CContentTypes* GetContentTypes(); +//------------------------------------------------------------------------------------------------------------------------ + std::map m_mapShapeTypes; + std::map> m_mapBinDatas; + NSBinPptxRW::CBinaryFileWriter* m_pBinaryWriter; + NSBinPptxRW::CBinaryFileReader* m_pBinaryReader; + + int m_lNextId; + unsigned int m_nDrawingMaxZIndex = 0; // для смешанных записей pict & Drawing + + int m_lCurrentObjectTop; + + NSBinPptxRW::CImageManager2* m_pImageManager; + NSBinPptxRW::CXmlWriter* m_pXmlWriter; + + int m_nCurrentIndexObject; + IRenderer* m_pOOXToVMLRenderer; + bool m_bIsUseConvertion2007; + bool m_bNeedMainProps; + + NSCommon::smart_ptr* m_pTheme; + NSCommon::smart_ptr* m_pClrMap; + + std::wstring m_strFontDirectory; + protected: nullable m_oxfrm_override; - bool ParceObject (const std::wstring& strXml, std::wstring** pMainProps); - void SendMainProps (const std::wstring& strMainProps, std::wstring**& pMainProps); + bool ParceObject(const std::wstring& strXml, std::wstring** pMainProps); + void SendMainProps(const std::wstring& strMainProps, std::wstring**& pMainProps); - void ConvertShape (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); - void ConvertGroup (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); - void ConvertDrawing (PPTX::Logic::SpTreeElem *result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); + void ConvertShape(PPTX::Logic::SpTreeElem* result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); + void ConvertGroup(PPTX::Logic::SpTreeElem* result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); + void ConvertDrawing(PPTX::Logic::SpTreeElem* result, XmlUtils::CXmlNode& oNode, std::wstring**& pMainProps, bool bIsTop = true); void ConvertWordArtShape(PPTX::Logic::SpTreeElem* result, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); - void CheckBrushShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); - void CheckPenShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); - void CheckBorderShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); - void CheckEffectShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); + void CheckBrushShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); + void CheckPenShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); + void CheckBorderShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); + void CheckEffectShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape); - void ConvertColor (PPTX::Logic::UniColor& uniColor, nullable_string& sColor, nullable_string& sOpacity); - void LoadCoordSize (XmlUtils::CXmlNode& oNode, ::CShapePtr pShape); - void LoadCoordPos (XmlUtils::CXmlNode& oNode, ::CShapePtr pShape); - - std::wstring GetDrawingMainProps (XmlUtils::CXmlNode& oNode, PPTX::CCSS& oCssStyles, CSpTreeElemProps& oProps); + void ConvertColor(PPTX::Logic::UniColor& uniColor, nullable_string& sColor, nullable_string& sOpacity); - void ConvertMainPropsToVML (const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter, PPTX::Logic::SpTreeElem& oElem); - void ConvertPicVML (PPTX::Logic::SpTreeElem& oElem, const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter); - void ConvertShapeVML (PPTX::Logic::SpTreeElem& oShape, const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter, bool bSignature = false); - void ConvertGroupVML (PPTX::Logic::SpTreeElem& oGroup, const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter); + void LoadCoordSize(XmlUtils::CXmlNode& oNode, ::CShapePtr pShape); + void LoadCoordPos(XmlUtils::CXmlNode& oNode, ::CShapePtr pShape); - void ConvertTextVML (XmlUtils::CXmlNode &node, PPTX::Logic::Shape* pShape); - void ConvertParaVML (XmlUtils::CXmlNode& node, PPTX::Logic::Paragraph* p); + std::wstring GetDrawingMainProps(XmlUtils::CXmlNode& oNode, PPTX::CCSS& oCssStyles, CSpTreeElemProps& oProps); - HRESULT SetCurrentRelsPath(); + void ConvertMainPropsToVML(const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter, PPTX::Logic::SpTreeElem& oElem); + void ConvertPicVML(PPTX::Logic::SpTreeElem& oElem, const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter); + void ConvertShapeVML(PPTX::Logic::SpTreeElem& oShape, const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter, bool bSignature = false); + void ConvertGroupVML(PPTX::Logic::SpTreeElem& oGroup, const std::wstring& sMainProps, NSBinPptxRW::CXmlWriter& oWriter); + + void ConvertTextVML(XmlUtils::CXmlNode& node, PPTX::Logic::Shape* pShape); + void ConvertParaVML(XmlUtils::CXmlNode& node, PPTX::Logic::Paragraph* p); + + void SaveObject(long lStart, long lLength, const std::wstring& sMainProps, std::wstring& sXml); }; } diff --git a/OOXML/PPTXFormat/Logic/CSld.cpp b/OOXML/PPTXFormat/Logic/CSld.cpp index 3cad32af9d..8d002a7267 100644 --- a/OOXML/PPTXFormat/Logic/CSld.cpp +++ b/OOXML/PPTXFormat/Logic/CSld.cpp @@ -111,6 +111,7 @@ namespace PPTX pWriter->WriteString2(0, attrName); pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + pWriter->ClearCurShapeSize(); pWriter->WriteRecord2(0, bg); pWriter->StartRecord(1); @@ -122,7 +123,7 @@ namespace PPTX pWriter->WriteULONG((_UINT32)spTree.SpTreeElems.size()); for (size_t i = 0; i < spTree.SpTreeElems.size(); i++) { - pWriter->m_bInGroup = false; + pWriter->ClearCurShapeSize(); pWriter->WriteRecord1(0, spTree.SpTreeElems[i]); } pWriter->EndRecord(); diff --git a/OOXML/PPTXFormat/Logic/Fills/Blip.cpp b/OOXML/PPTXFormat/Logic/Fills/Blip.cpp index e9c310fbc3..990a6d023f 100644 --- a/OOXML/PPTXFormat/Logic/Fills/Blip.cpp +++ b/OOXML/PPTXFormat/Logic/Fills/Blip.cpp @@ -302,8 +302,8 @@ namespace PPTX pWriter->EndRecord(); - double dW = pWriter->GetShapeWidth(); //mm - double dH = pWriter->GetShapeHeight(); + double dW = pWriter->GetShapeWidth() / 12700. ; //emu to pt + double dH = pWriter->GetShapeHeight() / 12700.; OOX::IFileContainer* pRels = pWriter->GetRelsPtr(); diff --git a/OOXML/PPTXFormat/Logic/GrpSpPr.cpp b/OOXML/PPTXFormat/Logic/GrpSpPr.cpp index e26b0aa218..7eeaa08d9b 100644 --- a/OOXML/PPTXFormat/Logic/GrpSpPr.cpp +++ b/OOXML/PPTXFormat/Logic/GrpSpPr.cpp @@ -195,9 +195,6 @@ namespace PPTX pWriter->WriteLimit2(0, bwMode); pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); - pWriter->m_dCxCurShape = pWriter->m_dCyCurShape = 1; - pWriter->m_bInGroup = true; - pWriter->WriteRecord2(0, xfrm); pWriter->WriteRecord1(1, Fill); pWriter->WriteRecord1(2, EffectList); diff --git a/OOXML/PPTXFormat/Logic/Pic.cpp b/OOXML/PPTXFormat/Logic/Pic.cpp index 5355e053ad..0bb47518ae 100644 --- a/OOXML/PPTXFormat/Logic/Pic.cpp +++ b/OOXML/PPTXFormat/Logic/Pic.cpp @@ -411,16 +411,16 @@ namespace PPTX office_checker.nFileType == AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM) { embedded_type = 1; - BinDocxRW::CDocxSerializer* old_serializer = pWriter->m_pMainDocument; + BinDocxRW::CDocxSerializer* old_serializer = pWriter->m_pDocxSerializer; BinDocxRW::CDocxSerializer oDocxSerializer; - oDrawingConverter.m_pBinaryWriter->m_pMainDocument = &oDocxSerializer; + oDrawingConverter.m_pBinaryWriter->m_pDocxSerializer = &oDocxSerializer; oDocxSerializer.m_pParamsWriter = new BinDocxRW::ParamsWriter(oDrawingConverter.m_pBinaryWriter, &oFontProcessor, &oDrawingConverter, NULL); BinDocxRW::BinaryFileWriter oBinaryFileWriter(*oDocxSerializer.m_pParamsWriter); oBinaryFileWriter.intoBindoc(oox_unpacked.GetPath()); - pWriter->m_pMainDocument = old_serializer; + pWriter->m_pDocxSerializer = old_serializer; } else if (office_checker.nFileType == AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX || office_checker.nFileType == AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM || @@ -614,16 +614,16 @@ namespace PPTX { pReader->Seek(pReader->GetPos() - 4); //roll back to size record std::wstring sXmlContent; - if (pReader->m_pMainDocument) + if (pReader->m_pDocxSerializer) { - pReader->m_pMainDocument->getXmlContentElem(OOX::et_m_oMathPara, *pReader, sXmlContent); + pReader->m_pDocxSerializer->getXmlContentElem(OOX::et_m_oMathPara, *pReader, sXmlContent); } else { - BinDocxRW::CDocxSerializer oDocxSerializer; - NSBinPptxRW::CDrawingConverter oDrawingConverter; + BinDocxRW::CDocxSerializer oDocxSerializer; + NSBinPptxRW::CDrawingConverter oDrawingConverter; - oDrawingConverter.SetMainDocument(&oDocxSerializer); + oDrawingConverter.SetDocxSerializer(&oDocxSerializer); //oDocxSerializer.m_pParamsWriter = new BinDocxRW::ParamsWriter(oDrawingConverter.m_pBinaryWriter, &oFontProcessor, &oDrawingConverter, NULL); oDocxSerializer.m_pCurFileWriter = new Writers::FileWriter(L"", L"", false, 111, &oDrawingConverter, L""); @@ -1839,9 +1839,9 @@ namespace PPTX std::wstring sThemePath, sMediaPath, sEmbedPath; oDocxSerializer.CreateDocxFolders(sDstEmbeddedTemp, sThemePath, sMediaPath, sEmbedPath); - oDrawingConverter.m_pReader->Init(pData, 0, length); + oDrawingConverter.m_pBinaryReader->Init(pData, 0, length); - oDrawingConverter.SetMainDocument(&oDocxSerializer); + oDrawingConverter.SetDocxSerializer(&oDocxSerializer); oDrawingConverter.SetDstPath(sDstEmbeddedTemp + FILE_SEPARATOR_STR + L"word"); oDrawingConverter.SetSrcPath(pReader->m_strFolder, XMLWRITER_DOC_TYPE_DOCX); @@ -1851,7 +1851,7 @@ namespace PPTX std::wstring sDocxFilename = L"Microsoft_Word_Document" + std::to_wstring(id) + L".docx"; - NSBinPptxRW::CBinaryFileReader& oBufferedStream = *oDrawingConverter.m_pReader; + NSBinPptxRW::CBinaryFileReader& oBufferedStream = *oDrawingConverter.m_pBinaryReader; oDocxSerializer.m_pCurFileWriter = new Writers::FileWriter(sDstEmbeddedTemp, L"", false, 111, &oDrawingConverter, sThemePath); @@ -1914,7 +1914,7 @@ namespace PPTX oXlsx.m_mapEnumeratedGlobal.clear(); - oDrawingConverter.m_pReader->Init(pData, 0, length); + oDrawingConverter.m_pBinaryReader->Init(pData, 0, length); oDrawingConverter.SetDstPath(sDstEmbeddedTemp + FILE_SEPARATOR_STR + L"xl"); oDrawingConverter.SetSrcPath(pReader->m_strFolder, XMLWRITER_DOC_TYPE_XLSX); @@ -1922,7 +1922,7 @@ namespace PPTX oDrawingConverter.SetMediaDstPath(sMediaPath); oDrawingConverter.SetEmbedDstPath(sEmbedPath); - oEmbeddedReader.ReadMainTable(oXlsx, *oDrawingConverter.m_pReader, pReader->m_strFolder, sDstEmbeddedTemp, oSaveParams, &oDrawingConverter); + oEmbeddedReader.ReadMainTable(oXlsx, *oDrawingConverter.m_pBinaryReader, pReader->m_strFolder, sDstEmbeddedTemp, oSaveParams, &oDrawingConverter); oXlsx.PrepareToWrite(); @@ -1951,7 +1951,7 @@ namespace PPTX NSBinPptxRW::CDrawingConverter oDrawingConverter; - oDrawingConverter.m_pReader->Init(pData, 0, length); + oDrawingConverter.m_pBinaryReader->Init(pData, 0, length); std::wstring sXmlOptions, sMediaPath, sEmbedPath; BinVsdxRW::CVsdxSerializer::CreateVsdxFolders(sDstEmbeddedTemp, sMediaPath, sEmbedPath); @@ -1967,7 +1967,7 @@ namespace PPTX BinVsdxRW::BinaryFileReader oEmbeddedReader; BinVsdxRW::SaveParams oSaveParams(true); - oEmbeddedReader.ReadContent(oVsdx, *oDrawingConverter.m_pReader, pReader->m_strFolder, sDstEmbeddedTemp, oSaveParams); + oEmbeddedReader.ReadContent(oVsdx, *oDrawingConverter.m_pBinaryReader, pReader->m_strFolder, sDstEmbeddedTemp, oSaveParams); OOX::CContentTypes oContentTypes; oVsdx.Write(sDstEmbeddedTemp, oContentTypes); diff --git a/OOXML/PPTXFormat/Logic/Runs/MathParaWrapper.cpp b/OOXML/PPTXFormat/Logic/Runs/MathParaWrapper.cpp index 7a1876ba1c..dee9f4f327 100644 --- a/OOXML/PPTXFormat/Logic/Runs/MathParaWrapper.cpp +++ b/OOXML/PPTXFormat/Logic/Runs/MathParaWrapper.cpp @@ -160,9 +160,9 @@ xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\">\ { pWriter->StartRecord(nRecordType); long lDataSize = 0; - if(NULL != pWriter->m_pMainDocument) + if(NULL != pWriter->m_pDocxSerializer) { - pWriter->m_pMainDocument->getBinaryContentElem(eElemType, pElem, *pWriter, lDataSize); + pWriter->m_pDocxSerializer->getBinaryContentElem(eElemType, pElem, *pWriter, lDataSize); } else { @@ -200,15 +200,15 @@ xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\">\ NSBinPptxRW::CDrawingConverter oDrawingConverter; NSBinPptxRW::CImageManager2* pOldImageManager = oDrawingConverter.m_pImageManager; - NSBinPptxRW::CBinaryFileReader* pOldReader = oDrawingConverter.m_pReader; + NSBinPptxRW::CBinaryFileReader* pOldReader = oDrawingConverter.m_pBinaryReader; oDrawingConverter.m_pImageManager = pReader->m_pRels->m_pManager; - oDrawingConverter.m_pReader = pReader; + oDrawingConverter.m_pBinaryReader = pReader; oDocxSerializer.m_pCurFileWriter = new Writers::FileWriter(L"", L"", true, BinDocxRW::g_nFormatVersion, &oDrawingConverter, L""); oDocxSerializer.getXmlContentElem(eType, *pReader, sXml); - oDrawingConverter.m_pReader = pOldReader; + oDrawingConverter.m_pBinaryReader = pOldReader; oDrawingConverter.m_pImageManager = pOldImageManager; RELEASEOBJECT(oDocxSerializer.m_pCurFileWriter); diff --git a/OOXML/PPTXFormat/Logic/Shape.cpp b/OOXML/PPTXFormat/Logic/Shape.cpp index 0d22fa42a1..8182e6ef79 100644 --- a/OOXML/PPTXFormat/Logic/Shape.cpp +++ b/OOXML/PPTXFormat/Logic/Shape.cpp @@ -409,7 +409,7 @@ namespace PPTX }break; case 4: { - if (NULL != pReader->m_pMainDocument) + if (NULL != pReader->m_pDocxSerializer) { LONG lLenRec = pReader->GetLong(); @@ -418,7 +418,7 @@ namespace PPTX BYTE* pData_Reader = pReader->GetData(); std::wstring sXmlContent; - pReader->m_pMainDocument->getXmlContent(*pReader, lLenRec, sXmlContent); + pReader->m_pDocxSerializer->getXmlContent(*pReader, lLenRec, sXmlContent); std::wstring strC = L""; strC += sXmlContent; @@ -505,7 +505,7 @@ namespace PPTX pWriter->WriteRecord1(1, spPr); pWriter->WriteRecord2(2, style); - if (pWriter->m_pMainDocument != NULL) + if (pWriter->m_pDocxSerializer != NULL) { if (oTextBoxShape.is_init()) { @@ -514,7 +514,7 @@ namespace PPTX pWriter->SetPosition(lPos); pWriter->StartRecord(4); - pWriter->m_pMainDocument->getBinaryContentElem(OOX::et_w_sdtContent, oTextBoxShape.GetPointer(), *pWriter, lDataSize); + pWriter->m_pDocxSerializer->getBinaryContentElem(OOX::et_w_sdtContent, oTextBoxShape.GetPointer(), *pWriter, lDataSize); pWriter->EndRecord(); if (oTextBoxBodyPr.is_init()) @@ -531,7 +531,7 @@ namespace PPTX pWriter->SetPosition(lPos); pWriter->StartRecord(4); - pWriter->m_pMainDocument->getBinaryContent(strTextBoxShape.get(), *pWriter, lDataSize); + pWriter->m_pDocxSerializer->getBinaryContent(strTextBoxShape.get(), *pWriter, lDataSize); pWriter->EndRecord(); if (oTextBoxBodyPr.is_init()) @@ -550,7 +550,7 @@ namespace PPTX ULONG lPos = pWriter->GetPosition(); pWriter->SetPosition(lPos); pWriter->StartRecord(4); - pWriter->m_pMainDocument->getBinaryContent(strContent, *pWriter, lDataSize); + pWriter->m_pDocxSerializer->getBinaryContent(strContent, *pWriter, lDataSize); pWriter->EndRecord(); pWriter->WriteRecord2(5, txBody->bodyPr); diff --git a/OOXML/PPTXFormat/Logic/SmartArt.cpp b/OOXML/PPTXFormat/Logic/SmartArt.cpp index 3b70530e2c..9462cbde19 100644 --- a/OOXML/PPTXFormat/Logic/SmartArt.cpp +++ b/OOXML/PPTXFormat/Logic/SmartArt.cpp @@ -178,8 +178,8 @@ namespace PPTX { OOX::IFileContainer* pDocumentRels = pWriter->GetRelsPtr(); - BinDocxRW::CDocxSerializer *main_document = pWriter->m_pMainDocument; - pWriter->m_pMainDocument = NULL; + BinDocxRW::CDocxSerializer *main_document = pWriter->m_pDocxSerializer; + pWriter->m_pDocxSerializer = NULL; if (id_data.IsInit()) { smart_ptr oFileData; @@ -280,7 +280,7 @@ namespace PPTX } } pWriter->SetRelsPtr(pDocumentRels); - pWriter->m_pMainDocument = main_document; + pWriter->m_pDocxSerializer = main_document; } void SmartArt::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) { @@ -622,9 +622,9 @@ namespace PPTX //---------------------------------------------------------------- NSBinPptxRW::CDrawingConverter oDrawingConverter; NSBinPptxRW::CBinaryFileWriter *pOldDrawingWriter = oDrawingConverter.m_pBinaryWriter; - BinDocxRW::CDocxSerializer *pOldMainDocument = pWriter->m_pMainDocument; + BinDocxRW::CDocxSerializer *pOldMainDocument = pWriter->m_pDocxSerializer; - pWriter->m_pMainDocument = NULL; + pWriter->m_pDocxSerializer = NULL; oDrawingConverter.m_pBinaryWriter = pWriter; OOX::IFileContainer* oldRels = oDrawingConverter.GetRelsPtr(); oDrawingConverter.SetRelsPtr(dynamic_cast(file.GetPointer())); @@ -672,7 +672,7 @@ namespace PPTX oDrawingConverter.SetRelsPtr(oldRels); oDrawingConverter.m_pBinaryWriter = pOldDrawingWriter; - pWriter->m_pMainDocument = pOldMainDocument; + pWriter->m_pDocxSerializer = pOldMainDocument; } std::wstring ChartRec::toXML() const @@ -707,10 +707,10 @@ namespace PPTX NSBinPptxRW::CDrawingConverter oDrawingConverter; NSBinPptxRW::CImageManager2* pOldImageManager = oDrawingConverter.m_pImageManager; - NSBinPptxRW::CBinaryFileReader* pOldReader = oDrawingConverter.m_pReader; + NSBinPptxRW::CBinaryFileReader* pOldReader = oDrawingConverter.m_pBinaryReader; oDrawingConverter.m_pImageManager = pReader->m_pRels->m_pManager; - oDrawingConverter.m_pReader = pReader; + oDrawingConverter.m_pBinaryReader = pReader; oXlsxSerializer.setDrawingConverter(&oDrawingConverter); @@ -745,8 +745,8 @@ namespace PPTX id_data = new OOX::RId(nRId); } } - oDrawingConverter.m_pReader = pOldReader; - oDrawingConverter.m_pImageManager = pOldImageManager; + oDrawingConverter.m_pBinaryReader = pOldReader; + oDrawingConverter.m_pImageManager = pOldImageManager; } void ChartRec::FillParentPointersForChilds() { diff --git a/OOXML/PPTXFormat/Logic/SpTree.cpp b/OOXML/PPTXFormat/Logic/SpTree.cpp index 6cacb0f291..25c5483d33 100644 --- a/OOXML/PPTXFormat/Logic/SpTree.cpp +++ b/OOXML/PPTXFormat/Logic/SpTree.cpp @@ -409,15 +409,9 @@ namespace PPTX _UINT32 len = (_UINT32)SpTreeElems.size(); pWriter->WriteULONG(len); - double oldCxCurShape = pWriter->m_dCxCurShape; - double oldCyCurShape = pWriter->m_dCyCurShape; - for (_UINT32 i = 0; i < len; ++i) { - pWriter->WriteRecord1(0, SpTreeElems[i]); - - pWriter->m_dCxCurShape = oldCxCurShape; - pWriter->m_dCyCurShape = oldCyCurShape; + pWriter->WriteRecord1(0, SpTreeElems[i]); } pWriter->EndRecord(); //--------------------------------------------------------------------------------------- @@ -551,8 +545,8 @@ namespace PPTX } void LockedCanvas::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const { - BinDocxRW::CDocxSerializer* docx = pWriter->m_pMainDocument; - pWriter->m_pMainDocument = NULL; + BinDocxRW::CDocxSerializer* docx = pWriter->m_pDocxSerializer; + pWriter->m_pDocxSerializer = NULL; pWriter->StartRecord(SPTREE_TYPE_LOCKED_CANVAS); @@ -561,7 +555,7 @@ namespace PPTX pWriter->WriteRecordArray(2, 0, SpTreeElems); pWriter->EndRecord(); - pWriter->m_pMainDocument = docx; + pWriter->m_pDocxSerializer = docx; } void LockedCanvas::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) { @@ -569,8 +563,8 @@ namespace PPTX pReader->Skip(5); // type + len - BinDocxRW::CDocxSerializer* docx = pReader->m_pMainDocument; - pReader->m_pMainDocument = NULL; + BinDocxRW::CDocxSerializer* docx = pReader->m_pDocxSerializer; + pReader->m_pDocxSerializer = NULL; while (pReader->GetPos() < _end_rec) { @@ -621,7 +615,7 @@ namespace PPTX } } pReader->Seek(_end_rec); - pReader->m_pMainDocument = docx; + pReader->m_pDocxSerializer = docx; } } } diff --git a/OOXML/PPTXFormat/Logic/Xfrm.cpp b/OOXML/PPTXFormat/Logic/Xfrm.cpp index 600f649e4c..185c1620fd 100644 --- a/OOXML/PPTXFormat/Logic/Xfrm.cpp +++ b/OOXML/PPTXFormat/Logic/Xfrm.cpp @@ -291,16 +291,18 @@ namespace PPTX } void Xfrm::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const { - if (chExtX.IsInit() && extX.IsInit()) - pWriter->m_dCxCurShape = pWriter->m_dCxCurShape * (double)*extX / (double)*chExtX; - else if (extX.IsInit()) - pWriter->m_dCxCurShape = ((pWriter->m_bInGroup && pWriter->m_dCxCurShape > 0) ? pWriter->m_dCxCurShape : 1) * *extX; - - if (chExtY.IsInit() && extY.IsInit()) - pWriter->m_dCyCurShape = pWriter->m_dCyCurShape * (double)*extY / (double)*chExtY; - else if (extY.IsInit()) - pWriter->m_dCyCurShape = ((pWriter->m_bInGroup && pWriter->m_dCyCurShape > 0) ? pWriter->m_dCyCurShape : 1) * *extY; + if (pWriter->GetShapeWidth() < 1 || pWriter->GetShapeHeight() < 1) + { + double cx = 0, cy = 0; + + if (extX.IsInit()) + cx = *extX; + if (extY.IsInit()) + cy = *extY; + + pWriter->SetCurShapeSize(cx, cy); + } pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); pWriter->WriteInt2(0, offX); pWriter->WriteInt2(1, offY); diff --git a/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.cpp b/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.cpp index 10ba2ef1ed..134488d7cb 100644 --- a/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.cpp +++ b/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.cpp @@ -92,7 +92,8 @@ namespace Spreadsheet BinXlsxRW::BinaryStyleTableWriter oBinaryStyleTableWriter(*pWriter, &pWriter->m_pCommon->m_pNativePicker->m_oEmbeddedFonts); DocWrapper::FontProcessor oFontProcessor; OOX::Spreadsheet::CIndexedColors* pIndexedColors = NULL; - CXlsx* xlsx = dynamic_cast(pWriter->m_pMainDocument); + + CXlsx* xlsx = dynamic_cast(m_pMainDocument); if (xlsx && xlsx->m_pStyles && xlsx->m_pStyles->m_oColors.IsInit() && xlsx->m_pStyles->m_oColors->m_oIndexedColors.IsInit()) { pIndexedColors = xlsx->m_pStyles->m_oColors->m_oIndexedColors.GetPointer(); @@ -185,7 +186,7 @@ namespace Spreadsheet const char* sName = XmlUtils::GetNameNoNS(oReader.GetNameChar()); if (strcmp("sortRule", sName) == 0) { - CSortRule* pSortRule = new CSortRule(); + CSortRule* pSortRule = new CSortRule(m_pMainDocument); *pSortRule = oReader; m_arrItems.push_back(pSortRule); } @@ -256,7 +257,7 @@ namespace Spreadsheet for (ULONG i = 0; i < _c; ++i) { pReader->Skip(1); // type - m_arrItems.push_back(new CSortRule()); + m_arrItems.push_back(new CSortRule(m_pMainDocument)); m_arrItems.back()->fromPPTY(pReader); } break; @@ -332,7 +333,8 @@ namespace Spreadsheet BinXlsxRW::BinaryStyleTableWriter oBinaryStyleTableWriter(*pWriter, &pWriter->m_pCommon->m_pNativePicker->m_oEmbeddedFonts); DocWrapper::FontProcessor oFontProcessor; OOX::Spreadsheet::CIndexedColors* pIndexedColors = NULL; - CXlsx* xlsx = dynamic_cast(pWriter->m_pMainDocument); + + CXlsx* xlsx = dynamic_cast(m_pMainDocument); if (xlsx && xlsx->m_pStyles && xlsx->m_pStyles->m_oColors.IsInit() && xlsx->m_pStyles->m_oColors->m_oIndexedColors.IsInit()) { pIndexedColors = xlsx->m_pStyles->m_oColors->m_oIndexedColors.GetPointer(); @@ -422,10 +424,10 @@ namespace Spreadsheet void CNsvFilter::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { WritingElement_ReadAttributes_StartChar_No_NS(oReader) - WritingElement_ReadAttributes_Read_ifChar( oReader, "filterId", m_oFilterId) - WritingElement_ReadAttributes_Read_else_ifChar( oReader, "ref", m_oRef) - WritingElement_ReadAttributes_Read_else_ifChar( oReader, "tableId", m_oTableId) - WritingElement_ReadAttributes_EndChar_No_NS( oReader ) + WritingElement_ReadAttributes_Read_ifChar( oReader, "filterId", m_oFilterId) + WritingElement_ReadAttributes_Read_else_ifChar( oReader, "ref", m_oRef) + WritingElement_ReadAttributes_Read_else_ifChar( oReader, "tableId", m_oTableId) + WritingElement_ReadAttributes_EndChar_No_NS( oReader ) } void CNsvFilter::fromXML(XmlUtils::CXmlLiteReader& oReader) { @@ -438,12 +440,15 @@ namespace Spreadsheet const char* sName = XmlUtils::GetNameNoNS(oReader.GetNameChar()); if (strcmp("columnFilter", sName) == 0) { - CColumnFilter* pColumnFilter = new CColumnFilter(); + CColumnFilter* pColumnFilter = new CColumnFilter(m_pMainDocument); *pColumnFilter = oReader; m_arrItems.push_back(pColumnFilter); } else if (strcmp("sortRules", sName) == 0) - m_oSortRules = oReader; + { + m_oSortRules = new CSortRules(m_pMainDocument); + m_oSortRules->fromXML(oReader); + } else if (strcmp("extLst", sName) == 0) m_oExtLst = oReader; } @@ -516,7 +521,7 @@ namespace Spreadsheet for (ULONG i = 0; i < _c; ++i) { pReader->Skip(1); // type - m_arrItems.push_back(new CColumnFilter()); + m_arrItems.push_back(new CColumnFilter(m_pMainDocument)); m_arrItems.back()->fromPPTY(pReader); } break; @@ -545,9 +550,9 @@ namespace Spreadsheet void CNamedSheetView::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { WritingElement_ReadAttributes_StartChar_No_NS(oReader) - WritingElement_ReadAttributes_Read_ifChar( oReader, "name", m_oName) - WritingElement_ReadAttributes_Read_else_ifChar( oReader, "id", m_oId) - WritingElement_ReadAttributes_EndChar_No_NS( oReader ) + WritingElement_ReadAttributes_Read_ifChar( oReader, "name", m_oName) + WritingElement_ReadAttributes_Read_else_ifChar( oReader, "id", m_oId) + WritingElement_ReadAttributes_EndChar_No_NS( oReader ) } void CNamedSheetView::fromXML(XmlUtils::CXmlLiteReader& oReader) { @@ -560,7 +565,7 @@ namespace Spreadsheet const char* sName = XmlUtils::GetNameNoNS(oReader.GetNameChar()); if (strcmp("nsvFilter", sName) == 0) { - CNsvFilter* pNsvFilter = new CNsvFilter(); + CNsvFilter* pNsvFilter = new CNsvFilter(m_pMainDocument); *pNsvFilter = oReader; m_arrItems.push_back(pNsvFilter); } @@ -627,7 +632,7 @@ namespace Spreadsheet for (ULONG i = 0; i < _c; ++i) { pReader->Skip(1); // type - m_arrItems.push_back(new CNsvFilter()); + m_arrItems.push_back(new CNsvFilter(m_pMainDocument)); m_arrItems.back()->fromPPTY(pReader); } break; @@ -663,7 +668,7 @@ namespace Spreadsheet const char* sName = XmlUtils::GetNameNoNS(oReader.GetNameChar()); if (strcmp("namedSheetView", sName) == 0) { - CNamedSheetView* pNamedSheetView = new CNamedSheetView(); + CNamedSheetView* pNamedSheetView = new CNamedSheetView(m_pMainDocument); *pNamedSheetView = oReader; m_arrItems.push_back(pNamedSheetView); } @@ -715,7 +720,7 @@ namespace Spreadsheet for (ULONG i = 0; i < _c; ++i) { pReader->Skip(1); // type - m_arrItems.push_back(new CNamedSheetView()); + m_arrItems.push_back(new CNamedSheetView(m_pMainDocument)); m_arrItems.back()->fromPPTY(pReader); } break; @@ -780,7 +785,8 @@ namespace Spreadsheet if ( !oReader.ReadNextNode() ) return; - m_oNamedSheetViews = oReader; + m_oNamedSheetViews = new CNamedSheetViews(OOX::IFileContainer::m_pMainDocument); + m_oNamedSheetViews->fromXML(oReader); } void CNamedSheetViewFile::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const { diff --git a/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.h b/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.h index 34d95e7370..1d8ce17dfc 100644 --- a/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.h +++ b/OOXML/XlsxFormat/NamedSheetViews/NamedSheetViews.h @@ -68,7 +68,7 @@ namespace OOX { public: WritingElement_AdditionMethods(CSortRule) - CSortRule(){} + CSortRule(OOX::Document* pMain = NULL) : WritingElement(pMain) {} virtual ~CSortRule(){} virtual void fromXML(XmlUtils::CXmlNode& node){} virtual std::wstring toXML() const{return L"";} @@ -82,10 +82,8 @@ namespace OOX { return et_x_SortRule; } - //Attributes nullable_uint m_oColId; nullable_string m_oId; - //Members nullable m_oDxf; // nullable m_oRichSortCondition; nullable m_oSortCondition; @@ -94,7 +92,7 @@ namespace OOX { public: WritingElement_AdditionMethods(CSortRules) - CSortRules(){} + CSortRules(OOX::Document* pMain = NULL) : WritingElementWithChilds(pMain) {} virtual ~CSortRules(){} virtual void fromXML(XmlUtils::CXmlNode& node){} virtual std::wstring toXML() const{return L"";} @@ -108,17 +106,17 @@ namespace OOX { return et_x_SortRules; } - //Attributes + nullable m_oSortMethod;//none nullable_bool m_oCaseSensitive;//False - //Members + nullable m_oExtLst; }; class CColumnFilter : public WritingElementWithChilds { public: WritingElement_AdditionMethods(CColumnFilter) - CColumnFilter(){} + CColumnFilter(OOX::Document* pMain = NULL) : WritingElementWithChilds(pMain) {} virtual ~CColumnFilter(){} virtual void fromXML(XmlUtils::CXmlNode& node){} virtual std::wstring toXML() const{return L"";} @@ -143,7 +141,7 @@ namespace OOX { public: WritingElement_AdditionMethods(CNsvFilter) - CNsvFilter(){} + CNsvFilter(OOX::Document* pMain = NULL) : WritingElementWithChilds(pMain) {} virtual ~CNsvFilter(){} virtual void fromXML(XmlUtils::CXmlNode& node){} virtual std::wstring toXML() const{return L"";} @@ -157,11 +155,10 @@ namespace OOX { return et_x_NsvFilter; } - //Attributes nullable_string m_oFilterId; nullable_string m_oRef; nullable_uint m_oTableId; - //Members + nullable m_oSortRules; nullable m_oExtLst; }; @@ -169,7 +166,7 @@ namespace OOX { public: WritingElement_AdditionMethods(CNamedSheetView) - CNamedSheetView(){} + CNamedSheetView(OOX::Document* pMain = NULL) : WritingElementWithChilds(pMain) {} virtual ~CNamedSheetView(){} virtual void fromXML(XmlUtils::CXmlNode& node){} virtual std::wstring toXML() const{return L"";} @@ -193,7 +190,7 @@ namespace OOX { public: WritingElement_AdditionMethods(CNamedSheetViews) - CNamedSheetViews(){} + CNamedSheetViews(OOX::Document* pMain = NULL) : WritingElementWithChilds(pMain) {} virtual ~CNamedSheetViews(){} virtual void fromXML(XmlUtils::CXmlNode& node){} virtual std::wstring toXML() const{return L"";} From 75477e8c0388d1cfe42a3abe6b21202ba0592d4b Mon Sep 17 00:00:00 2001 From: Dmitry Okunev Date: Thu, 25 Dec 2025 12:30:33 +0300 Subject: [PATCH 122/125] fix text direction --- .../Converter/StarMath2OOXML/StarMath2OOXML.pro | 2 +- .../Converter/StarMath2OOXML/TextDirection.h | 8 ++++++++ .../Reader/Converter/StarMath2OOXML/TypeLanguage.h | 8 -------- .../StarMath2OOXML/cconversionsmtoooxml.cpp | 6 +++--- .../StarMath2OOXML/cconversionsmtoooxml.h | 2 +- .../Converter/StarMath2OOXML/cstarmathpars.cpp | 14 +++++++------- .../Converter/StarMath2OOXML/cstarmathpars.h | 6 +++--- 7 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/TextDirection.h delete mode 100644 OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro index 152df0ec05..5d155cb07d 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro +++ b/OdfFile/Reader/Converter/StarMath2OOXML/StarMath2OOXML.pro @@ -24,7 +24,7 @@ SOURCES += $$PWD/cconversionsmtoooxml.cpp \ $$PWD/cstarmathpars.cpp HEADERS += \ - $$PWD/TypeLanguage.h \ + $$PWD/TextDirection.h \ $$PWD/cconversionsmtoooxml.h \ $$CORE_ROOT_DIR\OOXML\Base\Unit.h \ $$PWD/conversionmathformula.h \ diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TextDirection.h b/OdfFile/Reader/Converter/StarMath2OOXML/TextDirection.h new file mode 100644 index 0000000000..a97c20f681 --- /dev/null +++ b/OdfFile/Reader/Converter/StarMath2OOXML/TextDirection.h @@ -0,0 +1,8 @@ +namespace StarMath +{ +enum class TextDirection +{ + LeftToRight, + RightToLeft, +}; +} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h b/OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h deleted file mode 100644 index 6f0f4d6684..0000000000 --- a/OdfFile/Reader/Converter/StarMath2OOXML/TypeLanguage.h +++ /dev/null @@ -1,8 +0,0 @@ -namespace StarMath -{ -enum class TypeLanguage -{ - Russian, - Arabic, -}; -} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp index 0b720870f3..f5449a066f 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp @@ -105,7 +105,7 @@ namespace StarMath { m_pXmlWrite->WriteNodeEnd(L"m:oMath",false,false); m_pXmlWrite->WriteNodeEnd(L"m:oMathPara",false,false); } - void CConversionSMtoOOXML::StandartProperties(XmlUtils::CXmlWriter* pXmlWrite, CAttribute* pAttribute, const TypeConversion &enTypeConversion, const TypeLanguage &enTypeLang) + void CConversionSMtoOOXML::StandartProperties(XmlUtils::CXmlWriter* pXmlWrite, CAttribute* pAttribute, const TypeConversion &enTypeConversion, const TextDirection &enTypeLang) { if(TypeConversion::docx == enTypeConversion || TypeConversion::undefine == enTypeConversion) { @@ -188,10 +188,10 @@ namespace StarMath { pXmlWrite->WriteNodeBegin(L"w:strike",true); pXmlWrite->WriteNodeEnd(L"w",true,true); } - if(enTypeLang != TypeLanguage::Russian) + if(enTypeLang == TextDirection::RightToLeft) { switch (enTypeLang) { - case StarMath::TypeLanguage::Arabic: + case StarMath::TextDirection::RightToLeft: { pXmlWrite->WriteNodeBegin(L"w:rtl",true); pXmlWrite->WriteNodeEnd(L"w",true,true); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h index cbccf12664..740b98fe35 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.h @@ -40,7 +40,7 @@ namespace StarMath { CConversionSMtoOOXML(); ~CConversionSMtoOOXML(); void StartConversion(const std::vector arPars, const unsigned int& iAlignment = 1); - static void StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion& enTypeConversion, const TypeLanguage& enTypeLang = TypeLanguage::Russian); + static void StandartProperties(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion& enTypeConversion, const TextDirection& enTypeLang = TextDirection::LeftToRight); static void PropertiesMFPR(const std::wstring& wsType,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); static void PropertiesNaryPr(const TypeElement& enTypeOp,bool bEmptySub,bool bEmptySup,XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion,const bool& bEQN = false); static void PropertiesFuncPr(XmlUtils::CXmlWriter* pXmlWrite,CAttribute* pAttribute,const TypeConversion &enTypeConversion); diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp index 7e0e36549a..5e0c7961d1 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.cpp @@ -915,7 +915,7 @@ namespace StarMath } //class methods CElementString CElementString::CElementString(const std::wstring& wsTokenString,const TypeConversion &enTypeConversion) - :CElement(TypeElement::String,enTypeConversion),m_enTypeLang(TypeLanguage::Russian),m_wsString(wsTokenString) + :CElement(TypeElement::String,enTypeConversion),m_enTypeLang(TextDirection::LeftToRight),m_wsString(wsTokenString) { } CElementString::~CElementString() @@ -939,21 +939,21 @@ namespace StarMath break; } } - CheckingForArabicCharacters(); + CheckingTextDirection(); pReader->ClearReader(); } - void CElementString::CheckingForArabicCharacters() + void CElementString::CheckingTextDirection() { - bool bArabic; + bool bRightToLeft; for(wchar_t cOneElement:m_wsString) { if(cOneElement <= 1791 && cOneElement >= 1536) - bArabic = true; + bRightToLeft = true; else return; } - if(bArabic) - m_enTypeLang = TypeLanguage::Arabic; + if(bRightToLeft) + m_enTypeLang = TextDirection::RightToLeft; } void CElementString::ParseEQN(CStarMathReader *pReader) {} diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h index 3dcce5d4dd..639c3e18a7 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cstarmathpars.h @@ -34,7 +34,7 @@ #define CSTARMATHPARS_H #include "typeselements.h" #include "typeConversion.h" -#include "TypeLanguage.h" +#include "TextDirection.h" #include "TFormulaSize.h" #include #include @@ -232,9 +232,9 @@ namespace StarMath void Parse(CStarMathReader* pReader) override; void ParseEQN(CStarMathReader* pReader) override; void ConversionToOOXML(XmlUtils::CXmlWriter* pXmlWrite) override; - void CheckingForArabicCharacters(); + void CheckingTextDirection(); TFormulaSize GetSize() override; - TypeLanguage m_enTypeLang; + TextDirection m_enTypeLang; std::wstring m_wsString; }; From 3839ab4c153e6b4827566a7fe1524e76641639d5 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Thu, 25 Dec 2025 14:26:35 +0300 Subject: [PATCH 123/125] Brush offset, brush scale, tile flip --- PdfFile/PdfFile.cpp | 24 +++++++++++++++++ PdfFile/PdfFile.h | 4 +++ PdfFile/PdfWriter.cpp | 49 ++++++++++++++++++++++++++++++++--- PdfFile/PdfWriter.h | 4 +++ PdfFile/SrcWriter/Pattern.cpp | 18 ++++++++----- PdfFile/SrcWriter/States.cpp | 6 +++++ PdfFile/SrcWriter/States.h | 29 +++++++++++++++++++++ PdfFile/test/test.cpp | 6 ++--- 8 files changed, 127 insertions(+), 13 deletions(-) diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 7e65573d60..860e5fbdf4 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -955,6 +955,30 @@ HRESULT CPdfFile::put_BrushTransform(const Aggplus::CMatrix& oMatrix) return S_FALSE; return m_pInternal->pWriter->put_BrushTransform(oMatrix); } +HRESULT CPdfFile::get_BrushOffset(double& offsetX, double& offsetY) const +{ + if (!m_pInternal->pWriter) + return S_FALSE; + return m_pInternal->pWriter->get_BrushOffset(offsetX, offsetY); +} +HRESULT CPdfFile::put_BrushOffset(const double& offsetX, const double& offsetY) +{ + if (!m_pInternal->pWriter) + return S_FALSE; + return m_pInternal->pWriter->put_BrushOffset(offsetX, offsetY); +} +HRESULT CPdfFile::get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const +{ + if (!m_pInternal->pWriter) + return S_FALSE; + return m_pInternal->pWriter->get_BrushScale(isScale, scaleX, scaleY); +} +HRESULT CPdfFile::put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) +{ + if (!m_pInternal->pWriter) + return S_FALSE; + return m_pInternal->pWriter->put_BrushScale(isScale, scaleX, scaleY); +} HRESULT CPdfFile::get_FontName(std::wstring* wsName) { diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 1cdd33be19..6b5b746cb1 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -236,6 +236,10 @@ public: virtual HRESULT put_BrushTextureImage(Aggplus::CImage* pImage); virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix); virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix); + virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const; + virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY); + virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const; + virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY); //---------------------------------------------------------------------------------------- // Функции для работы со шрифтами //---------------------------------------------------------------------------------------- diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 442a5587e4..4eac18f6c2 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -567,6 +567,26 @@ HRESULT CPdfWriter::put_BrushTransform(const Aggplus::CMatrix& oMatrix) // TODO: return S_OK; } +HRESULT CPdfWriter::get_BrushOffset(double& offsetX, double& offsetY) const +{ + m_oBrush.GetBrushOffset(offsetX, offsetY); + return S_OK; +} +HRESULT CPdfWriter::put_BrushOffset(const double& offsetX, const double& offsetY) +{ + m_oBrush.SetBrushOffset(offsetX, offsetY); + return S_OK; +} +HRESULT CPdfWriter::get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const +{ + m_oBrush.GetBrushScale(isScale, scaleX, scaleY); + return S_OK; +} +HRESULT CPdfWriter::put_BrushScale(bool isScale, const double& scaleX, const double& scaleY) +{ + m_oBrush.SetBrushScale(isScale, scaleX, scaleY); + return S_OK; +} //---------------------------------------------------------------------------------------- // Функции для работы со шрифтами //---------------------------------------------------------------------------------------- @@ -3912,8 +3932,11 @@ void CPdfWriter::UpdateBrush(NSFonts::IApplicationFonts* pAppFonts, const std::w } else { - dL = MM_2_PT(oRect.dLeft); - dB = MM_2_PT(m_dPageHeight - oRect.dTop); + double dOffsetX, dOffsetY; + m_oBrush.GetBrushOffset(dOffsetX, dOffsetY); + + dL = MM_2_PT(oRect.dLeft + dOffsetX); + dB = MM_2_PT(m_dPageHeight - oRect.dTop - dOffsetY); dR = MM_2_PT(oRect.dLeft + oRect.dWidth); dT = MM_2_PT(m_dPageHeight - oRect.dTop - oRect.dHeight); } @@ -3930,22 +3953,40 @@ void CPdfWriter::UpdateBrush(NSFonts::IApplicationFonts* pAppFonts, const std::w dXStepSpacing = dW; dYStepSpacing = dH; } - else + else // Tile { // Размеры картинки заданы в пикселях. Размеры тайла - это размеры картинки в пунктах. dW = (double)nImageW * 72.0 / 96.0; dH = (double)nImageH * 72.0 / 96.0; dT = dB; + + bool isScale; + double scaleX, scaleY; + m_oBrush.GetBrushScale(isScale, scaleX, scaleY); + if (isScale) + { + dW *= scaleX; + dH *= scaleY; + } } + PdfWriter::EImageTilePatternType ePatternType = PdfWriter::imagetilepatterntype_Default; + if (c_BrushTextureModeTileFlipX == lTextureMode) + ePatternType = PdfWriter::imagetilepatterntype_InverseX; + else if (c_BrushTextureModeTileFlipY == lTextureMode) + ePatternType = PdfWriter::imagetilepatterntype_InverseY; + else if (c_BrushTextureModeTileFlipXY == lTextureMode) + ePatternType = PdfWriter::imagetilepatterntype_InverseXY; + // Нам нужно, чтобы левый нижний угол границ нашего пата являлся точкой переноса для матрицы преобразования. PdfWriter::CMatrix* pMatrix = m_pPage->GetTransform(); pMatrix->Apply(dL, dT); PdfWriter::CMatrix oPatternMatrix = *pMatrix; oPatternMatrix.x = dL; oPatternMatrix.y = dT; - m_pPage->SetPatternColorSpace(m_pDocument->CreateImageTilePattern(dW, dH, pImage, &oPatternMatrix, PdfWriter::imagetilepatterntype_Default, dXStepSpacing, dYStepSpacing)); + + m_pPage->SetPatternColorSpace(m_pDocument->CreateImageTilePattern(dW, dH, pImage, &oPatternMatrix, ePatternType, dXStepSpacing, dYStepSpacing)); } } else if (c_BrushTypeHatch1 == lBrushType) diff --git a/PdfFile/PdfWriter.h b/PdfFile/PdfWriter.h index 65d58babc7..c8612cfc33 100644 --- a/PdfFile/PdfWriter.h +++ b/PdfFile/PdfWriter.h @@ -133,6 +133,10 @@ public: HRESULT put_BrushTextureImage(Aggplus::CImage* pImage); HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix); HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix); + HRESULT get_BrushOffset(double& offsetX, double& offsetY) const; + HRESULT put_BrushOffset(const double& offsetX, const double& offsetY); + HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const; + HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY); //---------------------------------------------------------------------------------------- // Функции для работы со шрифтами //---------------------------------------------------------------------------------------- diff --git a/PdfFile/SrcWriter/Pattern.cpp b/PdfFile/SrcWriter/Pattern.cpp index 18a1886343..3d1dbfeef6 100644 --- a/PdfFile/SrcWriter/Pattern.cpp +++ b/PdfFile/SrcWriter/Pattern.cpp @@ -130,7 +130,9 @@ namespace PdfWriter pStream->WriteReal(dW); pStream->WriteStr(" 0 0 "); pStream->WriteReal(dH); - pStream->WriteStr(" 0 0 cm\12"); + pStream->WriteStr(" 0 "); + pStream->WriteReal(dH); + pStream->WriteStr(" cm\12"); pStream->WriteStr("/X1 Do\12"); pStream->WriteStr("Q\12"); @@ -138,7 +140,7 @@ namespace PdfWriter pStream->WriteStr(" 0 0 "); pStream->WriteReal(-dH); pStream->WriteStr(" 0 "); - pStream->WriteReal(2 * dH); + pStream->WriteReal(dH); pStream->WriteStr(" cm\12"); pStream->WriteStr("/X1 Do\12"); } @@ -152,7 +154,9 @@ namespace PdfWriter pStream->WriteReal(dW); pStream->WriteStr(" 0 0 "); pStream->WriteReal(dH); - pStream->WriteStr(" 0 0 cm\12"); + pStream->WriteStr(" 0 "); + pStream->WriteReal(dH); + pStream->WriteStr(" cm\12"); pStream->WriteStr("/X1 Do\12"); pStream->WriteStr("Q\12"); @@ -161,7 +165,7 @@ namespace PdfWriter pStream->WriteStr(" 0 0 "); pStream->WriteReal(-dH); pStream->WriteStr(" 0 "); - pStream->WriteReal(2 * dH); + pStream->WriteReal(dH); pStream->WriteStr(" cm\12"); pStream->WriteStr("/X1 Do\12"); pStream->WriteStr("Q\12"); @@ -172,7 +176,9 @@ namespace PdfWriter pStream->WriteReal(dH); pStream->WriteStr(" "); pStream->WriteReal(2 * dW); - pStream->WriteStr(" 0 cm\12"); + pStream->WriteStr(" "); + pStream->WriteReal(dH); + pStream->WriteStr(" cm\12"); pStream->WriteStr("/X1 Do\12"); pStream->WriteStr("Q\12"); @@ -182,7 +188,7 @@ namespace PdfWriter pStream->WriteStr(" "); pStream->WriteReal(2 * dW); pStream->WriteStr(" "); - pStream->WriteReal(2 * dH); + pStream->WriteReal(dH); pStream->WriteStr(" cm\12"); pStream->WriteStr("/X1 Do\12"); } diff --git a/PdfFile/SrcWriter/States.cpp b/PdfFile/SrcWriter/States.cpp index c65d68a9bc..b5a828d225 100644 --- a/PdfFile/SrcWriter/States.cpp +++ b/PdfFile/SrcWriter/States.cpp @@ -925,4 +925,10 @@ void CBrushState::Reset() m_pShadingColors = NULL; m_pShadingPoints = NULL; m_lShadingPointsCount = 0; + + m_bIsScale = false; + m_dScaleX = 1.0; + m_dScaleY = 1.0; + m_dOffsetX = 0.0; + m_dOffsetY = 0.0; } diff --git a/PdfFile/SrcWriter/States.h b/PdfFile/SrcWriter/States.h index 073a0a58d1..5c14279eed 100644 --- a/PdfFile/SrcWriter/States.h +++ b/PdfFile/SrcWriter/States.h @@ -1060,6 +1060,29 @@ public: lCount = m_lShadingPointsCount; } + inline void GetBrushScale(bool& isScale, double& scaleX, double& scaleY) const + { + isScale = m_bIsScale; + scaleX = m_dScaleX; + scaleY = m_dScaleY; + } + inline void SetBrushScale(bool isScale, const double& scaleX, const double& scaleY) + { + m_bIsScale = isScale; + m_dScaleX = scaleX; + m_dScaleY = scaleY; + } + inline void GetBrushOffset(double& offsetX, double& offsetY) const + { + offsetX = m_dOffsetX; + offsetY = m_dOffsetY; + } + inline void SetBrushOffset(const double& offsetX, const double& offsetY) + { + m_dOffsetX = offsetX; + m_dOffsetY = offsetY; + } + inline double* GetDColor2(int& nSize) { nSize = m_nColor2Size; @@ -1092,6 +1115,12 @@ private: LONG m_lShadingPointsCount; double m_pShadingPattern[6]; // У линейного градиента x0, y0, x1, y1 (2 не используются), у радиального x0, y0, r0, x1, y1, r1 + bool m_bIsScale; + double m_dScaleX; + double m_dScaleY; + double m_dOffsetX; + double m_dOffsetY; + double m_dColor2[4]; int m_nColor2Size; }; diff --git a/PdfFile/test/test.cpp b/PdfFile/test/test.cpp index 01bcf0515d..e081e356f4 100644 --- a/PdfFile/test/test.cpp +++ b/PdfFile/test/test.cpp @@ -340,9 +340,9 @@ TEST_F(CPdfFileTest, ConvertToRaster) } } -TEST_F(CPdfFileTest, ConvertToRasterBase64) +TEST_F(CPdfFileTest, Base64ConvertToRaster) { - //GTEST_SKIP(); + GTEST_SKIP(); // чтение и конвертации бинарника NSFile::CFileBinary oFile; @@ -494,7 +494,7 @@ TEST_F(CPdfFileTest, EditPdf) TEST_F(CPdfFileTest, EditPdfFromBase64) { - GTEST_SKIP(); + //GTEST_SKIP(); NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NSFonts::NSApplicationFontStream::CreateDefaultGlobalMemoryStorage()); From 69948ba383c564657dab872d5b7845933ae12baa Mon Sep 17 00:00:00 2001 From: Elena Subbotina Date: Thu, 25 Dec 2025 16:36:20 +0300 Subject: [PATCH 124/125] . --- OdfFile/Projects/Windows/cpodf.vcxproj | 10 ++++++++-- OdfFile/Projects/Windows/cpodf.vcxproj.filters | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/OdfFile/Projects/Windows/cpodf.vcxproj b/OdfFile/Projects/Windows/cpodf.vcxproj index 0a21068ba0..82c7690522 100644 --- a/OdfFile/Projects/Windows/cpodf.vcxproj +++ b/OdfFile/Projects/Windows/cpodf.vcxproj @@ -93,7 +93,7 @@ Disabled %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) + DONT_WRITE_EMBEDDED_FONTS;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -114,7 +114,7 @@ Disabled ..\include;..\..\DesktopEditor\xml\libxml2\include;%(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) + DONT_WRITE_EMBEDDED_FONTS;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -285,6 +285,8 @@ + + /bigobj %(AdditionalOptions) @@ -684,8 +686,12 @@ + + + + diff --git a/OdfFile/Projects/Windows/cpodf.vcxproj.filters b/OdfFile/Projects/Windows/cpodf.vcxproj.filters index 90f4ea38b7..62dfe40d54 100644 --- a/OdfFile/Projects/Windows/cpodf.vcxproj.filters +++ b/OdfFile/Projects/Windows/cpodf.vcxproj.filters @@ -166,6 +166,12 @@ custom shape + + math + + + math + @@ -341,6 +347,18 @@ custom shape + + math + + + math + + + math + + + math + From d82c96dc0f03a45b3a8ccbf787f1ff606180eff8 Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Thu, 25 Dec 2025 22:18:09 +0400 Subject: [PATCH 125/125] Fix path to binary in docbuilder.py on mac --- DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py b/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py index 3e2b988091..f81d5d26a5 100644 --- a/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py +++ b/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py @@ -26,7 +26,7 @@ def _loadLibrary(path): library_name = 'libdocbuilder.c.dylib' # if there is no dylib file, get library from framework if not os.path.exists(path + '/' + library_name): - path = path + '/docbuilder.c.framework' + path = path + '/docbuilder.c.framework/Versions/A' library_name = 'docbuilder.c' _lib = ctypes.CDLL(path + '/' + library_name)