<commit_before>"use strict";

//величина символа "сигма" не меняется в зависимости от аргумента
//если не выставлено в настройках
/////////////////////****//////////////////////////

function CMathNaryPr()
{
    this.chr     = undefined;
    this.chrType = NARY_INTEGRAL;
    this.grow    = false;
    this.limLoc  = undefined;
    this.subHide = false;
    this.supHide = false;
}

CMathNaryPr.prototype.Set_FromObject = function(Obj)
{
    this.chr     = Obj.chr;
    this.chrType = Obj.chrType;

    if(true === Obj.grow === true || 1 === Obj.grow)
        this.grow = true;

    if(NARY_UndOvr === Obj.limLoc || NARY_SubSup === Obj.limLoc)
        this.limLoc = Obj.limLoc;

    if(true === Obj.subHide === true || 1 === Obj.subHide)
        this.subHide = true;

    if(true === Obj.supHide === true || 1 === Obj.supHide)
        this.supHide = true;
};

CMathNaryPr.prototype.Copy = function()
{
    var NewPr = new CMathNaryPr();

    NewPr.chr     = this.chr    ;
    NewPr.chrType = this.chrType;
    NewPr.grow    = this.grow   ;
    NewPr.limLoc  = this.limLoc ;
    NewPr.subHide = this.subHide;
    NewPr.supHide = this.supHide;

    return NewPr;
};

CMathNaryPr.prototype.Write_ToBinary = function(Writer)
{
    // Long : flags

    // Long : chr
    // Long : chrType
    // Long : limLoc

    // Bool : grow
    // Bool : subHide
    // Bool : supHide

    var StartPos = Writer.GetCurPosition();
    Writer.Skip(4);
    var Flags = 0;

    if (undefined !== this.chr)
    {
        Writer.WriteLong(this.chr);
        Flags |= 1;
    }

    if (undefined !== this.chrType)
    {
        Writer.WriteLong(this.chrType);
        Flags |= 2;
    }

    if (undefined !== this.limLoc)
    {
        Writer.WriteLong(this.limLoc);
        Flags |= 4;
    }

    var EndPos = Writer.GetCurPosition();
    Writer.Seek(StartPos);
    Writer.WriteLong(Flags);
    Writer.Seek(EndPos);

    Writer.WriteBool(this.grow);
    Writer.WriteBool(this.subHide);
    Writer.WriteBool(this.supHide);
};

CMathNaryPr.prototype.Read_FromBinary = function(Reader)
{
    // Long : flags

    // Long : chr
    // Long : chrType
    // Long : limLoc

    // Bool : grow
    // Bool : subHide
    // Bool : supHide

    var Flags = Reader.GetLong();

    if (Flags & 1)
        this.chr = Reader.GetLong();
    else
        this.chr = undefined;

    if (Flags & 2)
        this.chrType = Reader.GetLong();
    else
        this.chrType = undefined;

    if (Flags & 4)
        this.limLoc = Reader.GetLong();
    else
        this.limLoc = undefined;

    this.grow    = Reader.GetBool();
    this.subHide = Reader.GetBool();
    this.supHide = Reader.GetBool();
};

function CNary(props)
{
    CNary.superclass.constructor.call(this);

	this.Id = g_oIdCounter.Get_NewId();

    this.Pr = new CMathNaryPr();

    this.Base = null;
    this.Sign = null;
    this.LowerIterator = null;
    this.UpperIterator = null;
    this.Arg           = null;

    if(props !== null && props !== undefined)
        this.init(props);

	g_oTableId.Add( this, this.Id );
}
Asc.extendClass(CNary, CMathBase);

CNary.prototype.ClassType = historyitem_type_nary;
CNary.prototype.kind      = MATH_NARY;
  
