vagran / dxf-viewer

DXF 2D viewer written in JavaScript
Mozilla Public License 2.0
295 stars 87 forks source link

Convert layer name unicode characters to ASCII #31

Closed igortheodoro closed 1 year ago

igortheodoro commented 1 year ago

Layers that had special characters in the name were converted to Unicode characters (\U+XXXX).

image

So to solve this I used the String.replace() function to replace the characters in Unicode with a group of characters. Then the String.fromCharCode() function is used to convert the string of characters to its equivalent in ASCII characters. Finally, the conversion result is returned to the String.replace() function.

image

In this file File.zip have the DXF to test.

vagran commented 1 year ago

Hello, Thanks for your contribution! Seems fixing it in such a way breaks the example, the layer cannot be longer hidden by unchecking its checkbox. Probably it happens because the layer original name is still used as a key in the layers collection, as well as in references from all document entities. Some common approach should be introduced, either using this conversion only for display purposes, or convert it everywhere. Also some special sequences like %%d may be parsed as well (BTW there already exist corresponding method _ParseSpecialChars() which may be moved somewhere to reuse it) . Also some other entities may be affected, not only layers (block names, dimstyles, etc.), so this should be solved in a complex manner. I have created corresponding issue.

igortheodoro commented 1 year ago

I added a new property on the layer object that contains the normalized layer name. In this way, we can use the "normalizedName" property which contains the layer name with the converted unicode characters.

image image

And the code to display the list of layers would look like this: `

{{layer.normalizedName}}

`

vagran commented 1 year ago

I have added displayName attribute for a layer, which is available in just released v1.0.21.