steven0lisa / flying-saucer

Automatically exported from code.google.com/p/flying-saucer
0 stars 0 forks source link

ImageResourceLoader wrong scales on images without csswidth (only height) used multiple times with different sizes #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
*** This issue was imported from http://java.net/jira/browse/XHTMLRENDERER-308

It was reported by bago on 12.01.2010 21:47:14 +0100 and last updated in the 
previous bug tracker on 12.01.2010 21:47:14 +0100

Found in
Operating System: All
Platform: All

The priority for this issue at migration was Major.

Original description: 
The regress test suite includes many tests that simply reuse the same graphics 
multiple time but with different sizes.

E.g: t100801-c544-valgn-04-d-agi.xhtml uses always the same image but declare 
different heights.

Once the resource is loaded "get" will find an already loaded instance so try 
to 
resize the image to (-1 x height) receiving an 1 x height image. Once the 
scaled 
version is wrongly computed the following layout algo will do wrong 
positioning/sizing.

Basically I had to add the  same algo found in ImageReplacedElement constructor:
---------
} else {
// loaded at base size, need to scale
int w = ir.getImage().getWidth();
int h = ir.getImage().getHeight();

int newW = width;
int newH = height;

    if (newW == -1) {
        newW = (int)(w * ((double)height / h));
    }

if (newH == -1) {
    newH = (int)(h * ((double)newW / w));
}

XRLog.load(Level.FINE, this + ", scaling " + uri + " to " + newW + ", " + 
height);
FSImage awtfsImage = ir.getImage();
BufferedImage newImg = (BufferedImage) ((AWTFSImage) awtfsImage).getImage();

newImg = ImageUtil.getScaledInstance(newImg, newW, newH);
ir = new ImageResource(ir.getImageUri(), AWTFSImage.createImage(newImg));
loaded(ir, newW, newH);
}
-------------

Sorry if this is not a diff, I'm on a branch and I cannot easily create a diff 
against HEAD. It should be simple enough to apply the fix as it mainly 
introduce 
new LOCs.

Original issue reported on code.google.com by pdoubl...@gmail.com on 16 Feb 2011 at 9:47