cn.atomtool.captcha.text.renderer.TextString Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atomtool-captcha Show documentation
Show all versions of atomtool-captcha Show documentation
atomTool核心工具包,包括集合、字符串、Bean等工具类
The newest version!
package cn.atomtool.captcha.text.renderer;
import java.util.ArrayList;
public class TextString {
private ArrayList characters = new ArrayList();
public void clear() {
characters.clear();
}
public void addCharacter(TextCharacter tc) {
characters.add(tc);
}
public ArrayList getCharacters() {
return characters;
}
public double getWidth() {
double minx = 0;
double maxx = 0;
boolean first = true;
for (TextCharacter tc : characters) {
if (first) {
minx = tc.getX();
maxx = tc.getX() + tc.getWidth();
first = false;
} else {
if (minx > tc.getX()) {
minx = tc.getX();
}
if (maxx < tc.getX() + tc.getWidth()) {
maxx = tc.getX() + tc.getWidth();
}
}
}
return maxx - minx;
}
public double getHeight() {
double miny = 0;
double maxy = 0;
boolean first = true;
for (TextCharacter tc : characters) {
if (first) {
miny = tc.getY();
maxy = tc.getY() + tc.getHeight();
first = false;
} else {
if (miny > tc.getY()) {
miny = tc.getY();
}
if (maxy < tc.getY() + tc.getHeight()) {
maxy = tc.getY() + tc.getHeight();
}
}
}
return maxy - miny;
}
}