From 68ed359f9735e047218e5458715a78fe04d1ebb6 Mon Sep 17 00:00:00 2001 From: plough Date: Wed, 23 May 2018 15:02:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-7222=20=E5=AE=89=E5=85=A8=E6=80=A7?= =?UTF-8?q?=E4=B9=8B=E6=B0=B4=E5=8D=B0=3D>=E8=B0=83=E6=95=B4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/report/WatermarkPreviewPane.java | 48 +------------------ 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java b/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java index 94b3a503d0..1e2d834b76 100644 --- a/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java +++ b/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java @@ -2,29 +2,18 @@ package com.fr.design.report; import com.fr.base.iofileattr.WatermarkAttr; import com.fr.design.constants.UIConstants; -import com.fr.general.FRFont; +import com.fr.page.WatermarkPainter; import javax.swing.JPanel; -import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.image.BufferedImage; /** * Created by plough on 2018/5/15. */ public class WatermarkPreviewPane extends JPanel { - private static final double SCALE_FACTOR = 3; // 水印层的放大比例 - private static final int ROTATE_DEGREE = -20; // 旋转角度 - // 绘制水印层的坐标,用来控制图层偏移 - private static final int MARK_X = 0; - private static final int MARK_Y = -120; - - private int horizontalGap = 20; // 水平间隔(一个中文字符宽度) - private int verticalGap = 40; // 垂直间隔(两个中文字符宽度) private WatermarkAttr watermark; - public WatermarkPreviewPane() { this.watermark = new WatermarkAttr(); repaint(); @@ -38,44 +27,11 @@ public class WatermarkPreviewPane extends JPanel { super.repaint(); } - private void updateGap(FontMetrics fontMetrics) { - horizontalGap = fontMetrics.stringWidth("帆"); // 任意一个中文字符 - verticalGap = horizontalGap * 2; - } - - private int getLineHeight() { - return horizontalGap; - } - - private BufferedImage paintWatermark() { - int width = (int)(this.getWidth() * SCALE_FACTOR); - int height = (int)(this.getHeight() * SCALE_FACTOR); - BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - Graphics g = image.getGraphics(); - g.setColor(watermark.getColor()); - g.setFont(FRFont.getInstance().applySize(watermark.getFontSize())); - updateGap(g.getFontMetrics()); - for (int y = getLineHeight(); y < height; y += verticalGap) { - for (int x = 0; x < width; x += horizontalGap) { - g.drawString(watermark.getText(), x, y); - x += g.getFontMetrics().stringWidth(watermark.getText()); - } - y += getLineHeight(); - } - return image; - } - @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; g2d.drawImage(UIConstants.WATERMARK_BACKGROUND, 0, 0, this.getWidth(), this.getHeight(), null); - BufferedImage markImage = paintWatermark(); - g2d.rotate( - Math.toRadians(ROTATE_DEGREE), - (double) markImage.getWidth() / 2, - (double) markImage.getHeight() / 2 - ); - g.drawImage(markImage, MARK_X, MARK_Y, null); + WatermarkPainter.getInstance().paint(watermark, g2d, this.getWidth(), this.getHeight()); } } From 458ffcf0f5ffd523afc3627ed5d9d24a6ea479a6 Mon Sep 17 00:00:00 2001 From: plough Date: Wed, 23 May 2018 15:35:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-7222=20=E5=AE=89=E5=85=A8=E6=80=A7?= =?UTF-8?q?=E4=B9=8B=E6=B0=B4=E5=8D=B0=3D>=E6=94=AF=E6=8C=81=E5=85=AC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/report/WatermarkPreviewPane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java b/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java index 1e2d834b76..086ce569a4 100644 --- a/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java +++ b/designer-base/src/com/fr/design/report/WatermarkPreviewPane.java @@ -32,6 +32,6 @@ public class WatermarkPreviewPane extends JPanel { super.paint(g); Graphics2D g2d = (Graphics2D)g; g2d.drawImage(UIConstants.WATERMARK_BACKGROUND, 0, 0, this.getWidth(), this.getHeight(), null); - WatermarkPainter.getInstance().paint(watermark, g2d, this.getWidth(), this.getHeight()); + WatermarkPainter.getInstance().paint(watermark, g2d, this.getWidth(), this.getHeight(), true); } }