Skip to content

Commit 0aaf792

Browse files
committed
图片绘制插件支持圆角矩形填充,fix圆角矩形刷子样式
1 parent ebb90ac commit 0aaf792

File tree

12 files changed

+278
-117
lines changed

12 files changed

+278
-117
lines changed

console/pom.xml

+7-14
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2020
<java.version>1.8</java.version>
21-
<qrcode-plugin.version>2.4.2</qrcode-plugin.version>
22-
<image-plugin.version>2.4</image-plugin.version>
23-
<svg-plugin.version>2.4</svg-plugin.version>
24-
<markdonw-plugin.version>2.4</markdonw-plugin.version>
25-
<audio-plugin.version>2.4</audio-plugin.version>
26-
<date-plugin.version>2.4</date-plugin.version>
27-
<phantom-plugin.version>2.4</phantom-plugin.version>
21+
<qrcode-plugin.version>2.5</qrcode-plugin.version>
22+
<image-plugin.version>2.5</image-plugin.version>
23+
<svg-plugin.version>2.5</svg-plugin.version>
24+
<markdonw-plugin.version>2.5</markdonw-plugin.version>
25+
<audio-plugin.version>2.5</audio-plugin.version>
26+
<date-plugin.version>2.5</date-plugin.version>
27+
<phantom-plugin.version>2.5</phantom-plugin.version>
2828
</properties>
2929

3030
<repositories>
@@ -41,13 +41,6 @@
4141
</snapshots>
4242
</repository>
4343
</repositories>
44-
<pluginRepositories>
45-
<pluginRepository>
46-
<id>spring-releases</id>
47-
<url>https://repo.spring.io/libs-release-local</url>
48-
</pluginRepository>
49-
</pluginRepositories>
50-
5144
<dependencies>
5245

5346
<dependency>

plugins/audio-plugin/src/test/java/com/github/hui/quick/plugin/test/AudioWrapperTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.github.hui.quick.plugin.test;
22

33
import com.github.hui.quick.plugin.audio.AudioWrapper;
4-
import lombok.extern.slf4j.Slf4j;
54
import org.junit.Test;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
67

