Commit c28e3473 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил выставление цвета для CStyleImage

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@66646 954022d7-b5bf-4e40-9824-e11837661b57
parent 40235494
......@@ -2836,15 +2836,17 @@ CAscMathCategory.prototype["get_W"] = function(){ return this.W; };
CAscMathCategory.prototype["get_H"] = function(){ return this.H; };
CAscMathCategory.prototype.private_Sort = function(){ this.Data.sort( function(a,b){ return a.Id- b.Id; } ); };
function CStyleImage(name, ind, type, uiPriority) {
function CStyleImage(name, ind, type, image, uiPriority) {
this.name = name;
this.thumbnailOffset = ind;
this.type = type;
this.image = image;
this.uiPriority = uiPriority;
}
CStyleImage.prototype['asc_getName'] = CStyleImage.prototype['get_Name'] = function() { return this.name; };
CStyleImage.prototype['asc_getThumbnailOffset'] = CStyleImage.prototype['get_ThumbnailOffset'] = function() { return this.thumbnailOffset; };
CStyleImage.prototype['asc_getType'] = CStyleImage.prototype['get_Type'] = function() { return this.type; };
CStyleImage.prototype['asc_getName'] = CStyleImage.prototype['get_Name'] = function() { return this.name; };
CStyleImage.prototype['asc_getImage'] = function() { return this.image; };
// эта функция ДОЛЖНА минимизироваться
function CreateAscFill(unifill)
......
......@@ -4962,7 +4962,7 @@ function CStylesPainter()
this.defaultStyles = [];
for (var i in styles)
{
this.defaultStyles[cur_index] = new CStyleImage(styles[i].Name, cur_index, c_oAscStyleImage.Default);
this.defaultStyles[cur_index] = new CStyleImage(styles[i].Name, cur_index, c_oAscStyleImage.Default, '');
cur_index++;
}
......@@ -4990,7 +4990,7 @@ function CStylesPainter()
if(true == style.qFormat)
{
this.drawStyle(graphics, style, cur_index);
this.defaultStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Default, style.uiPriority);
this.defaultStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Default, '', style.uiPriority);
cur_index++;
}
}
......@@ -5042,7 +5042,7 @@ function CStylesPainter()
var index = (res) ? res[1] - 1 : -1;
this.drawStyle(graphics, __Styles.Get_Pr(i, styletype_Paragraph), cur_index);
this.docStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Document, style.uiPriority);
this.docStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Document, '', style.uiPriority);
// алгоритм смены имени
if (style.Default)
......
......@@ -4158,7 +4158,7 @@ function CStylesPainter()
this.defaultStyles = [];
for (var i in styles)
{
this.defaultStyles[cur_index] = new CStyleImage(styles[i].Name, cur_index, c_oAscStyleImage.Default);
this.defaultStyles[cur_index] = new CStyleImage(styles[i].Name, cur_index, c_oAscStyleImage.Default, '');
cur_index++;
}
......@@ -4186,7 +4186,7 @@ function CStylesPainter()
if(true == style.qFormat)
{
this.drawStyle(graphics, style, cur_index);
this.defaultStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Default, style.uiPriority);
this.defaultStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Default, '', style.uiPriority);
cur_index++;
}
}
......@@ -4238,7 +4238,7 @@ function CStylesPainter()
var index = (res) ? res[1] - 1 : -1;
this.drawStyle(graphics, __Styles.Get_Pr(i, styletype_Paragraph), cur_index);
this.docStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Document, style.uiPriority);
this.docStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Document, '', style.uiPriority);
// алгоритм смены имени
if (style.Default)
......
......@@ -1358,6 +1358,12 @@
oCanvas.height = nDefaultStylesCount * this.styleThumbnailHeightWithRetina;
var oGraphics = new asc.DrawingContext({canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
// ToDo оставить один, когда меню добавит обработку (нарезаем по одной картинке)
var oCanvas2 = document.createElement('canvas');
oCanvas2.width = this.styleThumbnailWidthWithRetina;
oCanvas2.height = this.styleThumbnailHeightWithRetina;
var oGraphics2 = new asc.DrawingContext({canvas: oCanvas2, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
var oStyle, oCustomStyle;
this.defaultStyles = [];
for (var i = 0, styleIndex = 0; i < nLength; ++i) {
......@@ -1367,8 +1373,10 @@
// ToDo Возможно стоит переписать немного, чтобы не пробегать каждый раз по массиву custom-стилей (нужно генерировать AllStyles)
oCustomStyle = cellStylesAll.getCustomStyleByBuiltinId(oStyle.BuiltinId);
this.defaultStyles[i] = new CStyleImage(oStyle.Name, styleIndex, c_oAscStyleImage.Default);
this.drawStyle(oGraphics, stringRenderer, oCustomStyle || oStyle, oStyle.Name, styleIndex);
this.drawStyle2(oGraphics2, stringRenderer, oCustomStyle || oStyle, oStyle.Name);
this.defaultStyles[i] = new CStyleImage(oStyle.Name, styleIndex, c_oAscStyleImage.Default, oCanvas2.toDataURL("image/png"));
++styleIndex;
}
......@@ -1383,14 +1391,23 @@
oCanvas.height = nDocumentStylesCount * this.styleThumbnailHeightWithRetina;
var oGraphics = new asc.DrawingContext({canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
// ToDo оставить один, когда меню добавит обработку (нарезаем по одной картинке)
var oCanvas2 = document.createElement('canvas');
oCanvas2.width = this.styleThumbnailWidthWithRetina;
oCanvas2.height = this.styleThumbnailHeightWithRetina;
var oGraphics2 = new asc.DrawingContext({canvas: oCanvas2, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
var oStyle;
this.docStyles = [];
for (var i = 0, styleIndex = 0; i < nLength; ++i) {
oStyle = cellStyles[i];
if (oStyle.Hidden || null != oStyle.BuiltinId)
continue;
this.docStyles[styleIndex] = new CStyleImage(oStyle.Name, styleIndex, c_oAscStyleImage.Document);
this.drawStyle(oGraphics, stringRenderer, oStyle, oStyle.Name, styleIndex);
this.drawStyle2(oGraphics2, stringRenderer, oCustomStyle || oStyle, oStyle.Name);
this.docStyles[styleIndex] = new CStyleImage(oStyle.Name, styleIndex, c_oAscStyleImage.Document, oCanvas2.toDataURL("image/png"));
++styleIndex;
}
......@@ -1408,7 +1425,6 @@
if (null !== oColor)
oGraphics.fill();
var drawBorder = function (b, x1, y1, x2, y2) {
if (null != b && c_oAscBorderStyles.None !== b.s) {
oGraphics.setStrokeStyle(b.c);
......@@ -1442,7 +1458,50 @@
oGraphics.setFillStyle(oFontColor);
oGraphics.fillText(sStyleName, width_padding, textY + tm.baseline);
oGraphics.restore();
}
},
drawStyle2: function (oGraphics, stringRenderer, oStyle, sStyleName) {
oGraphics.clear();
// Fill cell
var oColor = oStyle.getFill();
if (null !== oColor) {
oGraphics.setFillStyle(oColor);
oGraphics.rect(0, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt);
oGraphics.fill();
}
var drawBorder = function (b, x1, y1, x2, y2) {
if (null != b && c_oAscBorderStyles.None !== b.s) {
oGraphics.setStrokeStyle(b.c);
// ToDo поправить
oGraphics.setLineWidth(b.w).beginPath().moveTo(x1, y1).lineTo(x2, y2).stroke();
}
};
// borders
var oBorders = oStyle.getBorder();
drawBorder(oBorders.l, 0, 0, 0, this.styleThumbnailHeightPt);
drawBorder(oBorders.r, this.styleThumbnailWidthPt, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt);
drawBorder(oBorders.t, 0, 0, this.styleThumbnailWidthPt, 0);
drawBorder(oBorders.b, 0, this.styleThumbnailHeightPt, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt);
// Draw text
var fc = oStyle.getFontColor();
var oFontColor = fc !== null ? fc : new CColor(0, 0, 0);
var format = oStyle.getFont();
// Для размера шрифта делаем ограничение для превью в 16pt (у Excel 18pt, но и высота превью больше 22px)
var oFont = new asc.FontProperties(format.fn, (16 < format.fs) ? 16 : format.fs,
format.b, format.i, format.u, format.s);
var width_padding = 3; // 4 * 72 / 96
var tm = stringRenderer.measureString(sStyleName);
// Текст будем рисовать по центру (в Excel чуть по другому реализовано, у них постоянный отступ снизу)
var textY = 0.5 * (this.styleThumbnailHeightPt - tm.height);
oGraphics.setFont(oFont);
oGraphics.setFillStyle(oFontColor);
oGraphics.fillText(sStyleName, width_padding, textY + tm.baseline);
}
};
/** @constructor */
......
......@@ -7079,7 +7079,7 @@ CStylesPainter.prototype =
this.defaultStyles = [];
for (var i in styles)
{
this.defaultStyles[cur_index] = new CStyleImage(styles[i].Name, cur_index, c_oAscStyleImage.Default);
this.defaultStyles[cur_index] = new CStyleImage(styles[i].Name, cur_index, c_oAscStyleImage.Default, '');
cur_index++;
}
......@@ -7111,7 +7111,7 @@ CStylesPainter.prototype =
if(true == style.qFormat && null === DocumentStyles.Get_StyleIdByName(style.Name, false))
{
this.drawStyle(graphics, style, cur_index);
this.defaultStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Default, style.uiPriority);
this.defaultStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Default, '', style.uiPriority);
cur_index++;
}
}
......@@ -7173,7 +7173,7 @@ CStylesPainter.prototype =
_dr_style.Id = i;
this.drawStyle(graphics, _dr_style, cur_index);
this.docStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Document, style.uiPriority);
this.docStyles[cur_index] = new CStyleImage(style.Name, cur_index, c_oAscStyleImage.Document, '', style.uiPriority);
// алгоритм смены имени
if (style.Default)
......
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