Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

center_text=False cuts off text at left when justifying barcode text in SVG output #145

Open
toxicantidote opened this issue Feb 9, 2022 · 3 comments

Comments

@toxicantidote
Copy link

Barcode version: 0.13.1-py3
Python version: 3.7.3 (64 bit)
Platform: Windows 10 (20H2)

If the center_text=False option is used when writing a code128 (and possibly others) barcode in SVG format, the text under the barcode is justified beyond the left of the SVG. It appears that the justification is based on the center of the the SVG text, rather than its left edge.

I am using this in an application that embeds these SVG images within a table in a webpage, and for the same code (97660) they appear as below:
barcode-bug

A simplified extract of the code section being used to generate the SVG is below, however it uses the same writer options as my production code. I suspect that changes to the quiet_zone option are not being accounted for in text positioning.

code = 97660
## imports
import barcode
import io
## make a file-like object to write to
handle = io.BytesIO()
writer = barcode.writer.SVGWriter()
## no doctype, just svg tags
writer.with_doctype = False
## create the barcode
c128 = barcode.get_barcode('code128', str(code), writer = writer)
## render it, saving the data to the file-like object. pass in options
## to specify the sizing and dimensions of the barcode
c128.write(handle, options = {'text_distance': 4.0, 'module_height': 4.0, 'font_size': 8, 'quiet_zone': 1.0, 'module_width': 0.15})
## seek back to the start of the file-like object
handle.seek(0)
## get the binary image data
data = handle.read()
## close the file-like object
handle.close()
## print the SVG data as text
print(data.decode('utf-8', errors = 'ignore'))
@toxicantidote
Copy link
Author

Looked at the code. I see quiet_zone appears to be accounted for after all.

Also in case it's relevant. browser is Chrome.

@WhyNotHugo
Copy link
Owner

Can you try 0.14.0? There were a few fixes related to positioning and sizes in that release.

@toxicantidote
Copy link
Author

I have updated to the 0.14.0 wheel from the releases page and the issue still persists as originally described.

Confirmed barcode.version returns '0.14.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants