1
2 package org.freehep.graphicsio.font.truetype.test;
3
4 import java.awt.BasicStroke;
5 import java.awt.Color;
6 import java.awt.Dimension;
7 import java.awt.Font;
8 import java.awt.Graphics;
9 import java.awt.Graphics2D;
10 import java.awt.Rectangle;
11 import java.awt.geom.AffineTransform;
12
13 import javax.swing.JPanel;
14
15 import org.freehep.graphicsio.font.truetype.TTFGlyfTable;
16
17
18
19
20
21 public class GlyphPanel extends JPanel {
22
23 private TTFGlyfTable.Glyph glyph;
24
25 private Rectangle maxCharBounds;
26
27 private final static AffineTransform transform = new AffineTransform();
28
29 static {
30 transform.scale(0.2, -0.2);
31 transform.translate(1500, -2250);
32 }
33
34 public GlyphPanel(TTFGlyfTable.Glyph glyph, Rectangle maxCharBounds) {
35 this.glyph = glyph;
36 this.maxCharBounds = maxCharBounds;
37
38 this.setBackground(Color.white);
39 }
40
41 public void paint(Graphics g) {
42 Graphics2D g2d = (Graphics2D) g;
43 g2d.setBackground(Color.white);
44 g2d.clearRect(0, 0, 1000, 700);
45
46 g2d.setTransform(transform);
47
48 g2d.setColor(new Color(200, 200, 255));
49 g2d.fill(maxCharBounds);
50
51 Rectangle bbox = glyph.getShape().getBounds();
52 g2d.setColor(Color.lightGray);
53 g2d.fill(bbox);
54
55 g2d.setColor(Color.black);
56 g2d.drawLine(-10000, glyph.yMin, 10000, glyph.yMin);
57 g2d.drawLine(glyph.xMin, -10000, glyph.xMin, 10000);
58 g2d.drawLine(-10000, glyph.yMax, 10000, glyph.yMax);
59 g2d.drawLine(glyph.xMax, -10000, glyph.xMax, 10000);
60
61 g2d.setFont(new Font("Helvetica", Font.PLAIN, 60));
62 drawString(g2d, "yMin=" + glyph.yMin, glyph.xMin - 325, glyph.yMin);
63 drawString(g2d, "yMax=" + glyph.yMax, glyph.xMin - 325, glyph.yMax);
64 drawString(g2d, "xMin=" + glyph.xMin, glyph.xMin + 20, glyph.yMin - 75);
65 drawString(g2d, "xMax=" + glyph.xMax, glyph.xMax + 20, glyph.yMin - 75);
66
67 g2d.fillOval(-10, -10, 21, 21);
68
69 g2d.fill(glyph.getShape());
70
71 g2d.setStroke(new BasicStroke(5));
72 g2d.setColor(Color.red);
73 g2d.draw(glyph.getShape());
74 }
75
76 private void drawString(Graphics2D g2d, String str, int x, int y) {
77 AffineTransform tx = g2d.getTransform();
78 g2d.translate(0, y);
79 g2d.scale(1, -1);
80 g2d.drawString(str, x, 0);
81 g2d.setTransform(tx);
82 }
83
84 public Dimension getPreferredSize() {
85 return new Dimension(1000, 700);
86 }
87 }