[I] Picture Resize fails due to error in getDimFromCell() [poi]

Nicola-Reseda (via GitHub) <[email protected]>
Newsgroups gmane.comp.jakarta.poi.devel
Message-ID <[email protected]>
Nicola-Reseda opened a new issue, #1201:
URL: https://github.com/apache/poi/issues/1201

   Trying to resize a picture in a XSSF Spreadsheet but this fails consistently because the target size is computed as negative. The computation of the `picture.resize(double, double)` is done by the help of `getDimFromCell(...)` method in ImageUtils.class where the bug is located.
   I havent'checked whether this logic works for pictures spreading over several cells, but it surely fails when the picture should be within one single cell. Both the width and height computation return 0 in the best case (when no Dx/Dy is defined), negative values otherwise (which leads to subsequent IllegalArgumentException)
   
       for (int cellIdx = startCell; cellIdx<=endCell; cellIdx++) {
                   final double dim = nextSize.apply(cellIdx).doubleValue() * EMU_PER_PIXEL;
                   double leadSpace = 0;
                   if (cellIdx == startCell) {
                       //space in the leftmost cell
                       leadSpace = (hssfUnits > 0)
                           ? dim * startD/(double)hssfUnits
                           : startD;
                   }
   
                   double trailSpace = 0;
                   if (cellIdx == endCell) {
                       // space after the rightmost cell
                       trailSpace = (hssfUnits > 0)
                           ? dim * (hssfUnits-endD)/(double)hssfUnits
                           : dim - endD;
                   }
                   targetSize += dim - leadSpace - trailSpace; // --> = dim - startD - dim - endD = -startD - endD
               }
   
   The computation of trail space should not be `trailSpace = dim - endD` but rather `trailSpace = endD`
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.