Skip to content

Commit

Permalink
[apibuilder] Added methods for creating and adding word arts. (#2525)
Browse files Browse the repository at this point in the history
* Added methods for creating and adding word arts.
Added return values to ApiTextPr methods.

* TextTransform parameter for creating WordArt methods.
  • Loading branch information
KhromovNikita authored Feb 1, 2022
1 parent 849ea7f commit 9be00a1
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 4 deletions.
49 changes: 49 additions & 0 deletions cell/apiBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@
* */

/**
* Text transform preset
* @typedef {("textArchDown" | "textArchDownPour" | "textArchUp" | "textArchUpPour" | "textButton" | "textButtonPour" | "textCanDown"
* | "textCanUp" | "textCascadeDown" | "textCascadeUp" | "textChevron" | "textChevronInverted" | "textCircle" | "textCirclePour"
* | "textCurveDown" | "textCurveUp" | "textDeflate" | "textDeflateBottom" | "textDeflateInflate" | "textDeflateInflateDeflate" | "textDeflateTop"
* | "textDoubleWave1" | "textFadeDown" | "textFadeLeft" | "textFadeRight" | "textFadeUp" | "textInflate" | "textInflateBottom" | "textInflateTop"
* | "textPlain" | "textRingInside" | "textRingOutside" | "textSlantDown" | "textSlantUp" | "textStop" | "textTriangle" | "textTriangleInverted"
* | "textWave1" | "textWave2" | "textWave4" | "textNoShape")} TextTransofrm
* */

/**
* Class representing a base class for color types.
* @constructor
*/
Expand Down Expand Up @@ -1415,6 +1425,44 @@
return new ApiImage(oImage);
};

/**
* Adds an word art to the current sheet with the parameters specified.
* @memberof ApiWorksheet
* @typeofeditors ["CSE"]
* @param {ApiTextPr} [oTextPr=Api.CreateTextPr()] - The text properties.
* @param {string} [sText="Your text here"] - text for text art.
* @param {TextTransofrm} [sTransform="textNoShape"] - Text transform type.
* @param {ApiFill} [oFill=Api.CreateNoFill()] - The color or pattern used to fill the shape.
* @param {ApiStroke} [oStroke=Api.CreateStroke(0, Api.CreateNoFill())] - The stroke used to create the shape shadow.
* @param {number} [nRotAngle=0] - Rotation angle
* @param {EMU} [nWidth=1828800] - Word atr width
* @param {EMU} [nHeight=1828800] - Word atr heigth
* @param {number} [nFromCol=0] - The number of the column where the beginning of the shape will be placed.
* @param {number} [nFromRow=0] - The number of the row where the beginning of the shape will be placed.
* @param {EMU} [nColOffset=0] - The offset from the nFromCol column to the left part of the shape measured in English measure units.
* @param {EMU} [nRowOffset=0] - The offset from the nFromRow row to the upper part of the shape measured in English measure units.
* @returns {ApiDrawing}
*/
ApiWorksheet.prototype.AddWordArt = function(oTextPr, sText, sTransform, oFill, oStroke, nRotAngle, nWidth, nHeight, nFromCol, nFromRow, nColOffset, nRowOffset) {
oTextPr = oTextPr && oTextPr.TextPr ? oTextPr.TextPr : null;
nRotAngle = typeof(nRotAngle) === "number" && nRotAngle > 0 ? nRotAngle : 0;
nWidth = typeof(nWidth) === "number" && nWidth > 0 ? nWidth : 1828800;
nHeight = typeof(nHeight) === "number" && nHeight > 0 ? nHeight : 1828800;
oFill = oFill && oFill.UniFill ? oFill.UniFill : Asc.editor.CreateNoFill().UniFill;
oStroke = oStroke && oStroke.Ln ? oStroke.Ln : Asc.editor.CreateStroke(0, Asc.editor.CreateNoFill()).Ln;
nFromCol = typeof(nFromCol) === "number" && nFromCol > 0 ? nFromCol : 0;
nFromRow = typeof(nFromRow) === "number" && nFromRow > 0 ? nFromRow : 0;
nColOffset = typeof(nColOffset) === "number" && nColOffset > 0 ? nColOffset : 0;
nRowOffset = typeof(nRowOffset) === "number" && nRowOffset > 0 ? nRowOffset : 0;
sTransform = typeof(sTransform) === "string" && sTransform !== "" ? sTransform : "textNoShape";

var oArt = Asc.editor.private_createWordArt(oTextPr, sText, sTransform, oFill, oStroke, nRotAngle, nWidth, nHeight);

private_SetCoords(oArt, this.worksheet, nWidth, nHeight, nFromCol, nColOffset, nFromRow, nRowOffset);

return new ApiDrawing(oArt);
};

