Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

Support for font kerning #297

Open
beta opened this issue Sep 4, 2019 · 4 comments
Open

Support for font kerning #297

beta opened this issue Sep 4, 2019 · 4 comments

Comments

@beta
Copy link

beta commented Sep 4, 2019

It seems gofpdf does not support font kerning at the moment. For example, when outputting "Tourist" with Arial font:

Result of gofpdf:
image

Expected:
image

Note the difference of the spacing between "T" and "o". Is there any way to apply font kerning?

@jung-kurt
Copy link
Owner

Unfortunately, gofpdf (like FPDF from which it is derived) does not currently support font kerning. This feature would be valuable so I will tag this as an enhancement. I imagine a solution would involve a font-specific table that associates letter pairs with spacing amount. Thanks for your post.

@beta
Copy link
Author

beta commented Sep 5, 2019

I had some experiments and below is what I've got with gofpdf and my simple implementation of font kerning.

image

It's not completely implemented (only applied when using AddUTF8Font() and Text()), but it can meet my need now. I will continue to work on this when I have time.

@jung-kurt
Copy link
Owner

Nice work, @beta! If your solution if generally applicable, please consider sharing.

@phpdave11
Copy link
Contributor

phpdave11 commented Sep 17, 2019

I have added this feature to another PDF generator library in the past, so I may be able to provide some insight. Basically, you just need to parse the kern move amount for each letter pair from the font file. Then, when writing text, if there is a kern move amount defined for a letter pair, you embed that amount in between parentheses.

For example, within a TJ operation (show one or more text strings), if the kern move amount is 120 between the letters "T" and "o", then the PDF content would be: [(T)120(ourist)] TJ

More information is in the PDF specification under "Text-Showing Operators".

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

No branches or pull requests

3 participants