BF [ 1673548 ] Image is not scaled in a report table cell

This commit is contained in:
teo_sarca 2007-03-04 22:00:21 +00:00
parent 69336cd9a0
commit 2c92c25022
3 changed files with 36 additions and 1 deletions

View File

@ -234,6 +234,7 @@ public class ImageElement extends PrintElement
return true; // don't bother scaling and prevent div by 0
// 0 = unlimited so scale to fit restricted dimension
/* teo_sarca, [ 1673548 ] Image is not scaled in a report table cell
if (p_maxWidth * p_maxHeight != 0) // scale to maintain aspect ratio
{
if (p_width/p_height > p_maxWidth/p_maxHeight)
@ -242,6 +243,13 @@ public class ImageElement extends PrintElement
else
m_scaleFactor = p_maxHeight/p_height;
}
*/
m_scaleFactor = 1;
if (p_maxWidth != 0 && p_width > p_maxWidth)
m_scaleFactor = p_maxWidth / p_width;
if (p_maxHeight != 0 && p_height > p_maxHeight && p_maxHeight/p_height < m_scaleFactor)
m_scaleFactor = p_maxHeight / p_height;
p_width = (float) m_scaleFactor * p_width;
p_height = (float) m_scaleFactor * p_height;
}
@ -257,6 +265,18 @@ public class ImageElement extends PrintElement
return m_image;
} // getImage
/**
* Get image scale factor.
*
* @author teo_sarca - [ 1673548 ] Image is not scaled in a report table cell
* @return scale factor
*/
public double getScaleFactor() {
if (!p_sizeCalculated)
p_sizeCalculated = calculateSize();
return m_scaleFactor;
}
/**
* Paint Image
* @param g2D Graphics

View File

@ -1558,6 +1558,9 @@ public class LayoutEngine implements Pageable, Printable, Doc
data[row][col] = ImageElement.get (item.get_ID());
else
data[row][col] = ImageElement.get (item.getImageURL());
// Image layout - teo_sarca, [ 1673548 ]
if (data[row][col] != null)
((ImageElement)data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
}
else if (item.isBarcode())
{

View File

@ -1355,7 +1355,19 @@ public class TableElement extends PrintElement
{
Image imageToDraw = ((ImageElement)printItems[index]).getImage();
if (imageToDraw.getHeight((ImageElement)printItems[index]) != -1)
g2D.drawImage(imageToDraw, curX, (int)penY, this);
{
// Draw image using the scale factor - teo_sarca, [ 1673548 ] Image is not scaled in a report table cell
double scale = ((ImageElement)printItems[index]).getScaleFactor();
if (scale != 1.0) {
AffineTransform transform = new AffineTransform();
transform.translate(curX, penY);
transform.scale(scale, scale);
g2D.drawImage(imageToDraw, transform, this);
}
else {
g2D.drawImage(imageToDraw, curX, (int)penY, this);
}
}
}
else if (printItems[index] instanceof BarcodeElement)
{