1 Clazz.declarePackage ("jssun.font");
\r
2 Clazz.load (["java.awt.FontMetrics", "java.util.Hashtable"], "jssun.font.FontDesignMetrics", ["java.lang.IndexOutOfBoundsException", "java.awt.Toolkit", "swingjs.JSToolkit"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
8 Clazz.instantialize (this, arguments);
\r
9 }, jssun.font, "FontDesignMetrics", java.awt.FontMetrics);
\r
10 c$.getMetrics = Clazz.defineMethod (c$, "getMetrics",
\r
14 r = jssun.font.FontDesignMetrics.metricsCache.get (font);
\r
18 m = new jssun.font.FontDesignMetrics (font);
\r
19 jssun.font.FontDesignMetrics.metricsCache.put (font, new jssun.font.FontDesignMetrics.KeyReference (font, m));
\r
20 }for (var i = 0; i < jssun.font.FontDesignMetrics.recentMetrics.length; i++) {
\r
21 if (jssun.font.FontDesignMetrics.recentMetrics[i] === m) {
\r
25 jssun.font.FontDesignMetrics.recentMetrics[jssun.font.FontDesignMetrics.recentIndex++] = m;
\r
26 if (jssun.font.FontDesignMetrics.recentIndex == 5) {
\r
27 jssun.font.FontDesignMetrics.recentIndex = 0;
\r
29 }, "java.awt.Font");
\r
30 Clazz.makeConstructor (c$,
\r
32 Clazz.superConstructor (this, jssun.font.FontDesignMetrics, [font]);
\r
34 this.initMatrixAndMetrics ();
\r
35 }, "java.awt.Font");
\r
36 Clazz.defineMethod (c$, "initMatrixAndMetrics",
\r
39 //need to calculate ascent, descent, leading, and maxAdvance
\r
41 Clazz.defineMethod (c$, "charWidth",
\r
46 }return this.stringWidth (s);
\r
48 Clazz.overrideMethod (c$, "stringWidth",
\r
50 return Clazz.doubleToInt (0.5 + this.getWidth (str));
\r
52 Clazz.defineMethod (c$, "getWidth",
\r
54 return swingjs.JSToolkit.getStringWidth (null, this.font, str);
\r
56 Clazz.overrideMethod (c$, "charsWidth",
\r
57 function (data, off, len) {
\r
60 throw new IndexOutOfBoundsException ("len=" + len);
\r
61 }var limit = off + len;
\r
62 for (var i = off; i < limit; i++) {
\r
64 width += this.stringWidth ("" + ch);
\r
66 return Clazz.doubleToInt (0.5 + width);
\r
68 Clazz.overrideMethod (c$, "getWidths",
\r
70 var widths = Clazz.newIntArray (256, 0);
\r
73 Clazz.defineMethod (c$, "getAscent",
\r
75 if (this.ascent == 0) this.ascent = java.awt.Toolkit.getDefaultToolkit ().getFontMetrics (this.font).getAscent ();
\r
76 return Clazz.floatToInt (jssun.font.FontDesignMetrics.roundingUpValue + this.ascent);
\r
78 Clazz.defineMethod (c$, "getDescent",
\r
80 if (this.descent == 0) this.descent = java.awt.Toolkit.getDefaultToolkit ().getFontMetrics (this.font).getDescent ();
\r
81 return Clazz.floatToInt (jssun.font.FontDesignMetrics.roundingUpValue + this.descent);
\r
83 Clazz.overrideMethod (c$, "getLeading",
\r
85 return Clazz.floatToInt (jssun.font.FontDesignMetrics.roundingUpValue + this.descent + this.leading) - Clazz.floatToInt (jssun.font.FontDesignMetrics.roundingUpValue + this.descent);
\r
87 Clazz.overrideMethod (c$, "getHeight",
\r
89 if (this.height < 0) {
\r
90 this.height = this.getAscent () + Clazz.floatToInt (jssun.font.FontDesignMetrics.roundingUpValue + this.descent + this.leading);
\r
91 }return this.height;
\r
93 Clazz.pu$h(self.c$);
\r
94 c$ = Clazz.decorateAsClass (function () {
\r
97 Clazz.instantialize (this, arguments);
\r
98 }, jssun.font.FontDesignMetrics, "KeyReference");
\r
99 Clazz.makeConstructor (c$,
\r
104 Clazz.defineMethod (c$, "get",
\r
108 Clazz.defineMethod (c$, "dispose",
\r
110 if (jssun.font.FontDesignMetrics.metricsCache.get (this.key) === this) {
\r
111 jssun.font.FontDesignMetrics.metricsCache.remove (this.key);
\r
114 Clazz.defineStatics (c$,
\r
115 "roundingUpValue", 0.95);
\r
116 c$.metricsCache = c$.prototype.metricsCache = new java.util.Hashtable ();
\r
117 Clazz.defineStatics (c$,
\r
119 c$.recentMetrics = c$.prototype.recentMetrics = new Array (5);
\r
120 Clazz.defineStatics (c$,
\r