1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================== */
18 package org
.apache
.poi
.hssf
.usermodel
;
20 import org
.apache
.poi
.hssf
.record
.CFRuleRecord
;
21 import org
.apache
.poi
.hssf
.record
.cf
.FontFormatting
;
23 * High level representation for Font Formatting component
24 * of Conditional Formatting settings
26 * @author Dmitriy Kumshayev
29 public final class HSSFFontFormatting
31 /** Escapement type - None */
32 public final static short SS_NONE
= FontFormatting
.SS_NONE
;
33 /** Escapement type - Superscript */
34 public final static short SS_SUPER
= FontFormatting
.SS_SUPER
;
35 /** Escapement type - Subscript */
36 public final static short SS_SUB
= FontFormatting
.SS_SUB
;
38 /** Underline type - None */
39 public final static byte U_NONE
= FontFormatting
.U_NONE
;
40 /** Underline type - Single */
41 public final static byte U_SINGLE
= FontFormatting
.U_SINGLE
;
42 /** Underline type - Double */
43 public final static byte U_DOUBLE
= FontFormatting
.U_DOUBLE
;
44 /** Underline type - Single Accounting */
45 public final static byte U_SINGLE_ACCOUNTING
= FontFormatting
.U_SINGLE_ACCOUNTING
;
46 /** Underline type - Double Accounting */
47 public final static byte U_DOUBLE_ACCOUNTING
= FontFormatting
.U_DOUBLE_ACCOUNTING
;
49 private final FontFormatting fontFormatting
;
51 protected HSSFFontFormatting(CFRuleRecord cfRuleRecord
)
53 this.fontFormatting
= cfRuleRecord
.getFontFormatting();
56 protected FontFormatting
getFontFormattingBlock()
58 return fontFormatting
;
62 * get the type of super or subscript for the font
64 * @return super or subscript option
69 public short getEscapementType()
71 return fontFormatting
.getEscapementType();
75 * @return font color index
77 public short getFontColorIndex()
79 return fontFormatting
.getFontColorIndex();
83 * gets the height of the font in 1/20th point units
85 * @return fontheight (in points/20); or -1 if not modified
87 public int getFontHeight()
89 return fontFormatting
.getFontHeight();
93 * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
94 * 0x190 for normal and 0x2bc for bold
96 * @return bw - a number between 100-1000 for the fonts "boldness"
99 public short getFontWeight()
101 return fontFormatting
.getFontWeight();
106 * @see org.apache.poi.hssf.record.cf.FontFormatting#getRawRecord()
108 protected byte[] getRawRecord()
110 return fontFormatting
.getRawRecord();
114 * get the type of underlining for the font
116 * @return font underlining type
121 * @see #U_SINGLE_ACCOUNTING
122 * @see #U_DOUBLE_ACCOUNTING
124 public short getUnderlineType()
126 return fontFormatting
.getUnderlineType();
130 * get whether the font weight is set to bold or not
132 * @return bold - whether the font is bold or not
134 public boolean isBold()
136 return fontFormatting
.isFontWeightModified() && fontFormatting
.isBold();
140 * @return true if escapement type was modified from default
142 public boolean isEscapementTypeModified()
144 return fontFormatting
.isEscapementTypeModified();
148 * @return true if font cancellation was modified from default
150 public boolean isFontCancellationModified()
152 return fontFormatting
.isFontCancellationModified();
156 * @return true if font outline type was modified from default
158 public boolean isFontOutlineModified()
160 return fontFormatting
.isFontOutlineModified();
164 * @return true if font shadow type was modified from default
166 public boolean isFontShadowModified()
168 return fontFormatting
.isFontShadowModified();
172 * @return true if font style was modified from default
174 public boolean isFontStyleModified()
176 return fontFormatting
.isFontStyleModified();
180 * @return true if font style was set to <i>italic</i>
182 public boolean isItalic()
184 return fontFormatting
.isFontStyleModified() && fontFormatting
.isItalic();
188 * @return true if font outline is on
190 public boolean isOutlineOn()
192 return fontFormatting
.isFontOutlineModified() && fontFormatting
.isOutlineOn();
196 * @return true if font shadow is on
198 public boolean isShadowOn()
200 return fontFormatting
.isFontOutlineModified() && fontFormatting
.isShadowOn();
204 * @return true if font strikeout is on
206 public boolean isStruckout()
208 return fontFormatting
.isFontCancellationModified() && fontFormatting
.isStruckout();
212 * @return true if font underline type was modified from default
214 public boolean isUnderlineTypeModified()
216 return fontFormatting
.isUnderlineTypeModified();
220 * @return true if font weight was modified from default
222 public boolean isFontWeightModified()
224 return fontFormatting
.isFontWeightModified();
228 * set font style options.
230 * @param italic - if true, set posture style to italic, otherwise to normal
231 * @param bold- if true, set font weight to bold, otherwise to normal
234 public void setFontStyle(boolean italic
, boolean bold
)
236 boolean modified
= italic
|| bold
;
237 fontFormatting
.setItalic(italic
);
238 fontFormatting
.setBold(bold
);
239 fontFormatting
.setFontStyleModified(modified
);
240 fontFormatting
.setFontWieghtModified(modified
);
244 * set font style options to default values (non-italic, non-bold)
246 public void resetFontStyle()
248 setFontStyle(false,false);
252 * set the escapement type for the font
254 * @param escapementType super or subscript option
259 public void setEscapementType(short escapementType
)
261 switch(escapementType
)
263 case HSSFFontFormatting
.SS_SUB
:
264 case HSSFFontFormatting
.SS_SUPER
:
265 fontFormatting
.setEscapementType(escapementType
);
266 fontFormatting
.setEscapementTypeModified(true);
268 case HSSFFontFormatting
.SS_NONE
:
269 fontFormatting
.setEscapementType(escapementType
);
270 fontFormatting
.setEscapementTypeModified(false);
278 * @see org.apache.poi.hssf.record.cf.FontFormatting#setEscapementTypeModified(boolean)
280 public void setEscapementTypeModified(boolean modified
)
282 fontFormatting
.setEscapementTypeModified(modified
);
287 * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCancellationModified(boolean)
289 public void setFontCancellationModified(boolean modified
)
291 fontFormatting
.setFontCancellationModified(modified
);
296 * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontColorIndex(short)
298 public void setFontColorIndex(short fci
)
300 fontFormatting
.setFontColorIndex(fci
);
305 * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(short)
307 public void setFontHeight(int height
)
309 fontFormatting
.setFontHeight(height
);
314 * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontOutlineModified(boolean)
316 public void setFontOutlineModified(boolean modified
)
318 fontFormatting
.setFontOutlineModified(modified
);
323 * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontShadowModified(boolean)
325 public void setFontShadowModified(boolean modified
)
327 fontFormatting
.setFontShadowModified(modified
);
332 * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontStyleModified(boolean)
334 public void setFontStyleModified(boolean modified
)
336 fontFormatting
.setFontStyleModified(modified
);
341 * @see org.apache.poi.hssf.record.cf.FontFormatting#setOutline(boolean)
343 public void setOutline(boolean on
)
345 fontFormatting
.setOutline(on
);
346 fontFormatting
.setFontOutlineModified(on
);
351 * @see org.apache.poi.hssf.record.cf.FontFormatting#setShadow(boolean)
353 public void setShadow(boolean on
)
355 fontFormatting
.setShadow(on
);
356 fontFormatting
.setFontShadowModified(on
);
361 * @see org.apache.poi.hssf.record.cf.FontFormatting#setStrikeout(boolean)
363 public void setStrikeout(boolean strike
)
365 fontFormatting
.setStrikeout(strike
);
366 fontFormatting
.setFontCancellationModified(strike
);
370 * set the type of underlining type for the font
372 * @param u super or subscript option
377 * @see #U_SINGLE_ACCOUNTING
378 * @see #U_DOUBLE_ACCOUNTING
380 public void setUnderlineType(short underlineType
)
382 switch(underlineType
)
384 case HSSFFontFormatting
.U_SINGLE
:
385 case HSSFFontFormatting
.U_DOUBLE
:
386 case HSSFFontFormatting
.U_SINGLE_ACCOUNTING
:
387 case HSSFFontFormatting
.U_DOUBLE_ACCOUNTING
:
388 fontFormatting
.setUnderlineType(underlineType
);
389 setUnderlineTypeModified(true);
392 case HSSFFontFormatting
.U_NONE
:
393 fontFormatting
.setUnderlineType(underlineType
);
394 setUnderlineTypeModified(false);
402 * @see org.apache.poi.hssf.record.cf.FontFormatting#setUnderlineTypeModified(boolean)
404 public void setUnderlineTypeModified(boolean modified
)
406 fontFormatting
.setUnderlineTypeModified(modified
);