Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing leading FNC1 char #5

Open
polRk opened this issue Oct 22, 2021 · 3 comments
Open

Missing leading FNC1 char #5

polRk opened this issue Oct 22, 2021 · 3 comments

Comments

@polRk
Copy link

polRk commented Oct 22, 2021

No description provided.

@DC-jc
Copy link

DC-jc commented Nov 1, 2021

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?

@polRk
Copy link
Author

polRk commented Nov 1, 2021

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

FNC1 (или ASCII <29>)

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

@boriborm
Copy link

@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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants