Commit 251415e0 authored by Ilya Kirillov's avatar Ilya Kirillov

В билдер добавлен класс ApiTablePr для поддержки настроек таблицы. Класс...

В билдер добавлен класс ApiTablePr для поддержки настроек таблицы. Класс ApiTable снаследован от класса ApiTablePr.
parent 2a807040
...@@ -119,6 +119,7 @@ function CTable(DrawingDocument, Parent, Inline, PageNum, X, Y, XLimit, YLimit, ...@@ -119,6 +119,7 @@ function CTable(DrawingDocument, Parent, Inline, PageNum, X, Y, XLimit, YLimit,
this.TableGridNeedRecalc = true; this.TableGridNeedRecalc = true;
this.bPresentation = bPresentation === true; this.bPresentation = bPresentation === true;
// TODO: TableLook и TableStyle нужно перемесить в TablePr
this.TableStyle = (undefined !== this.DrawingDocument && null !== this.DrawingDocument && this.DrawingDocument.m_oLogicDocument && this.DrawingDocument.m_oLogicDocument.Styles ? this.DrawingDocument.m_oLogicDocument.Styles.Get_Default_TableGrid() : null); this.TableStyle = (undefined !== this.DrawingDocument && null !== this.DrawingDocument && this.DrawingDocument.m_oLogicDocument && this.DrawingDocument.m_oLogicDocument.Styles ? this.DrawingDocument.m_oLogicDocument.Styles.Get_Default_TableGrid() : null);
this.TableLook = new CTableLook(true, true, false, false, true, false); this.TableLook = new CTableLook(true, true, false, false, true, false);
...@@ -9139,6 +9140,7 @@ CTable.prototype = ...@@ -9139,6 +9140,7 @@ CTable.prototype =
{ {
History.Add( this, { Type : historyitem_Table_Pr, Old : this.Pr, New : TablePr } ); History.Add( this, { Type : historyitem_Table_Pr, Old : this.Pr, New : TablePr } );
this.Pr = TablePr; this.Pr = TablePr;
this.Recalc_CompiledPr2();
}, },
Set_TableStyle : function(StyleId, bNoClearFormatting) Set_TableStyle : function(StyleId, bNoClearFormatting)
...@@ -9154,7 +9156,7 @@ CTable.prototype = ...@@ -9154,7 +9156,7 @@ CTable.prototype =
{ {
this.Clear_DirectFormatting(false); this.Clear_DirectFormatting(false);
} }
this.Recalc_CompiledPr(); this.Recalc_CompiledPr2();
}, },
Set_TableStyle2 : function(StyleId) Set_TableStyle2 : function(StyleId)
...@@ -9177,7 +9179,7 @@ CTable.prototype = ...@@ -9177,7 +9179,7 @@ CTable.prototype =
{ {
History.Add( this, { Type : historyitem_Table_TableLook, Old : this.TableLook, New : TableLook } ); History.Add( this, { Type : historyitem_Table_TableLook, Old : this.TableLook, New : TableLook } );
this.TableLook = TableLook; this.TableLook = TableLook;
this.Recalc_CompiledPr(); this.Recalc_CompiledPr2();
}, },
Get_TableLook : function() Get_TableLook : function()
...@@ -9313,14 +9315,14 @@ CTable.prototype = ...@@ -9313,14 +9315,14 @@ CTable.prototype =
} }
else if ( undefined === this.Pr.TableW ) else if ( undefined === this.Pr.TableW )
{ {
var TableW = new CTableMeasurement(Type, W) var TableW = new CTableMeasurement(Type, W);
History.Add( this, { Type : historyitem_Table_TableW, Old : undefined, New : TableW } ); History.Add( this, { Type : historyitem_Table_TableW, Old : undefined, New : TableW } );
this.Pr.TableW = TableW; this.Pr.TableW = TableW;
this.Recalc_CompiledPr(); this.Recalc_CompiledPr();
} }
else if ( Type != this.Pr.TableW.Type || Math.abs( this.Pr.TableW.W - W ) > 0.001 ) else if ( Type != this.Pr.TableW.Type || Math.abs( this.Pr.TableW.W - W ) > 0.001 )
{ {
var TableW = new CTableMeasurement(Type, W) var TableW = new CTableMeasurement(Type, W);
History.Add( this, { Type : historyitem_Table_TableW, Old : this.Pr.TableW, New : TableW } ); History.Add( this, { Type : historyitem_Table_TableW, Old : this.Pr.TableW, New : TableW } );
this.Pr.TableW = TableW; this.Pr.TableW = TableW;
this.Recalc_CompiledPr(); this.Recalc_CompiledPr();
......
...@@ -68,16 +68,29 @@ ...@@ -68,16 +68,29 @@
ApiParagraph.superclass.constructor.call(this, this, Paragraph.Pr.Copy()); ApiParagraph.superclass.constructor.call(this, this, Paragraph.Pr.Copy());
this.Paragraph = Paragraph; this.Paragraph = Paragraph;
} }
AscCommon.extendClass(ApiParagraph, ApiParaPr); AscCommon.extendClass(ApiParagraph, ApiParaPr);
/**
* Class representing a table properties.
* @constructor
*/
function ApiTablePr(Parent, TablePr)
{
this.Parent = Parent;
this.TablePr = TablePr;
}
/** /**
* Class representing a table. * Class representing a table.
* @constructor * @constructor
*/ */
function ApiTable(Table) function ApiTable(Table)
{ {
ApiTable.superclass.constructor.call(this, this, Table.Pr.Copy());
this.Table = Table; this.Table = Table;
} }
AscCommon.extendClass(ApiTable, ApiTablePr);
/** /**
* Class representing a text properties. * Class representing a text properties.
...@@ -99,6 +112,7 @@ ...@@ -99,6 +112,7 @@
ApiRun.superclass.constructor.call(this, this, Run.Pr.Copy()); ApiRun.superclass.constructor.call(this, this, Run.Pr.Copy());
this.Run = Run; this.Run = Run;
} }
AscCommon.extendClass(ApiRun, ApiTextPr); AscCommon.extendClass(ApiRun, ApiTextPr);
/** /**
...@@ -214,6 +228,11 @@ ...@@ -214,6 +228,11 @@
* @typedef {("default" | "title" | "even")} HdrFtrType * @typedef {("default" | "title" | "even")} HdrFtrType
*/ */
/**
* The possible values for the units of the width property being defined by a specific table width property.
* @typedef {("auto" | "twips" | "nul" | "percent")} TableWidth
*/
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
// //
// Base Api // Base Api
...@@ -261,10 +280,10 @@ ...@@ -261,10 +280,10 @@
// //
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
/** /**
* Create new history point * Create new history point
*/ */
ApiDocument.prototype.Create_NewHistoryPoint = function() ApiDocument.prototype.Create_NewHistoryPoint = function()
{ {
this.Document.Create_NewHistoryPoint(); this.Document.Create_NewHistoryPoint();
}; };
...@@ -336,7 +355,7 @@ ...@@ -336,7 +355,7 @@
*/ */
ApiDocument.prototype.GetStyle = function(sStyleName) ApiDocument.prototype.GetStyle = function(sStyleName)
{ {
var oStyles = this.Document.Get_Styles(); var oStyles = this.Document.Get_Styles();
var oStyleId = oStyles.Get_StyleIdByName(sStyleName); var oStyleId = oStyles.Get_StyleIdByName(sStyleName);
return new ApiStyle(oStyles.Get(oStyleId)); return new ApiStyle(oStyles.Get(oStyleId));
}; };
...@@ -359,10 +378,10 @@ ...@@ -359,10 +378,10 @@
else if ("numbering" === sType) else if ("numbering" === sType)
nStyleType = styletype_Numbering; nStyleType = styletype_Numbering;
var oStyle = new CStyle(sStyleName, null, null, nStyleType, (styletype_Table !== nStyleType? false : true)); var oStyle = new CStyle(sStyleName, null, null, nStyleType, (styletype_Table !== nStyleType ? false : true));
oStyle.qFormat = true; oStyle.qFormat = true;
oStyle.uiPriority = 1; oStyle.uiPriority = 1;
var oStyles = this.Document.Get_Styles(); var oStyles = this.Document.Get_Styles();
// Если у нас есть стиль с данным именем, тогда мы старый стиль удаляем, а новый добавляем со старым Id, // Если у нас есть стиль с данным именем, тогда мы старый стиль удаляем, а новый добавляем со старым Id,
// чтобы если были ссылки на старый стиль - теперь они стали на новый. // чтобы если были ссылки на старый стиль - теперь они стали на новый.
...@@ -454,8 +473,8 @@ ...@@ -454,8 +473,8 @@
ApiDocument.prototype.CreateNumbering = function(sType) ApiDocument.prototype.CreateNumbering = function(sType)
{ {
var oGlobalNumbering = this.Document.Get_Numbering(); var oGlobalNumbering = this.Document.Get_Numbering();
var oNumberingId = oGlobalNumbering.Create_AbstractNum(); var oNumberingId = oGlobalNumbering.Create_AbstractNum();
var oNumbering = oGlobalNumbering.Get_AbstractNum(oNumberingId); var oNumbering = oGlobalNumbering.Get_AbstractNum(oNumberingId);
if ("numbered" === sType) if ("numbered" === sType)
oNumbering.Create_Default_Numbered(); oNumbering.Create_Default_Numbered();
...@@ -554,9 +573,9 @@ ...@@ -554,9 +573,9 @@
if (!oNumPr) if (!oNumPr)
return null; return null;
var oLogicDocument = private_GetLogicDocument(); var oLogicDocument = private_GetLogicDocument();
var oGlobalNumbering = oLogicDocument.Get_Numbering(); var oGlobalNumbering = oLogicDocument.Get_Numbering();
var oNumbering = oGlobalNumbering.Get_AbstractNum(oNumPr.NumId); var oNumbering = oGlobalNumbering.Get_AbstractNum(oNumPr.NumId);
if (!oNumbering) if (!oNumbering)
return null; return null;
...@@ -644,13 +663,13 @@ ...@@ -644,13 +663,13 @@
ApiSection.prototype.SetNotEqualColumns = function(aWidths, aSpaces) ApiSection.prototype.SetNotEqualColumns = function(aWidths, aSpaces)
{ {
if (!aWidths || !aWidths.length || aWidths.length <= 1 || aSpaces.length !== aWidths.length - 1) if (!aWidths || !aWidths.length || aWidths.length <= 1 || aSpaces.length !== aWidths.length - 1)
return false; return;
this.Section.Set_Columns_EqualWidth(false); this.Section.Set_Columns_EqualWidth(false);
var aCols = []; var aCols = [];
for (var nPos = 0, nCount = aWidths.length; nPos < nCount; ++nPos) for (var nPos = 0, nCount = aWidths.length; nPos < nCount; ++nPos)
{ {
var SectionColumn = new CSectionColumn(); var SectionColumn = new CSectionColumn();
SectionColumn.W = private_Twips2MM(aWidths[nPos]); SectionColumn.W = private_Twips2MM(aWidths[nPos]);
SectionColumn.Space = private_Twips2MM(nPos !== nCount - 1 ? aSpaces[nPos] : 0); SectionColumn.Space = private_Twips2MM(nPos !== nCount - 1 ? aSpaces[nPos] : 0);
aCols.push(SectionColumn); aCols.push(SectionColumn);
...@@ -719,7 +738,7 @@ ...@@ -719,7 +738,7 @@
if (null === oHeader && true === isCreate) if (null === oHeader && true === isCreate)
{ {
var oLogicDocument = private_GetLogicDocument(); var oLogicDocument = private_GetLogicDocument();
oHeader = new CHeaderFooter(oLogicDocument.Get_HdrFtr(), oLogicDocument, oLogicDocument.Get_DrawingDocument(), hdrftr_Header); oHeader = new CHeaderFooter(oLogicDocument.Get_HdrFtr(), oLogicDocument, oLogicDocument.Get_DrawingDocument(), hdrftr_Header);
if ("title" === sType) if ("title" === sType)
this.Section.Set_Header_First(oHeader); this.Section.Set_Header_First(oHeader);
else if ("even" === sType) else if ("even" === sType)
...@@ -767,7 +786,7 @@ ...@@ -767,7 +786,7 @@
if (null === oFooter && true === isCreate) if (null === oFooter && true === isCreate)
{ {
var oLogicDocument = private_GetLogicDocument(); var oLogicDocument = private_GetLogicDocument();
oFooter = new CHeaderFooter(oLogicDocument.Get_HdrFtr(), oLogicDocument, oLogicDocument.Get_DrawingDocument(), hdrftr_Footer); oFooter = new CHeaderFooter(oLogicDocument.Get_HdrFtr(), oLogicDocument, oLogicDocument.Get_DrawingDocument(), hdrftr_Footer);
if ("title" === sType) if ("title" === sType)
this.Section.Set_Footer_First(oFooter); this.Section.Set_Footer_First(oFooter);
else if ("even" === sType) else if ("even" === sType)
...@@ -836,7 +855,7 @@ ...@@ -836,7 +855,7 @@
*/ */
ApiTable.prototype.MergeCells = function(aCells) ApiTable.prototype.MergeCells = function(aCells)
{ {
var oTable = this.Table; var oTable = this.Table;
oTable.Selection.Use = true; oTable.Selection.Use = true;
oTable.Selection.Type = table_Selection_Cell; oTable.Selection.Type = table_Selection_Cell;
oTable.Selection.Data = []; oTable.Selection.Data = [];
...@@ -844,7 +863,7 @@ ...@@ -844,7 +863,7 @@
for (var nPos = 0, nCount = aCells.length; nPos < nCount; ++nPos) for (var nPos = 0, nCount = aCells.length; nPos < nCount; ++nPos)
{ {
var oCell = aCells[nPos].Cell; var oCell = aCells[nPos].Cell;
var oPos = {Cell : oCell.Index, Row : oCell.Row.Index}; var oPos = {Cell : oCell.Index, Row : oCell.Row.Index};
var nResultPos = 0; var nResultPos = 0;
var nResultLength = oTable.Selection.Data.length; var nResultLength = oTable.Selection.Data.length;
...@@ -882,44 +901,15 @@ ...@@ -882,44 +901,15 @@
return null; return null;
}; };
/** /**
* Set table style * Set table style.
* @param {ApiStyle} oStyle * @param {ApiStyle} oStyle
* @return {boolean}
*/ */
ApiTable.prototype.SetStyle = function(oStyle) ApiTable.prototype.SetStyle = function(oStyle)
{ {
if (!oStyle || !(oStyle instanceof ApiStyle) || styletype_Table !== oStyle.Style.Get_Type()) if (!oStyle || !(oStyle instanceof ApiStyle) || styletype_Table !== oStyle.Style.Get_Type())
return false; return;
this.Table.Set_Props({TableStyle : oStyle.Style.Get_Id()}); this.Table.Set_TableStyle(oStyle.Style.Get_Id(), true);
return true;
};
/**
* Set the preferred width for this table.
* @param {("auto" | "twips" | "percent" | "nil")} sType - Type of the width value
* @param {number} [nValue]
*/
ApiTable.prototype.SetWidth = function(sType, nValue)
{
if ("auto" === sType)
this.Table.Set_Props({TableWidth : null});
else if ("twips" === sType)
this.Table.Set_Props({TableWidth : private_Twips2MM(nValue)});
else if ("percent" === sType)
this.Table.Set_Props({TableWidth : -nValue});
};
/**
* Set the alignment of the current table with respect to the text margins in the current section.
* @param {("left" | "right" | "center")} sJcType
*/
ApiTable.prototype.SetJc = function(sJcType)
{
if ("left" === sJcType)
this.Table.Set_Props({TableAlignment : 0});
else if ("right" === sJcType)
this.Table.Set_Props({TableAlignment : 2});
else if ("center" === sJcType)
this.Table.Set_Props({TableAlignment : 1});
}; };
/** /**
* Specify the components of the conditional formatting of the referenced table style (if one exists) * Specify the components of the conditional formatting of the referenced table style (if one exists)
...@@ -938,95 +928,13 @@ ...@@ -938,95 +928,13 @@
*/ */
ApiTable.prototype.SetTableLook = function(isFirstColumn, isFirstRow, isLastColumn, isLastRow, isHorBand, isVerBand) ApiTable.prototype.SetTableLook = function(isFirstColumn, isFirstRow, isLastColumn, isLastRow, isHorBand, isVerBand)
{ {
this.Table.Set_Props({TableLook : var oTableLook = new CTableLook(private_GetBoolean(isFirstColumn),
{ private_GetBoolean(isFirstRow),
FirstCol : isFirstColumn, private_GetBoolean(isLastColumn),
FirstRow : isFirstRow, private_GetBoolean(isLastRow),
LastCol : isLastColumn, private_GetBoolean(isHorBand),
LastRow : isLastRow, private_GetBoolean(isVerBand));
BandHor : isHorBand, this.Table.Set_TableLook(oTableLook);
BandVer : isVerBand
}});
};
/**
* Set the border which shall be displayed at the top of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTable.prototype.SetTableBorderTop = function(sType, nSize, nSpace, r, g, b)
{
this.Table.Set_Props({TableBorders : {Top : private_GetTableBorder(sType, nSize, nSpace, r, g, b)}});
};
/**
* Set the border which shall be displayed at the bottom of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTable.prototype.SetTableBorderBottom = function(sType, nSize, nSpace, r, g, b)
{
this.Table.Set_Props({TableBorders : {Bottom : private_GetTableBorder(sType, nSize, nSpace, r, g, b)}});
};
/**
* Set the border which shall be displayed on the left of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTable.prototype.SetTableBorderLeft = function(sType, nSize, nSpace, r, g, b)
{
this.Table.Set_Props({TableBorders : {Left : private_GetTableBorder(sType, nSize, nSpace, r, g, b)}});
};
/**
* Set the border which shall be displayed on the right of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTable.prototype.SetTableBorderRight = function(sType, nSize, nSpace, r, g, b)
{
this.Table.Set_Props({TableBorders : {Right : private_GetTableBorder(sType, nSize, nSpace, r, g, b)}});
};
/**
* Specify the border which shall be displayed on all horizontal table cell borders which are not on
* an outmost edge of the parent table (all horizontal borders which are not the topmost or bottommost border).
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTable.prototype.SetTableBorderInsideH = function(sType, nSize, nSpace, r, g, b)
{
this.Table.Set_Props({TableBorders : {InsideH : private_GetTableBorder(sType, nSize, nSpace, r, g, b)}});
};
/**
* Specify the border which shall be displayed on all vertical table cell borders which are not on an
* outmost edge of the parent table (all horizontal borders which are not the leftmost or rightmost border).
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTable.prototype.SetTableBorderInsideV = function(sType, nSize, nSpace, r, g, b)
{
this.Table.Set_Props({TableBorders : {InsideV : private_GetTableBorder(sType, nSize, nSpace, r, g, b)}});
}; };
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
...@@ -1503,18 +1411,18 @@ ...@@ -1503,18 +1411,18 @@
if ("auto" === sLineRule) if ("auto" === sLineRule)
{ {
this.ParaPr.Spacing.LineRule = Asc.linerule_Auto; this.ParaPr.Spacing.LineRule = Asc.linerule_Auto;
this.ParaPr.Spacing.Line = nLine / 240.0; this.ParaPr.Spacing.Line = nLine / 240.0;
} }
else if ("atLeast" === sLineRule) else if ("atLeast" === sLineRule)
{ {
this.ParaPr.Spacing.LineRule = Asc.linerule_AtLeast; this.ParaPr.Spacing.LineRule = Asc.linerule_AtLeast;
this.ParaPr.Spacing.Line = private_Twips2MM(nLine); this.ParaPr.Spacing.Line = private_Twips2MM(nLine);
} }
else if ("exact" === sLineRule) else if ("exact" === sLineRule)
{ {
this.ParaPr.Spacing.LineRule = Asc.linerule_Exact; this.ParaPr.Spacing.LineRule = Asc.linerule_Exact;
this.ParaPr.Spacing.Line = private_Twips2MM(nLine); this.ParaPr.Spacing.Line = private_Twips2MM(nLine);
} }
} }
...@@ -1681,7 +1589,7 @@ ...@@ -1681,7 +1589,7 @@
if (!(oNumPr instanceof ApiNumbering)) if (!(oNumPr instanceof ApiNumbering))
return; return;
this.ParaPr.NumPr = new CNumPr(); this.ParaPr.NumPr = new CNumPr();
this.ParaPr.NumPr.NumId = oNumPr.Num.Get_Id(); this.ParaPr.NumPr.NumId = oNumPr.Num.Get_Id();
this.ParaPr.NumPr.Lvl = undefined; this.ParaPr.NumPr.Lvl = undefined;
...@@ -1756,15 +1664,33 @@ ...@@ -1756,15 +1664,33 @@
{ {
switch (sType) switch (sType)
{ {
case "none" : this.Num.Set_Lvl_None(this.Lvl); break; case "none" :
case "bullet": this.Num.Set_Lvl_Bullet(this.Lvl, sSymbol, new CTextPr()); break; this.Num.Set_Lvl_None(this.Lvl);
case "1)" : this.Num.Set_Lvl_Numbered_1(this.Lvl); break; break;
case "1." : this.Num.Set_Lvl_Numbered_2(this.Lvl); break; case "bullet":
case "I." : this.Num.Set_Lvl_Numbered_5(this.Lvl); break; this.Num.Set_Lvl_Bullet(this.Lvl, sSymbol, new CTextPr());
case "A." : this.Num.Set_Lvl_Numbered_6(this.Lvl); break; break;
case "a)" : this.Num.Set_Lvl_Numbered_7(this.Lvl); break; case "1)" :
case "a." : this.Num.Set_Lvl_Numbered_8(this.Lvl); break; this.Num.Set_Lvl_Numbered_1(this.Lvl);
case "i." : this.Num.Set_Lvl_Numbered_9(this.Lvl); break; break;
case "1." :
this.Num.Set_Lvl_Numbered_2(this.Lvl);
break;
case "I." :
this.Num.Set_Lvl_Numbered_5(this.Lvl);
break;
case "A." :
this.Num.Set_Lvl_Numbered_6(this.Lvl);
break;
case "a)" :
this.Num.Set_Lvl_Numbered_7(this.Lvl);
break;
case "a." :
this.Num.Set_Lvl_Numbered_8(this.Lvl);
break;
case "i." :
this.Num.Set_Lvl_Numbered_9(this.Lvl);
break;
} }
}; };
/** /**
...@@ -1807,7 +1733,7 @@ ...@@ -1807,7 +1733,7 @@
this.Num.Set_Lvl_ByFormat(this.Lvl, nType, sTextFormatString, nAlign); this.Num.Set_Lvl_ByFormat(this.Lvl, nType, sTextFormatString, nAlign);
}; };
/** /**
* This element specifies a one-based index which determines when a numbering level should restart to its start * This element specifies a one-based index which determines when a numbering level should restart to its start
* value. A numbering level restarts when an instance of the specified numbering level, which shall be * value. A numbering level restarts when an instance of the specified numbering level, which shall be
* higher (earlier than the this level) is used in the given document's contents. By default this value is true. * higher (earlier than the this level) is used in the given document's contents. By default this value is true.
* @param {boolean} isRestart * @param {boolean} isRestart
...@@ -1840,6 +1766,230 @@ ...@@ -1840,6 +1766,230 @@
this.Num.Set_Lvl_Suff(this.Lvl, numbering_suff_Nothing); this.Num.Set_Lvl_Suff(this.Lvl, numbering_suff_Nothing);
}; };
//------------------------------------------------------------------------------------------------------------------
//
// ApiTablePr
//
//------------------------------------------------------------------------------------------------------------------
/**
* Specifies the number of columns which shall comprise each a table style column band for this table style.
* @param {number} nCount
*/
ApiTablePr.prototype.SetStyleColBandSize = function(nCount)
{
this.TablePr.TableStyleColBandSize = private_GetInt(nCount, 1, null);
this.private_OnChange();
};
/**
* Specifies the number of rows which shall comprise each a table style row band for this table style.
* @param {number} nCount
*/
ApiTablePr.prototype.SetStyleRowBandSize = function(nCount)
{
this.TablePr.TableStyleRowBandSize = private_GetInt(nCount, 1, null);
this.private_OnChange();
};
/**
* Specifies the alignment of the current table with respect to the text margins in the current section.
* @param {("left" | "right" | "center")} sJcType
*/
ApiTablePr.prototype.SetJc = function(sJcType)
{
if ("left" === sJcType)
this.TablePr.Jc = AscCommon.align_Left;
else if ("right" === sJcType)
this.TablePr.Jc = AscCommon.align_Right;
else if ("center" === sJcType)
this.TablePr.Jc = AscCommon.align_Center;
this.private_OnChange();
};
/**
* Specify the shading which shall be applied to the extents of the current table.
* @param {ShdType} sType
* @param {byte} r
* @param {byte} g
* @param {byte} b
* @param {boolean} [isAuto=false]
*/
ApiTablePr.prototype.SetShd = function(sType, r, g, b, isAuto)
{
this.TablePr.Shd = private_GetShd(sType, r, g, b, isAuto);
this.private_OnChange();
};
/**
* Set the border which shall be displayed at the top of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTablePr.prototype.SetTableBorderTop = function(sType, nSize, nSpace, r, g, b)
{
this.TablePr.TableBorders.Top = private_GetTableBorder(sType, nSize, nSpace, r, g, b);
this.private_OnChange();
};
/**
* Set the border which shall be displayed at the bottom of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTablePr.prototype.SetTableBorderBottom = function(sType, nSize, nSpace, r, g, b)
{
this.TablePr.TableBorders.Bottom = private_GetTableBorder(sType, nSize, nSpace, r, g, b);
this.private_OnChange();
};
/**
* Set the border which shall be displayed on the left of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTablePr.prototype.SetTableBorderLeft = function(sType, nSize, nSpace, r, g, b)
{
this.TablePr.TableBorders.Left = private_GetTableBorder(sType, nSize, nSpace, r, g, b);
this.private_OnChange();
};
/**
* Set the border which shall be displayed on the right of the current table.
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTablePr.prototype.SetTableBorderRight = function(sType, nSize, nSpace, r, g, b)
{
this.TablePr.TableBorders.Right = private_GetTableBorder(sType, nSize, nSpace, r, g, b);
this.private_OnChange();
};
/**
* Specify the border which shall be displayed on all horizontal table cell borders which are not on
* an outmost edge of the parent table (all horizontal borders which are not the topmost or bottommost border).
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTablePr.prototype.SetTableBorderInsideH = function(sType, nSize, nSpace, r, g, b)
{
this.TablePr.TableBorders.InsideH = private_GetTableBorder(sType, nSize, nSpace, r, g, b);
this.private_OnChange();
};
/**
* Specify the border which shall be displayed on all vertical table cell borders which are not on an
* outmost edge of the parent table (all horizontal borders which are not the leftmost or rightmost border).
* @param {BorderType} sType - The style of border.
* @param {pt_8} nSize - The width of the current border.
* @param {pt} nSpace - The spacing offset that shall be used to place this border.
* @param {byte} r
* @param {byte} g
* @param {byte} b
*/
ApiTablePr.prototype.SetTableBorderInsideV = function(sType, nSize, nSpace, r, g, b)
{
this.TablePr.TableBorders.InsideV = private_GetTableBorder(sType, nSize, nSpace, r, g, b);
this.private_OnChange();
};
/**
* Specifies the amount of space which shall be left between the bottom extent of the cell contents and the border
* of all table cells within the parent table (or table row).
* @param {twips} nValue
*/
ApiTablePr.prototype.SetTableCellMarginBottom = function(nValue)
{
this.TablePr.TableCellMar.Bottom = private_GetTableMeasure("twips", nValue);
this.private_OnChange();
};
/**
* Specifies the amount of space which shall be present between the left extent of the cell contents and the left
* border of all table cells within the parent table (or table row) .
* @param {twips} nValue
*/
ApiTablePr.prototype.SetTableCellMarginLeft = function(nValue)
{
this.TablePr.TableCellMar.Left = private_GetTableMeasure("twips", nValue);
this.private_OnChange();
};
/**
* Specifies the amount of space which shall be present between the right extent of the cell contents and the right
* border of all table cells within the parent table (or table row) .
* @param {twips} nValue
*/
ApiTablePr.prototype.SetTableCellMarginRight = function(nValue)
{
this.TablePr.TableCellMar.Right = private_GetTableMeasure("twips", nValue);
this.private_OnChange();
};
/**
* Specifies the amount of space which shall be present between the top extent of the cell contents and the top
* border of all table cells within the parent table (or table row) .
* @param {twips} nValue
*/
ApiTablePr.prototype.SetTableCellMarginTop = function(nValue)
{
this.TablePr.TableCellMar.Top = private_GetTableMeasure("twips", nValue);
this.private_OnChange();
};
/**
* Specifies the default table cell spacing (the spacing between adjacent cells and the edges of the table).
* @param {?twips} nValue - Value of the spacing. Null mean no spacing.
*/
ApiTablePr.prototype.SetCellSpacing = function(nValue)
{
if (null === nValue)
this.TablePr.TableCellSpacing = null;
else
this.TablePr.TableCellSpacing = private_Twips2MM(nValue);
this.private_OnChange();
};
/**
* Specifies the indentation which shall be added before the leading edge of the current table in the document (the
* left edge in a left-to-right table, and the right edge in a right-to-left table).
* @param {twips} nValue
*/
ApiTablePr.prototype.SetTableInd = function(nValue)
{
this.TablePr.TableInd = private_Twips2MM(nValue);
this.private_OnChange();
};
/**
* Set the preferred width for this table.
* @param {TableWidth} sType - Type of the width value
* @param {number} [nValue]
*/
ApiTablePr.prototype.SetWidth = function(sType, nValue)
{
this.TablePr.TableW = private_GetTableMeasure(sType, nValue);
this.private_OnChange();
};
/**
* Specifies the algorithm which shall be used to lay out the contents of this table within the document.
* @param {("autofit" | "fixed")} sType
*/
ApiTablePr.prototype.SetTableLayout = function(sType)
{
if ("autofit" === sType)
this.TablePr.TableLayout = tbllayout_AutoFit;
else if ("fixed" === sType)
this.TablePr.TableLayout = tbllayout_Fixed;
this.private_OnChange();
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Export // Export
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -1872,10 +2022,8 @@ ...@@ -1872,10 +2022,8 @@
ApiParagraph.prototype["GetNumbering"] = ApiParagraph.prototype.GetNumbering; ApiParagraph.prototype["GetNumbering"] = ApiParagraph.prototype.GetNumbering;
ApiParagraph.prototype["SetNumbering"] = ApiParagraph.prototype.SetNumbering; ApiParagraph.prototype["SetNumbering"] = ApiParagraph.prototype.SetNumbering;
ApiRun.prototype["GetTextPr"] = ApiRun.prototype.GetTextPr; ApiRun.prototype["GetTextPr"] = ApiRun.prototype.GetTextPr;
ApiSection.prototype["SetType"] = ApiSection.prototype.SetType; ApiSection.prototype["SetType"] = ApiSection.prototype.SetType;
ApiSection.prototype["SetEqualColumns"] = ApiSection.prototype.SetEqualColumns; ApiSection.prototype["SetEqualColumns"] = ApiSection.prototype.SetEqualColumns;
ApiSection.prototype["SetNotEqualColumns"] = ApiSection.prototype.SetNotEqualColumns; ApiSection.prototype["SetNotEqualColumns"] = ApiSection.prototype.SetNotEqualColumns;
...@@ -1894,15 +2042,7 @@ ...@@ -1894,15 +2042,7 @@
ApiTable.prototype["GetRow"] = ApiTable.prototype.GetRow; ApiTable.prototype["GetRow"] = ApiTable.prototype.GetRow;
ApiTable.prototype["MergeCells"] = ApiTable.prototype.MergeCells; ApiTable.prototype["MergeCells"] = ApiTable.prototype.MergeCells;
ApiTable.prototype["SetStyle"] = ApiTable.prototype.SetStyle; ApiTable.prototype["SetStyle"] = ApiTable.prototype.SetStyle;
ApiTable.prototype["SetWidth"] = ApiTable.prototype.SetWidth;
ApiTable.prototype["SetJc"] = ApiTable.prototype.SetJc;
ApiTable.prototype["SetTableLook"] = ApiTable.prototype.SetTableLook; ApiTable.prototype["SetTableLook"] = ApiTable.prototype.SetTableLook;
ApiTable.prototype["SetTableBorderTop"] = ApiTable.prototype.SetTableBorderTop;
ApiTable.prototype["SetTableBorderBottom"] = ApiTable.prototype.SetTableBorderBottom;
ApiTable.prototype["SetTableBorderLeft"] = ApiTable.prototype.SetTableBorderLeft;
ApiTable.prototype["SetTableBorderRight"] = ApiTable.prototype.SetTableBorderRight;
ApiTable.prototype["SetTableBorderInsideH"] = ApiTable.prototype.SetTableBorderInsideH;
ApiTable.prototype["SetTableBorderInsideV"] = ApiTable.prototype.SetTableBorderInsideV;
ApiTableRow.prototype["GetCellsCount"] = ApiTableRow.prototype.GetCellsCount; ApiTableRow.prototype["GetCellsCount"] = ApiTableRow.prototype.GetCellsCount;
ApiTableRow.prototype["GetCell"] = ApiTableRow.prototype.GetCell; ApiTableRow.prototype["GetCell"] = ApiTableRow.prototype.GetCell;
...@@ -1972,6 +2112,25 @@ ...@@ -1972,6 +2112,25 @@
ApiNumberingLevel.prototype["SetStart"] = ApiNumberingLevel.prototype.SetStart; ApiNumberingLevel.prototype["SetStart"] = ApiNumberingLevel.prototype.SetStart;
ApiNumberingLevel.prototype["SetSuff"] = ApiNumberingLevel.prototype.SetSuff; ApiNumberingLevel.prototype["SetSuff"] = ApiNumberingLevel.prototype.SetSuff;
ApiTablePr.prototype["SetStyleColBandSize"] = ApiTablePr.prototype.SetStyleColBandSize;
ApiTablePr.prototype["SetStyleRowBandSize"] = ApiTablePr.prototype.SetStyleRowBandSize;
ApiTablePr.prototype["SetJc"] = ApiTablePr.prototype.SetJc;
ApiTablePr.prototype["SetShd"] = ApiTablePr.prototype.SetShd;
ApiTablePr.prototype["SetTableBorderTop"] = ApiTablePr.prototype.SetTableBorderTop;
ApiTablePr.prototype["SetTableBorderBottom"] = ApiTablePr.prototype.SetTableBorderBottom;
ApiTablePr.prototype["SetTableBorderLeft"] = ApiTablePr.prototype.SetTableBorderLeft;
ApiTablePr.prototype["SetTableBorderRight"] = ApiTablePr.prototype.SetTableBorderRight;
ApiTablePr.prototype["SetTableBorderInsideH"] = ApiTablePr.prototype.SetTableBorderInsideH;
ApiTablePr.prototype["SetTableBorderInsideV"] = ApiTablePr.prototype.SetTableBorderInsideV;
ApiTablePr.prototype["SetTableCellMarginBottom"] = ApiTablePr.prototype.SetTableCellMarginBottom;
ApiTablePr.prototype["SetTableCellMarginLeft"] = ApiTablePr.prototype.SetTableCellMarginLeft;
ApiTablePr.prototype["SetTableCellMarginRight"] = ApiTablePr.prototype.SetTableCellMarginRight;
ApiTablePr.prototype["SetTableCellMarginTop"] = ApiTablePr.prototype.SetTableCellMarginTop;
ApiTablePr.prototype["SetCellSpacing"] = ApiTablePr.prototype.SetCellSpacing;
ApiTablePr.prototype["SetTableInd"] = ApiTablePr.prototype.SetTableInd;
ApiTablePr.prototype["SetWidth"] = ApiTablePr.prototype.SetWidth;
ApiTablePr.prototype["SetTableLayout"] = ApiTablePr.prototype.SetTableLayout;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area // Private area
...@@ -2061,6 +2220,34 @@ ...@@ -2061,6 +2220,34 @@
return oBorder; return oBorder;
} }
function private_GetTableMeasure(sType, nValue)
{
var nType = tblwidth_Auto;
var nW = 0;
if ("auto" === sType)
{
nType = tblwidth_Auto;
nW = 0;
}
else if ("nil" === sType)
{
nType = tblwidth_Nil;
nW = 0;
}
else if ("percent" === sType)
{
nType = tblwidth_Pct;
nW = private_GetInt(nValue, null, null);
}
else if ("twips" === sType)
{
nType = tblwidth_Mm;
nW = private_Twips2MM(nValue);
}
return new CTableMeasurement(nType, nW);
}
function private_GetShd(sType, r, g, b, isAuto) function private_GetShd(sType, r, g, b, isAuto)
{ {
var oShd = new CDocumentShd(); var oShd = new CDocumentShd();
...@@ -2084,9 +2271,17 @@ ...@@ -2084,9 +2271,17 @@
return (undefined !== bDefValue ? bDefValue : false); return (undefined !== bDefValue ? bDefValue : false);
} }
function private_GetInt(nValue) function private_GetInt(nValue, nMin, nMax)
{ {
return nValue | 0; var nResult = nValue | 0;
if (undefined !== nMin && null !== nMin)
nResult = Math.max(nMin, nResult);
if (undefined !== nMax && null !== nMax)
nResult = Math.min(nMax, nResult);
return nResult;
} }
function private_PtToMM(pt) function private_PtToMM(pt)
...@@ -2134,6 +2329,11 @@ ...@@ -2134,6 +2329,11 @@
{ {
return this.Table; return this.Table;
}; };
ApiTable.prototype.OnChangeTablePr = function(oApiTablePr)
{
this.Table.Set_Pr(oApiTablePr.TablePr);
oApiTablePr.TablePr = this.Table.Pr.Copy();
};
ApiStyle.prototype.OnChangeTextPr = function(oApiTextPr) ApiStyle.prototype.OnChangeTextPr = function(oApiTextPr)
{ {
this.Style.Set_TextPr(oApiTextPr.TextPr); this.Style.Set_TextPr(oApiTextPr.TextPr);
...@@ -2162,6 +2362,10 @@ ...@@ -2162,6 +2362,10 @@
{ {
this.Parent.OnChangeParaPr(this); this.Parent.OnChangeParaPr(this);
}; };
ApiTablePr.prototype.private_OnChange = function()
{
this.Parent.OnChangeTablePr(this);
};
}(window, null)); }(window, null));
...@@ -2901,6 +3105,71 @@ function TEST_BUILDER2() ...@@ -2901,6 +3105,71 @@ function TEST_BUILDER2()
oParagraph = oHeader.GetElement(0); oParagraph = oHeader.GetElement(0);
oParagraph.AddText("I'm in default header"); oParagraph.AddText("I'm in default header");
var oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetJc("left");
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetJc("center");
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetJc("right");
var oTableStyle = oDocument.GetStyle("Bordered & Lined - Accent 3");
oTable = Api.CreateTable(10, 10);
oDocument.Push(oTable);
oTable.SetStyle(oTableStyle);
oTable = Api.CreateTable(10, 10);
oDocument.Push(oTable);
oTable.SetStyle(oTableStyle);
oTable.SetTableLook(false, false, true, true, false, true);
oTable = Api.CreateTable(10, 10);
oDocument.Push(oTable);
oTable.SetTableLook(true, true, true, true, true, true);
oTable.SetStyle(oTableStyle);
oTable.SetStyleColBandSize(2);
oTable.SetStyleRowBandSize(3);
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetShd("clear", 255, 0, 0);
oTable.SetTableBorderTop("single", 32, 0, 0, 255, 0);
oTable.SetTableBorderBottom("single", 64, 0, 0, 255, 0);
oTable.SetTableBorderLeft("single", 32, 0, 0, 0, 255);
oTable.SetTableBorderRight("single", 16, 0, 0, 0, 255);
oTable.SetTableBorderInsideV("single", 32, 0, 0, 0, 0);
oTable.SetTableBorderInsideH("single", 32, 0, 0, 0, 0);
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetTableInd(1000);
oTable.SetTableCellMarginBottom(200);
oTable.SetTableCellMarginTop(100);
oTable.SetTableCellMarginLeft(400);
oTable.SetTableCellMarginRight(200);
oTable.SetCellSpacing(200);
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetWidth("auto");
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetWidth("twips", 3000);
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetWidth("percent", 100);
oTable = Api.CreateTable(3, 3);
oDocument.Push(oTable);
oTable.SetTableLayout("fixed");
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
oLD.Recalculate_FromStart(); oLD.Recalculate_FromStart();
} }
......
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