string-pixel-width icon indicating copy to clipboard operation
string-pixel-width copied to clipboard

Only latin characters?

Open iliakan opened this issue 6 years ago • 2 comments

Looks like it doesn't work with non-latin characters, e.g. cyrillic.

Please make that very clear in Readme start, not in "How to contribute" section.

So that people don't waste their time.

iliakan avatar Jul 27 '19 15:07 iliakan

@iliakan you can try this https://github.com/Evgenus/js-server-text-width if it is still relevant.

Evgenus avatar Jan 05 '21 22:01 Evgenus

Looks like it doesn't work with non-latin characters, e.g. cyrillic.

Please make that very clear in Readme start, not in "How to contribute" section.

So that people don't waste their time.

I tried to add cyrillic adding this loop

for (let i = 0; i < hexArray.length; i++) {
         for (let j = 0; j < hexArray.length; j++) {
           let russianUnicode = `${hexArray[i]}${hexArray[j]}`.padStart(
             4,
             "04"
           );
           var russianLetter = String.fromCharCode(
             parseInt(`${russianUnicode}`, 16)
           );
           widths[russianLetter] = [
             getWidthOf(sandbox, printableLetter, name, "normal", "normal"),
             getWidthOf(sandbox, printableLetter, name, "bold", "normal"),
             getWidthOf(sandbox, printableLetter, name, "normal", "italic"),
             getWidthOf(sandbox, printableLetter, name, "bold", "italic"),
           ];
         }
         if (hexArray[i] === "5") {
           break;
         }
       }

just below the loop iterating for latin chars and I can have those chars included

image

but even adding it when I try to use it to have the getWidth of a text, it seems the width are not correctly calculated, because the result to apply a font resized based on the full text width and the container dimension where the text might fit, it doesn't work as it does for latin chars.

jmvelasco avatar Sep 22 '23 14:09 jmvelasco