首页 > 解决方案 > 通过 ezdxf 使用自定义字体

问题描述

我想使用 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")

标签: pythondxfezdxf

解决方案


推荐阅读