manuelbl / SwissQRBill.NET

.NET library for Swiss QR bill payment slips (aka QR-Rechnung)
MIT License
88 stars 33 forks source link

Swiss cross in QR-code as SVG file as combination of rectangles #46

Closed reureu closed 2 years ago

reureu commented 2 years ago

Hi there,

Apache FOP is unable to properly render the QR-code that SwissQRBill generates as SVG file. This is due to a bug in the AFP renderer of Apache FOP: https://issues.apache.org/jira/browse/FOP-3058

The problem is related to the path of the Swiss cross that SwissQRBill generates.

The cross is described as

<path fill="#FFFFFF" shape-rendering="crispEdges"
d="M63.543,-70.709h3.307v11.024h-3.307zm-3.858,3.858h11.024v3.307h-11.024z"/>

Unfortunately, FOP doesn't interpret this white cross correctly when generating an AFP file, and adds a black square in the middle of the Swiss cross.

Would it be okay to change the way the cross is added to the QR code?

<!-- 2 Rectangles as workaround for Bug in FOP's AFP-Renderer -->
<rect x="59.685" y="-66.85" width="11.024" height="3.307" fill="#FFFFFF"/>
<rect x="63.543" y="-70.709" height="11.024" width="3.307" fill="#FFFFFF"/>

I am fully aware that this would only be a workaround for a bug in a different software library, but it would certainly be much simpler and quicker to implement this workaround in SwissQRBill.

What do you reckon?

Kind regards, Reureu

manuelbl commented 2 years ago

There is no code in this library generating the Swiss cross in SVG directly. Instead, there is general code drawing the Swiss cross and multiple backends for generating SVG, PDF (with multiple PDF libraries), PNG, EMF etc. The common interface is ICanvas.

ICanvas is defined such that AddRectangle doesn't draw an independent rectangle but instead adds a rectangle to a path, which is then stroked or filled. So I'm afraid I can't change it without breaking all the backend implementations.

What's the exact limitation in Apache FOP? Is it the winding direction or the fact that the two rectangles within the same path overlap?

We could possibly change it into a single subpath with 8 explicit points (instead of 2 overlapping subpaths).

reureu commented 2 years ago

Hi @manuelbl ,

Thanks for your reply and your short reaction time!

Yes, the problem is the overlap of the 2 rectangles within the same path.

In other words, the AFP-renderer in FOP does not honour the fill-rule. It seems to assume a fill-rule of kind "evenodd". See here to understand the difference. https://www.w3.org/TR/SVG/painting.html#WindingRule

So, yes, a single subpath with 8 explicit points would probably work. Or perhaps 2 separate paths for the rectangles making up the cross.

Kind regards, Reureu

reureu commented 2 years ago

I would be happy to submit a PR if you're interested.

manuelbl commented 2 years ago

I'm happy to accept a PR.

reureu commented 2 years ago

Is this repo open for pushes?

manuelbl commented 2 years ago

Yes, it is

manuelbl commented 2 years ago

Resolved with version 3.0.3.