From aaebb31ffb5ecf94ce3167d55738c19332eb46e6 Mon Sep 17 00:00:00 2001
From: "Ilya.Kirillov" <Ilya.Kirillov@OnlyOffice.com>
Date: Fri, 26 Sep 2014 11:57:59 +0000
Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D1=80=D0=B0=D1=81?=
 =?UTF-8?q?=D1=81=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20=D0=B2=D1=8B=D1=81=D0=BE?=
 =?UTF-8?q?=D1=82=D1=8B=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D1=81=20?=
 =?UTF-8?q?=D0=B8=D0=BD=D0=BB=D0=B0=D0=B9=D0=BD-=D0=B0=D0=B2=D1=82=D0=BE?=
 =?UTF-8?q?=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=BE=D0=B9(=D0=B1=D0=B0=D0=B3?=
 =?UTF-8?q?=2026687).=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D0=BE=D0=BF=D1=80=D0=B5?=
 =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BA=D0=BE?=
 =?UTF-8?q?=D0=B3=D0=B4=D0=B0=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D1=80=D0=B8?=
 =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B8=D0=B6=D0=BD?=
 =?UTF-8?q?=D1=8E=D1=8E=20=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=83=20?=
 =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=B3=D1=80=D0=B0=D1=84=D0=B0=20(?=
 =?UTF-8?q?=D0=B1=D0=B0=D0=B3=2026695).=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?=
 =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D0=B1?=
 =?UTF-8?q?=D1=8B=D1=81=D1=82=D1=80=D1=8B=D0=BC=20=D1=80=D0=B0=D1=81=D1=81?=
 =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20=D1=82=D0=B5=D0=BA=D1=81=D1=82?=
 =?UTF-8?q?=D0=B0=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD?=
 =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20PageBreak?=
 =?UTF-8?q?.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58510 954022d7-b5bf-4e40-9824-e11837661b57
---
 Word/Editor/Paragraph.js             | 14 ++--
 Word/Editor/Paragraph_Recalculate.js | 96 ++++++++++++----------------
 2 files changed, 47 insertions(+), 63 deletions(-)

diff --git a/Word/Editor/Paragraph.js b/Word/Editor/Paragraph.js
index df668c14c..57cd38afd 100644
--- a/Word/Editor/Paragraph.js
+++ b/Word/Editor/Paragraph.js
@@ -2130,7 +2130,7 @@ Paragraph.prototype =
         }
 
         var CurLine = this.Pages[CurPage].EndLine;
-        var bEnd = ( this.Content.length - 2 <= this.Lines[CurLine].EndPos ? true : false );
+        var bEnd    = (this.Lines[CurLine].Info & paralineinfo_End ? true : false);
 
         // Рисуем линию после параграфа
         if ( true === bEnd && true === Pr.ParaPr.Brd.Last && border_Single === Pr.ParaPr.Brd.Bottom.Value )
@@ -5710,12 +5710,12 @@ Paragraph.prototype =
                 var _StartLine = this.Pages[CurPage].StartLine;
                 var _EndLine   = this.Pages[CurPage].EndLine;
 
-                if ( StartPos > this.Lines[_EndLine].EndPos || EndPos < this.Lines[_StartLine].StartPos )
+                if ( StartPos > this.Lines[_EndLine].Get_EndPos() || EndPos < this.Lines[_StartLine].Get_StartPos() )
                     return;
                 else
                 {
-                    StartPos = Math.max( StartPos, this.Lines[_StartLine].StartPos );
-                    EndPos   = Math.min( EndPos,   ( _EndLine != this.Lines.length - 1 ? this.Lines[_EndLine].EndPos : this.Content.length - 1 ) );
+                    StartPos = Math.max( StartPos, this.Lines[_StartLine].Get_StartPos() );
+                    EndPos   = Math.min( EndPos,   ( _EndLine != this.Lines.length - 1 ? this.Lines[_EndLine].Get_EndPos() : this.Content.length - 1 ) );
                 }
 
                 var DrawSelection = new CParagraphDrawSelectionRange();
