graphicore / librebarcode

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

Code-128 does not encode with FNC-1 character (needed for GS1-128) #46

Open Ragiton opened 2 years ago

Ragiton commented 2 years ago

Code-128 encoder does not work with an FNC-1 character.

I'd like to be able to add the "Ê" char to put an FNC-1 at the beginning of the barcode and have the encoder work. ( I pulled the "Ê" char out of the data map [here] )(https://github.com/graphicore/librebarcode/blob/f9864c42b2c467f255659c8851c124e4cd56c67a/app/lib/code128Encoder/encoder.mjs#L110)

This is needed to be able to meet the GS1-128 barcode standard to create GTIN numbers.

graphicore commented 2 years ago

Hi @Ragiton, thanks for reporting and sorry for the belated answer.

The core issue is that so far there's no way to input FNC 1 into the encoder, there should probably be some escape sequence that enables this. The Ê char that you found would be the output of the encoder (to render with the font), but, since it's

Since this is not about changing the fonts, but only about changing the encoder, I'd rather prefer e.g. \FNC1 or \DC4 as nice way to input these.

Ragiton commented 2 years ago

@graphicore thanks for the response! Totally makes sense to use an escape character. Using the Ê char is kind of a hack.

It would be really nice to be able to use the encoder with all values!

The checksum calculation makes it difficult to use a manual workaround in the mean time.

pfumagalli commented 4 months ago

I needed this for our own project (dealing with GS-1) so I wrote a little encoder that also supports the various FNCx of Code128.

I just pushed it out here https://www.npmjs.com/package/@juit/librebarcode

PLZ note, it's a clean-room implementation of the EAN "compatible" and Code128 encoders (and all tests pass), so any help with further testing would be really appreciated!

Bonus points, it's both CJS and ESM and has no dependencies (no Node) so should work pretty much everywhere!

graphicore commented 4 months ago

@pfumagalli Very nice to see alternative implementations of some encoders! We should mention them in the docs.

graphicore commented 4 months ago

[...] any help with further testing would be really appreciated!

@pfumagalli I should probably start porting your tests. :-)

pfumagalli commented 4 months ago

[...] any help with further testing would be really appreciated!

@pfumagalli I should probably start porting your tests. :-)

Thanks, I'd be happy to help, if you setup a testing framework for the encoders!

Note, the results the @juit/librebarcode produce for Code128 are not exactly the same as the encoders here, as we prefer code-set 'A' over 'B' (e.g. 'ABC' which has the same length in both code sets), and we're a bit more "eager" when switching from from 'C' to 'A' or 'B' (and back) when an odd-number of digits is detected in the input (output has the same length, but the switch happens at a different place).

rhdaly commented 4 months ago

This is wonderful! I've been jumping through hoops trying to encode FNC3, and failing miserably. Thank you!

Could I make a feature request? For those of us unable to help ourselves with the source alone, would a web implementation be possible? Maybe something similar to the textbox 128 encoder on /graphicore/librebarcode ?