Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read image vertical alignment form osenv #908

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading