Commit 8313434c authored by Sergey.Tsarkov's avatar Sergey.Tsarkov Committed by Alexander.Trofimov

Автозамена формул

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@59435 954022d7-b5bf-4e40-9824-e11837661b57
parent a28783fd
...@@ -4010,8 +4010,29 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE ...@@ -4010,8 +4010,29 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
var Element = AutoCorrectionEngine.Elements[CurPos]; var Element = AutoCorrectionEngine.Elements[CurPos];
if (undefined === Element.Text) if (undefined === Element.Text)
TempElements.splice(0, 0, Element); TempElements.splice(0, 0, Element);
else if ('(' === Element.Text)
TempElements.splice(0, 0, Element);
else if (')' === Element.Text)
TempElements.splice(0, 0, Element);
else if ('/' === Element.Text) else if ('/' === Element.Text)
{ {
AutoCorrectionEngine.Type = MATH_FRACTION;
CurPos--;
break;
}
else if ('^' === Element.Text)
{
TempElements.Type = DEGREE_SUPERSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SUPERSCRIPT;
AutoCorrectionEngine.Type = MATH_DEGREE;
CurPos--;
break;
}
else if ('_' === Element.Text)
{
TempElements.Type = DEGREE_SUBSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SUBSCRIPT;
AutoCorrectionEngine.Type = MATH_DEGREE;
CurPos--; CurPos--;
break; break;
} }
...@@ -4029,6 +4050,31 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE ...@@ -4029,6 +4050,31 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
var Element = AutoCorrectionEngine.Elements[CurPos]; var Element = AutoCorrectionEngine.Elements[CurPos];
if (undefined === Element.Text) if (undefined === Element.Text)
TempElements2.splice(0, 0, Element); TempElements2.splice(0, 0, Element);
else if ('(' === Element.Text)
TempElements2.splice(0, 0, Element);
else if (')' === Element.Text)
TempElements2.splice(0, 0, Element);
else if ('_' === Element.Text)
{
if (TempElements2.length == 0)
break;
TempElements2.Type = DEGREE_SUBSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SubSup;
AutoCorrectionEngine.Type = MATH_DEGREESubSup;
CurPos--;
break;
}
else if ('^' === Element.Text)
{
if (TempElements2.length == 0)
break;
TempElements2.Type = DEGREE_SUPERSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SubSup;
AutoCorrectionEngine.Type = MATH_DEGREESubSup;
CurPos--;
break;
}
else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)]) else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)])
break; break;
else else
...@@ -4037,49 +4083,120 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE ...@@ -4037,49 +4083,120 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
CurPos--; CurPos--;
} }
if (TempElements2.length > 0) var TempElements3 = [];
{ if (AutoCorrectionEngine.Type == MATH_DEGREESubSup)
var Fraction = new CFraction(new CMathFractionPr()); {
while (CurPos >= 0)
var DenMathContent = Fraction.Content[0]; {
var NumMathContent = Fraction.Content[1]; var Element = AutoCorrectionEngine.Elements[CurPos];
if (undefined === Element.Text)
for (var nPos = 0; nPos < TempElements2.length; nPos++) TempElements3.splice(0, 0, Element);
{ else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)])
if (undefined === TempElements2[nPos].Text) break;
DenMathContent.Internal_Content_Add(nPos, TempElements2[nPos].Element); else
else TempElements3.splice(0, 0, Element);
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true); CurPos--;
var MathText = new CMathText(); }
MathText.add(TempElements2[nPos].Text.charCodeAt(0)); }
MathRun.Add_ToContent(nPos, MathText);
DenMathContent.Internal_Content_Add(nPos, MathRun); if (AutoCorrectionEngine.Type == MATH_FRACTION)
} {
} if (TempElements2.length > 0)
{
for (var nPos = 0; nPos < TempElements.length; nPos++) var Fraction = new CFraction(new CMathFractionPr());
{
if (undefined === TempElements[nPos].Text) var DenMathContent = Fraction.Content[0];
NumMathContent.Internal_Content_Add(nPos, TempElements[nPos]); var NumMathContent = Fraction.Content[1];
else
{ this.PackTextToContent(DenMathContent, TempElements2);
var MathRun = new ParaRun(this.ParaMath.Paragraph, true); this.PackTextToContent(NumMathContent, TempElements);
var MathText = new CMathText();
MathText.add(TempElements[nPos].Text.charCodeAt(0)); AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
MathRun.Add_ToContent(nPos, MathText); AutoCorrectionEngine.ReplaceContent.push(Fraction);
NumMathContent.Internal_Content_Add(nPos, MathRun);
} return true;
} }
}
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1; else if (AutoCorrectionEngine.Type == MATH_DEGREE)
AutoCorrectionEngine.ReplaceContent.push(Fraction); {
//if (TempElements2.length > 0)
return true; //{
} var props = new CMathDegreePr();
props.type = AutoCorrectionEngine.Kind;
var oDegree = new CDegree(props)
var BaseContent = oDegree.Content[0];
var IterContent = oDegree.Content[1];
this.PackTextToContent(BaseContent, TempElements2);
this.PackTextToContent(IterContent, TempElements);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.ReplaceContent.push(oDegree);
return true;
//}
}
else if (AutoCorrectionEngine.Type == MATH_DEGREESubSup)
{
if (TempElements2.length > 0 || TempElements3.length > 0)
{
var props = new CMathDegreePr();
props.type = AutoCorrectionEngine.Kind;
var oDegree = new CDegreeSubSup(props)
var BaseContent = oDegree.Content[0];
var IterUpContent = oDegree.Content[1];
var IterDnContent = oDegree.Content[2];
if (TempElements.Type == DEGREE_SUPERSCRIPT)
{
this.PackTextToContent(IterUpContent, TempElements2);
this.PackTextToContent(IterDnContent, TempElements);
}
else if (TempElements.Type == DEGREE_SUBSCRIPT)
{
this.PackTextToContent(IterUpContent, TempElements);
this.PackTextToContent(IterDnContent, TempElements2);
}
this.PackTextToContent(BaseContent, TempElements3);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.ReplaceContent.push(oDegree);
return true;
}
}
return false; return false;
}; };
CMathContent.prototype.PackTextToContent = function(Element, TempElements)
{
var len = TempElements.length;
if (len > 1)
if (TempElements[0].Text === '(' && TempElements[len-1].Text === ')')
{
TempElements.splice(len-1,1);
TempElements.splice(0,1);
len -= 2 ;
}
for (var nPos = 0; nPos < len; nPos++)
{
if (undefined === TempElements[nPos].Text)
Element.Internal_Content_Add(nPos, TempElements[nPos].Element);
else
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
var MathText = new CMathText();
MathText.add(TempElements[nPos].Text.charCodeAt(0));
MathRun.Add_ToContent(nPos, MathText);
Element.Internal_Content_Add(nPos, MathRun);
}
}
};
function CMathAutoCorrectEngine(Element) function CMathAutoCorrectEngine(Element)
{ {
...@@ -4087,6 +4204,8 @@ function CMathAutoCorrectEngine(Element) ...@@ -4087,6 +4204,8 @@ function CMathAutoCorrectEngine(Element)
this.Elements = []; this.Elements = [];
this.CollectText = true; this.CollectText = true;
this.Type = null;
this.Kind = null;
this.RemoveCount = 0; this.RemoveCount = 0;
this.ReplaceContent = []; this.ReplaceContent = [];
......
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