Commit 82a95873 authored by Sergey.Tsarkov's avatar Sergey.Tsarkov Committed by Alexander Trofimov

поправлены баги при падениях

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@59606 954022d7-b5bf-4e40-9824-e11837661b57
parent 3278762b
...@@ -29,6 +29,7 @@ namespace MathEquation ...@@ -29,6 +29,7 @@ namespace MathEquation
std::stack<int> m_aAccentStack; std::stack<int> m_aAccentStack;
std::stack<int> m_aRowsCounter; std::stack<int> m_aRowsCounter;
std::stack<int> m_aRowsPosCounter; std::stack<int> m_aRowsPosCounter;
std::stack<int> m_aDelimiterStack;
LONG nTextSize; LONG nTextSize;
LONG nCtrlSize; LONG nCtrlSize;
...@@ -114,9 +115,12 @@ namespace MathEquation ...@@ -114,9 +115,12 @@ namespace MathEquation
} }
virtual void EndEquation() virtual void EndEquation()
{ {
int nCurPos = m_aEquationStack.top(); if (!m_aEquationStack.empty())
WriteItemEnd(nCurPos); {
m_aEquationStack.pop(); int nCurPos = m_aEquationStack.top();
WriteItemEnd(nCurPos);
m_aEquationStack.pop();
}
} }
virtual void BeginBlock() virtual void BeginBlock()
{ {
...@@ -137,21 +141,13 @@ namespace MathEquation ...@@ -137,21 +141,13 @@ namespace MathEquation
} }
virtual void SetSize(uint16_t nSize) virtual void SetSize(uint16_t nSize)
{ {
nTextSize = nSize*2; nTextSize = nSize*2;
if (!m_aCommandStack.empty())
{
ECommandType type;
type = m_aCommandStack.top()->GetCommand();
int i = 1;
}
} }
virtual void BeginChar(Unicode_t uChar, uint8_t nTypeFace, bool bSpecialSymbol) virtual void BeginChar(Unicode_t uChar, uint8_t nTypeFace, bool bSpecialSymbol)
{ {
BOOL bIsOpen; BOOL bIsOpen;
if (!m_aCommandStack.empty()) if (!m_aCommandStack.empty())
bIsOpen = m_aCommandStack.top()->IsOpenNode(); // false ctrlPrp bIsOpen = m_aCommandStack.top()->IsOpenNode(); //if false write ctrlPrp
else else
bIsOpen = true; bIsOpen = true;
...@@ -228,26 +224,29 @@ namespace MathEquation ...@@ -228,26 +224,29 @@ namespace MathEquation
} }
virtual void EndChar() virtual void EndChar()
{ {
int nCurPos = m_aRunStack.top(); if (!m_aRunStack.empty())
WriteItemEnd(nCurPos);
m_aRunStack.pop();
if (bEmbel)
{ {
int nCurPos; int nCurPos = m_aRunStack.top();
if (!m_aAccentStack.empty()) WriteItemEnd(nCurPos);
{ m_aRunStack.pop();
nCurPos = m_aAccentStack.top();
m_aAccentStack.pop(); if (bEmbel)
WriteItemEnd(nCurPos);
}
if (!m_aAccentStack.empty())
{ {
nCurPos = m_aAccentStack.top(); int nCurPos;
m_aAccentStack.pop(); if (!m_aAccentStack.empty())
WriteItemEnd(nCurPos); {
nCurPos = m_aAccentStack.top();
m_aAccentStack.pop();
WriteItemEnd(nCurPos);
}
if (!m_aAccentStack.empty())
{
nCurPos = m_aAccentStack.top();
m_aAccentStack.pop();
WriteItemEnd(nCurPos);
}
bEmbel = false;
} }
bEmbel = false;
} }
} }
virtual void BeginMatrix(uint8_t nVAlign, MMATRIXHORALIGN eHorAlign, MMATRIXVERALIGN eVerAlign, bool bEqualRows, bool bEqualCols, uint8_t nRows, uint8_t nCols, uint8_t* pVerBorders, uint8_t* pHorBorders) virtual void BeginMatrix(uint8_t nVAlign, MMATRIXHORALIGN eHorAlign, MMATRIXVERALIGN eVerAlign, bool bEqualRows, bool bEqualCols, uint8_t nRows, uint8_t nCols, uint8_t* pVerBorders, uint8_t* pHorBorders)
...@@ -287,9 +286,12 @@ namespace MathEquation ...@@ -287,9 +286,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aMatrixStack.top(); if (!m_aMatrixStack.empty())
WriteItemEnd(nCurPos); {
m_aMatrixStack.pop(); int nCurPos = m_aMatrixStack.top();
WriteItemEnd(nCurPos);
m_aMatrixStack.pop();
}
} }
virtual void StartPile(uint8_t nHAlign, uint8_t nVAlign) virtual void StartPile(uint8_t nHAlign, uint8_t nVAlign)
{ {
...@@ -325,7 +327,7 @@ namespace MathEquation ...@@ -325,7 +327,7 @@ namespace MathEquation
PushCommand(commandBrackets); PushCommand(commandBrackets);
int nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::Delimiter); int nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::Delimiter);
m_aRadicalStack.push(nCurPos); m_aDelimiterStack.push(nCurPos);
int nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::DelimiterPr); int nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::DelimiterPr);
...@@ -382,6 +384,13 @@ namespace MathEquation ...@@ -382,6 +384,13 @@ namespace MathEquation
virtual void EndBrackets (MBRACKETSTYPE eType, bool bOpen, bool bClose) virtual void EndBrackets (MBRACKETSTYPE eType, bool bOpen, bool bClose)
{ {
PopCommand(); PopCommand();
if (!m_aDelimiterStack.empty())
{
int nCurPos = m_aDelimiterStack.top();
WriteItemEnd(nCurPos);
m_aDelimiterStack.pop();
}
} }
virtual void BeginRoot(bool bDegree) virtual void BeginRoot(bool bDegree)
{ {
...@@ -399,9 +408,12 @@ namespace MathEquation ...@@ -399,9 +408,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aRadicalStack.top(); if (!m_aRadicalStack.empty())
WriteItemEnd(nCurPos); {
m_aRadicalStack.pop(); int nCurPos = m_aRadicalStack.top();
WriteItemEnd(nCurPos);
m_aRadicalStack.pop();
}
} }
virtual void BeginFraction(MFRACTIONTYPES eType, bool bInline) virtual void BeginFraction(MFRACTIONTYPES eType, bool bInline)
{ {
...@@ -432,9 +444,12 @@ namespace MathEquation ...@@ -432,9 +444,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aFractionStack.top(); if (!m_aFractionStack.empty())
WriteItemEnd(nCurPos); {
m_aFractionStack.pop(); int nCurPos = m_aFractionStack.top();
WriteItemEnd(nCurPos);
m_aFractionStack.pop();
}
} }
virtual void BeginScript(MSCRIPTALIGN eAlign, bool bBase = false, bool bSup = false, bool bSub = false, bool bInline = true) virtual void BeginScript(MSCRIPTALIGN eAlign, bool bBase = false, bool bSup = false, bool bSub = false, bool bInline = true)
{ {
...@@ -443,51 +458,51 @@ namespace MathEquation ...@@ -443,51 +458,51 @@ namespace MathEquation
int nCurPos; int nCurPos;
int nCurPos1; int nCurPos1;
if (bBase) switch(eAlign)
{ {
switch(eAlign) case scriptalignRight:
{ if (bSub)
case scriptalignRight: {
if (bSub) if (bSup)
{ {
if (bSup) nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSubSup);
{ nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSubSupPr);
nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSubSup);
nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSubSupPr);
}
else
{
nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSub);
nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSubPr);
}
} }
else if (bSup) else
{ {
nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSup); nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSub);
nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSupPr); nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSubPr);
} }
break; }
case scriptalignCenter: break; else if (bSup)
case scriptalignLeft:
{ {
nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SPre); nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSup);
nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SPrePr); nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SSupPr);
} }
break; break;
case scriptalignCenter: break;
case scriptalignLeft:
{
nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SPre);
nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::SPrePr);
} }
if (bInline) break;
WriteItemVal(BinDocxRW::c_oSer_OMathBottomNodesType::AlnScr, true);
WriteItemEnd(nCurPos1);
m_aScriptStack.push(nCurPos);
} }
if (bInline)
WriteItemVal(BinDocxRW::c_oSer_OMathBottomNodesType::AlnScr, true);
WriteItemEnd(nCurPos1);
m_aScriptStack.push(nCurPos);
} }
virtual void EndScript () virtual void EndScript ()
{ {
PopCommand(); PopCommand();
int nCurPos = m_aScriptStack.top(); if (!m_aScriptStack.empty())
WriteItemEnd(nCurPos); {
m_aScriptStack.pop(); int nCurPos = m_aScriptStack.top();
WriteItemEnd(nCurPos);
m_aScriptStack.pop();
}
} }
virtual void BeginBar(MBARTYPE eType, bool bTop) virtual void BeginBar(MBARTYPE eType, bool bTop)
{ {
...@@ -531,9 +546,12 @@ namespace MathEquation ...@@ -531,9 +546,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aGroupChrStack.top(); if (!m_aGroupChrStack.empty())
WriteItemEnd(nCurPos); {
m_aGroupChrStack.pop(); int nCurPos = m_aGroupChrStack.top();
WriteItemEnd(nCurPos);
m_aGroupChrStack.pop();
}
} }
virtual void BeginArrow(MARROWTYPE eType, bool bTop) virtual void BeginArrow(MARROWTYPE eType, bool bTop)
{ {
...@@ -574,9 +592,12 @@ namespace MathEquation ...@@ -574,9 +592,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aGroupChrStack.top(); if (!m_aGroupChrStack.empty())
WriteItemEnd(nCurPos); {
m_aGroupChrStack.pop(); int nCurPos = m_aGroupChrStack.top();
WriteItemEnd(nCurPos);
m_aGroupChrStack.pop();
}
} }
virtual void BeginIntegral(MINTEGRALTYPE eType) virtual void BeginIntegral(MINTEGRALTYPE eType)
{ {
...@@ -727,9 +748,12 @@ namespace MathEquation ...@@ -727,9 +748,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aNArrayStack.top(); if (!m_aNArrayStack.empty())
WriteItemEnd(nCurPos); {
m_aNArrayStack.pop(); int nCurPos = m_aNArrayStack.top();
WriteItemEnd(nCurPos);
m_aNArrayStack.pop();
}
} }
virtual void BeginVerticalBrace(bool bTop) virtual void BeginVerticalBrace(bool bTop)
{ {
...@@ -779,9 +803,12 @@ namespace MathEquation ...@@ -779,9 +803,12 @@ namespace MathEquation
{ {
PopCommand(); PopCommand();
int nCurPos = m_aLimitStack.top(); if (!m_aLimitStack.empty())
WriteItemEnd(nCurPos); {
m_aLimitStack.pop(); int nCurPos = m_aLimitStack.top();
WriteItemEnd(nCurPos);
m_aLimitStack.pop();
}
} }
virtual void BeingNArray(MNARRAYTYPE eType) virtual void BeingNArray(MNARRAYTYPE eType)
{ {
...@@ -956,26 +983,83 @@ namespace MathEquation ...@@ -956,26 +983,83 @@ namespace MathEquation
MNARRAYTYPE eType = pCommand->GetType(); MNARRAYTYPE eType = pCommand->GetType();
PopCommand(); PopCommand();
int nCurPos = m_aNArrayStack.top(); if (!m_aNArrayStack.empty())
WriteItemEnd(nCurPos); {
m_aNArrayStack.pop(); int nCurPos = m_aNArrayStack.top();
WriteItemEnd(nCurPos);
m_aNArrayStack.pop();
}
} }
virtual void BeginLongDivision(MLONGDIVISION eType) virtual void BeginLongDivision(MLONGDIVISION eType)
{ {
PushCommand(commandLongDivision); //PushCommand(commandLongDivision);
if (eType == longdivisionWithResult)
{
BeginFraction(fractionRegular, true);
}
else if (eType == longdivisionRegular)
{
BeginBrackets(bracketsLine, true, false);
}
} }
virtual void EndLongDivision () virtual void EndLongDivision ()
{ {
PopCommand(); ECommandType eType;
CBaseCommand* pCommand = TopCommand();
eType = pCommand->GetCommand();
if (eType == commandFraction)
{
EndFraction();
}
else if (eType == commandBrackets)
{
MBRACKETSTYPE ebType;
EndBrackets(ebType, false,false);
}
} }
virtual void BeginAngleBracketsWithSeparator(MANGLEBRACKETSWITHSEPARATORTYPE eType) virtual void BeginAngleBracketsWithSeparator(MANGLEBRACKETSWITHSEPARATORTYPE eType)
{ {
CBracketsWithSeparatorCommand* pCommand = (CBracketsWithSeparatorCommand*)PushCommand(commandBracketsSep); CBracketsWithSeparatorCommand* pCommand = (CBracketsWithSeparatorCommand*)PushCommand(commandBracketsSep);
pCommand->SetType(eType); pCommand->SetType(eType);
int nCurPos = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::Delimiter);
m_aDelimiterStack.push(nCurPos);
int nCurPos1 = WriteItemStart(BinDocxRW::c_oSer_OMathContentType::DelimiterPr);
CString beg, sep, end;
switch (eType)
{
case angbrwithsepBoth: // < | >
beg.Insert(0,0x27E8); sep.Insert(0, 0x007C); end.Insert(0, 0x27E9);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::BegChr, beg);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::SepChr, sep);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::EndChr, end);
WriteItemValLong(BinDocxRW::c_oSer_OMathBottomNodesType::Column, 2);
break;
case angbrwithsepLeft: // < |
beg.Insert(0,0x27E8); end.Insert(0, 0x007C);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::BegChr, beg);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::EndChr, end);
break;
case angbrwithsepRight: // | >
beg.Insert(0,0x007C); end.Insert(0, 0x27E9);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::BegChr, beg);
WriteItemValStr(BinDocxRW::c_oSer_OMathBottomNodesType::EndChr, end);
break;
}
WriteItemEnd(nCurPos1);
} }
virtual void EndAngleBracketsWithSeparator () virtual void EndAngleBracketsWithSeparator ()
{ {
PopCommand(); PopCommand();
if (!m_aDelimiterStack.empty())
{
int nCurPos = m_aDelimiterStack.top();
WriteItemEnd(nCurPos);
m_aDelimiterStack.pop();
}
} }
void AddFont(uint8_t nTypeFace, std::string sName, bool bBold, bool bItalic) void AddFont(uint8_t nTypeFace, std::string sName, bool bBold, bool bItalic)
...@@ -1040,7 +1124,7 @@ namespace MathEquation ...@@ -1040,7 +1124,7 @@ namespace MathEquation
commandIntegral = 0x07, commandIntegral = 0x07,
commandVerticalBrace = 0x08, commandVerticalBrace = 0x08,
commandNArray = 0x09, commandNArray = 0x09,
commandLongDivision = 0x0a, //commandLongDivision = 0x0a,
commandBracketsSep = 0x0b, commandBracketsSep = 0x0b,
commandVerticalBraceLim = 0x0c commandVerticalBraceLim = 0x0c
}; };
...@@ -1461,14 +1545,6 @@ namespace MathEquation ...@@ -1461,14 +1545,6 @@ namespace MathEquation
} }
} }
void WriteNode(const char* sNodeName, BinaryEquationWriter* pWriter, bool bNodeBegin)
{
if (bNodeBegin)
pWriter->WriteNodeBegin(sNodeName);
else
pWriter->WriteNodeEnd(sNodeName);
}
private: private:
bool bBase; bool bBase;
bool bSup; bool bSup;
...@@ -1582,12 +1658,6 @@ namespace MathEquation ...@@ -1582,12 +1658,6 @@ namespace MathEquation
else else
{ {
WriteEndNode(pWriter); WriteEndNode(pWriter);
/*if (!pWriter->m_aCommandStack.empty())
{
CBaseCommand* pCommand = pWriter->TopCommand();
pCommand->WriteEndBlock(pWriter);
}*/
pWriter->PopCommand(); pWriter->PopCommand();
int nCurPos = pWriter->m_aLimitStack.top(); int nCurPos = pWriter->m_aLimitStack.top();
...@@ -1700,7 +1770,7 @@ namespace MathEquation ...@@ -1700,7 +1770,7 @@ namespace MathEquation
MNARRAYTYPE eType; MNARRAYTYPE eType;
}; };
class CLongDivisionCommand : public CBaseCommand /*class CLongDivisionCommand : public CBaseCommand
{ {
public: public:
CLongDivisionCommand() {} CLongDivisionCommand() {}
...@@ -1724,7 +1794,7 @@ namespace MathEquation ...@@ -1724,7 +1794,7 @@ namespace MathEquation
} }
private: private:
BOOL bPile; BOOL bPile;
}; };*/
class CBracketsWithSeparatorCommand : public CBaseCommand class CBracketsWithSeparatorCommand : public CBaseCommand
{ {
public: public:
...@@ -1750,26 +1820,23 @@ namespace MathEquation ...@@ -1750,26 +1820,23 @@ namespace MathEquation
void Write(BinaryEquationWriter* pWriter, bool bBeginNode) void Write(BinaryEquationWriter* pWriter, bool bBeginNode)
{ {
bOpenNode = bBeginNode;
if (0 == nBlockNum) if (0 == nBlockNum)
{ {
if (angbrwithsepBoth == eType || angbrwithsepLeft == eType) if (bBeginNode)
WriteNode("left", pWriter, bBeginNode); WriteBeginNode(pWriter, BinDocxRW::c_oSer_OMathContentType::Element);
else else
WriteNode("right", pWriter, bBeginNode); WriteEndNode(pWriter);
} }
else if (1 == nBlockNum) else if (1 == nBlockNum)
{ {
WriteNode("right", pWriter, bBeginNode); if (bBeginNode)
WriteBeginNode(pWriter, BinDocxRW::c_oSer_OMathContentType::Element);
else
WriteEndNode(pWriter);
} }
} }
void WriteNode(const char* sNodeName, BinaryEquationWriter* pWriter, bool bNodeBegin)
{
if (bNodeBegin)
pWriter->WriteNodeBegin(sNodeName);
else
pWriter->WriteNodeEnd(sNodeName);
}
private: private:
MANGLEBRACKETSWITHSEPARATORTYPE eType; MANGLEBRACKETSWITHSEPARATORTYPE eType;
...@@ -1790,7 +1857,7 @@ namespace MathEquation ...@@ -1790,7 +1857,7 @@ namespace MathEquation
case commandVerticalBrace: pCommand = new CVerticalBraceCommand(); break; case commandVerticalBrace: pCommand = new CVerticalBraceCommand(); break;
case commandVerticalBraceLim: pCommand = new CVerticalBraceLimCommand(); break; case commandVerticalBraceLim: pCommand = new CVerticalBraceLimCommand(); break;
case commandNArray: pCommand = new CNArrayCommand(); break; case commandNArray: pCommand = new CNArrayCommand(); break;
case commandLongDivision: pCommand = new CLongDivisionCommand(); break; //case commandLongDivision: pCommand = new CLongDivisionCommand(); break;
case commandBracketsSep: pCommand = new CBracketsWithSeparatorCommand(); break; case commandBracketsSep: pCommand = new CBracketsWithSeparatorCommand(); break;
} }
...@@ -1811,63 +1878,6 @@ namespace MathEquation ...@@ -1811,63 +1878,6 @@ namespace MathEquation
{ {
return m_aCommandStack.top(); return m_aCommandStack.top();
} }
void WriteNodeBegin(const char* sName, bool bAttributes = false)
{
rRet += "<";
rRet += sName;
if (!bAttributes)
rRet += ">";
}
void WriteNodeEnd(bool bEmpty = false)
{
if (bEmpty)
rRet += "/>";
else
rRet += ">";
}
void WriteNodeEnd(const char* sName)
{
rRet += "</";
rRet += sName;
rRet += ">";
}
void WriteBOOLAttribute(const char* sName, bool bValue)
{
rRet += " ";
rRet += sName;
rRet += "=\"";
if (bValue)
rRet += "true";
else
rRet += "false";
rRet += "\"";
}
void WriteStringAttribute(const char* sName, std::string sValue)
{
/*rRet += " ";
rRet += sName;
rRet += "=\"";
rRet += sValue;
rRet += "\"";*/
}
void WriteStringAttribute(const char* sName, Unicode_t uChar)
{
/*rRet += " ";
rRet += sName;
rRet += "=\"";
rRet += uChar;
rRet += "\"";*/
}
void WriteIntAttribute(const char* sName, int nValue)
{
/*rRet += " ";
rRet += sName;
rRet += "=\"";
rRet += String::CreateFromInt32(nValue);
rRet += "\"";*/
}
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment