From 7e53d829e26e8c7c0bac8654973be622bbe9d962 Mon Sep 17 00:00:00 2001 From: hengsin Date: Thu, 9 Nov 2023 20:35:15 +0800 Subject: [PATCH] IDEMPIERE-5908 Report parameters are not displayed in full in PDF. (#2099) --- .../compiere/print/layout/GridElement.java | 18 ++-- .../compiere/print/layout/LayoutEngine.java | 1 + .../print/layout/ParameterElement.java | 95 +++++++++++++++++++ 3 files changed, 105 insertions(+), 9 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/layout/GridElement.java b/org.adempiere.base/src/org/compiere/print/layout/GridElement.java index 5beea18553..9c40a363ca 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/GridElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/GridElement.java @@ -70,25 +70,25 @@ public class GridElement extends PrintElement } // GridElement /** Gap between Rows */ - private int m_rowGap = 3; + protected int m_rowGap = 3; /** Gap between Columns */ - private int m_colGap = 5; + protected int m_colGap = 5; /** Rows */ - private int m_rows; + protected int m_rows; /** Columns */ - private int m_cols; + protected int m_cols; /** The Layout Data */ - private TextLayout[][] m_textLayout = null; + protected TextLayout[][] m_textLayout = null; /** Character Iterator */ - private AttributedCharacterIterator[][] m_iterator = null; + protected AttributedCharacterIterator[][] m_iterator = null; /** Row Height */ - private int[] m_rowHeight = null; + protected int[] m_rowHeight = null; /** Column Width */ - private int[] m_colWidth = null; + protected int[] m_colWidth = null; /** Context */ - private FontRenderContext m_frc = new FontRenderContext(null, true, true); + protected FontRenderContext m_frc = new FontRenderContext(null, true, true); /** * Create TextLayout from Data and calculate size. diff --git a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java index 4a5c2efe6f..914f19b6ec 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java +++ b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java @@ -1912,6 +1912,7 @@ public class LayoutEngine implements Pageable, Printable, Doc // ParameterElement pe = new ParameterElement(m_query, m_printCtx, m_format.getTableFormat()); pe.layout(0, 0, false, null); + pe.fitToPage((int) getPaper().getImageableWidth(true)); return pe; } // layoutParameter diff --git a/org.adempiere.base/src/org/compiere/print/layout/ParameterElement.java b/org.adempiere.base/src/org/compiere/print/layout/ParameterElement.java index 531139e2ff..430722f6f6 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/ParameterElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/ParameterElement.java @@ -16,6 +16,15 @@ *****************************************************************************/ package org.compiere.print.layout; +import java.awt.Graphics2D; +import java.awt.font.LineBreakMeasurer; +import java.awt.font.TextLayout; +import java.awt.geom.Point2D; +import java.text.AttributedCharacterIterator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Properties; import org.compiere.model.MQuery; @@ -58,5 +67,91 @@ public class ParameterElement extends GridElement } } // ParameterElement + /** Row:List for parameter value text column */ + private Map> valueTextLayoutMap = new HashMap>(); + + /** + * Fit parameter text to page width + * @param pageWidth + */ + public void fitToPage(int pageWidth) { + //label + parameter name + operator + int offsetWidth = m_colWidth[0] + m_colGap + m_colWidth[1] + m_colGap + m_colWidth[2]; + int maxWidth = pageWidth - offsetWidth; + for (int row = 0; row < m_rows; row++) { + int height = 0; + AttributedCharacterIterator iter = m_iterator[row][3]; + LineBreakMeasurer measurer = new LineBreakMeasurer(iter, m_frc); + while (measurer.getPosition() < iter.getEndIndex()) { + TextLayout layout = measurer.nextLayout(maxWidth); + List layouts = valueTextLayoutMap.get(row); + if (layouts == null) { + layouts = new ArrayList(); + valueTextLayoutMap.put(row, layouts); + } + height = height + ((int)(layout.getAscent() + layout.getDescent() + layout.getLeading())+1); + layouts.add(layout); + } + if (m_rowHeight[row] < height) + m_rowHeight[row] = height; + } + calculateSize(); + } + + /** + * Paint it + * @param g2D Graphics + * @param pageStart top left Location of page + * @param pageNo page number for multi page support (0 = header/footer) - ignored + * @param ctx print context + * @param isView true if online view (IDs are links) + */ + @Override + public void paint(Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView) + { + //fall back to GridElement paint if fitToPage(int pageWidth) is not call + if (valueTextLayoutMap.isEmpty()) + { + super.paint(g2D, pageNo, pageStart, ctx, isView); + return; + } + + Point2D.Double location = getAbsoluteLocation(pageStart); + float y = (float)location.y; + // + for (int row = 0; row < m_rows; row++) + { + float x = (float)location.x; + for (int col = 0; col < m_cols; col++) + { + //use valueTextLayoutMap for parameter value text column + if (col == 3 && valueTextLayoutMap.get(row) != null) + { + List layouts = valueTextLayoutMap.get(row); + float curY = y; + for(TextLayout layout : layouts) + { + curY = curY + layout.getAscent(); + layout.draw(g2D, x, curY); + curY += m_rowGap; + } + } + else + { + if (m_textLayout[row][col] != null) + { + float yy = y + m_textLayout[row][col].getAscent(); + m_textLayout[row][col].draw(g2D, x, yy); + } + x += m_colWidth[col]; + if (m_colWidth[col] > 0) + x += m_colGap; + } + } + y += m_rowHeight[row]; + if (m_rowHeight[row] > 0) + y += m_rowGap; + } + } // paint } // ParameterElement