Draw text along the bezier curve in paper.js

我的梦境 提交于 2019-12-03 03:41:40

We haven't implement text along path in Paper.js yet. At the moment, text support is rather rudimentary, but this will hopefully change soon once we have rolled out version 1.0 of the library.

As mentioned in the previous answer, PaperJS does not offer this functionality out of the box. But You can achieve the effect with very little effort.

Here is how to proceed:

  1. Get the offset to the x-center of each glyph in the text. This can be done by using the width of a PointText for the substring until the glyph.
  2. Find the point for the offset on the path that you want your text to align to.
  3. Place the single centered glyph at the just found point. Rotate the glph by the path's tangent angle.

Here is the Paper Sketch: Align Text to Path Sketch

And here is the result of a simple test:

You can move the PointText objects of the glyphs along the y-axis before applying the rotation to achieve the offset from the path (like the red text in your example).

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