Commit 7f113082 authored by Sergey.Luzyanin's avatar Sergey.Luzyanin Committed by Alexander.Trofimov

TextArtPreviewManager

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@63493 954022d7-b5bf-4e40-9824-e11837661b57
parent 8e797149
......@@ -441,4 +441,422 @@ function arrReverse(arr) {
}
}
return newarr;
}
function CreateAscColorByIndex(nIndex)
{
var oColor = new asc_CColor();
oColor.type = c_oAscColor.COLOR_TYPE_SCHEME;
oColor.value = nIndex;
return oColor;
}
function CreateAscFillByIndex(nIndex)
{
var oAscFill = new CAscFill();
oAscFill.type = c_oAscFill.FILL_TYPE_SOLID;
oAscFill.fill = new asc_CFillSolid();
oAscFill.fill.color = CreateAscColorByIndex(nIndex);
return oAscFill;
}
function CreateAscGradFillByIndex(nIndex1, nIndex2, nAngle)
{
var oAscFill = new CAscFill();
oAscFill.type = c_oAscFill.FILL_TYPE_GRAD;
oAscFill.fill = new asc_CFillGrad();
oAscFill.fill.GradType = c_oAscFillGradType.GRAD_LINEAR;
oAscFill.fill.LinearAngle = nAngle;
oAscFill.fill.LinearScale = true;
oAscFill.fill.Colors = [CreateAscColorByIndex(nIndex1), CreateAscColorByIndex(nIndex2)];
oAscFill.fill.Positions = [0, 100000];
oAscFill.fill.LinearAngle = nAngle;
oAscFill.fill.LinearScale = true;
return oAscFill;
}
function TextArtPreviewManager()
{
this.canvas = null;
this.canvasWidth = 50;
this.canvasHeight = 50;
this.shapeWidth = 50;
this.shapeHeight = 50;
this.TAShape = null;
this.TextArtStyles = [];
this.aStylesByIndex = [];
this.aStylesByIndexToApply = [];
this.dKoeff = 4;
//if (AscBrowser.isRetina) {
// this.dKoeff <<= 1;
//}
}
TextArtPreviewManager.prototype.initStyles = function()
{
var oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(24), new CUniFill());
oTextPr.TextOutline = CreateNoFillLine();
this.aStylesByIndex[0] = oTextPr;
this.aStylesByIndexToApply[0] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscGradFillByIndex(52, 24, 5400000), new CUniFill());
oTextPr.TextOutline = CreateNoFillLine();
this.aStylesByIndex[1] = oTextPr;
this.aStylesByIndexToApply[1] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscGradFillByIndex(44, 42, 5400000), new CUniFill());
oTextPr.TextOutline = CreateNoFillLine();
this.aStylesByIndex[2] = oTextPr;
this.aStylesByIndexToApply[2] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CreateNoFillUniFill();
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(34)), undefined, undefined, undefined, undefined, (15773/36000)*this.dKoeff);
this.aStylesByIndex[3] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CreateNoFillUniFill();
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(34)), undefined, undefined, undefined, undefined, (15773/36000));
this.aStylesByIndexToApply[3] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CreateNoFillUniFill();
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(59)), undefined, undefined, undefined, undefined, (15773/36000)*this.dKoeff);
this.aStylesByIndex[4] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CreateNoFillUniFill();
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(59)), undefined, undefined, undefined, undefined, (15773/36000));
this.aStylesByIndexToApply[4] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CreateNoFillUniFill();
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(52)), undefined, undefined, undefined, undefined, (15773/36000)*this.dKoeff);
this.aStylesByIndex[5] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CreateNoFillUniFill();
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(52)), undefined, undefined, undefined, undefined, (15773/36000));
this.aStylesByIndexToApply[5] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(27), new CUniFill());
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(52)), undefined, undefined, undefined, undefined, (12700/36000)*this.dKoeff);
this.aStylesByIndex[6] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(27), new CUniFill());
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(52)), undefined, undefined, undefined, undefined, (12700/36000));
this.aStylesByIndexToApply[6] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(42), new CUniFill());
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(46)), undefined, undefined, undefined, undefined, (12700/36000)*this.dKoeff);
this.aStylesByIndex[7] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(42), new CUniFill());
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(46)), undefined, undefined, undefined, undefined, (12700/36000));
this.aStylesByIndexToApply[7] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(57), new CUniFill());
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(54)), undefined, undefined, undefined, undefined, (12700/36000)*this.dKoeff);
this.aStylesByIndex[8] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscFillByIndex(57), new CUniFill());
oTextPr.TextOutline = CreatePenFromParams(CorrectUniFill(CreateAscFillByIndex(54)), undefined, undefined, undefined, undefined, (12700/36000));
this.aStylesByIndexToApply[8] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscGradFillByIndex(45, 57, 0), new CUniFill());
oTextPr.TextOutline = CreateNoFillLine();
this.aStylesByIndex[9] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscGradFillByIndex(52, 33, 0), new CUniFill());
oTextPr.TextOutline = CreateNoFillLine();
this.aStylesByIndex[10] = oTextPr;
oTextPr = new CTextPr();
oTextPr.Bold = true;
oTextPr.TextFill = CorrectUniFill(CreateAscGradFillByIndex(27, 45, 5400000), new CUniFill());
oTextPr.TextOutline = CreateNoFillLine();
this.aStylesByIndex[11] = oTextPr;
}
TextArtPreviewManager.prototype.clear = function()
{
this.TextArtStyles.length = 0;
};
TextArtPreviewManager.prototype.getWordArtStyles = function()
{
if(this.TextArtStyles.length === 0)
{
this.generateTextArtStyles();
}
return this.TextArtStyles;
};
TextArtPreviewManager.prototype.getCanvas = function()
{
if (null === this.canvas)
{
this.canvas = document.createElement('canvas');
this.canvas.width = this.canvasWidth;
this.canvas.height = this.canvasHeight;
if (AscBrowser.isRetina) {
this.canvas.width <<= 1;
this.canvas.height <<= 1;
}
}
return this.canvas;
};
TextArtPreviewManager.prototype.getShapeByPrst = function(prst)
{
var oShape = this.getShape();
var oContent = oShape.getDocContent();
var textStr = "abcde";
var TextSpacing = undefined;
switch(prst)
{
case "textButton":
{
TextSpacing = 4;
textStr = "abcde";
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
textStr = "Fghi";
oContent.Add_NewParagraph();
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
textStr = "Jklmn";
oContent.Add_NewParagraph();
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
break;
}
case "textArchUp":
case "textArchDown":
{
TextSpacing = 4;
textStr = "abcdefg";
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
break;
}
case "textCircle":
{
TextSpacing = 4;
textStr = "abcdefghijklmnop";
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
break;
}
default:
{
var textStr = "abcde";
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
/*oContent.Add_NewParagraph();
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}
oContent.Add_NewParagraph();
for(var i = 0; i < textStr.length; ++i)
{
oContent.Paragraph_Add(new ParaText(textStr[i]), false);
}*/
}
}
oContent.Set_ApplyToAll(true);
oContent.Set_ParagraphAlign(align_Center);
oContent.Paragraph_Add(new ParaTextPr({FontSize: 36, Spacing: TextSpacing}));
//oContent.Set_ParagraphAlign(new ParaTextPr({FontSize: 16}));
oContent.Set_ApplyToAll(false);
var oBodypr = oShape.getBodyPr().createDuplicate();
oBodypr.prstTxWarp = ExecuteNoHistory(
function()
{
return CreatePrstTxWarpGeometry(prst)
}, []);
if(!oShape.bWordShape)
{
oShape.txBody.setBodyPr(oBodypr);
}
else
{
oShape.setBodyPr(oBodypr);
}
oShape.setBDeleted(false);
oShape.recalculate();
return oShape;
};
TextArtPreviewManager.prototype.getShape = function()
{
var oShape = new CShape();
var oParent = null, oWorkSheet = null;
var bWord = true;
if(window["Asc"]["editor"])
{
var api_sheet = window["Asc"]["editor"];
oShape.setWorksheet(api_sheet.wb.getWorksheet().model);
oWorkSheet = api_sheet.wb.getWorksheet().model;
bWord = false;
}
else
{
if(editor && editor.WordControl && editor.WordControl.m_oLogicDocument.Slides && editor.WordControl.m_oLogicDocument.Slides[editor.WordControl.m_oLogicDocument.CurPage])
{
oShape.setParent(editor.WordControl.m_oLogicDocument.Slides[editor.WordControl.m_oLogicDocument.CurPage]);
oParent = editor.WordControl.m_oLogicDocument.Slides[editor.WordControl.m_oLogicDocument.CurPage];
bWord = false;
}
}
var oParentObjects = oShape.getParentObjects();
var oTrack = new NewShapeTrack("textRect", 0, 0, oParentObjects.theme, oParentObjects.master, oParentObjects.layout, oParentObjects.slide, 0);
oTrack.track({}, oShape.convertPixToMM(this.canvasWidth), oShape.convertPixToMM(this.canvasHeight));
oShape = oTrack.getShape(bWord, oShape.getDrawingDocument(), oShape.drawingObjects);
var oBodypr = oShape.getBodyPr().createDuplicate();
oBodypr.lIns = 0;
oBodypr.tIns = 0;
oBodypr.rIns = 0;
oBodypr.bIns = 0;
oBodypr.anchor = 1;
if(!bWord)
{
oShape.txBody.setBodyPr(oBodypr);
}
else
{
oShape.setBodyPr(oBodypr);
}
oShape.spPr.setLn(CreatePenFromParams(CreateNoFillUniFill(), null, null, null, 2, null));
if(oWorkSheet)
{
oShape.setWorksheet(oWorkSheet);
}
if(oParent)
{
oShape.setParent(oParent);
}
oShape.spPr.xfrm.setOffX(0);
oShape.spPr.xfrm.setOffY(0);
oShape.spPr.xfrm.setExtX(this.shapeWidth);
oShape.spPr.xfrm.setExtY(this.shapeHeight);
return oShape;
};
TextArtPreviewManager.prototype.getTAShape = function()
{
if(!this.TAShape)
{
var oShape = this.getShape();
var oContent = oShape.getDocContent();
var sText = "Ta";
for(var i = 0; i < sText.length; ++i)
{
oContent.Paragraph_Add(new ParaText(sText[i]), false);
}
oContent.Set_ApplyToAll(true);
oContent.Paragraph_Add(new ParaTextPr({FontSize: 109, RFonts: {Ascii : {Name: "Arial", Index: -1}}}));
oContent.Set_ParagraphAlign(align_Center);
oContent.Set_ParagraphIndent({FirstLine: 0, Left: 0, Right: 0});
oContent.Set_ApplyToAll(false);
this.TAShape = oShape;
}
return this.TAShape;
};
TextArtPreviewManager.prototype.getWordArtPreview = function(prst)
{
var _canvas = this.getCanvas();
var ctx = _canvas.getContext('2d');
var graphics = new CGraphics();
var oShape = this.getShapeByPrst(prst);
graphics.init(ctx, _canvas.width, _canvas.height, oShape.extX, oShape.extY);
graphics.m_oFontManager = g_fontManager;
graphics.transform(1,0,0,1,0,0);
oShape.draw(graphics);
return _canvas.toDataURL("image/png");
};
TextArtPreviewManager.prototype.generateTextArtStyles = function()
{
if(this.aStylesByIndex.length === 0)
{
this.initStyles();
}
var _canvas = this.getCanvas();
var ctx = _canvas.getContext('2d');
var graphics = new CGraphics();
var oShape = this.getTAShape();
oShape.recalculate();
graphics.m_oFontManager = g_fontManager;
var oContent = oShape.getDocContent();
oContent.Set_ApplyToAll(true);
for(var i = 0; i < this.aStylesByIndex.length; ++i)
{
oContent.Paragraph_Add(new ParaTextPr(this.aStylesByIndex[i]));
graphics.init(ctx, _canvas.width, _canvas.height, oShape.extX, oShape.extY);
graphics.transform(1,0,0,1,0,0);
oShape.recalcText();
if(!oShape.bWordShape)
{
oShape.recalculate();
}
else
{
oShape.recalculateText();
}
oShape.draw(graphics);
this.TextArtStyles[i] = _canvas.toDataURL("image/png");
}
oContent.Set_ApplyToAll(false);
};
function GenerateWordArtPrewiewJson()
{
var oWordArtPreview = new TextArtPreviewManager(); for(var i = 0; i < 49; ++i){ console.log({Type: getPrstByNumber(i), Image: oWordArtPreview.getWordArtPreview(getPrstByNumber(i))}); }
}
\ No newline at end of file
......@@ -1866,15 +1866,17 @@
{
if(obj)
{
this.Fill = obj.Fill;//asc_Fill
this.Fill = obj.Fill;//asc_Fill
this.Line = obj.Line;//asc_Stroke
this.Form = obj.Form;//srting
this.Style = obj.Style;//
}
else
{
this.Fill = undefined;
this.Fill = undefined;
this.Line = undefined;
this.Form = undefined;
this.Style = undefined;
}
}
......@@ -1906,6 +1908,15 @@
{
return this.Form;
};
asc_TextArtProperties.prototype["asc_putStyle"] = asc_TextArtProperties.prototype.asc_putStyle = function(Style)
{
this.Style = Style;
};
asc_TextArtProperties.prototype["asc_getStyle"] = asc_TextArtProperties.prototype.asc_getStyle = function()
{
return this.Style;
};
window["asc_TextArtProperties"] = window["Asc"]["asc_TextArtProperties"] = window["asc_TextArtProperties"] = asc_TextArtProperties;
......@@ -2697,6 +2708,7 @@ var asc_CStroke = window["asc_CStroke"];
var CParagraphFrame = window["CParagraphFrame"];
var asc_CParagraphFrame = window["asc_CParagraphFrame"];
var CMouseMoveData = window["CMouseMoveData"];
var asc_TextArtProperties = window["asc_TextArtProperties"];
......
......@@ -120,6 +120,9 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
this.isChartEditor = false;
if(typeof ChartPreviewManager !== "undefined")
this.chartPreviewManager = new ChartPreviewManager();
if(typeof TextArtPreviewManager !== "undefined")
this.textArtPreviewManager = new TextArtPreviewManager();
// Chart
this.chartTranslate = new asc_CChartTranslate();
......@@ -2606,6 +2609,10 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
return this.chartPreviewManager.getChartPreviews(chartType);
};
spreadsheet_api.prototype.asc_getTextArtPreviews = function() {
return this.textArtPreviewManager.getWordArtStyles();
};
spreadsheet_api.prototype.asc_checkDataRange = function(dialogType, dataRange, fullCheck, isRows, chartType) {
return parserHelp.checkDataRange(this.wbModel, this.wb, dialogType, dataRange, fullCheck, isRows, chartType);
};
......@@ -3240,6 +3247,7 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
}
}
this.chartPreviewManager.clearPreviews();
this.textArtPreviewManager.clear();
}
// На view-режиме не нужно отправлять стили
......
......@@ -2848,6 +2848,7 @@ CPresentation.prototype =
{
text_pr = new CTextPr();
}
editor.textArtPreviewManager.clear();
var theme = graphic_objects.getTheme();
if(text_pr.RFonts)
{
......
......@@ -153,6 +153,11 @@ function asc_docs_api(name)
else
this.chartTranslate = null;
if(typeof TextArtPreviewManager !== "undefined")
this.textArtPreviewManager = new TextArtPreviewManager();
else
this.textArtPreviewManager = null;
// объекты, нужные для отправки в тулбар (шрифты, стили)
this._gui_fonts = null;
this._gui_editor_themes = null;
......@@ -5031,6 +5036,10 @@ asc_docs_api.prototype.asc_getChartPreviews = function(chartType)
{
return this.chartPreviewManager.getChartPreviews(chartType);
};
asc_docs_api.prototype.asc_getTextArtPreviews = function()
{
return this.textArtPreviewManager.getWordArtStyles();
};
asc_docs_api.prototype.sync_closeChartEditor = function()
{
......
......@@ -2767,6 +2767,7 @@ CGraphicObjects.prototype =
this.drawingDocument.CheckGuiControlColors();
editor.chartPreviewManager.clearPreviews();
editor.textArtPreviewManager.clear();
break;
}
}
......@@ -2781,6 +2782,7 @@ CGraphicObjects.prototype =
this.document.theme.themeElements.clrScheme = data.newScheme;
this.drawingDocument.CheckGuiControlColors();
editor.chartPreviewManager.clearPreviews();
editor.textArtPreviewManager.clear();
break;
}
}
......@@ -2825,6 +2827,7 @@ CGraphicObjects.prototype =
}
}
editor.chartPreviewManager.clearPreviews();
editor.textArtPreviewManager.clear();
break;
}
}
......@@ -2843,6 +2846,7 @@ CGraphicObjects.prototype =
}
}
editor.chartPreviewManager.clearPreviews();
editor.textArtPreviewManager.clear();
}
};
......
......@@ -508,6 +508,11 @@ function asc_docs_api(name)
else
this.chartPreviewManager = null;
if(typeof TextArtPreviewManager != "undefined")
this.textArtPreviewManager = new TextArtPreviewManager();
else
this.textArtPreviewManager = null;
this.IsLongActionCurrent = 0;
this.LongActionCallbacks = [];
this.LongActionCallbacksParams = [];
......@@ -6084,6 +6089,7 @@ asc_docs_api.prototype.ChangeColorScheme = function(index_scheme)
History.Add(this.WordControl.m_oLogicDocument.DrawingObjects, data);
this.WordControl.m_oDrawingDocument.CheckGuiControlColors();
this.chartPreviewManager.clearPreviews();
this.textArtPreviewManager.clear();
this.asc_fireCallback("asc_onUpdateChartStyles");
this.WordControl.m_oLogicDocument.Recalculate();
......@@ -7242,6 +7248,10 @@ asc_docs_api.prototype.asc_getChartPreviews = function(chartType)
{
return this.chartPreviewManager.getChartPreviews(chartType);
};
asc_docs_api.prototype.asc_getTextArtPreviews = function()
{
return this.textArtPreviewManager.getWordArtStyles();
};
asc_docs_api.prototype.sync_closeChartEditor = function()
{
......
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