Reformat with sbt-java-formatter 0.8.0
Executed command: sbt javafmtAll
This commit is contained in:
parent
55e68d23f4
commit
57ce691a00
|
@ -5,12 +5,12 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import lc.captchas.interfaces.Challenge;
|
import lc.captchas.interfaces.Challenge;
|
||||||
import lc.captchas.interfaces.ChallengeProvider;
|
import lc.captchas.interfaces.ChallengeProvider;
|
||||||
import lc.misc.PngImageWriter;
|
|
||||||
import lc.misc.HelperFunctions;
|
import lc.misc.HelperFunctions;
|
||||||
|
import lc.misc.PngImageWriter;
|
||||||
|
|
||||||
public class FontFunCaptcha implements ChallengeProvider {
|
public class FontFunCaptcha implements ChallengeProvider {
|
||||||
|
|
||||||
|
@ -58,7 +58,8 @@ public class FontFunCaptcha implements ChallengeProvider {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] fontFun(final int width, final int height, String captchaText, String level, String path) {
|
private byte[] fontFun(
|
||||||
|
final int width, final int height, String captchaText, String level, String path) {
|
||||||
String[] colors = {"#f68787", "#f8a978", "#f1eb9a", "#a4f6a5"};
|
String[] colors = {"#f68787", "#f8a978", "#f1eb9a", "#a4f6a5"};
|
||||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
Graphics2D graphics2D = img.createGraphics();
|
Graphics2D graphics2D = img.createGraphics();
|
||||||
|
@ -87,7 +88,8 @@ public class FontFunCaptcha implements ChallengeProvider {
|
||||||
final int width = size2D[0];
|
final int width = size2D[0];
|
||||||
final int height = size2D[1];
|
final int height = size2D[1];
|
||||||
String path = "./lib/fonts/";
|
String path = "./lib/fonts/";
|
||||||
return new Challenge(fontFun(width, height, secret, "medium", path), "image/png", secret.toLowerCase());
|
return new Challenge(
|
||||||
|
fontFun(width, height, secret, "medium", path), "image/png", secret.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkAnswer(String secret, String answer) {
|
public boolean checkAnswer(String secret, String answer) {
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
package lc.captchas;
|
package lc.captchas;
|
||||||
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import lc.captchas.interfaces.Challenge;
|
import lc.captchas.interfaces.Challenge;
|
||||||
import lc.captchas.interfaces.ChallengeProvider;
|
import lc.captchas.interfaces.ChallengeProvider;
|
||||||
import lc.misc.HelperFunctions;
|
|
||||||
import lc.misc.GifSequenceWriter;
|
import lc.misc.GifSequenceWriter;
|
||||||
|
import lc.misc.HelperFunctions;
|
||||||
|
|
||||||
public class PoppingCharactersCaptcha implements ChallengeProvider {
|
public class PoppingCharactersCaptcha implements ChallengeProvider {
|
||||||
|
|
||||||
private int[] computeOffsets(final Font font, final int width, final int height, final String text) {
|
private int[] computeOffsets(
|
||||||
|
final Font font, final int width, final int height, final String text) {
|
||||||
final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
final var graphics2D = img.createGraphics();
|
final var graphics2D = img.createGraphics();
|
||||||
final var frc = graphics2D.getFontRenderContext();
|
final var frc = graphics2D.getFontRenderContext();
|
||||||
|
@ -32,17 +32,20 @@ public class PoppingCharactersCaptcha implements ChallengeProvider {
|
||||||
advances[i] = currX;
|
advances[i] = currX;
|
||||||
currX += font.getStringBounds(String.valueOf(c), frc).getWidth();
|
currX += font.getStringBounds(String.valueOf(c), frc).getWidth();
|
||||||
currX += spacing;
|
currX += spacing;
|
||||||
};
|
}
|
||||||
|
;
|
||||||
advances[text.length()] = currX;
|
advances[text.length()] = currX;
|
||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
return advances;
|
return advances;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage makeImage(final Font font, final int width, final int height, final Consumer<Graphics2D> f) {
|
private BufferedImage makeImage(
|
||||||
|
final Font font, final int width, final int height, final Consumer<Graphics2D> f) {
|
||||||
final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
final var graphics2D = img.createGraphics();
|
final var graphics2D = img.createGraphics();
|
||||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
graphics2D.setRenderingHint(
|
||||||
|
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
graphics2D.setFont(font);
|
graphics2D.setFont(font);
|
||||||
f.accept(graphics2D);
|
f.accept(graphics2D);
|
||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
|
@ -64,17 +67,31 @@ public class PoppingCharactersCaptcha implements ChallengeProvider {
|
||||||
final var expectedWidth = advances[advances.length - 1];
|
final var expectedWidth = advances[advances.length - 1];
|
||||||
final var scale = width / (float) expectedWidth;
|
final var scale = width / (float) expectedWidth;
|
||||||
final var prevColor = Color.getHSBColor(0f, 0f, 0.1f);
|
final var prevColor = Color.getHSBColor(0f, 0f, 0.1f);
|
||||||
IntStream.range(0, text.length()).forEach(i -> {
|
IntStream.range(0, text.length())
|
||||||
final var color = Color.getHSBColor(HelperFunctions.randomNumber(0, 100)/100.0f, 0.6f, 1.0f);
|
.forEach(
|
||||||
final var nextImage = makeImage(font, width, height, (g) -> {
|
i -> {
|
||||||
|
final var color =
|
||||||
|
Color.getHSBColor(HelperFunctions.randomNumber(0, 100) / 100.0f, 0.6f, 1.0f);
|
||||||
|
final var nextImage =
|
||||||
|
makeImage(
|
||||||
|
font,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
(g) -> {
|
||||||
g.scale(scale, 1);
|
g.scale(scale, 1);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
final var prevI = (i - 1) % text.length();
|
final var prevI = (i - 1) % text.length();
|
||||||
g.setColor(prevColor);
|
g.setColor(prevColor);
|
||||||
g.drawString(String.valueOf(text.charAt(prevI)), advances[prevI] + jitter(), fontHeight*1.1f + jitter());
|
g.drawString(
|
||||||
|
String.valueOf(text.charAt(prevI)),
|
||||||
|
advances[prevI] + jitter(),
|
||||||
|
fontHeight * 1.1f + jitter());
|
||||||
}
|
}
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
g.drawString(String.valueOf(text.charAt(i)), advances[i] + jitter(), fontHeight*1.1f + jitter());
|
g.drawString(
|
||||||
|
String.valueOf(text.charAt(i)),
|
||||||
|
advances[i] + jitter(),
|
||||||
|
fontHeight * 1.1f + jitter());
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
writer.writeToSequence(nextImage);
|
writer.writeToSequence(nextImage);
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
package lc.captchas;
|
package lc.captchas;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.ConvolveOp;
|
import java.awt.image.ConvolveOp;
|
||||||
import java.awt.image.Kernel;
|
import java.awt.image.Kernel;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import lc.misc.HelperFunctions;
|
|
||||||
import lc.misc.PngImageWriter;
|
|
||||||
import lc.captchas.interfaces.Challenge;
|
import lc.captchas.interfaces.Challenge;
|
||||||
import lc.captchas.interfaces.ChallengeProvider;
|
import lc.captchas.interfaces.ChallengeProvider;
|
||||||
|
import lc.misc.HelperFunctions;
|
||||||
|
import lc.misc.PngImageWriter;
|
||||||
|
|
||||||
public class ShadowTextCaptcha implements ChallengeProvider {
|
public class ShadowTextCaptcha implements ChallengeProvider {
|
||||||
|
|
||||||
|
@ -62,7 +60,11 @@ public class ShadowTextCaptcha implements ChallengeProvider {
|
||||||
graphics2D.drawString(text, padding, fontHeight * 1.1f);
|
graphics2D.drawString(text, padding, fontHeight * 1.1f);
|
||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
final int kernelSize = (int) Math.ceil((Math.min(width, height) / 50.0));
|
final int kernelSize = (int) Math.ceil((Math.min(width, height) / 50.0));
|
||||||
ConvolveOp op = new ConvolveOp(new Kernel(kernelSize, kernelSize, makeKernel(kernelSize)), ConvolveOp.EDGE_NO_OP, null);
|
ConvolveOp op =
|
||||||
|
new ConvolveOp(
|
||||||
|
new Kernel(kernelSize, kernelSize, makeKernel(kernelSize)),
|
||||||
|
ConvolveOp.EDGE_NO_OP,
|
||||||
|
null);
|
||||||
BufferedImage img2 = op.filter(img, null);
|
BufferedImage img2 = op.filter(img, null);
|
||||||
Graphics2D g2d = img2.createGraphics();
|
Graphics2D g2d = img2.createGraphics();
|
||||||
HelperFunctions.setRenderingHints(g2d);
|
HelperFunctions.setRenderingHints(g2d);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package lc.captchas.interfaces;
|
package lc.captchas.interfaces;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ChallengeProvider {
|
public interface ChallengeProvider {
|
||||||
public String getId();
|
public String getId();
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
package lc.misc;
|
package lc.misc;
|
||||||
|
|
||||||
import javax.imageio.*;
|
|
||||||
import javax.imageio.metadata.*;
|
|
||||||
import javax.imageio.stream.*;
|
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import javax.imageio.*;
|
||||||
|
import javax.imageio.metadata.*;
|
||||||
|
import javax.imageio.stream.*;
|
||||||
|
|
||||||
public class GifSequenceWriter {
|
public class GifSequenceWriter {
|
||||||
protected ImageWriter gifWriter;
|
protected ImageWriter gifWriter;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package lc.misc;
|
package lc.misc;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.imageio.IIOImage;
|
import javax.imageio.IIOImage;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.ImageTypeSpecifier;
|
import javax.imageio.ImageTypeSpecifier;
|
||||||
|
@ -13,7 +13,6 @@ import javax.imageio.metadata.IIOInvalidTreeException;
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
import javax.imageio.metadata.IIOMetadata;
|
||||||
import javax.imageio.metadata.IIOMetadataNode;
|
import javax.imageio.metadata.IIOMetadataNode;
|
||||||
import javax.imageio.stream.ImageOutputStream;
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
public class PngImageWriter {
|
public class PngImageWriter {
|
||||||
|
|
||||||
|
@ -26,7 +25,8 @@ public class PngImageWriter {
|
||||||
iw.hasNext(); ) {
|
iw.hasNext(); ) {
|
||||||
ImageWriter writer = iw.next();
|
ImageWriter writer = iw.next();
|
||||||
ImageWriteParam writeParam = writer.getDefaultWriteParam();
|
ImageWriteParam writeParam = writer.getDefaultWriteParam();
|
||||||
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
ImageTypeSpecifier typeSpecifier =
|
||||||
|
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
||||||
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
|
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
|
||||||
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
|
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3,21 +3,21 @@
|
||||||
|
|
||||||
package org.limium.picoserve;
|
package org.limium.picoserve;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
|
import com.sun.net.httpserver.HttpServer;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import com.sun.net.httpserver.HttpServer;
|
import java.util.Arrays;
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
import java.util.LinkedList;
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class Server {
|
public final class Server {
|
||||||
private final HttpServer server;
|
private final HttpServer server;
|
||||||
|
|
Loading…
Reference in New Issue