Browse Source

Pull request #8635: KERNEL-10665 图片导出优化

Merge in DESIGN/design from ~VITO/c-design:feature/x to feature/x

* commit 'fd32268176d2c78b6b24fbfa9eeead2ce4d55625':
  KERNEL-10665 图片导出优化
feature/x
vito 3 years ago
parent
commit
150b050a3e
  1. 77
      designer-base/src/main/java/com/fr/design/ui/util/GraphicsConfig.java
  2. 242
      designer-realize/src/main/java/com/fr/design/report/ImageExportPane.java
  3. 9
      designer-realize/src/main/java/com/fr/design/report/ReportExportAttrPane.java
  4. 8
      designer-realize/src/main/java/com/fr/grid/GridUI.java
  5. 2
      designer-realize/src/main/java/com/fr/start/common/SplashPane.java

77
designer-base/src/main/java/com/fr/design/ui/util/GraphicsConfig.java

@ -1,77 +0,0 @@
package com.fr.design.ui.util;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Map;
/**
* 图形渲染配置
*
* @author vito
* @version 10.0
* Created by vito on 2019/9/18
*/
public class GraphicsConfig {
private final Graphics2D myG;
private final Map myHints;
private final Composite myComposite;
private final Stroke myStroke;
public GraphicsConfig(@NotNull Graphics g) {
myG = (Graphics2D) g;
myHints = (Map) myG.getRenderingHints().clone();
myComposite = myG.getComposite();
myStroke = myG.getStroke();
}
public GraphicsConfig setAntialiasing(boolean on) {
myG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, on ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
return this;
}
public GraphicsConfig setAlpha(float alpha) {
myG.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
return this;
}
public GraphicsConfig setRenderingHint(RenderingHints.Key hintKey, Object hintValue) {
myG.setRenderingHint(hintKey, hintValue);
return this;
}
public Graphics2D getG() {
return myG;
}
public GraphicsConfig setComposite(Composite composite) {
myG.setComposite(composite);
return this;
}
public GraphicsConfig setStroke(Stroke stroke) {
myG.setStroke(stroke);
return this;
}
public GraphicsConfig setupAAPainting() {
return setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
}
public GraphicsConfig disableAAPainting() {
return setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)
.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
}
public GraphicsConfig paintWithAlpha(float alpha) {
assert 0.0f <= alpha && alpha <= 1.0f : "alpha should be in range 0.0f .. 1.0f";
return setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
}
public void restore() {
myG.setRenderingHints(myHints);
myG.setComposite(myComposite);
myG.setStroke(myStroke);
}
}

242
designer-realize/src/main/java/com/fr/design/report/ImageExportPane.java

