Browse Source

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

newui
obo 2 years ago
parent
commit
0b8b849e2e
  1. 6
      designer-base/src/main/java/com/fr/design/icon/WarningIcon.java
  2. 2
      designer-base/src/main/java/com/fr/design/utils/SvgDraw.java
  3. 24
      designer-base/src/main/java/com/fr/design/utils/SvgDrawUtils.java

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

@ -2,7 +2,7 @@ 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.design.utils.SvgDrawUtils;
import com.fr.log.FineLoggerFactory;
import javax.swing.GrayFilter;
@ -45,10 +45,10 @@ public class WarningIcon extends ImageIcon {
//裁剪绘制svg的位置,以免影响到图标右侧的文字
Graphics2D graphics = (Graphics2D) g.create(x, y, WARNING_IMAGE.getWidth(null), WARNING_IMAGE.getHeight(null));
if (mainImage != null) {
SvgPaintUtils.doDrawSVG(graphics, () -> SvgPaintUtils.drawImage(graphics, mainImage, x, y, null));
SvgDrawUtils.doDrawSVG(graphics, () -> SvgDrawUtils.drawImage(graphics, mainImage, x, y, null));
}
if (WARNING_IMAGE != null) {
SvgPaintUtils.doDrawSVG(graphics, () -> SvgPaintUtils.drawImage(graphics, WARNING_IMAGE, x, y, null));
SvgDrawUtils.doDrawSVG(graphics, () -> SvgDrawUtils.drawImage(graphics, WARNING_IMAGE, x, y, null));
}
graphics.dispose();
}

2
designer-base/src/main/java/com/fr/design/utils/SvgPainter.java → designer-base/src/main/java/com/fr/design/utils/SvgDraw.java

@ -7,7 +7,7 @@ package com.fr.design.utils;
* @since 11.0
* Created on 2023/3/24
*/
public interface SvgPainter<T> {
public interface SvgDraw<T> {
/**
* 绘制svg图标的具体逻辑,方法体

24
designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java → designer-base/src/main/java/com/fr/design/utils/SvgDrawUtils.java

@ -16,17 +16,23 @@ import java.awt.image.ImageObserver;
* @version 11.0
* Created by hades on 2022/5/6
*/
public class SvgPaintUtils {
public class SvgDrawUtils {
private static final boolean HI_DPI_ENABLED = SystemScaleUtils.isJreHiDPIEnabled();
public static void beforePaint(Graphics2D g2) {
/**
* 绘制svg前若环境支持高清化则对缩放比例进行适配
* */
public static void beforeDraw(Graphics2D g2) {
if (HI_DPI_ENABLED) {
g2.scale(1 / SVGLoader.SYSTEM_SCALE, 1 / SVGLoader.SYSTEM_SCALE);
}
}
public static void afterPaint(Graphics2D g2) {
/**
* 绘制svg后还原缩放矩阵
* */
public static void afterDraw(Graphics2D g2) {
if (HI_DPI_ENABLED) {
g2.scale(SVGLoader.SYSTEM_SCALE, SVGLoader.SYSTEM_SCALE);
}
@ -44,12 +50,12 @@ public class SvgPaintUtils {
/**
* 绘制svg图像的完整逻辑
* @param graphics 绘图
* @param svgPainter 具体绘制逻辑
* @param svgDraw 具体绘制逻辑
* */
public static void doDrawSVG(@NotNull Graphics graphics, @NotNull final SvgPainter<Graphics> svgPainter) {
SvgPaintUtils.beforePaint((Graphics2D) graphics);
svgPainter.drawSVG();
SvgPaintUtils.afterPaint((Graphics2D) graphics);
public static void doDrawSVG(@NotNull Graphics graphics, @NotNull final SvgDraw<Graphics> svgDraw) {
SvgDrawUtils.beforeDraw((Graphics2D) graphics);
svgDraw.drawSVG();
SvgDrawUtils.afterDraw((Graphics2D) graphics);
}
/**
@ -62,6 +68,6 @@ public class SvgPaintUtils {
* */
public static void drawImage(Graphics graphics, Image image, int x, int y, ImageObserver imageObserver) {
//如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整
graphics.drawImage(image, SvgPaintUtils.calculatePosition(x), SvgPaintUtils.calculatePosition(y), imageObserver);
graphics.drawImage(image, SvgDrawUtils.calculatePosition(x), SvgDrawUtils.calculatePosition(y), imageObserver);
}
}
Loading…
Cancel
Save