KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 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 org.apache.batik.util.SVGConstants;
21
22 /**
23  * One line Class Desc
24  *
25  * Complete Class Desc
26  *
27  * @author <a HREF="mailto:deweese@apache.org">l449433</a>
28  * @version $Id: GVTFontFace.java,v 1.6 2005/03/27 08:58:34 cam Exp $
29  */

30 public class GVTFontFace implements SVGConstants {
31     protected String JavaDoc familyName;
32     protected float unitsPerEm;
33     protected String JavaDoc fontWeight;
34     protected String JavaDoc fontStyle;
35     protected String JavaDoc fontVariant;
36     protected String JavaDoc fontStretch;
37     protected float slope;
38     protected String JavaDoc panose1;
39     protected float ascent;
40     protected float descent;
41     protected float strikethroughPosition;
42     protected float strikethroughThickness;
43     protected float underlinePosition;
44     protected float underlineThickness;
45     protected float overlinePosition;
46     protected float overlineThickness;
47
48     /**
49      * Constructes an GVTFontFace with the specfied font-face attributes.
50      */

51     public GVTFontFace
52         (String JavaDoc familyName, float unitsPerEm, String JavaDoc fontWeight,
53          String JavaDoc fontStyle, String JavaDoc fontVariant, String JavaDoc fontStretch,
54          float slope, String JavaDoc panose1, float ascent, float descent,
55          float strikethroughPosition, float strikethroughThickness,
56          float underlinePosition, float underlineThickness,
57          float overlinePosition, float overlineThickness) {
58         this.familyName = familyName;
59         this.unitsPerEm = unitsPerEm;
60         this.fontWeight = fontWeight;
61         this.fontStyle = fontStyle;
62         this.fontVariant = fontVariant;
63         this.fontStretch = fontStretch;
64         this.slope = slope;
65         this.panose1 = panose1;
66         this.ascent = ascent;
67         this.descent = descent;
68         this.strikethroughPosition = strikethroughPosition;
69         this.strikethroughThickness = strikethroughThickness;
70         this.underlinePosition = underlinePosition;
71         this.underlineThickness = underlineThickness;
72         this.overlinePosition = overlinePosition;
73         this.overlineThickness = overlineThickness;
74     }
75
76     /**
77      * Constructs an SVGFontFace with default values for all the
78      * font-face attributes other than familyName
79      */

80     public GVTFontFace(String JavaDoc familyName) {
81         this(familyName, 1000,
82              SVG_FONT_FACE_FONT_WEIGHT_DEFAULT_VALUE,
83              SVG_FONT_FACE_FONT_STYLE_DEFAULT_VALUE,
84              SVG_FONT_FACE_FONT_VARIANT_DEFAULT_VALUE,
85              SVG_FONT_FACE_FONT_STRETCH_DEFAULT_VALUE,
86              0, SVG_FONT_FACE_PANOSE_1_DEFAULT_VALUE,
87              800, 200, 300, 50, -75, 50, 800, 50);
88     }
89
90     /**
91      * Returns the family name of this font, it may contain more than one.
92      */

93     public String JavaDoc getFamilyName() {
94         return familyName;
95     }
96
97     public boolean hasFamilyName(String JavaDoc family) {
98         String JavaDoc ffname = familyName;
99         if (ffname.length() < family.length()) {
100             return false;
101         }
102
103         ffname = ffname.toLowerCase();
104
105         int idx = ffname.indexOf(family.toLowerCase());
106
107         if (idx == -1) {
108             return false;
109         }
110
111         // see if the family name is not the part of a bigger family name.
112
if (ffname.length() > family.length()) {
113             boolean quote = false;
114             if (idx > 0) {
115                 char c = ffname.charAt(idx - 1);
116                 switch (c) {
117                 default:
118                     return false;
119                 case ' ':
120                     loop: for (int i = idx - 2; i >= 0; --i) {
121                         switch (ffname.charAt(i)) {
122                         default:
123                             return false;
124                         case ' ':
125                             continue;
126                         case '"':
127                         case '\'':
128                             quote = true;
129                             break loop;
130                         }
131                     }
132                     break;
133                 case '"':
134                 case '\'':
135                     quote = true;
136                 case ',':
137                 }
138             }
139             if (idx + family.length() < ffname.length()) {
140                 char c = ffname.charAt(idx + family.length());
141                 switch (c) {
142                 default:
143                     return false;
144                 case ' ':
145                     loop: for (int i = idx + family.length() + 1;
146                          i < ffname.length(); i++) {
147                         switch (ffname.charAt(i)) {
148                         default:
149                             return false;
150                         case ' ':
151                             continue;
152                         case '"':
153                         case '\'':
154                             if (!quote) {
155                                 return false;
156                             }
157                             break loop;
158                         }
159                     }
160                     break;
161                 case '"':
162                 case '\'':
163                     if (!quote) {
164                         return false;
165                     }
166                 case ',':
167                 }
168             }
169         }
170         return true;
171     }
172
173     /**
174      * Returns the font-weight.
175      */

176     public String JavaDoc getFontWeight() {
177         return fontWeight;
178     }
179
180     /**
181      * Returns the font-style.
182      */

183     public String JavaDoc getFontStyle() {
184         return fontStyle;
185     }
186
187     /**
188      * The number of coordinate units on the em square for this font.
189      */

190     public float getUnitsPerEm() {
191         return unitsPerEm;
192     }
193
194     /**
195      * Returns the maximum unaccented height of the font within the font
196      * coordinate system.
197      */

198     public float getAscent() {
199         return ascent;
200     }
201
202     /**
203      * Returns the maximum unaccented depth of the font within the font
204      * coordinate system.
205      */

206     public float getDescent() {
207         return descent;
208     }
209
210     /**
211      * Returns the position of the strikethrough decoration.
212      */

213     public float getStrikethroughPosition() {
214         return strikethroughPosition;
215     }
216
217     /**
218      * Returns the stroke thickness to use when drawing a strikethrough.
219      */

220     public float getStrikethroughThickness() {
221         return strikethroughThickness;
222     }
223
224     /**
225      * Returns the position of the underline decoration.
226      */

227     public float getUnderlinePosition() {
228         return underlinePosition;
229     }
230
231     /**
232      * Returns the stroke thickness to use when drawing a underline.
233      */

234     public float getUnderlineThickness() {
235         return underlineThickness;
236     }
237
238     /**
239      * Returns the position of the overline decoration.
240      */

241     public float getOverlinePosition() {
242         return overlinePosition;
243     }
244
245     /**
246      * Returns the stroke thickness to use when drawing a overline.
247      */

248     public float getOverlineThickness() {
249         return overlineThickness;
250     }
251 }
252
Popular Tags