From 5df6bf5477ff065e9d430c021fa2f7c42f01f76c Mon Sep 17 00:00:00 2001 From: obo Date: Fri, 24 Mar 2023 15:46:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-92439=20=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E8=AE=A1=E7=AE=97svg=E4=BD=8D=E7=BD=AEx,y=E7=9A=84=E5=86=99?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../icontainer/UIEastResizableContainer.java | 6 +---- .../gui/icontainer/UIResizableContainer.java | 18 ++++---------- .../mainframe/EastRegionContainerPane.java | 6 +---- .../com/fr/design/utils/SvgPaintUtils.java | 24 +++++++++++++++++-- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java index 17511d391e..2a9fcacb82 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java +++ b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java @@ -1,8 +1,6 @@ package com.fr.design.gui.icontainer; -import com.fr.base.svg.SVGLoader; -import com.fr.base.svg.SystemScaleUtils; import com.fr.design.base.mode.DesignModeContext; import com.fr.design.constants.UIConstants; import com.fr.design.gui.ibutton.UIButton; @@ -342,9 +340,7 @@ public class UIEastResizableContainer extends JPanel { } SvgPaintUtils.beforePaint((Graphics2D) g); //如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整 - int x = SystemScaleUtils.isJreHiDPIEnabled() ? (int) (10 * SVGLoader.SYSTEM_SCALE) : 10; - int y = SystemScaleUtils.isJreHiDPIEnabled() ? (int) (7 * SVGLoader.SYSTEM_SCALE) : 7; - g.drawImage(button, x, y, null); + g.drawImage(button, SvgPaintUtils.calculatePositionX(10), SvgPaintUtils.calculatePositionY(7), null); SvgPaintUtils.afterPaint((Graphics2D) g); } } diff --git a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java index cbc175a0d9..44806b3bf9 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java +++ b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java @@ -1,7 +1,5 @@ package com.fr.design.gui.icontainer; -import com.fr.base.svg.SVGLoader; -import com.fr.base.svg.SystemScaleUtils; import com.fr.base.vcs.DesignerMode; import com.fr.design.constants.UIConstants; import com.fr.design.mainframe.DesignerContext; @@ -29,8 +27,6 @@ import java.awt.event.MouseMotionListener; public class UIResizableContainer extends JPanel { private static final long serialVersionUID = 1854340560790476907L; private static final int MAX_PARA_HEIGHT = 240; - private final boolean HI_DPI_SUPPORT = SystemScaleUtils.isJreHiDPIEnabled(); - private int containerWidth = 240; private int preferredWidth = 240; private int toolPaneY = 300; @@ -428,12 +424,9 @@ public class UIResizableContainer extends JPanel { g.drawImage(UIConstants.DRAG_BAR_LIGHT, 0, 0, getWidth(), getHeight(), null); SvgPaintUtils.beforePaint((Graphics2D) g); //如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整 - int dragLineX = HI_DPI_SUPPORT ? (int) ((getWidth() - toolPaneHeight) / 2 * SVGLoader.SYSTEM_SCALE) : (getWidth() - toolPaneHeight) / 2; - int dragLineY = HI_DPI_SUPPORT ? (int) (3 * SVGLoader.SYSTEM_SCALE) : 3; - int downButtonX = HI_DPI_SUPPORT ? (int) ((getWidth() - toolPaneHeight - ARROW_MARGIN) * SVGLoader.SYSTEM_SCALE) : (getWidth() - toolPaneHeight - ARROW_MARGIN); - g.drawImage(UIConstants.DRAG_LINE, dragLineX, dragLineY, null); + g.drawImage(UIConstants.DRAG_LINE, SvgPaintUtils.calculatePositionX((getWidth() - toolPaneHeight) / 2), SvgPaintUtils.calculatePositionY(3), null); g.drawImage(upButton, ARROW_MARGIN, 0, null); - g.drawImage(downButton, downButtonX, 0, null); + g.drawImage(downButton, SvgPaintUtils.calculatePositionX(getWidth() - toolPaneHeight - ARROW_MARGIN), 0, null); SvgPaintUtils.afterPaint((Graphics2D) g); } } @@ -533,9 +526,7 @@ public class UIResizableContainer extends JPanel { } SvgPaintUtils.beforePaint((Graphics2D) g); //如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整 - int x = HI_DPI_SUPPORT ? (int) (-6 * SVGLoader.SYSTEM_SCALE) : -6; - int y = HI_DPI_SUPPORT ? (int) (ARROW_MARGIN_VERTICAL * SVGLoader.SYSTEM_SCALE) : ARROW_MARGIN_VERTICAL; - g.drawImage(button, x, y, this); + g.drawImage(button, SvgPaintUtils.calculatePositionX(-6), SvgPaintUtils.calculatePositionY(ARROW_MARGIN_VERTICAL), this); SvgPaintUtils.afterPaint((Graphics2D) g); } else { g.drawImage(UIConstants.DRAG_BAR_LIGHT, 0, 0, toolPaneHeight, getHeight(), null); @@ -552,8 +543,7 @@ public class UIResizableContainer extends JPanel { button = UIConstants.DRAG_RIGHT_PRESS; } } - int x = HI_DPI_SUPPORT ? (int) (10 * SVGLoader.SYSTEM_SCALE) : 10; - g.drawImage(button, x, ARROW_MARGIN_VERTICAL, this); + g.drawImage(button, SvgPaintUtils.calculatePositionX(10), ARROW_MARGIN_VERTICAL, this); } if (isLeftRightDragEnabled) { g.drawImage(UIConstants.DRAG_DOT_VERTICAL, 2, getHeight() / 2, 5, toolPaneHeight, null); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java index 7ac1aac409..b460e1e31d 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java @@ -2,8 +2,6 @@ package com.fr.design.mainframe; import com.fr.base.FRContext; import com.fr.base.svg.IconUtils; -import com.fr.base.svg.SVGLoader; -import com.fr.base.svg.SystemScaleUtils; import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; @@ -1318,9 +1316,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer { } SvgPaintUtils.beforePaint((Graphics2D) g); //如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整 - int x = SystemScaleUtils.isJreHiDPIEnabled() ? (int) ((ARROW_RANGE_START + 8) * SVGLoader.SYSTEM_SCALE) : (ARROW_RANGE_START + 8); - int y = SystemScaleUtils.isJreHiDPIEnabled() ? (int) (4 * SVGLoader.SYSTEM_SCALE) : 4; - g.drawImage(button, x, y, null); + g.drawImage(button, SvgPaintUtils.calculatePositionX(ARROW_RANGE_START + 8), SvgPaintUtils.calculatePositionY(4), null); SvgPaintUtils.afterPaint((Graphics2D) g); } } diff --git a/designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java b/designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java index a51783d8fa..85e34caba2 100644 --- a/designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java @@ -14,16 +14,36 @@ import java.awt.Graphics2D; */ public class SvgPaintUtils { + private static final boolean HI_DPI_ENABLED = SystemScaleUtils.isJreHiDPIEnabled(); + public static void beforePaint(Graphics2D g2) { - if (SystemScaleUtils.isJreHiDPIEnabled()) { + if (HI_DPI_ENABLED) { g2.scale(1 / SVGLoader.SYSTEM_SCALE, 1 / SVGLoader.SYSTEM_SCALE); } } public static void afterPaint(Graphics2D g2) { - if (SystemScaleUtils.isJreHiDPIEnabled()) { + if (HI_DPI_ENABLED) { g2.scale(1.0D, 1.0D); } } + /** + * 计算高缩放下绘制svg图标时新的的位置x + * @param x 旧x的值 + * @return 新的x值 + * */ + public static int calculatePositionX(int x) { + return HI_DPI_ENABLED ? (int) (x * SVGLoader.SYSTEM_SCALE) : x; + } + + /** + * 计算高缩放下绘制svg图标时新的的位置y + * @param y 旧y的值 + * @return 新的y值 + * */ + public static int calculatePositionY(int y) { + return HI_DPI_ENABLED ? (int) (y * SVGLoader.SYSTEM_SCALE) : y; + } + }