Commit 555a4d1d authored by Alexander.Trofimov's avatar Alexander.Trofimov

formatting

parent ad9a304e
...@@ -1989,36 +1989,37 @@ ...@@ -1989,36 +1989,37 @@
this.styleThumbnailWidthWithRetina = this.styleThumbnailWidth; this.styleThumbnailWidthWithRetina = this.styleThumbnailWidth;
this.styleThumbnailHeightWithRetina = this.styleThumbnailHeight; this.styleThumbnailHeightWithRetina = this.styleThumbnailHeight;
if (AscCommon.AscBrowser.isRetina) { if (AscCommon.AscBrowser.isRetina) {
this.styleThumbnailWidthWithRetina = AscCommon.AscBrowser.convertToRetinaValue(this.styleThumbnailWidthWithRetina, true); this.styleThumbnailWidthWithRetina =
this.styleThumbnailHeightWithRetina = AscCommon.AscBrowser.convertToRetinaValue(this.styleThumbnailHeightWithRetina, true); AscCommon.AscBrowser.convertToRetinaValue(this.styleThumbnailWidthWithRetina, true);
this.styleThumbnailHeightWithRetina =
AscCommon.AscBrowser.convertToRetinaValue(this.styleThumbnailHeightWithRetina, true);
} }
} }
asc_CStylesPainter.prototype = { asc_CStylesPainter.prototype.asc_getStyleThumbnailWidth = function () {
constructor: asc_CStylesPainter,
asc_getStyleThumbnailWidth: function() {
return this.styleThumbnailWidthWithRetina; return this.styleThumbnailWidthWithRetina;
}, };
asc_getStyleThumbnailHeight: function() { asc_CStylesPainter.prototype.asc_getStyleThumbnailHeight = function () {
return this.styleThumbnailHeightWithRetina; return this.styleThumbnailHeightWithRetina;
}, };
asc_getDefaultStyles: function() { asc_CStylesPainter.prototype.asc_getDefaultStyles = function () {
return this.defaultStyles; return this.defaultStyles;
}, };
asc_getDocStyles: function() { asc_CStylesPainter.prototype.asc_getDocStyles = function () {
return this.docStyles; return this.docStyles;
}, };
generateStylesAll: function(cellStylesAll, fmgrGraphics, oFont, stringRenderer) { asc_CStylesPainter.prototype.generateStylesAll = function (cellStylesAll, fmgrGraphics, oFont, sr) {
this.generateDefaultStyles(cellStylesAll, fmgrGraphics, oFont, stringRenderer); this.generateDefaultStyles(cellStylesAll, fmgrGraphics, oFont, sr);
this.generateDocumentStyles(cellStylesAll, fmgrGraphics, oFont, stringRenderer); this.generateDocumentStyles(cellStylesAll, fmgrGraphics, oFont, sr);
}, };
generateDefaultStyles: function(cellStylesAll, fmgrGraphics, oFont, stringRenderer) { asc_CStylesPainter.prototype.generateDefaultStyles = function (cellStylesAll, fmgrGraphics, oFont, sr) {
var cellStyles = cellStylesAll.DefaultStyles; var cellStyles = cellStylesAll.DefaultStyles;
var oCanvas = document.createElement('canvas'); var oCanvas = document.createElement('canvas');
oCanvas.width = this.styleThumbnailWidthWithRetina; oCanvas.width = this.styleThumbnailWidthWithRetina;
oCanvas.height = this.styleThumbnailHeightWithRetina; oCanvas.height = this.styleThumbnailHeightWithRetina;
var oGraphics = new Asc.DrawingContext({canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont}); var oGraphics = new Asc.DrawingContext(
{canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
var oStyle, oCustomStyle; var oStyle, oCustomStyle;
this.defaultStyles = []; this.defaultStyles = [];
...@@ -2030,17 +2031,19 @@ ...@@ -2030,17 +2031,19 @@
// ToDo Возможно стоит переписать немного, чтобы не пробегать каждый раз по массиву custom-стилей (нужно генерировать AllStyles) // ToDo Возможно стоит переписать немного, чтобы не пробегать каждый раз по массиву custom-стилей (нужно генерировать AllStyles)
oCustomStyle = cellStylesAll.getCustomStyleByBuiltinId(oStyle.BuiltinId); oCustomStyle = cellStylesAll.getCustomStyleByBuiltinId(oStyle.BuiltinId);
this.drawStyle(oGraphics, stringRenderer, oCustomStyle || oStyle, oStyle.Name); this.drawStyle(oGraphics, sr, oCustomStyle || oStyle, oStyle.Name);
this.defaultStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Default, oCanvas.toDataURL("image/png"))); this.defaultStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Default,
oCanvas.toDataURL("image/png")));
} }
}, };
generateDocumentStyles: function(cellStylesAll, fmgrGraphics, oFont, stringRenderer) { asc_CStylesPainter.prototype.generateDocumentStyles = function (cellStylesAll, fmgrGraphics, oFont, sr) {
var cellStyles = cellStylesAll.CustomStyles; var cellStyles = cellStylesAll.CustomStyles;
var oCanvas = document.createElement('canvas'); var oCanvas = document.createElement('canvas');
oCanvas.width = this.styleThumbnailWidthWithRetina; oCanvas.width = this.styleThumbnailWidthWithRetina;
oCanvas.height = this.styleThumbnailHeightWithRetina; oCanvas.height = this.styleThumbnailHeightWithRetina;
var oGraphics = new Asc.DrawingContext({canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont}); var oGraphics = new Asc.DrawingContext(
{canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
var oStyle; var oStyle;
this.docStyles = []; this.docStyles = [];
...@@ -2050,11 +2053,12 @@ ...@@ -2050,11 +2053,12 @@
continue; continue;
} }
this.drawStyle(oGraphics, stringRenderer, oStyle, oStyle.Name); this.drawStyle(oGraphics, sr, oStyle, oStyle.Name);
this.docStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Document, oCanvas.toDataURL("image/png"))); this.docStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Document,
oCanvas.toDataURL("image/png")));
} }
}, };
drawStyle: function(oGraphics, stringRenderer, oStyle, sStyleName) { asc_CStylesPainter.prototype.drawStyle = function (oGraphics, sr, oStyle, sStyleName) {
oGraphics.clear(); oGraphics.clear();
// Fill cell // Fill cell
var oColor = oStyle.getFill(); var oColor = oStyle.getFill();
...@@ -2063,8 +2067,8 @@ ...@@ -2063,8 +2067,8 @@
oGraphics.fillRect(0, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt); oGraphics.fillRect(0, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt);
} }
var drawBorder = function(b, x1, y1, x2, y2) { var drawBorder = function (b, x1, y1, x2, y2) {
if (null != b && AscCommon.c_oAscBorderStyles.None !== b.s) { if (b && AscCommon.c_oAscBorderStyles.None !== b.s) {
oGraphics.setStrokeStyle(b.c); oGraphics.setStrokeStyle(b.c);
// ToDo поправить // ToDo поправить
...@@ -2075,9 +2079,11 @@ ...@@ -2075,9 +2079,11 @@
// borders // borders
var oBorders = oStyle.getBorder(); var oBorders = oStyle.getBorder();
drawBorder(oBorders.l, 0, 0, 0, this.styleThumbnailHeightPt); drawBorder(oBorders.l, 0, 0, 0, this.styleThumbnailHeightPt);
drawBorder(oBorders.r, this.styleThumbnailWidthPt, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt); drawBorder(oBorders.r, this.styleThumbnailWidthPt, 0, this.styleThumbnailWidthPt,
this.styleThumbnailHeightPt);
drawBorder(oBorders.t, 0, 0, this.styleThumbnailWidthPt, 0); drawBorder(oBorders.t, 0, 0, this.styleThumbnailWidthPt, 0);
drawBorder(oBorders.b, 0, this.styleThumbnailHeightPt, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt); drawBorder(oBorders.b, 0, this.styleThumbnailHeightPt, this.styleThumbnailWidthPt,
this.styleThumbnailHeightPt);
// Draw text // Draw text
var fc = oStyle.getFontColor(); var fc = oStyle.getFontColor();
...@@ -2085,18 +2091,17 @@ ...@@ -2085,18 +2091,17 @@
var format = oStyle.getFont(); var format = oStyle.getFont();
var fs = format.getSize(); var fs = format.getSize();
// Для размера шрифта делаем ограничение для превью в 16pt (у Excel 18pt, но и высота превью больше 22px) // Для размера шрифта делаем ограничение для превью в 16pt (у Excel 18pt, но и высота превью больше 22px)
var oFont = new Asc.FontProperties(format.getName(), (16 < fs) ? 16 : fs, var oFont = new Asc.FontProperties(format.getName(), (16 < fs) ? 16 : fs, format.getBold(),
format.getBold(), format.getItalic(), format.getUnderline(), format.getStrikeout()); format.getItalic(), format.getUnderline(), format.getStrikeout());
var width_padding = 3; // 4 * 72 / 96 var width_padding = 3; // 4 * 72 / 96
var tm = stringRenderer.measureString(sStyleName); var tm = sr.measureString(sStyleName);
// Текст будем рисовать по центру (в Excel чуть по другому реализовано, у них постоянный отступ снизу) // Текст будем рисовать по центру (в Excel чуть по другому реализовано, у них постоянный отступ снизу)
var textY = 0.5 * (this.styleThumbnailHeightPt - tm.height); var textY = 0.5 * (this.styleThumbnailHeightPt - tm.height);
oGraphics.setFont(oFont); oGraphics.setFont(oFont);
oGraphics.setFillStyle(oFontColor); oGraphics.setFillStyle(oFontColor);
oGraphics.fillText(sStyleName, width_padding, textY + tm.baseline); oGraphics.fillText(sStyleName, width_padding, textY + tm.baseline);
}
}; };
/** @constructor */ /** @constructor */
......
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