kerning support added

This commit is contained in:
eugenesqr
2018-02-07 18:06:07 +03:00
parent 52f1b91387
commit 091ee2d75c
3 changed files with 31 additions and 13 deletions

View File

@@ -46,6 +46,7 @@
var that = this;
this.dummyCanvas = Konva.Util.createCanvasElement();
this.dataArray = [];
this.getKerning = config.getKerning;
// call super constructor
Konva.Shape.call(this, config);
@@ -429,11 +430,19 @@
var width = Konva.Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
// Note: Since glyphs are rendered one at a time, any kerning pair data built into the font will not be used.
// Can foresee having a rough pair table built in that the developer can override as needed.
var kern = 0;
// placeholder for future implementation
if (this.getKerning) {
try {
// getKerning is a user provided getter. Make sure it never breaks our logic
kern = this.getKerning(charArr[i - 1], charArr[i]) * this.fontSize();
}
catch(e) {
kern = 0;
}
}
p0.x += kern;
p1.x += kern;
var midpoint = Konva.Path.getPointOnLine(
kern + width / 2.0,