Commit 65eebd09 authored by Oleg.Korshul's avatar Oleg.Korshul

math images generate

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@59274 954022d7-b5bf-4e40-9824-e11837661b57
parent 306531c2
......@@ -1081,4 +1081,22 @@ var g_oArrUserColors = [15064320, 58807, 16724950, 1759488, 9981439, 56805, 1505
53721, 16718545, 1625088, 15881472, 13419776, 50636, 14752511, 55659, 14261760, 32985, 11389952, 16711800,
8571904, 1490688, 16711884, 8991743, 13407488, 41932, 11010303, 7978752, 15028480, 52387, 15007927, 52325, 47295,
14549247, 12552960, 12564480, 39359, 15007852, 12114176, 1421824, 55726, 13041893, 10665728, 30924, 49049,
14251264, 48990, 14241024, 36530, 11709440, 13369507, 44210, 11698688, 7451136, 13397504, 45710, 34214];
\ No newline at end of file
14251264, 48990, 14241024, 36530, 11709440, 13369507, 44210, 11698688, 7451136, 13397504, 45710, 34214];
function CAscMathType()
{
this.Id = 0;
this.Image = "";
}
CAscMathType.prototype.get_Id = function(){ return this.Id; };
CAscMathType.prototype.get_Image = function(){ return this.Image; };
function CAscMathCategory()
{
this.Id = 0;
this.Data = [];
}
CAscMathCategory.prototype.get_Id = function(){ return this.Id; };
CAscMathCategory.prototype.get_Data = function(){ return this.Data; };
CAscMathCategory.prototype.private_Sort = function(){ this.Data.sort( function(a,b){ return a.Id- b.Id; } ); };
\ No newline at end of file
......@@ -6336,4 +6336,128 @@ CStylesPainter.prototype =
History.TurnOn();
}
}
}
function CMathPainter(_api)
{
this.Api = _api;
this.StartLoad = function()
{
var loader = window.g_font_loader;
var nIndex = loader.map_font_index["Cambria Math"];
if (undefined === nIndex)
{
// нет Cambria Math - нет и формул
return;
}
var fontinfo = loader.fontInfos[nIndex];
if (undefined === fontinfo)
{
// нет Cambria Math - нет и формул
return;
}
var isasync = loader.LoadFont(fontinfo, this.Api.asyncFontEndLoaded_MathDraw, null);
if (false === isasync)
{
this.Generate();
}
}
this.Generate = function()
{
var bTurnOnId = false, bTurnOnHistory = false;
if (false === g_oTableId.m_bTurnOff)
{
g_oTableId.m_bTurnOff = true;
bTurnOnId = true;
}
if (true === History.Is_On())
{
bTurnOnHistory = true;
History.TurnOff();
}
var _math = new CAscMathCategory();
var _canvas = document.createElement('canvas');
var _sizes =
[
{ w : 100, h : 100 }, // Symbols
{ w : 100, h : 100 }, // Fraction
{ w : 100, h : 100 }, // Script
{ w : 100, h : 100 }, // Radical
{ w : 100, h : 100 }, // Integral
{ w : 100, h : 100 }, // LargeOperator
{ w : 100, h : 100 }, // Bracket
{ w : 100, h : 100 }, // Function
{ w : 100, h : 100 }, // Accent
{ w : 100, h : 100 }, // LimitLog
{ w : 100, h : 100 }, // Operator
{ w : 100, h : 100 }, // Matrix
];
var _types = [];
for (var _name in c_oAscMathType)
{
_types.push(c_oAscMathType[_name]);
}
_types.sort( function(a,b){ return a-b; } );
//var _time1 = new Date().getTime();
var _types_len = _types.length;
for (var t = 0; t < _types_len; t++)
{
var _type = _types[t];
var _category1 = (_type >> 24) & 0xFF;
var _category2 = (_type >> 16) & 0xFF;
_type &= 0xFFFF;
if (undefined == _math.Data[_category1])
{
_math.Data[_category1] = new CAscMathCategory();
_math.Data[_category1].Id = _category1;
}
if (undefined == _math.Data[_category1].Data[_category2])
{
_math.Data[_category1].Data[_category2] = new CAscMathCategory();
_math.Data[_category1].Data[_category2].Id = _category2;
}
var _menuType = new CAscMathType();
_menuType.Id = _type;
var _paraMath = new ParaMath();
_paraMath.Root.Load_FromMenu(_types[t]);
_paraMath.Root.Correct_Content(true);
_menuType.Image = _paraMath.MathToImageConverter(false, _canvas, _sizes[_category1].w, _sizes[_category1].h);
var tt = new Image();
tt.src = _menuType.Image;
_math.Data[_category1].Data[_category2].Data.push(_menuType);
}
_canvas = null;
//var _time2 = new Date().getTime();
//alert("" + (_time2 - _time1));
if (true === bTurnOnId)
g_oTableId.m_bTurnOff = false;
if (true === bTurnOnHistory)
History.TurnOn();
this.Api.sendMathTypesToMenu(_math);
}
}
\ No newline at end of file
......@@ -1009,7 +1009,7 @@ ParaMath.prototype.NeedCompiledCtrPr = function()
{
this.Root.NeedCompiledCtrPr();
};
ParaMath.prototype.MathToImageConverter = function(bCopy)
ParaMath.prototype.MathToImageConverter = function(bCopy, _canvasInput, _widthPx, _heightPx)
{
var bTurnOnId = false, bTurnOnHistory = false;
if (false === g_oTableId.m_bTurnOff)
......@@ -1069,7 +1069,7 @@ ParaMath.prototype.MathToImageConverter = function(bCopy)
g_oTableId.m_bTurnOff = false;
if (true === bTurnOnHistory)
History.TurnOn();
History.TurnOn();
window.IsShapeToImageConverter = true;
......@@ -1079,9 +1079,10 @@ ParaMath.prototype.MathToImageConverter = function(bCopy)
var w_px = (w_mm * dKoef) >> 0;
var h_px = (h_mm * dKoef) >> 0;
var _canvas = document.createElement('canvas');
_canvas.width = w_px;
_canvas.height = h_px;
var _canvas = (_canvasInput === undefined) ? document.createElement('canvas') : _canvasInput;
_canvas.width = (undefined == _widthPx) ? w_px : _widthPx;
_canvas.height = (undefined == _heightPx) ? h_px : _heightPx;
var _ctx = _canvas.getContext('2d');
......@@ -1091,22 +1092,43 @@ ParaMath.prototype.MathToImageConverter = function(bCopy)
g.m_oCoordTransform.tx = 0;
g.m_oCoordTransform.ty = 0;
if (_widthPx !== undefined && _heightPx !== undefined)
{
g.m_oCoordTransform.tx = (_widthPx - w_px) / 2;
g.m_oCoordTransform.ty = (_heightPx - h_px) / 2;
}
g.transform(1,0,0,1,0,0);
this.Root.draw(0, 0, g);
window.IsShapeToImageConverter = false;
var _ret = { ImageNative : _canvas, ImageUrl : "" };
try
if (undefined === _canvasInput)
{
_ret.ImageUrl = _canvas.toDataURL("image/png");
var _ret = { ImageNative: _canvas, ImageUrl: "" };
try
{
_ret.ImageUrl = _canvas.toDataURL("image/png");
}
catch (err)
{
_ret.ImageUrl = "";
}
return _ret;
}
catch (err)
else
{
_ret.ImageUrl = "";
try
{
return _canvas.toDataURL("image/png");
}
catch (err)
{
}
return "";
}
return _ret;
};
ParaMath.prototype.ApplyArgSize = function(FontSize, argSize)
......
......@@ -2167,7 +2167,7 @@ CMathContent.prototype.private_LoadFromMenuSymbol = function(Type, Pr)
case c_oAscMathType.Symbol_Omega : Code = 0x03A9; break;
}
if (-1 !== nCode)
if (-1 !== Code)
this.Add_Symbol(Code);
};
CMathContent.prototype.private_LoadFromMenuFraction = function(Type, Pr)
......@@ -2707,12 +2707,9 @@ CMathContent.prototype.Add_Symbol = function(Code)
{
var MathRun = new ParaRun(this.Paragraph, true);
for (var nCharPos = 0, nTextLen = sText.length; nCharPos < nTextLen; nCharPos++)
{
var Symbol = new CMathText(false);
Symbol.add(Code);
MathRun.Add(Symbol, true);
}
var Symbol = new CMathText(false);
Symbol.add(Code);
MathRun.Add(Symbol, true);
this.Internal_Content_Add(this.content.length, MathRun, true);
};
......
......@@ -641,6 +641,8 @@ function asc_docs_api(name)
this.TrackFile = null;
this.MathDrawer = new CMathPainter(this);
var oThis = this;
if(window.addEventListener)
window.addEventListener("message", function(){
......@@ -2005,6 +2007,17 @@ asc_docs_api.prototype.put_FramePr = function(Obj)
}
}
asc_docs_api.prototype.asyncFontEndLoaded_MathDraw = function(Obj)
{
this.sync_EndAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.LoadFont);
this.MathDrawer.Generate();
}
asc_docs_api.prototype.sendMathTypesToMenu = function(_math)
{
this.asc_fireCallback("asc_onMathTypes", _math);
this.MathDrawer = null;
}
asc_docs_api.prototype.asyncFontEndLoaded_DropCap = function(Obj)
{
this.sync_EndAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.LoadFont);
......@@ -6469,6 +6482,7 @@ asc_docs_api.prototype.OpenDocumentEndCallback = function()
}
this.WordControl.InitControl();
//this.MathDrawer.StartLoad();
if (this.isViewMode)
this.SetViewMode(true);
......
......@@ -342,7 +342,7 @@ var c_oAscSectionBreakType =
var c_oAscMathMainType =
{
Symbols : 0x00,
Symbol : 0x00,
Fraction : 0x01,
Script : 0x02,
Radical : 0x03,
......@@ -357,7 +357,7 @@ var c_oAscMathMainType =
};
var c_oAscMathMainTypeStrings = {};
c_oAscMathMainTypeStrings[c_oAscMathMainType.Symbols ] = "Symbols";
c_oAscMathMainTypeStrings[c_oAscMathMainType.Symbol ] = "Symbols";
c_oAscMathMainTypeStrings[c_oAscMathMainType.Fraction ] = "Fraction";
c_oAscMathMainTypeStrings[c_oAscMathMainType.Script ] = "Script";
c_oAscMathMainTypeStrings[c_oAscMathMainType.Radical ] = "Radical";
......
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