1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging.operations.text; |
35 |
|
|
36 |
|
import java.awt.Color; |
37 |
|
import java.awt.Font; |
38 |
|
import java.awt.Graphics2D; |
39 |
|
import java.awt.Rectangle; |
40 |
|
import java.awt.RenderingHints; |
41 |
|
import java.awt.font.FontRenderContext; |
42 |
|
import java.awt.font.GlyphVector; |
43 |
|
import java.awt.geom.Rectangle2D; |
44 |
|
import java.awt.image.BufferedImage; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 2 |
Complexity Density: 0.12 |
|
49 |
|
public class BasicTextRenderer implements TextRenderer { |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private boolean drawBoundingBox; |
54 |
|
|
55 |
|
|
56 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
57 |
4 |
@Override... |
58 |
|
public void renderText(BufferedImage img, String txt, TextStyle style, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, int txtPositionX, int txtPositionY) { |
59 |
4 |
final Graphics2D g = img.createGraphics(); |
60 |
|
|
61 |
4 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
62 |
4 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
63 |
|
|
64 |
4 |
g.setColor(style.getColor()); |
65 |
4 |
final Font font = style.getFont(); |
66 |
4 |
final FontRenderContext fontRenderContext = g.getFontRenderContext(); |
67 |
4 |
final GlyphVector glyph = font.createGlyphVector(fontRenderContext, txt); |
68 |
4 |
final Rectangle2D bounds = glyph.getVisualBounds(); |
69 |
4 |
final float textWidth = (float) bounds.getWidth(); |
70 |
4 |
final float textHeight = (float) bounds.getHeight(); |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
4 |
final float x = ((Alignment) horizontalAlignment).getPositionFor(textWidth, img.getWidth(), txtPositionX); |
76 |
4 |
final float y = ((Alignment) verticalAlignment).getPositionFor(textHeight, img.getHeight(), txtPositionY); |
77 |
4 |
g.drawGlyphVector(glyph, x, y); |
78 |
|
|
79 |
4 |
if (drawBoundingBox) { |
80 |
0 |
g.setColor(Color.YELLOW); |
81 |
0 |
g.draw(new Rectangle((int) x, (int) (y - textHeight), (int) textWidth, (int) textHeight)); |
82 |
|
} |
83 |
|
|
84 |
4 |
g.dispose(); |
85 |
|
} |
86 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
87 |
|
public boolean isDrawBoundingBox() {... |
88 |
|
return drawBoundingBox; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
94 |
|
public void setDrawBoundingBox(boolean drawBoundingBox) {... |
95 |
|
this.drawBoundingBox = drawBoundingBox; |
96 |
|
} |
97 |
|
} |