feat: support bold-italic standard fonts #1841
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wordspace
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 ofspace: 200
, now it's being shipped once asspace:[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 ofnull
sBy 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