Commit ceaa8f64 authored by Ilya Kirillov's avatar Ilya Kirillov

Сделаны функции в билдере для работы со отступами и расстояниями между строк у параграфа.

parent e1bb3076
......@@ -223,6 +223,15 @@
private_PushElementToParagraph(this.Paragraph, oRun);
return new ApiRun(oRun);
};
/**
* Get ApiRun with paragraph mark
* @returns {ApiRun}
*/
ApiParagraph.prototype["GetParagraphMark"] = function()
{
var oEndRun = this.Paragraph.Content[this.Paragraph.Content.length - 1];
return new ApiRun(oEndRun);
};
/**
* Set paragraph style
* @param oStyle (ApiStyle)
......@@ -236,6 +245,90 @@
this.Paragraph.Style_Add(oStyle.Style.Get_Id(), true);
return true;
};
/**
* Set paragraph spacing line
* @param nLine (twips | undefined)
*/
ApiParagraph.prototype["SetSpacingLine"] = function(nLine)
{
this.Paragraph.Set_Spacing(private_GetParaSpacing(nLine, undefined, undefined, undefined, undefined, undefined), false);
};
/**
* Set paragraph spacing line rule
* @param sLineRule ("auto" | "atLeast" | "exact")
*/
ApiParagraph.prototype["SetSpacingLineRule"] = function(sLineRule)
{
this.Paragraph.Set_Spacing(private_GetParaSpacing(undefined, sLineRule, undefined, undefined, undefined, undefined), false);
};
/**
* Set paragraph spacing before
* @param nBefore (twips | undefined)
*/
ApiParagraph.prototype["SetSpacingBefore"] = function(nBefore)
{
this.Paragraph.Set_Spacing(private_GetParaSpacing(undefined, undefined, nBefore, undefined, undefined, undefined), false);
};
/**
* Set paragraph spacing after
* @param nAfter (twips | undefined)
*/
ApiParagraph.prototype["SetSpacingAfter"] = function(nAfter)
{
this.Paragraph.Set_Spacing(private_GetParaSpacing(undefined, undefined, undefined, nAfter, undefined, undefined), false);
};
/**
* Set paragraph before auto spacing
* @param isBeforeAuto (true | false | undefined)
*/
ApiParagraph.prototype["SetSpacingBeforeAuto"] = function(isBeforeAuto)
{
this.Paragraph.Set_Spacing(private_GetParaSpacing(undefined, undefined, undefined, undefined, isBeforeAuto, undefined), false);
};
/**
* Set paragraph after auto spacing
* @param isAfterAuto (true | false | undefined)
*/
ApiParagraph.prototype["SetSpacingAfterAuto"] = function(isAfterAuto)
{
this.Paragraph.Set_Spacing(private_GetParaSpacing(undefined, undefined, undefined, undefined, undefined, isAfterAuto), false);
};
/**
* Set paragraph justification
* @param sJc ("left" | "right" | "both" | "center")
*/
ApiParagraph.prototype["SetJc"] = function(sJc)
{
var nAlign = private_GetParaAlign(sJc);
if (undefined !== nAlign)
this.Paragraph.Set_Align(nAlign);
};
/**
* Set left indentation
* @param nValue (twips)
*/
ApiParagraph.prototype["SetIndLeft"] = function(nValue)
{
this.Paragraph.Set_Ind(private_GetParaInd(nValue, undefined, undefined));
};
/**
* Set right indentation
* @param nValue (twips)
*/
ApiParagraph.prototype["SetIndRight"] = function(nValue)
{
this.Paragraph.Set_Ind(private_GetParaInd(undefined, nValue, undefined));
};
/**
* Set first line indentation
* @param nValue (twips)
*/
ApiParagraph.prototype["SetIndFirstLine"] = function(nValue)
{
this.Paragraph.Set_Ind(private_GetParaInd(undefined, undefined, nValue));
};
//------------------------------------------------------------------------------------------------------------------
//
......@@ -245,7 +338,7 @@
/**
* Set bold
* @param isBold
* @param isBold (true | false)
*/
ApiRun.prototype["SetBold"] = function(isBold)
{
......@@ -253,7 +346,7 @@
};
/**
* Set italic
* @param isItalic
* @param isItalic (true | false)
*/
ApiRun.prototype["SetItalic"] = function(isItalic)
{
......@@ -262,12 +355,39 @@
/**
* Set underline
* @param isUnderline
* @param isUnderline (true | false)
*/
ApiRun.prototype["SetUnderline"] = function(isUnderline)
{
this.Run.Set_Underline(isUnderline);
};
/**
* Set font size
* @param nSize (half-points)
*/
ApiRun.prototype["SetFontSize"] = function(nSize)
{
this.Run.Set_FontSize(private_GetHps(nSize));
};
/**
* Set text color in rgb
* @param r (0-255)
* @param g (0-255)
* @param b (0-255)
* @oaram isAuto (true | false) false is default
*/
ApiRun.prototype["SetColor"] = function(r, g, b, isAuto)
{
this.Run.Set_Color(private_GetColor(r, g, b, isAuto));
};
/**
* Set text spacing
* @param nSpacing (twips)
*/
ApiRun.prototype["SetSpacing"] = function(nSpacing)
{
this.Run.Set_Spacing(private_Twips2MM(nSpacing));
};
//------------------------------------------------------------------------------------------------------------------
// Private area
......@@ -288,6 +408,83 @@
return editor.WordControl.m_oLogicDocument;
}
function private_Twips2MM(twips)
{
return 25.4 / 72.0 / 20 * twips;
}
function private_GetHps(hps)
{
return 2 * Math.ceil(hps);
}
function private_GetColor(r, g, b, Auto)
{
return new CDocumentColor(r, g, b, Auto ? Auto : false);
}
function private_GetParaSpacing(nLine, sLineRule, nBefore, nAfter, isBeforeAuto, isAfterAuto)
{
var oSp = new CParaSpacing();
if (undefined !== nLine)
oSp.Line = private_Twips2MM(nLine);
if (undefined !== sLineRule)
{
if ("auto" === sLineRule)
oSp.LineRule = linerule_Auto;
else if ("atLeast" === sLineRule)
oSp.LineRule = linerule_AtLeast;
else if ("exact" === sLineRule)
oSp.LineRule = linerule_Exact;
}
if (undefined !== nBefore)
oSp.Before = private_Twips2MM(nBefore);
if (undefined !== nAfter)
oSp.After = private_Twips2MM(nAfter);
if (undefined !== isAfterAuto)
oSp.AfterAutoSpacing = isAfterAuto;
if (undefined !== isBeforeAuto)
oSp.BeforeAutoSpacing = isBeforeAuto;
return oSp;
}
function private_GetParaInd(nLeft, nRight, nFirstLine)
{
var oInd = new CParaInd();
if (undefined !== nLeft)
oInd.Left = private_Twips2MM(nLeft);
if (undefined !== nRight)
oInd.Right = private_Twips2MM(nRight);
if (undefined !== nFirstLine)
oInd.FirstLine = private_Twips2MM(nFirstLine);
return oInd;
}
function private_GetParaAlign(sJc)
{
if ("left" === sJc)
return align_Left;
else if ("right" === sJc)
return align_Right;
else if ("both" === sJc)
return align_Justify;
else if ("center" === sJc)
return align_Center;
return undefined;
}
ApiParagraph.prototype.private_GetImpl = function()
{
return this.Paragraph;
......@@ -312,16 +509,105 @@ function TEST_BUILDER()
var oDocument = Api.GetDocument();
var oHeadingStyle = oDocument.GetStyle("Heading 1");
var oNoSpacingStyle = oDocument.GetStyle("No Spacing");
var oParagraph = Api.CreateParagraph();
oParagraph.SetSpacingLine(276);
oParagraph.SetSpacingLineRule("auto");
oParagraph.SetJc("left");
var oEndRun = oParagraph.GetParagraphMark();
oEndRun.SetFontSize(52);
oEndRun.SetColor(0x14, 0x14, 0x14);
oEndRun.SetSpacing(5);
oParagraph.AddPageBreak();
// TODO: Добавить 2 автофигуры
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetStyle(oNoSpacingStyle);
// TODO: Добавить aвтофигуру
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetStyle(oHeadingStyle);
// TODO: Добавить aвтофигуру
oParagraph.AddText("Overview");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.AddText("In the previous meeting of the board of directors funds were approved to take the product “Innovate 1” to market. They have also allocated a sum of $250,000 towards market identification and launch efforts. This document describes in brief the objective set forth by the VP of marketing pursuant to the board’s decision.");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetStyle(oHeadingStyle);
oParagraph.SetSpacingAfter(100);
oParagraph.SetSpacingAfterAuto(true);
oParagraph.SetSpacingBefore(100);
oParagraph.SetSpacingBeforeAuto(true);
// TODO: Добавить aвтофигуру
oParagraph.AddText("Summary");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetSpacingAfter(100);
oParagraph.SetSpacingAfterAuto(true);
oParagraph.SetSpacingBefore(100);
oParagraph.SetSpacingBeforeAuto(true);
// TODO: Добавить автофигуру
oParagraph.AddText("After years of market research and focused creative effort we are in a position to take our “Innovate 1” to market. We have a three phase approach in place to complete the product and take the product to market. The first step of this initiative is to test the market. Once we have identified the market, then we will make any final product product to drive that effectively keeps down costs while meeting sales goals. ");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetStyle(oHeadingStyle);
oParagraph.SetSpacingAfter(100);
oParagraph.SetSpacingAfterAuto(true);
oParagraph.SetSpacingBefore(100);
oParagraph.SetSpacingBeforeAuto(true);
// TODO: Добавить автофигуру
oParagraph.AddText("Financial Overview");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetIndRight(5040);
oParagraph.AddText("Included are the estimated investment costs to introduce the new product. As you can see for the first 3 years we will be in the investment phase. Generating market demand and building our reputation in this category. By 201");
oParagraph.AddText("7");
oParagraph.AddText(" we expect to be profitable.");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetIndRight(5040);
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetStyle(oHeadingStyle);
oParagraph.SetSpacingAfter(100);
oParagraph.SetSpacingAfterAuto(true);
oParagraph.SetSpacingBefore(100);
oParagraph.SetSpacingBeforeAuto(true);
oParagraph.AddText("Details");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetSpacingAfter(240);
oParagraph.AddText("Out of the $250,000 allocated for this effort, we would like to spend about $50,000 towards the identification of the market. For this we are allowed to engage with a marketing consulting organization. Let us start with creating an RFP for this and start inviting the bids. We would like to get the selection process completed by no later than end of first quarter.");
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.SetSpacingBefore(100);
oParagraph.SetSpacingBeforeAuto(true);
oParagraph.SetSpacingAfter(360);
// TODO: Вставить разрыв секции
oDocument.Push(oParagraph);
//------------------------------------------------------------------------------------------------------------------
oLD.Recalculate_FromStart(true);
}
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