mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
@@ -1,6 +1,6 @@
|
||||
(function() {
|
||||
var EMPTY_STRING = '',
|
||||
CALIBRI = 'Calibri',
|
||||
//CALIBRI = 'Calibri',
|
||||
NORMAL = 'normal';
|
||||
|
||||
/**
|
||||
@@ -176,7 +176,7 @@
|
||||
|
||||
return {};
|
||||
};
|
||||
var findSegmentToFitCharacter = function(c, before) {
|
||||
var findSegmentToFitCharacter = function(c) {
|
||||
|
||||
var glyphWidth = that._getTextSize(c).width;
|
||||
|
||||
@@ -196,8 +196,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
if(pathCmd === {} || p0 === undefined)
|
||||
if(pathCmd === {} || p0 === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var needNewSegment = false;
|
||||
|
||||
@@ -206,8 +207,9 @@
|
||||
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);
|
||||
}
|
||||
else
|
||||
else {
|
||||
pathCmd = undefined;
|
||||
}
|
||||
break;
|
||||
case 'A':
|
||||
|
||||
@@ -217,13 +219,16 @@
|
||||
// 5 = dTheta
|
||||
var end = pathCmd.points[4] + dTheta;
|
||||
|
||||
if(currentT === 0)
|
||||
if(currentT === 0){
|
||||
currentT = start + 0.00000001;
|
||||
}
|
||||
// Just in case start is 0
|
||||
else if(glyphWidth > currLen)
|
||||
else if(glyphWidth > currLen) {
|
||||
currentT += (Math.PI / 180.0) * dTheta / Math.abs(dTheta);
|
||||
else
|
||||
}
|
||||
else {
|
||||
currentT -= Math.PI / 360.0 * dTheta / Math.abs(dTheta);
|
||||
}
|
||||
|
||||
// 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"
|
||||
@@ -235,15 +240,19 @@
|
||||
break;
|
||||
case 'C':
|
||||
if(currentT === 0) {
|
||||
if(glyphWidth > pathCmd.pathLength)
|
||||
if(glyphWidth > pathCmd.pathLength) {
|
||||
currentT = 0.00000001;
|
||||
else
|
||||
}
|
||||
else {
|
||||
currentT = glyphWidth / pathCmd.pathLength;
|
||||
}
|
||||
}
|
||||
else if(glyphWidth > currLen)
|
||||
else if(glyphWidth > currLen) {
|
||||
currentT += (glyphWidth - currLen) / pathCmd.pathLength;
|
||||
else
|
||||
}
|
||||
else {
|
||||
currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
|
||||
}
|
||||
|
||||
if(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]);
|
||||
break;
|
||||
case 'Q':
|
||||
if(currentT === 0)
|
||||
if(currentT === 0) {
|
||||
currentT = glyphWidth / pathCmd.pathLength;
|
||||
else if(glyphWidth > currLen)
|
||||
}
|
||||
else if(glyphWidth > currLen) {
|
||||
currentT += (glyphWidth - currLen) / pathCmd.pathLength;
|
||||
else
|
||||
}
|
||||
else {
|
||||
currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
|
||||
}
|
||||
|
||||
if(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
|
||||
findSegmentToFitCharacter(charArr[i]);
|
||||
|
||||
if(p0 === undefined || p1 === undefined)
|
||||
if(p0 === undefined || p1 === undefined) {
|
||||
break;
|
||||
}
|
||||
|
||||
var width = Kinetic.Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
|
||||
|
||||
@@ -376,5 +389,5 @@
|
||||
* @memberof Kinetic.TextPath.prototype
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.TextPath);
|
||||
Kinetic.Collection.mapMethods(Kinetic.TextPath);
|
||||
})();
|
||||
|
@@ -267,6 +267,7 @@
|
||||
}
|
||||
}
|
||||
this._addTextLine(match, matchWidth);
|
||||
textWidth = Math.max(textWidth, matchWidth);
|
||||
currentHeightPx += lineHeightPx;
|
||||
if (!shouldWrap ||
|
||||
(fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)) {
|
||||
@@ -284,6 +285,7 @@
|
||||
// if it does, add the line and break out of the loop
|
||||
this._addTextLine(line, lineWidth);
|
||||
currentHeightPx += lineHeightPx;
|
||||
textWidth = Math.max(textWidth, lineWidth);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -451,5 +453,5 @@
|
||||
* text.text('Hello world!');
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Text);
|
||||
Kinetic.Collection.mapMethods(Kinetic.Text);
|
||||
})();
|
||||
|
@@ -275,4 +275,19 @@ suite('Text', function(){
|
||||
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);
|
||||
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user