mirror of
https://github.com/konvajs/konva.git
synced 2026-01-09 11:34:38 +08:00
kerning support added
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user