Read an existing DXF and change the font using .ttf file. #918
Replies: 2 comments 2 replies
-
First, don't change a global constant. Although Python does not support constants, uppercase variables should be treated as such, I guarantee this code will break in the future. # don't do this
ezdxf.addons.drawing.properties.MODEL_SPACE_BG_COLOR = '#FFFFFF' I'm sure you've seen this example on Stackoverflow and my comment on it is clear: https://stackoverflow.com/questions/63514133/is-there-a-way-to-change-the-background-color-in-ezdxf This section of the documenation shows how to do it right: https://ezdxf.mozman.at/docs/howto/drawing-addon.html#how-to-set-background-and-foreground-colors from ezdxf.addons.drawing.properties import LayoutProperties
# -x-x-x snip -x-x-x-
msp_properties = LayoutProperties.from_layout(msp)
msp_properties.set_colors("#FFFFFF")
out = MatplotlibBackend(ax)
# override the layout properties and render the modelspace
Frontend(ctx, out).draw_layout(
msp,
finalize=True,
layout_properties=msp_properties,
)
fig.savefig(outfile) The first solution to this problem that comes to my mind is to change the font of all text styles: for style in doc.styles:
style.dxf.font = "Arial.ttf" This does not work for font changes by inline code in MTEXT entities. |
Beta Was this translation helpful? Give feedback.
-
Upload DXF files as zip-files and of course, you must use an appropriate font, in this case the unicode font "arialuni.ttf" does the job. For Chinese texts, the font "simsun.ttc" can be used, the ".ttc" extensions is important, at least on my system. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As the title says, I'm simply trying to read an existing dxf and change the font using a custom font and finally render the dxf using matplotlib (to either svg or png). Here's the code I'm using to render that, I'd appretiate any suggestions to solve this problem.
Beta Was this translation helpful? Give feedback.
All reactions