1
2
3
4
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>Takes a random font and apply a rotation to it. </p>
14 *
15 * @author <a href="mailto:mga@octo.com">Mathieu Gandin</a>
16 * @version 1.0
17 */
18 public class DeformedRandomFontGenerator extends RandomFontGenerator {
19
20
21 public DeformedRandomFontGenerator(Integer minFontSize,
22 Integer maxFontSize) {
23 super(minFontSize, maxFontSize);
24 }
25
26
27 /***
28 * Provides a way for children class to customize the generated font array
29 *
30 * @param font
31 * @return a customized font
32 */
33 protected Font applyCustomDeformationOnGeneratedFont(Font font) {
34
35 float theta = (myRandom.nextBoolean() ? 1 : -1) * myRandom.nextFloat() / 3;
36
37
38
39
40
41 AffineTransform at = new AffineTransform();
42 at.rotate(theta, myRandom.nextDouble()
43 return font.deriveFont(at);
44 }
45 }