Skip to content

Commit

Permalink
Read image vertical alignment form osenv (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-sexenian authored Nov 18, 2024
1 parent 3620111 commit d823680
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions java/src/main/java/com/genexus/reports/PDFReportItext2.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public void GxDrawBitMap(String bitmap, int left, int top, int right, int bottom

log.debug("GxDrawBitMap -> '" + bitmap + "' [" + left + "," + top + "] - Size: (" + (right - left) + "," + (bottom - top) + ")");

if(image != null) { // Si la imagen NO se encuentra, no hago nada
if(image != null) { // Si la imagen NO se encuentra, no hago nada
float rightAux = (float)convertScale(right);
float bottomAux = (float)convertScale(bottom);
float leftAux = (float)convertScale(left);
Expand All @@ -417,11 +417,28 @@ public void GxDrawBitMap(String bitmap, int left, int top, int right, int bottom
image.setAbsolutePosition(leftAux + leftMargin, this.pageSize.getTop() - bottomAux - topMargin - bottomMargin);
if (aspectRatio == 0)
image.scaleAbsolute(rightAux - leftAux , bottomAux - topAux);
else
else {
image.scaleToFit(rightAux - leftAux , bottomAux - topAux);
String verticalAlignment = System.getenv("IMAGE_VERTICAL_ALIGNMENT");
verticalAlignment = (verticalAlignment != null) ? verticalAlignment.toUpperCase() : "";
if (verticalAlignment.equals("TOP") || verticalAlignment.equals("MIDDLE") || verticalAlignment.equals("BOTTOM")) {
float imageHeight = image.getScaledHeight();
float yPosition;
if (verticalAlignment.equals("TOP")) {
yPosition = this.pageSize.getTop() - topAux - imageHeight - topMargin - bottomMargin;
} else if (verticalAlignment.equals("MIDDLE")) {
float centerY = (topAux + bottomAux) / 2;
yPosition = this.pageSize.getTop() - centerY - imageHeight / 2 - topMargin - bottomMargin;
} else {
yPosition = this.pageSize.getTop() - bottomAux - topMargin - bottomMargin;
}
image.setAbsolutePosition(leftAux + leftMargin, yPosition);
}
}
PdfContentByte cb = writer.getDirectContent();
cb.addImage(image);
}

}
catch(DocumentException de) {
log.error("GxDrawBitMap failed:", de);
Expand Down

0 comments on commit d823680

Please sign in to comment.