Bug 34732 - Barcode image generator doesn't generate correct Code39 barcode
Summary: Barcode image generator doesn't generate correct Code39 barcode
Status: Pushed to oldstable
Alias: None
Product: Koha
Classification: Unclassified
Component: Tools (show other bugs)
Version: 23.05
Hardware: All All
: P5 - low normal (vote)
Assignee: David Cook
QA Contact: Victor Grousset/tuxayo
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-06 20:42 UTC by Kevin Furst
Modified: 2023-10-12 16:11 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.04,22.11.11


Attachments
Code39 Examples (40.24 KB, image/jpeg)
2023-09-06 20:42 UTC, Kevin Furst
Details
Label creator and barcode generator create different barcodes (29.28 KB, image/jpeg)
2023-09-06 23:27 UTC, David Cook
Details
Bug 34732: For Code39, append or prepend asterisk if missing from barcode (1.53 KB, patch)
2023-09-08 02:22 UTC, David Cook
Details | Diff | Splinter Review
Bug 34732: For Code39, append or prepend asterisk if missing from barcode (1.61 KB, patch)
2023-09-08 10:07 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 34732: For Code39, append or prepend asterisk if missing from barcode (1.65 KB, patch)
2023-09-15 18:37 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 34732: (QA follow-up): tidy up code (723 bytes, patch)
2023-09-15 18:37 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Furst 2023-09-06 20:42:17 UTC
Created attachment 155281 [details]
Code39 Examples

When using the barcode generator tool in Koha with the code39 settings, the barcode image it generates is not a code39 barcode and thus can't be read by our book scanners at checkout desks. I'm not sure what type of barcode it is but the generated image does not have the telltale opening and closing lines of a code39. 

I've attached two screenshots. The first is from the Koha tool with the non-working barcode. 

The second is from another barcode generating tool that makes a barcode exactly the same as the one on the book I have (already in the catalog). 

The number it is using is 34517100048832

We're new to Koha so this has been happening since we started using it this summer. Expected behavior would be for it to generate the correct barcode image for a code39 barcode.
Comment 1 David Cook 2023-09-06 23:27:39 UTC
Created attachment 155282 [details]
Label creator and barcode generator create different barcodes
Comment 2 David Cook 2023-09-06 23:30:57 UTC
Thanks for the report, Kevin.

I've been using Koha for over 11 years and this is the first time I've actually noticed the "Barcode image generator" tool. I typically use the "Label creator" and have had no issues with it in the past.

But it looks like you're right. I've attached a screenshot comparing the two tools, and it looks like the "Barcode image generator" is missing some of the start and end of the barcode.

