Browse Source

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

newui
obo 2 years ago
parent
commit
efbfb9ecbe
  1. 16
      designer-base/src/main/java/com/fr/design/icon/WarningIcon.java
  2. 28
      designer-base/src/main/java/com/fr/design/utils/SvgPaintUtils.java
  3. 34
      designer-base/src/main/java/com/fr/design/utils/SvgPainter.java

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

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

@ -2,8 +2,12 @@ package com.fr.design.utils;
import com.fr.base.svg.SVGLoader; import com.fr.base.svg.SVGLoader;
import com.fr.base.svg.SystemScaleUtils; import com.fr.base.svg.SystemScaleUtils;
import org.jetbrains.annotations.NotNull;
import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.ImageObserver;
/** /**
* 用于绘制svg图片缩放(高分屏下) * 用于绘制svg图片缩放(高分屏下)
@ -36,4 +40,28 @@ public class SvgPaintUtils {
public static int calculatePosition(int position) { public static int calculatePosition(int position) {
return HI_DPI_ENABLED ? (int) (position * SVGLoader.SYSTEM_SCALE) : position; return HI_DPI_ENABLED ? (int) (position * SVGLoader.SYSTEM_SCALE) : position;
} }
/**
* 绘制svg图像的完整逻辑
* @param graphics 绘图
* @param svgPainter 具体绘制逻辑
* */
public static void doDrawSVG(@NotNull Graphics graphics, @NotNull final SvgPainter<Graphics> svgPainter) {
SvgPaintUtils.beforePaint((Graphics2D) graphics);
svgPainter.drawSVG();
SvgPaintUtils.afterPaint((Graphics2D) graphics);
}
/**
* 绘制前对坐标x和y进行处理
* @param graphics 绘图
* @param image svg的Image对象
* @param x x坐标
* @param y y坐标
* @param imageObserver 图像观察器
* */
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);
}
} }

34
designer-base/src/main/java/com/fr/design/utils/SvgPainter.java

@ -1,40 +1,16 @@
package com.fr.design.utils; package com.fr.design.utils;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.ImageObserver;
/** /**
* SVG图标绘制器 * 绘制SVG图标的函数式接口
* *
* @author obo * @author obo
* @since 11.0 * @since 11.0
* Created on 2023/3/24 * Created on 2023/3/24
*/ */
public abstract class SvgPainter { public interface SvgPainter<T> {
private final Graphics graphics;
public SvgPainter(Graphics g) {
graphics = g;
}
protected abstract void doPaint();
protected void drawImage(Image image, int x, int y, ImageObserver imageObserver) {
//如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整
graphics.drawImage(image, SvgPaintUtils.calculatePosition(x), SvgPaintUtils.calculatePosition(y), imageObserver);
}
/** /**
* 执行完整的svg绘制逻辑 * 绘制svg图标的具体逻辑,方法体
* * */
* @author obo void drawSVG();
* @since 11.0
* Created on 2023/3/24
*/
public void paint() {
SvgPaintUtils.beforePaint((Graphics2D) graphics);
doPaint();
SvgPaintUtils.afterPaint((Graphics2D) graphics);
}
} }

Loading…
Cancel
Save