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

Doesn't working with Google Fonts #59

Closed
ralharabi opened this issue Sep 5, 2016 · 24 comments
Closed

Doesn't working with Google Fonts #59

ralharabi opened this issue Sep 5, 2016 · 24 comments

Comments

@ralharabi
Copy link

ralharabi commented Sep 5, 2016

https://jsfiddle.net/3Lu1xpxh/

It generates the DOM element without applying the element font as it's show. I'm not sure if there is limitation with some types of fonts or there are another way to apply the element font

https://jsfiddle.net/3Lu1xpxh/

@tomeraz
Copy link

tomeraz commented Sep 19, 2016

I'm also having fonts changed in the image, using 'open sans' font.
style is written as:

font-family: 'Open Sans', sans-serif

It seems to replace open sans with another font.
Does dom-to-image handle fonts with quotation marks?

@srapp
Copy link

srapp commented Sep 23, 2016

I've run into this as well. It looks like webfonts aren't being included as part of the SVG. I've modified @ralharabi's fiddle to make it easier to access the SVG: https://jsfiddle.net/kuou44ry/

One workaround I've found is that including the contents of the Webfont into your app's CSS seems to work: https://jsfiddle.net/heycr5em/

I've done a little research and it looks like it's possible to include webfonts within an SVG. I'm not sure just yet how it should be approached in this library, but this does seem like a solvable problem.

@ralharabi
Copy link
Author

Thanks, it's work with me
one more note you have to make sure where you should but the font face code !.

@MichalBryxi
Copy link

Example of workaround for Google fonts:

  1. Get your font import URL:
<style>
@import url('https://fonts.googleapis.com/css?family=Lato');
</style>
  1. Visit that URL (https://fonts.googleapis.com/css?family=Lato) and copy & paste everything you will see there to your CSS.

@TiagoRocha1985
Copy link

Thanks!

@TiagoRocha1985
Copy link

TiagoRocha1985 commented Jun 18, 2018

@MichalBryxi stopped working in Chrome =/

@MichalBryxi
Copy link

@TiagoRocha1985 Yes the same for me with latest Chrome. And that's not the only regression I encountered. I believe there is something really wrong in Chrome-67. In Safari, it works still ok.

@TiagoRocha1985
Copy link

@MichalBryxi For me in firefox still works!!

Is it possible to find another solution to get back to working in chrome?

@MichalBryxi
Copy link

No idea @TiagoRocha1985. Haven't dug into that one yet. But for me not only the fonts are an issue. So I suspect that it's something bigger.

@TiagoRocha1985
Copy link

Then it will be the way to use the html2canvas for the chrome.

If you find out something, I'll let you know @MichalBryxi

@MichalBryxi
Copy link

MichalBryxi commented Jun 19, 2018

FYI: Looks like some of the forks have patches: fireworkz@bd1ccfd. So I forked the repo and cherry-picked everything that looked nice here: https://github.com/MichalBryxi/dom-to-image (no guarantee)

@TiagoRocha1985
Copy link

thank you brother!

Yes, it worked! Many, many thanks!

@randomdipesh
Copy link

Many thanks to the fork of @MichalBryxi , it worked fine

@alexeyuzlov
Copy link

alexeyuzlov commented Aug 30, 2018

https://github.com/MichalBryxi/dom-to-image
it works fine for me. Will it include to dev branch? I still hope use it via npm

@impactcolor
Copy link

I'm trying this fix but I get a CORS error. The error doesn't appear in the regular js file (updated a year ago) from the src folder. Any idea why?

@alexeyuzlov
Copy link

Can you check with anonymous attribute?
<script src"path/to" crossorigin="anonymous"></script>

https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes#Example_crossorigin_with_the_script_element

@MichalBryxi
Copy link

@sentika The branch I provided is consumable via npm. You just need to point directly on GitHub: https://stackoverflow.com/questions/16350673/depend-on-a-branch-or-tag-using-a-git-url-in-a-package-json

As I'm not a maintainer, I can't integrate it into a build.

@bornfree
Copy link

Thank you @MichalBryxi.
Works like a charm!

@conradolopez
Copy link

Excellent, solved a bug with Google Fonts. Thanks

@Hinrick
Copy link

Hinrick commented Feb 20, 2020

@MichalBryxi thanks for your hard work, however, I got the issues with using your version with adobe fonts (typekit)

There are two ways to import adobe fonts, one of them is put the in the head of your app, the other way is to put the script like this:

<script src="https://use.typekit.net/xxxxxxx.js"></script> <script>try{Typekit.load({ async: true });}catch(e){}</script>

--

Because I'm developing a Chinese web, I need to do the script one. I tried the script of google font it works ok and the link tag of adobe font it also works fine. But it doesn't work when I importing adobe font by script.

Any thoughts?

@MichalBryxi
Copy link

@Hinrick I might take a look if you provide jsbin where (a) you have working example with "standard" fonts and (b) your non-working example.

Quick search showed me that this PR might have the necessary code: #118

If that is proven true by testing on your example, I could integrate it to my branch as well.

@arijitnaskar
Copy link

Example of workaround for Google fonts:

  1. Get your font import URL:
<style>
@import url('https://fonts.googleapis.com/css?family=Lato');
</style>
  1. Visit that URL (https://fonts.googleapis.com/css?family=Lato) and copy & paste everything you will see there to your CSS.

Thanks :)

@akshaybosamiya
Copy link

Example of workaround for Google fonts:

  1. Get your font import URL:
<style>
@import url('https://fonts.googleapis.com/css?family=Lato');
</style>
  1. Visit that URL (https://fonts.googleapis.com/css?family=Lato) and copy & paste everything you will see there to your CSS.

It works! :)

But do you have any idea that how it can be done dynamically without copy & paste?

@akshaybosamiya
Copy link

Example of workaround for Google fonts:

  1. Get your font import URL:
<style>
@import url('https://fonts.googleapis.com/css?family=Lato');
</style>
  1. Visit that URL (https://fonts.googleapis.com/css?family=Lato) and copy & paste everything you will see there to your CSS.

It works! :)

But do you have any idea that how it can be done dynamically without copy & paste?

Never mind. I found the below way to achieve it.

const loadFont = (url) => {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', url, true);
  xhr.onreadystatechange = () => {
    if (xhr.readyState == 4 && xhr.status == 200) {
      let css = xhr.responseText;
      css = css.replace(/}/g, 'font-display: swap; }');

      const head = document.getElementsByTagName('head')[0];
      const style = document.createElement('style');
      style.appendChild(document.createTextNode(css));
      head.appendChild(style);
    }
  };
  xhr.send();
}

loadFont(format('https://fonts.googleapis.com/css2?{0}display=swap', fontFamilies));

ThereseKH added a commit to ThereseKH/Monthly-backdrop-generator that referenced this issue Jan 1, 2022
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