Generate the dataMAtrix with a forced c40 encoding

223 views
Skip to first unread message

Elyes Bezzine

unread,
Nov 29, 2021, 3:37:35 AM11/29/21
to zxing
Hello, are there plans to generate the DataMatrix with a forced C40 encoding ?
Why not add a parameter that allows you to choose the exclusive encoding type in the DataMatrixWriter and encodeHighLevel class ?
Thanks

Elyes Bezzine

unread,
Dec 8, 2021, 3:40:43 AM12/8/21
to zxing
Hello,
I have created an attached Git patch (DataMatrixZxingForceC40.patch) which allows to force the encoding in C40. I couldn't create a pull request on github, that's why I'm putting a patch here, it can still be useful to someone.
I also added the zip of the core project which embeds the modifications.
zxing.zip
DataMatrixZxingForceC40.patch

Elyes Bezzine

unread,
Dec 8, 2021, 3:44:40 AM12/8/21
to zxing
How to use it:
...
...
        final DataMatrixWriter barcode = new DataMatrixWriter();
        Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
        hints.put(EncodeHintType.DM_ENCODING_TO_FORCE, HighLevelEncoder.C40_ENCODATION);
        final BitMatrix bitMatrix = barcode.encode(this.dmTextToEncode, DATA_MATRIX, this.size, this.size, hints);
...
...

Alex Geller

unread,
Dec 8, 2021, 3:55:57 AM12/8/21
to zxing
Hi,
I am guessing that you want to force C40 encoding to get a smaller size. Can you confirm? If yes, wouldn't the fix be rather to improve the algorithm that finds the most compact representation? Can you give a sample string that it not encoded as compact as it could be?

Elyes Bezzine

unread,
Dec 8, 2021, 4:42:22 AM12/8/21
to zxing
Hello,
No, I want to force the encoding in C40 to respect the specifications imposed by the French government for health documents, the DataMatrix is rejected if the encoding is not in C40.
Here is the DataMatrix validation link:  https://interop.esante.gouv.fr/datamatrixins-1.0-SNAPSHOT/
Example of input string: IS010000000000000000000000S1118058599124123S21.2.250.1.213.1.4.8 S3FIRST NAMETEST S5MS618-06-1985S713201S4LASTNAMETEST

Elyes Bezzine

unread,
Dec 8, 2021, 4:48:39 AM12/8/21
to zxing
Message has been deleted

Elyes Bezzine

unread,
Dec 8, 2021, 4:57:18 AM12/8/21
to zxing
Most paid libraries offer the forced encoding mode in C40,  Unfortunatly Zxing doesn't.

Alex Geller

unread,
Dec 8, 2021, 5:11:21 AM12/8/21
to zxing
I see, thanks for clarifying. 
It can be encoded in 80 bytes as follows: ASCII(IS010000000000000000000000S1118058599124123S21), EDF(.2.250.1.213.1.4.8 S3FIRST NAMETEST S5MS618-06-), ASCII(1985S713201S4), X12(LASTNAMETEST).
Note the large ASCII encoding parts which encodes every digit in 4 bits instead of the 5,33 bits of C40. The combination of dots and digits can be encoded in EDIFACT by 6 bits per character where C40 takes 10.66 bytes for every dot character.
Strange that the French government forces inefficient encoding.
 Thanks again for clarifying and giving the reference. If the issue had been related to an algorithmic problem of the minimal encoding then I could have possibly been of help.

Best regards,
Alex

Elyes Bezzine

unread,
Dec 8, 2021, 5:29:30 AM12/8/21
to zxing
I agree that the choice of the forced C40 is weird, best regards

Alex Geller

unread,
Dec 8, 2021, 8:06:39 AM12/8/21
to zxing
Not relevant for your request, I just share the information because I was curious to quantify the difference of C40 vs. minimal encoding in this example. I takes 10% more bytes to encode (88 bytes instead of 80) and the surface increases by 20% (40 x 40 instead of 36 x 36).

Elyes Bezzine

unread,
Dec 8, 2021, 8:17:32 AM12/8/21
to zxing

thank you for your feedback

Alex Geller

unread,
Jan 27, 2022, 3:10:30 AM1/27/22
to zxing
FYI, upcoming version 3.5.0 includes EncodeHintType.FORCE_C40 that forces C40 encodation.

Regards,
Alex   

Elyes Bezzine

unread,
Jan 27, 2022, 3:41:31 AM1/27/22
to zxing
great news, thanks
Reply all
Reply to author
Forward
0 new messages