spatialillusions / milsymbol

Military Symbols in JavaScript
www.spatialillusions.com/milsymbol
MIT License
557 stars 136 forks source link

toDataUrl fails on symbol with non Latin1 content #221

Closed alcalin closed 5 years ago

alcalin commented 5 years ago

Hello, I'm having some troubles trying to export a specific symbol with the code EFFPB------- . While it is working fine in your https://spatialillusions.com/unitgenerator/ when I try to create and export it using toDataUrl()it throws the following:

DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

The call to window.btoa(this.asSVG())inside toDataUrl is the one that is causing it and I presume it is because it contains the '€' character. How is the unitgenerator handling this?

spatialillusions commented 5 years ago

I don't think we do any special thing in the unit generator to solve this: https://github.com/spatialillusions/milsymbol-generator/blob/253cdae451467e3483a5ff5732e48601d66c0544/src/render-symbol.js However the unit generator is using the latest master branch of milsymbol and not the npm release, so there might be someting I have fixed in the main library. The next version of milsymbol will be released really soon, I was planning to do it this weekend but got a really bad cold unfortunately.

scottnc27603 commented 5 years ago

Get well soon!

On Thu, Apr 25, 2019 at 9:38 AM Måns Beckman notifications@github.com wrote:

I don't think we do any special thing in the unit generator to solve this:

https://github.com/spatialillusions/milsymbol-generator/blob/253cdae451467e3483a5ff5732e48601d66c0544/src/render-symbol.js However the unit generator is using the latest master branch of milsymbol and not the npm release, so there might be someting I have fixed in the main library. The next version of milsymbol will be released really soon, I was planning to do it this weekend but got a really bad cold unfortunately.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/spatialillusions/milsymbol/issues/221#issuecomment-486676272, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJYBXJNDAFEYTFGK5L4D5LPSGX4XANCNFSM4HIK2POQ .

spatialillusions commented 5 years ago

Release published! Both here and on NPM.

alcalin commented 5 years ago

Get well soon! Awesome, thanks! I'll try again with the latest version.

alcalin commented 5 years ago

I've upgraded to 2.0.0. I have the same issue. While debugging the unitgenerator I see there is catch for the toDataURL() function:

elm.querySelector("a.png").href = downloadSymbol.asCanvas().toDataURL();
try {
    elm.querySelector("a.svg").href = downloadSymbol.toDataURL();
} catch (err) {
    elm.querySelector("a.svg").href = "";
}

So the library also throws the same exception in the unitgenerator but it gets handled, and the actual image gets set in the first place using downloadSymbol.asCanvas().toDataURL(). I guess svg is preferred though.

Thanks for the prompt response!