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

Font variation after Chrome update #225

Open
1 task
zaghop opened this issue Jun 12, 2018 · 9 comments
Open
1 task

Font variation after Chrome update #225

zaghop opened this issue Jun 12, 2018 · 9 comments

Comments

@zaghop
Copy link

zaghop commented Jun 12, 2018

Expected behavior

An image is created that is identical to the DOM element being referenced

Actual behavior

Font styles (weights, size, etc...) seems to be reverting to the browser defaults.

Library version

2.5.2

Browsers

  • Chrome 67.0.3396.79.
@ranneyd
Copy link

ranneyd commented Jun 12, 2018

+1. Have the same issue. Very bad

@CarlosAzocar
Copy link

+1. Have the same issue.

1 similar comment
@yqkqknct
Copy link

+1. Have the same issue.

@fireworkz
Copy link

it applies to 2.6.0 (latest at the time of writing) as well

@newmandani
Copy link

newmandani commented Jun 13, 2018

I've resolved this bug on our company product. The real problem is a css font property you getting here:

function cloneStyle() {
copyStyle(window.getComputedStyle(original), clone.style);

function copyStyle(source, target) {
    target.fontStretch == '';

    if (source.cssText) target.cssText = source.cssText;
    else copyProperties(source, target);

    target.fontStretch = 'normal';
    // here's my fix

    function copyProperties(source, target) {
        util.asArray(source).forEach(function (name) {
            target.setProperty(
                name,
                source.getPropertyValue(name),
                source.getPropertyPriority(name)
            );
        });
    }
}

If I don't do it such way, my font css property become something like
font: 400 100% 14px/14px Arial, Helvetica, sans-serif;

Firefox & Chrome will warn you that whole font statement is wrong and no one of your font property except browser default will not be applied for svg that will become wrong canvas.

image

You can check it on your own if you set breakpoint to the if (source.cssText) target.cssText = source.cssText; string.

It's not looks like a "silver bullet" so I'll wait for more elegant solution with community help.

@lawsumisu
Copy link

@tsayen Considering how much a loss of functionality this is for Chrome users, what is the process for expediting a new release that fixes this?

The one-liner that @newmandani suggested seems fine as long as the fontStretch was originally 100% (also since no browsers support font-stretch right now, it's a fine bandaid for any case at worst).

@saintplay
Copy link

This repo have the fix: https://github.com/MichalBryxi/dom-to-image

@maltem-za
Copy link

Also related: #220, #235

@IDisposable
Copy link

This is actually better fixed by copying the font itself over.

See 1904labs@7d1476a#diff-94b43d5a54b46e49799cce165ab4fec0R236

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

10 participants