Some lint error resolve
This commit is contained in:
Лаврёнов Антон
2014-02-27 08:19:29 +08:00
parent a7ceaa8f24
commit 2757842935
3 changed files with 47 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
(function() { (function() {
var EMPTY_STRING = '', var EMPTY_STRING = '',
CALIBRI = 'Calibri', //CALIBRI = 'Calibri',
NORMAL = 'normal'; NORMAL = 'normal';
/** /**
@@ -176,7 +176,7 @@
return {}; return {};
}; };
var findSegmentToFitCharacter = function(c, before) { var findSegmentToFitCharacter = function(c) {
var glyphWidth = that._getTextSize(c).width; var glyphWidth = that._getTextSize(c).width;
@@ -196,8 +196,9 @@
} }
} }
if(pathCmd === {} || p0 === undefined) if(pathCmd === {} || p0 === undefined) {
return undefined; return undefined;
}
var needNewSegment = false; var needNewSegment = false;
@@ -206,8 +207,9 @@
if(Kinetic.Path.getLineLength(p0.x, p0.y, pathCmd.points[0], pathCmd.points[1]) > glyphWidth) { if(Kinetic.Path.getLineLength(p0.x, p0.y, pathCmd.points[0], pathCmd.points[1]) > glyphWidth) {
p1 = Kinetic.Path.getPointOnLine(glyphWidth, p0.x, p0.y, pathCmd.points[0], pathCmd.points[1], p0.x, p0.y); p1 = Kinetic.Path.getPointOnLine(glyphWidth, p0.x, p0.y, pathCmd.points[0], pathCmd.points[1], p0.x, p0.y);
} }
else else {
pathCmd = undefined; pathCmd = undefined;
}
break; break;
case 'A': case 'A':
@@ -217,13 +219,16 @@
// 5 = dTheta // 5 = dTheta
var end = pathCmd.points[4] + dTheta; var end = pathCmd.points[4] + dTheta;
if(currentT === 0) if(currentT === 0){
currentT = start + 0.00000001; currentT = start + 0.00000001;
}
// Just in case start is 0 // Just in case start is 0
else if(glyphWidth > currLen) else if(glyphWidth > currLen) {
currentT += (Math.PI / 180.0) * dTheta / Math.abs(dTheta); currentT += (Math.PI / 180.0) * dTheta / Math.abs(dTheta);
else }
else {
currentT -= Math.PI / 360.0 * dTheta / Math.abs(dTheta); currentT -= Math.PI / 360.0 * dTheta / Math.abs(dTheta);
}
// Credit for bug fix: @therth https://github.com/ericdrowell/KineticJS/issues/249 // Credit for bug fix: @therth https://github.com/ericdrowell/KineticJS/issues/249
// Old code failed to render text along arc of this path: "M 50 50 a 150 50 0 0 1 250 50 l 50 0" // Old code failed to render text along arc of this path: "M 50 50 a 150 50 0 0 1 250 50 l 50 0"
@@ -235,15 +240,19 @@
break; break;
case 'C': case 'C':
if(currentT === 0) { if(currentT === 0) {
if(glyphWidth > pathCmd.pathLength) if(glyphWidth > pathCmd.pathLength) {
currentT = 0.00000001; currentT = 0.00000001;
else }
else {
currentT = glyphWidth / pathCmd.pathLength; currentT = glyphWidth / pathCmd.pathLength;
}
} }
else if(glyphWidth > currLen) else if(glyphWidth > currLen) {
currentT += (glyphWidth - currLen) / pathCmd.pathLength; currentT += (glyphWidth - currLen) / pathCmd.pathLength;
else }
else {
currentT -= (currLen - glyphWidth) / pathCmd.pathLength; currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
}
if(currentT > 1.0) { if(currentT > 1.0) {
currentT = 1.0; currentT = 1.0;
@@ -252,12 +261,15 @@
p1 = Kinetic.Path.getPointOnCubicBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], pathCmd.points[4], pathCmd.points[5]); p1 = Kinetic.Path.getPointOnCubicBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], pathCmd.points[4], pathCmd.points[5]);
break; break;
case 'Q': case 'Q':
if(currentT === 0) if(currentT === 0) {
currentT = glyphWidth / pathCmd.pathLength; currentT = glyphWidth / pathCmd.pathLength;
else if(glyphWidth > currLen) }
else if(glyphWidth > currLen) {
currentT += (glyphWidth - currLen) / pathCmd.pathLength; currentT += (glyphWidth - currLen) / pathCmd.pathLength;
else }
else {
currentT -= (currLen - glyphWidth) / pathCmd.pathLength; currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
}
if(currentT > 1.0) { if(currentT > 1.0) {
currentT = 1.0; currentT = 1.0;
@@ -283,8 +295,9 @@
// Find p1 such that line segment between p0 and p1 is approx. width of glyph // Find p1 such that line segment between p0 and p1 is approx. width of glyph
findSegmentToFitCharacter(charArr[i]); findSegmentToFitCharacter(charArr[i]);
if(p0 === undefined || p1 === undefined) if(p0 === undefined || p1 === undefined) {
break; break;
}
var width = Kinetic.Path.getLineLength(p0.x, p0.y, p1.x, p1.y); var width = Kinetic.Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
@@ -376,5 +389,5 @@
* @memberof Kinetic.TextPath.prototype * @memberof Kinetic.TextPath.prototype
*/ */
Kinetic.Collection.mapMethods(Kinetic.TextPath); Kinetic.Collection.mapMethods(Kinetic.TextPath);
})(); })();

View File

@@ -267,6 +267,7 @@
} }
} }
this._addTextLine(match, matchWidth); this._addTextLine(match, matchWidth);
textWidth = Math.max(textWidth, matchWidth);
currentHeightPx += lineHeightPx; currentHeightPx += lineHeightPx;
if (!shouldWrap || if (!shouldWrap ||
(fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)) { (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)) {
@@ -284,6 +285,7 @@
// if it does, add the line and break out of the loop // if it does, add the line and break out of the loop
this._addTextLine(line, lineWidth); this._addTextLine(line, lineWidth);
currentHeightPx += lineHeightPx; currentHeightPx += lineHeightPx;
textWidth = Math.max(textWidth, lineWidth);
break; break;
} }
} }
@@ -451,5 +453,5 @@
* text.text('Hello world!'); * text.text('Hello world!');
*/ */
Kinetic.Collection.mapMethods(Kinetic.Text); Kinetic.Collection.mapMethods(Kinetic.Text);
})(); })();

View File

@@ -275,4 +275,19 @@ suite('Text', function(){
assert(text.getHeight() > height, 'height should have increased'); assert(text.getHeight() > height, 'height should have increased');
}); });
test('get text width', function() {
var stage = addStage();
var layer = new Kinetic.Layer();
stage.add(layer);
var text = new Kinetic.Text({
text : 'hello asd fasdf asdf asd fasdf asdfasd fa sds helloo',
fill : 'black',
width: 100
});
layer.add(text);
layer.draw();
assert.equal(text.getTextWidth() > 0 && text.getTextWidth() < 100, true);
});
}); });