Closed gabrielronai closed 3 years ago
this is strange, because as you can see from these images: https://github.com/mozman/ezdxf/pull/447, color 50 is solid yellow and ezdxf does display this color correctly. It looks to me like the hatch has some transparency to it? if I take solid yellow and overlay it onto the modelspace background color at 60% opacity I get this color which is close to that of the hatch: it's not exactly the same though. I don't know how else to explain the difference
@mbway Thank you. Opening the input in Autocad and editing the B character hatch looks like this. The color is correct, fill=solid and transparency is 0.
I have also looped all HATCH entities in draw_cad.py
before passing starting the render and made sure the transparency is set to 0. Additionally, I verified the fill for each HATCH entity:
[..readfile & auditor..]
for e in doc.modelspace().query('HATCH'):
e.transparency = 1
if e.has_solid_fill == True:
print(f'has solid fill')
fig: plt.Figure = plt.figure(args.dpi)
ax: plt.Axes = fig.add_axes([0, 0, 1, 1])
ax.margins(0)
ctx = RenderContext(doc)
I checked and sure enough in MatplotlibBackend.draw_filled_paths
there is transparency. I forgot that the frontend is instructed to add transparency to all hatches. This is because most hatches are not solid and before patterns were supported it made sense to add some transparency so that the images looked closer to how they would in AutoCAD.
To remove this feature, create a custom frontend like:
class MyFrontend(Frontend):
def override_properties(self, entity: DXFGraphic, properties: Properties) -> None:
pass
maybe the default override_properties
should do nothing now that rendering is more accurate @mozman ?
Thank you!
The custom frontend class fixed all colors except black (250) also mentioned in #447.
The output of draw_cad.py
is in foreground, Autocad in the back.
Here draw_cad.py
is above.
In BricsCAD the ACI color 250 is not black:
In AutoCAD it is black:
In ezdxf view ...
it is black by the default model space palette:
Also in ezdxf draw ...
:
Do you override the default color palette?
Setting the hatch color as true color value is maybe the safest way to get the color you really want, setting hatch.rgb = (0, 0, 0)
for the middle square, gets the correct result also in BricsCAD:
@mozman @mbway Using RGB tuples instead of the ACAD index for the HATCH entities in the input DXF fixed all the colors and the PDF looks great. Thank you for your assistance!
I am experiencing this issue when converting DXF files to PDF or image formats with the drawing add-on. The colors in the output are different from the original.
Additional info: The input DXF is first created with ezdxf using the importer add-on, all colors are referenced by Autocad index, all HATCH are filled with solid. I am using Matplotlib 3.4.2 and ezdxf 0.16.3 both installed with pip under Python 3.9.2 on Windows 10. Tried pdf, jpg, png, eps outputs, all show the same color mismatch. According to the drawing add-on docs, the RenderContext uses the same palette as AutoCAD by default.
Steps I took:
python examples/addons/drawing/draw_cad.py input.dxf --out=output.pdf
Attachment includes input, outputs in different formats and a screenshot with the correct colors from Autocad LT 2021. ezdxf-hatch-color-mismatch.zip