Adding textpath to group shifts layer and group positions in version 4.7.0
Hi Eric, There seems to be something fishy going with text handling in new version. When adding textpath elements to a group the layer seems to shift and shows the old remains in the "shift area". There is a simplified code in jsfiddle http://jsfiddle.net/hakhak/zfW3z/. If one adds only one textpath in the end everything seems to be ok but adding next ones causes the problem. I could get the same problem also with mousein/mouseout events etc. to the main group but I think the cause must be from same origin. Also the texts should be at the same position. The previous version produced right result as can be seen when changing kinetic-v4.7.0.min.js to kinetic-v4.6.0.min.js in the code
Also below is the code if jsfiddle is not available
window.stage = new Kinetic.Stage({
container: 'canvasDiv',
width: 400,
height: 400,
draggable: false
});
window.layer = new Kinetic.Layer();
window.stage.add(window.layer);
var mrect = new Kinetic.Rect({
x: 0,
y: 0,
width: 400,
height: 400,
stroke: "#888",
strokeWidth: 2,
name: 'mainrect',
});
window.layer.add(mrect);
window.stage.draw();
var textGroup = new Kinetic.Group({
x: 40,
y: 40,
draggable: true
});
window.layer.add(textGroup);
var complexText = new Kinetic.TextPath({
x: 0,
y: 0,
text: "test",
fontSize: 10,
fontFamily: 'Arial',
fontStyle: 'normal',
listening: false,
fill: '#000000',
data: "M0,0 L2024,0 Z"
});
textGroup.add(complexText);
window.layer.draw();
var complexText2 = new Kinetic.TextPath({
x: 0,
y: 0,
text: "test2",
fontSize: 10,
fontFamily: 'Arial',
fontStyle: 'normal',
listening: false,
fill: '#000000',
data: "M0,0 L2024,0 Z"
});
textGroup.add(complexText2);
window.layer.draw();
Note: It's the layer.draw() that is causing the offset issue, not the inclusion of additional textpath elements in the group.
http://jsfiddle.net/BBWE3/5/
Eric: Looks like there's an extra context save() that is not being restored when you look at the trace:
{ "property": "textAlign", "val": "left" }, { "method": "save", "args": [] }, { "method": "save", "args": [] },
just to clarify, this does appear to be related to TextPath specifically. If you just use Text, everything works correctly:
http://jsfiddle.net/BaTxP/
You mentioned that there may be missing restores, so I'll check out the TextPath draw func. Also, you use layer.getContext().getTrace() if you want to see strict trace string, or layer.getContext().getTrace(true) for the relaxed trace string
fixed. You were right Jason, somehow I deleted a restore() from the text path draw func. Fixed it up, and added a test that uses the new nifty context trace :)