Commit bc78351b authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Улучшен алгоритм для автоподбора ширины таблицы по содержимому(теперь...

Улучшен алгоритм для автоподбора ширины таблицы по содержимому(теперь учитываются максимальная длина содержимого ячеек и ширины ячеек, записанные в свойствах).

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47762 954022d7-b5bf-4e40-9824-e11837661b57
parent 09d3d308
......@@ -162,7 +162,7 @@ CDocumentContent.prototype =
Get_PageFields : function(PageIndex)
{
if ( true === this.Parent.Is_Cell() )
if ( true === this.Parent.Is_Cell() || this.Parent instanceof WordShape )
{
var Y = this.Pages[PageIndex].Y ;
var YLimit = this.Pages[PageIndex].YLimit;
......@@ -757,19 +757,24 @@ CDocumentContent.prototype =
return Result;
},
Recalculate_MinContentWidth : function()
Recalculate_MinMaxContentWidth : function()
{
var Min = 0;
var Max = 0;
var Count = this.Content.length;
for ( var Pos = 0; Pos < Count; Pos++ )
{
var Element = this.Content[Pos];
var CurMin = Element.Recalculate_MinContentWidth();
if ( Min < CurMin )
Min = CurMin;
var CurMinMax = Element.Recalculate_MinMaxContentWidth();
if ( Min < CurMinMax.Min )
Min = CurMinMax.Min;
if ( Max < CurMinMax.Max )
Max = CurMinMax.Max;
}
return Min;
return { Min : Min, Max : Max };
},
ReDraw : function(StartPage, EndPage)
......
......@@ -3390,14 +3390,18 @@ Paragraph.prototype =
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, true, false );
},
Recalculate_MinContentWidth : function()
Recalculate_MinMaxContentWidth : function()
{
// Пересчитаем ширины всех элементов
this.Internal_Recalculate_0();
var bWord = false;
var nWordLen = 0;
var nSpaceLen = 0;
var nMinWidth = 0;
var nMaxWidth = 0;
var nCurMaxWidth = 0;
var Count = this.Content.length;
for ( var Pos = 0; Pos < Count; Pos++ )
......@@ -3427,6 +3431,14 @@ Paragraph.prototype =
}
}
if ( nSpaceLen > 0 )
{
nCurMaxWidth += nSpaceLen;
nSpaceLen = 0;
}
nCurMaxWidth += Item.Width;
break;
}
......@@ -3441,6 +3453,11 @@ Paragraph.prototype =
nWordLen = 0;
}
// Мы сразу не добавляем ширину пробелов к максимальной ширине, потому что
// пробелы, идущие в конце параграфа или перед переносом строки(явным), не
// должны учитываться.
nSpaceLen += Item.Width;
break;
}
......@@ -3458,6 +3475,14 @@ Paragraph.prototype =
if ( ( true === Item.Is_Inline() || true === this.Parent.Is_DrawingShape() ) && Item.Width > nMinWidth )
nMinWidth = Item.Width;
if ( nSpaceLen > 0 )
{
nCurMaxWidth += nSpaceLen;
nSpaceLen = 0;
}
nCurMaxWidth += Item.Width;
break;
}
......@@ -3475,6 +3500,14 @@ Paragraph.prototype =
if ( Item.Width > nMinWidth )
nMinWidth = Item.Width;
if ( nSpaceLen > 0 )
{
nCurMaxWidth += nSpaceLen;
nSpaceLen = 0;
}
nCurMaxWidth += Item.Width;
break;
}
......@@ -3488,6 +3521,14 @@ Paragraph.prototype =
bWord = false;
nWordLen = 0;
if ( nSpaceLen > 0 )
{
nCurMaxWidth += nSpaceLen;
nSpaceLen = 0;
}
nCurMaxWidth += Item.Width;
break;
}
......@@ -3496,6 +3537,16 @@ Paragraph.prototype =
if ( nMinWidth < nWordLen )
nMinWidth = nWordLen;
bWord = false;
nWordLen = 0;
nSpaceLen = 0;
if ( nCurMaxWidth > nMaxWidth )
nMaxWidth = nCurMaxWidth;
nCurMaxWidth = 0;
break;
}
......@@ -3504,13 +3555,16 @@ Paragraph.prototype =
if ( nMinWidth < nWordLen )
nMinWidth = nWordLen;
if ( nCurMaxWidth > nMaxWidth )
nMaxWidth = nCurMaxWidth;
break;
}
}
}
// добавляем 0.001, чтобы избавиться от погрешностей
return ( nMinWidth > 0 ? nMinWidth + 0.001 : 0 );
return { Min : ( nMinWidth > 0 ? nMinWidth + 0.001 : 0 ), Max : ( nMaxWidth > 0 ? nMaxWidth + 0.001 : 0 ) };
},
Draw : function(PageNum, pGraphics)
......
This diff is collapsed.
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