spring.turbo.module.misc.captcha.google.renderer.RandomYBestFitTextRenderer Maven / Gradle / Ivy
package spring.turbo.module.misc.captcha.google.renderer;
import java.util.Random;
/**
* @since 1.0.0
*/
public class RandomYBestFitTextRenderer extends AbstractTextRenderer {
@Override
protected void arrangeCharacters(int width, int height, TextString ts) {
double widthRemaining = (width - ts.getWidth() - leftMargin - rightMargin) / ts.getCharacters().size();
double vmiddle = height / 2;
double x = leftMargin + widthRemaining / 2;
Random r = new Random();
height -= topMargin + bottomMargin;
for (TextCharacter tc : ts.getCharacters()) {
double heightRemaining = height - tc.getHeight();
double y = vmiddle + 0.35 * tc.getAscent() + (1 - 2 * r.nextDouble()) * heightRemaining;
tc.setX(x);
tc.setY(y);
x += tc.getWidth() + widthRemaining;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy