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

loadFont() and callback not working properly. #27

Open
alterebro opened this issue Apr 12, 2024 · 1 comment · May be fixed by #28
Open

loadFont() and callback not working properly. #27

alterebro opened this issue Apr 12, 2024 · 1 comment · May be fixed by #28

Comments

@alterebro
Copy link

loadFont() and its callback argument don't seem to work.
Loaded font is only available once the browser has cached the file, which normally happens when you open the sketch for the second time. This behaviour is even present when loadFont() is called within the preload() function.
Also the callback argument is not implemented.

@alterebro alterebro linked a pull request Apr 12, 2024 that will close this issue
@quinton-ashley
Copy link

quinton-ashley commented Jun 22, 2024

I fixed this issue in q5.js v2, check it out!
https://q5js.org

$.loadFont = (url, cb) => {
  p._preloadCount++;
  let sp = url.split('/');
  let name = sp.at(-1).split('.')[0].replace(' ', '');
  let f = new FontFace(name, 'url(' + url + ')');
  document.fonts.add(f);
  f.load().then(() => {
    p._preloadCount--;
    if (cb) cb(name);
  });
  return name;
};

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

Successfully merging a pull request may close this issue.

2 participants