这个问题听起来可能很愚蠢,但我无法自己找到正确的答案。
我正在尝试在 python 脚本中使用 SVG DOM 接口。我想使用 getCompulatedTextLength 但我找不到即使我首先认为它可以通过模块或像 python-svg 或类似的东西的包来使用。
我确信我错过了什么,但我找不到什么。
任何帮助将不胜感激。
谢谢。
编辑:我忘记谈论我的脚本实际上做了什么。它是一个 Python 脚本,用于从互联网上抓取的数据生成 SVG 文件。我的脚本需要编写文本并沿着一条路径重复它们。另外,因为我知道路径的确切长度(以像素为单位),所以我需要知道文本的长度,以便仅重复我需要的内容。这就是为什么像 getCompulatedTextLength 这样的方法会很有帮助。
This question may sounds dumb, but I can't manage to find a correct answer on my own.
I am trying to use the SVG DOM interface in my python script. I would like to use getComputedTextLength but I can't find how even if I firstly thought it would be available thanks to modules or a packages like python-svg or something like that.
I am sure there is something I miss, but I can't find what.
Any help would be appreciated.
Thank you.
EDIT: I forgot to talk about what my script actually does. It's a Python script used to generate a SVG file from data grabbed on the Internet. My script needs to write texts and repeat them all along a path. Also, as I know the exact length (in pixels) of the path I need to know the length of the text in order to repeat it only what I need to. That's why a method like getComputedTextLength would be helpful.
发布评论
评论(2)
试试这个: http://www.gnu.org/software/pythonwebkit/
Try this: http://www.gnu.org/software/pythonwebkit/
我认为这是不可能的。 DOM 是一回事,调用浏览器的函数是另一回事。我只看到 Python 模块可以帮助您创建 HTML 或 SVG 等树结构,但它们不提供任何其他附加功能。 (顺便说一句,上次我什至看到浏览器在正确计算
getCompulatedTextLength
时出现问题,但那是前一段时间了......)您可以尝试使用 fonttools。
I don't think this is possible. DOM is one thing and calling browser's function is other thing. I only saw Python module which help you to create tree structures like HTML or SVG but they don't provide any other additional functionality. (Btw., last time I look even browsers had problems correctly computing
getComputedTextLength
but that was some time ago...)You could try better luck with fonttools.