@ -0,0 +1,242 @@
package com.fr.design.report;
import com.fr.base.extension.FileExtension;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.io.attr.ImageExportAttr;
import com.fr.io.attr.ReportExportAttr;
import com.fr.report.ReportConfigManager;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
/**
* 导出图片配置
*
* @author vito
* @date 2015/7/6 0006
*/
public class ImageExportPane extends AbstractExportPane {
private UIRadioButton globalResolutionBtnS;
private UIRadioButton globalResolutionBtnM;
private UIRadioButton globalResolutionBtnL;
private UIRadioButton globalRenderSpeed;
private UIRadioButton globalRenderQuality;
private UIRadioButton globalFormatJpg;
private UIRadioButton globalFormatPng;
private UIRadioButton previewResolutionBtnS;
private UIRadioButton previewResolutionBtnM;
private UIRadioButton previewRenderSpeed;
private UIRadioButton previewRenderQuality;
private static final int RESOLUTION_S = 96;
private static final int RESOLUTION_M = 192;
private static final int RESOLUTION_L = 300;
private static final int DPI_SCALE_S = 1;
private static final int DPI_SCALE_M = 2;
private static final int GAP = 20;
public static final String GLOBAL_CONF = Toolkit.i18nText("Fine-Design_Image_Export_Global_Configuration");
private ReportExportAttr reportExportAttr;
public ImageExportPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JPanel globalTitlePane = FRGUIPaneFactory.createTitledBorderPane(GLOBAL_CONF);
JPanel previewSetting = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_Preview"));
this.add(globalTitlePane, BorderLayout.NORTH);
this.add(previewSetting, BorderLayout.CENTER);
initGlobalSettings();
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
JComponent[][] comps = {
{new UILabel(Toolkit.i18nText("Fine-Design_Image_Export_Resolution") + ":"), this.globalResolutionBtnS, this.globalResolutionBtnM, this.globalResolutionBtnL},
{new UILabel(Toolkit.i18nText("Fine-Design_Report_Format") + ":"), this.globalFormatJpg, null, this.globalFormatPng},
{new UILabel(Toolkit.i18nText("Fine-Design_Image_Export_Rendering_Quality") + ":"), this.globalRenderQuality, null, this.globalRenderSpeed},
};
centerPane.add(
TableLayoutHelper.createCommonTableLayoutPane(
comps,
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
GAP),
BorderLayout.CENTER);
globalTitlePane.add(centerPane, BorderLayout.CENTER);
JPanel templateCenterPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
JComponent[][] templateComps = {
{new UILabel(Toolkit.i18nText("Fine-Design_Report_Engine_Enlarge_Or_Reduce") + ":"), this.previewResolutionBtnS, this.previewResolutionBtnM},
{new UILabel(Toolkit.i18nText("Fine-Design_Image_Export_Rendering_Quality") + ":"), this.previewRenderQuality, this.previewRenderSpeed},
};
templateCenterPane.add(
TableLayoutHelper.createCommonTableLayoutPane(
templateComps,
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
GAP),
BorderLayout.CENTER);
previewSetting.add(templateCenterPane, BorderLayout.CENTER);
}
private void initGlobalSettings() {
globalResolutionBtnS = new UIRadioButton("96dpi", true);
globalResolutionBtnM = new UIRadioButton("192dpi");
globalResolutionBtnL = new UIRadioButton("300dpi");
ButtonGroup globalResolutionBtnGroup = new ButtonGroup();
globalResolutionBtnGroup.add(globalResolutionBtnS);
globalResolutionBtnGroup.add(globalResolutionBtnM);
globalResolutionBtnGroup.add(globalResolutionBtnL);
globalFormatJpg = new UIRadioButton("jpg", true);
globalFormatPng = new UIRadioButton("png");
ButtonGroup globalFormatGroup = new ButtonGroup();
globalFormatGroup.add(globalFormatJpg);
globalFormatGroup.add(globalFormatPng);
globalRenderQuality = new UIRadioButton("Fine-Design_Image_Export_Quality_First", true);
globalRenderSpeed = new UIRadioButton("Fine-Design_Image_Export_Speed_Priority");
ButtonGroup globalRenderGroup = new ButtonGroup();
globalRenderGroup.add(globalRenderQuality);
globalRenderGroup.add(globalRenderSpeed);
previewResolutionBtnS = new UIRadioButton("100%", true);
previewResolutionBtnM = new UIRadioButton("200%");
ButtonGroup previewResolutionBtnGroup = new ButtonGroup();
previewResolutionBtnGroup.add(previewResolutionBtnS);
previewResolutionBtnGroup.add(previewResolutionBtnM);
previewRenderSpeed = new UIRadioButton("Fine-Design_Image_Export_Speed_Priority");
previewRenderQuality = new UIRadioButton("Fine-Design_Image_Export_Quality_First");
ButtonGroup previewRenderGroup = new ButtonGroup();
previewRenderGroup.add(previewRenderQuality);
previewRenderGroup.add(previewRenderSpeed);
}
/**
* 展示界面
*/
@Override
public void populate(Object exportAttr) {
populateBean(exportAttr);
}
/**
* 提交数据
*
* @return 界面上的更新数据
*/
@Override
public void update(Object exportAttr) {
updateBean();
}
private ImageExportAttr getGlobalImageExportAttr() {
return ReportConfigManager.getProviderInstance().getImageExportAttr();
}
/**
* 标题
*
* @return 标题
*/
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Image_Export_Export_Image_Setting");
}
@Override
public void populateBean(Object exportAttr) {
ImageExportAttr attr = getGlobalImageExportAttr();
switch (attr.getResolution()) {
case 192:
globalResolutionBtnM.setSelected(true);
break;
case 300:
globalResolutionBtnL.setSelected(true);
break;
default:
globalResolutionBtnS.setSelected(true);
}
if (FileExtension.PNG.getExtension().equals(attr.getFormat())) {
globalFormatPng.setSelected(true);
} else {
globalFormatJpg.setSelected(true);
}
if (attr.getRenderQuality() == ImageExportAttr.RENDER_SPEED) {
globalRenderSpeed.setSelected(true);
} else {
globalRenderQuality.setSelected(true);
}
if (attr.getPreviewRenderQuality() == ImageExportAttr.RENDER_SPEED) {
previewRenderSpeed.setSelected(true);
} else {
previewRenderQuality.setSelected(true);
}
if (attr.getPreviewResolutionScale() == DPI_SCALE_S) {
previewResolutionBtnS.setSelected(true);
} else {
previewResolutionBtnM.setSelected(true);
}
}
@Override
public void updateBean(Object exportAttr) {
ImageExportAttr attr = getGlobalImageExportAttr();
if (globalResolutionBtnS.isSelected()) {
attr.setResolution(RESOLUTION_S);
} else if (globalResolutionBtnM.isSelected()) {
attr.setResolution(RESOLUTION_M);
} else {
attr.setResolution(RESOLUTION_L);
}
if (globalFormatPng.isSelected()) {
attr.setFormat(FileExtension.PNG.getExtension());
} else {
attr.setFormat(FileExtension.JPG.getExtension());
}
if (globalRenderSpeed.isSelected()) {
attr.setRenderQuality(ImageExportAttr.RENDER_SPEED);
} else {
attr.setRenderQuality(ImageExportAttr.RENDER_QUALITY);
}
if (previewRenderSpeed.isSelected()) {
attr.setPreviewRenderQuality(ImageExportAttr.RENDER_SPEED);
} else {
attr.setPreviewRenderQuality(ImageExportAttr.RENDER_QUALITY);
}
if (previewResolutionBtnS.isSelected()) {
attr.setPreviewResolutionScale(DPI_SCALE_S);
} else {
attr.setPreviewResolutionScale(DPI_SCALE_M);
}
}
@Override
public String getTitle() {
return "Image";
}
}