CNary.prototype.init = function(props)
{
    this.Fill_LogicalContent(3);

    this.setProperties(props);
    this.fillContent();
};
CNary.prototype.fillContent = function()
{
    this.NeedBreakContent(2);
    
    this.LowerIterator = this.Content[0];
    this.UpperIterator = this.Content[1];
    this.Arg           = this.Content[2];
};
CNary.prototype.fillBase = function(PropsInfo)
{
    this.setDimension(1, 2);

    var base;

    var Sign = PropsInfo.sign;
    var ctrPrp = this.CtrPrp.Copy();

    if(PropsInfo.limLoc === NARY_UndOvr)
    {
        if(PropsInfo.supHide && PropsInfo.subHide)
        {
            base = Sign;
        }
        else if( PropsInfo.supHide && !PropsInfo.subHide )
        {
            base = new CNaryOvr(true);
            base.setBase(Sign);
            base.setLowerIterator(this.LowerIterator);
        }
        else if( !PropsInfo.supHide && PropsInfo.subHide )
        {
            base = new CNaryUnd(true);
            base.setBase(Sign);
            base.setUpperIterator(this.UpperIterator);
        }
        else
        {
            base = new CNaryUndOvr(true);
            base.setBase(Sign);
            base.setUpperIterator(this.UpperIterator);
            base.setLowerIterator(this.LowerIterator);
        }
    }
    else
    {
        var prp;

        if( PropsInfo.supHide && !PropsInfo.subHide )
        {
            prp = {type: DEGREE_SUBSCRIPT, ctrPrp:  ctrPrp};
            base = new CDegreeBase(prp, true);
            base.setBase(Sign);
            base.setIterator(this.LowerIterator);
            base.fillContent();
        }
        else if( !PropsInfo.supHide && PropsInfo.subHide )
        {
            prp = {type: DEGREE_SUPERSCRIPT, ctrPrp: ctrPrp};
            base = new CDegreeBase(prp, true);
            base.setBase(Sign);
            base.setIterator(this.UpperIterator);

            base.fillContent();

        }
        else if(PropsInfo.supHide && PropsInfo.subHide)
        {
            base = Sign;
        }
        else
        {
            prp = {type: DEGREE_SubSup, ctrPrp: ctrPrp};
            base = new CDegreeSubSupBase(prp, true);
            base.setBase(Sign);
            base.setLowerIterator(this.LowerIterator);
            base.setUpperIterator(this.UpperIterator);
            
            base.fillContent();
        }
    }

    this.Base = base;

    this.addMCToContent( [base, this.Arg] );

};
CNary.prototype.ApplyProperties = function(RPI)
{
    if(this.RecalcInfo.bProps || RPI.bChangeInline == true)
    {
        var oSign = this.getSign(this.Pr.chr, this.Pr.chrType);
        this.Sign = oSign.operator;

        var limLoc         = this.Pr.limLoc;

        if(RPI.bInline == true || RPI.bDecreasedComp == true)
        {
            limLoc = NARY_SubSup;
            this.Sign = new CMathText(true);
            this.Sign.add(oSign.chrCode);
        }

        if(limLoc === null || limLoc === undefined)
        {
            var bIntegral = oSign.chrCode > 0x222A && oSign.chrCode < 0x2231;

            var oMathSettings = Get_WordDocumentDefaultMathSettings();
            if(bIntegral)
                limLoc = oMathSettings.Get_IntLim();
            else
                limLoc = oMathSettings.Get_NaryLim();
        }

        var PropsInfo =
        {
            limLoc :    limLoc,
            sign:       this.Sign,
            supHide:    this.Pr.supHide,
            subHide:    this.Pr.subHide
        };

        // пока оставим так, chrType сейчас нигде не используется
        this.Pr.chrType = oSign.chrType;

        this.fillBase(PropsInfo);

        this.RecalcInfo.bProps = false;
    }
};
CNary.prototype.PreRecalc = function(Parent, ParaMath, ArgSize, RPI, GapsInfo)
{
    var NewRPI = RPI.Copy();

    if(RPI.bInline || RPI.bDecreasedComp)
        NewRPI.bNaryInline = true;

    CNary.superclass.PreRecalc.call(this, Parent, ParaMath, ArgSize, NewRPI, GapsInfo);
};
CNary.prototype.getSign = function(chrCode, chrType)
{    
    var result = 
    {
        chrCode:   null,
        chrType:   null,
        operator:  null
    };

    var bChr = chrCode !== null && chrCode == chrCode + 0;

    if(chrCode == 0x222B || chrType == NARY_INTEGRAL)
    {
        result.chrCode = 0x222B;
        result.chrType = NARY_INTEGRAL;
        result.operator = new CIntegral();
    }
    else if(chrCode == 0x222C || chrType == NARY_DOUBLE_INTEGRAL)
    {
        result.chrCode = 0x222C;
        result.chrType = NARY_DOUBLE_INTEGRAL;
        result.operator = new CDoubleIntegral();
    }
    else if(chrCode == 0x222D || chrType == NARY_TRIPLE_INTEGRAL)
    {
        result.chrCode = 0x222D;
        result.chrType = NARY_TRIPLE_INTEGRAL;
        result.operator = new CTripleIntegral();
    }
    else if(chrCode == 0x222E || chrType == NARY_CONTOUR_INTEGRAL )
    {
        result.chrCode = 0x222E;
        result.chrType = NARY_CONTOUR_INTEGRAL;
        result.operator = new CContourIntegral();
    }
    else if(chrCode == 0x222F || chrType == NARY_SURFACE_INTEGRAL )
    {
        result.chrCode = 0x222F;
        result.chrType = NARY_SURFACE_INTEGRAL;
        result.operator = new CSurfaceIntegral();
    }
    else if(chrCode == 0x2230 || chrType == NARY_VOLUME_INTEGRAL)
    {
        result.chrCode = 0x2230;
        result.chrType = NARY_VOLUME_INTEGRAL;
        result.operator = new CVolumeIntegral();
    }
    else if(chrCode == 0x2211 || chrType == NARY_SIGMA)
    {
        result.chrCode = 0x2211;
        result.chrType = NARY_SIGMA;
        result.operator = new CSigma();
    }
    else if(chrCode == 0x220F || chrType == NARY_PRODUCT)
    {
        result.chrCode = 0x220F;
        result.chrType = NARY_PRODUCT;
        result.operator = new CProduct();
    }
    else if(chrCode == 0x2210 || chrType == NARY_COPRODUCT)
    {
        result.chrCode = 0x2210;
        result.chrType = NARY_COPRODUCT;
        result.operator = new CProduct(-1);
    }
    else if(chrCode == 0x22C3 || chrType == NARY_UNION)
    {
        result.chrCode = 0x22C3;
        result.chrType = NARY_UNION;
        result.operator = new CUnion();
    }
    else if(chrCode == 0x22C2 || chrType == NARY_INTERSECTION)
    {
        result.chrCode = 0x22C2;
        result.chrType = NARY_INTERSECTION;
        result.operator = new CUnion(-1);
    }
    else if(chrCode == 0x22C1 || chrType == NARY_LOGICAL_OR)
    {
        result.chrCode = 0x22C1;
        result.chrType = NARY_LOGICAL_OR;
        result.operator  = new CLogicalOr();
    }
    else if(chrCode == 0x22C0 || chrType == NARY_LOGICAL_AND)
    {
        result.chrCode = 0x22C0;
        result.chrType = NARY_LOGICAL_AND;
        result.operator  = new CLogicalOr(-1);
    }
    else if(bChr)
    {
        result.chrCode = chrCode;
        result.chrType = NARY_TEXT_OPER;
        result.operator = new CMathText(true);
        result.operator.add(chrCode);

    }
    else
    {
        result.chrCode = 0x222B;
        result.chrType = NARY_INTEGRAL;
        result.operator = new CIntegral();
    }

    return result;
};
CNary.prototype.setCtrPrp = function(txtPrp)
{
    this.CtrPrp.Merge(txtPrp); // only runPrp for paragraph
    //this.RunPrp.setTxtPrp(txtPrp);

    if(this.elements.length > 0 && !this.elements[0][0].IsJustDraw())
    {
        this.elements[0][0].setCtrPrp(this.CtrPrp);
    }
};
CNary.prototype.setDistance = function()
{
    this.dW = this.Get_TxtPrControlLetter().FontSize/36*2.45;
};
CNary.prototype.getBase = function()
{
    return this.Arg;
};
CNary.prototype.getUpperIterator = function()
{
	if (!this.Pr.supHide)
		return this.UpperIterator;
};
CNary.prototype.getLowerIterator = function()
{
	if (!this.Pr.subHide)
		return this.LowerIterator;
};
CNary.prototype.getBaseMathContent = function()
{
    return this.Arg;
};
CNary.prototype.getSupMathContent = function()
{
    return this.UpperIterator;
};
CNary.prototype.getSubMathContent = function()
{
    return this.LowerIterator;
};
CNary.prototype.Document_UpdateInterfaceState = function(MathProps)
{
    MathProps.Type = c_oAscMathInterfaceType.LargeOperator;
    MathProps.Pr   = null;
};
CNary.prototype.Is_ContentUse = function(MathContent)
{
    if (MathContent === this.getBaseMathContent())
        return true;

    if (true !== this.Pr.subHide && MathContent === this.getSubMathContent())
        return true;

    if (true !== this.Pr.supHide && MathContent === this.getSupMathContent())
        return true;

    return false;
};
CNary.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
{
    this.bOneLine = PRS.bMath_OneLine;

    if(this.bOneLine === true)
    {
        CNary.superclass.Recalculate_Range.call(this, PRS, ParaPr, Depth);
    }
    else
    {
        var CurLine  = PRS.Line - this.StartLine;
        var CurRange = ( 0 === CurLine ? PRS.Range - this.StartRange : PRS.Range );

        this.setDistance();

        var RangeStartPos = this.protected_AddRange(CurLine, CurRange),
            RangeEndPos = 2;


        if(CurLine == 0 && CurRange == 0)
        {
            PRS.WordLen += this.BrGapLeft;
            var WordLen = PRS.WordLen;

            if(this.Base.IsJustDraw())
            {
                this.MeasureJustDraw(this.Base);
            }
            else
            {
                PRS.bMath_OneLine = true;
                this.Base.Recalculate_Reset(PRS.Range, PRS.Line, PRS);
                this.LowerIterator.Recalculate_Reset(PRS.Range, PRS.Line, PRS);
                this.UpperIterator.Recalculate_Reset(PRS.Range, PRS.Line, PRS);
                this.Base.Recalculate_Range(PRS, ParaPr, Depth);
            }

            PRS.WordLen = WordLen + this.Base.size.width;

            if(false === PRS.Word && false === PRS.FirstItemOnLine)
            {
                PRS.Word = true;
            }

            PRS.WordLen += this.dW;

            this.Arg.Recalculate_Reset(PRS.Range, PRS.Line, PRS); // обновим StartLine и StartRange
        }

        PRS.Update_CurPos(2, Depth); // this.Arg = this.Content[2]
        PRS.bMath_OneLine  = false;
        this.Arg.Recalculate_Range(PRS, ParaPr, Depth+1);


        if(PRS.NewRange == false)
        {
            PRS.WordLen += this.BrGapRight;
        }

        this.protected_FillRange(CurLine, CurRange, RangeStartPos, RangeEndPos);

        PRS.bMath_OneLine = false;
    }
};
CNary.prototype.Recalculate_Range_Width = function(PRSC, _CurLine, _CurRange)
{
    if(this.bOneLine == true)
    {
        CNary.superclass.Recalculate_Range_Width.call(this, PRSC, _CurLine, _CurRange);
    }
    else
    {
        var CurLine = _CurLine - this.StartLine;
        var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );

        var RangeW = PRSC.Range.W;

        if(CurLine == 0 && CurRange == 0)
        {
            PRSC.Range.W += this.BrGapLeft;
            var RangeW2 = PRSC.Range.W;

            if(this.Base.IsJustDraw() == false)
            {
                this.LowerIterator.Recalculate_Range_Width(PRSC, _CurLine, _CurRange);
                this.UpperIterator.Recalculate_Range_Width(PRSC, _CurLine, _CurRange);

                this.Base.Bounds.SetWidth(CurLine, CurRange, this.Base.size.width);
            }

            PRSC.Range.W = RangeW2 + this.Base.size.width + this.dW;

        }

        this.Arg.Recalculate_Range_Width( PRSC, _CurLine, _CurRange );

        if(this.Arg.Math_Is_End( _CurLine, _CurRange))
        {
            PRSC.Range.W += this.BrGapRight;
        }

        this.Bounds.SetWidth(CurLine, CurRange, PRSC.Range.W - RangeW);
    }
};
CNary.prototype.Draw_Elements = function(PDSE)
{
    var CurLine  = PDSE.Line - this.StartLine;
    var CurRange = ( 0 === CurLine ? PDSE.Range - this.StartRange : PDSE.Range );

    if(CurLine == 0 && CurRange == 0)
    {
        if(this.Base.IsJustDraw()) // для Just-Draw элементов надо выставить Font
        {
            var ctrPrp = this.Get_TxtPrControlLetter();

            var Font =
            {
                FontSize:   ctrPrp.FontSize,
                FontFamily: {Name : ctrPrp.FontFamily.Name, Index : ctrPrp.FontFamily.Index},
                Italic:     false,
                Bold:       false //ctrPrp.Bold
            };

            PDSE.Graphics.SetFont(Font);
        }
        this.Base.Draw_Elements(PDSE);
    }

    this.Arg.Draw_Elements(PDSE);
};
CNary.prototype.UpdateBoundsPosInfo = function(PRSA, _CurLine, _CurRange, _CurPage)
{
    if(this.bOneLine == false)
    {
        var CurLine  = _CurLine - this.StartLine;
        var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange);

        this.Bounds.SetGenPos(CurLine, CurRange, PRSA);
        this.Bounds.SetPage(CurLine, CurRange, _CurPage);

        if(false == this.Base.IsJustDraw())
        {
            this.Base.UpdateBoundsPosInfo(PRSA, _CurLine, _CurRange, _CurPage);
        }

        this.Arg.UpdateBoundsPosInfo(PRSA, _CurLine, _CurRange, _CurPage);

    }
    else
    {
        CNary.superclass.UpdateBoundsPosInfo(this, PRSA, _CurLine, _CurRange, _CurPage);
    }

};
CNary.prototype.Recalculate_LineMetrics = function(PRS, ParaPr, _CurLine, _CurRange, ContentMetrics)
{
    if(this.bOneLine)
    {
        CNary.superclass.Recalculate_LineMetrics.call(this, PRS, ParaPr, _CurLine, _CurRange, ContentMetrics);
    }
    else
    {
        var CurLine = _CurLine - this.StartLine;
        var CurRange = (0 === CurLine ? _CurRange - this.StartRange : _CurRange);

        // т.к. ParaNumbering привязывается к первому текстовому элементы, он может находится в аргументе
        // обновляем LineMetrics для Base после того, как обновим метрики для аргумента

        this.Arg.Recalculate_LineMetrics(PRS, ParaPr, _CurLine, _CurRange, ContentMetrics);

        var BoundArg = this.Arg.Get_LineBound(_CurLine, _CurRange);

        this.Bounds.UpdateMetrics(CurLine, CurRange, BoundArg);

        this.UpdatePRS(PRS, BoundArg);


        if(CurLine == 0 && CurRange == 0)
        {
            this.Bounds.Reset();<commit_msg>к rev 64968 : отсутствовал call <commit_after>"use strict";

//величина символа "сигма" не меняется в зависимости от аргумента
//если не выставлено в настройках
/////////////////////****//////////////////////////

function CMathNaryPr()
{
    this.chr     = undefined;
    this.chrType = NARY_INTEGRAL;
    this.grow    = false;
    this.limLoc  = undefined;
    this.subHide = false;
    this.supHide = false;
}

CMathNaryPr.prototype.Set_FromObject = function(Obj)
{
    this.chr     = Obj.chr;
    this.chrType = Obj.chrType;

    if(true === Obj.grow === true || 1 === Obj.grow)
        this.grow = true;

    if(NARY_UndOvr === Obj.limLoc || NARY_SubSup === Obj.limLoc)
        this.limLoc = Obj.limLoc;

    if(true === Obj.subHide === true || 1 === Obj.subHide)
        this.subHide = true;

    if(true === Obj.supHide === true || 1 === Obj.supHide)
        this.supHide = true;
};

CMathNaryPr.prototype.Copy = function()
{
    var NewPr = new CMathNaryPr();

    NewPr.chr     = this.chr    ;
    NewPr.chrType = this.chrType;
    NewPr.grow    = this.grow   ;
    NewPr.limLoc  = this.limLoc ;
    NewPr.subHide = this.subHide;
    NewPr.supHide = this.supHide;

    return NewPr;
};

CMathNaryPr.prototype.Write_ToBinary = function(Writer)
{
    // Long : flags

    // Long : chr
    // Long : chrType
    // Long : limLoc

    // Bool : grow
    // Bool : subHide
    // Bool : supHide

    var StartPos = Writer.GetCurPosition();
    Writer.Skip(4);
    var Flags = 0;

    if (undefined !== this.chr)
    {
        Writer.WriteLong(this.chr);
        Flags |= 1;
    }

    if (undefined !== this.chrType)
    {
        Writer.WriteLong(this.chrType);
        Flags |= 2;
    }

    if (undefined !== this.limLoc)
    {
        Writer.WriteLong(this.limLoc);
        Flags |= 4;
    }

    var EndPos = Writer.GetCurPosition();
    Writer.Seek(StartPos);
    Writer.WriteLong(Flags);
    Writer.Seek(EndPos);

    Writer.WriteBool(this.grow);
    Writer.WriteBool(this.subHide);
    Writer.WriteBool(this.supHide);
};

CMathNaryPr.prototype.Read_FromBinary = function(Reader)
{
    // Long : flags

    // Long : chr
    // Long : chrType
    // Long : limLoc

    // Bool : grow
    // Bool : subHide
    // Bool : supHide

    var Flags = Reader.GetLong();

    if (Flags & 1)
        this.chr = Reader.GetLong();
    else
        this.chr = undefined;

    if (Flags & 2)
        this.chrType = Reader.GetLong();
    else
        this.chrType = undefined;

    if (Flags & 4)
        this.limLoc = Reader.GetLong();
    else
        this.limLoc = undefined;

    this.grow    = Reader.GetBool();
    this.subHide = Reader.GetBool();
    this.supHide = Reader.GetBool();
};

function CNary(props)
{
    CNary.superclass.constructor.call(this);

	this.Id = g_oIdCounter.Get_NewId();

    this.Pr = new CMathNaryPr();

    this.Base = null;
    this.Sign = null;
    this.LowerIterator = null;
    this.UpperIterator = null;
    this.Arg           = null;

    if(props !== null && props !== undefined)
        this.init(props);

	g_oTableId.Add( this, this.Id );
}
Asc.extendClass(CNary, CMathBase);

CNary.prototype.ClassType = historyitem_type_nary;
CNary.prototype.kind      = MATH_NARY;
  
CNary.prototype.init = function(props)
{
    this.Fill_LogicalContent(3);

    this.setProperties(props);
    this.fillContent();
};
CNary.prototype.fillContent = function()
{
    this.NeedBreakContent(2);
    
    this.LowerIterator = this.Content[0];
    this.UpperIterator = this.Content[1];
    this.Arg           = this.Content[2];
};
CNary.prototype.fillBase = function(PropsInfo)
{
    this.setDimension(1, 2);

    var base;

    var Sign = PropsInfo.sign;
    var ctrPrp = this.CtrPrp.Copy();

    if(PropsInfo.limLoc === NARY_UndOvr)
    {
        if(PropsInfo.supHide && PropsInfo.subHide)
        {
            base = Sign;
        }
        else if( PropsInfo.supHide && !PropsInfo.subHide )
        {
            base = new CNaryOvr(true);
            base.setBase(Sign);
            base.setLowerIterator(this.LowerIterator);
        }
        else if( !PropsInfo.supHide && PropsInfo.subHide )
        {
            base = new CNaryUnd(true);
            base.setBase(Sign);
            base.setUpperIterator(this.UpperIterator);
        }
        else
        {
            base = new CNaryUndOvr(true);
            base.setBase(Sign);
            base.setUpperIterator(this.UpperIterator);
            base.setLowerIterator(this.LowerIterator);
        }
    }
    else
    {
        var prp;

        if( PropsInfo.supHide && !PropsInfo.subHide )
        {
            prp = {type: DEGREE_SUBSCRIPT, ctrPrp:  ctrPrp};
            base = new CDegreeBase(prp, true);
            base.setBase(Sign);
            base.setIterator(this.LowerIterator);
            base.fillContent();
        }
        else if( !PropsInfo.supHide && PropsInfo.subHide )
        {
            prp = {type: DEGREE_SUPERSCRIPT, ctrPrp: ctrPrp};
            base = new CDegreeBase(prp, true);
            base.setBase(Sign);
            base.setIterator(this.UpperIterator);

            base.fillContent();

        }
        else if(PropsInfo.supHide && PropsInfo.subHide)
        {
            base = Sign;
        }
        else
        {
            prp = {type: DEGREE_SubSup, ctrPrp: ctrPrp};
            base = new CDegreeSubSupBase(prp, true);
            base.setBase(Sign);
            base.setLowerIterator(this.LowerIterator);
            base.setUpperIterator(this.UpperIterator);
            
            base.fillContent();
        }
    }

    this.Base = base;

    this.addMCToContent( [base, this.Arg] );

};
CNary.prototype.ApplyProperties = function(RPI)
{
    if(this.RecalcInfo.bProps || RPI.bChangeInline == true)
    {
        var oSign = this.getSign(this.Pr.chr, this.Pr.chrType);
        this.Sign = oSign.operator;

        var limLoc         = this.Pr.limLoc;

        if(RPI.bInline == true || RPI.bDecreasedComp == true)
        {
            limLoc = NARY_SubSup;
            this.Sign = new CMathText(true);
            this.Sign.add(oSign.chrCode);
        }

        if(limLoc === null || limLoc === undefined)
        {
            var bIntegral = oSign.chrCode > 0x222A && oSign.chrCode < 0x2231;

            var oMathSettings = Get_WordDocumentDefaultMathSettings();
            if(bIntegral)
                limLoc = oMathSettings.Get_IntLim();
            else
                limLoc = oMathSettings.Get_NaryLim();
        }

        var PropsInfo =
        {
            limLoc :    limLoc,
            sign:       this.Sign,
            supHide:    this.Pr.supHide,
            subHide:    this.Pr.subHide
        };

        // пока оставим так, chrType сейчас нигде не используется
        this.Pr.chrType = oSign.chrType;

        this.fillBase(PropsInfo);

        this.RecalcInfo.bProps = false;
    }
};
CNary.prototype.PreRecalc = function(Parent, ParaMath, ArgSize, RPI, GapsInfo)
{
    var NewRPI = RPI.Copy();

    if(RPI.bInline || RPI.bDecreasedComp)
        NewRPI.bNaryInline = true;

    CNary.superclass.PreRecalc.call(this, Parent, ParaMath, ArgSize, NewRPI, GapsInfo);
};
CNary.prototype.getSign = function(chrCode, chrType)
{    
    var result = 
    {
        chrCode:   null,
        chrType:   null,
        operator:  null
    };

    var bChr = chrCode !== null && chrCode == chrCode + 0;

    if(chrCode == 0x222B || chrType == NARY_INTEGRAL)
    {
        result.chrCode = 0x222B;
        result.chrType = NARY_INTEGRAL;
        result.operator = new CIntegral();
    }
    else if(chrCode == 0x222C || chrType == NARY_DOUBLE_INTEGRAL)
    {
        result.chrCode = 0x222C;
        result.chrType = NARY_DOUBLE_INTEGRAL;
        result.operator = new CDoubleIntegral();
    }
    else if(chrCode == 0x222D || chrType == NARY_TRIPLE_INTEGRAL)
    {
        result.chrCode = 0x222D;
        result.chrType = NARY_TRIPLE_INTEGRAL;
        result.operator = new CTripleIntegral();
    }
    else if(chrCode == 0x222E || chrType == NARY_CONTOUR_INTEGRAL )
    {
        result.chrCode = 0x222E;
        result.chrType = NARY_CONTOUR_INTEGRAL;
        result.operator = new CContourIntegral();
    }
    else if(chrCode == 0x222F || chrType == NARY_SURFACE_INTEGRAL )
    {
        result.chrCode = 0x222F;
        result.chrType = NARY_SURFACE_INTEGRAL;
        result.operator = new CSurfaceIntegral();
    }
    else if(chrCode == 0x2230 || chrType == NARY_VOLUME_INTEGRAL)
    {
        result.chrCode = 0x2230;
        result.chrType = NARY_VOLUME_INTEGRAL;
        result.operator = new CVolumeIntegral();
    }
    else if(chrCode == 0x2211 || chrType == NARY_SIGMA)
    {
        result.chrCode = 0x2211;
        result.chrType = NARY_SIGMA;
        result.operator = new CSigma();
    }
    else if(chrCode == 0x220F || chrType == NARY_PRODUCT)
    {
        result.chrCode = 0x220F;
        result.chrType = NARY_PRODUCT;
        result.operator = new CProduct();
    }
    else if(chrCode == 0x2210 || chrType == NARY_COPRODUCT)
    {
        result.chrCode = 0x2210;
        result.chrType = NARY_COPRODUCT;
        result.operator = new CProduct(-1);
    }
    else if(chrCode == 0x22C3 || chrType == NARY_UNION)
    {
        result.chrCode = 0x22C3;
        result.chrType = NARY_UNION;
        result.operator = new CUnion();
    }
    else if(chrCode == 0x22C2 || chrType == NARY_INTERSECTION)
    {
        result.chrCode = 0x22C2;
        result.chrType = NARY_INTERSECTION;
        result.operator = new CUnion(-1);
    }
    else if(chrCode == 0x22C1 || chrType == NARY_LOGICAL_OR)
    {
        result.chrCode = 0x22C1;
        result.chrType = NARY_LOGICAL_OR;
        result.operator  = new CLogicalOr();
    }
    else if(chrCode == 0x22C0 || chrType == NARY_LOGICAL_AND)
    {
        result.chrCode = 0x22C0;
        result.chrType = NARY_LOGICAL_AND;
        result.operator  = new CLogicalOr(-1);
    }
    else if(bChr)
    {
        result.chrCode = chrCode;
        result.chrType = NARY_TEXT_OPER;
        result.operator = new CMathText(true);
        result.operator.add(chrCode);

    }
    else
    {
        result.chrCode = 0x222B;
        result.chrType = NARY_INTEGRAL;
        result.operator = new CIntegral();
    }

    return result;
};
CNary.prototype.setCtrPrp = function(txtPrp)
{
    this.CtrPrp.Merge(txtPrp); // only runPrp for paragraph
    //this.RunPrp.setTxtPrp(txtPrp);

    if(this.elements.length > 0 && !this.elements[0][0].IsJustDraw())
    {
        this.elements[0][0].setCtrPrp(this.CtrPrp);
    }
};
CNary.prototype.setDistance = function()
{
    this.dW = this.Get_TxtPrControlLetter().FontSize/36*2.45;
};
CNary.prototype.getBase = function()
{
    return this.Arg;
};
CNary.prototype.getUpperIterator = function()
{
	if (!this.Pr.supHide)
		return this.UpperIterator;
};
CNary.prototype.getLowerIterator = function()
{
	if (!this.Pr.subHide)
		return this.LowerIterator;
};
CNary.prototype.getBaseMathContent = function()
{
    return this.Arg;
};
CNary.prototype.getSupMathContent = function()
{
    return this.UpperIterator;
};
CNary.prototype.getSubMathContent = function()
{
    return this.LowerIterator;
};
CNary.prototype.Document_UpdateInterfaceState = function(MathProps)
{
    MathProps.Type = c_oAscMathInterfaceType.LargeOperator;
    MathProps.Pr   = null;
};
CNary.prototype.Is_ContentUse = function(MathContent)
{
    if (MathContent === this.getBaseMathContent())
        return true;

    if (true !== this.Pr.subHide && MathContent === this.getSubMathContent())
        return true;

    if (true !== this.Pr.supHide && MathContent === this.getSupMathContent())
        return true;

    return false;
};
CNary.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
{
    this.bOneLine = PRS.bMath_OneLine;

    if(this.bOneLine === true)
    {
        CNary.superclass.Recalculate_Range.call(this, PRS, ParaPr, Depth);
    }
    else
    {
        var CurLine  = PRS.Line - this.StartLine;
        var CurRange = ( 0 === CurLine ? PRS.Range - this.StartRange : PRS.Range );

        this.setDistance();

        var RangeStartPos = this.protected_AddRange(CurLine, CurRange),
            RangeEndPos = 2;


        if(CurLine == 0 && CurRange == 0)
        {
            PRS.WordLen += this.BrGapLeft;
            var WordLen = PRS.WordLen;

            if(this.Base.IsJustDraw())
            {
                this.MeasureJustDraw(this.Base);
            }
            else
            {
                PRS.bMath_OneLine = true;
                this.Base.Recalculate_Reset(PRS.Range, PRS.Line, PRS);
                this.LowerIterator.Recalculate_Reset(PRS.Range, PRS.Line, PRS);
                this.UpperIterator.Recalculate_Reset(PRS.Range, PRS.Line, PRS);
                this.Base.Recalculate_Range(PRS, ParaPr, Depth);
            }

            PRS.WordLen = WordLen + this.Base.size.width;

            if(false === PRS.Word && false === PRS.FirstItemOnLine)
            {
                PRS.Word = true;
            }

            PRS.WordLen += this.dW;

            this.Arg.Recalculate_Reset(PRS.Range, PRS.Line, PRS); // обновим StartLine и StartRange
        }

        PRS.Update_CurPos(2, Depth); // this.Arg = this.Content[2]
        PRS.bMath_OneLine  = false;
        this.Arg.Recalculate_Range(PRS, ParaPr, Depth+1);


        if(PRS.NewRange == false)
        {
            PRS.WordLen += this.BrGapRight;
        }

        this.protected_FillRange(CurLine, CurRange, RangeStartPos, RangeEndPos);

        PRS.bMath_OneLine = false;
    }
};
CNary.prototype.Recalculate_Range_Width = function(PRSC, _CurLine, _CurRange)
{
    if(this.bOneLine == true)
    {
        CNary.superclass.Recalculate_Range_Width.call(this, PRSC, _CurLine, _CurRange);
    }
    else
    {
        var CurLine = _CurLine - this.StartLine;
        var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );

        var RangeW = PRSC.Range.W;

        if(CurLine == 0 && CurRange == 0)
        {
            PRSC.Range.W += this.BrGapLeft;
            var RangeW2 = PRSC.Range.W;

            if(this.Base.IsJustDraw() == false)
            {
                this.LowerIterator.Recalculate_Range_Width(PRSC, _CurLine, _CurRange);
                this.UpperIterator.Recalculate_Range_Width(PRSC, _CurLine, _CurRange);

                this.Base.Bounds.SetWidth(CurLine, CurRange, this.Base.size.width);
            }

            PRSC.Range.W = RangeW2 + this.Base.size.width + this.dW;

        }

        this.Arg.Recalculate_Range_Width( PRSC, _CurLine, _CurRange );

        if(this.Arg.Math_Is_End( _CurLine, _CurRange))
        {
            PRSC.Range.W += this.BrGapRight;
        }

        this.Bounds.SetWidth(CurLine, CurRange, PRSC.Range.W - RangeW);
    }
};
CNary.prototype.Draw_Elements = function(PDSE)
{
    var CurLine  = PDSE.Line - this.StartLine;
    var CurRange = ( 0 === CurLine ? PDSE.Range - this.StartRange : PDSE.Range );

    if(CurLine == 0 && CurRange == 0)
    {
        if(this.Base.IsJustDraw()) // для Just-Draw элементов надо выставить Font
        {
            var ctrPrp = this.Get_TxtPrControlLetter();

            var Font =
            {
                FontSize:   ctrPrp.FontSize,
                FontFamily: {Name : ctrPrp.FontFamily.Name, Index : ctrPrp.FontFamily.Index},
                Italic:     false,
                Bold:       false //ctrPrp.Bold
            };

            PDSE.Graphics.SetFont(Font);
        }
        this.Base.Draw_Elements(PDSE);
    }

    this.Arg.Draw_Elements(PDSE);
};
CNary.prototype.UpdateBoundsPosInfo = function(PRSA, _CurLine, _CurRange, _CurPage)
{
    if(this.bOneLine == false)
    {
        var CurLine  = _CurLine - this.StartLine;
        var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange);

        this.Bounds.SetGenPos(CurLine, CurRange, PRSA);
        this.Bounds.SetPage(CurLine, CurRange, _CurPage);

        if(false == this.Base.IsJustDraw())
        {
            this.Base.UpdateBoundsPosInfo(PRSA, _CurLine, _CurRange, _CurPage);
        }

        this.Arg.UpdateBoundsPosInfo(PRSA, _CurLine, _CurRange, _CurPage);

    }
    else
    {
        CNary.superclass.UpdateBoundsPosInfo.call(this, PRSA, _CurLine, _CurRange, _CurPage);
    }

};
CNary.prototype.Recalculate_LineMetrics = function(PRS, ParaPr, _CurLine, _CurRange, ContentMetrics)
{
    if(this.bOneLine)
    {
        CNary.superclass.Recalculate_LineMetrics.call(this, PRS, ParaPr, _CurLine, _CurRange, ContentMetrics);
    }
    else
    {
        var CurLine = _CurLine - this.StartLine;
        var CurRange = (0 === CurLine ? _CurRange - this.StartRange : _CurRange);

        // т.к. ParaNumbering привязывается к первому текстовому элементы, он может находится в аргументе
        // обновляем LineMetrics для Base после того, как обновим метрики для аргумента

        this.Arg.Recalculate_LineMetrics(PRS, ParaPr, _CurLine, _CurRange, ContentMetrics);

        var BoundArg = this.Arg.Get_LineBound(_CurLine, _CurRange);

        this.Bounds.UpdateMetrics(CurLine, CurRange, BoundArg);

        this.UpdatePRS(PRS, BoundArg);


        if(CurLine == 0 && CurRange == 0)
        {
            this.Bounds.Reset();
{'fraction_non_alphanumeric': 0.1223373297637062, 'fraction_numerical': 0.010272378070073333, 'mean_word_length': 2.1122079333454082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5676898', 'n_tokens_mistral': 11975, 'n_tokens_neox': 11562, 'n_words': 1978}