Skip to content

Commit

Permalink
图片绘制插件支持圆角矩形填充,fix圆角矩形刷子样式
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyueyi committed Sep 15, 2020
1 parent ebb90ac commit 0aaf792
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 117 deletions.
21 changes: 7 additions & 14 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<qrcode-plugin.version>2.4.2</qrcode-plugin.version>
<image-plugin.version>2.4</image-plugin.version>
<svg-plugin.version>2.4</svg-plugin.version>
<markdonw-plugin.version>2.4</markdonw-plugin.version>
<audio-plugin.version>2.4</audio-plugin.version>
<date-plugin.version>2.4</date-plugin.version>
<phantom-plugin.version>2.4</phantom-plugin.version>
<qrcode-plugin.version>2.5</qrcode-plugin.version>
<image-plugin.version>2.5</image-plugin.version>
<svg-plugin.version>2.5</svg-plugin.version>
<markdonw-plugin.version>2.5</markdonw-plugin.version>
<audio-plugin.version>2.5</audio-plugin.version>
<date-plugin.version>2.5</date-plugin.version>
<phantom-plugin.version>2.5</phantom-plugin.version>
</properties>

<repositories>
Expand All @@ -41,13 +41,6 @@
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release-local</url>
</pluginRepository>
</pluginRepositories>

<dependencies>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.github.hui.quick.plugin.test;

