Curved Text side
by Steve Eberhardt
HTML
<script src="https://rawgit.com/fabricjs/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width="600" height="400"></canvas>
CSS
canvas {
border: 1px solid #999;
}
JavaScript
var canvas = new fabric.Canvas('c');
var path = new fabric.Path("M 50 0 a 50 100 0 1 1 1 0 Z", {
strokeWidth: 2,
stroke: 'red',
left: 100,
top: 100,
fill: 'transparent'
});
var path2 = new fabric.Path('M 0 0 l 10 0 l 20 0 l 30 0 l 40 0 l 50 0 l 60 0', {
strokeWidth: 2,
stroke: 'red',
left: 300,
top: 100,
fill: 'transparent'
});
var text = new fabric.Text('One Ring to rule them all, one ring to find them', {
path: path,
fontSize: 24,
left: 100,
top: 100,
textAlign: 'center',
charSpacing: -20,
padding: 20,
startOffset: -40,
side: "right"
});
var text2 = new fabric.Text('One Ring to ', {
path: path2,
fontSize: 30,
left: 300,
top: 100,
startOffset: 0,
charSpacing: 0,
padding: 20,
//startOffset: -90,
startOffset: 105,
side: "right"
});
canvas.add(path);
canvas.add(text);
canvas.add(path2);
canvas.add(text2);
fabric.Text.prototype._measureLine = function(lineIndex) {
var width = 0, i, grapheme, line = this._textLines[lineIndex], prevGrapheme,
graphemeInfo, numOfSpaces = 0, lineBounds = new Array(line.length),
positionInPath = 0, startingPoint, totalPathLength, path = this.path;
this.__charBounds[lineIndex] = lineBounds;
if (path) {
startingPoint = fabric.util.getPointOnPath(path.path, 0, path.segmentsInfo);
totalPathLength = path.segmentsInfo[path.segmentsInfo.length - 1].length;
startingPoint.x += path.pathOffset.x;
startingPoint.y += path.pathOffset.y;
if(this.textAlign == "center" || this.textAlign == "right") {
for (i = 0; i < line.length; i++) {
grapheme = line[i];
graphemeInfo = this._getGraphemeBox(grapheme, lineIndex, i, prevGrapheme);
lineBounds[i] = graphemeInfo;
width += graphemeInfo.kernedWidth;
prevGrapheme = grapheme;
}
//width = this.getLineWidth(0);
switch(this.textAlign) {
case...