KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > font > AWTFontFamily


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.gvt.font;
19
20 import java.awt.Font JavaDoc;
21 import java.awt.font.TextAttribute JavaDoc;
22 import java.text.AttributedCharacterIterator JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
26
27 /**
28  * A font family class for AWT fonts.
29  *
30  * @author <a HREF="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
31  * @version $Id: AWTFontFamily.java,v 1.9 2005/03/27 08:58:34 cam Exp $
32  */

33 public class AWTFontFamily implements GVTFontFamily {
34
35     protected GVTFontFace fontFace;
36     protected Font JavaDoc font;
37
38     /**
39      * Constructs an AWTFontFamily with the specified familyName.
40      *
41      * @param fontFace The name of the font family.
42      */

43     public AWTFontFamily(GVTFontFace fontFace) {
44         this.fontFace = fontFace;
45     }
46
47     /**
48      * Constructs an AWTFontFamily with the specified familyName.
49      *
50      * @param familyName The name of the font family.
51      */

52     public AWTFontFamily(String JavaDoc familyName) {
53         this(new GVTFontFace(familyName));
54     }
55
56     /**
57      * Constructs an AWTFontFamily with the specified familyName.
58      *
59      * @param fontFace The name of the font family.
60      */

61     public AWTFontFamily(GVTFontFace fontFace, Font JavaDoc font) {
62         this.fontFace = fontFace;
63         this.font = font;
64     }
65
66     /**
67      * Returns the font family name.
68      *
69      * @return The family name.
70      */

71     public String JavaDoc getFamilyName() {
72         return fontFace.getFamilyName();
73     }
74
75     /**
76      * Returns the font-face information for this font family.
77      */

78     public GVTFontFace getFontFace() {
79         return fontFace;
80     }
81
82     /**
83      * Derives a GVTFont object of the correct size.
84      *
85      * @param size The required size of the derived font.
86      * @param aci The character iterator that will be rendered using
87      * the derived font.
88      */

89     public GVTFont deriveFont(float size, AttributedCharacterIterator JavaDoc aci) {
90         if (font != null)
91             return new AWTGVTFont(font, size);
92
93         return deriveFont(size, aci.getAttributes());
94     }
95
96
97     /**
98      * Derives a GVTFont object of the correct size from an attribute Map.
99      * @param size The required size of the derived font.
100      * @param attrs The Attribute Map to get Values from.
101      */

102     public GVTFont deriveFont(float size, Map JavaDoc attrs) {
103         if (font != null)
104             return new AWTGVTFont(font, size);
105
106         Map JavaDoc fontAttributes = new HashMap JavaDoc(attrs);
107         fontAttributes.put(TextAttribute.SIZE, new Float JavaDoc(size));
108         fontAttributes.put(TextAttribute.FAMILY, fontFace.getFamilyName());
109         fontAttributes.remove(GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
110         return new AWTGVTFont(fontAttributes);
111     }
112      
113 }
114
Popular Tags