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

feat: support bold-italic standard fonts #1841

Merged
merged 5 commits into from
May 31, 2022
Merged

feat: support bold-italic standard fonts #1841

merged 5 commits into from
May 31, 2022

Conversation

diegomura
Copy link
Owner

@diegomura diegomura commented May 31, 2022

This PR changes the way we pre-build font data. We used to have this data compressed and we removed it because was expensive to decompress it for small documents. This takes a different approach though. It just changes the way we store font JSON fields. Most of these JSON objects is duplicate data. Big objects with character and kernPairs names that are repeated in all font sources. While each value is a 2 or 3 char number, the keys sometimes can be several characters long.

As an example: each font has the width of the space character. We supported 9 fonts, so we built 9 times the word space plus :. That's 54 characters just for a single char, while in practice cab be only 6. What used to be repeated key-values in the form of space: 200, now it's being shipped once as space:[200,200,400,400], each value representing a supported font by index.

Some extra small implementations were made on top of that, such as removing trailing empty values and using 0 instead of nulls

By just grouping all fonts into a single object that way, and expand it once, this PR manages to reduce pdfkit bundle size in ~45% (around 200kb minified!), while at the same time supporting 3 new fonts that in the past got removed due to size constrains (bold + italic fonts). There is a small price to pay on the data expansion, but I measured it and it's around 3 to 4ms. It's a small price to pay, maybe not even so, if we count network load time and JS parsing of those extra 200kb

@diegomura diegomura merged commit 25a80eb into master May 31, 2022
@diegomura diegomura deleted the dm/pdfkit-size branch May 31, 2022 03:47
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 this pull request may close these issues.

1 participant