Commit f202badb authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander.Trofimov

table & paragraph styles

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57986 954022d7-b5bf-4e40-9824-e11837661b57
parent 7bd79bb4
......@@ -22,6 +22,11 @@
this.TableMatrix = null;
this.CurrentPageIndex = null;
// TABLE_STYLES
this.TableStylesLastLook = null;
this.TableStylesSheckLook = null;
this.TableStylesSheckLookFlag = false;
this.Native = window["native"];
this.checkMouseDown = function(pos, drDoc)
......@@ -1279,15 +1284,174 @@ CDrawingDocument.prototype =
///////////////////////////////////////////
StartTableStylesCheck : function()
{
{
this.TableStylesSheckLookFlag = true;
},
EndTableStylesCheck : function()
{
this.TableStylesSheckLookFlag = false;
if (this.TableStylesSheckLook != null)
{
this.CheckTableStyles(this.TableStylesSheckLook);
this.TableStylesSheckLook = null;
}
},
CheckTableStyles : function(tableLook)
{
if (this.TableStylesSheckLookFlag)
{
this.TableStylesSheckLook = tableLook;
return;
}
// сначала проверим, подписан ли кто на этот евент
// а то во вьюере не стоит ничего посылать
/*
TODO:
if (!this.m_oWordControl.m_oApi.asc_checkNeedCallback("asc_onInitTableTemplates"))
return;
*/
var bIsChanged = false;
if (null == this.TableStylesLastLook)
{
this.TableStylesLastLook = new CTablePropLook();
this.TableStylesLastLook.FirstCol = tableLook.FirstCol;
this.TableStylesLastLook.FirstRow = tableLook.FirstRow;
this.TableStylesLastLook.LastCol = tableLook.LastCol;
this.TableStylesLastLook.LastRow = tableLook.LastRow;
this.TableStylesLastLook.BandHor = tableLook.BandHor;
this.TableStylesLastLook.BandVer = tableLook.BandVer;
bIsChanged = true;
}
else
{
if (this.TableStylesLastLook.FirstCol != tableLook.FirstCol)
{
this.TableStylesLastLook.FirstCol = tableLook.FirstCol;
bIsChanged = true;
}
if (this.TableStylesLastLook.FirstRow != tableLook.FirstRow)
{
this.TableStylesLastLook.FirstRow = tableLook.FirstRow;
bIsChanged = true;
}
if (this.TableStylesLastLook.LastCol != tableLook.LastCol)
{
this.TableStylesLastLook.LastCol = tableLook.LastCol;
bIsChanged = true;
}
if (this.TableStylesLastLook.LastRow != tableLook.LastRow)
{
this.TableStylesLastLook.LastRow = tableLook.LastRow;
bIsChanged = true;
}
if (this.TableStylesLastLook.BandHor != tableLook.BandHor)
{
this.TableStylesLastLook.BandHor = tableLook.BandHor;
bIsChanged = true;
}
if (this.TableStylesLastLook.BandVer != tableLook.BandVer)
{
this.TableStylesLastLook.BandVer = tableLook.BandVer;
bIsChanged = true;
}
}
if (!bIsChanged)
return;
var logicDoc = this.m_oWordControl.m_oLogicDocument;
var _styles = logicDoc.Styles.Get_AllTableStyles();
var _styles_len = _styles.length;
if (_styles_len == 0)
return;
var _x_mar = 10;
var _y_mar = 10;
var _r_mar = 10;
var _b_mar = 10;
var _pageW = 297;
var _pageH = 210;
var W = (_pageW - _x_mar - _r_mar);
var H = (_pageH - _y_mar - _b_mar);
var _stream = global_memory_stream_menu;
var _graphics = new CDrawingStream();
this.Native["DD_PrepareNativeDraw"]();
var Rows = 5;
History.TurnOff();
g_oTableId.m_bTurnOff = true;
for (var i1 = 0; i1 < _styles_len; i1++)
{
var i = _styles[i1];
var _style = logicDoc.Styles.Style[i];
if (!_style || _style.Type != styletype_Table)
continue;
if (_table_styles == null)
{
var Cols = 5;
var Grid = [];
for (var ii = 0; ii < Cols; ii++)
Grid[ii] = W / Cols;
_table_styles = new CTable(this, logicDoc, true, 0, _x_mar, _y_mar, 1000, 1000, Rows, Cols, Grid);
_table_styles.Set_Props({TableStyle : i, TableLook : tableLook, TableLayout : c_oAscTableLayout.Fixed});
for (var j = 0; j < Rows; j++)
_table_styles.Content[j].Set_Height(H / Rows, heightrule_AtLeast);
}
else
{
_table_styles.Set_Props({TableStyle : i, TableLook : tableLook, TableLayout : c_oAscTableLayout.Fixed, CellSelect: false});
_table_styles.Recalc_CompiledPr2();
for (var j = 0; j < Rows; j++)
_table_styles.Content[j].Set_Height(H / Rows, heightrule_AtLeast);
}
_table_styles.Recalculate_Page(0);
this.Native["DD_StartNativeDraw"](TABLE_STYLE_WIDTH_PIX, TABLE_STYLE_HEIGHT_PIX, _pageW, _pageH);
var _old_mode = editor.isViewMode;
editor.isViewMode = true;
editor.isShowTableEmptyLineAttack = true;
_table_styles.Draw(0, _graphics);
editor.isShowTableEmptyLineAttack = false;
editor.isViewMode = _old_mode;
_stream["ClearNoAttack"]();
_stream["WriteByte"](0);
_stream["WriteLong"](0);
_stream["WriteString2"]("" + i);
this.Native["DD_EndNativeDraw"](_stream);
_graphics.ClearParams();
}
g_oTableId.m_bTurnOff = false;
History.TurnOn();
_stream["ClearNoAttack"]();
_stream["WriteByte"](1);
this.Native["DD_EndNativeDraw"](_stream);
},
SendControlColors : function()
......
......@@ -14,6 +14,18 @@
CDrawingStream.prototype =
{
ClearParams : function()
{
this.m_oTextPr = null;
this.m_oGrFonts = new CGrRFonts();
this.m_oLastFont = new CFontSetup();
this.IsUseFonts2 = false;
this.m_oLastFont2 = null;
this.m_bIntegerGrid = true;
},
EndDraw : function()
{
// not used
......
......@@ -166,6 +166,12 @@ asc_docs_api.prototype["Call_VR_Table"] = function(_params, _cols, _margins, _ro
}
};
asc_docs_api.prototype.GenerateNativeStyles = function()
{
var StylesPainter = new CStylesPainter();
StylesPainter.GenerateStyles(this, this.LoadedObjectDS);
};
// TEXTFONTFAMILY
function asc_menu_ReadFontFamily(_params, _cursor)
{
......@@ -4196,6 +4202,236 @@ function CFontManager()
this.Initialize = function(){};
};
function CStylesPainter()
{
this.STYLE_THUMBNAIL_WIDTH = GlobalSkin.STYLE_THUMBNAIL_WIDTH;
this.STYLE_THUMBNAIL_HEIGHT = GlobalSkin.STYLE_THUMBNAIL_HEIGHT;
this.CurrentTranslate = null;
this.IsRetinaEnabled = false;
this.GenerateStyles = function(_api, ds)
{
if (_api.WordControl.bIsRetinaSupport)
{
this.STYLE_THUMBNAIL_WIDTH <<= 1;
this.STYLE_THUMBNAIL_HEIGHT <<= 1;
this.IsRetinaEnabled = true;
}
this.CurrentTranslate = _api.CurrentTranslate;
var _stream = global_memory_stream_menu;
var _graphics = new CDrawingStream();
_api.WordControl.m_oDrawingDocument.Native["DD_PrepareNativeDraw"]();
this.GenerateDefaultStyles(_api, ds, _graphics);
this.GenerateDocumentStyles(_api, _graphics);
_stream["ClearNoAttack"]();
_stream["WriteByte"](1);
_api.WordControl.m_oDrawingDocument.Native["DD_EndNativeDraw"](_stream);
}
this.GenerateDefaultStyles = function(_api, ds, _graphics)
{
var styles = ds;
for (var i in styles)
{
var style = styles[i];
if (true == style.qFormat)
{
this.drawStyle(_graphics, style, _api);
}
}
}
this.GenerateDocumentStyles = function(_api, _graphics)
{
if (_api.WordControl.m_oLogicDocument == null)
return;
var __Styles = _api.WordControl.m_oLogicDocument.Get_Styles();
var styles = __Styles.Style;
if (styles == null)
return;
for (var i in styles)
{
var style = styles[i];
if (true == style.qFormat)
{
// как только меняется сериалайзер - меняется и код здесь. Да, не очень удобно,
// зато быстро делается
var formalStyle = i.toLowerCase().replace(/\s/g, "");
var res = formalStyle.match(/^heading([1-9][0-9]*)$/);
var index = (res) ? res[1] - 1 : -1;
var _dr_style = __Styles.Get_Pr(i, styletype_Paragraph);
_dr_style.Name = style.Name;
_dr_style.Id = i;
this.drawStyle(_graphics, _dr_style, _api);
var _name = "";
// алгоритм смены имени
if (style.Default)
{
switch (style.Default)
{
case 1:
break;
case 2:
_name = "No List";
break;
case 3:
_name = "Normal";
break;
case 4:
_name = "Normal Table";
break;
}
}
else if (index != -1)
{
_name = "Heading ".concat(index + 1);
}
}
}
}
this.drawStyle = function(graphics, style, _api)
{
_api.WordControl.m_oDrawingDocument.Native["DD_StartNativeDraw"](this.STYLE_THUMBNAIL_WIDTH, this.STYLE_THUMBNAIL_HEIGHT,
this.STYLE_THUMBNAIL_WIDTH * g_dKoef_pix_to_mm, this.STYLE_THUMBNAIL_HEIGHT * g_dKoef_pix_to_mm);
var dKoefToMM = g_dKoef_pix_to_mm;
if (this.IsRetinaEnabled)
dKoefToMM /= 2;
g_oTableId.m_bTurnOff = true;
History.TurnOff();
var oldDefTabStop = Default_Tab_Stop;
Default_Tab_Stop = 1;
var hdr = new CHeaderFooter(_api.WordControl.m_oLogicDocument.HdrFtr, _api.WordControl.m_oLogicDocument, _api.WordControl.m_oDrawingDocument, hdrftr_Header);
var _dc = hdr.Content;//new CDocumentContent(editor.WordControl.m_oLogicDocument, editor.WordControl.m_oDrawingDocument, 0, 0, 0, 0, false, true, false);
var par = new Paragraph(_api.WordControl.m_oDrawingDocument, _dc, 0, 0, 0, 0, false);
var run = new ParaRun(par, false);
for (var i = 0; i < style.Name.length; i++)
{
run.Add_ToContent(i, new ParaText(style.Name.charAt(i)), false);
}
_dc.Internal_Content_Add(0, par, false);
par.Add_ToContent(0, run);
par.Style_Add(style.Id, false);
par.Set_Align(align_Left);
par.Set_Tabs(new CParaTabs());
var _brdL = style.ParaPr.Brd.Left;
if ( undefined !== _brdL && null !== _brdL )
{
var brdL = new CDocumentBorder();
brdL.Set_FromObject(_brdL);
brdL.Space = 0;
par.Set_Border(brdL, historyitem_Paragraph_Borders_Left);
}
var _brdT = style.ParaPr.Brd.Top;
if ( undefined !== _brdT && null !== _brdT )
{
var brd = new CDocumentBorder();
brd.Set_FromObject(_brdT);
brd.Space = 0;
par.Set_Border(brd, historyitem_Paragraph_Borders_Top);
}
var _brdB = style.ParaPr.Brd.Bottom;
if ( undefined !== _brdB && null !== _brdB )
{
var brd = new CDocumentBorder();
brd.Set_FromObject(_brdB);
brd.Space = 0;
par.Set_Border(brd, historyitem_Paragraph_Borders_Bottom);
}
var _brdR = style.ParaPr.Brd.Right;
if ( undefined !== _brdR && null !== _brdR )
{
var brd = new CDocumentBorder();
brd.Set_FromObject(_brdR);
brd.Space = 0;
par.Set_Border(brd, historyitem_Paragraph_Borders_Right);
}
var _ind = new CParaInd();
_ind.FirstLine = 0;
_ind.Left = 0;
_ind.Right = 0;
par.Set_Ind(_ind, false);
var _sp = new CParaSpacing();
_sp.Line = 1;
_sp.LineRule = linerule_Auto;
_sp.Before = 0;
_sp.BeforeAutoSpacing = false;
_sp.After = 0;
_sp.AfterAutoSpacing = false;
par.Set_Spacing(_sp, false);
_dc.Reset(0, 0, 10000, 10000);
_dc.Recalculate_Page(0, true);
_dc.Reset(0, 0, par.Lines[0].Ranges[0].W + 0.001, 10000);
_dc.Recalculate_Page(0, true);
var y = 0;
var b = dKoefToMM * this.STYLE_THUMBNAIL_HEIGHT;
var w = dKoefToMM * this.STYLE_THUMBNAIL_WIDTH;
var off = 10 * dKoefToMM;
var off2 = 5 * dKoefToMM;
var off3 = 1 * dKoefToMM;
graphics.transform(1,0,0,1,0,0);
graphics.save();
graphics._s();
graphics._m(off2, y + off3);
graphics._l(w - off, y + off3);
graphics._l(w - off, b - off3);
graphics._l(off2, b - off3);
graphics._z();
graphics.clip();
var baseline = par.Lines[0].Y;
par.Shift(0, off + 0.5, y + 0.75 * (b - y) - baseline);
par.Draw(0, graphics);
graphics.restore();
Default_Tab_Stop = oldDefTabStop;
g_oTableId.m_bTurnOff = false;
History.TurnOn();
var _stream = global_memory_stream_menu;
_stream["ClearNoAttack"]();
_stream["WriteByte"](0);
_api.WordControl.m_oDrawingDocument.Native["DD_EndNativeDraw"](_stream);
graphics.ClearParams();
}
};
window["use_native_fonts_only"] = 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