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

Not able to load local fonts that have same name as google fonts #7

Closed
ol-cheesebeard opened this issue Dec 3, 2020 · 1 comment
Closed

Comments

@ol-cheesebeard
Copy link

Use case:

  1. Font picker is defined with local fonts only, no google or system fonts, --> googleFonts: false,
  2. User saves a "project" with various text elements, fonts have been selected with this plugin.
  3. User reloads page.
  4. User clicks on an existing text element.

Expected result:
$("#font").val(f).trigger("change"); is called and the font picker displays the element's current font.

Actual result:
"Uncaught TypeError: Cannot read property 'variants' of undefined. jquery.fontpicker.js:5128 "

Line 5128 shows this:
var url = 'https://fonts.googleapis.com/css?family=' + font.replace(/ /g,'+') + ':' + this.options.googleFonts[font].variants + '&display=swap';

Upon further inspection I found that this was only happening with local fonts that also appear on the google fonts list with exactly the same name. Specific fonts I had trouble with were Roboto, Cabin, and Quicksliver. Fonts that do not appear on the google fonts list do not throw this error, and work as expected.

Current work around:
Rename the font files; for example I renamed Roboto to Roboto-Regular and this fixed the error. Another solution is to open the font picker modal to force the fonts to load. These solutions seems hacky to me. Furthermore, I don't think I should have to implement onSelected to differentiate types when googleFonts is set to false.

@av01d
Copy link
Owner

av01d commented Dec 8, 2020

Please try version 1.3. It should fix your issue.
As for implementing onSelect: this is optional, in your case (not using google Fonts), an on('change', ...) event handler should suffice.
Thanks for your very clear bug report!

@av01d av01d closed this as completed Dec 8, 2020
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

2 participants