From afc565d2e10d7636a8fca32f2ce0ff0c4bba29a0 Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 1 Dec 2022 16:06:59 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-85708=20FR10=E5=86=B3=E7=AD=96=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8-=E8=AE=BE=E8=AE=A1=E7=94=BB=E5=B8=83=E5=86=85?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E8=A1=A8=E5=9D=97=E7=9A=84=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 问题产生的原因有两点: 1. 生成的截图内容不全,只包含了表格可见部分内容 2. 使用报表块的尺寸对原始截图裁切时,裁切的尺寸不对 10.0/11.0都有此问题 【改动思路】 1. 对表格进行截图时,要使得表格可以绘制所有有内容的单元格 2. 当报表块创建或尺寸改变时,在handleSizeChange方法中通知修改裁切尺寸 --- .../form/FormElementCaseDesigner.java | 70 ++++++++++++++----- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java index 5be6362a4d..e2af5b36f2 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCaseDesigner.java @@ -3,6 +3,8 @@ */ package com.fr.design.mainframe.form; +import com.fr.base.DynamicUnitList; +import com.fr.base.GraphHelper; import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignState; import com.fr.design.actions.AllowAuthorityEditAction; @@ -31,13 +33,18 @@ import com.fr.design.selection.SelectionListener; import com.fr.form.FormElementCaseProvider; import com.fr.form.main.Form; import com.fr.grid.Grid; +import com.fr.grid.GridUtils; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.Selection; import com.fr.log.FineLoggerFactory; +import com.fr.report.ReportHelper; import com.fr.report.cell.CellElement; +import com.fr.report.elementcase.ElementCase; import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.worksheet.FormElementCase; import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ColumnRow; +import com.fr.stable.Constants; import javax.swing.JComponent; import javax.swing.JPanel; @@ -122,16 +129,23 @@ public class FormElementCaseDesigner } /** - * 获取当前ElementCase的缩略图 + * 获取当前ElementCase的缩略图, 缩略图中包含所有有内容的单元格 * * @param size 缩略图的大小 */ @Override public BufferedImage getElementCaseImage(Dimension size) { + Grid grid = this.elementCasePane != null ? this.elementCasePane.getGrid() : null; + if (grid == null) { + return new BufferedImage(0, 0, BufferedImage.TYPE_INT_RGB); + } + + resetGrid(grid); + BufferedImage image = null; try { - int width = size.width; - int height = size.height; + int width = Math.max(grid.getWidth(), size.width); + int height = Math.max(grid.getHeight(), size.width); // 使用TYPE_INT_RGB和new Color(255, 255, 255, 1)设置有透明背景buffer image, // 使得创建出来的透明像素是(255, 255, 255, 1),而不是(0, 0, 0, 0) @@ -147,19 +161,16 @@ public class FormElementCaseDesigner // 使得创建出来的透明像素是(255, 255, 255, 1),而不是(0, 0, 0, 0) // 这样不支持透明通道缩略图的旧设计器打开新设计器创建的模版时,就不会创建出拥有黑色背景的缩略图 g2d.setColor(new Color(255, 255, 255, 1)); - g2d.fillRect(0, 0, (int) size.getWidth(), (int) size.getHeight()); - - Grid grid = this.elementCasePane != null ? this.elementCasePane.getGrid() : null; - if (grid != null) { - boolean oldTranslucent = grid.isTranslucent(); - boolean oldShowExtraGridLine = grid.isShowExtraGridLine(); - // 截缩图图时grid需支持半透明,不能用默认白色填充画布,否则会遮挡组件样式背景 - grid.setTranslucent(true); - grid.setShowExtraGridLine(false); - grid.paint(g2d); - grid.setTranslucent(oldTranslucent); - grid.setShowExtraGridLine(oldShowExtraGridLine); - } + g2d.fillRect(0, 0, width, height); + + boolean oldTranslucent = grid.isTranslucent(); + boolean oldShowExtraGridLine = grid.isShowExtraGridLine(); + // 截缩图图时grid需支持半透明,不能用默认白色填充画布,否则会遮挡组件样式背景 + grid.setTranslucent(true); + grid.setShowExtraGridLine(false); + grid.paint(g2d); + grid.setTranslucent(oldTranslucent); + grid.setShowExtraGridLine(oldShowExtraGridLine); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); @@ -168,6 +179,33 @@ public class FormElementCaseDesigner return image; } + private void resetGrid(Grid grid) { + grid.setVerticalValue(0); + grid.setHorizontalValue(0); + + FormElementCasePaneDelegate reportPane = getEditingElementCasePane(); + ColumnRow lastColumnRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane); + + int lastColumn = lastColumnRow.getColumn(); + int lastRow = lastColumnRow.getRow(); + + grid.setVerticalExtent(lastRow); + grid.setHorizontalExtent(lastColumn); + + ElementCase report = reportPane.getEditingElementCase(); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + + int resolution = grid.getResolution(); + int width = columnWidthList.getRangeValueFromZero(lastColumn).toPixI(resolution); + int height = rowHeightList.getRangeValueFromZero(lastRow).toPixI(resolution); + + int gridLineWidth = GraphHelper.getLineStyleSize(Constants.LINE_THIN); + grid.setSize(width + gridLineWidth, height + gridLineWidth); + + grid.updateUI(); + } + /** * 刷新右侧属性面板 */