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:
parent
44f79edbbb
commit
0e1afd3d5c
@ -3,6 +3,11 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
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
|
## 7.1.1
|
||||||
|
|
||||||
* fixes for `dragstart` event when `Konva.Transformer` is used. `dragstart` event will have correct native `evt` reference
|
* fixes for `dragstart` event when `Konva.Transformer` is used. `dragstart` event will have correct native `evt` reference
|
||||||
|
10
konva.js
10
konva.js
@ -8,7 +8,7 @@
|
|||||||
* Konva JavaScript Framework v7.1.1
|
* Konva JavaScript Framework v7.1.1
|
||||||
* http://konvajs.org/
|
* http://konvajs.org/
|
||||||
* Licensed under the MIT
|
* Licensed under the MIT
|
||||||
* Date: Mon Sep 14 2020
|
* Date: Wed Sep 16 2020
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||||
@ -13716,7 +13716,7 @@
|
|||||||
Text.prototype._setTextData = function () {
|
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(),
|
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(),
|
// 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 = [];
|
this.textArr = [];
|
||||||
getDummyContext$1().font = this._getContextFont();
|
getDummyContext$1().font = this._getContextFont();
|
||||||
var additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
|
var additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
|
||||||
@ -13786,8 +13786,10 @@
|
|||||||
if (!haveSpace) {
|
if (!haveSpace) {
|
||||||
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
|
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
|
||||||
}
|
}
|
||||||
this.textArr.splice(this.textArr.length - 1, 1);
|
if (shouldAddEllipsis) {
|
||||||
this._addTextLine(lastLine.text + ELLIPSIS);
|
this.textArr.splice(this.textArr.length - 1, 1);
|
||||||
|
this._addTextLine(lastLine.text + ELLIPSIS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* stop wrapping if wrapping is disabled or if adding
|
* stop wrapping if wrapping is disabled or if adding
|
||||||
|
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -427,7 +427,7 @@ export class Text extends Shape<TextConfig> {
|
|||||||
// align = this.align(),
|
// align = this.align(),
|
||||||
shouldWrap = wrap !== NONE,
|
shouldWrap = wrap !== NONE,
|
||||||
wrapAtWord = wrap !== CHAR && shouldWrap,
|
wrapAtWord = wrap !== CHAR && shouldWrap,
|
||||||
shouldAddEllipsis = this.ellipsis() && !shouldWrap;
|
shouldAddEllipsis = this.ellipsis();
|
||||||
|
|
||||||
this.textArr = [];
|
this.textArr = [];
|
||||||
getDummyContext().font = this._getContextFont();
|
getDummyContext().font = this._getContextFont();
|
||||||
@ -509,8 +509,10 @@ export class Text extends Shape<TextConfig> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.textArr.splice(this.textArr.length - 1, 1);
|
if (shouldAddEllipsis) {
|
||||||
this._addTextLine(lastLine.text + ELLIPSIS);
|
this.textArr.splice(this.textArr.length - 1, 1);
|
||||||
|
this._addTextLine(lastLine.text + ELLIPSIS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -476,6 +476,28 @@ suite('Text', function () {
|
|||||||
assert.equal(text.textArr[6].text.slice(-1), '…');
|
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 () {
|
test('text multi line with justify align', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
|
@ -627,7 +627,6 @@ suite('TextPath', function () {
|
|||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
var trace = layer.getContext().getTrace();
|
var trace = layer.getContext().getTrace();
|
||||||
console.log(trace);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('visual check for text path', function () {
|
test('visual check for text path', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user