mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
937 stars 191 forks source link

Drawing image support #999

Closed mbway closed 11 months ago

mbway commented 11 months ago

This PR adds support for the drawing addon to draw Image entities as requested here

The approach is for the frontend to load the image and apply any effects and clipping paths by altering the pixels of the image (so the image is pre-cropped before it is sent to the backend).

This design allows the backends to be relatively simple: they are given an array containing RGBA pixels (even if the image on disk has no transparency) and a Matrix44 indicating the transform to apply to the image when drawing it.

I have implemented image rendering in Qt and matplotlib and compared to a fairly detailed reference document that a colleague prepared for me.

reference image (created in AutoCAD) image ezdxf matplotlib -> pdf render (with white background / paperspace): image ezdxf Qt viewer: image

So as you can see from the images above, the addon now supports:

I think the support is pretty good and should cover almost all use cases but there are still some things I'm not sure about:

There are some limitations:

mbway commented 11 months ago

I missed that new svg and pdf backends have been added that do not use matplotlib. I'll look into those soon.

btw, this PR includes the reference dxf file and the associated images which comes to ~650KiB. Is that OK or would you prefer if I remove them?

mozman commented 11 months ago

@mbway Thanks for your great work!

A future improvement would be to move the clipping of the image to the designer stage, where the viewport clipping happens. This may allow to clip the images at the viewport borders.

mbway commented 11 months ago

I suppose clipping could be moved entirely to the designer, or it could be done twice, so the frontend clips the image to its boundary and the designer clips to the active viewport (if there is one)? but that's up to you