fix: add ellipsis for last line

This commit is contained in:
gloryyin
2022-08-01 02:09:00 +08:00
parent 54964ba37d
commit 40267e0d44
2 changed files with 94 additions and 20 deletions

View File

@@ -487,6 +487,39 @@ describe('Text', function () {
}
});
// ======================================================
it('multiline with ellipsis and lineWidth less than maxWidth', function () {
var stage = addStage();
var layer = new Konva.Layer();
var text = new Konva.Text({
x: 10,
y: 10,
text: "HEADING\nAll the\n world's a stage, merely players. They have theirrrrrrr exits and theirrrrr entrances; And one man in his time plays many parts.",
fontSize: 14,
fontFamily: 'Arial',
fontStyle: 'normal',
width: 100,
padding: 0,
align: 'center',
height: 30,
ellipsis: true,
});
layer.add(text);
stage.add(layer);
assert.equal(text.textArr.length, 2);
assert.equal(text.textArr[1].text.slice(-1), '…');
if (isBrowser) {
assert.equal(
layer.getContext().getTrace(false, true),
"clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);font=normal normal 14px Arial;textBaseline=middle;textAlign=left;translate(0,0);save();fillStyle=black;fillText(HEADING,18,7);restore();save();fillStyle=black;fillText(All the…,23,21);restore();restore();"
);
}
});
// ======================================================
it('make sure we respect false for ellipsis', function () {
var stage = addStage();