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

Incorrect font height #143

Open
Chris-SP365 opened this issue May 25, 2022 · 5 comments
Open

Incorrect font height #143

Chris-SP365 opened this issue May 25, 2022 · 5 comments

Comments

@Chris-SP365
Copy link

Font height is determined in PdfUtils. The code corresponds to the 'best' SO answer if one googles 'PDFBox font height'.

But that codes uses getCapHeight and is wrong if I have descents or Umlauts. Cap Height is just the height of capital letters.

for (int fontSize : new int[]{6, 10, 12, 24, 48}) {
    tableBuilder.addRow(
            Row.builder()
                    .add(TextCell.builder()
                                 .text("gÜ Text with word wrap")
                                 .padding(0f)
                                 .borderWidth(0.000001f)
                                 .fontSize(fontSize)
                                 .build())
                    .build());
}

grafik

My proposal would be to determine the height this way:

PDFontDescriptor fd = font.getFontDescriptor();
return (fd.getFontBoundingBox().getHeight() - fd.getLeading()) / 1000.0f * fontSize;
@vandeseer
Copy link
Owner

Thanks for your suggestion @INPUTsys-Chris!
I will check that (as soon as I find some time for it).

@vandeseer
Copy link
Owner

I added the correction and introduced a flag to allow for backwards compatibility. Would be nice if you could have a look @INPUTsys-Chris and try it out. Still needs some tests IMHO ...

@vandeseer
Copy link
Owner

This is the PR: #149

@Chris-SP365
Copy link
Author

Thank you for your hard work.
I ran my quick test and while the spacing is better, the letters don't seem to be on the right place:

grafik

@vandeseer
Copy link
Owner

Yeah, there's clearly something odd here. Thanks. If I will have a look when I find some time.

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

2 participants