9
designer-realize/src/main/java/com/fr/design/report/ReportExportAttrPane.java

@ -14,13 +14,14 @@ import java.util.Set;
public class ReportExportAttrPane extends BasicPane { public class ReportExportAttrPane extends BasicPane {
UITabbedPane uiTabbedPane;
private ExcelExportPane excelExportPane; private ExcelExportPane excelExportPane;
private PDFExportPane pdfExportPane; private PDFExportPane pdfExportPane;
private WordExportPane wordExportPane; private WordExportPane wordExportPane;
private List<BasicStorePane<?>> paneList; private List<BasicStorePane<?>> paneList;
public ReportExportAttrPane() { public ReportExportAttrPane() {
UITabbedPane uiTabbedPane = new UITabbedPane(); uiTabbedPane = new UITabbedPane();
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
excelExportPane = new ExcelExportPane(); excelExportPane = new ExcelExportPane();
@ -31,6 +32,7 @@ public class ReportExportAttrPane extends BasicPane {
uiTabbedPane.addTab("Word", wordExportPane); uiTabbedPane.addTab("Word", wordExportPane);
Set<ExportAttrTabProvider> providers = ExtraDesignClassManager.getInstance().getArray(ExportAttrTabProvider.XML_TAG); Set<ExportAttrTabProvider> providers = ExtraDesignClassManager.getInstance().getArray(ExportAttrTabProvider.XML_TAG);
paneList = new ArrayList<>(); paneList = new ArrayList<>();
initPane(new ImageExportPane());
for (ExportAttrTabProvider provider : providers) { for (ExportAttrTabProvider provider : providers) {
BasicStorePane<?> storePane = provider.toServiceComponent(); BasicStorePane<?> storePane = provider.toServiceComponent();
uiTabbedPane.addTab(storePane.getTitle(), storePane); uiTabbedPane.addTab(storePane.getTitle(), storePane);
@ -39,6 +41,11 @@ public class ReportExportAttrPane extends BasicPane {
this.add(uiTabbedPane); this.add(uiTabbedPane);
} }
private void initPane(BasicStorePane<?> exportPane) {
uiTabbedPane.addTab(exportPane.getTitle(), exportPane);
paneList.add(exportPane);
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_ReportD_Excel_Export"); return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_ReportD_Excel_Export");

8
designer-realize/src/main/java/com/fr/grid/GridUI.java

@ -406,7 +406,7 @@ public class GridUI extends ComponentUI {
rowHeight = gridRange.rowHeightList.get(i); rowHeight = gridRange.rowHeightList.get(i);
paperYAxisSumSize = paperYAxisSumSize.add(rowHeight); paperYAxisSumSize = paperYAxisSumSize.add(rowHeight);
if (showGridLine) { if (showGridLine) {
UNIT columnWidth, xAxisSumSize = FU.getInstance(0); UNIT columnWidth, xAxisSumSize = FU.getInstance(0);
for (int j = gridRange.xBeginIndex; j <= gridRange.xEndIndex; j++) { for (int j = gridRange.xBeginIndex; j <= gridRange.xEndIndex; j++) {
columnWidth = gridRange.columnWidthList.get(j); columnWidth = gridRange.columnWidthList.get(j);
if (!mergeCellElementTable.get(CellPosition.value(i - 1, j)).contains(CellPosition.BOTTOM)) { if (!mergeCellElementTable.get(CellPosition.value(i - 1, j)).contains(CellPosition.BOTTOM)) {
@ -1018,7 +1018,7 @@ public class GridUI extends ComponentUI {
g2d.translate(floatX, floatY); g2d.translate(floatX, floatY);
PaintUtils.paintFloatElement(g2d, tmpFloatElement, PaintUtils.paintFloatElementWithBackgroundAndBorder(g2d, tmpFloatElement,
tmpFloatElement.getWidth().toPixI(resolution), tmpFloatElement.getWidth().toPixI(resolution),
tmpFloatElement.getHeight().toPixI(resolution), resolution); tmpFloatElement.getHeight().toPixI(resolution), resolution);
@ -1220,8 +1220,8 @@ public class GridUI extends ComponentUI {
Stroke oldStroke = g2d.getStroke(); Stroke oldStroke = g2d.getStroke();
g2d.setPaint(Color.black); g2d.setPaint(Color.black);
g2d.setStroke(GraphDrawHelper.getStroke(Constants.LINE_DASH_DOT)); g2d.setStroke(GraphDrawHelper.getStroke(Constants.LINE_DASH_DOT));
g2d.drawLine( 0, height, width, height); g2d.drawLine(0, height, width, height);
g2d.drawLine( width, 0, width, height); g2d.drawLine(width, 0, width, height);
g2d.setPaint(oldPaint); g2d.setPaint(oldPaint);
g2d.setStroke(oldStroke); g2d.setStroke(oldStroke);
} }

2
designer-realize/src/main/java/com/fr/start/common/SplashPane.java

@ -4,7 +4,7 @@ import com.bulenkov.iconloader.IconLoader;
import com.bulenkov.iconloader.util.JBUI; import com.bulenkov.iconloader.util.JBUI;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.design.locale.impl.SplashMark; import com.fr.design.locale.impl.SplashMark;
import com.fr.design.ui.util.GraphicsConfig; import com.fr.stable.GraphicsConfig;
import com.fr.general.locale.LocaleCenter; import com.fr.general.locale.LocaleCenter;
import com.fr.general.locale.LocaleMark; import com.fr.general.locale.LocaleMark;
import com.fr.stable.GraphDrawHelper; import com.fr.stable.GraphDrawHelper;

Loading…
Cancel
Save