ezdxf dxf to png always use a fallback font

64 Views Asked by At

I am using matplotlib and ezdxf to convert a dxf to a png file.

DXF File: https://gist.githubusercontent.com/ru4ert/0f099e0ad5133b36547b5cb6663ed4c5/raw/e7b1c1e1ccba7b7004d6c21c8dcecc04814f0c51/gistfile1.txt

When viewing AutoCAD (viewer.autodesk.com) i get this result:

viewer.autodesk.com

When i call my python fn i get this: python generated

Python code

import matplotlib as mpl
import matplotlib.pyplot as plt
from ezdxf.addons.drawing import RenderContext, Frontend
from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
import matplotlib.font_manager as font_manager
import re

mpl.use('Agg') 

default_img_format = '.png'
default_img_res = 300
default_bg_color = '#FFFFFF'
def convert_dxf2img(dxfFile, imgFormat=default_img_format, imgRes=default_img_res, clr=default_bg_color):
    doc = ezdxf.readfile(dxfFile)
    msp = doc.modelspace()
    auditor = doc.audit()
    if len(auditor.errors) != 0:
        raise Exception("This DXF document is damaged and can't be converted! --> ", dxfFile)
    else :
        fig = plt.figure()
        ax = fig.add_axes([0, 0, 1, 1])
        ctx = RenderContext(doc)
        ctx.set_current_layout(msp)
        ezdxf.addons.drawing.properties.MODEL_SPACE_BG_COLOR = clr
        out = MatplotlibBackend(ax)
        Frontend(ctx, out).draw_layout(msp, finalize=True)
        imgName = re.findall("(\S+)\.",dxfFile)
        fullPath = ''.join(imgName) + imgFormat
        fig.savefig(fullPath, dpi=imgRes)
        return fullPath

font_manager.get_font_names() includes 'Arial' or 'Comic Sans MS'

0

There are 0 best solutions below