1
2
3
4
5
6
7
8
9
10
11
12
13 package com.octo.captcha.component.image.textpaster;
14
15 import com.octo.captcha.CaptchaException;
16 import com.octo.captcha.component.image.color.ColorGenerator;
17
18 import java.awt.*;
19 import java.awt.image.BufferedImage;
20 import java.text.AttributedString;
21
22 /***
23 * Pastes characters in differents height lines in the background
24 *
25 * @date 19 mars 2007
26 * @author <a href="mailto:antoine.veret@gmail.com">Antoine Véret</a>
27 * @deprecated
28 */
29 public class NonLinearTextPaster extends AbstractTextPaster {
30
31 public NonLinearTextPaster(Integer minAcceptedWordLength, Integer maxAcceptedWordLength,
32 Color textColor) {
33 super(minAcceptedWordLength, maxAcceptedWordLength, textColor);
34 }
35
36 public NonLinearTextPaster(Integer minAcceptedWordLength, Integer maxAcceptedWordLength,
37 ColorGenerator colorGenerator) {
38 super(minAcceptedWordLength, maxAcceptedWordLength, colorGenerator);
39 }
40
41 public NonLinearTextPaster(Integer minAcceptedWordLength, Integer maxAcceptedWordLength,
42 ColorGenerator colorGenerator, Boolean manageColorPerGlyph) {
43 super(minAcceptedWordLength, maxAcceptedWordLength, colorGenerator, manageColorPerGlyph);
44 }
45
46 /***
47 * Pastes the attributed string on the backround image and return the final image. Implementation must take into
48 * account the fact that the text must be readable by human and non by programs.
49 *
50 * @return the final image
51 *
52 * @throws com.octo.captcha.CaptchaException
53 * if any exception accurs during paste routine.
54 */
55 public BufferedImage pasteText(final BufferedImage background,
56 final AttributedString attributedWord) throws CaptchaException {
57
58 BufferedImage out = copyBackground(background);
59 Graphics2D g2 = pasteBackgroundAndSetTextColor(out, background);
60
61
62 MutableAttributedString newAttrString = new MutableAttributedString(g2,
63 attributedWord, 2);
64
65
66 newAttrString.useMinimumSpacing(6);
67
68
69 newAttrString.shiftBoundariesToNonLinearLayout(background.getWidth(), background.getHeight());
70
71
72 if (isManageColorPerGlyph())
73 newAttrString.drawString(g2, getColorGenerator());
74 else
75 newAttrString.drawString(g2);
76
77 g2.dispose();
78 return out;
79 }
80 }