将自定义字体与ezdxf一起使用

2024-06-08 19:31:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用ezdxf在dxf上编写一个带有自定义ttf的文本

我尝试使用doc.styles.new('custom_font', dxfattribs={'font' : 'myFont.ttf'})加载ttf文件(它与我的脚本位于同一个文件夹中),但不起作用

我的代码:

import ezdxf

doc = ezdxf.new('R12', setup=True)
msp = doc.modelspace()

doc.styles.new('custom_style', dxfattribs={'font': 'myFont.ttf'})

text_to_export = ex.text_to_export.text()

msp.add_text(text_to_export,
             dxfattribs={
                  'style': "custom_style",
                  'height': 0.35}
             ).set_pos((2, 6), align='LEFT')

doc.saveas("text.dxf")

Tags: totextdxfnewdocstylecustomexport