@@ -6022,10 +6022,10 @@ Paragraph.prototype =
             
             for (var CurLine = 0; CurLine < LinesCount; CurLine++ )
             {
-                if ( -1 === StartLine && StartPos >= this.Lines[CurLine].StartPos && StartPos <= this.Lines[CurLine].EndPos )
+                if ( -1 === StartLine && StartPos >= this.Lines[CurLine].Get_StartPos() && StartPos <= this.Lines[CurLine].Get_EndPos() )
                     StartLine = CurLine;
                 
-                if ( EndPos >= this.Lines[CurLine].StartPos && EndPos <= this.Lines[CurLine].EndPos )
+                if ( EndPos >= this.Lines[CurLine].Get_StartPos() && EndPos <= this.Lines[CurLine].Get_EndPos() )
                     EndLine = CurLine;
             }
 
@@ -10097,7 +10097,7 @@ Paragraph.prototype =
             {
                 for ( CurPage = this.Pages.length - 1; CurPage > 0; CurPage-- )
                 {
-                    if ( Data.Pos > this.Lines[this.Pages[CurPage].StartLine].StartPos )
+                    if ( Data.Pos > this.Lines[this.Pages[CurPage].StartLine].Get_StartPos() )
                         break;
                 }
 
diff --git a/Word/Editor/Paragraph_Recalculate.js b/Word/Editor/Paragraph_Recalculate.js
index f040c9128..ba303e026 100644
--- a/Word/Editor/Paragraph_Recalculate.js
+++ b/Word/Editor/Paragraph_Recalculate.js
@@ -727,14 +727,14 @@ Paragraph.prototype.private_RecalculateLine            = function(CurLine, CurPa
         return;
 
     //-------------------------------------------------------------------------------------------------------------
-    // 10. Пересчитываем сдвиги элементов внутри параграфа и видимые ширины пробелов, в зависимости от align.
+    // 10. Выставляем вертикальное смещение данной строки
     //-------------------------------------------------------------------------------------------------------------
-    this.private_RecalculateLineAlign(CurLine, CurPage, PRS, ParaPr, false);
+    this.private_RecalculateLineBaseLine(CurLine, CurPage, PRS, ParaPr);
 
     //-------------------------------------------------------------------------------------------------------------
-    // 11. Выставляем вертикальное смещение данной строки
+    // 11. Пересчитываем сдвиги элементов внутри параграфа и видимые ширины пробелов, в зависимости от align.
     //-------------------------------------------------------------------------------------------------------------
-    if (false === this.private_RecalculateLineBaseLine(CurLine, CurPage, PRS, ParaPr))
+    if (recalcresult_NextElement !== this.private_RecalculateLineAlign(CurLine, CurPage, PRS, ParaPr, false))
         return;
 
     //-------------------------------------------------------------------------------------------------------------
@@ -838,7 +838,7 @@ Paragraph.prototype.private_RecalculateLineRanges      = function(CurLine, CurPa
 
 Paragraph.prototype.private_RecalculateLineInfo        = function(CurLine, CurPage, PRS, ParaPr)
 {
-    if ( true === PRS.BreakPageLine )
+    if ( true === PRS.BreakPageLine || true === PRS.SkipPageBreak )
         this.Lines[CurLine].Info |= paralineinfo_BreakPage;
 
     if ( true === PRS.EmptyLine )
@@ -1162,6 +1162,31 @@ Paragraph.prototype.private_RecalculateLineCheckRanges = function(CurLine, CurPa
 };
 
 Paragraph.prototype.private_RecalculateLineBaseLine    = function(CurLine, CurPage, PRS, ParaPr)
+{
+    if (this.Lines[CurLine].Info & paralineinfo_RangeY)
+    {
+        this.Lines[CurLine].Y = PRS.Y - this.Pages[CurPage].Y;
+    }
+    else
+    {
+        if ( CurLine > 0 )
+        {
+            // Первая линия на странице не должна двигаться
+            if ( CurLine != this.Pages[CurPage].FirstLine && ( true === PRS.End || true !== PRS.EmptyLine || PRS.RangesCount <= 0 || true === PRS.NewPage  ) )
+                PRS.Y += this.Lines[CurLine - 1].Metrics.Descent + this.Lines[CurLine - 1].Metrics.LineGap +  this.Lines[CurLine].Metrics.Ascent;
+
+            this.Lines[CurLine].Y = PRS.Y - this.Pages[CurPage].Y;
+        }
+        else
+            this.Lines[0].Y = 0;
+    }
+
+    this.Lines[CurLine].Y += PRS.BaseLineOffset;
+    if (this.Lines[CurLine].Metrics.LineGap < 0)
+        this.Lines[CurLine].Y += this.Lines[CurLine].Metrics.LineGap;
+};
+
+Paragraph.prototype.private_RecalculateLineEnd         = function(CurLine, CurPage, PRS, ParaPr)
 {
     if ( true === PRS.NewPage )
     {
@@ -1182,62 +1207,11 @@ Paragraph.prototype.private_RecalculateLineBaseLine    = function(CurLine, CurPa
             return false;
         }
 
-        if (this.Lines[CurLine].Info & paralineinfo_RangeY)
-        {
-            this.Lines[CurLine].Y = PRS.Y - this.Pages[CurPage].Y;
-        }
-        else
-        {
-            if ( CurLine > 0 )
-            {
-                // Первая линия на странице не должна двигаться
-                if ( CurLine != this.Pages[CurPage].FirstLine )
-                    PRS.Y += this.Lines[CurLine - 1].Metrics.Descent + this.Lines[CurLine - 1].Metrics.LineGap +  this.Lines[CurLine].Metrics.Ascent;
-
-                this.Lines[CurLine].Y = PRS.Y - this.Pages[CurPage].Y;
-            }
-            else
-                this.Lines[0].Y = 0;
-        }
-
-        this.Lines[CurLine].Y += PRS.BaseLineOffset;
-        if (this.Lines[CurLine].Metrics.LineGap < 0)
-            this.Lines[CurLine].Y += this.Lines[CurLine].Metrics.LineGap;
-
         this.Pages[CurPage].Set_EndLine( CurLine );
         PRS.RecalcResult = recalcresult_NextPage;
         return false;
     }
-    else
-    {
-        if (this.Lines[CurLine].Info & paralineinfo_RangeY)
-        {
-            this.Lines[CurLine].Y = PRS.Y - this.Pages[CurPage].Y;
-        }
-        else
-        {
-            if ( CurLine > 0 )
-            {
-                // Первая линия на странице не должна двигаться
-                if ( CurLine != this.Pages[CurPage].FirstLine && ( true === PRS.End || true !== PRS.EmptyLine || PRS.RangesCount <= 0 ) )
-                    PRS.Y += this.Lines[CurLine - 1].Metrics.Descent + this.Lines[CurLine - 1].Metrics.LineGap +  this.Lines[CurLine].Metrics.Ascent;
 
-                this.Lines[CurLine].Y = PRS.Y - this.Pages[CurPage].Y;
-            }
-            else
-                this.Lines[0].Y = 0;
-        }
-
-        this.Lines[CurLine].Y += PRS.BaseLineOffset;
-        if (this.Lines[CurLine].Metrics.LineGap < 0)
-            this.Lines[CurLine].Y += this.Lines[CurLine].Metrics.LineGap;
-
-        return true;
-    }
-};
-
-Paragraph.prototype.private_RecalculateLineEnd         = function(CurLine, CurPage, PRS, ParaPr)
-{
     // Такое случается, когда у нас после пересчета Flow картинки, место к которому она была привязана перешло на
     // следующую страницу.
     if (recalcresult_NextPage === PRS.RecalcResult)
@@ -1666,6 +1640,16 @@ CParaLine.prototype =
         }
     },
 
+    Get_StartPos : function()
+    {
+        return this.Ranges[0].StartPos;
+    },
+
+    Get_EndPos : function()
+    {
+        return this.Ranges[this.Ranges.length - 1].EndPos;
+    },
+
     Set_RangeStartPos : function(CurRange, StartPos)
     {
         this.Ranges[CurRange].StartPos = StartPos;
-- 
2.30.9