Debian Codegraph @

freehep-graphicsio-tests/src/main/java/org/freehep/graphicsio/test/TestFonts.java

raw
1 // Copyright 2001-2005, freehep
2 package org.freehep.graphicsio.test;
3
4 import java.awt.Color;
5 import java.awt.Dimension;
6 import java.awt.Font;
7 import java.awt.Graphics;
8 import java.awt.Insets;
9
10 import org.freehep.graphics2d.VectorGraphics;
11 import org.freehep.graphics2d.font.CharTable;
12 import org.freehep.graphics2d.font.Lookup;
13
14 /**
15 * @author Simon Fischer
16 * @version $Id: freehep-graphicsio-tests/src/main/java/org/freehep/graphicsio/test/TestFonts.java f493ff6e61b2 2005/12/01 18:46:43 duns $
17 */
18 public class TestFonts extends TestingPanel {
19
20 public TestFonts(String[] args) throws Exception {
21 super(args);
22 setName("Fonts");
23 }
24
25 public void paintComponent(Graphics g) {
26
27 if (g == null)
28 return;
29
30 VectorGraphics vg = VectorGraphics.create(g);
31
32 Dimension dim = getSize();
33 Insets insets = getInsets();
34
35 vg.setColor(Color.white);
36 vg.fillRect(insets.left, insets.top, dim.width - insets.left
37 - insets.right, dim.height - insets.top - insets.bottom);
38
39 // int dw = dim.width / 5;
40 int dh = dim.height / 8;
41
42 vg.setColor(Color.black);
43 Font serif = new Font("Serif", Font.PLAIN, 12);
44 Font sansserif = new Font("SansSerif", Font.PLAIN, 12);
45 Font dialog = new Font("Dialog", Font.PLAIN, 12);
46 Font monospaced = new Font("Monospaced", Font.PLAIN, 12);
47
48 // Font standard = new Font("TimesRoman", Font.PLAIN, 12);
49 // Font standard = new Font("Impact", Font.PLAIN, 12);
50 Font standard = serif;
51
52 // Font standard = new Font("Lucida Times Unicode", Font.PLAIN, 12);
53 // Font embedded = new Font("ZapfChancery", Font.PLAIN, 12);
54 // Font embedded = new Font("Impact", Font.PLAIN, 12);
55 // Font embedded = new Font("Arial", Font.PLAIN, 12);
56 // Font standard = new Font("Lucida Sans", Font.PLAIN, 12);
57 Font embedded = new Font("Monotype Corsiva", Font.PLAIN, 12);
58 // Font embedded = new Font("Lucida Sans", Font.PLAIN, 12);
59 // Font embedded = new Font("ZapfDingbats", Font.PLAIN, 12);
60
61 vg.setFont(standard);
62 vg.drawString("[" + standard + "]", 10, 20);
63 vg.drawLine(10, 40, 200, 40);
64 vg.drawString("This font is a standard font: " + standard.getName()
65 + ".", 10, 40);
66
67 vg.setFont(embedded);
68 vg.drawString("[" + embedded + "]", 10, dh);
69 vg.drawLine(10, dh + 20, 200, dh + 20);
70 vg.drawString("This font is a special font: " + embedded.getName()
71 + ".", 10, dh + 20);
72
73 CharTable table = Lookup.getInstance().getTable("PDFLatin");
74
75 for (int i = 0; i < 8; i++) {
76 for (int j = 0; j < 32; j++) {
77 int c = 32 * i + j;
78 String name = table.toName(c);
79 char ch = '?';
80 if (name != null) {
81 ch = table.toUnicode(name);
82 }
83
84 vg.setFont(standard);
85 vg.drawString(" " + ch, 10 + j * 15, i * 35 + 2 * dh);
86 vg.setFont(embedded);
87 vg.drawString(" " + ch, 10 + j * 15, i * 35 + 15 + 2 * dh);
88 }
89 }
90
91 vg.setFont(standard);
92 vg.drawString("Symbol Font:", 20, 7 * dh - 40);
93 vg.setFont(new Font("Symbol", Font.PLAIN, 12));
94 vg.drawString("ABC abc 123 .,!", 200, 7 * dh - 40);
95
96 vg.setFont(standard);
97 vg.drawString("Dingbats:", 20, 7 * dh - 20);
98 vg.setFont(new Font("ZapfDingbats", Font.PLAIN, 12));
99 vg.drawString("ABC abc 123 .,!", 200, 7 * dh - 20);
100
101 String ucs = "Unicode chars (greek, dingbats): \u03b1 \u03b2 \u03b3 \u263a \u2665 \u2729 \u270c";
102 vg.setFont(serif);
103 vg.drawString(ucs + " in " + serif.getName(), 20, 7 * dh);
104 vg.setFont(sansserif);
105 vg.drawString(ucs + " in " + sansserif.getName(), 20, 7 * dh + 20);
106 vg.setFont(dialog);
107 vg.drawString(ucs + " in " + dialog.getName(), 20, 7 * dh + 40);
108 vg.setFont(monospaced);
109 vg.drawString(ucs + " in " + monospaced.getName(), 20, 7 * dh + 60);
110 }
111
112 public static void main(String[] args) throws Exception {
113 new TestFonts(args).runTest();
114 }
115 }