X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fswingjs%2Fj2s%2Fswingjs%2FJSFontMetrics.js;fp=site%2Fswingjs%2Fj2s%2Fswingjs%2FJSFontMetrics.js;h=cd4440e5e84476f6c712094b4ddf61680b0a900b;hp=0fc2e9bc8fa255bbac1bc8292e0b9603eade7e6e;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/swingjs/j2s/swingjs/JSFontMetrics.js b/site/swingjs/j2s/swingjs/JSFontMetrics.js index 0fc2e9b..cd4440e 100644 --- a/site/swingjs/j2s/swingjs/JSFontMetrics.js +++ b/site/swingjs/j2s/swingjs/JSFontMetrics.js @@ -1,59 +1,59 @@ -Clazz.declarePackage ("swingjs"); -Clazz.load (["java.awt.FontMetrics"], "swingjs.JSFontMetrics", ["swingjs.JSToolkit"], function () { -c$ = Clazz.decorateAsClass (function () { -this.widths = null; -this.iwidths = null; -Clazz.instantialize (this, arguments); -}, swingjs, "JSFontMetrics", java.awt.FontMetrics); -Clazz.makeConstructor (c$, -function () { -Clazz.superConstructor (this, swingjs.JSFontMetrics, [null]); -}); -Clazz.defineMethod (c$, "setFont", -function (f) { -this.font = f; -}, "java.awt.Font"); -Clazz.overrideMethod (c$, "getLeading", -function () { -return Clazz.doubleToInt (this.font.getSize () / 20) + 1; -}); -Clazz.overrideMethod (c$, "getAscent", -function () { -return this.font.getSize (); -}); -Clazz.overrideMethod (c$, "getDescent", -function () { -return Clazz.doubleToInt (this.font.getSize () / 4) + 1; -}); -Clazz.defineMethod (c$, "charWidth", -function (pt) { -return (pt.charCodeAt (0) < 256 ? Clazz.floatToInt (this.getWidthsFloat ()[pt.charCodeAt (0)]) : this.stringWidth ("" + pt)); -}, "~S"); -Clazz.defineMethod (c$, "charWidth", -function (pt) { -return (pt < 256 ? Clazz.floatToInt (this.getWidthsFloat ()[pt]) : this.stringWidth ("" + String.fromCharCode (pt))); -}, "~N"); -Clazz.overrideMethod (c$, "stringWidth", -function (s) { -return Clazz.floatToInt (swingjs.JSToolkit.getStringWidth (null, this.font, s)); -}, "~S"); -Clazz.overrideMethod (c$, "getWidths", -function () { -if (this.iwidths != null) return this.iwidths; -this.iwidths = Clazz.newIntArray (256, 0); -this.getWidthsFloat (); -for (var ch = 0; ch < 256; ch++) { -this.iwidths[ch] = Clazz.floatToInt (this.widths[ch]); -} -return this.iwidths; -}); -Clazz.defineMethod (c$, "getWidthsFloat", -function () { -if (this.widths != null) return this.widths; -this.widths = Clazz.newFloatArray (256, 0); -for (var ch = 0; ch < 256; ch++) { -this.widths[ch] = swingjs.JSToolkit.getStringWidth (null, this.font, "" + String.fromCharCode (ch)); -} -return this.widths; -}); -}); +Clazz.declarePackage ("swingjs"); +Clazz.load (["java.awt.FontMetrics"], "swingjs.JSFontMetrics", ["swingjs.JSToolkit"], function () { +c$ = Clazz.decorateAsClass (function () { +this.widths = null; +this.iwidths = null; +Clazz.instantialize (this, arguments); +}, swingjs, "JSFontMetrics", java.awt.FontMetrics); +Clazz.makeConstructor (c$, +function () { +Clazz.superConstructor (this, swingjs.JSFontMetrics, [null]); +}); +Clazz.defineMethod (c$, "setFont", +function (f) { +this.font = f; +}, "java.awt.Font"); +Clazz.overrideMethod (c$, "getLeading", +function () { +return Clazz.doubleToInt (this.font.getSize () / 20) + 1; +}); +Clazz.overrideMethod (c$, "getAscent", +function () { +return this.font.getSize (); +}); +Clazz.overrideMethod (c$, "getDescent", +function () { +return Clazz.doubleToInt (this.font.getSize () / 4) + 1; +}); +Clazz.defineMethod (c$, "charWidth", +function (pt) { +return (pt.charCodeAt (0) < 256 ? Clazz.floatToInt (this.getWidthsFloat ()[pt.charCodeAt (0)]) : this.stringWidth ("" + pt)); +}, "~S"); +Clazz.defineMethod (c$, "charWidth", +function (pt) { +return (pt < 256 ? Clazz.floatToInt (this.getWidthsFloat ()[pt]) : this.stringWidth ("" + String.fromCharCode (pt))); +}, "~N"); +Clazz.overrideMethod (c$, "stringWidth", +function (s) { +return Clazz.floatToInt (swingjs.JSToolkit.getStringWidth (null, this.font, s)); +}, "~S"); +Clazz.overrideMethod (c$, "getWidths", +function () { +if (this.iwidths != null) return this.iwidths; +this.iwidths = Clazz.newIntArray (256, 0); +this.getWidthsFloat (); +for (var ch = 0; ch < 256; ch++) { +this.iwidths[ch] = Clazz.floatToInt (this.widths[ch]); +} +return this.iwidths; +}); +Clazz.defineMethod (c$, "getWidthsFloat", +function () { +if (this.widths != null) return this.widths; +this.widths = Clazz.newFloatArray (256, 0); +for (var ch = 0; ch < 256; ch++) { +this.widths[ch] = swingjs.JSToolkit.getStringWidth (null, this.font, "" + String.fromCharCode (ch)); +} +return this.widths; +}); +});