[Bug 40473] New: X scale for Code39 barcodes is calculated incorrectly
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Bug ID: 40473 Summary: X scale for Code39 barcodes is calculated incorrectly Change sponsored?: --- Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Label/patron card printing Assignee: cnighswonger@foundations.edu Reporter: dcook@prosentient.com.au QA Contact: testopia@bugs.koha-community.org While reviewing how "Barcode width" works as added by bug 10762, I noticed that the calculation of the X scale factor for Code39 barcodes is incorrect. If you specify a Barcode width of 1, you'd expect that to use 100% of the label width. But it doesn't. Now this isn't a problem introduced by Bug 10762, because Bug 10762 just replaced a hard-coded value of .8 with a editable value. It's a much older bug. Consider the following: $x_scale_factor = ( $params{'width'} / $tot_bar_length ); $params{'width'} is the "Barcode width" multiplied by the label width. This makes sense as it represents the total width that we're willing to use. The problem is $tot_bar_length. It uses an algorithm which is inconsistent with the algorithm used by PDF::Reuse::Barcode. But that's easy to fix! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #1 from David Cook <dcook@prosentient.com.au> --- In PDF::Reuse::Barcode, the barcode is actually rendered on top of a white background, and that white background is calculated using this code: $length = 20 + (length($sPtn) * 0.9); 20 is an arbitrary number chosen by the creator of PDF::Reuse::Barcode to add padding around the barcode. Now $sPtn is the output of the following: my $oGDBar = GD::Barcode::Code39->new($value); $sPtn = $oGDBar->barcode(); Consider you have the Koha item barcode 39999000001310 The $sPtn will contain the following: 1000101110111010111011100010101010111000101110101011100010111010101110001011101010111000101110101010001110111010101000111011101010100011101110101010001110111010101000111011101011101000101011101110111000101010111010001010111010100011101110101000101110111010 When we use this calculation from PDF::Reuse::Barcode in Koha to calculate the barcode length, we get the *real* length of the barcode. With this patched, if we use a "Barcode width" of "1", the barcode plus its white barcode box background will take up 100% of the label. Thanks to that 20 point padding, we'll have some whitespace on the left and right sides of the barcode. When using a "Barcode with" of 1, you get a perfectly centered barcode as well. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #2 from David Cook <dcook@prosentient.com.au> --- Note: if you use a Barcode width of .8, you do not get a centered barcode, but that's the status quo. That's how it is in main anyway. I'll raise a different bug report for that... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|X scale for Code39 barcodes |X scale for Code39 barcodes |is calculated incorrectly |is calculated incorrectly | |when generating barcode | |labels -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #3 from David Cook <dcook@prosentient.com.au> --- The difference becomes even more obvious when you use "Code39 + Modulo43" or "Code39 + Modulo10". -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #4 from David Cook <dcook@prosentient.com.au> --- Created attachment 184529 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=184529&action=edit Bug 40473: Use better algorithm for calculating Code39 barcode length This patch uses the PDF::Reuse::Barcode algorithm for calculating barcode background box length relative to barcode length in order to determine the actual barcode width and thus the X scale factor required to re-size that barcode so that it fits on the label width (or rather the "Barcode width" which is a percentage applied to the label width to create a narrower usable surface for the barcode and barcode background box). To test: 0. Apply the patch 1. Go to http://localhost:8081/cgi-bin/koha/cataloguing/additem.pl?biblionumber=29 2. Add an item with barcode 123456, add an item with barcode 39999000001310399991, and ensure an item with barcode 39999000001310 already exists 3. Go to http://localhost:8081/cgi-bin/koha/labels/label-manage.pl?label_element=batc... 4. Create a patch that uses 3 items using 39999000001310, 2 items with 123456, and 2 items with 39999000001310399991 4. Go to http://localhost:8081/cgi-bin/koha/labels/label-manage.pl?label_element=layo... 5. Edit the layout "Label Test" 6. Change the "Barcode width" to 1, and enable "Draw guide boxes", and click "Save" 7. Export the batch using the template "Avery 5160 | 1 x 2-5/8" and the layout "Label Test" and open as PDF 8. Note that the whole barcode fits inside the red guidebox (there should be some overlap of white on top of the red guidebox but that is normal since we're using 100% of the barcode label width). 9. Edit the "Label Test" layout to try "Code39 + Modulo43" and "Code39 + Modulo10" and retry batch export 10. Edit the "Label Test" and try different "Barcode width" like the usual default .8 11. Celebrate that your barcodes fit on the label! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=10762 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|cnighswonger@foundations.ed |dcook@prosentient.com.au |u | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #184529|0 |1 is obsolete| | --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 186907 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=186907&action=edit Bug 40473: Use better algorithm for calculating Code39 barcode length This patch uses the PDF::Reuse::Barcode algorithm for calculating barcode background box length relative to barcode length in order to determine the actual barcode width and thus the X scale factor required to re-size that barcode so that it fits on the label width (or rather the "Barcode width" which is a percentage applied to the label width to create a narrower usable surface for the barcode and barcode background box). To test: 0. Apply the patch 1. Go to http://localhost:8081/cgi-bin/koha/cataloguing/additem.pl?biblionumber=29 2. Add an item with barcode 123456, add an item with barcode 39999000001310399991, and ensure an item with barcode 39999000001310 already exists 3. Go to http://localhost:8081/cgi-bin/koha/labels/label-manage.pl?label_element=batc... 4. Create a patch that uses 3 items using 39999000001310, 2 items with 123456, and 2 items with 39999000001310399991 4. Go to http://localhost:8081/cgi-bin/koha/labels/label-manage.pl?label_element=layo... 5. Edit the layout "Label Test" 6. Change the "Barcode width" to 1, and enable "Draw guide boxes", and click "Save" 7. Export the batch using the template "Avery 5160 | 1 x 2-5/8" and the layout "Label Test" and open as PDF 8. Note that the whole barcode fits inside the red guidebox (there should be some overlap of white on top of the red guidebox but that is normal since we're using 100% of the barcode label width). 9. Edit the "Label Test" layout to try "Code39 + Modulo43" and "Code39 + Modulo10" and retry batch export 10. Edit the "Label Test" and try different "Barcode width" like the usual default .8 11. Celebrate that your barcodes fit on the label! Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |martin.renvoize@openfifth.c |y.org |o.uk CC| |martin.renvoize@openfifth.c | |o.uk -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA --- Comment #6 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- This is a solid improvement. The dependency added is already a dependency of modules so we don't need to add it explicitly here. I'm happy to fast QA this one. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=40478 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to main Version(s)| |25.11.00 released in| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #7 from Lucas Gass (lukeg) <lucas@bywatersolutions.com> --- Nice work everyone! Pushed to main for 25.11 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)|25.11.00 |25.11.00,25.05.05 released in| | Status|Pushed to main |Pushed to stable -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #8 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Nice work everyone! Pushed to 25.05.x -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Fridolin Somers <fridolin.somers@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fridolin.somers@biblibre.co | |m --- Comment #9 from Fridolin Somers <fridolin.somers@biblibre.com> --- GD::Barcode::Code39 is a new dependency ? We currently have : cpanfile:requires 'GD::Barcode::UPCE', '1.1'; -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #10 from Fridolin Somers <fridolin.somers@biblibre.com> --- (In reply to Martin Renvoize (ashimema) from comment #6)
This is a solid improvement. The dependency added is already a dependency of modules so we don't need to add it explicitly here.
I'm happy to fast QA this one.
Ah OK no worries :D -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |baptiste.wojtkowski@biblibr | |e.com Version(s)|25.11.00,25.05.05 |25.11.00,25.05.05,24.11.11 released in| | Status|Pushed to stable |Pushed to oldstable --- Comment #11 from Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski@biblibre.com> --- Pushed into 24.11.x for 24.11.11 nice work everyone -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 --- Comment #12 from David Cook <dcook@prosentient.com.au> --- (In reply to Fridolin Somers from comment #9)
GD::Barcode::Code39 is a new dependency ?
We currently have : cpanfile:requires 'GD::Barcode::UPCE', '1.1';
Hmmm that's actually an interesting question. In debian/control, we specify libgd-barcode-perl which is correct. It contains the submodules QRcode, UPCE, Code39, etc. But then in cpanfile we have individual submodules listed: requires 'GD::Barcode::QRcode', '2.01'; requires 'GD::Barcode::UPCE', '1.1'; That should probably just say this: requires 'GD::Barcode', '2.01'; I think out of scope for this bug report, but maybe worth raising as a separate report? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40473 Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to oldstable |Needs documenting --- Comment #13 from Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz> --- Not backporting to 22.11.x as it wasn't backported to 24.05.x -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org