check for parseTags in wrapContent. recenter shrunken elements.

This commit is contained in:
Christopher Jeffrey 2013-06-20 08:12:39 -05:00
parent dc623ee0d1
commit 8a39e9aaf4
1 changed files with 27 additions and 10 deletions

View File

@ -833,7 +833,7 @@ Element.prototype.parseContent = function() {
if (this._clines == null if (this._clines == null
|| this._clines.width !== w || this._clines.width !== w
|| this._clines.content !== this.content) { || this._clines.content !== this.content) {
this._clines = wrapContent(this.content, w, this.align); this._clines = wrapContent(this.content, w, this.parseTags, this.align);
this._pcontent = this._clines.join('\n'); this._pcontent = this._clines.join('\n');
this.emit('parsed content'); this.emit('parsed content');
return true; return true;
@ -1299,7 +1299,9 @@ Box.prototype.render = function(stop) {
if (this.shrink) { if (this.shrink) {
var hw = this._getShrinkSize(content) var hw = this._getShrinkSize(content)
, h = hw.height , h = hw.height
, w = hw.width; , w = hw.width
, xll = xl
, yll = yl;
if (this.options.width == null if (this.options.width == null
&& (this.options.left == null && (this.options.left == null
|| this.options.right == null)) { || this.options.right == null)) {
@ -1321,6 +1323,17 @@ Box.prototype.render = function(stop) {
yl = yi_ + h + (this.border ? 2 : 0) + this.padding; yl = yi_ + h + (this.border ? 2 : 0) + this.padding;
} }
} }
// Recenter shrunken elements.
if (xl < xll && this.options.left === 'center') {
xll = (xll - xl) / 2 | 0;
xi_ += xll;
xl += xll;
}
if (yl < yll && this.options.top === 'center') {
yll = (yll - yl) / 2 | 0;
yi_ += yll;
yl += yll;
}
} }
var ret = this._lastPos = { var ret = this._lastPos = {
@ -2348,7 +2361,7 @@ function sp(line, width, align) {
return line; return line;
} }
function wrapContent(content, width, state) { function wrapContent(content, width, tags, state) {
var lines = content.split('\n') var lines = content.split('\n')
, out = []; , out = [];
@ -2363,14 +2376,18 @@ function wrapContent(content, width, state) {
var align = state var align = state
, cap; , cap;
if (cap = /^{(center|right)}/.exec(line)) { if (tags) {
line = line.substring(cap[0].length); if (cap = /^{(left|center|right)}/.exec(line)) {
align = state = cap[1]; line = line.substring(cap[0].length);
} align = state = cap[1] !== 'left'
? cap[1]
: null;
}
if (cap = /{\/(center|right)}$/.exec(line)) { if (cap = /{\/(left|center|right)}$/.exec(line)) {
line = line.slice(0, -cap[0].length); line = line.slice(0, -cap[0].length);
state = null; state = null;
}
} }
var total var total