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

formatting

parent ad9a304e
...@@ -1976,128 +1976,133 @@ ...@@ -1976,128 +1976,133 @@
} }
/** @constructor */ /** @constructor */
function asc_CStylesPainter(width, height) { function asc_CStylesPainter(width, height) {
this.defaultStyles = null; this.defaultStyles = null;
this.docStyles = null; this.docStyles = null;
this.styleThumbnailWidth = width; this.styleThumbnailWidth = width;
this.styleThumbnailHeight = height; this.styleThumbnailHeight = height;
this.styleThumbnailWidthPt = this.styleThumbnailWidth * 72 / 96; this.styleThumbnailWidthPt = this.styleThumbnailWidth * 72 / 96;
this.styleThumbnailHeightPt = this.styleThumbnailHeight * 72 / 96; this.styleThumbnailHeightPt = this.styleThumbnailHeight * 72 / 96;
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 = { }
constructor: asc_CStylesPainter,
asc_getStyleThumbnailWidth: function() { asc_CStylesPainter.prototype.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;
this.defaultStyles = []; var oStyle, oCustomStyle;
for (var i = 0; i < cellStyles.length; ++i) { this.defaultStyles = [];
oStyle = cellStyles[i]; for (var i = 0; i < cellStyles.length; ++i) {
if (oStyle.Hidden) { oStyle = cellStyles[i];
continue; if (oStyle.Hidden) {
} continue;
// ToDo Возможно стоит переписать немного, чтобы не пробегать каждый раз по массиву custom-стилей (нужно генерировать AllStyles) }
oCustomStyle = cellStylesAll.getCustomStyleByBuiltinId(oStyle.BuiltinId); // ToDo Возможно стоит переписать немного, чтобы не пробегать каждый раз по массиву custom-стилей (нужно генерировать AllStyles)
oCustomStyle = cellStylesAll.getCustomStyleByBuiltinId(oStyle.BuiltinId);
this.drawStyle(oGraphics, stringRenderer, oCustomStyle || oStyle, oStyle.Name);
this.defaultStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Default, oCanvas.toDataURL("image/png"))); this.drawStyle(oGraphics, sr, oCustomStyle || oStyle, oStyle.Name);
} this.defaultStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Default,
}, oCanvas.toDataURL("image/png")));
generateDocumentStyles: function(cellStylesAll, fmgrGraphics, oFont, stringRenderer) { }
var cellStyles = cellStylesAll.CustomStyles; };
asc_CStylesPainter.prototype.generateDocumentStyles = function (cellStylesAll, fmgrGraphics, oFont, sr) {
var oCanvas = document.createElement('canvas'); var cellStyles = cellStylesAll.CustomStyles;
oCanvas.width = this.styleThumbnailWidthWithRetina;
oCanvas.height = this.styleThumbnailHeightWithRetina; var oCanvas = document.createElement('canvas');
var oGraphics = new Asc.DrawingContext({canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont}); oCanvas.width = this.styleThumbnailWidthWithRetina;
oCanvas.height = this.styleThumbnailHeightWithRetina;
var oStyle; var oGraphics = new Asc.DrawingContext(
this.docStyles = []; {canvas: oCanvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics, font: oFont});
for (var i = 0; i < cellStyles.length && i < 1000; ++i) {
oStyle = cellStyles[i]; var oStyle;
if (oStyle.Hidden || null != oStyle.BuiltinId) { this.docStyles = [];
continue; for (var i = 0; i < cellStyles.length && i < 1000; ++i) {
} oStyle = cellStyles[i];
if (oStyle.Hidden || null != oStyle.BuiltinId) {
this.drawStyle(oGraphics, stringRenderer, oStyle, oStyle.Name); continue;
this.docStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Document, oCanvas.toDataURL("image/png"))); }
}
}, this.drawStyle(oGraphics, sr, oStyle, oStyle.Name);
drawStyle: function(oGraphics, stringRenderer, oStyle, sStyleName) { this.docStyles.push(new AscCommon.CStyleImage(oStyle.Name, AscCommon.c_oAscStyleImage.Document,
oGraphics.clear(); oCanvas.toDataURL("image/png")));
// Fill cell }
var oColor = oStyle.getFill(); };
if (null !== oColor) { asc_CStylesPainter.prototype.drawStyle = function (oGraphics, sr, oStyle, sStyleName) {
oGraphics.setFillStyle(oColor); oGraphics.clear();
oGraphics.fillRect(0, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt); // Fill cell
} var oColor = oStyle.getFill();
if (null !== oColor) {
var drawBorder = function(b, x1, y1, x2, y2) { oGraphics.setFillStyle(oColor);
if (null != b && AscCommon.c_oAscBorderStyles.None !== b.s) { oGraphics.fillRect(0, 0, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt);
oGraphics.setStrokeStyle(b.c); }
// ToDo поправить var drawBorder = function (b, x1, y1, x2, y2) {
oGraphics.setLineWidth(b.w).beginPath().moveTo(x1, y1).lineTo(x2, y2).stroke(); if (b && AscCommon.c_oAscBorderStyles.None !== b.s) {
} oGraphics.setStrokeStyle(b.c);
};
// ToDo поправить
// borders oGraphics.setLineWidth(b.w).beginPath().moveTo(x1, y1).lineTo(x2, y2).stroke();
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); // borders
drawBorder(oBorders.b, 0, this.styleThumbnailHeightPt, this.styleThumbnailWidthPt, this.styleThumbnailHeightPt); var oBorders = oStyle.getBorder();
drawBorder(oBorders.l, 0, 0, 0, this.styleThumbnailHeightPt);
// Draw text drawBorder(oBorders.r, this.styleThumbnailWidthPt, 0, this.styleThumbnailWidthPt,
var fc = oStyle.getFontColor(); this.styleThumbnailHeightPt);
var oFontColor = fc !== null ? fc : new AscCommon.CColor(0, 0, 0); drawBorder(oBorders.t, 0, 0, this.styleThumbnailWidthPt, 0);
var format = oStyle.getFont(); drawBorder(oBorders.b, 0, this.styleThumbnailHeightPt, this.styleThumbnailWidthPt,
var fs = format.getSize(); this.styleThumbnailHeightPt);
// Для размера шрифта делаем ограничение для превью в 16pt (у Excel 18pt, но и высота превью больше 22px)
var oFont = new Asc.FontProperties(format.getName(), (16 < fs) ? 16 : fs, // Draw text
format.getBold(), format.getItalic(), format.getUnderline(), format.getStrikeout()); var fc = oStyle.getFontColor();
var oFontColor = fc !== null ? fc : new AscCommon.CColor(0, 0, 0);
var width_padding = 3; // 4 * 72 / 96 var format = oStyle.getFont();
var fs = format.getSize();
var tm = stringRenderer.measureString(sStyleName); // Для размера шрифта делаем ограничение для превью в 16pt (у Excel 18pt, но и высота превью больше 22px)
// Текст будем рисовать по центру (в Excel чуть по другому реализовано, у них постоянный отступ снизу) var oFont = new Asc.FontProperties(format.getName(), (16 < fs) ? 16 : fs, format.getBold(),
var textY = 0.5 * (this.styleThumbnailHeightPt - tm.height); format.getItalic(), format.getUnderline(), format.getStrikeout());
oGraphics.setFont(oFont);
oGraphics.setFillStyle(oFontColor); var width_padding = 3; // 4 * 72 / 96
oGraphics.fillText(sStyleName, width_padding, textY + tm.baseline);
} var tm = sr.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 */ /** @constructor */
function asc_CSheetPr() { function asc_CSheetPr() {
......
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