Skip to content

Commit

Permalink
Fix bug #61643
Browse files Browse the repository at this point in the history
- fix processing og brackets in Unicode
- fix processing of Matrix in Unicode and LaTeX
  • Loading branch information
IgolJack committed Oct 9, 2023
1 parent ae748d3 commit e762eaa
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 62 deletions.
42 changes: 32 additions & 10 deletions word/Math/LaTeXParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 ()
{
Expand Down
12 changes: 9 additions & 3 deletions word/Math/NamesOfLiterals.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@

function OpenBrackets()
{
this.data = ["(", "{", "〖", "⟨", "["];
this.data = ["(", "{", "〖", "⟨", "[", "⌊", "⌈", "⟦"];
this.fromSymbols = {};
this.toSymbols = {};
this.Init();
Expand All @@ -129,7 +129,7 @@
{
this.data = [
")", "}", "⟫", // "\\"
"⟧", "〗", "⟩", "]",
"⟧", "〗", "⟩", "]", "⌋", "⌉", "⟧"
];
this.fromSymbols = {};
this.toSymbols = {};
Expand Down Expand Up @@ -1373,6 +1373,9 @@
"⟩": 10217,

}
if (code === undefined)
return -1;

if (code) {
let strBracket = oBrackets[code];
if (strBracket) {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
94 changes: 69 additions & 25 deletions word/Math/UnicodeParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -623,36 +629,56 @@
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);
}

let arrContent = this.GetContentOfBracket();
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],
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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)
{
Expand All @@ -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())
Expand Down
50 changes: 26 additions & 24 deletions word/Math/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e762eaa

Please sign in to comment.