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

Only latin characters? #18

Open
iliakan opened this issue Jul 27, 2019 · 2 comments
Open

Only latin characters? #18

iliakan opened this issue Jul 27, 2019 · 2 comments

Comments

@iliakan
Copy link

iliakan commented Jul 27, 2019

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.

@Evgenus
Copy link

Evgenus commented Jan 5, 2021

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

@jmvelasco
Copy link

jmvelasco commented Sep 22, 2023

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.

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