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

Wrong element size on mobile #361

Open
nuthinking opened this issue Apr 27, 2017 · 1 comment
Open

Wrong element size on mobile #361

nuthinking opened this issue Apr 27, 2017 · 1 comment

Comments

@nuthinking
Copy link

nuthinking commented Apr 27, 2017

When I check for the text size of a custom font straight after the font has been loaded for the first time, on mobile (tested only on webkit) often I get wrong results (in my case, roughly double the size).

When the font is "active" I do the following:

    const nextText = document.createElement('span');
    nextText.style.position = 'absolute';
    nextText.style.fontFamily = style.fontFamily;
    nextText.style.fontWeight = style.fontWeight || 'normal';
    nextText.textContent = nextWord;
    this.el.appendChild( nextText ); // this.el is already added to the DOM
    const rect = nextText.getBoundingClientRect();

After the font has been loaded once, the issue disappears.

Any idea how to safely postpone the check of the sizes after the new loaded font has been assigned and the new element added to the DOM? Thanks!

Dependency: "webfontloader": "^1.6.10"

@tomcardoso
Copy link

Would love to find a solution to this too. I've got some D3 scripts that need text measurements to do their thing, but the text size is often wrong on the first pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants