WhyNotHugo / python-barcode

㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.
http://python-barcode.rtfd.io/
MIT License
572 stars 123 forks source link

Text placement in ImageWriter #177

Open tytouf opened 2 years ago

tytouf commented 2 years ago

I believe text is incorrectly located in barcode when using ImageWriter as of 0.14.0. This is mainly due to a wrong computation of text height which is a very common problem due to the fact that total height for a font is different from the height of rendered glyphs for most of the ascii characters.

Attached is a proposed patch to place text correctly. Note that because most of the time a barcode is followed by a text with capital letters, the blank space at the bottom is more that 1mm (which would be nice to set as an option). It should be closer to 1mm when using letters that goes below the font baseline ('p', 'q', etc).

text_placement.patch.txt

WhyNotHugo commented 2 years ago

There have been changes to how text is aligned and how it's size is calculated since 0.14. Do you still have the same issue on main?

See https://github.com/WhyNotHugo/python-barcode/pull/165 for discussion on this.

tytouf commented 2 years ago

I didn't test with the source but it should be equivalent.