KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > FontFamily


1 /*****************************************************************************
2  * FontFamily.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.compiler;
11
12 import org.openlaszlo.iv.flash.api.text.*;
13
14 import java.awt.geom.Rectangle2D JavaDoc;
15
16 /**
17  * Class for holding Font Families
18  *
19  * @author Eric Bloch
20  */

21 final class FontFamily {
22
23     private Rectangle2D JavaDoc[] boundsPlain = null;
24     private Rectangle2D JavaDoc[] boundsBold = null;
25     private Rectangle2D JavaDoc[] boundsItalic = null;
26     private Rectangle2D JavaDoc[] boundsBitalic = null;
27
28     public FontFamily() {
29         plain = null;
30         bold = null;
31         italic = null;
32         bitalic = null;
33     }
34     /**
35      * Create a font description
36      */

37     public FontFamily(Font plain, Font bold, Font italic, Font bitalic) {
38         this.plain = plain;
39         this.bold = bold;
40         this.italic = italic;
41         this.bitalic = bitalic;
42     }
43
44     /**
45      * @return the font font for the given style
46      */

47     public Font getStyle(int style) {
48         switch (style) {
49         case FontInfo.PLAIN:
50             return plain;
51         case FontInfo.BOLD:
52             return bold;
53         case FontInfo.ITALIC:
54             return italic;
55         case FontInfo.BOLDITALIC:
56             return bitalic;
57         default:
58             throw new CompilationError("Unknown style " + style);
59         }
60     }
61     
62     private String JavaDoc getBookRecommendations() {
63         return "http://www.wetmachine.com/books.html";
64     }
65     
66     /**
67      * @return the glpyh bounds array for this font
68      */

69     public Rectangle2D JavaDoc[] getBounds(int style) {
70         switch (style) {
71         case FontInfo.PLAIN:
72             if (plain != null && boundsPlain == null) {
73                 boundsPlain = plain.getGlyphBounds();
74             }
75             return boundsPlain;
76         case FontInfo.BOLD:
77             if (bold != null && boundsBold == null) {
78                 boundsBold = bold.getGlyphBounds();
79             }
80             return boundsBold;
81         case FontInfo.ITALIC:
82             if (italic != null && boundsItalic == null) {
83                 boundsItalic = italic.getGlyphBounds();
84             }
85             return boundsItalic;
86         case FontInfo.BOLDITALIC:
87             if (bitalic != null && boundsBitalic == null) {
88                 boundsBitalic = bitalic.getGlyphBounds();
89             }
90             return boundsBitalic;
91         default:
92             throw new CompilationError("Unknown style " + style);
93         }
94     }
95
96     /** the plain font */
97     public Font plain = null;
98     /** the bold font */
99     public Font bold = null;
100     /** the italic font */
101     public Font italic = null;
102     /** the bold italic font */
103     public Font bitalic = null;
104 }
105
Popular Tags