datamatrix-svg icon indicating copy to clipboard operation
datamatrix-svg copied to clipboard

Missing leading FNC1 char

Open polRk opened this issue 4 years ago • 3 comments

polRk avatar Oct 22 '21 12:10 polRk

A leading FNC1 (or a ASCII <29>) is only mandatory for GS1-DataMatrix, not the general DataMatrix symbology. Can't you just add a leading FNC1 to your message?

DC-jc avatar Nov 01 '21 10:11 DC-jc

I know, that i can make it only programmatically way.

FNC1 (или ASCII <29>)

Not, FNC1 it is not a <\GS> or <29>

polRk avatar Nov 01 '21 15:11 polRk

@DC-jc If add leading FNC1 char, then it replaces in unescape function to other chars. If not use unescape, then it replaces by codes 235 + (232-128)

@polRk If you need only GS1-DataMatrix, you can change code in js file

	,toAscii = function( t ) {

		var
		r = [232], // <-- leading char FNC1

For me i changed code to

,toAscii = function( t ) {
    var gsCodes = {
      FNC1: 232,
      GS: 30
    };
    var matchAll = Array.from(t.matchAll(/<(FNC1|GS)>/g));
    var mathIdx = [];
    for (var m in matchAll){
      mathIdx.push(matchAll[m].index);
    }

		var
		r = [],
		l = t.length;

		for( var i = 0; i < l; i++ ) {

		  var mIdx = mathIdx.indexOf(i);

		  if (mIdx >= 0){
		    var m = matchAll[mIdx][1];
		    if (gsCodes.hasOwnProperty(m)){
          r.push(gsCodes[m]);
          i = i + m.length + 1;
        }
      } else {
        var
          c = t.charCodeAt(i),
          c1 = (i + 1 < l) ? t.charCodeAt(i + 1) : 0;

        if (c > 47 && c < 58 && c1 > 47 && c1 < 58) { /* 2 digits */

          r.push((c - 48) * 10 + c1 + 82), /* - 48 + 130 = 82 */
            i++;
        } else if (c > 127) { /* extended char */

          r.push(235),
            r.push((c - 127) & 255);

        } else r.push(c + 1); /* char */
      }
		}

		return r;
	}

Then i run

DATAMatrix('<FNC1>010290001017432721y/DRds*ZtuU0d<GS>91EE06<GS>92s9IomdL');

boriborm avatar Nov 16 '21 16:11 boriborm