View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   package com.octo.captcha.component.image.fontgenerator;
8   
9   import java.awt.*;
10  import java.awt.geom.AffineTransform;
11  
12  /***
13   * <p>Description: </p>
14   *
15   * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
16   * @version 1.0
17   */
18  public class TwistedRandomFontGenerator extends RandomFontGenerator {
19  
20      public TwistedRandomFontGenerator(Integer minFontSize, Integer maxFontSize) {
21          super(minFontSize, maxFontSize);
22      }
23  
24  
25      /***
26       * Provides a way for children class to customize the generated font array
27       *
28       * @param font
29       * @return a customized font
30       */
31      protected Font applyCustomDeformationOnGeneratedFont(Font font) {
32          AffineTransform at = new AffineTransform();
33          float angle = myRandom.nextFloat() / 3;
34          at.rotate(myRandom.nextBoolean() ? angle : -angle);
35          return font.deriveFont(at);
36      }
37  }