1 package com.octo.captcha.component.image.textpaster.glyphsvisitor;
2
3 import com.octo.captcha.component.image.textpaster.Glyphs;
4
5 import java.awt.geom.Rectangle2D;
6 import java.util.Random;
7 import java.security.SecureRandom;
8
9 /***
10 *
11 * @author mag
12 * @Date 6 mars 2008
13 */
14 public class TranslateAllToRandomPointVisitor implements GlyphsVisitors {
15 private Random myRandom = new SecureRandom();
16 private double horizontalMargins=0;
17 private double verticalMargins=0;
18
19
20 public TranslateAllToRandomPointVisitor() {
21 }
22
23 /***
24 *
25 * @param horizontalmargins the horizontal margin, default 0
26 * @param verticalmargins the vertical margin, default 0
27 */
28 public TranslateAllToRandomPointVisitor(double horizontalmargins,double verticalmargins){
29 this.horizontalMargins=horizontalmargins;
30 this.verticalMargins=verticalmargins;
31 }
32
33 public void visit(Glyphs glyphs, Rectangle2D backroundBounds) {
34 double xRange = backroundBounds.getWidth() - glyphs.getBoundsWidth()-horizontalMargins;
35 double yRange = backroundBounds.getHeight() - glyphs.getBoundsHeight()-verticalMargins;
36 double tx = xRange * myRandom.nextDouble() - glyphs.getBoundsX()+horizontalMargins/2;
37 double ty = yRange*myRandom.nextDouble()- glyphs.getBoundsY()+verticalMargins/2;
38 glyphs.translate(tx,ty);
39 }
40 }