mirror of
https://github.com/konvajs/konva.git
synced 2025-10-20 19:01:04 +08:00
Better TextPath
hit function
This commit is contained in:
@@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Not released][Not released]
|
||||
|
||||
## [1.1.2][2016-09-12]
|
||||
|
||||
### Changed
|
||||
- Better hit function for `TextPath`.
|
||||
- Validation of `Shape` filters.
|
||||
|
||||
## [1.1.2][2016-09-10]
|
||||
|
||||
### Fixed
|
||||
|
3
konva.js
3
konva.js
@@ -15013,6 +15013,7 @@
|
||||
this.dataArray = Konva.Path.parsePathData(this.attrs.data);
|
||||
this.on('dataChange.konva', function() {
|
||||
that.dataArray = Konva.Path.parsePathData(this.attrs.data);
|
||||
that._setTextData();
|
||||
});
|
||||
|
||||
// update text data for certain attr changes
|
||||
@@ -15102,7 +15103,7 @@
|
||||
|
||||
this.glyphInfo = [];
|
||||
|
||||
var charArr = this.attrs.text.split('');
|
||||
var charArr = this.getText().split('');
|
||||
|
||||
var p0, p1, pathCmd;
|
||||
|
||||
|
2
konva.min.js
vendored
2
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -62,12 +62,14 @@
|
||||
this.dataArray = Konva.Path.parsePathData(this.attrs.data);
|
||||
this.on('dataChange.konva', function() {
|
||||
that.dataArray = Konva.Path.parsePathData(this.attrs.data);
|
||||
that._setTextData();
|
||||
});
|
||||
|
||||
// update text data for certain attr changes
|
||||
this.on('textChange.konva textStroke.konva textStrokeWidth.konva', that._setTextData);
|
||||
that._setTextData();
|
||||
this.sceneFunc(this._sceneFunc);
|
||||
this.hitFunc(this._hitFunc);
|
||||
},
|
||||
_sceneFunc: function(context) {
|
||||
context.setAttr('font', this._getContextFont());
|
||||
@@ -101,6 +103,22 @@
|
||||
}
|
||||
context.restore();
|
||||
},
|
||||
_hitFunc: function(context) {
|
||||
context.beginPath();
|
||||
|
||||
var glyphInfo = this.glyphInfo;
|
||||
if (glyphInfo.length >= 1) {
|
||||
var p0 = glyphInfo[0].p0;
|
||||
context.moveTo(p0.x, p0.y);
|
||||
}
|
||||
for(var i = 0; i < glyphInfo.length; i++) {
|
||||
var p1 = glyphInfo[i].p1;
|
||||
context.lineTo(p1.x, p1.y);
|
||||
}
|
||||
context.setAttr('lineWidth', this.getFontSize());
|
||||
context.setAttr('strokeStyle', this.colorKey);
|
||||
context.stroke();
|
||||
},
|
||||
/**
|
||||
* get text width in pixels
|
||||
* @method
|
||||
@@ -151,7 +169,7 @@
|
||||
|
||||
this.glyphInfo = [];
|
||||
|
||||
var charArr = this.attrs.text.split('');
|
||||
var charArr = this.getText().split('');
|
||||
|
||||
var p0, p1, pathCmd;
|
||||
|
||||
|
@@ -190,7 +190,7 @@ suite('TextPath', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('Render Text Along complex path cached', function() {
|
||||
test.only('Render Text Along complex path cached', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
|
Reference in New Issue
Block a user