vandeseer / easytable

Small table drawing library built upon Apache PDFBox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect font height

Chris-SP365 opened this issue · comments

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;

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

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 ...

This is the PR: #149

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

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