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