vandeseer / easytable

Small table drawing library built upon Apache PDFBox
MIT License
239 stars 91 forks source link

Incorrect font height #143

Open Chris-SP365 opened 2 years ago

Chris-SP365 commented 2 years ago

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 commented 2 years ago

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

vandeseer commented 1 year ago

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 commented 1 year ago

This is the PR: https://github.com/vandeseer/easytable/pull/149

Chris-SP365 commented 1 year ago

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 commented 1 year ago

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