Browse Source

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

newui
obo 2 years ago
parent
commit
810f67af61
  1. 19
      designer-base/src/main/java/com/fr/design/icon/WarningIcon.java
  2. 33
      designer-base/src/main/java/com/fr/design/utils/SvgPaintWorker.java

19
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.SvgPaintWorker;
import com.fr.log.FineLoggerFactory;
import javax.swing.GrayFilter;
@ -44,14 +44,23 @@ public class WarningIcon extends ImageIcon {
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
//裁剪绘制svg的位置,以免影响到图标右侧的文字
Graphics2D graphics = (Graphics2D) g.create(x, y, WARNING_IMAGE.getWidth(null), WARNING_IMAGE.getHeight(null));
SvgPaintUtils.beforePaint(graphics);
if (mainImage != null) {
graphics.drawImage(mainImage, x, y, null);
new SvgPaintWorker(graphics) {
@Override
protected void doPrint() {
this.drawImage(mainImage, x, y, null);
}
}.execute();
}
if (WARNING_IMAGE != null) {
graphics.drawImage(WARNING_IMAGE, x, y, null);
new SvgPaintWorker(graphics) {
@Override
protected void doPrint() {
this.drawImage(WARNING_IMAGE, x, y, null);
}
}.execute();
}
SvgPaintUtils.afterPaint(graphics);
graphics.dispose();
}
/**

33
designer-base/src/main/java/com/fr/design/utils/SvgPaintWorker.java

@ -0,0 +1,33 @@
package com.fr.design.utils;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.ImageObserver;
/**
* SVG图标绘制器
*
* @author obo
* @since 11.0
* Created on 2023/3/24
*/
abstract public class SvgPaintWorker {
private final Graphics graphics;
public SvgPaintWorker(Graphics g) {
graphics = g;
}
protected abstract void doPrint();
protected void drawImage(Image image, int x, int y, ImageObserver imageObserver) {
//如果环境支持高清化,在调整缩放比例时绘制svg会影响到位置的变化,若图标无确定裁剪位置,则需要进行调整
graphics.drawImage(image, SvgPaintUtils.calculatePosition(x), SvgPaintUtils.calculatePosition(y), imageObserver);
}
public void execute() {
SvgPaintUtils.beforePaint((Graphics2D) graphics);
doPrint();
SvgPaintUtils.afterPaint((Graphics2D) graphics);
}
}
Loading…
Cancel
Save