1
0
mirror of https://github.com/konvajs/konva.git synced 2025-04-05 20:48:28 +08:00

fix ellipsis for Konva.Text

This commit is contained in:
Anton Lavrenov 2020-09-16 09:55:40 -05:00
parent 44f79edbbb
commit 0e1afd3d5c
6 changed files with 40 additions and 10 deletions

View File

@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 7.1.2
* fix ellipses behavior for `Konva.Text`.
* fix scaled fill pattern for text.
## 7.1.1
* fixes for `dragstart` event when `Konva.Transformer` is used. `dragstart` event will have correct native `evt` reference

View File

@ -8,7 +8,7 @@
* Konva JavaScript Framework v7.1.1
* http://konvajs.org/
* Licensed under the MIT
* Date: Mon Sep 14 2020
* Date: Wed Sep 16 2020
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@ -13716,7 +13716,7 @@
Text.prototype._setTextData = function () {
var lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(),
// align = this.align(),
shouldWrap = wrap !== NONE$1, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis() && !shouldWrap;
shouldWrap = wrap !== NONE$1, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
this.textArr = [];
getDummyContext$1().font = this._getContextFont();
var additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
@ -13786,8 +13786,10 @@
if (!haveSpace) {
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
}
this.textArr.splice(this.textArr.length - 1, 1);
this._addTextLine(lastLine.text + ELLIPSIS);
if (shouldAddEllipsis) {
this.textArr.splice(this.textArr.length - 1, 1);
this._addTextLine(lastLine.text + ELLIPSIS);
}
}
/*
* stop wrapping if wrapping is disabled or if adding

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -427,7 +427,7 @@ export class Text extends Shape<TextConfig> {
// align = this.align(),
shouldWrap = wrap !== NONE,
wrapAtWord = wrap !== CHAR && shouldWrap,
shouldAddEllipsis = this.ellipsis() && !shouldWrap;
shouldAddEllipsis = this.ellipsis();
this.textArr = [];
getDummyContext().font = this._getContextFont();
@ -509,8 +509,10 @@ export class Text extends Shape<TextConfig> {
);
}
this.textArr.splice(this.textArr.length - 1, 1);
this._addTextLine(lastLine.text + ELLIPSIS);
if (shouldAddEllipsis) {
this.textArr.splice(this.textArr.length - 1, 1);
this._addTextLine(lastLine.text + ELLIPSIS);
}
}
/*

View File

@ -476,6 +476,28 @@ suite('Text', function () {
assert.equal(text.textArr[6].text.slice(-1), '…');
});
// ======================================================
test('make sure we respect false for ellipsis', function () {
var stage = addStage();
var layer = new Konva.Layer();
var text = new Konva.Text({
x: 10,
y: 10,
text: 'Hello foo bar',
wrap: 'word',
ellipsis: false,
width: 60,
height: 20,
});
layer.add(text);
stage.add(layer);
assert.equal(text.textArr.length, 1);
assert.equal(text.textArr[0].text, 'Hello foo');
});
// ======================================================
test('text multi line with justify align', function () {
var stage = addStage();

View File

@ -627,7 +627,6 @@ suite('TextPath', function () {
layer.draw();
var trace = layer.getContext().getTrace();
console.log(trace);
});
test('visual check for text path', function () {