All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spring.turbo.module.misc.captcha.google.renderer.RandomYBestFitTextRenderer Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
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 - 2024 Weber Informatics LLC | Privacy Policy