Skip to content

Implement option to embed fonts #45

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ThomasTJdev
Copy link
Contributor

This PR adds the ability to embed fonts directly into the generated PDF files.

Embedding increases the PDF file size slightly, but enables much better post-processing compatibility - especially when copying text or handling non-ASCII characters.

This also solves my issue from 2021 :) #39


Example

To enable font embedding, simply set the new option:

var opts = newPDFOptions()
opts.setEmbedFont(true)

var doc = newPDF(opts)

Notes

I've aimed to keep the implementation as non-intrusive as possible, but it will always load the font cache in the makeTTFont().

discard

method EscapeString*(f: Base14, text: string): string =
method EscapeString*(f: Base14, text: string, embedFont: bool = false): string =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

embedFont should passed through setFont, then the table initialization is done once in makeFont.
I prefer users have liberty to choose which font they want to embed. And for the global embedFont flag,
it will override the setFont's embedFont flag.

Built in font have no effect when setting this font.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. During my testing I used some more fonts from the demo folder an got in trouble with the width, so that's the first commit #da483d4.

For the setFont() I added an embedFont: bool and got it to work partially, so the font got embedded (copy-paste'able) but the rendering broke. So I'm gonna pass on that one for now.

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.

2 participants