Commit 2a6eb567 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Поправил в значении ячейки наличие повторяющегося символа (баг...

Поправил в значении ячейки наличие повторяющегося символа (баг http://bugzserver/show_bug.cgi?id=18119)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@52040 954022d7-b5bf-4e40-9824-e11837661b57
parent 916e6793
...@@ -609,8 +609,8 @@ ...@@ -609,8 +609,8 @@
} }
// process 'repeat char' marker // process 'repeat char' marker
if (dontCalcRepeatChars && p && p.repeat > 0) { if (dontCalcRepeatChars && p && p.repeat) {
l.tw -= this._calcCharsWidth(i, i + p.repeat - 1); l.tw -= this._calcCharsWidth(i, i + p.total);
} }
// process 'new line' marker // process 'new line' marker
...@@ -631,64 +631,90 @@ ...@@ -631,64 +631,90 @@
return new asc_TM(TW, TH, 0, BL, 0, 0, CL); return new asc_TM(TW, TH, 0, BL, 0, 0, CL);
}, },
_getRepeatCharPos: function () {
var charProp;
for (var i = 0; i < this.chars.length; ++i) {
charProp = this.charProps[i];
if (charProp && charProp.repeat)
return i;
}
return -1;
},
/** /**
* @param {Number} maxWidth * @param {Number} maxWidth
*/ */
_insertRepeatChars: function (maxWidth) { _insertRepeatChars: function (maxWidth) {
var self = this, width, w, pos; var self = this, width, w, pos, charProp;
function getNextRepeatCharsPos(fromPos) { function shiftCharPropsLeft(fromPos, delta) {
for (var i = fromPos; i < self.chars.length; ++i) { // delta - отрицательная
if (self.charProps[i] && self.charProps[i].repeat > 0) {return i;} var length = self.charProps.length;
for (var i = fromPos; i < length; ++i) {
var p = self.charProps[i];
if (p) {
delete self.charProps[i];
self.charProps[i + delta] = p;
}
} }
return -1;
}
function calcRepeatCharsWidth(pos) {
return self._calcCharsWidth(pos, pos + self.charProps[pos].repeat - 1);
} }
function shiftCharProps(fromPos, delta) { function shiftCharPropsRight(fromPos, delta) {
for (var i = self.chars.length - 1; i >= fromPos; --i) { // delta - положительная
if (self.charProps[i]) { for (var i = self.charProps.length - 1; i >= fromPos; --i) {
var p = self.charProps[i]; var p = self.charProps[i];
if (p) {
delete self.charProps[i]; delete self.charProps[i];
self.charProps[i + delta] = p; self.charProps[i + delta] = p;
} }
} }
} }
function insertRepeatChars(pos) { function insertRepeatChars() {
if (self.charProps[pos].total === undefined) { if (0 === charProp.total)
self.charProps[pos].total = self.charProps[pos].repeat; return; // Символ уже изначально лежит в строке и в списке
} else { var repeatEnd = pos + charProp.total;
var repeatCount = self.charProps[pos].repeat, self.chars = "" +
repeatEnd = pos + self.charProps[pos].total; self.chars.slice(0, repeatEnd) +
self.chars = "" + self.chars.slice(pos, pos + 1) +
self.chars.slice(0, repeatEnd) + self.chars.slice(repeatEnd);
self.chars.slice(pos, pos + repeatCount) +
self.chars.slice(repeatEnd); self.charWidths = [].concat(
self.charWidths = [].concat( self.charWidths.slice(0, repeatEnd),
self.charWidths.slice(0, repeatEnd), self.charWidths.slice(pos, pos + 1),
self.charWidths.slice(pos, pos + repeatCount), self.charWidths.slice(repeatEnd));
self.charWidths.slice(repeatEnd));
self.charProps[pos].total += repeatCount; shiftCharPropsRight(pos + 1, 1);
shiftCharProps(pos + 1, repeatCount); }
}
function removeRepeatChar() {
self.chars = "" +
self.chars.slice(0, pos) +
self.chars.slice(pos + 1);
self.charWidths = [].concat(
self.charWidths.slice(0, pos),
self.charWidths.slice(pos + 1));
delete self.charProps[pos];
shiftCharPropsLeft(pos + 1, -1);
} }
width = this._calcTextMetrics(true).width; width = this._calcTextMetrics(true).width;
pos = 0; pos = this._getRepeatCharPos();
if (-1 === pos)
while (1) { return;
do {pos = getNextRepeatCharsPos(pos < 0 ? 0 : pos);} while (pos < 0); w = this._calcCharsWidth(pos, pos);
w = calcRepeatCharsWidth(pos); charProp = this.charProps[pos];
if (w + width > maxWidth) {break;}
insertRepeatChars(pos); while (charProp.total * w + width + w <= maxWidth) {
width += w; insertRepeatChars();
++pos; charProp.total += 1;
} }
if (0 === charProp.total)
removeRepeatChar();
this.lines = []; this.lines = [];
}, },
...@@ -810,7 +836,11 @@ ...@@ -810,7 +836,11 @@
} }
if (fmt.repeat) { if (fmt.repeat) {
charPropAt(pIndex).repeat = text.length; if (hasRepeats)
throw "Repeat should occur no more than once";
charPropAt(pIndex).repeat = true;
charPropAt(pIndex).total = 0;
hasRepeats = true; hasRepeats = true;
} }
......
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