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

Правка с рассчетом высоты строки (почти как в Excel)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56609 954022d7-b5bf-4e40-9824-e11837661b57
parent 70a813a8
...@@ -371,26 +371,29 @@ function TextMetrics(width, height, lineHeight, baseline, descender, fontSize, c ...@@ -371,26 +371,29 @@ function TextMetrics(width, height, lineHeight, baseline, descender, fontSize, c
* Creates font metrics * Creates font metrics
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
* @constructor * @constructor
* @param {Number} ascender
* @param {Number} descender
* @param {Number} lineGap
* *
* @memberOf Asc * @memberOf Asc
*/ */
function FontMetrics(ascender, descender, lineGap) { function FontMetrics () {
if ( !(this instanceof FontMetrics) ) { this.ascender = 0;
return new FontMetrics(ascender, descender, lineGap); this.descender = 0;
} this.lineGap = 0;
this.ascender = ascender !== undefined ? ascender : 0; this.nat_scale = 0;
this.descender = descender !== undefined ? descender : 0; this.nat_y1 = 0;
this.lineGap = lineGap !== undefined ? lineGap : 0; this.nat_y2 = 0;
return this;
} }
FontMetrics.prototype.clone = function () { FontMetrics.prototype.clone = function () {
return new FontMetrics(this.ascender, this.descender, this.lineGap); var res = new FontMetrics();
res.ascender = this.ascender;
res.descender = this.descender;
res.lineGap = this.lineGap;
res.nat_scale = this.nat_scale;
res.nat_y1 = this.nat_y1;
res.nat_y2 = this.nat_y2;
return res;
}; };
...@@ -797,15 +800,21 @@ DrawingContext.prototype = { ...@@ -797,15 +800,21 @@ DrawingContext.prototype = {
* @return {FontMetrics} * @return {FontMetrics}
*/ */
getFontMetrics: function (units) { getFontMetrics: function (units) {
var fm = this.fmgrGraphics[0], var fm = this.fmgrGraphics[0];
d = Math.abs(fm.m_lDescender), var d = Math.abs(fm.m_lDescender);
r = getCvtRatio(0/*px*/, units >= 0 && units <=3 ? units : this.units, this.ppiX), var r = getCvtRatio(0/*px*/, units >= 0 && units <=3 ? units : this.units, this.ppiX);
factor = this.getFontSize() * r / fm.m_lUnits_Per_Em; var factor = this.getFontSize() * r / fm.m_lUnits_Per_Em;
return new FontMetrics(
factor * fm.m_lAscender, var res = new FontMetrics();
factor * d, res.ascender = factor * fm.m_lAscender;
factor * (fm.m_lLineHeight - fm.m_lAscender - d) res.descender = factor * d;
); res.lineGap = factor * (fm.m_lLineHeight - fm.m_lAscender - d);
var face = fm.m_pFont.m_pFace;
res.nat_scale = face.header.Units_Per_EM;
res.nat_y1 = face.header.yMax;
res.nat_y2 = face.header.yMin;
return res;
}, },
setFont: function (font, angle) { setFont: function (font, angle) {
......
...@@ -937,7 +937,7 @@ ...@@ -937,7 +937,7 @@
var z = t.defaults.canvasZIndex; var z = t.defaults.canvasZIndex;
var left = t.left * t.kx; var left = t.left * t.kx;
var top = t.top * t.ky; var top = t.top * t.ky;
var widthStyle = (t.right - t.left) * t.kx - 1; var widthStyle = (t.right - t.left) * t.kx - 1; // ToDo разобраться с '-1'
var heightStyle = (t.bottom - t.top) * t.ky - 1; var heightStyle = (t.bottom - t.top) * t.ky - 1;
var isRetina = AscBrowser.isRetina; var isRetina = AscBrowser.isRetina;
var width = widthStyle, height = heightStyle; var width = widthStyle, height = heightStyle;
......
...@@ -604,6 +604,17 @@ ...@@ -604,6 +604,17 @@
l.bl = a; l.bl = a;
l.a = fm.ascender; l.a = fm.ascender;
l.d = fm.descender; l.d = fm.descender;
var _a = Math.max(0, fm.nat_y1 * f / fm.nat_scale);
var _d = Math.max(0, (-fm.nat_y2) * f / fm.nat_scale);
var _aa = asc_calcnpt(_a, ppi);
var _dd = asc_calcnpt(_d, ppi);
l.th = _aa + _dd;
l.bl = _aa;
l.a = _aa;
l.d = _dd;
} }
return l; return l;
}; };
...@@ -1108,3 +1119,43 @@ ...@@ -1108,3 +1119,43 @@
} }
)(window); )(window);
/*
function get_span_height(_fm)
{
var fm = _fm.fm;
var face = fm.m_pFont.m_pFace;
var _min = 0xFFFF;
var _max = -0xFFFF;
var _max_h = 0;
var _max_h2 = 0;
var _key = fm.m_pFont.m_sFileName + "_teamlab_" + fm.m_pFont.m_lFaceIndex + "_teamlab_" + fm.m_pFont.m_fSize + "_teamlab_" + fm.m_pFont.m_unVerDpi;
if (_maps_cached_height[_key])
return _maps_cached_height[_key];
fm.SetStringGID(true);
for (var i = 0; i < face.num_glyphs; i++)
{
var _s = fm.MeasureChar(i);
if (_s && _s.oBBox)
{
if (_s.oBBox.fMaxY > _max)
_max = _s.oBBox.fMaxY;
if (_s.oBBox.fMinY < _min)
_min = _s.oBBox.fMinY;
if (_s.oMetrics.fHeight > _max_h)
_max_h = _s.oMetrics.fHeight;
var _p = _s.oBBox.fMaxY - _s.oBBox.fMinY + _s.oMetrics.fVertBearingY;
if (_p > _max_h2)
_max_h2 = _p;
}
}
fm.SetStringGID(false);
_maps_cached_height[_key] = { a : _max, d : _min, h : _max_h, h2 : _max_h2 };
return _maps_cached_height[_key];
}
var _maps_cached_height = {};*/
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