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

parsefnc with iso-8859-15 seems not to work for pdf417 #308

Open
fradev1988 opened this issue Oct 12, 2023 · 11 comments
Open

parsefnc with iso-8859-15 seems not to work for pdf417 #308

fradev1988 opened this issue Oct 12, 2023 · 11 comments

Comments

@fradev1988
Copy link

fradev1988 commented Oct 12, 2023

Hi,

I'm working on a project where is mandatory to use as encoding iso-8859-15 to generate a pdf417 barcode.

I'm calling the bwipjs.toCanvas with the following options:
bcid: 'pdf417',
text: myText,
scaleX: 3,
scaleY: 2,
columns: 7,
eclevel: 4,
parsefnc: true

where "myText" is of this form: "^ECI000017" + valueString.

It seems that all the characters that contain a dieresis like ë are not encoding correcty

as example if I try to convert the following world Schaumbërg the result is Schaumbërg.

Moreover also other special chars like the euro symbol are not correctly rapresented. In this case the euro became €

@metafloor
Copy link
Owner

Set the binarytext flag to true. By default, UTF-16 strings are assumed and converted to UTF-8.

@fradev1988 fradev1988 changed the title parsefnc with iso-5589-15 seems not to work for pdf417 parsefnc with iso-8859-15 seems not to work for pdf417 Oct 13, 2023
@fradev1988
Copy link
Author

Hi @metafloor, thanks for the quick response.

Now I set the option as follow:
bwipjs.toCanvas(canvas, {
bcid: 'pdf417',
text: myText,
binarytext: true,
scaleX: 3,
scaleY: 2,
columns: 7,
eclevel: 4,
parsefnc: true

where "myText" is always of this form: "^ECI000017" + valueString.

Unfortunatly nothing have changed. Same problems:
world 'Schaumbërg' is read as 'Schaumbërg'
and
euro symbl is read as 'â ¬'

@metafloor
Copy link
Owner

What version of bwip-js are you using? binarytext is a very new option, only available in 4.1+.

Also, please provide the output from this code for a failing myText string:

console.log(myText.replace(/[\x80-\xff]/g, ($) => {
  let cd = $.charCodeAt(0);
  if (cd < 128) {
      return $;
  } else {
    return '\\x' + cd.toString(16);
  }
}));

I need the output for my testing and to verify the 8859 encoding.

@fradev1988
Copy link
Author

Hi @metafloor, we used last version of 3.x. I just udated to 4.1.1 but we have a problem with the toCanvas method.
Just to clarify we are developing in angular 14, using node.js and typescript.
After the update we are no more able to find the toCanvas method inside bwipjs module.

"Property 'toCanvas' does not exist on type 'typeof BwipJs'."

@metafloor
Copy link
Owner

Likely pulling in the node-js package. Does angular support the exports map in package.json?

@fradev1988
Copy link
Author

finally we were able to work with the version 4.1.1. adding binarytext to true we receive the following error:
"Error: bwip-js: 16-bit chars not allowed with binarytext"

without we have as output from your console.log this:
^ECI00001710 13 Schaumb\xebrg-von-und-zu-Schaumburg-und-Rad\xebberg Fri\xebdrich-Wilhelm-Karl-Gustav-Justus-Gotfried 19510712 20341231 101308719 LKK Schlesw-Holst. und H 38 H030170228 1 00 02 398212400 776299002 20210704 Prof. habil. Dr. med Grossherzog von und zu der 53639 K\xf6nigswinter Pfaffenschlag bei Waidhofen an der Thaya Allee 155155133 D 20210704 1234 2 1 06151/1111111 J09 G, G00.0 V kBB €-Zeichensatztest Y/9/2107/36/001

@metafloor
Copy link
Owner

If you look closely at the console output, you will see a euro character in €-Zeichensatztest. That is probably a utf-16 codepoint.

@fradev1988
Copy link
Author

fradev1988 commented Oct 27, 2023

Sure I can see the euro character =)

But that was the output before to pass the string inside the toCanvas method.

If we have a text without euro symbol (using binarytext = true) we don't have problem with any characters and also umlaut chars are displayed correctly in the barcode. (So this fix the first problem that we have).
But,
if we use a text that has a euro symbol with binarytext = true the ToCanvas method return an error at this point inside the library:

if (opts.binarytext) {
        // THE TEXT DOESN T PASS THIS .test
        if (/[\u0100-\uffff]/.test(text)) {                
            throw new Error('bwip-js: 16-bit chars not allowed with binarytext');  
        }
    } else if (/[\u0080-\uffff]/.test(text)) {
        text = unescape(encodeURIComponent(text));
    }

we tried to pass the text preprocessing it with a library that convert it to iso-8859-15, or pass it in utf-8 but in both ways we have the same error with euro symbol.

@fradev1988
Copy link
Author

Moreover, if I was able to partially understand the code, if no 16-bit chars are allowed with binarytext option I think there is a problem with € symbol in any case. Is it right?

@metafloor
Copy link
Owner

The issue is that you are not passing in a iso-8859-15 encoded string. The euro symbol is being passed in as unicode U+20AC. You need to convert it to \xa4 per iso-8859-15.

@fradev1988
Copy link
Author

Ok I understand the situation.

We investigate a little bit and it seems that both the libraries that we tried to convert to iso 8859-15 effectively convert the euro as uncode U+20AC mainwhile all the other symbols in the form \x'something'.

I think there is all.

Thanks a lot for your support and really really thanks for your time!

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

2 participants