I'll take a quick look and see if I can find anything obvious...
Comment 3 David Cook 2023-09-06 23:33:34 UTC
(In reply to David Cook from comment #2)
> I've been using Koha for over 11 years and this is the first time I've
> actually noticed the "Barcode image generator" tool. I typically use the
> "Label creator" and have had no issues with it in the past.

Looks like the tool was added in Koha 22.05 so quite a recent feature, although the underlying barcode generation is much older, and I am sure I've used it for other things...
Comment 4 David Cook 2023-09-06 23:53:41 UTC
(In reply to David Cook from comment #2)
> But it looks like you're right. I've attached a screenshot comparing the two
> tools, and it looks like the "Barcode image generator" is missing some of
> the start and end of the barcode.

Deep in the code, the "Label creator" puts a "*" at the start and end of the stored text barcode value before generating the barcode image.

But the "Barcode image generator" doesn't do that automatically for you.

To generate the barcode as you expect, you'd need to add the "*" to the start and end of your barcode before clicking "Show barcode".

I suppose the question is whether or not we should have some automatic adding of the "*" prefix and suffix if it's not supplied...
Comment 5 Katrin Fischer 2023-09-07 07:56:51 UTC
We've run into the same issue. When using in notices we add the * before and after what we want to print and that fixes the issue.

I think it would be great to test for these and add them if not present. It's not obvious for users and it took us quite some research to figure it out :)
Comment 6 David Cook 2023-09-07 23:40:52 UTC
(In reply to Katrin Fischer from comment #5)
> We've run into the same issue. When using in notices we add the * before and
> after what we want to print and that fixes the issue.
> 
> I think it would be great to test for these and add them if not present.
> It's not obvious for users and it took us quite some research to figure it
> out :)

Sounds like a plan. It should be easy enough to do.
Comment 7 David Cook 2023-09-08 02:22:03 UTC
Created attachment 155350 [details] [review]
Bug 34732: For Code39, append or prepend asterisk if missing from barcode

This patch appends or prepends an asterisk on Code39 barcodes if
they are missing from the input. This is so that they form correct
Code39 barcode images.

Test plan:
0. Apply the patch
1. koha-plack --reload kohadev
2. Go to http://localhost:8081/cgi-bin/koha/labels/barcode-print.pl
3. Type 39999000001310 into "Barcode" and click "Show barcode"
4. Note that the barcode text on the right includes asterisks around it
5. Type *39999000001310 into "Barcode" and click "Show barcode"
6. Note the same as above
7. Type 39999000001310* into "Barcode" and click "Show barcode"
8. Note the same as above
9. Type *39999000001310* into "Barcode" and click "Show barcode"
10. Note the same as above
Comment 8 Matt Blenkinsop 2023-09-08 10:07:16 UTC
Created attachment 155391 [details] [review]
Bug 34732: For Code39, append or prepend asterisk if missing from barcode

This patch appends or prepends an asterisk on Code39 barcodes if
they are missing from the input. This is so that they form correct
Code39 barcode images.

Test plan:
0. Apply the patch
1. koha-plack --reload kohadev
2. Go to http://localhost:8081/cgi-bin/koha/labels/barcode-print.pl
3. Type 39999000001310 into "Barcode" and click "Show barcode"
4. Note that the barcode text on the right includes asterisks around it
5. Type *39999000001310 into "Barcode" and click "Show barcode"
6. Note the same as above
7. Type 39999000001310* into "Barcode" and click "Show barcode"
8. Note the same as above
9. Type *39999000001310* into "Barcode" and click "Show barcode"
10. Note the same as above

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 9 Victor Grousset/tuxayo 2023-09-13 18:57:51 UTC
For some reason GD::Barcode commented the addition of the surrounding "*" :o

https://metacpan.org/release/KWITKNR/GD-Barcode-1.15/source/Barcode/Code39.pm#L85
Comment 10 Victor Grousset/tuxayo 2023-09-13 20:37:55 UTC
19 years since last update but there is a more recent fork. I contacted both maintainers to know if they are still active in the maintenance of this package.

To then know if there is a reason to not have the surrounding "*" added. At least having the choice with a different method or params.

Maybe the root of the problem is this:
> This code is traditionally mapped to the * character in barcode fonts and will often appear with the human-readable representation alongside the barcode
https://en.wikipedia.org/wiki/Code_39

Anyway given all that context, the proposed fix here makes sense.

Testing in progress.
Comment 11 Victor Grousset/tuxayo 2023-09-15 18:37:32 UTC
Created attachment 155708 [details] [review]
Bug 34732: For Code39, append or prepend asterisk if missing from barcode

This patch appends or prepends an asterisk on Code39 barcodes if
they are missing from the input. This is so that they form correct
Code39 barcode images.

Test plan:
0. Apply the patch
1. koha-plack --reload kohadev
2. Go to http://localhost:8081/cgi-bin/koha/labels/barcode-print.pl
3. Type 39999000001310 into "Barcode" and click "Show barcode"
4. Note that the barcode text on the right includes asterisks around it
5. Type *39999000001310 into "Barcode" and click "Show barcode"
6. Note the same as above
7. Type 39999000001310* into "Barcode" and click "Show barcode"
8. Note the same as above
9. Type *39999000001310* into "Barcode" and click "Show barcode"
10. Note the same as above

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 12 Victor Grousset/tuxayo 2023-09-15 18:37:36 UTC
Created attachment 155709 [details] [review]
Bug 34732: (QA follow-up): tidy up code
Comment 13 Victor Grousset/tuxayo 2023-09-15 18:38:00 UTC
Works, makes sense, QA script happy, code looks good, passing QA :)
Comment 14 Victor Grousset/tuxayo 2023-09-15 18:40:08 UTC
(double checked scanning with a phone before and after the patch)
Comment 15 Tomás Cohen Arazi 2023-09-19 19:35:48 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 16 Fridolin Somers 2023-09-21 06:13:38 UTC
Pushed to 23.05.x for 23.05.04
Comment 17 Matt Blenkinsop 2023-10-12 16:11:11 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x