/**
* Replaces the current image with a new one.
* @memberof ApiWorksheet
Expand Down Expand Up @@ -3581,6 +3629,7 @@
ApiWorksheet.prototype["AddShape"] = ApiWorksheet.prototype.AddShape;
ApiWorksheet.prototype["AddImage"] = ApiWorksheet.prototype.AddImage;
ApiWorksheet.prototype["ReplaceCurrentImage"] = ApiWorksheet.prototype.ReplaceCurrentImage;
ApiWorksheet.prototype["AddWordArt"] = ApiWorksheet.prototype.AddWordArt;

ApiRange.prototype["GetClassType"] = ApiRange.prototype.GetClassType
ApiRange.prototype["GetRow"] = ApiRange.prototype.GetRow;
Expand Down
75 changes: 74 additions & 1 deletion slide/apiBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@
* @typedef {("cross" | "in" | "none" | "out")} TickMark
* */

/**
* Text transform preset
* @typedef {("textArchDown" | "textArchDownPour" | "textArchUp" | "textArchUpPour" | "textButton" | "textButtonPour" | "textCanDown"
* | "textCanUp" | "textCascadeDown" | "textCascadeUp" | "textChevron" | "textChevronInverted" | "textCircle" | "textCirclePour"
* | "textCurveDown" | "textCurveUp" | "textDeflate" | "textDeflateBottom" | "textDeflateInflate" | "textDeflateInflateDeflate" | "textDeflateTop"
* | "textDoubleWave1" | "textFadeDown" | "textFadeLeft" | "textFadeRight" | "textFadeUp" | "textInflate" | "textInflateBottom" | "textInflateTop"
* | "textPlain" | "textRingInside" | "textRingOutside" | "textSlantDown" | "textSlantUp" | "textStop" | "textTriangle" | "textTriangleInverted"
* | "textWave1" | "textWave2" | "textWave4" | "textNoShape")} TextTransofrm
* */
//------------------------------------------------------------------------------------------------------------------
//
// Base Api
Expand Down Expand Up @@ -780,6 +789,43 @@
return true;
};

