From e762eaa8a8eed2b1d9fb5db0a2bbc239f3cfdddb Mon Sep 17 00:00:00 2001 From: EvgeniyIgol Date: Mon, 9 Oct 2023 18:18:51 +0300 Subject: [PATCH] Fix bug #61643 - fix processing og brackets in Unicode - fix processing of Matrix in Unicode and LaTeX --- word/Math/LaTeXParser.js | 42 ++++++++++++---- word/Math/NamesOfLiterals.js | 12 +++-- word/Math/UnicodeParser.js | 94 ++++++++++++++++++++++++++---------- word/Math/operators.js | 50 ++++++++++--------- 4 files changed, 136 insertions(+), 62 deletions(-) diff --git a/word/Math/LaTeXParser.js b/word/Math/LaTeXParser.js index 7a858c4681..9bf56276df 100644 --- a/word/Math/LaTeXParser.js +++ b/word/Math/LaTeXParser.js @@ -254,28 +254,34 @@ return ( this.oLookahead.class === oLiteralNames.opOpenBracket[0] || this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0] || - this.oLookahead.data === "├" || this.oLookahead.data === "\\left" ); }; + CLaTeXParser.prototype.IsBracketLiteral = function () + { + return this.oLookahead.class === oLiteralNames.opOpenBracket[0] || + this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0] || + this.oLookahead.class === oLiteralNames.opCloseBracket[0]; + } CLaTeXParser.prototype.GetBracketLiteral = function () { - let arrBracketContent, strLeftSymbol, strRightSymbol; + let arrBracketContent, + strLeftSymbol, + strRightSymbol; - if (this.oLookahead.data === "├" || this.oLookahead.data === "\\left") + if (this.oLookahead.data === "\\left") { this.EatToken(this.oLookahead.class); - if (this.oLookahead.class === oLiteralNames.opOpenBracket[0] || this.oLookahead.data === "." || this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0]) { + if (this.IsBracketLiteral() || this.oLookahead.data === ".") strLeftSymbol = this.EatToken(this.oLookahead.class).data; - } arrBracketContent = this.GetContentOfBracket(); - if (this.oLookahead.data === "┤" || this.oLookahead.data === "\\right") + if (this.oLookahead.data === "\\right") { this.EatToken(this.oLookahead.class); - if (this.oLookahead.class === oLiteralNames.opCloseBracket[0] || this.oLookahead.data === "." || this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0]) { + if (this.IsBracketLiteral() || this.oLookahead.data === ".") { strRightSymbol = this.EatToken(this.oLookahead.class).data; } } @@ -1063,9 +1069,21 @@ let arrMatrixContent = []; + let nCounter = 0; while (this.oLookahead.data !== "}" && this.oLookahead.class !== "endOfMatrix") { - arrMatrixContent.push(this.GetRayOfMatrixLiteral()); + let oContent = this.GetRayOfMatrixLiteral(); + if (oContent === undefined) + { + oContent = []; + nCounter++; + } + arrMatrixContent.push(oContent); + } + + while(arrMatrixContent.length < nCounter + 1) + { + arrMatrixContent.push([]); } let intMaxLengthOfMatrixRow = -Infinity; @@ -1074,6 +1092,10 @@ for (let i = 0; i < arrMatrixContent.length; i++) { let arrContent = arrMatrixContent[i]; + if (arrContent === undefined) + { + arrMatrixContent[i] = arrContent = []; + } intMaxLengthOfMatrixRow = arrContent.length; intIndexOfMaxMatrixRow = i; } @@ -1114,12 +1136,12 @@ if (this.oLookahead.data === "\\\\") { - this.EatToken(this.oLookahead.class) + this.EatToken(this.oLookahead.class); } this.SkipFreeSpace(); - return arrRayContent + return arrRayContent; }; CLaTeXParser.prototype.GetElementOfMatrix = function () { diff --git a/word/Math/NamesOfLiterals.js b/word/Math/NamesOfLiterals.js index 6c874e61aa..984b487a60 100644 --- a/word/Math/NamesOfLiterals.js +++ b/word/Math/NamesOfLiterals.js @@ -117,7 +117,7 @@ function OpenBrackets() { - this.data = ["(", "{", "〖", "⟨", "["]; + this.data = ["(", "{", "〖", "⟨", "[", "⌊", "⌈", "⟦"]; this.fromSymbols = {}; this.toSymbols = {}; this.Init(); @@ -129,7 +129,7 @@ { this.data = [ ")", "}", "⟫", // "\\" - "⟧", "〗", "⟩", "]", + "⟧", "〗", "⟩", "]", "⌋", "⌉", "⟧" ]; this.fromSymbols = {}; this.toSymbols = {}; @@ -1373,6 +1373,9 @@ "⟩": 10217, } + if (code === undefined) + return -1; + if (code) { let strBracket = oBrackets[code]; if (strBracket) { @@ -1922,6 +1925,9 @@ } let rows = oTokens.value.length; let cols = oTokens.value[0].length; + + if (cols === 0) + cols++; if (strEndBracket && strStartBracket) { let Delimiter = oContext.Add_DelimiterEx(new CTextPr(), 1, [null], strStartBracket, strEndBracket); oContext = Delimiter.getElementMathContent(0); @@ -1939,7 +1945,7 @@ } break; case oNamesOfLiterals.arrayLiteral[num]: - let intCountOfRows = oTokens.value.length + let intCountOfRows = oTokens.value.length + 1; let oEqArray = oContext.Add_EqArray({ ctrPrp: new CTextPr(), row: intCountOfRows diff --git a/word/Math/UnicodeParser.js b/word/Math/UnicodeParser.js index 1002a1ab86..ab4dbf5864 100644 --- a/word/Math/UnicodeParser.js +++ b/word/Math/UnicodeParser.js @@ -605,6 +605,12 @@ third: oThird, } }; + CUnicodeParser.prototype.IsBracketLiteral = function () + { + return AscMath.MathLiterals.rBrackets.IsIncludes(this.oLookahead.data) + || AscMath.MathLiterals.lBrackets.IsIncludes(this.oLookahead.data) + || AscMath.MathLiterals.lrBrackets.IsIncludes(this.oLookahead.data) + } CUnicodeParser.prototype.IsExpBracketLiteral = function () { return ( @@ -623,14 +629,27 @@ strClose, oExp; - if (this.oLookahead.class === oLiteralNames.opOpenBracket[0] || this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0]) + if (this.oLookahead.class === oLiteralNames.opOpenBracket[0] || this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0] || this.oLookahead.class === "├") { - strOpen = this.GetOpOpenLiteral(); + if (this.oLookahead.data === "├") + { + this.EatToken("├"); + if (this.IsBracketLiteral()) + { + strOpen = this.oLookahead.data; + this.EatToken(this.oLookahead.class); + } + } + else if (this.IsBracketLiteral()) + { + strOpen = this.GetOpOpenLiteral(); + } if (strOpen === "|" || strOpen === "‖") this.strBreakSymbol.push(strOpen); - if (this.IsPreScriptLiteral() && strOpen === "(") { + if (this.IsPreScriptLiteral() && strOpen === "(") + { return this.GetPreScriptLiteral(strOpen); } @@ -638,21 +657,28 @@ oExp = arrContent[0]; let counter = arrContent[1]; - if (oExp.length === 0 && !this.IsOpCloserLiteral()) { + if (oExp.length === 0 && !this.IsOpCloserLiteral()) + { return { type: oLiteralNames.charLiteral[num], value: strOpen, } } - if (this.oLookahead.class === "┤") + if (this.oLookahead.data === "┤") + { this.EatToken("┤"); - - - if (this.oLookahead.class === oLiteralNames.opOpenCloseBracket[0] || this.oLookahead.class === oLiteralNames.opCloseBracket[0]) - strClose = this.GetOpCloseLiteral(); + if (this.IsBracketLiteral()) + { + strClose = this.oLookahead.data; + this.EatToken(this.oLookahead.class); + } + } else - strClose = "."; + { + if (this.IsBracketLiteral()) + strClose = this.GetOpCloseLiteral(); + } return { type: oLiteralNames.bracketBlockLiteral[num], @@ -1631,16 +1657,25 @@ CUnicodeParser.prototype.GetRowsLiteral = function () { let arrRows = []; - + let nCount = 0; while (this.IsRowLiteral() || this.oLookahead.class === "@") { if (this.oLookahead.class === "@") { this.EatToken("@"); + nCount++; } else { arrRows.push(this.GetRowLiteral()); } } + + if (arrRows.length !== nCount + 1) + { + while (arrRows.length != nCount + 1) + { + arrRows.push([]); + } + } return arrRows }; CUnicodeParser.prototype.GetArrayLiteral = function () @@ -1730,7 +1765,11 @@ }; CUnicodeParser.prototype.IsExpLiteral = function () { - return this.IsElementLiteral() || this.oLookahead.class === oLiteralNames.operatorLiteral[0] || this.oLookahead.data === "/" || this.IsPreScriptLiteral(); + return this.IsElementLiteral() || + this.oLookahead.class === oLiteralNames.operatorLiteral[0] || + this.oLookahead.data === "/" || + this.oLookahead.data === "¦" || + this.IsPreScriptLiteral(); }; CUnicodeParser.prototype.GetExpLiteral = function (arrCorrectSymbols) { @@ -1741,21 +1780,26 @@ while (this.IsExpLiteral() || arrCorrectSymbols.includes(this.oLookahead.data)) { - if (this.oLookahead.data === "/") + if (this.oLookahead.data === "/" || this.oLookahead.data === "¦" || this.oLookahead.data === "⒞") { - let down; - this.EatToken(this.oLookahead.class) - if (this.oLookahead.class) - { - down = this.GetElementLiteral() - } + let type = oLiteralNames.fractionLiteral[num]; + + if (this.oLookahead.data === "¦") + type = oLiteralNames.binomLiteral[num]; - oExpLiteral.push({ - type: oLiteralNames.fractionLiteral[num], - up: null, - down: down, - fracType: null, - }) + let down; + let intTypeFraction = this.GetFractionType(this.oLookahead.data); + this.EatToken(this.oLookahead.class) + + if (this.oLookahead.class) + down = this.GetElementLiteral(); + + oExpLiteral.push({ + type: type, + up: null, + down: down, + fracType: intTypeFraction, + }) } else if (this.IsElementLiteral()) diff --git a/word/Math/operators.js b/word/Math/operators.js index 60a706ef99..db8684a3dd 100644 --- a/word/Math/operators.js +++ b/word/Math/operators.js @@ -4053,39 +4053,41 @@ CDelimiter.prototype.GetTextOfElement = function(isLaTeX) { var strTemp = ""; var strStartSymbol = this.Pr.begChr === -1 ? "" : String.fromCharCode((this.begOper.code || this.Pr.begChr) || 40); var strEndSymbol = this.Pr.endChr === -1 ? "" : String.fromCharCode((this.endOper.code || this.Pr.endChr) || 41); - var strSeparatorSymbol = isLaTeX ? "\\mid " : "∣"; - if (isLaTeX) - { - strStartSymbol = strStartSymbol === "" ? "." : strStartSymbol; - strTemp += "\\left" + strStartSymbol; - } - else - { - strStartSymbol = strStartSymbol === "" ? "├" : strStartSymbol; - strTemp += strStartSymbol; - } + if ((!AscMath.MathLiterals.lBrackets.IsIncludes(strStartSymbol) && !AscMath.MathLiterals.lrBrackets.IsIncludes(strStartSymbol)) || isLaTeX) + { + strTemp += isLaTeX ? "\\left" : "├"; + strTemp += strStartSymbol; + } + else + { + strTemp += strStartSymbol; + } for (let intCount = 0; intCount < this.Content.length; intCount++) - { + { strTemp += this.Content[intCount].GetMultipleContentForGetText(isLaTeX, true); - if (strSeparatorSymbol && this.Content.length > 1 && intCount < this.Content.length - 1) strTemp += strSeparatorSymbol; } - if (isLaTeX) - { - strEndSymbol = strEndSymbol === "" ? "." : strEndSymbol; - strTemp += "\\right" + strEndSymbol; - } - else - { - strEndSymbol = strEndSymbol === "" ? "┤" : strEndSymbol; - strTemp += strEndSymbol; - } - + if ((!AscMath.MathLiterals.lrBrackets.IsIncludes(strEndSymbol) && !AscMath.MathLiterals.rBrackets.IsIncludes(strEndSymbol)) || isLaTeX) + { + strTemp += isLaTeX ? "\\right" : "┤"; + strTemp += strEndSymbol; + } + else + { + if ("├" === strTemp) + { + strTemp += "┤" + strEndSymbol; + } + else + { + strTemp += strEndSymbol; + } + } return strTemp; }