From 9336b1d7f2bbfeca698185df75cb2943e7e1649b Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Thu, 16 Dec 2021 17:07:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-62440=20=E8=A1=A8=E5=A4=B4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E5=86=85=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sort/header/HeaderSortRulePane.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java index 71ecf9ced..9b1de9477 100644 --- a/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java +++ b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java @@ -10,6 +10,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.theme.edit.ui.ColorListPane; import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; import com.fr.report.core.sort.header.SortHeader; import com.fr.report.core.sort.common.SortRule; import org.apache.batik.transcoder.TranscoderInput; @@ -21,7 +22,10 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; public class HeaderSortRulePane extends JPanel { private static final String ASC_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/asc.svg"; @@ -33,6 +37,7 @@ public class HeaderSortRulePane extends JPanel { UICheckBox ascUICheckBox; UICheckBox desUICheckBox; UICheckBox nosortUICheckBox; + static Map originalSvgTextMap = new HashMap<>(); HeaderSortRulePane() { initComponents(); @@ -166,19 +171,27 @@ public class HeaderSortRulePane extends JPanel { Icon getIcon(String iconPath, Color color) { try { - InputStream inputStream = IOUtils.getResourceAsStream(iconPath, HeaderSortRulePane.class); - String svgText = getSvgText(inputStream); - svgText = svgText.replaceAll("\\{fillColor\\}", shiftColor(color)); - InputStream svgInputStream = new ByteArrayInputStream(svgText.getBytes()); + String originalSvgText = getOriginalSvgText(iconPath); + String svgText = originalSvgText.replaceAll("\\{fillColor\\}", shiftColor(color)); + InputStream svgInputStream = new ByteArrayInputStream(svgText.getBytes(StandardCharsets.UTF_8)); TranscoderInput input = new TranscoderInput(svgInputStream); - bufferedImage = SVGTranscoder.createImage(1.0, input).getImage(); + bufferedImage = SVGTranscoder.createImage(SVGIcon.SYSTEM_SCALE, input).getImage(); SVGIcon svgIcon = new SVGIcon(bufferedImage); return svgIcon; } catch (Exception e) { - + FineLoggerFactory.getLogger().error(e, e.getMessage()); } return null; + } + String getOriginalSvgText(String iconPath) throws Exception { + String originalSvgText = originalSvgTextMap.get(iconPath); + if (originalSvgText == null) { + InputStream inputStream = IOUtils.getResourceAsStream(iconPath, HeaderSortRulePane.class); + originalSvgText = getSvgText(inputStream); + originalSvgTextMap.put(iconPath, originalSvgText); + } + return originalSvgText; } String shiftColor(Color color) {