Commit 41a18a78 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

DrawingContext для основной отрисовки и DrawingContext для overlay теперь одни на весь документ.

StringRender также один, и измеряем размер цифры в дефалтовом шрифте только 1 раз при открытии документа (на 100% - 96ppi)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47329 954022d7-b5bf-4e40-9824-e11837661b57
parent d01015f9
...@@ -15,16 +15,18 @@ ...@@ -15,16 +15,18 @@
* Import * Import
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
var asc = window["Asc"]; var asc = window["Asc"];
var asc_round = asc.round; var asc_round = asc.round;
var asc_typeof = asc.typeOf; var asc_typeof = asc.typeOf;
var asc_FP = asc.FontProperties; var asc_FP = asc.FontProperties;
var asc_CE = asc.CellEditor; var asc_CE = asc.CellEditor;
var asc_WSV = asc.WorksheetView; var asc_WSV = asc.WorksheetView;
var asc_CB = asc.Clipboard; var asc_CB = asc.Clipboard;
var asc_CMM = asc.asc_CMouseMoveData; var asc_CMM = asc.asc_CMouseMoveData;
var asc_Range = asc.Range; var asc_CPrintPagesData = asc.CPrintPagesData;
var asc_CPrintPagesData = asc.CPrintPagesData; var asc_DC = asc.DrawingContext;
var asc_SR = asc.StringRender;
var asc_getcvt = asc.getCvtRatio;
/** /**
...@@ -76,6 +78,12 @@ ...@@ -76,6 +78,12 @@
this.fmgrGraphics[0].Initialize(true); // IE memory enable this.fmgrGraphics[0].Initialize(true); // IE memory enable
this.fmgrGraphics[1].Initialize(true); // IE memory enable this.fmgrGraphics[1].Initialize(true); // IE memory enable
this.buffers = {};
this.stringRender = undefined;
this.emSize = 0;
this.defaultFont = new asc_FP(this.model.getDefaultFont(), this.model.getDefaultSize());
//----------------------- //-----------------------
this.init(fontRenderingMode); this.init(fontRenderingMode);
...@@ -114,6 +122,15 @@ ...@@ -114,6 +122,15 @@
.attr("width", outer.width()) .attr("width", outer.width())
.attr("height", outer.height()); .attr("height", outer.height());
this.buffers.main = asc_DC({canvas: this.canvas[0], units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics});
this.buffers.overlay = asc_DC({canvas: this.canvasOverlay[0], units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics});
this.stringRender = asc_SR(this.buffers.main);
this.stringRender.setDefaultFont(this.defaultFont);
// Мерить нужно только со 100% и один раз для всего документа
this._calcEmSize();
// initialize events controller // initialize events controller
this.controller.init(this, this.element, this.canvasOverlay, /*handlers*/{ this.controller.init(this, this.element, this.canvasOverlay, /*handlers*/{
"resize": function () {self.resize.apply(self, arguments);}, "resize": function () {self.resize.apply(self, arguments);},
...@@ -277,7 +294,7 @@ ...@@ -277,7 +294,7 @@
} }
}, },
/*settings*/{ /*settings*/{
font: new asc_FP(this.model.getDefaultFont(), this.model.getDefaultSize()) font: this.defaultFont
}); });
this.clipboard.Api = this.Api; this.clipboard.Api = this.Api;
...@@ -307,7 +324,7 @@ ...@@ -307,7 +324,7 @@
"setAutoFiltersDialog" : function (arrVal) {self.handlers.trigger("asc_onSetAFDialog", arrVal);}, "setAutoFiltersDialog" : function (arrVal) {self.handlers.trigger("asc_onSetAFDialog", arrVal);},
"selectionRangeChanged" : function (val) {self.handlers.trigger("asc_onSelectionRangeChanged", val);} "selectionRangeChanged" : function (val) {self.handlers.trigger("asc_onSelectionRangeChanged", val);}
}); });
return new asc_WSV(wsModel, this.canvas[0], this.canvasOverlay[0], this.collaborativeEditing, this.fmgrGraphics, opt); return new asc_WSV(wsModel, this.buffers, this.stringRender, this.emSize, this.collaborativeEditing, opt);
}, },
_onSelectionNameChanged: function (name) { _onSelectionNameChanged: function (name) {
...@@ -1369,6 +1386,26 @@ ...@@ -1369,6 +1386,26 @@
manager.ClearFontsRasterCache(); manager.ClearFontsRasterCache();
} }
},
_calcEmSize: function () {
// set default worksheet header font for calculations
this.buffers.main.setFont(this.defaultFont);
// Измеряем в pt
this.stringRender.measureString(
"0123456789", {wrapText: false, shrinkToFit: false, isMerged: false, textAlign: /*khaLeft*/"left"});
var ppiX = 96; // Мерить только с 96
var ptConvToPx = asc_getcvt(1/*pt*/, 0/*px*/, ppiX);
var pxConvToPt = asc_getcvt(0/*px*/, 1/*pt*/, ppiX);
// Максимальная ширина в Pt
var maxWidthInPt = this.stringRender.getWidestCharWidth();
// Переводим в px и приводим к целому (int), а затем переводим обратно в pt
this.emSize = asc_round(maxWidthInPt * ptConvToPx) * pxConvToPt;
// Проверка для Calibri 11 должно быть asc_round(maxWidthInPt * ptConvToPx) = 7
if (!this.emSize) {throw "Error: can't measure text string";}
} }
}; };
......
...@@ -27,9 +27,7 @@ ...@@ -27,9 +27,7 @@
var asc_obj2Color = asc.colorObjToAscColor; var asc_obj2Color = asc.colorObjToAscColor;
var asc_typeof = asc.typeOf; var asc_typeof = asc.typeOf;
var asc_debug = asc.outputDebugStr; var asc_debug = asc.outputDebugStr;
var asc_DC = asc.DrawingContext;
var asc_Range = asc.Range; var asc_Range = asc.Range;
var asc_SR = asc.StringRender;
var asc_FP = asc.FontProperties; var asc_FP = asc.FontProperties;
var asc_parsecolor = asc.parseColor; var asc_parsecolor = asc.parseColor;
var asc_clone = asc.clone; var asc_clone = asc.clone;
...@@ -345,18 +343,18 @@ ...@@ -345,18 +343,18 @@
* Widget for displaying and editing Worksheet object * Widget for displaying and editing Worksheet object
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
* @param {Worksheet} model Worksheet * @param {Worksheet} model Worksheet
* @param {Object} canvas Canvas for drawing * @param {Array} buffers DrawingContext + Overlay
* @param {Object} overlay Canvas for selection * @param {StringRender} stringRender StringRender
* @param {Number} emSize Размер символа
* @param {asc_CCollaborativeEditing} collaborativeEditing * @param {asc_CCollaborativeEditing} collaborativeEditing
* @param {Array} fmgrGraphics
* @param {Object} settings Settings * @param {Object} settings Settings
* *
* @constructor * @constructor
* @memberOf Asc * @memberOf Asc
*/ */
function WorksheetView(model, canvas, overlay, collaborativeEditing, fmgrGraphics, settings) { function WorksheetView(model, buffers, stringRender, emSize, collaborativeEditing, settings) {
if ( !(this instanceof WorksheetView) ) { if ( !(this instanceof WorksheetView) ) {
return new WorksheetView(model, canvas, overlay, collaborativeEditing, fmgrGraphics, settings); return new WorksheetView(model, buffers, stringRender, emSize, collaborativeEditing, settings);
} }
this.settings = $.extend(true, {}, this.defaults, settings); this.settings = $.extend(true, {}, this.defaults, settings);
...@@ -369,15 +367,11 @@ ...@@ -369,15 +367,11 @@
this.model = model; this.model = model;
this.buffers = {}; this.buffers = buffers;
this.buffers.main = canvas.getPPIX ? canvas : asc_DC({canvas: canvas, units: 1/*pt*/, fmgrGraphics: fmgrGraphics});
this.buffers.overlay = overlay ? asc_DC({canvas: overlay, units: 1/*pt*/, fmgrGraphics: fmgrGraphics}) : null;
this.drawingCtx = this.buffers.main; this.drawingCtx = this.buffers.main;
this.overlayCtx = this.buffers.overlay; this.overlayCtx = this.buffers.overlay;
this.stringRender = asc_SR(this.drawingCtx); this.stringRender = stringRender;
this.stringRender.setDefaultFontFromFmt({fn: cells.fontName, fs: cells.fontSize});
var cnv = $('<canvas width="2" height="2"/>')[0]; var cnv = $('<canvas width="2" height="2"/>')[0];
var ctx = cnv.getContext("2d"); var ctx = cnv.getContext("2d");
...@@ -390,7 +384,7 @@ ...@@ -390,7 +384,7 @@
this.cache = new Cache(); this.cache = new Cache();
//---member declaration--- //---member declaration---
this.emSize = 0; this.emSize = emSize;
this.maxNumWidth = 0; this.maxNumWidth = 0;
this.defaultColWidth = 0; this.defaultColWidth = 0;
this.defaultRowHeight = 0; this.defaultRowHeight = 0;
...@@ -1030,12 +1024,11 @@ ...@@ -1030,12 +1024,11 @@
// ----- Initialization ----- // ----- Initialization -----
_init: function () { _init: function () {
this._calcEmSize();
this._initCellsArea(true); this._initCellsArea(true);
this._cleanCellsTextMetricsCache();
this._prepareCellTextMetricsCache(this.visibleRange);
this.autoFilters.addFiltersAfterOpen(this); this.autoFilters.addFiltersAfterOpen(this);
this._initConditionalFormatting(); this._initConditionalFormatting();
this._cleanCellsTextMetricsCache();
this._prepareCellTextMetricsCache(this.visibleRange);
// initializing is completed // initializing is completed
this._trigger("initialized"); this._trigger("initialized");
}, },
...@@ -1101,28 +1094,6 @@ ...@@ -1101,28 +1094,6 @@
} }
} }
}, },
_calcEmSize: function () {
// ToDo Мерить нужно только со 100% и один раз для всего документа
// set default worksheet header font for calculations
var c = this.settings.cells;
this._setFont(/*drawingCtx*/ undefined, c.fontName, c.fontSize);
// Измеряем в pt
this.stringRender.measureString(
"0123456789", {wrapText: false, shrinkToFit: false, isMerged: false, textAlign: khaLeft});
var ppiX = this._getPPIX(); // ToDo Мерить только с 96
var ptConvToPx = asc_getcvt(1/*pt*/, 0/*px*/, ppiX);
var pxConvToPt = asc_getcvt(0/*px*/, 1/*pt*/, ppiX);
// Максимальная ширина в Pt
var maxWidthInPt = this.stringRender.getWidestCharWidth();
// Переводим в px и приводим к целому (int), а затем переводим обратно в pt
this.emSize = asc_round(maxWidthInPt * ptConvToPx) * pxConvToPt;
// Проверка для Calibri 11 должно быть asc_round(maxWidthInPt * ptConvToPx) = 7
if (!this.emSize) {throw "Error: can't measure text string";}
},
_prepareComments: function () { _prepareComments: function () {
var commentList = []; // для отправки за один раз var commentList = []; // для отправки за один раз
for(var i = 0, length = this.model.aComments.length; i < length; ++i) for(var i = 0, length = this.model.aComments.length; i < length; ++i)
......
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