-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJSFontMetrics.java
More file actions
120 lines (106 loc) · 3.19 KB
/
Copy pathJSFontMetrics.java
File metadata and controls
120 lines (106 loc) · 3.19 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package swingjs;
import jsjava.awt.Font;
import jsjava.awt.FontMetrics;
public class JSFontMetrics extends FontMetrics {
private float[] fwidths;
private int[] iwidths;
private int FIRST_PRINTABLE = 32;
public JSFontMetrics() {
super(null);
}
public void setFont(Font f) {
font = f;
}
/**
* Determines the <em>standard leading</em> of the
* <code>Font</code> described by this <code>FontMetrics</code>
* object. The standard leading, or
* interline spacing, is the logical amount of space to be reserved
* between the descent of one line of text and the ascent of the next
* line. The height metric is calculated to include this extra space.
* @return the standard leading of the <code>Font</code>.
* @see #getHeight()
* @see #getAscent()
* @see #getDescent()
*/
@Override
public int getLeading() {
return font.getSize() / 20 + 1;
}
/**
* Determines the <em>font ascent</em> of the <code>Font</code>
* described by this <code>FontMetrics</code> object. The font ascent
* is the distance from the font's baseline to the top of most
* alphanumeric characters. Some characters in the <code>Font</code>
* might extend above the font ascent line.
* @return the font ascent of the <code>Font</code>.
* @see #getMaxAscent()
*/
@Override
public int getAscent() {
return font.getSize();
}
/**
* Determines the <em>font descent</em> of the <code>Font</code>
* described by this
* <code>FontMetrics</code> object. The font descent is the distance
* from the font's baseline to the bottom of most alphanumeric
* characters with descenders. Some characters in the
* <code>Font</code> might extend
* below the font descent line.
* @return the font descent of the <code>Font</code>.
* @see #getMaxDescent()
*/
@Override
public int getDescent() {
return font.getSize() / 4 + 1;
}
/**
* @j2sIgnore
*
*/
@Override
public int charWidth(char pt) {
return (pt < 256 ? (int) getWidthsFloat()[pt] : stringWidth("" + pt));
}
@Override
public int charWidth(int pt) {
/**
* could be a character
*
* @j2sNative
*
* var spt;
* return ((pt + 0 == pt ? pt : (pt = (spt = pt).charCodeAt(0))) < 256 ?
* Clazz.floatToInt(this.getWidthsFloat()[pt])
* : this.stringWidth(isChar ? spt : String.fromCharCode (pt)));
*/
{
return (pt < 256 ? (int) getWidthsFloat()[pt] : stringWidth("" + (char) pt));
}
}
@Override
public int stringWidth(String s) {
return (int) JSToolkit.getStringWidth(null, font, s);
}
@Override
public int[] getWidths() {
if (iwidths != null)
return iwidths;
iwidths = new int[256];
getWidthsFloat();
for (int ch = FIRST_PRINTABLE ; ch < 256; ch++) {
iwidths[ch] = (int) fwidths[ch];
}
return iwidths;
}
public float[] getWidthsFloat() {
if (fwidths != null)
return fwidths;
fwidths = new float[256];
for (int ch = FIRST_PRINTABLE; ch < 256; ch++) {
fwidths[ch] = JSToolkit.getStringWidth(null, font, "" + (char) ch);
}
return fwidths;
}
}