JAL-1807 test
[jalviewjs.git] / bin / javajs / awt / Font.js
1 Clazz.declarePackage ("javajs.awt");
2 Clazz.load (null, "javajs.awt.Font", ["javajs.util.AU"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.fid = 0;
5 this.fontFace = null;
6 this.fontStyle = null;
7 this.fontSizeNominal = 0;
8 this.idFontFace = 0;
9 this.idFontStyle = 0;
10 this.fontSize = 0;
11 this.font = null;
12 this.fontMetrics = null;
13 this.manager = null;
14 this.ascent = 0;
15 this.descent = 0;
16 this.isBold = false;
17 this.isItalic = false;
18 Clazz.instantialize (this, arguments);
19 }, javajs.awt, "Font");
20 Clazz.makeConstructor (c$, 
21 ($fz = function (manager, fid, idFontFace, idFontStyle, fontSize, fontSizeNominal, graphics) {
22 this.manager = manager;
23 this.fid = fid;
24 this.fontFace = javajs.awt.Font.fontFaces[idFontFace];
25 this.fontStyle = javajs.awt.Font.fontStyles[idFontStyle];
26 this.idFontFace = idFontFace;
27 this.idFontStyle = idFontStyle;
28 this.fontSize = fontSize;
29 this.isBold = (idFontStyle & 1) == 1;
30 this.isItalic = (idFontStyle & 2) == 2;
31 this.fontSizeNominal = fontSizeNominal;
32 this.font = manager.newFont (javajs.awt.Font.fontFaces[idFontFace], this.isBold, this.isItalic, fontSize);
33 this.fontMetrics = manager.getFontMetrics (this, graphics);
34 this.descent = manager.getFontDescent (this.fontMetrics);
35 this.ascent = manager.getFontAscent (this.fontMetrics);
36 }, $fz.isPrivate = true, $fz), "javajs.api.FontManager,~N,~N,~N,~N,~N,~O");
37 c$.getFont3D = Clazz.defineMethod (c$, "getFont3D", 
38 function (fontID) {
39 return javajs.awt.Font.font3ds[fontID & 0xFF];
40 }, "~N");
41 c$.createFont3D = Clazz.defineMethod (c$, "createFont3D", 
42 function (fontface, fontstyle, fontsize, fontsizeNominal, manager, graphicsForMetrics) {
43 if (fontsize > 0xFF) fontsize = 0xFF;
44 var fontsizeX16 = (Clazz.floatToInt (fontsize)) << 4;
45 var fontkey = ((fontface & 3) | ((fontstyle & 3) << 2) | (fontsizeX16 << 4));
46 for (var i = javajs.awt.Font.fontkeyCount; --i > 0; ) if (fontkey == javajs.awt.Font.fontkeys[i] && javajs.awt.Font.font3ds[i].fontSizeNominal == fontsizeNominal) return javajs.awt.Font.font3ds[i];
47
48 var fontIndexNext = javajs.awt.Font.fontkeyCount++;
49 if (fontIndexNext == javajs.awt.Font.fontkeys.length) javajs.awt.Font.fontkeys = javajs.util.AU.arrayCopyI (javajs.awt.Font.fontkeys, fontIndexNext + 8);
50 javajs.awt.Font.font3ds = javajs.util.AU.arrayCopyObject (javajs.awt.Font.font3ds, fontIndexNext + 8);
51 var font3d =  new javajs.awt.Font (manager, fontIndexNext, fontface, fontstyle, fontsize, fontsizeNominal, graphicsForMetrics);
52 javajs.awt.Font.font3ds[fontIndexNext] = font3d;
53 javajs.awt.Font.fontkeys[fontIndexNext] = fontkey;
54 return font3d;
55 }, "~N,~N,~N,~N,javajs.api.FontManager,~O");
56 c$.getFontFaceID = Clazz.defineMethod (c$, "getFontFaceID", 
57 function (fontface) {
58 return ("Monospaced".equalsIgnoreCase (fontface) ? 2 : "Serif".equalsIgnoreCase (fontface) ? 1 : 0);
59 }, "~S");
60 c$.getFontStyleID = Clazz.defineMethod (c$, "getFontStyleID", 
61 function (fontstyle) {
62 for (var i = 4; --i >= 0; ) if (javajs.awt.Font.fontStyles[i].equalsIgnoreCase (fontstyle)) return i;
63
64 return -1;
65 }, "~S");
66 Clazz.defineMethod (c$, "getAscent", 
67 function () {
68 return this.ascent;
69 });
70 Clazz.defineMethod (c$, "getDescent", 
71 function () {
72 return this.descent;
73 });
74 Clazz.defineMethod (c$, "getHeight", 
75 function () {
76 return this.getAscent () + this.getDescent ();
77 });
78 Clazz.defineMethod (c$, "getFontMetrics", 
79 function () {
80 return this.fontMetrics;
81 });
82 Clazz.defineMethod (c$, "stringWidth", 
83 function (text) {
84 return this.manager.fontStringWidth (this, text);
85 }, "~S");
86 Clazz.defineMethod (c$, "getInfo", 
87 function () {
88 return this.fontSizeNominal + " " + this.fontFace + " " + this.fontStyle;
89 });
90 Clazz.defineStatics (c$,
91 "FONT_ALLOCATION_UNIT", 8,
92 "fontkeyCount", 1,
93 "fontkeys",  Clazz.newIntArray (8, 0));
94 c$.font3ds = c$.prototype.font3ds =  new Array (8);
95 Clazz.defineStatics (c$,
96 "FONT_FACE_SANS", 0,
97 "FONT_FACE_SERIF", 1,
98 "FONT_FACE_MONO", 2,
99 "fontFaces",  Clazz.newArray (-1, ["SansSerif", "Serif", "Monospaced", ""]),
100 "FONT_STYLE_PLAIN", 0,
101 "FONT_STYLE_BOLD", 1,
102 "FONT_STYLE_ITALIC", 2,
103 "FONT_STYLE_BOLDITALIC", 3,
104 "fontStyles",  Clazz.newArray (-1, ["Plain", "Bold", "Italic", "BoldItalic"]));
105 });