曲线上的字母间距 SVG 使用 D3 使字母倾斜

发布于 2025-01-15 08:06:28 字数 1360 浏览 4 评论 0原文

当我将 letter-spacing 样式添加到 D3 中路径上的文本时,它会倾斜字母,并且它们不再很好地遵循圆圈(请参见图像 2 上突出显示的字母)

在此处输入图像描述 输入图片这里的描述

你可以看到我的此笔记本中的 D3 代码

我尝试在 InkScape 中执行此操作,看起来它以不同的方式处理字母间距(参见图 3)

在此处输入图像描述

inkscape 中文本的样式is

font-size:17.6389px;line-height:1.25;text-align:center;text-decoration-color:#000000;letter-spacing:5.29167px;writing-mode:vertical-lr;text-anchor:middle;white-space:pre;fill:#990000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3.77953;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers;stop-color:#000000

和 textPath is

font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:17.6389px;font-family:Arial;-inkscape-font-specification:Arial

我尝试使用其中一些属性,但在 D3 中无法获得相同的结果。我希望字母像 InkScape 中那样直,

谢谢您的帮助。

When I add letter-spacing style to my text on path in D3, it tilts the letters and they don't follow nicely the circle anymore (see highlighted letters on image 2)

enter image description here
enter image description here

You can see my D3 code in this notebook

I've tried to do it in InkScape and it looks like it handles the letter-spacing differently (see image 3)

enter image description here

The style in the inkscape for the text is

font-size:17.6389px;line-height:1.25;text-align:center;text-decoration-color:#000000;letter-spacing:5.29167px;writing-mode:vertical-lr;text-anchor:middle;white-space:pre;fill:#990000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3.77953;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers;stop-color:#000000

and for textPath is

font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:17.6389px;font-family:Arial;-inkscape-font-specification:Arial

I've tried to use some of these attributes, but I cannot get the same result in D3. I would like the letters to be straight as in InkScape

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九歌凝 2025-01-22 08:06:28

使用要对称倾斜的 letter-spacing 属性可能无法将字母居中。

我最终创建了一个函数,在每个字符之间添加不可破坏的空格 d.data.split("").join("\xa0".repeat(d.space)) 其中 d.data 是文本,d.space 是每个字母之间的空格数。现在这对我来说很好,并给出以下结果。

输入图片此处描述

It might be impossible to center the letter with the letter-spacing attribute to be tilted symetrically.

I ended up creating a function that add non-breakable spaces between every character d.data.split("").join("\xa0".repeat(d.space)) where d.data is the text and d.space is the number of spaces inbetween every letter. This is just good for me now and give the following result.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文