graphicore / librebarcode

Libre Barcode: barcode fonts for various barcode standards.
https://graphicore.github.io/librebarcode
SIL Open Font License 1.1
425 stars 25 forks source link

How to specify 128 A? #31

Open rdyar opened 3 years ago

rdyar commented 3 years ago

On your encoder here: https://graphicore.github.io/librebarcode/ is it possible to specify to encode the string as 128A?

I see in the encode.js file what looks like different start characters for 128A, B and C but I don't see how to specify which one.

I have a spec that says my barcode should be 128A and I am thinking just encoding like you are and wrapping it in the libracode font is not actually doing that?

I have an example barcode and other than the first few lines mine matches but I think those first few lines are the start character but not specifically 128A.

graphicore commented 3 years ago

On your encoder here: https://graphicore.github.io/librebarcode/ is it possible to specify to encode the string as 128A?

No.

The encoder is optimizing for length and switching codes when appropriate. Code B adds mainly "lowercase" characters and Code C offers possible size reductions by encoding numbers from 00 to 99 in one symbol instead of two.

If you restrict your input to symbols that are only in Code A you basically have to calculate the checksum character and are done:

{Start Code A =Ë}{YOUR INPUT}{checksum char}{stopChar = Î}

No optimizing and code switching needed.

I have an example barcode and other than the first few lines mine matches but I think those first few lines are the start character but not specifically 128A.

If you look into encoder.js, the first entries in Code A and Code B encode the same values, so if the encoder starts with Code B and you only have encoded chars common to Code A and B, only the start symbol and the checksum/digit should differ, (checkdigit could be the same in some cases).

If you need further help with this please ask.

rdyar commented 3 years ago

thanks for the quick reply. I think I am getting there. This is for an amazon specific barcode, they say to use code 128A - which to me means the start character is Ë but when they generate the barcode the start character is Ì which is a little confusing. So the code from your encoder app and from amazon both match - but to me they both have the wrong start character if you are told it has to be 128A.

I'm guessing it is no big deal - I edited the encode.js file to have all 3 have the same start digit as A but then undid that when I saw that the labels amazon creates match what you have. A service that makes this same barcode looks like it has Ë for its start code which to me is correct. That bar code and the one amazon generates both work, even though the start code is different.

To me it looks like what amazon wants you to do 128 Auto which is what it sounds like your encoder is doing.

graphicore commented 3 years ago

I'll leave this open as a feature request for the encoder.

So the code from your encoder app and from amazon both match - but to me they both have the wrong start character if you are told it has to be 128A.

I'm guessing it is no big deal - I edited the encode.js file to have all 3 have the same start digit as A but then undid that when I saw that the labels amazon creates match what you have. A service that makes this same barcode looks like it has Ë for its start code which to me is correct. That bar code and the one amazon generates both work, even though the start code is different.

I agree, however, if they accept it it's not too bad.

To me it looks like what amazon wants you to do 128 Auto which is what it sounds like your encoder is doing.

Maybe they just want to make sure that you encode only uppercase characters.

rdyar commented 3 years ago

I ended up switching to JsBarcode as it allows you to specify 128A. I liked the way the libre font worked though, and would prefer it if there was a way to specify the code type.

That said my use case may be a bit weird - a spec to follow where even the spec creator is not following the spec. Good times.

Thanks for your work and help.

graphicore commented 3 years ago

Thanks for the feedback!

pfumagalli commented 3 months ago

In case someone stumbles here for the same reason (third party logistics provider can be awfully annoying in what they require), I needed to have the same feature, so I made it available here:

https://www.npmjs.com/package/@juit/librebarcode#encoding-with-a-specific-code-set