/**
* Creates a word art with the parameters specified.
* @memberof Api
* @typeofeditors ["CPE"]
* @param {ApiTextPr} [oTextPr=Api.CreateTextPr()] - The text properties.
* @param {string} [sText="Your text here"] - text for text art.
* @param {TextTransofrm} [sTransform="textNoShape"] - Text transform type.
* @param {ApiFill} [oFill=Api.CreateNoFill()] - The color or pattern used to fill the shape.
* @param {ApiStroke} [oStroke=Api.CreateStroke(0, Api.CreateNoFill())] - The stroke used to create the shape shadow.
* @param {number} [nRotAngle=0] - rotation angle
* @param {EMU} [nWidth=1828800] - word atr width
* @param {EMU} [nHeight=1828800] - word atr heigth
* @param {EMU} [nIndLeft=ApiPresentation.GetWidth() / 2] - word atr width
* @param {EMU} [nIndTop=ApiPresentation.GetHeight() / 2] - word atr heigth
* @returns {ApiDrawing}
*/
Api.prototype.CreateWordArt = function(oTextPr, sText, sTransform, oFill, oStroke, nRotAngle, nWidth, nHeight, nIndLeft, nIndTop) {
var oPres = private_GetPresentation();
oTextPr = oTextPr && oTextPr.TextPr ? oTextPr.TextPr : null;
nRotAngle = typeof(nRotAngle) === "number" && nRotAngle > 0 ? nRotAngle : 0;
nWidth = typeof(nWidth) === "number" && nWidth > 0 ? nWidth : 1828800;
nHeight = typeof(nHeight) === "number" && nHeight > 0 ? nHeight : 1828800;
oFill = oFill && oFill.UniFill ? oFill.UniFill : this.CreateNoFill().UniFill;
oStroke = oStroke && oStroke.Ln ? oStroke.Ln : this.CreateStroke(0, this.CreateNoFill()).Ln;
sTransform = typeof(sTransform) === "string" && sTransform !== "" ? sTransform : "textNoShape";

var oArt = this.private_createWordArt(oTextPr, sText, sTransform, oFill, oStroke, nRotAngle, nWidth, nHeight);

nIndLeft = typeof(nIndLeft) === "number" && nIndLeft > -1 ? nIndLeft : (oPres.GetWidthMM() - oArt.spPr.xfrm.extX) / 2;
nIndTop = typeof(nIndTop) === "number" && nIndTop > -1 ? nIndTop : (oPres.GetHeightMM() - oArt.spPr.xfrm.extY) / 2;

oArt.spPr.xfrm.setOffX(nIndLeft);
oArt.spPr.xfrm.setOffY(nIndTop);

return new ApiDrawing(oArt);
};

//------------------------------------------------------------------------------------------------------------------
//
// ApiPresentation
Expand Down Expand Up @@ -1062,6 +1108,30 @@
return false;
};

/**
* Gets the width of the current presentation.
* @typeofeditors ["CPE"]
* @memberof ApiPresentation
* @returns {EMU}
*/
ApiPresentation.prototype.GetWidth = function() {
if(this.Presentation){
this.Presentation.GetWidthEMU();
}
};

/**
* Gets the height of the current presentation.
* @typeofeditors ["CPE"]
* @memberof ApiPresentation
* @returns {EMU}
*/
ApiPresentation.prototype.GetHeight = function() {
if(this.Presentation){
this.Presentation.GetHeightEMU();
}
};

//------------------------------------------------------------------------------------------------------------------
//
// ApiMaster
Expand Down Expand Up @@ -3945,7 +4015,8 @@
Api.prototype["CreateThemeColorScheme"] = Api.prototype.CreateThemeColorScheme;
Api.prototype["CreateThemeFormatScheme"] = Api.prototype.CreateThemeFormatScheme;
Api.prototype["CreateThemeFontScheme"] = Api.prototype.CreateThemeFontScheme;

Api.prototype["CreateWordArt"] = Api.prototype.CreateWordArt;

ApiPresentation.prototype["GetClassType"] = ApiPresentation.prototype.GetClassType;
ApiPresentation.prototype["GetCurSlideIndex"] = ApiPresentation.prototype.GetCurSlideIndex;
ApiPresentation.prototype["GetSlideByIndex"] = ApiPresentation.prototype.GetSlideByIndex;
Expand All @@ -3961,6 +4032,8 @@
ApiPresentation.prototype["ApplyTheme"] = ApiPresentation.prototype.ApplyTheme;
ApiPresentation.prototype["RemoveSlides"] = ApiPresentation.prototype.RemoveSlides;
ApiPresentation.prototype["SetLanguage"] = ApiPresentation.prototype.SetLanguage;
ApiPresentation.prototype["GetWidth"] = ApiPresentation.prototype.GetWidth;
ApiPresentation.prototype["GetHeight"] = ApiPresentation.prototype.GetHeight;

ApiMaster.prototype["GetClassType"] = ApiMaster.prototype.GetClassType;
ApiMaster.prototype["GetLayout"] = ApiMaster.prototype.GetLayout;
Expand Down
Loading

0 comments on commit 9be00a1

Please sign in to comment.