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

Replace default font with smaller one #383

Open
pveiga2 opened this issue Sep 23, 2022 · 3 comments
Open

Replace default font with smaller one #383

pveiga2 opened this issue Sep 23, 2022 · 3 comments

Comments

@pveiga2
Copy link

pveiga2 commented Sep 23, 2022

First of all, thank you for this great work!
I'd like to suggest a size optimization.

While inspecting through the sources, I noticed the NotoSans Font is only used as a fallback for the Label component.
Out of the approximately 16.8 MB the endroid/qr-code takes, 16MB alone are due to this font file.

I think this is a bit too much, considering that :

  • Labels might not be the most common use-case?
  • Labels don't seem to work on SVG.
  • Custom Fonts can easily be configured through a FontInterface implementation.

Suggestions:

  • Changing the fallback font to something smaller, like the open_sans.ttf ;
  • Skip including the NotoSans file entirely;
  • Maybe NotoSans could become a suggested package and, if detected, could then become the default font;

Thank you for your time ;)

@endroid endroid self-assigned this Sep 28, 2022
@endroid
Copy link
Owner

endroid commented Sep 28, 2022

Hi @pveiga2 I completely agree. Unfortunately I'm stuck with this font in this major version because removing it or replacing it with a font that has a smaller character set would be a BC break that impacts many users. I will keep this issue open for the next major so we don't forget.

In the meantime if anyone has any suggestions for fonts with a high character set vs. small file size ratio, please post them here. As a reference: the current default font is "Noto Sans CJK JP" (noto_sans.otf), contains 65535 characters and is 16.4MB. The alternative font I provide "Open Sans" (open_sans.ttf) contains 938 characters and is 217.4kB. I need something that covers most use cases but has an acceptable small file size.

@endroid endroid changed the title Suggestion: Assets Size reduction Replace default font with smaller one in next major Oct 4, 2022
@endroid endroid changed the title Replace default font with smaller one in next major Replace default font with smaller one Oct 4, 2022
@dkarlovi
Copy link

dkarlovi commented Dec 2, 2022

One thing to note is the possibility a compatible font is already provided on the system. For example, we add exactly the same font in our web2print Docker image to enable wkhtmltopdf to work, installing this lib means it's installed twice.

@kevinpapst
Copy link

Considering the amount of daily installations of your package, the proposed changes could make a huge difference in the necessary "computing footprint".

I wonder how many percent of generated QR codes have labels and how any of those have UTF-8 character?

Maybe it is enough to add a small check:

  • if a label character is outside the ascii range
  • throw an exception if setFont() was not called before?

Combined with the idea of @pveiga2 to have a new suggested composer package, re-defining the default font, the BC impact should be rather small for a new major version.

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

No branches or pull requests

4 participants