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