View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Excel is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Excel; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.excel.records;
22  
23  import org.millscript.office.excel.Record;
24  import org.millscript.office.excel.alerts.BIFFAlert;
25  
26  import java.nio.charset.Charset;
27  
28  /**
29   * 
30   */
31  public class Font extends Record {
32  
33      /**
34       *
35       */
36      public enum EscapementType {
37  
38          None, Superscript, Subscript;
39  
40          public static EscapementType getEscapementType( final int type ) {
41              switch ( type ) {
42                  case 0x0000:
43                      return None;
44                  case 0x0001:
45                      return Superscript;
46                  case 0x0002:
47                      return Subscript;
48                  default:
49                      throw new BIFFAlert(
50                          "Unknown escapement type for FONT record"
51                      ).culprit( "type", type ).mishap();
52              }
53          }
54  
55      }
56  
57      /**
58       *
59       */
60      public enum FontFamily {
61  
62          None, Roman, Swiss, Modern, Script, Decorative;
63  
64          public static FontFamily getFontFamily( final int family ) {
65              switch ( family ) {
66                  case 0x0000:
67                      return None;
68                  case 0x0001:
69                      return Roman;
70                  case 0x0002:
71                      return Swiss;
72                  case 0x0003:
73                      return Modern;
74                  case 0x0004:
75                      return Script;
76                  case 0x0005:
77                      return Decorative;
78                  default:
79                      throw new BIFFAlert(
80                          "Unknown font family for FONT record"
81                      ).culprit( "family", family ).mishap();
82              }
83          }
84  
85      }
86  
87      /**
88       *
89       */
90      public enum UnderlineType {
91  
92          None, Single, Double, SingleAccounting, DoubleAccounting;
93  
94          public static UnderlineType getUnderlineType( final int type ) {
95              switch ( type ) {
96                  case 0x0000:
97                      return None;
98                  case 0x0001:
99                      return Single;
100                 case 0x0002:
101                     return Double;
102                 case 0x0021:
103                     return SingleAccounting;
104                 case 0x0022:
105                     return DoubleAccounting;
106                 default:
107                     throw new BIFFAlert(
108                         "Unknown underline type for FONT record"
109                     ).culprit( "type", type ).mishap();
110             }
111         }
112 
113     }
114 
115     private Charset charset;
116 
117     private char colourIndex;
118 
119     private EscapementType escapementType;
120 
121     private FontFamily fontFamily;
122 
123     private java.lang.String fontName;
124 
125     private char fontWeight;
126 
127     private char fontHeight;
128 
129     private char options;
130 
131     private boolean recommendReadOnlyWhileLoading;
132 
133     private UnderlineType underlineType;
134 
135     private java.lang.String userNameOfFileCreator;
136 
137     public Font( final char height, final char opt ) {
138         this.fontHeight = height;
139         this.options = opt;
140     }
141 
142     public boolean charactersAreBold() {
143         return 1 == ( this.options & 0x0001 );
144     }
145 
146     public boolean charactersAreItalic() {
147         return 2 == ( this.options & 0x0002 );
148     }
149 
150     public boolean charactersAreStruckOut() {
151         return 8 == ( this.options & 0x0008 );
152     }
153 
154     public boolean charactersAreUnderlined() {
155         return 4 == ( this.options & 0x0004 );
156     }
157 
158     /**
159      * @param set The charset to set.
160      */
161     public void setCharset( final Charset set ) {
162         this.charset = set;
163     }
164 
165     /**
166      * @param index The colourIndex to set.
167      */
168     public void setColourIndex( final char index ) {
169         this.colourIndex = index;
170     }
171 
172     /**
173      * @param type The escapementType to set.
174      */
175     public void setEscapementType( final EscapementType type ) {
176         this.escapementType = type;
177     }
178 
179     /**
180      * @param family The fontFamily to set.
181      */
182     public void setFontFamily( final FontFamily family ) {
183         this.fontFamily = family;
184     }
185 
186     /**
187      * @param name The fontName to set.
188      */
189     public void setFontName( final java.lang.String name ) {
190         this.fontName = name;
191     }
192 
193     /**
194      * @param weight The fontWeight to set.
195      */
196     public void setFontWeight( final char weight ) {
197         this.fontWeight = weight;
198     }
199 
200     /**
201      * @param readonly The recommendReadOnlyWhileLoading to set.
202      */
203     public void setRecommendReadOnlyWhileLoading( final boolean readonly ) {
204         this.recommendReadOnlyWhileLoading = readonly;
205     }
206 
207     /**
208      * @param type The underlineType to set.
209      */
210     public void setUnderlineType( final UnderlineType type ) {
211         this.underlineType = type;
212     }
213 
214     /**
215      * @param name The userNameOfFileCreator to set.
216      */
217     public void setUserNameOfFileCreator( final java.lang.String name ) {
218         this.userNameOfFileCreator = name;
219     }
220 
221 }