import com.github.hui.quick.plugin.audio.AudioWrapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Created by yihui on 2017/7/13.
*/
@Slf4j
public class AudioWrapperTest {

private static final Logger log = LoggerFactory.getLogger(AudioWrapperTest.class);


@Test
public void testAudioParse() {
Expand Down
5 changes: 5 additions & 0 deletions plugins/image-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<artifactId>base-plugin</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ public class RectCell implements IMergeCell {


/**
* 是否为虚线
*/
private boolean dashed;


/**
* 虚线样式
* 虚线样式,指定线宽等,如 {@link CellConstants#RECT_DEFAULT_DASH}
*/
private Stroke stroke;

Expand All @@ -45,25 +39,24 @@ public class RectCell implements IMergeCell {
public RectCell() {
}

public RectCell(int x, int y, int w, int h, Color color, boolean dashed, Stroke stroke, int radius) {
public RectCell(int x, int y, int w, int h, Color color, Stroke stroke, int radius) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.color = color;
this.dashed = dashed;
this.stroke = stroke;
this.radius = radius;
}

@Override
public void draw(Graphics2D g2d) {
g2d.setColor(color);
if (!dashed) {
if (stroke == null) {
g2d.drawRoundRect(x, y, w, h, radius, radius);
} else {
Stroke stroke = g2d.getStroke();
g2d.setStroke(stroke);
g2d.setStroke(this.stroke);
g2d.drawRoundRect(x, y, w, h, radius, radius);
g2d.setStroke(stroke);
}
Expand Down Expand Up @@ -109,14 +102,6 @@ public void setColor(Color color) {
this.color = color;
}

public boolean isDashed() {
return dashed;
}

public void setDashed(boolean dashed) {
this.dashed = dashed;
}

public Stroke getStroke() {
return stroke;
}
Expand All @@ -142,21 +127,20 @@ public boolean equals(Object o) {
return false;
}
RectCell rectCell = (RectCell) o;
return x == rectCell.x && y == rectCell.y && w == rectCell.w && h == rectCell.h && dashed == rectCell.dashed &&
radius == rectCell.radius && Objects.equals(color, rectCell.color) &&
Objects.equals(stroke, rectCell.stroke);
return x == rectCell.x && y == rectCell.y && w == rectCell.w && h == rectCell.h && radius == rectCell.radius &&
Objects.equals(color, rectCell.color) && Objects.equals(stroke, rectCell.stroke);
}

@Override
public int hashCode() {

return Objects.hash(x, y, w, h, color, dashed, stroke, radius);
return Objects.hash(x, y, w, h, color, stroke, radius);
}

@Override
public String toString() {
return "RectCell{" + "x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ", color=" + color + ", dashed=" +
dashed + ", stroke=" + stroke + ", radius=" + radius + '}';
return "RectCell{" + "x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ", color=" + color + ", stroke=" +
stroke + ", radius=" + radius + '}';
}

public static Builder builder() {
Expand All @@ -180,13 +164,6 @@ public static class Builder {
*/
private Color color;


/**
* 是否为虚线
*/
private boolean dashed;


/**
* 虚线样式
*/
Expand Down Expand Up @@ -223,11 +200,6 @@ public Builder color(Color color) {
return this;
}

public Builder dashed(boolean dashed) {
this.dashed = dashed;
return this;
}

public Builder stroke(Stroke stroke) {
this.stroke = stroke;
return this;
Expand All @@ -239,7 +211,7 @@ public Builder radius(int radius) {
}

public RectCell build() {
return new RectCell(x, y, w, h, color, dashed, stroke, radius);
return new RectCell(x, y, w, h, color, stroke, radius);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,31 @@ public class RectFillCell implements IMergeCell {

private int x, y, w, h;

private int radius;

@Override
public void draw(Graphics2D g2d) {
g2d.setFont(font);
g2d.setColor(color);
;
g2d.fillRect(x, y, w, h);

if (radius <= 0) {
g2d.fillRect(x, y, w, h);
} else {
g2d.fillRoundRect(x, y, w, h, radius, radius);
}
}

public RectFillCell() {
}

public RectFillCell(Font font, Color color, int x, int y, int w, int h) {
public RectFillCell(Font font, Color color, int x, int y, int w, int h, int radius) {
this.font = font;
this.color = color;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.radius = radius;
}

public Font getFont() {
Expand Down Expand Up @@ -85,6 +92,14 @@ public void setH(int h) {
this.h = h;
}

public int getRadius() {
return radius;
}

public void setRadius(int radius) {
this.radius = radius;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -94,20 +109,19 @@ public boolean equals(Object o) {
return false;
}
RectFillCell that = (RectFillCell) o;
return x == that.x && y == that.y && w == that.w && h == that.h && Objects.equals(font, that.font) &&
Objects.equals(color, that.color);
return x == that.x && y == that.y && w == that.w && h == that.h && radius == that.radius &&
Objects.equals(font, that.font) && Objects.equals(color, that.color);
}

@Override
public int hashCode() {

return Objects.hash(font, color, x, y, w, h);
return Objects.hash(font, color, x, y, w, h, radius);
}

@Override
public String toString() {
return "RectFillCell{" + "font=" + font + ", color=" + color + ", x=" + x + ", y=" + y + ", w=" + w + ", h=" +
h + '}';
h + ", radius=" + radius + '}';
}

public static Builder builder() {
Expand All @@ -120,7 +134,7 @@ public static class Builder {
private Color color;


private int x, y, w, h;
private int x, y, w, h, radius;

public Builder font(Font font) {
this.font = font;
Expand Down Expand Up @@ -152,8 +166,13 @@ public Builder h(int h) {
return this;
}

public Builder radius(int radius) {
this.radius = radius;
return this;
}

public RectFillCell build() {
return new RectFillCell(font, color, x, y, w, h);
return new RectFillCell(font, color, x, y, w, h, radius);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public void addText(String text) {
texts.add(text);
}

/**
* 文本框占用的高度, 水平绘制时有效
*
* @return
*/
public int getDrawHeight() {
FontMetrics fontMetrics = FontUtil.getFontMetric(font);
int size = batchSplitText(texts, fontMetrics).size();
return size * (fontMetrics.getHeight() + lineSpace);
}

@Override
public void draw(Graphics2D g2d) {
Expand Down
Loading

0 comments on commit 0aaf792

Please sign in to comment.