Skip to content

Commit

Permalink
Fix the image scaling based on the given dimension (#1750) (#1751)
Browse files Browse the repository at this point in the history
* Fix the image scaling based on the given dimension (#1750)
* Exchanged the direct use of the dpi-value to a constant
  • Loading branch information
speckyspooky committed Jun 23, 2024
1 parent 9ec800b commit c553c28
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (c) 2011, 2012, 2013 James Talbut.
* Copyright (c) 2011, 2012, 2013, 2024 James Talbut and others
* jim-emitters@spudsoft.co.uk
*
*
Expand Down Expand Up @@ -143,6 +143,8 @@ public class CellContentHandler extends AbstractHandler {

private static final String STYLE_OVERLAY_DEFAULT_UNIT = "mm";

private static final double DOTS_PER_INCH = 96.0;

/**
* Constructor
*
Expand All @@ -157,6 +159,7 @@ public CellContentHandler(IContentEmitter emitter, Logger log, IHandler parent,
colSpan = 1;
}

@SuppressWarnings("unused")
@Override
public void startCell(HandlerState state, ICellContent cell) throws BirtException {
if (cell.getBookmark() != null) {
Expand Down Expand Up @@ -341,7 +344,7 @@ protected void endCellContent(HandlerState state, ICellContent birtCell, IConten
&& ((lastValue instanceof String) || (lastValue instanceof RichTextString))) {
int spannedRowAlgorithm = EmitterServices.integerOption(state.getRenderOptions(), element,
ExcelEmitter.SPANNED_ROW_HEIGHT, ExcelEmitter.SPANNED_ROW_HEIGHT_SPREAD);
Font defaultFont = state.getWb().getFontAt(cell.getCellStyle().getFontIndexAsInt() /* .getFontIndex() */);
Font defaultFont = state.getWb().getFontAt(cell.getCellStyle().getFontIndex());
double cellWidth = spanWidthMillimetres(state.currentSheet, cell.getColumnIndex(),
cell.getColumnIndex() + colSpan - 1);
float cellDesiredHeight = smu.calculateTextHeightPoints(cell.getStringCellValue(), defaultFont, cellWidth,
Expand Down Expand Up @@ -823,18 +826,36 @@ public void recordImage(HandlerState state, Coordinate location, IImageContent i
+ birtImage.getPhysicalWidthDpi() + "dpi=" + birtImage.getPhysicalWidthInch() + "in) x "
+ birtImage.getHeight() + " (@" + birtImage.getPhysicalHeightDpi() + "dpi="
+ birtImage.getPhysicalHeightInch() + "in)");

if (image.getWidth() == null) {
DimensionType Width = new DimensionType(
(birtImage.getPhysicalWidthInch() > 0) ? birtImage.getPhysicalWidthInch()
: birtImage.getWidth() / 96.0,
"in");
// calculate the width based on the given height and the physical dimensions
DimensionType Width;
if (image.getHeight() != null) {
double factor = birtImage.getWidth() * 1.0 / birtImage.getHeight() * 1.0;
double imgWidth = image.getHeight().getMeasure() * factor;
Width = new DimensionType(imgWidth, image.getHeight().getUnits());
} else {
Width = new DimensionType(
(birtImage.getPhysicalWidthInch() > 0) ? birtImage.getPhysicalWidthInch()
: birtImage.getWidth() / DOTS_PER_INCH,
"in");
}
image.setWidth(Width);
}
if (image.getHeight() == null) {
DimensionType Height = new DimensionType(
(birtImage.getPhysicalHeightInch() > 0) ? birtImage.getPhysicalHeightInch()
: birtImage.getHeight() / 96.0,
"in");
if (image.getHeight() == null && birtImage.getWidth() > 0 && birtImage.getHeight() > 0) {

// calculate the height based on the given width and the physical dimensions
DimensionType Height;
if (image.getWidth() != null) {
double factor = birtImage.getHeight() * 1.0 / birtImage.getWidth() * 1.0;
double imgHeight = image.getWidth().getMeasure() * factor;
Height = new DimensionType(imgHeight, image.getWidth().getUnits());
} else {
Height = new DimensionType(
(birtImage.getPhysicalHeightInch() > 0) ? birtImage.getPhysicalHeightInch()
: birtImage.getHeight() / DOTS_PER_INCH,
"in");
}
image.setHeight(Height);
}
}
Expand Down

0 comments on commit c553c28

Please sign in to comment.