Bug 60282

Summary: getFontHeightInPoints() has wrong type
Product: POI Reporter: najh <najh.ru>
Component: HSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description najh 2016-10-20 12:04:22 UTC
short	getFontHeight()
Get the font height in unit's of 1/20th of a point.

Type short is wrong. There must be a double.
The font size can be for example 8.5. Now it returns 8, throwing a fractional part.
  170 / 20 =8,5

from HSSFFont:
    public short getFontHeightInPoints()
        return ( short ) (font.getFontHeight() / 20);

from XSSFFont:
    public short getFontHeightInPoints() {
        return (short)(getFontHeight()/20);
Comment 1 Javen O'Neal 2017-02-17 05:33:48 UTC
Unfortunately, changing the return type of this method would break backwards compatibility.

If you need the accuracy of fractional points, perform this computation yourself using getFontHeight.

We could add a warning in the JavaDoc that fractional values are discarded.
We could also make the 20 constant a public constant in Font.
Otherwise we could try to change the return type through some slow deprecation process.
Comment 2 Dominik Stadler 2020-03-08 08:29:29 UTC
As described the migration to different API would be a long and tedious process. Also some of the underlying formats store the 1/20th as integer-value, so they cannot represent the decimal value anyway.

Therefore I think we should stick with what we have right now as you can use the InPoints() for the raw value and do computations yourself in double-precision if necessary.

Updated comments and introduced a common constant Font.TWIPS_PER_POINT for the "20" via r1874966.