author | oheimb |
Wed, 03 Apr 2002 10:21:13 +0200 | |
changeset 13076 | 70704dd48bd5 |
parent 11874 | 83c97febc828 |
child 13968 | 689868b99bde |
permissions | -rw-r--r-- |
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
1 |
/*************************************************************************** |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
2 |
Title: GraphBrowser/DefaultFontMetrics.java |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
3 |
ID: $Id$ |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
4 |
Author: Stefan Berghofer, TU Muenchen |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
5 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
6 |
|
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
7 |
Default font metrics which is used when no graphics context |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
8 |
is available. |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
9 |
***************************************************************************/ |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
10 |
|
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
11 |
package GraphBrowser; |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
12 |
|
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
13 |
import java.awt.*; |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
14 |
|
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
15 |
public class DefaultFontMetrics extends FontMetrics |
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
16 |
{ |
11810 | 17 |
protected static int[] chars = |
18 |
{13, 13, 17, 27, 27, 43, 32, 11, 16, 16, 19, 28, 13, 28, 13, 13, 27, |
|
19 |
27, 27, 27, 27, 27, 27, 27, 27, 27, 13, 13, 28, 28, 28, 27, 49, 32, |
|
20 |
32, 35, 35, 32, 29, 37, 35, 13, 24, 32, 27, 40, 35, 37, 32, 37, 35, |
|
21 |
32, 29, 35, 32, 45, 32, 32, 29, 13, 13, 13, 22, 27, 11, 27, 27, 24, |
|
22 |
27, 27, 13, 27, 27, 11, 11, 24, 11, 40, 27, 27, 27, 27, 16, 24, 13, |
|
23 |
27, 24, 35, 24, 24, 24, 16, 12, 16, 28}; |
|
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
24 |
|
11874
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
25 |
int size; |
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
26 |
|
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
27 |
public DefaultFontMetrics(int size) |
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
28 |
{ super(null); this.size = size; } |
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
29 |
|
11810 | 30 |
public int getLeading() |
31 |
{ return 1; } |
|
32 |
||
33 |
public int getAscent() |
|
11874
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
34 |
{ return (int)(Math.round(size * 46.0 / 48.0)); } |
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
35 |
|
11810 | 36 |
public int getDescent() |
11874
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
37 |
{ return (int)(Math.round(size * 10.0 / 48.0)); } |
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
38 |
|
11810 | 39 |
public int charWidth(char c) { |
40 |
if (c < 32 || c > 126) { return 0; } |
|
41 |
else { |
|
11874
83c97febc828
Constructor no longer takes font as an argument.
berghofe
parents:
11810
diff
changeset
|
42 |
return (int)(Math.round(chars[c - 32] * size / 48.0)); |
11810 | 43 |
} |
44 |
} |
|
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
45 |
|
11810 | 46 |
public int stringWidth(String s) { |
47 |
int l=0, i; |
|
48 |
for (i=0; i < s.length(); i++) { l += charWidth(s.charAt(i)); } |
|
49 |
return l; |
|
50 |
} |
|
11799
533a95523f61
Font metrics used for batch mode layout (without X11 connection).
berghofe
parents:
diff
changeset
|
51 |
} |