| 1 |
// Copyright 2004, 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 |
import java.awt.geom.AffineTransform; |
| 10 |
|
| 11 |
import org.freehep.graphics2d.VectorGraphics; |
| 12 |
|
| 13 |
/** |
| 14 |
* |
| 15 |
* @author Mark Donszelmann |
| 16 |
* @version $Id: freehep-graphicsio-tests/src/main/java/org/freehep/graphicsio/test/TestFontDerivation.java f493ff6e61b2 2005/12/01 18:46:43 duns $ |
| 17 |
*/ |
| 18 |
public class TestFontDerivation extends TestingPanel { |
| 19 |
|
| 20 |
public TestFontDerivation(String[] args) throws Exception { |
| 21 |
super(args); |
| 22 |
setName("Font Derivation"); |
| 23 |
} |
| 24 |
|
| 25 |
public void paintComponent(Graphics g) { |
| 26 |
if (g == null) |
| 27 |
return; |
| 28 |
|
| 29 |
VectorGraphics vg = VectorGraphics.create(g.create()); |
| 30 |
|
| 31 |
Dimension dim = getSize(); |
| 32 |
Insets insets = getInsets(); |
| 33 |
|
| 34 |
int w = dim.width; |
| 35 |
int h = dim.height; |
| 36 |
vg.translate(w / 2, h / 2); |
| 37 |
|
| 38 |
vg.setColor(Color.white); |
| 39 |
vg.fillRect(insets.left - w / 2, insets.top - h / 2, w - insets.left |
| 40 |
- insets.right, h - insets.top - insets.bottom); |
| 41 |
|
| 42 |
String text = "FreeHEP"; |
| 43 |
|
| 44 |
Font font = vg.getFont(); |
| 45 |
double fw = w / 120.0; |
| 46 |
double fh = h / 120.0; |
| 47 |
|
| 48 |
vg.setColor(Color.BLACK); |
| 49 |
|
| 50 |
for (int i = 1; i < 36; i++) { |
| 51 |
AffineTransform t = AffineTransform.getRotateInstance(Math |
| 52 |
.toRadians(10 * i)); |
| 53 |
double s = 1.0 + i / 20.0; |
| 54 |
t.scale(fw / s, fh / s); |
| 55 |
vg.setFont(font.deriveFont(t)); |
| 56 |
vg.drawString(text, 0, 0); |
| 57 |
} |
| 58 |
|
| 59 |
vg.setColor(Color.BLUE); |
| 60 |
vg.setFont(font.deriveFont(AffineTransform.getScaleInstance(fw, fh))); |
| 61 |
vg.drawString(text, 0, 0); |
| 62 |
|
| 63 |
vg.dispose(); |
| 64 |
} |
| 65 |
|
| 66 |
public static void main(String[] args) throws Exception { |
| 67 |
new TestFontDerivation(args).runTest(); |
| 68 |
} |
| 69 |
} |