Bug 46197 - rounding bugs in HSSFPicture.getPreferredSize
Summary: rounding bugs in HSSFPicture.getPreferredSize
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-12 11:05 UTC by littlenoodles
Modified: 2008-11-16 05:28 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description littlenoodles 2008-11-12 11:05:28 UTC
In HSSFPicture.getPreferredSize().  This line:

 h += (1 - anchor.dy1/256)* getRowHeightInPixels(anchor.row1);

doesn't work right.  It computes (1 - anchor.dy1/256) as an integer before applying it as a fraction to getRowHeightInPixels.  So you always get h incremented by 1 full row height (anchor.dy/256 evaluates to 0).  It works if I change it to:

 h += ((float)1 - (float)anchor.dy1/256)* getRowHeightInPixels(anchor.row1);

Same problem with the code to apply an initial x-offset to the image width:

 //space in the leftmost cell
 w += getColumnWidthInPixels(anchor.col1)*(1 - anchor.dx1/1024);

should be:
 w += getColumnWidthInPixels(anchor.col1)*((float)1 - (float)anchor.dx1/1024);
Comment 1 Yegor Kozlov 2008-11-16 05:28:23 UTC
Thanks for the suggestion. Applied in r718023.

P.S. Inspired by the "images and anchors - controlling image size" thread in poi-user, I added HSSFPicture.resize(double scale).
scale is the amount by which image dimensions are multiplied relative to the original size:

picture.resize(); //resets to 100% size
picture.resize(1); //resets to 100% size
picture.resize(2); //resets to 200% size
picture.resize(0.5); //resets to 50% size

Yegor