78
/**
89
* Created by yihui on 2017/7/13.
910
*/
10-
@Slf4j
1111
public class AudioWrapperTest {
1212

13+
private static final Logger log = LoggerFactory.getLogger(AudioWrapperTest.class);
14+
1315

1416
@Test
1517
public void testAudioParse() {

plugins/image-plugin/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
<artifactId>base-plugin</artifactId>
1919
<version>2.5</version>
2020
</dependency>
21+
<dependency>
22+
<groupId>com.alibaba</groupId>
23+
<artifactId>fastjson</artifactId>
24+
<version>1.2.62</version>
25+
</dependency>
2126
</dependencies>
2227

2328

plugins/image-plugin/src/main/java/com/github/hui/quick/plugin/image/wrapper/merge/cell/RectCell.java

+10-38
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ public class RectCell implements IMergeCell {
2626

2727

2828
/**
29-
* 是否为虚线
30-
*/
31-
private boolean dashed;
32-
33-
34-
/**
35-
* 虚线样式
29+
* 虚线样式,指定线宽等,如 {@link CellConstants#RECT_DEFAULT_DASH}
3630
*/
3731
private Stroke stroke;
3832

@@ -45,25 +39,24 @@ public class RectCell implements IMergeCell {
4539
public RectCell() {
4640
}
4741

48-
public RectCell(int x, int y, int w, int h, Color color, boolean dashed, Stroke stroke, int radius) {
42+
public RectCell(int x, int y, int w, int h, Color color, Stroke stroke, int radius) {
4943
this.x = x;
5044
this.y = y;
5145
this.w = w;
5246
this.h = h;
5347
this.color = color;
54-
this.dashed = dashed;
5548
this.stroke = stroke;
5649
this.radius = radius;
5750
}
5851

5952
@Override
6053
public void draw(Graphics2D g2d) {
6154
g2d.setColor(color);
62-
if (!dashed) {
55+
if (stroke == null) {
6356
g2d.drawRoundRect(x, y, w, h, radius, radius);
6457
} else {
6558
Stroke stroke = g2d.getStroke();
66-
g2d.setStroke(stroke);
59+
g2d.setStroke(this.stroke);
6760
g2d.drawRoundRect(x, y, w, h, radius, radius);
6861
g2d.setStroke(stroke);
6962
}
@@ -109,14 +102,6 @@ public void setColor(Color color) {
109102
this.color = color;
110103
}
111104

112-
public boolean isDashed() {
113-
return dashed;
114-
}
115-
116-
public void setDashed(boolean dashed) {
117-
this.dashed = dashed;
118-
}
119-
120105
public Stroke getStroke() {
121106
return stroke;
122107
}
@@ -142,21 +127,20 @@ public boolean equals(Object o) {
142127
return false;
143128
}
144129
RectCell rectCell = (RectCell) o;
145-
return x == rectCell.x && y == rectCell.y && w == rectCell.w && h == rectCell.h && dashed == rectCell.dashed &&
146-
radius == rectCell.radius && Objects.equals(color, rectCell.color) &&
147-
Objects.equals(stroke, rectCell.stroke);
130+
return x == rectCell.x && y == rectCell.y && w == rectCell.w && h == rectCell.h && radius == rectCell.radius &&
131+
Objects.equals(color, rectCell.color) && Objects.equals(stroke, rectCell.stroke);
148132
}
149133

150134
@Override
151135
public int hashCode() {
152136

153-
return Objects.hash(x, y, w, h, color, dashed, stroke, radius);
137+
return Objects.hash(x, y, w, h, color, stroke, radius);
154138
}
155139

156140
@Override
157141
public String toString() {
158-
return "RectCell{" + "x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ", color=" + color + ", dashed=" +
159-
dashed + ", stroke=" + stroke + ", radius=" + radius + '}';
142+
return "RectCell{" + "x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ", color=" + color + ", stroke=" +
143+
stroke + ", radius=" + radius + '}';
160144
}
161145

162146
public static Builder builder() {
@@ -180,13 +164,6 @@ public static class Builder {
180164
*/
181165
private Color color;
182166

183-
184-
/**
185-
* 是否为虚线
186-
*/
187-
private boolean dashed;
188-
189-
190167
/**
191168
* 虚线样式
192169
*/
@@ -223,11 +200,6 @@ public Builder color(Color color) {
223200
return this;
224201
}
225202

226-
public Builder dashed(boolean dashed) {
227-
this.dashed = dashed;
228-
return this;
229-
}
230-
231203
public Builder stroke(Stroke stroke) {
232204
this.stroke = stroke;
233205
return this;
@@ -239,7 +211,7 @@ public Builder radius(int radius) {
239211
}
240212

241213
public RectCell build() {
242-
return new RectCell(x, y, w, h, color, dashed, stroke, radius);
214+
return new RectCell(x, y, w, h, color, stroke, radius);
243215
}
244216
}
245217
}

plugins/image-plugin/src/main/java/com/github/hui/quick/plugin/image/wrapper/merge/cell/RectFillCell.java

+29-10
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@ public class RectFillCell implements IMergeCell {
1717

1818
private int x, y, w, h;
1919

20+
private int radius;
21+
2022
@Override
2123
public void draw(Graphics2D g2d) {
2224
g2d.setFont(font);
2325
g2d.setColor(color);
24-
;
25-
g2d.fillRect(x, y, w, h);
26+
27+
if (radius <= 0) {
28+
g2d.fillRect(x, y, w, h);
29+
} else {
30+
g2d.fillRoundRect(x, y, w, h, radius, radius);
31+
}
2632
}
2733

2834
public RectFillCell() {
2935
}
3036

31-
public RectFillCell(Font font, Color color, int x, int y, int w, int h) {
37+
public RectFillCell(Font font, Color color, int x, int y, int w, int h, int radius) {
3238
this.font = font;
3339
this.color = color;
3440
this.x = x;
3541
this.y = y;
3642
this.w = w;
3743
this.h = h;
44+
this.radius = radius;
3845
}
3946

4047
public Font getFont() {
@@ -85,6 +92,14 @@ public void setH(int h) {
8592
this.h = h;
8693
}
8794

95+
public int getRadius() {
96+
return radius;
97+
}
98+
99+
public void setRadius(int radius) {
100+
this.radius = radius;
101+
}
102+
88103
@Override
89104
public boolean equals(Object o) {
90105
if (this == o) {
@@ -94,20 +109,19 @@ public boolean equals(Object o) {
94109
return false;
95110
}
96111
RectFillCell that = (RectFillCell) o;
97-
return x == that.x && y == that.y && w == that.w && h == that.h && Objects.equals(font, that.font) &&
98-
Objects.equals(color, that.color);
112+
return x == that.x && y == that.y && w == that.w && h == that.h && radius == that.radius &&
113+
Objects.equals(font, that.font) && Objects.equals(color, that.color);
99114
}
100115

101116
@Override
102117
public int hashCode() {
103-
104-
return Objects.hash(font, color, x, y, w, h);
118+
return Objects.hash(font, color, x, y, w, h, radius);
105119
}
106120

107121
@Override
108122
public String toString() {
109123
return "RectFillCell{" + "font=" + font + ", color=" + color + ", x=" + x + ", y=" + y + ", w=" + w + ", h=" +
110-
h + '}';
124+
h + ", radius=" + radius + '}';
111125
}
112126

113127
public static Builder builder() {
@@ -120,7 +134,7 @@ public static class Builder {
120134
private Color color;
121135

122136

123-
private int x, y, w, h;
137+
private int x, y, w, h, radius;
124138

125139
public Builder font(Font font) {
126140
this.font = font;
@@ -152,8 +166,13 @@ public Builder h(int h) {
152166
return this;
153167
}
154168

169+
public Builder radius(int radius) {
170+
this.radius = radius;
171+
return this;
172+
}
173+
155174
public RectFillCell build() {
156-
return new RectFillCell(font, color, x, y, w, h);
175+
return new RectFillCell(font, color, x, y, w, h, radius);
157176
}
158177
}
159178
}

plugins/image-plugin/src/main/java/com/github/hui/quick/plugin/image/wrapper/merge/cell/TextCell.java

+10
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public void addText(String text) {
127127
texts.add(text);
128128
}
129129

130+
/**
131+
* 文本框占用的高度, 水平绘制时有效
132+
*
133+
* @return
134+
*/
135+
public int getDrawHeight() {
136+
FontMetrics fontMetrics = FontUtil.getFontMetric(font);
137+
int size = batchSplitText(texts, fontMetrics).size();
138+
return size * (fontMetrics.getHeight() + lineSpace);
139+
}
130140

131141
@Override
132142
public void draw(Graphics2D g2d) {

0 commit comments

Comments
 (0)