How to create an Editable Text which is curved along a Path in Fabricjs?

吃可爱长大的小学妹 提交于 2019-12-08 07:53:00

问题


I want to make Editable Text which is curved along a fabric.Path as bellow expected image.


Here is my code:
I created a curved fabric.Path & a fabric.TextBox, but I don't know how to curve text along that Path. Please help me resolve this problem.

var canvasObject = document.getElementById("editorCanvas");
// set canvas equal size with div
$(canvasObject).width($("#canvasContainer").width());
$(canvasObject).height($("#canvasContainer").height());

var canvas = new fabric.Canvas('editorCanvas', {
  selectionLineWidth: 2,
  width: $("#canvasContainer").width(),
  height: $("#canvasContainer").height()
});

var Path_0_1 = new fabric.Path('M127.91,99.29c32.16,10.73,53.41,7.33,67.81,0 c34.07-17.34,41.99-62.82,60.98-60.98c8.19,0.79,14.11,9.98,17.91,17.91', {
  fill : null,
  stroke: '#000000',
});
canvas.add(Path_0_1);

var curvedText = new fabric.IText("Anh Minh", {
  left: 50, 
  top: 50, 
  width: 200, 
  fontSize: 24, 
  fontFamily: 'Times New Roman', 
  fontWeight: 'normal', 
  textAlign: 'center',
  lineHeight: 1,
  fill: "#404041",
});
canvas.add(curvedText);
#canvasContainer {
  width: 100%;
  height: 500px;
}
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.3/fabric.js"></script>
  
<div id="canvasContainer">
  <canvas id="editorCanvas"></canvas>
</div>



Addition information:
After few hours google search, I see an interesting Konva.TextPath, I wonder If can we make same Object like that Konva.TextPath in Fabric.js?

Thank you!

来源:https://stackoverflow.com/questions/55531132/how-to-create-an-editable-text-which-is-curved-along-a-path-in-fabricjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!