Commit 300b3014 authored by Sergey Luzyanin's avatar Sergey Luzyanin

Adding & editing math formulas in cell & slide

parent 53ec4a91
...@@ -2237,6 +2237,26 @@ var editor; ...@@ -2237,6 +2237,26 @@ var editor;
sendCommand(this, null, rData); sendCommand(this, null, rData);
}; };
spreadsheet_api.prototype.asc_AddMath = function(Type)
{
var t = this, fonts = {};
fonts["Cambria Math"] = 1;
t._loadFonts(fonts, function() {t.asc_AddMath2(Type);});
};
spreadsheet_api.prototype.asc_AddMath2 = function(Type)
{
var ws = this.wb.getWorksheet();
var ret = ws.objectRender.addMath(Type);
};
spreadsheet_api.prototype.asc_SetMathProps = function(MathProps)
{
var ws = this.wb.getWorksheet();
var ret = ws.objectRender.setMathProps(MathProps);
};
spreadsheet_api.prototype.asc_showImageFileDialog = function() { spreadsheet_api.prototype.asc_showImageFileDialog = function() {
// ToDo заменить на общую функцию для всех // ToDo заменить на общую функцию для всех
this.asc_addImage(); this.asc_addImage();
...@@ -3499,6 +3519,9 @@ var editor; ...@@ -3499,6 +3519,9 @@ var editor;
prot["asc_putLineSpacingBeforeAfter"] = prot.asc_putLineSpacingBeforeAfter; prot["asc_putLineSpacingBeforeAfter"] = prot.asc_putLineSpacingBeforeAfter;
prot["asc_setDrawImagePlaceParagraph"] = prot.asc_setDrawImagePlaceParagraph; prot["asc_setDrawImagePlaceParagraph"] = prot.asc_setDrawImagePlaceParagraph;
prot["asc_changeShapeImageFromFile"] = prot.asc_changeShapeImageFromFile; prot["asc_changeShapeImageFromFile"] = prot.asc_changeShapeImageFromFile;
prot["asc_AddMath"] = prot.asc_AddMath;
prot["asc_SetMathProps"] = prot.asc_SetMathProps;
//----------------------------------------------------------------------------------------------------------------------
// Frozen pane // Frozen pane
prot["asc_freezePane"] = prot.asc_freezePane; prot["asc_freezePane"] = prot.asc_freezePane;
......
...@@ -2396,6 +2396,72 @@ function DrawingObjects() { ...@@ -2396,6 +2396,72 @@ function DrawingObjects() {
}; };
_this.addMath = function(Type){
if (!_this.isViewerMode() && _this.controller) {
var oTargetContent = _this.controller.getTargetDocContent();
if(oTargetContent){
_this.controller.checkSelectedObjectsAndCallback(function(){
var MathElement = new AscCommonWord.MathMenu(Type);
_this.controller.paragraphAdd(MathElement, false);
}, [], false, AscDFH.historydescription_Spreadsheet_CreateGroup);
return;
}
var oVisibleRange = worksheet.getVisibleRange();
_this.objectLocker.reset();
_this.objectLocker.addObjectId(AscCommon.g_oIdCounter.Get_NewId());
_this.objectLocker.checkObjects(function (bLock) {
if (bLock !== true)
return;
_this.controller.resetSelection();
var activeCell = worksheet.model.selectionRange.activeCell;
var dLeft = worksheet.getCellLeft(activeCell.col, 3);
var dTop = worksheet.getCellTop(activeCell.row, 3);
var dRight = worksheet.getCellLeft(oVisibleRange.c2, 3) + worksheet.getColumnWidth(oVisibleRange.c2, 3);
var dBottom = worksheet.getCellTop(oVisibleRange.r2, 3) + worksheet.getRowHeight(oVisibleRange.r2, 3);
var coordsFrom = _this.coordsManager.calculateCoords({col: activeCell.col, row: activeCell.row, colOff: 0, rowOff: 0});
History.Create_NewPoint();
var oTextArt = _this.controller.createTextArt(0, false, worksheet.model, "");
_this.controller.resetSelection();
oTextArt.setWorksheet(_this.controller.drawingObjects.getWorksheetModel());
oTextArt.setDrawingObjects(_this.controller.drawingObjects);
oTextArt.addToDrawingObjects();
var oContent = oTextArt.getDocContent();
if(oContent){
oContent.Cursor_MoveToStartPos(false);
oContent.Paragraph_Add(new AscCommonWord.MathMenu(Type), false);
}
oTextArt.checkExtentsByDocContent();
oTextArt.spPr.xfrm.setOffX(pxToMm(coordsFrom.x) + MOVE_DELTA);
oTextArt.spPr.xfrm.setOffY(pxToMm(coordsFrom.y) + MOVE_DELTA);
oTextArt.checkDrawingBaseCoords();
_this.controller.selectObject(oTextArt, 0);
var oContent = oTextArt.getDocContent();
_this.controller.selection.textSelection = oTextArt;
oContent.Select_All();
oTextArt.addToRecalculate();
_this.controller.startRecalculate();
worksheet.setSelectionShape(true);
});
}
};
_this.setMathProps = function(MathProps)
{
_this.controller.setMathProps(MathProps);
}
_this.editImageDrawingObject = function(imageUrl) { _this.editImageDrawingObject = function(imageUrl) {
if ( imageUrl ) { if ( imageUrl ) {
......
...@@ -1750,6 +1750,24 @@ DrawingObjectsController.prototype = ...@@ -1750,6 +1750,24 @@ DrawingObjectsController.prototype =
this.applyTextFunction(CDocumentContent.prototype.Paragraph_Add, CTable.prototype.Paragraph_Add, [paraItem, bRecalculate]); this.applyTextFunction(CDocumentContent.prototype.Paragraph_Add, CTable.prototype.Paragraph_Add, [paraItem, bRecalculate]);
}, },
setMathProps: function(oMathProps)
{
var oContent = this.getTargetDocContent(false);
if(oContent){
this.checkSelectedObjectsAndCallback(function(){
var oContent2 = this.getTargetDocContent(true);
if(oContent2){
var SelectedInfo = oContent2.Get_SelectedElementsInfo();
if (null !== SelectedInfo.Get_Math()){
var ParaMath = SelectedInfo.Get_Math();
ParaMath.Set_MenuProps(oMathProps);
}
}
}, [], false, AscDFH.historydescription_Spreadsheet_SetCellFontName);
}
},
paragraphIncDecFontSize: function(bIncrease) paragraphIncDecFontSize: function(bIncrease)
{ {
this.applyDocContentFunction(CDocumentContent.prototype.Paragraph_IncDecFontSize, [bIncrease], CTable.prototype.Paragraph_IncDecFontSize); this.applyDocContentFunction(CDocumentContent.prototype.Paragraph_IncDecFontSize, [bIncrease], CTable.prototype.Paragraph_IncDecFontSize);
...@@ -7316,7 +7334,7 @@ DrawingObjectsController.prototype = ...@@ -7316,7 +7334,7 @@ DrawingObjectsController.prototype =
return oleObject; return oleObject;
}, },
createTextArt: function(nStyle, bWord, wsModel) createTextArt: function(nStyle, bWord, wsModel, sStartString)
{ {
var MainLogicDocument = (editor && editor.WordControl && editor.WordControl.m_oLogicDocument ? editor && editor.WordControl && editor.WordControl.m_oLogicDocument : null); var MainLogicDocument = (editor && editor.WordControl && editor.WordControl.m_oLogicDocument ? editor && editor.WordControl && editor.WordControl.m_oLogicDocument : null);
var TrackRevisions = (MainLogicDocument ? MainLogicDocument.Is_TrackRevisions() : false); var TrackRevisions = (MainLogicDocument ? MainLogicDocument.Is_TrackRevisions() : false);
...@@ -7340,6 +7358,10 @@ DrawingObjectsController.prototype = ...@@ -7340,6 +7358,10 @@ DrawingObjectsController.prototype =
nFontSize = 54; nFontSize = 54;
oShape.createTextBody(); oShape.createTextBody();
} }
if(typeof sStartString === "string")
{
nFontSize = undefined;
}
var oSpPr = new AscFormat.CSpPr(); var oSpPr = new AscFormat.CSpPr();
var oXfrm = new AscFormat.CXfrm(); var oXfrm = new AscFormat.CXfrm();
oXfrm.setOffX(0); oXfrm.setOffX(0);
...@@ -7414,22 +7436,35 @@ DrawingObjectsController.prototype = ...@@ -7414,22 +7436,35 @@ DrawingObjectsController.prototype =
else else
{ {
oShape.bSelectedText = false; oShape.bSelectedText = false;
sText = oShape.getTextArtTranslate().DefaultText; sText = (typeof sStartString === "string") ? sStartString : oShape.getTextArtTranslate().DefaultText;
AscFormat.AddToContentFromString(oContent, sText); AscFormat.AddToContentFromString(oContent, sText);
} }
} }
else else
{ {
sText = oShape.getTextArtTranslate().DefaultText; sText = (typeof sStartString === "string") ? sStartString : oShape.getTextArtTranslate().DefaultText;
AscFormat.AddToContentFromString(oContent, sText); AscFormat.AddToContentFromString(oContent, sText);
} }
var oTextPr = oShape.getTextArtPreviewManager().getStylesToApply()[nStyle].Copy(); var oTextPr;
oTextPr.FontSize = nFontSize; if(!(typeof sStartString === "string"))
oTextPr.RFonts.Ascii = undefined;
if(!((typeof CGraphicObjects !== "undefined") && (this instanceof CGraphicObjects)))
{ {
oTextPr.Unifill = oTextPr.TextFill; oTextPr = oShape.getTextArtPreviewManager().getStylesToApply()[nStyle].Copy();
oTextPr.TextFill = undefined; oTextPr.FontSize = nFontSize;
oTextPr.RFonts.Ascii = undefined;
if(!((typeof CGraphicObjects !== "undefined") && (this instanceof CGraphicObjects)))
{
oTextPr.Unifill = oTextPr.TextFill;
oTextPr.TextFill = undefined;
}
}
else
{
oTextPr = new CTextPr();
oTextPr.FontSize = nFontSize;
oTextPr.RFonts.Ascii = {Name: "Cambria Math", Index: -1};
oTextPr.RFonts.HAnsi = {Name: "Cambria Math", Index: -1};
oTextPr.RFonts.CS = {Name: "Cambria Math", Index: -1};
oTextPr.RFonts.EastAsia = {Name: "Cambria Math", Index: -1};
} }
oContent.Set_ApplyToAll(true); oContent.Set_ApplyToAll(true);
oContent.Paragraph_Add(new ParaTextPr(oTextPr)); oContent.Paragraph_Add(new ParaTextPr(oTextPr));
...@@ -9004,6 +9039,168 @@ function CalcLiterByLength(aAlphaBet, nLength) ...@@ -9004,6 +9039,168 @@ function CalcLiterByLength(aAlphaBet, nLength)
} }
function CollectUniColor(oUniColor)
{
if(!oUniColor || !oUniColor.color)
{
return 0;
}
var ret = [];
var oColor = oUniColor.color;
var oColorTypes = window['Asc'].c_oAscColor;
ret.push(oColor.type);
if(!oUniColor.Mods)
{
ret.push(0);
}
else
{
var aMods = oUniColor.Mods.Mods;
for(var i = 0; i < aMods.length; ++ i)
{
ret.push([aMods[i].name, aMods[i].val]);
}
}
switch(oColor.type)
{
case oColorTypes.COLOR_TYPE_NONE:
{
break;
}
case oColorTypes.COLOR_TYPE_SRGB:
{
ret.push(((oColor.RGBA.R << 16) & 0xFF0000) + ((oColor.RGBA.G << 8) & 0xFF00) + oColor.RGBA.B);
break;
}
case oColorTypes.COLOR_TYPE_PRST:
case oColorTypes.COLOR_TYPE_SCHEME:
case oColorTypes.COLOR_TYPE_SYS:
{
ret.push(oColor.id);
break;
}
}
}
function CollectGs(oGs)
{
if(!oGs)
{
return 0;
}
return [oGs.pos, CollectUniColor(oGs.color)];
}
function CollectSettingsUniFill(oUniFill)
{
if(!oUniFill || !oUniFill.fill){
return 0;
}
var ret = [];
var oFill = oUniFill.fill;
ret.push(oFill.type);
ret.push(oFill.transparent);
var oFillTypes = window['Asc'].c_oAscFill;
switch(oFill.type)
{
case oFillTypes.FILL_TYPE_NONE:{
break;
}
case oFillTypes.FILL_TYPE_BLIP:{
ret.push(oFill.RasterImageId);
break;
}
case oFillTypes.FILL_TYPE_NOFILL:{
break;
}
case oFillTypes.FILL_TYPE_SOLID:{
ret.push(CollectUniColor());
break;
}
case oFillTypes.FILL_TYPE_GRAD:{
ret.push(oFill.lin ? [oFill.lin.angle, oFill.lin.scale] : 0);
ret.push(oFill.path ? [] : 0);
ret.push(oFill.rotateWithShape ? [] : 0);
for(var i = 0; i < oFill.colors.length; ++i)
{
ret.push(CollectGs(oFill.colors[i]));
}
break;
}
case oFillTypes.FILL_TYPE_PATT:{
ret.push(oFill.ftype);
ret.push(CollectUniColor(oFill.fgClr));
ret.push(CollectUniColor(oFill.bgClr));
break;
}
case oFillTypes.FILL_TYPE_GRP:{
break;
}
}
return ret;
}
function CollectSettingsLn(oLn)
{
if(!oLn)
{
return 0;
}
var ret = [];
ret.push(CollectSettingsUniFill(oLn.Fill));
ret.push(oLn.prstDash);
if(!oLn.Join)
{
ret.push(0);
}
else
{
ret.push([oLn.Join.type, oLn.Join.limit]);
}
if(oLn.headEnd)
{
ret.push([oLn.headEnd.type, oLn.headEnd.len, oLn.headEnd.w]);
}
else
{
ret.push(0);
}
if(oLn.tailEnd)
{
ret.push([oLn.tailEnd.type, oLn.tailEnd.len, oLn.tailEnd.w]);
}
else
{
ret.push(0);
}
ret.push(oLn.algn);
ret.push(oLn.cap);
ret.push(oLn.cmpd);
ret.push(oLn.w);
return ret;
}
function CollectSettingsSpPr(oSpPr)
{
if(!oSpPr)
{
return 0;
}
return [CollectSettingsUniFill(oSpPr.Fill), CollectSettingsLn(oSpPr.ln)];
}
function CollectSettingsFromChart(oChartSpace)
{
}
//--------------------------------------------------------export---------------------------------------------------- //--------------------------------------------------------export----------------------------------------------------
......
...@@ -1722,12 +1722,49 @@ CPresentation.prototype = ...@@ -1722,12 +1722,49 @@ CPresentation.prototype =
return graphic_frame; return graphic_frame;
}, },
Set_MathProps: function (oMathProps) {
if(this.Slides[this.CurPage]){
this.Slides[this.CurPage].graphicObjects.setMathProps(oMathProps);
}
},
Paragraph_Add : function( ParaItem, bRecalculate, noUpdateInterface ) Paragraph_Add : function( ParaItem, bRecalculate, noUpdateInterface )
{ {
if(this.Slides[this.CurPage]) if(this.Slides[this.CurPage])
{ {
var oMathShape = null;
if(ParaItem.Type === para_Math)
{
var oController = this.Slides[this.CurPage].graphicObjects;
if(!(oController.selection.textSelection || (oController.selection.groupSelection && oController.selection.groupSelection.selection.textSelection)))
{
this.Slides[this.CurPage].graphicObjects.resetSelection();
var oMathShape = oController.createTextArt(0, false, null, "");
oMathShape.addToDrawingObjects();
oMathShape.select(oController, this.CurPage);
oController.selection.textSelection = oMathShape;
oMathShape.txBody.content.Cursor_MoveToStartPos(false);
}
}
this.Slides[this.CurPage].graphicObjects.paragraphAdd(ParaItem, bRecalculate); this.Slides[this.CurPage].graphicObjects.paragraphAdd(ParaItem, bRecalculate);
if(oMathShape)
{
//var oContent = oMathShape.txBody.content;
//var oTextPr = new CTextPr();
//oTextPr.RFonts.Ascii = {Name: "Cambria Math", Index: -1};
//oTextPr.RFonts.HAnsi = {Name: "Cambria Math", Index: -1};
//oTextPr.RFonts.CS = {Name: "Cambria Math", Index: -1};
//oTextPr.RFonts.EastAsia = {Name: "Cambria Math", Index: -1};
//oContent.Set_ApplyToAll(true);
//oContent.Paragraph_Add(new ParaTextPr(oTextPr));
//oContent.Set_ApplyToAll(false);
oMathShape.checkExtentsByDocContent();
oMathShape.spPr.xfrm.setOffX((this.Slides[this.CurPage].Width - oMathShape.spPr.xfrm.extX)/2);
oMathShape.spPr.xfrm.setOffY((this.Slides[this.CurPage].Height - oMathShape.spPr.xfrm.extY)/2);
}
this.Slides[this.CurPage].graphicObjects.startRecalculate(); this.Slides[this.CurPage].graphicObjects.startRecalculate();
if(!(noUpdateInterface === true)) if(!(noUpdateInterface === true))
{ {
......
...@@ -4104,8 +4104,10 @@ background-repeat: no-repeat;\ ...@@ -4104,8 +4104,10 @@ background-repeat: no-repeat;\
} }
this.SelectedObjectsStack[this.SelectedObjectsStack.length] = new asc_CSelectedObject(type, objects); this.SelectedObjectsStack[this.SelectedObjectsStack.length] = new asc_CSelectedObject(type, objects);
}; };
asc_docs_api.prototype.sync_MathPropCallback = function(mathProp)
asc_docs_api.prototype.sync_MathPropCallback = function(MathProp)
{ {
this.SelectedObjectsStack[this.SelectedObjectsStack.length] = new asc_CSelectedObject(c_oAscTypeSelectElement.Math, MathProp);
}; };
asc_docs_api.prototype.SetDrawingFreeze = function(bIsFreeze) asc_docs_api.prototype.SetDrawingFreeze = function(bIsFreeze)
...@@ -4856,6 +4858,45 @@ background-repeat: no-repeat;\ ...@@ -4856,6 +4858,45 @@ background-repeat: no-repeat;\
this.advancedOptionsAction = AscCommon.c_oAscAdvancedOptionsAction.None; this.advancedOptionsAction = AscCommon.c_oAscAdvancedOptionsAction.None;
}; };
asc_docs_api.prototype.asc_AddMath = function(Type)
{
var loader = AscCommon.g_font_loader;
var fontinfo = g_fontApplication.GetFontInfo("Cambria Math");
var isasync = loader.LoadFont(fontinfo);
if (false === isasync)
{
return this.asc_AddMath2(Type);
}
else
{
this.asyncMethodCallback = function()
{
return this.asc_AddMath2(Type);
}
}
};
asc_docs_api.prototype.asc_AddMath2 = function(Type)
{
if (false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
this.WordControl.m_oLogicDocument.Create_NewHistoryPoint(AscDFH.historydescription_Document_AddMath);
var MathElement = new AscCommonWord.MathMenu(Type);
this.WordControl.m_oLogicDocument.Paragraph_Add(MathElement, false);
}
};
//----------------------------------------------------------------------------------------------------------------------
// Работаем с формулами
//----------------------------------------------------------------------------------------------------------------------
asc_docs_api.prototype.asc_SetMathProps = function(MathProps)
{
this.WordControl.m_oLogicDocument.Set_MathProps(MathProps);
};
asc_docs_api.prototype.asyncFontEndLoaded = function(fontinfo) asc_docs_api.prototype.asyncFontEndLoaded = function(fontinfo)
{ {
this.sync_EndAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.LoadFont); this.sync_EndAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.LoadFont);
...@@ -6878,6 +6919,10 @@ background-repeat: no-repeat;\ ...@@ -6878,6 +6919,10 @@ background-repeat: no-repeat;\
asc_docs_api.prototype["asc_InputClearKeyboardElement"] = asc_docs_api.prototype.asc_InputClearKeyboardElement; asc_docs_api.prototype["asc_InputClearKeyboardElement"] = asc_docs_api.prototype.asc_InputClearKeyboardElement;
asc_docs_api.prototype["asc_getCurrentFocusObject"] = asc_docs_api.prototype.asc_getCurrentFocusObject; asc_docs_api.prototype["asc_getCurrentFocusObject"] = asc_docs_api.prototype.asc_getCurrentFocusObject;
asc_docs_api.prototype["asc_AddMath"] = asc_docs_api.prototype.asc_AddMath;
asc_docs_api.prototype["asc_SetMathProps"] = asc_docs_api.prototype.asc_SetMathProps;
window['Asc']['asc_CCommentData'] = window['Asc'].asc_CCommentData = asc_CCommentData; window['Asc']['asc_CCommentData'] = window['Asc'].asc_CCommentData = asc_CCommentData;
......
...@@ -6115,13 +6115,18 @@ ParaRun.prototype.Internal_Compile_Pr = function () ...@@ -6115,13 +6115,18 @@ ParaRun.prototype.Internal_Compile_Pr = function ()
var StyleId = this.Paragraph.Style_Get(); var StyleId = this.Paragraph.Style_Get();
// скопируем текстовые настройки прежде чем подменим на пустые // скопируем текстовые настройки прежде чем подменим на пустые
var MathFont = {Name : "Cambria Math", Index : -1};
var oShapeStyle = null, oShapeTextPr = null;;
if(Styles && typeof Styles.lastId === "string") if(Styles && typeof Styles.lastId === "string")
{ {
StyleId = Styles.lastId; StyleId = Styles.lastId;
Styles = Styles.styles; Styles = Styles.styles;
oShapeStyle = Styles.Get(StyleId);
oShapeTextPr = oShapeStyle.TextPr.Copy();
oShapeStyle.TextPr.RFonts.Merge({Ascii: MathFont});
} }
var StyleDefaultTextPr = Styles.Default.TextPr.Copy(); var StyleDefaultTextPr = Styles.Default.TextPr.Copy();
var MathFont = {Name : "Cambria Math", Index : -1};
// Ascii - по умолчанию шрифт Cambria Math // Ascii - по умолчанию шрифт Cambria Math
// hAnsi, eastAsia, cs - по умолчанию шрифты не Cambria Math, а те, которые компилируются в документе // hAnsi, eastAsia, cs - по умолчанию шрифты не Cambria Math, а те, которые компилируются в документе
...@@ -6134,6 +6139,10 @@ ParaRun.prototype.Internal_Compile_Pr = function () ...@@ -6134,6 +6139,10 @@ ParaRun.prototype.Internal_Compile_Pr = function ()
// подменяем обратно // подменяем обратно
Styles.Default.TextPr = StyleDefaultTextPr; Styles.Default.TextPr = StyleDefaultTextPr;
if(oShapeStyle && oShapeTextPr)
{
oShapeStyle.TextPr = oShapeTextPr;
}
} }
......
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