Browse Source

REPORT-92440 mac-数据源带叹号的宽度不正常

release/11.0
obo 2 years ago
parent
commit
e59b18264a
  1. 26
      designer-base/src/main/java/com/fr/design/icon/WarningIcon.java
  2. 3
      designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java

26
designer-base/src/main/java/com/fr/design/icon/WarningIcon.java

@ -1,12 +1,17 @@
package com.fr.design.icon;
import com.fr.base.svg.SVGLoader;
import com.fr.base.svg.SystemScaleUtils;
import com.fr.design.utils.SvgPaintUtils;
import com.fr.log.FineLoggerFactory;
import javax.swing.GrayFilter;
import javax.swing.ImageIcon;
import java.awt.*;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.ImageObserver;
/**
@ -20,7 +25,8 @@ public class WarningIcon extends ImageIcon {
};
protected final static MediaTracker TRACKER = new MediaTracker(COMPONENT);
private final static Image WARNING_IMAGE = SVGLoader.load("/com/fr/design/standard/warning.svg");
private static final boolean HI_DPI_SUPPORT = SystemScaleUtils.isJreHiDPIEnabled();
public static final float SYSTEM_SCALE = SystemScaleUtils.sysScale();
private Image mainImage = null;
private ImageObserver imageObserver;
private int width = -1;
@ -36,14 +42,16 @@ public class WarningIcon extends ImageIcon {
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
SvgPaintUtils.beforePaint((Graphics2D) g);
//裁剪绘制svg的位置,以免影响到图标右侧的文字
Graphics2D graphics = (Graphics2D) g.create(x, y, WARNING_IMAGE.getWidth(null), WARNING_IMAGE.getHeight(null));
SvgPaintUtils.beforePaint(graphics);
if (mainImage != null) {
g.drawImage(mainImage, x, y, c);
graphics.drawImage(mainImage, x, y, null);
}
if (WARNING_IMAGE != null) {
g.drawImage(WARNING_IMAGE, x, y, c);
graphics.drawImage(WARNING_IMAGE, x, y, null);
}
SvgPaintUtils.afterPaint((Graphics2D) g);
SvgPaintUtils.afterPaint(graphics);
}
/**
@ -91,7 +99,8 @@ public class WarningIcon extends ImageIcon {
* @return the width in pixels of this icon
*/
public int getIconWidth() {
return width;
//如果环境支持高清化,drawImage可能会缩放绘制的图像比例,需要保证svg正常显示的同时调整绘制范围
return HI_DPI_SUPPORT ? (int) (width / SYSTEM_SCALE) : width;
}
/**
@ -100,7 +109,8 @@ public class WarningIcon extends ImageIcon {
* @return the height in pixels of this icon
*/
public int getIconHeight() {
return height;
//如果环境支持高清化,drawImage可能会缩放绘制的图像比例,需要保证svg正常显示的同时调整绘制范围
return HI_DPI_SUPPORT ? (int) (height / SYSTEM_SCALE) : height;
}
{

3
designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java

@ -2,6 +2,7 @@ package com.fr.design.utils;
import com.fr.base.svg.SVGLoader;
import com.fr.base.svg.SystemScaleUtils;
import java.awt.Graphics2D;
/**
@ -21,7 +22,7 @@ public class SvgPaintUtils {
public static void afterPaint(Graphics2D g2) {
if (SystemScaleUtils.isJreHiDPIEnabled()) {
g2.scale(SVGLoader.SYSTEM_SCALE, SVGLoader.SYSTEM_SCALE);
g2.scale(1.0D, 1.0D);
}
}

Loading…
Cancel
Save