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.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lc.captchas.interfaces.Challenge;
|
||||
import lc.captchas.interfaces.ChallengeProvider;
|
||||
import lc.misc.PngImageWriter;
|
||||
import lc.misc.HelperFunctions;
|
||||
import lc.misc.PngImageWriter;
|
||||
|
||||
public class FontFunCaptcha implements ChallengeProvider {
|
||||
|
||||
|
@ -58,7 +58,8 @@ public class FontFunCaptcha implements ChallengeProvider {
|
|||
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"};
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
|
@ -87,7 +88,8 @@ public class FontFunCaptcha implements ChallengeProvider {
|
|||
final int width = size2D[0];
|
||||
final int height = size2D[1];
|
||||
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) {
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
package lc.captchas;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import lc.captchas.interfaces.Challenge;
|
||||
import lc.captchas.interfaces.ChallengeProvider;
|
||||
import lc.misc.HelperFunctions;
|
||||
import lc.misc.GifSequenceWriter;
|
||||
import lc.misc.HelperFunctions;
|
||||
|
||||
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 graphics2D = img.createGraphics();
|
||||
final var frc = graphics2D.getFontRenderContext();
|
||||
|
@ -32,17 +32,20 @@ public class PoppingCharactersCaptcha implements ChallengeProvider {
|
|||
advances[i] = currX;
|
||||
currX += font.getStringBounds(String.valueOf(c), frc).getWidth();
|
||||
currX += spacing;
|
||||
};
|
||||
}
|
||||
;
|
||||
advances[text.length()] = currX;
|
||||
graphics2D.dispose();
|
||||
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 graphics2D = img.createGraphics();
|
||||
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);
|
||||
f.accept(graphics2D);
|
||||
graphics2D.dispose();
|
||||
|
@ -64,24 +67,38 @@ public class PoppingCharactersCaptcha implements ChallengeProvider {
|
|||
final var expectedWidth = advances[advances.length - 1];
|
||||
final var scale = width / (float) expectedWidth;
|
||||
final var prevColor = Color.getHSBColor(0f, 0f, 0.1f);
|
||||
IntStream.range(0, text.length()).forEach(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);
|
||||
if (i > 0) {
|
||||
final var prevI = (i - 1) % text.length();
|
||||
g.setColor(prevColor);
|
||||
g.drawString(String.valueOf(text.charAt(prevI)), advances[prevI] + jitter(), fontHeight*1.1f + jitter());
|
||||
}
|
||||
g.setColor(color);
|
||||
g.drawString(String.valueOf(text.charAt(i)), advances[i] + jitter(), fontHeight*1.1f + jitter());
|
||||
});
|
||||
try {
|
||||
writer.writeToSequence(nextImage);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
IntStream.range(0, text.length())
|
||||
.forEach(
|
||||
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);
|
||||
if (i > 0) {
|
||||
final var prevI = (i - 1) % text.length();
|
||||
g.setColor(prevColor);
|
||||
g.drawString(
|
||||
String.valueOf(text.charAt(prevI)),
|
||||
advances[prevI] + jitter(),
|
||||
fontHeight * 1.1f + jitter());
|
||||
}
|
||||
g.setColor(color);
|
||||
g.drawString(
|
||||
String.valueOf(text.charAt(i)),
|
||||
advances[i] + jitter(),
|
||||
fontHeight * 1.1f + jitter());
|
||||
});
|
||||
try {
|
||||
writer.writeToSequence(nextImage);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
writer.close();
|
||||
output.close();
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package lc.captchas;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ConvolveOp;
|
||||
import java.awt.image.Kernel;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import lc.misc.HelperFunctions;
|
||||
import lc.misc.PngImageWriter;
|
||||
import java.util.Map;
|
||||
import lc.captchas.interfaces.Challenge;
|
||||
import lc.captchas.interfaces.ChallengeProvider;
|
||||
import lc.misc.HelperFunctions;
|
||||
import lc.misc.PngImageWriter;
|
||||
|
||||
public class ShadowTextCaptcha implements ChallengeProvider {
|
||||
|
||||
|
@ -56,20 +54,24 @@ public class ShadowTextCaptcha implements ChallengeProvider {
|
|||
graphics2D.setPaint(Color.BLACK);
|
||||
graphics2D.setFont(font);
|
||||
final var stringWidth = graphics2D.getFontMetrics().stringWidth(text);
|
||||
final var padding = (stringWidth > width) ? 0 : (width - stringWidth)/2;
|
||||
final var scaleX = (stringWidth > width) ? width/((double) stringWidth) : 1d;
|
||||
final var padding = (stringWidth > width) ? 0 : (width - stringWidth) / 2;
|
||||
final var scaleX = (stringWidth > width) ? width / ((double) stringWidth) : 1d;
|
||||
graphics2D.scale(scaleX, 1d);
|
||||
graphics2D.drawString(text, padding, fontHeight*1.1f);
|
||||
graphics2D.drawString(text, padding, fontHeight * 1.1f);
|
||||
graphics2D.dispose();
|
||||
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);
|
||||
Graphics2D g2d = img2.createGraphics();
|
||||
HelperFunctions.setRenderingHints(g2d);
|
||||
g2d.setPaint(Color.WHITE);
|
||||
g2d.scale(scaleX, 1d);
|
||||
g2d.setFont(font);
|
||||
g2d.drawString(text, padding-kernelSize, fontHeight*1.1f);
|
||||
g2d.drawString(text, padding - kernelSize, fontHeight * 1.1f);
|
||||
g2d.dispose();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package lc.captchas.interfaces;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ChallengeProvider {
|
||||
public String getId();
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
package lc.misc;
|
||||
|
||||
import javax.imageio.*;
|
||||
import javax.imageio.metadata.*;
|
||||
import javax.imageio.stream.*;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.util.Iterator;
|
||||
import javax.imageio.*;
|
||||
import javax.imageio.metadata.*;
|
||||
import javax.imageio.stream.*;
|
||||
|
||||
public class GifSequenceWriter {
|
||||
protected ImageWriter gifWriter;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package lc.misc;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
@ -13,7 +13,6 @@ import javax.imageio.metadata.IIOInvalidTreeException;
|
|||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class PngImageWriter {
|
||||
|
||||
|
@ -26,7 +25,8 @@ public class PngImageWriter {
|
|||
iw.hasNext(); ) {
|
||||
ImageWriter writer = iw.next();
|
||||
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);
|
||||
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
|
||||
continue;
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
|
||||
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.util.List;
|
||||
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.InetSocketAddress;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
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 {
|
||||
private final HttpServer server;
|
||||
|
|
Loading…
Reference in New Issue