1 Clazz.declarePackage ("java.awt");
2 Clazz.load (null, "java.awt.Font", ["java.awt.font.TextAttribute", "java.awt.geom.AffineTransform", "swingjs.JSToolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
9 this.$hasLayoutAttributes = false;
10 this.nonIdentityTx = false;
12 Clazz.instantialize (this, arguments);
14 Clazz.makeConstructor (c$,
15 function (name, style, size) {
16 this.name = (name != null) ? name : "Default";
17 this.style = (style & -4) == 0 ? style : 0;
19 this.pointSize = size;
21 Clazz.makeConstructor (c$,
22 function (name, style, sizePts) {
23 this.name = (name != null) ? name : "Default";
24 this.style = (style & -4) == 0 ? style : 0;
25 this.size = Clazz.doubleToInt (sizePts + 0.5);
26 this.pointSize = sizePts;
28 Clazz.makeConstructor (c$,
30 this.name = font.name;
31 this.style = font.style;
32 this.size = font.size;
33 this.pointSize = font.pointSize;
35 Clazz.defineMethod (c$, "getTransform",
37 return new java.awt.geom.AffineTransform ();
39 Clazz.defineMethod (c$, "getFamily",
41 return (this.family == null ? this.family = swingjs.JSToolkit.getFontFamily (this) : this.family);
43 Clazz.defineMethod (c$, "getName",
47 Clazz.defineMethod (c$, "getFontName",
51 Clazz.defineMethod (c$, "getStyle",
55 Clazz.defineMethod (c$, "getSize",
59 Clazz.defineMethod (c$, "getSize2D",
61 return this.pointSize;
63 Clazz.defineMethod (c$, "isPlain",
65 return this.style == 0;
67 Clazz.defineMethod (c$, "isBold",
69 return (this.style & 1) != 0;
71 Clazz.defineMethod (c$, "isItalic",
73 return (this.style & 2) != 0;
75 Clazz.defineMethod (c$, "isTransformed",
77 return this.nonIdentityTx;
79 Clazz.defineMethod (c$, "hasLayoutAttributes",
81 return this.$hasLayoutAttributes;
83 c$.getFont = Clazz.defineMethod (c$, "getFont",
85 return java.awt.Font.getFont (nm, null);
87 c$.decode = Clazz.defineMethod (c$, "decode",
94 return new java.awt.Font ("Dialog", fontStyle, fontSize);
95 }var lastHyphen = str.lastIndexOf ('-');
96 var lastSpace = str.lastIndexOf (' ');
97 var sepChar = (lastHyphen > lastSpace) ? '-' : ' ';
98 var sizeIndex = str.lastIndexOf (sepChar);
99 var styleIndex = str.lastIndexOf (sepChar, sizeIndex - 1);
100 var strlen = str.length;
101 if (sizeIndex > 0 && sizeIndex + 1 < strlen) {
103 fontSize = Integer.$valueOf (str.substring (sizeIndex + 1)).intValue ();
107 if (Clazz.exceptionOf (e, NumberFormatException)) {
108 styleIndex = sizeIndex;
110 if (str.charAt (sizeIndex - 1) == sepChar) {
116 }if (styleIndex >= 0 && styleIndex + 1 < strlen) {
117 styleName = str.substring (styleIndex + 1, sizeIndex);
118 styleName = styleName.toLowerCase ();
119 if (styleName.equals ("bolditalic")) {
121 } else if (styleName.equals ("italic")) {
123 } else if (styleName.equals ("bold")) {
125 } else if (styleName.equals ("plain")) {
128 styleIndex = sizeIndex;
129 if (str.charAt (styleIndex - 1) == sepChar) {
131 }}fontName = str.substring (0, styleIndex);
133 var fontEnd = strlen;
134 if (styleIndex > 0) {
135 fontEnd = styleIndex;
136 } else if (sizeIndex > 0) {
138 }if (fontEnd > 0 && str.charAt (fontEnd - 1) == sepChar) {
140 }fontName = str.substring (0, fontEnd);
141 }return new java.awt.Font (fontName, fontStyle, fontSize);
143 c$.getFont = Clazz.defineMethod (c$, "getFont",
144 function (nm, font) {
147 str = System.getProperty (nm);
149 if (Clazz.exceptionOf (e, SecurityException)) {
156 }return java.awt.Font.decode (str);
157 }, "~S,java.awt.Font");
158 Clazz.overrideMethod (c$, "hashCode",
160 if (this.hash == 0) {
161 this.hash = this.name.hashCode () ^ this.style ^ this.size;
164 Clazz.overrideMethod (c$, "equals",
171 if (this.size == font.size && this.style == font.style && this.nonIdentityTx == font.nonIdentityTx && this.$hasLayoutAttributes == font.$hasLayoutAttributes && this.pointSize == font.pointSize && this.name.equals (font.name)) {
174 if (Clazz.exceptionOf (e, ClassCastException)) {
181 Clazz.overrideMethod (c$, "toString",
184 if (this.isBold ()) {
185 strStyle = this.isItalic () ? "bolditalic" : "bold";
187 strStyle = this.isItalic () ? "italic" : "plain";
188 }return this.getClass ().getName () + "[family=" + this.getFamily () + ",name=" + this.name + ",style=" + strStyle + ",size=" + this.size + "]";
190 Clazz.defineMethod (c$, "getAvailableAttributes",
192 var attributes = Clazz.newArray (-1, [java.awt.font.TextAttribute.FAMILY, java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WIDTH, java.awt.font.TextAttribute.SIZE, java.awt.font.TextAttribute.UNDERLINE, java.awt.font.TextAttribute.STRIKETHROUGH]);
195 Clazz.defineMethod (c$, "deriveFont",
196 function (style, size) {
197 return new java.awt.Font (this.name, style, size);
199 Clazz.defineMethod (c$, "deriveFont",
201 return new java.awt.Font (this.name, this.style, size);
203 Clazz.defineMethod (c$, "deriveFont",
205 return new java.awt.Font (this.name, style, this.size);
207 Clazz.defineMethod (c$, "hasUniformLineMetrics",
211 Clazz.overrideMethod (c$, "finalize",
214 Clazz.defineStatics (c$,
216 "DIALOG_INPUT", "DialogInput",
217 "SANS_SERIF", "SansSerif",
219 "MONOSPACED", "Monospaced",
224 "CENTER_BASELINE", 1,
225 "HANGING_BASELINE", 2,
228 "LAYOUT_LEFT_TO_RIGHT", 0,
229 "LAYOUT_RIGHT_TO_LEFT", 1,
230 "LAYOUT_NO_START_CONTEXT", 2,
231 "LAYOUT_NO_LIMIT_CONTEXT", 4);