KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > HSSFFont


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

16
17
18 /*
19  * HSSFFont.java
20  *
21  * Created on December 9, 2001, 10:34 AM
22  */

23 package org.apache.poi.hssf.usermodel;
24
25 import org.apache.poi.hssf.record.FontRecord;
26
27 /**
28  * Represents a Font used in a workbook.
29  *
30  * @version 1.0-pre
31  * @author Andrew C. Oliver
32  * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
33  * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
34  * @see org.apache.poi.hssf.usermodel.HSSFCellStyle#setFont(HSSFFont)
35  */

36
37 public class HSSFFont
38 {
39
40     /**
41      * Arial font
42      */

43
44     public final static String JavaDoc FONT_ARIAL = "Arial";
45
46     /**
47      * Normal boldness (not bold)
48      */

49
50     public final static short BOLDWEIGHT_NORMAL = 0x190;
51
52     /**
53      * Bold boldness (bold)
54      */

55
56     public final static short BOLDWEIGHT_BOLD = 0x2bc;
57
58     /**
59      * normal type of black color
60      */

61
62     public final static short COLOR_NORMAL = 0x7fff;
63
64     /**
65      * Dark Red color
66      */

67
68     public final static short COLOR_RED = 0xa;
69
70     /**
71      * no type offsetting (not super or subscript)
72      */

73
74     public final static short SS_NONE = 0;
75
76     /**
77      * superscript
78      */

79
80     public final static short SS_SUPER = 1;
81
82     /**
83      * subscript
84      */

85
86     public final static short SS_SUB = 2;
87
88     /**
89      * not underlined
90      */

91
92     public final static byte U_NONE = 0;
93
94     /**
95      * single (normal) underline
96      */

97
98     public final static byte U_SINGLE = 1;
99
100     /**
101      * double underlined
102      */

103
104     public final static byte U_DOUBLE = 2;
105
106     /**
107      * accounting style single underline
108      */

109
110     public final static byte U_SINGLE_ACCOUNTING = 0x21;
111
112     /**
113      * accounting style double underline
114      */

115
116     public final static byte U_DOUBLE_ACCOUNTING = 0x22;
117     private FontRecord font;
118     private short index;
119
120     /** Creates a new instance of HSSFFont */
121
122     protected HSSFFont(short index, FontRecord rec)
123     {
124         font = rec;
125         this.index = index;
126     }
127
128     /**
129      * set the name for the font (i.e. Arial)
130      * @param name String representing the name of the font to use
131      * @see #FONT_ARIAL
132      */

133
134     public void setFontName(String JavaDoc name)
135     {
136         font.setFontName(name);
137         font.setFontNameLength(( byte ) name.length());
138     }
139
140     /**
141      * get the name for the font (i.e. Arial)
142      * @return String representing the name of the font to use
143      * @see #FONT_ARIAL
144      */

145
146     public String JavaDoc getFontName()
147     {
148         return font.getFontName();
149     }
150
151     /**
152      * get the index within the HSSFWorkbook (sequence within the collection of Font objects)
153      * @return unique index number of the underlying record this Font represents (probably you don't care
154      * unless you're comparing which one is which)
155      */

156
157     public short getIndex()
158     {
159         return index;
160     }
161
162     /**
163      * set the font height in unit's of 1/20th of a point. Maybe you might want to
164      * use the setFontHeightInPoints which matches to the familiar 10, 12, 14 etc..
165      * @param height height in 1/20ths of a point
166      * @see #setFontHeightInPoints(short)
167      */

168
169     public void setFontHeight(short height)
170     {
171         font.setFontHeight(height);
172     }
173
174     /**
175      * set the font height
176      * @param height height in the familiar unit of measure - points
177      * @see #setFontHeight(short)
178      */

179
180     public void setFontHeightInPoints(short height)
181     {
182         font.setFontHeight(( short ) (height * 20));
183     }
184
185     /**
186      * get the font height in unit's of 1/20th of a point. Maybe you might want to
187      * use the getFontHeightInPoints which matches to the familiar 10, 12, 14 etc..
188      * @return short - height in 1/20ths of a point
189      * @see #getFontHeightInPoints()
190      */

191
192     public short getFontHeight()
193     {
194         return font.getFontHeight();
195     }
196
197     /**
198      * get the font height
199      * @return short - height in the familiar unit of measure - points
200      * @see #getFontHeight()
201      */

202
203     public short getFontHeightInPoints()
204     {
205         return ( short ) (font.getFontHeight() / 20);
206     }
207
208     /**
209      * set whether to use italics or not
210      * @param italic italics or not
211      */

212
213     public void setItalic(boolean italic)
214     {
215         font.setItalic(italic);
216     }
217
218     /**
219      * get whether to use italics or not
220      * @return italics or not
221      */

222
223     public boolean getItalic()
224     {
225         return font.isItalic();
226     }
227
228     /**
229      * set whether to use a strikeout horizontal line through the text or not
230      * @param strikeout or not
231      */

232
233     public void setStrikeout(boolean strikeout)
234     {
235         font.setStrikeout(strikeout);
236     }
237
238     /**
239      * get whether to use a strikeout horizontal line through the text or not
240      * @return strikeout or not
241      */

242
243     public boolean getStrikeout()
244     {
245         return font.isStruckout();
246     }
247
248     /**
249      * set the color for the font
250      * @param color to use
251      * @see #COLOR_NORMAL
252      * @see #COLOR_RED
253      */

254
255     public void setColor(short color)
256     {
257         font.setColorPaletteIndex(color);
258     }
259
260     /**
261      * get the color for the font
262      * @return color to use
263      * @see #COLOR_NORMAL
264      * @see #COLOR_RED
265      */

266
267     public short getColor()
268     {
269         return font.getColorPaletteIndex();
270     }
271
272     /**
273      * set the boldness to use
274      * @param boldweight
275      * @see #BOLDWEIGHT_NORMAL
276      * @see #BOLDWEIGHT_BOLD
277      */

278
279     public void setBoldweight(short boldweight)
280     {
281         font.setBoldWeight(boldweight);
282     }
283
284     /**
285      * get the boldness to use
286      * @return boldweight
287      * @see #BOLDWEIGHT_NORMAL
288      * @see #BOLDWEIGHT_BOLD
289      */

290
291     public short getBoldweight()
292     {
293         return font.getBoldWeight();
294     }
295
296     /**
297      * set normal,super or subscript.
298      * @param offset type to use (none,super,sub)
299      * @see #SS_NONE
300      * @see #SS_SUPER
301      * @see #SS_SUB
302      */

303
304     public void setTypeOffset(short offset)
305     {
306         font.setSuperSubScript(offset);
307     }
308
309     /**
310      * get normal,super or subscript.
311      * @return offset type to use (none,super,sub)
312      * @see #SS_NONE
313      * @see #SS_SUPER
314      * @see #SS_SUB
315      */

316
317     public short getTypeOffset()
318     {
319         return font.getSuperSubScript();
320     }
321
322     /**
323      * set type of text underlining to use
324      * @param underline type
325      * @see #U_NONE
326      * @see #U_SINGLE
327      * @see #U_DOUBLE
328      * @see #U_SINGLE_ACCOUNTING
329      * @see #U_DOUBLE_ACCOUNTING
330      */

331
332     public void setUnderline(byte underline)
333     {
334         font.setUnderline(underline);
335     }
336
337     /**
338      * get type of text underlining to use
339      * @return underlining type
340      * @see #U_NONE
341      * @see #U_SINGLE
342      * @see #U_DOUBLE
343      * @see #U_SINGLE_ACCOUNTING
344      * @see #U_DOUBLE_ACCOUNTING
345      */

346
347     public byte getUnderline()
348     {
349         return font.getUnderline();
350     }
351
352     public String JavaDoc toString()
353     {
354         return "org.apache.poi.hssf.usermodel.HSSFFont{" +
355                  font +
356                 "}";
357     }
358
359
360 }
361
Popular Tags