1 Clazz.declarePackage ("java.awt");
2 Clazz.load (["java.awt.font.FontRenderContext"], "java.awt.FontMetrics", ["java.lang.Character"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 Clazz.instantialize (this, arguments);
6 }, java.awt, "FontMetrics");
7 Clazz.makeConstructor (c$,
11 Clazz.defineMethod (c$, "getFont",
15 Clazz.defineMethod (c$, "getFontRenderContext",
17 return java.awt.FontMetrics.DEFAULT_FRC;
19 Clazz.defineMethod (c$, "getLeading",
23 Clazz.defineMethod (c$, "getAscent",
25 return this.font.getSize ();
27 Clazz.defineMethod (c$, "getDescent",
31 Clazz.defineMethod (c$, "getHeight",
33 return this.getLeading () + this.getAscent () + this.getDescent ();
35 Clazz.defineMethod (c$, "getMaxAscent",
37 return this.getAscent ();
39 Clazz.defineMethod (c$, "getMaxDescent",
41 return this.getDescent ();
43 Clazz.defineMethod (c$, "getMaxDecent",
45 return this.getMaxDescent ();
47 Clazz.defineMethod (c$, "getMaxAdvance",
51 Clazz.defineMethod (c$, "charWidth",
52 function (codePoint) {
53 if (!Character.isValidCodePoint (codePoint)) {
55 }if (codePoint < 256) {
56 return this.getWidths ()[codePoint];
58 var buffer = Clazz.newCharArray (2, '\0');
59 var len = Character.toChars (codePoint, buffer, 0);
60 return this.charsWidth (buffer, 0, len);
62 Clazz.defineMethod (c$, "charWidth",
64 if (ch.charCodeAt (0) < 256) {
65 return this.getWidths ()[ch.charCodeAt (0)];
66 }var data = Clazz.newCharArray (-1, [ch]);
67 return this.charsWidth (data, 0, 1);
69 Clazz.defineMethod (c$, "stringWidth",
72 var data = Clazz.newCharArray (len, '\0');
73 str.getChars (0, len, data, 0);
74 return this.charsWidth (data, 0, len);
76 Clazz.defineMethod (c$, "charsWidth",
77 function (data, off, len) {
78 return this.stringWidth ( String.instantialize (data, off, len));
80 Clazz.defineMethod (c$, "bytesWidth",
81 function (data, off, len) {
82 return this.stringWidth ( String.instantialize (data, 0, off, len));
84 Clazz.defineMethod (c$, "getWidths",
86 var widths = Clazz.newIntArray (256, 0);
87 for (var ch = String.fromCharCode (0); ch.charCodeAt (0) < 256; ch = String.fromCharCode (ch.charCodeAt (0) + 1)) {
88 widths[ch.charCodeAt (0)] = this.charWidth (ch);
92 Clazz.overrideMethod (c$, "toString",
94 return this.getClass ().getName () + "[font=" + this.getFont () + "ascent=" + this.getAscent () + ", descent=" + this.getDescent () + ", height=" + this.getHeight () + "]";
96 c$.DEFAULT_FRC = c$.prototype.DEFAULT_FRC = new java.awt.font.FontRenderContext (null, false, false);