1 Clazz.declarePackage ("swingjs");
2 Clazz.load (["java.awt.FontMetrics"], "swingjs.JSFontMetrics", ["swingjs.JSToolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 Clazz.instantialize (this, arguments);
7 }, swingjs, "JSFontMetrics", java.awt.FontMetrics);
8 Clazz.makeConstructor (c$,
10 Clazz.superConstructor (this, swingjs.JSFontMetrics, [null]);
12 Clazz.defineMethod (c$, "setFont",
16 Clazz.overrideMethod (c$, "getLeading",
18 return Clazz.doubleToInt (this.font.getSize () / 20) + 1;
20 Clazz.overrideMethod (c$, "getAscent",
22 return this.font.getSize ();
24 Clazz.overrideMethod (c$, "getDescent",
26 return Clazz.doubleToInt (this.font.getSize () / 4) + 1;
28 Clazz.defineMethod (c$, "charWidth",
30 return (pt.charCodeAt (0) < 256 ? Clazz.floatToInt (this.getWidthsFloat ()[pt.charCodeAt (0)]) : this.stringWidth ("" + pt));
32 Clazz.defineMethod (c$, "charWidth",
34 return (pt < 256 ? Clazz.floatToInt (this.getWidthsFloat ()[pt]) : this.stringWidth ("" + String.fromCharCode (pt)));
36 Clazz.overrideMethod (c$, "stringWidth",
38 return Clazz.floatToInt (swingjs.JSToolkit.getStringWidth (null, this.font, s));
40 Clazz.overrideMethod (c$, "getWidths",
42 if (this.iwidths != null) return this.iwidths;
43 this.iwidths = Clazz.newIntArray (256, 0);
44 this.getWidthsFloat ();
45 for (var ch = 0; ch < 256; ch++) {
46 this.iwidths[ch] = Clazz.floatToInt (this.widths[ch]);
50 Clazz.defineMethod (c$, "getWidthsFloat",
52 if (this.widths != null) return this.widths;
53 this.widths = Clazz.newFloatArray (256, 0);
54 for (var ch = 0; ch < 256; ch++) {
55 this.widths[ch] = swingjs.JSToolkit.getStringWidth (null, this.font, "" + String.fromCharCode (ch));