/**
* Border Formatting Block of the Conditional Formatting Rule Record.
- *
- * @author Dmitriy Kumshayev
*/
public final class BorderFormatting {
-
/** No border */
public final static short BORDER_NONE = 0x0;
/** Thin border */
import org.apache.poi.ss.util.CellRangeAddress;
/**
- *
- * @author Dmitriy Kumshayev
+ * TODO Should this move to org.apache.poi.ss.util ?
*/
-public final class CellRangeUtil
-{
-
- private CellRangeUtil() {
- // no instance of this class
- }
-
- public static final int NO_INTERSECTION = 1;
- public static final int OVERLAP = 2;
- /** first range is within the second range */
- public static final int INSIDE = 3;
- /** first range encloses or is equal to the second */
- public static final int ENCLOSES = 4;
-
- /**
- * Intersect this range with the specified range.
- *
- * @param crB - the specified range
- * @return code which reflects how the specified range is related to this range.<br/>
- * Possible return codes are:
- * NO_INTERSECTION - the specified range is outside of this range;<br/>
- * OVERLAP - both ranges partially overlap;<br/>
- * INSIDE - the specified range is inside of this one<br/>
- * ENCLOSES - the specified range encloses (possibly exactly the same as) this range<br/>
- */
- public static int intersect(CellRangeAddress crA, CellRangeAddress crB )
- {
-
- int firstRow = crB.getFirstRow();
- int lastRow = crB.getLastRow();
- int firstCol = crB.getFirstColumn();
- int lastCol = crB.getLastColumn();
-
- if
- (
+public final class CellRangeUtil {
+ private CellRangeUtil() {
+ // no instance of this class
+ }
+
+ public static final int NO_INTERSECTION = 1;
+ public static final int OVERLAP = 2;
+ /** first range is within the second range */
+ public static final int INSIDE = 3;
+ /** first range encloses or is equal to the second */
+ public static final int ENCLOSES = 4;
+
+ /**
+ * Intersect this range with the specified range.
+ *
+ * @param crB - the specified range
+ * @return code which reflects how the specified range is related to this range.<br/>
+ * Possible return codes are:
+ * NO_INTERSECTION - the specified range is outside of this range;<br/>
+ * OVERLAP - both ranges partially overlap;<br/>
+ * INSIDE - the specified range is inside of this one<br/>
+ * ENCLOSES - the specified range encloses (possibly exactly the same as) this range<br/>
+ */
+ public static int intersect(CellRangeAddress crA, CellRangeAddress crB )
+ {
+
+ int firstRow = crB.getFirstRow();
+ int lastRow = crB.getLastRow();
+ int firstCol = crB.getFirstColumn();
+ int lastCol = crB.getLastColumn();
+
+ if
+ (
gt(crA.getFirstRow(),lastRow) ||
lt(crA.getLastRow(),firstRow) ||
gt(crA.getFirstColumn(),lastCol) ||
lt(crA.getLastColumn(),firstCol)
- )
- {
- return NO_INTERSECTION;
- }
- else if( contains(crA, crB) )
- {
- return INSIDE;
- }
- else if( contains(crB, crA))
- {
- return ENCLOSES;
- }
- else
- {
- return OVERLAP;
- }
-
- }
-
- /**
- * Do all possible cell merges between cells of the list so that:<br>
- * <li>if a cell range is completely inside of another cell range, it gets removed from the list
- * <li>if two cells have a shared border, merge them into one bigger cell range
- * @param cellRanges
- * @return updated List of cell ranges
- */
- public static CellRangeAddress[] mergeCellRanges(CellRangeAddress[] cellRanges) {
- if(cellRanges.length < 1) {
- return cellRanges;
- }
+ )
+ {
+ return NO_INTERSECTION;
+ }
+ else if( contains(crA, crB) )
+ {
+ return INSIDE;
+ }
+ else if( contains(crB, crA))
+ {
+ return ENCLOSES;
+ }
+ else
+ {
+ return OVERLAP;
+ }
+ }
+
+ /**
+ * Do all possible cell merges between cells of the list so that:<br>
+ * <li>if a cell range is completely inside of another cell range, it gets removed from the list
+ * <li>if two cells have a shared border, merge them into one bigger cell range
+ * @param cellRanges
+ * @return updated List of cell ranges
+ */
+ public static CellRangeAddress[] mergeCellRanges(CellRangeAddress[] cellRanges) {
+ if(cellRanges.length < 1) {
+ return cellRanges;
+ }
List<CellRangeAddress> lst = new ArrayList<CellRangeAddress>();
for(CellRangeAddress cr : cellRanges) {
lst.add(cr);
}
List<CellRangeAddress> temp = mergeCellRanges(lst);
- return toArray(temp);
- }
+ return toArray(temp);
+ }
- private static List<CellRangeAddress> mergeCellRanges(List<CellRangeAddress> cellRangeList)
- {
- // loop until either only one item is left or we did not merge anything any more
+ private static List<CellRangeAddress> mergeCellRanges(List<CellRangeAddress> cellRangeList)
+ {
+ // loop until either only one item is left or we did not merge anything any more
while (cellRangeList.size() > 1) {
boolean somethingGotMerged = false;
// look at all cell-ranges
for (int i = 0; i < cellRangeList.size(); i++) {
CellRangeAddress range1 = cellRangeList.get(i);
-
+
// compare each cell range to all other cell-ranges
for (int j = i + 1; j < cellRangeList.size(); j++) {
CellRangeAddress range2 = cellRangeList.get(j);
}
}
- return cellRangeList;
- }
-
- /**
- * @return the new range(s) to replace the supplied ones. <code>null</code> if no merge is possible
- */
- private static CellRangeAddress[] mergeRanges(CellRangeAddress range1, CellRangeAddress range2) {
- int x = intersect(range1, range2);
- switch(x)
- {
+ return cellRangeList;
+ }
+
+ /**
+ * @return the new range(s) to replace the supplied ones. <code>null</code> if no merge is possible
+ */
+ private static CellRangeAddress[] mergeRanges(CellRangeAddress range1, CellRangeAddress range2) {
+ int x = intersect(range1, range2);
+ switch(x)
+ {
case CellRangeUtil.NO_INTERSECTION:
// nothing in common: at most they could be adjacent to each other and thus form a single bigger area
if(hasExactSharedBorder(range1, range2)) {
throw new RuntimeException("unexpected intersection result (" + x + ")");
}
-
- private static CellRangeAddress[] toArray(List<CellRangeAddress> temp) {
- CellRangeAddress[] result = new CellRangeAddress[temp.size()];
- temp.toArray(result);
- return result;
- }
+ private static CellRangeAddress[] toArray(List<CellRangeAddress> temp) {
+ CellRangeAddress[] result = new CellRangeAddress[temp.size()];
+ temp.toArray(result);
+ return result;
+ }
+ /**
+ * Check if the specified range is located inside of this cell range.
+ *
+ * @param crB
+ * @return true if this cell range contains the argument range inside if it's area
+ */
+ public static boolean contains(CellRangeAddress crA, CellRangeAddress crB)
+ {
+ int firstRow = crB.getFirstRow();
+ int lastRow = crB.getLastRow();
+ int firstCol = crB.getFirstColumn();
+ int lastCol = crB.getLastColumn();
+ return le(crA.getFirstRow(), firstRow) && ge(crA.getLastRow(), lastRow)
+ && le(crA.getFirstColumn(), firstCol) && ge(crA.getLastColumn(), lastCol);
+ }
+ /**
+ * Check if the two cell ranges have a shared border.
+ *
+ * @return <code>true</code> if the ranges have a complete shared border (i.e.
+ * the two ranges together make a simple rectangular region.
+ */
+ public static boolean hasExactSharedBorder(CellRangeAddress crA, CellRangeAddress crB) {
+ int oFirstRow = crB.getFirstRow();
+ int oLastRow = crB.getLastRow();
+ int oFirstCol = crB.getFirstColumn();
+ int oLastCol = crB.getLastColumn();
- /**
- * Check if the specified range is located inside of this cell range.
- *
- * @param crB
- * @return true if this cell range contains the argument range inside if it's area
- */
- public static boolean contains(CellRangeAddress crA, CellRangeAddress crB)
- {
- int firstRow = crB.getFirstRow();
- int lastRow = crB.getLastRow();
- int firstCol = crB.getFirstColumn();
- int lastCol = crB.getLastColumn();
- return le(crA.getFirstRow(), firstRow) && ge(crA.getLastRow(), lastRow)
- && le(crA.getFirstColumn(), firstCol) && ge(crA.getLastColumn(), lastCol);
- }
-
- /**
- * Check if the two cell ranges have a shared border.
- *
- * @return <code>true</code> if the ranges have a complete shared border (i.e.
- * the two ranges together make a simple rectangular region.
- */
- public static boolean hasExactSharedBorder(CellRangeAddress crA, CellRangeAddress crB) {
- int oFirstRow = crB.getFirstRow();
- int oLastRow = crB.getLastRow();
- int oFirstCol = crB.getFirstColumn();
- int oLastCol = crB.getLastColumn();
-
- if (crA.getFirstRow() > 0 && crA.getFirstRow()-1 == oLastRow ||
- oFirstRow > 0 && oFirstRow-1 == crA.getLastRow()) {
- // ranges have a horizontal border in common
- // make sure columns are identical:
- return crA.getFirstColumn() == oFirstCol && crA.getLastColumn() == oLastCol;
- }
+ if (crA.getFirstRow() > 0 && crA.getFirstRow()-1 == oLastRow ||
+ oFirstRow > 0 && oFirstRow-1 == crA.getLastRow()) {
+ // ranges have a horizontal border in common
+ // make sure columns are identical:
+ return crA.getFirstColumn() == oFirstCol && crA.getLastColumn() == oLastCol;
+ }
- if (crA.getFirstColumn()>0 && crA.getFirstColumn() - 1 == oLastCol ||
- oFirstCol>0 && crA.getLastColumn() == oFirstCol -1) {
- // ranges have a vertical border in common
- // make sure rows are identical:
- return crA.getFirstRow() == oFirstRow && crA.getLastRow() == oLastRow;
- }
- return false;
- }
-
- /**
- * Create an enclosing CellRange for the two cell ranges.
- *
- * @return enclosing CellRange
- */
- public static CellRangeAddress createEnclosingCellRange(CellRangeAddress crA, CellRangeAddress crB) {
- if( crB == null) {
- return crA.copy();
- }
-
- return
- new CellRangeAddress(
- lt(crB.getFirstRow(), crA.getFirstRow()) ?crB.getFirstRow() :crA.getFirstRow(),
- gt(crB.getLastRow(), crA.getLastRow()) ?crB.getLastRow() :crA.getLastRow(),
- lt(crB.getFirstColumn(),crA.getFirstColumn())?crB.getFirstColumn():crA.getFirstColumn(),
- gt(crB.getLastColumn(), crA.getLastColumn()) ?crB.getLastColumn() :crA.getLastColumn()
- );
-
- }
-
- /**
- * @return true if a < b
- */
- private static boolean lt(int a, int b)
- {
- return a == -1 ? false : (b == -1 ? true : a < b);
- }
-
- /**
- * @return true if a <= b
- */
- private static boolean le(int a, int b)
- {
- return a == b || lt(a,b);
- }
-
- /**
- * @return true if a > b
- */
- private static boolean gt(int a, int b)
- {
- return lt(b,a);
- }
+ if (crA.getFirstColumn()>0 && crA.getFirstColumn() - 1 == oLastCol ||
+ oFirstCol>0 && crA.getLastColumn() == oFirstCol -1) {
+ // ranges have a vertical border in common
+ // make sure rows are identical:
+ return crA.getFirstRow() == oFirstRow && crA.getLastRow() == oLastRow;
+ }
+ return false;
+ }
- /**
- * @return true if a >= b
- */
- private static boolean ge(int a, int b)
- {
- return !lt(a,b);
- }
+ /**
+ * Create an enclosing CellRange for the two cell ranges.
+ *
+ * @return enclosing CellRange
+ */
+ public static CellRangeAddress createEnclosingCellRange(CellRangeAddress crA, CellRangeAddress crB) {
+ if( crB == null) {
+ return crA.copy();
+ }
+
+ return new CellRangeAddress(
+ lt(crB.getFirstRow(), crA.getFirstRow()) ?crB.getFirstRow() :crA.getFirstRow(),
+ gt(crB.getLastRow(), crA.getLastRow()) ?crB.getLastRow() :crA.getLastRow(),
+ lt(crB.getFirstColumn(),crA.getFirstColumn())?crB.getFirstColumn():crA.getFirstColumn(),
+ gt(crB.getLastColumn(), crA.getLastColumn()) ?crB.getLastColumn() :crA.getLastColumn()
+ );
+ }
+
+ /**
+ * @return true if a < b
+ */
+ private static boolean lt(int a, int b)
+ {
+ return a == -1 ? false : (b == -1 ? true : a < b);
+ }
+
+ /**
+ * @return true if a <= b
+ */
+ private static boolean le(int a, int b)
+ {
+ return a == b || lt(a,b);
+ }
+
+ /**
+ * @return true if a > b
+ */
+ private static boolean gt(int a, int b)
+ {
+ return lt(b,a);
+ }
+
+ /**
+ * @return true if a >= b
+ */
+ private static boolean ge(int a, int b)
+ {
+ return !lt(a,b);
+ }
}
/**
* Font Formatting Block of the Conditional Formatting Rule Record.
- *
- * @author Dmitriy Kumshayev
*/
-public final class FontFormatting
-{
- private byte[] _rawData;
-
- private static final int OFFSET_FONT_NAME = 0;
- private static final int OFFSET_FONT_HEIGHT = 64;
- private static final int OFFSET_FONT_OPTIONS = 68;
- private static final int OFFSET_FONT_WEIGHT = 72;
- private static final int OFFSET_ESCAPEMENT_TYPE = 74;
- private static final int OFFSET_UNDERLINE_TYPE = 76;
- private static final int OFFSET_FONT_COLOR_INDEX = 80;
- private static final int OFFSET_OPTION_FLAGS = 88;
- private static final int OFFSET_ESCAPEMENT_TYPE_MODIFIED = 92;
- private static final int OFFSET_UNDERLINE_TYPE_MODIFIED = 96;
- private static final int OFFSET_FONT_WEIGHT_MODIFIED = 100;
- private static final int OFFSET_NOT_USED1 = 104;
- private static final int OFFSET_NOT_USED2 = 108;
- private static final int OFFSET_NOT_USED3 = 112; // for some reason Excel always writes 0x7FFFFFFF at this offset
- private static final int OFFSET_FONT_FORMATING_END = 116;
- private static final int RAW_DATA_SIZE = 118;
-
-
- public final static int FONT_CELL_HEIGHT_PRESERVED = 0xFFFFFFFF;
-
- // FONT OPTIONS MASKS
- private static final BitField posture = BitFieldFactory.getInstance(0x00000002);
- private static final BitField outline = BitFieldFactory.getInstance(0x00000008);
- private static final BitField shadow = BitFieldFactory.getInstance(0x00000010);
- private static final BitField cancellation = BitFieldFactory.getInstance(0x00000080);
-
- // OPTION FLAGS MASKS
-
- private static final BitField styleModified = BitFieldFactory.getInstance(0x00000002);
- private static final BitField outlineModified = BitFieldFactory.getInstance(0x00000008);
- private static final BitField shadowModified = BitFieldFactory.getInstance(0x00000010);
- private static final BitField cancellationModified = BitFieldFactory.getInstance(0x00000080);
-
- /** Escapement type - None */
- public static final short SS_NONE = 0;
- /** Escapement type - Superscript */
- public static final short SS_SUPER = 1;
- /** Escapement type - Subscript */
- public static final short SS_SUB = 2;
- /** Underline type - None */
- public static final byte U_NONE = 0;
- /** Underline type - Single */
- public static final byte U_SINGLE = 1;
- /** Underline type - Double */
- public static final byte U_DOUBLE = 2;
- /** Underline type - Single Accounting */
- public static final byte U_SINGLE_ACCOUNTING = 0x21;
- /** Underline type - Double Accounting */
- public static final byte U_DOUBLE_ACCOUNTING = 0x22;
- /** Normal boldness (not bold) */
- private static final short FONT_WEIGHT_NORMAL = 0x190;
-
- /**
- * Bold boldness (bold)
- */
- private static final short FONT_WEIGHT_BOLD = 0x2bc;
-
- private FontFormatting(byte[] rawData) {
- _rawData = rawData;
- }
-
- public FontFormatting()
- {
- this(new byte[RAW_DATA_SIZE]);
-
- setFontHeight(-1);
- setItalic(false);
- setFontWieghtModified(false);
- setOutline(false);
- setShadow(false);
- setStrikeout(false);
- setEscapementType((short)0);
- setUnderlineType((byte)0);
- setFontColorIndex((short)-1);
-
- setFontStyleModified(false);
- setFontOutlineModified(false);
- setFontShadowModified(false);
- setFontCancellationModified(false);
-
- setEscapementTypeModified(false);
- setUnderlineTypeModified(false);
-
- setShort(OFFSET_FONT_NAME, 0);
- setInt(OFFSET_NOT_USED1, 0x00000001);
- setInt(OFFSET_NOT_USED2, 0x00000000);
- setInt(OFFSET_NOT_USED3, 0x7FFFFFFF);// for some reason Excel always writes 0x7FFFFFFF at this offset
- setShort(OFFSET_FONT_FORMATING_END, 0x0001);
- }
-
- /** Creates new FontFormatting */
- public FontFormatting(RecordInputStream in)
- {
- this(new byte[RAW_DATA_SIZE]);
- for (int i = 0; i < _rawData.length; i++)
- {
- _rawData[i] = in.readByte();
- }
- }
-
- private short getShort(int offset) {
- return LittleEndian.getShort( _rawData, offset);
- }
- private void setShort(int offset, int value) {
- LittleEndian.putShort( _rawData, offset, (short)value);
- }
- private int getInt(int offset) {
- return LittleEndian.getInt( _rawData, offset);
- }
- private void setInt(int offset, int value) {
- LittleEndian.putInt( _rawData, offset, value);
- }
-
- public byte[] getRawRecord()
- {
- return _rawData;
- }
-
- public int getDataLength() {
- return RAW_DATA_SIZE;
- }
-
- /**
- * sets the height of the font in 1/20th point units
- *
- *
- * @param height fontheight (in points/20); or -1 to preserve the cell font height
- */
-
- public void setFontHeight(int height)
- {
- setInt(OFFSET_FONT_HEIGHT, height);
- }
-
- /**
- * gets the height of the font in 1/20th point units
- *
- * @return fontheight (in points/20); or -1 if not modified
- */
- public int getFontHeight()
- {
- return getInt(OFFSET_FONT_HEIGHT);
- }
-
- private void setFontOption(boolean option, BitField field)
- {
- int options = getInt(OFFSET_FONT_OPTIONS);
- options = field.setBoolean(options, option);
- setInt(OFFSET_FONT_OPTIONS, options);
- }
-
- private boolean getFontOption(BitField field)
- {
- int options = getInt(OFFSET_FONT_OPTIONS);
- return field.isSet(options);
- }
-
- /**
- * set the font to be italics or not
- *
- * @param italic - whether the font is italics or not
- * @see #setFontOption(boolean, org.apache.poi.util.BitField)
- */
-
- public void setItalic(boolean italic)
- {
- setFontOption(italic, posture);
- }
-
- /**
- * get whether the font is to be italics or not
- *
- * @return italics - whether the font is italics or not
- * @see #getFontOption(org.apache.poi.util.BitField)
- */
-
- public boolean isItalic()
- {
- return getFontOption(posture);
- }
-
- public void setOutline(boolean on)
- {
- setFontOption(on, outline);
- }
-
- public boolean isOutlineOn()
- {
- return getFontOption(outline);
- }
-
- public void setShadow(boolean on)
- {
- setFontOption(on, shadow);
- }
-
- public boolean isShadowOn()
- {
- return getFontOption(shadow);
- }
-
- /**
- * set the font to be stricken out or not
- *
- * @param strike - whether the font is stricken out or not
- */
-
- public void setStrikeout(boolean strike)
- {
- setFontOption(strike, cancellation);
- }
-
- /**
- * get whether the font is to be stricken out or not
- *
- * @return strike - whether the font is stricken out or not
- * @see #getFontOption(org.apache.poi.util.BitField)
- */
-
- public boolean isStruckout()
- {
- return getFontOption(cancellation);
- }
-
- /**
- * set the font weight (100-1000dec or 0x64-0x3e8). Default is
- * 0x190 for normal and 0x2bc for bold
- *
- * @param bw - a number between 100-1000 for the fonts "boldness"
- */
-
- private void setFontWeight(short pbw)
- {
- short bw = pbw;
- if( bw<100) { bw=100; }
- if( bw>1000){ bw=1000; }
- setShort(OFFSET_FONT_WEIGHT, bw);
- }
-
- /**
- * set the font weight to bold (weight=700) or to normal(weight=400) boldness.
- *
- * @param bold - set font weight to bold if true; to normal otherwise
- */
- public void setBold(boolean bold)
- {
- setFontWeight(bold?FONT_WEIGHT_BOLD:FONT_WEIGHT_NORMAL);
- }
-
- /**
- * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
- * 0x190 for normal and 0x2bc for bold
- *
- * @return bw - a number between 100-1000 for the fonts "boldness"
- */
-
- public short getFontWeight()
- {
- return getShort(OFFSET_FONT_WEIGHT);
- }
-
- /**
- * get whether the font weight is set to bold or not
- *
- * @return bold - whether the font is bold or not
- */
-
- public boolean isBold()
- {
- return getFontWeight()==FONT_WEIGHT_BOLD;
- }
-
- /**
- * get the type of super or subscript for the font
- *
- * @return super or subscript option
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUPER
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUB
- */
- public short getEscapementType()
- {
- return getShort(OFFSET_ESCAPEMENT_TYPE);
- }
-
- /**
- * set the escapement type for the font
- *
- * @param escapementType super or subscript option
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUPER
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUB
- */
- public void setEscapementType( short escapementType)
- {
- setShort(OFFSET_ESCAPEMENT_TYPE, escapementType);
- }
-
- /**
- * get the type of underlining for the font
- *
- * @return font underlining type
- *
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE_ACCOUNTING
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE_ACCOUNTING
- */
-
- public short getUnderlineType()
- {
- return getShort(OFFSET_UNDERLINE_TYPE);
- }
-
- /**
- * set the type of underlining type for the font
- *
- * @param underlineType underline option
- *
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE_ACCOUNTING
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE_ACCOUNTING
- */
- public void setUnderlineType( short underlineType)
- {
- setShort(OFFSET_UNDERLINE_TYPE, underlineType);
- }
-
-
- public short getFontColorIndex()
- {
- return (short)getInt(OFFSET_FONT_COLOR_INDEX);
- }
-
- public void setFontColorIndex(short fci )
- {
- setInt(OFFSET_FONT_COLOR_INDEX,fci);
- }
-
- private boolean getOptionFlag(BitField field)
- {
- int optionFlags = getInt(OFFSET_OPTION_FLAGS);
- int value = field.getValue(optionFlags);
- return value==0? true : false ;
- }
-
- private void setOptionFlag(boolean modified, BitField field)
- {
- int value = modified? 0 : 1;
- int optionFlags = getInt(OFFSET_OPTION_FLAGS);
- optionFlags = field.setValue(optionFlags, value);
- setInt(OFFSET_OPTION_FLAGS, optionFlags);
- }
-
-
- public boolean isFontStyleModified()
- {
- return getOptionFlag(styleModified);
- }
-
-
- public void setFontStyleModified(boolean modified)
- {
- setOptionFlag(modified, styleModified);
- }
-
- public boolean isFontOutlineModified()
- {
- return getOptionFlag(outlineModified);
- }
-
- public void setFontOutlineModified(boolean modified)
- {
- setOptionFlag(modified, outlineModified);
- }
-
- public boolean isFontShadowModified()
- {
- return getOptionFlag(shadowModified);
- }
-
- public void setFontShadowModified(boolean modified)
- {
- setOptionFlag(modified, shadowModified);
- }
- public void setFontCancellationModified(boolean modified)
- {
- setOptionFlag(modified, cancellationModified);
- }
-
- public boolean isFontCancellationModified()
- {
- return getOptionFlag(cancellationModified);
- }
-
- public void setEscapementTypeModified(boolean modified)
- {
- int value = modified? 0 : 1;
- setInt(OFFSET_ESCAPEMENT_TYPE_MODIFIED, value);
- }
- public boolean isEscapementTypeModified()
- {
- int escapementModified = getInt(OFFSET_ESCAPEMENT_TYPE_MODIFIED);
- return escapementModified == 0;
- }
-
- public void setUnderlineTypeModified(boolean modified)
- {
- int value = modified? 0 : 1;
- setInt(OFFSET_UNDERLINE_TYPE_MODIFIED, value);
- }
-
- public boolean isUnderlineTypeModified()
- {
- int underlineModified = getInt(OFFSET_UNDERLINE_TYPE_MODIFIED);
- return underlineModified == 0;
- }
-
- public void setFontWieghtModified(boolean modified)
- {
- int value = modified? 0 : 1;
- setInt(OFFSET_FONT_WEIGHT_MODIFIED, value);
- }
-
- public boolean isFontWeightModified()
- {
- int fontStyleModified = getInt(OFFSET_FONT_WEIGHT_MODIFIED);
- return fontStyleModified == 0;
- }
-
- public String toString()
- {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" [Font Formatting]\n");
-
- buffer.append(" .font height = ").append(getFontHeight()).append(" twips\n");
-
- if( isFontStyleModified() )
- {
- buffer.append(" .font posture = ").append(isItalic()?"Italic":"Normal").append("\n");
- }
- else
- {
- buffer.append(" .font posture = ]not modified]").append("\n");
- }
-
- if( isFontOutlineModified() )
- {
- buffer.append(" .font outline = ").append(isOutlineOn()).append("\n");
- }
- else
- {
- buffer.append(" .font outline is not modified\n");
- }
-
- if( isFontShadowModified() )
- {
- buffer.append(" .font shadow = ").append(isShadowOn()).append("\n");
- }
- else
- {
- buffer.append(" .font shadow is not modified\n");
- }
-
- if( isFontCancellationModified() )
- {
- buffer.append(" .font strikeout = ").append(isStruckout()).append("\n");
- }
- else
- {
- buffer.append(" .font strikeout is not modified\n");
- }
-
- if( isFontStyleModified() )
- {
- buffer.append(" .font weight = ").
- append(getFontWeight()).
- append(
- getFontWeight() == FONT_WEIGHT_NORMAL ? "(Normal)"
- : getFontWeight() == FONT_WEIGHT_BOLD ? "(Bold)" : "0x"+Integer.toHexString(getFontWeight())).
- append("\n");
- }
- else
- {
- buffer.append(" .font weight = ]not modified]").append("\n");
- }
-
- if( isEscapementTypeModified() )
- {
- buffer.append(" .escapement type = ").append(getEscapementType()).append("\n");
- }
- else
- {
- buffer.append(" .escapement type is not modified\n");
- }
-
- if( isUnderlineTypeModified() )
- {
- buffer.append(" .underline type = ").append(getUnderlineType()).append("\n");
- }
- else
- {
- buffer.append(" .underline type is not modified\n");
- }
- buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase()).append("\n");
-
- buffer.append(" [/Font Formatting]\n");
- return buffer.toString();
- }
-
- public Object clone()
- {
- byte[] rawData = _rawData.clone();
- return new FontFormatting(rawData);
- }
+public final class FontFormatting {
+ private byte[] _rawData;
+
+ private static final int OFFSET_FONT_NAME = 0;
+ private static final int OFFSET_FONT_HEIGHT = 64;
+ private static final int OFFSET_FONT_OPTIONS = 68;
+ private static final int OFFSET_FONT_WEIGHT = 72;
+ private static final int OFFSET_ESCAPEMENT_TYPE = 74;
+ private static final int OFFSET_UNDERLINE_TYPE = 76;
+ private static final int OFFSET_FONT_COLOR_INDEX = 80;
+ private static final int OFFSET_OPTION_FLAGS = 88;
+ private static final int OFFSET_ESCAPEMENT_TYPE_MODIFIED = 92;
+ private static final int OFFSET_UNDERLINE_TYPE_MODIFIED = 96;
+ private static final int OFFSET_FONT_WEIGHT_MODIFIED = 100;
+ private static final int OFFSET_NOT_USED1 = 104;
+ private static final int OFFSET_NOT_USED2 = 108;
+ private static final int OFFSET_NOT_USED3 = 112; // for some reason Excel always writes 0x7FFFFFFF at this offset
+ private static final int OFFSET_FONT_FORMATING_END = 116;
+ private static final int RAW_DATA_SIZE = 118;
+
+
+ public final static int FONT_CELL_HEIGHT_PRESERVED = 0xFFFFFFFF;
+
+ // FONT OPTIONS MASKS
+ private static final BitField posture = BitFieldFactory.getInstance(0x00000002);
+ private static final BitField outline = BitFieldFactory.getInstance(0x00000008);
+ private static final BitField shadow = BitFieldFactory.getInstance(0x00000010);
+ private static final BitField cancellation = BitFieldFactory.getInstance(0x00000080);
+
+ // OPTION FLAGS MASKS
+
+ private static final BitField styleModified = BitFieldFactory.getInstance(0x00000002);
+ private static final BitField outlineModified = BitFieldFactory.getInstance(0x00000008);
+ private static final BitField shadowModified = BitFieldFactory.getInstance(0x00000010);
+ private static final BitField cancellationModified = BitFieldFactory.getInstance(0x00000080);
+
+ /** Escapement type - None */
+ public static final short SS_NONE = 0;
+ /** Escapement type - Superscript */
+ public static final short SS_SUPER = 1;
+ /** Escapement type - Subscript */
+ public static final short SS_SUB = 2;
+ /** Underline type - None */
+ public static final byte U_NONE = 0;
+ /** Underline type - Single */
+ public static final byte U_SINGLE = 1;
+ /** Underline type - Double */
+ public static final byte U_DOUBLE = 2;
+ /** Underline type - Single Accounting */
+ public static final byte U_SINGLE_ACCOUNTING = 0x21;
+ /** Underline type - Double Accounting */
+ public static final byte U_DOUBLE_ACCOUNTING = 0x22;
+ /** Normal boldness (not bold) */
+ private static final short FONT_WEIGHT_NORMAL = 0x190;
+
+ /**
+ * Bold boldness (bold)
+ */
+ private static final short FONT_WEIGHT_BOLD = 0x2bc;
+
+ private FontFormatting(byte[] rawData) {
+ _rawData = rawData;
+ }
+
+ public FontFormatting()
+ {
+ this(new byte[RAW_DATA_SIZE]);
+
+ setFontHeight(-1);
+ setItalic(false);
+ setFontWieghtModified(false);
+ setOutline(false);
+ setShadow(false);
+ setStrikeout(false);
+ setEscapementType((short)0);
+ setUnderlineType((byte)0);
+ setFontColorIndex((short)-1);
+
+ setFontStyleModified(false);
+ setFontOutlineModified(false);
+ setFontShadowModified(false);
+ setFontCancellationModified(false);
+
+ setEscapementTypeModified(false);
+ setUnderlineTypeModified(false);
+
+ setShort(OFFSET_FONT_NAME, 0);
+ setInt(OFFSET_NOT_USED1, 0x00000001);
+ setInt(OFFSET_NOT_USED2, 0x00000000);
+ setInt(OFFSET_NOT_USED3, 0x7FFFFFFF);// for some reason Excel always writes 0x7FFFFFFF at this offset
+ setShort(OFFSET_FONT_FORMATING_END, 0x0001);
+ }
+
+ /** Creates new FontFormatting */
+ public FontFormatting(RecordInputStream in)
+ {
+ this(new byte[RAW_DATA_SIZE]);
+ for (int i = 0; i < _rawData.length; i++)
+ {
+ _rawData[i] = in.readByte();
+ }
+ }
+
+ private short getShort(int offset) {
+ return LittleEndian.getShort( _rawData, offset);
+ }
+ private void setShort(int offset, int value) {
+ LittleEndian.putShort( _rawData, offset, (short)value);
+ }
+ private int getInt(int offset) {
+ return LittleEndian.getInt( _rawData, offset);
+ }
+ private void setInt(int offset, int value) {
+ LittleEndian.putInt( _rawData, offset, value);
+ }
+
+ public byte[] getRawRecord()
+ {
+ return _rawData;
+ }
+
+ public int getDataLength() {
+ return RAW_DATA_SIZE;
+ }
+
+ /**
+ * sets the height of the font in 1/20th point units
+ *
+ *
+ * @param height fontheight (in points/20); or -1 to preserve the cell font height
+ */
+
+ public void setFontHeight(int height)
+ {
+ setInt(OFFSET_FONT_HEIGHT, height);
+ }
+
+ /**
+ * gets the height of the font in 1/20th point units
+ *
+ * @return fontheight (in points/20); or -1 if not modified
+ */
+ public int getFontHeight()
+ {
+ return getInt(OFFSET_FONT_HEIGHT);
+ }
+
+ private void setFontOption(boolean option, BitField field)
+ {
+ int options = getInt(OFFSET_FONT_OPTIONS);
+ options = field.setBoolean(options, option);
+ setInt(OFFSET_FONT_OPTIONS, options);
+ }
+
+ private boolean getFontOption(BitField field)
+ {
+ int options = getInt(OFFSET_FONT_OPTIONS);
+ return field.isSet(options);
+ }
+
+ /**
+ * set the font to be italics or not
+ *
+ * @param italic - whether the font is italics or not
+ * @see #setFontOption(boolean, org.apache.poi.util.BitField)
+ */
+
+ public void setItalic(boolean italic)
+ {
+ setFontOption(italic, posture);
+ }
+
+ /**
+ * get whether the font is to be italics or not
+ *
+ * @return italics - whether the font is italics or not
+ * @see #getFontOption(org.apache.poi.util.BitField)
+ */
+
+ public boolean isItalic()
+ {
+ return getFontOption(posture);
+ }
+
+ public void setOutline(boolean on)
+ {
+ setFontOption(on, outline);
+ }
+
+ public boolean isOutlineOn()
+ {
+ return getFontOption(outline);
+ }
+
+ public void setShadow(boolean on)
+ {
+ setFontOption(on, shadow);
+ }
+
+ public boolean isShadowOn()
+ {
+ return getFontOption(shadow);
+ }
+
+ /**
+ * set the font to be stricken out or not
+ *
+ * @param strike - whether the font is stricken out or not
+ */
+ public void setStrikeout(boolean strike)
+ {
+ setFontOption(strike, cancellation);
+ }
+
+ /**
+ * get whether the font is to be stricken out or not
+ *
+ * @return strike - whether the font is stricken out or not
+ * @see #getFontOption(org.apache.poi.util.BitField)
+ */
+ public boolean isStruckout()
+ {
+ return getFontOption(cancellation);
+ }
+
+ /**
+ * set the font weight (100-1000dec or 0x64-0x3e8). Default is
+ * 0x190 for normal and 0x2bc for bold
+ *
+ * @param bw - a number between 100-1000 for the fonts "boldness"
+ */
+
+ private void setFontWeight(short pbw)
+ {
+ short bw = pbw;
+ if( bw<100) { bw=100; }
+ if( bw>1000){ bw=1000; }
+ setShort(OFFSET_FONT_WEIGHT, bw);
+ }
+
+ /**
+ * set the font weight to bold (weight=700) or to normal(weight=400) boldness.
+ *
+ * @param bold - set font weight to bold if true; to normal otherwise
+ */
+ public void setBold(boolean bold)
+ {
+ setFontWeight(bold?FONT_WEIGHT_BOLD:FONT_WEIGHT_NORMAL);
+ }
+
+ /**
+ * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
+ * 0x190 for normal and 0x2bc for bold
+ *
+ * @return bw - a number between 100-1000 for the fonts "boldness"
+ */
+
+ public short getFontWeight()
+ {
+ return getShort(OFFSET_FONT_WEIGHT);
+ }
+
+ /**
+ * get whether the font weight is set to bold or not
+ *
+ * @return bold - whether the font is bold or not
+ */
+
+ public boolean isBold()
+ {
+ return getFontWeight()==FONT_WEIGHT_BOLD;
+ }
+
+ /**
+ * get the type of super or subscript for the font
+ *
+ * @return super or subscript option
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_NONE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUPER
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUB
+ */
+ public short getEscapementType()
+ {
+ return getShort(OFFSET_ESCAPEMENT_TYPE);
+ }
+
+ /**
+ * set the escapement type for the font
+ *
+ * @param escapementType super or subscript option
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_NONE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUPER
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUB
+ */
+ public void setEscapementType( short escapementType)
+ {
+ setShort(OFFSET_ESCAPEMENT_TYPE, escapementType);
+ }
+
+ /**
+ * get the type of underlining for the font
+ *
+ * @return font underlining type
+ *
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_NONE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE_ACCOUNTING
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE_ACCOUNTING
+ */
+ public short getUnderlineType()
+ {
+ return getShort(OFFSET_UNDERLINE_TYPE);
+ }
+
+ /**
+ * set the type of underlining type for the font
+ *
+ * @param underlineType underline option
+ *
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_NONE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE_ACCOUNTING
+ * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE_ACCOUNTING
+ */
+ public void setUnderlineType( short underlineType)
+ {
+ setShort(OFFSET_UNDERLINE_TYPE, underlineType);
+ }
+
+
+ public short getFontColorIndex()
+ {
+ return (short)getInt(OFFSET_FONT_COLOR_INDEX);
+ }
+
+ public void setFontColorIndex(short fci )
+ {
+ setInt(OFFSET_FONT_COLOR_INDEX,fci);
+ }
+
+ private boolean getOptionFlag(BitField field)
+ {
+ int optionFlags = getInt(OFFSET_OPTION_FLAGS);
+ int value = field.getValue(optionFlags);
+ return value==0? true : false ;
+ }
+
+ private void setOptionFlag(boolean modified, BitField field)
+ {
+ int value = modified? 0 : 1;
+ int optionFlags = getInt(OFFSET_OPTION_FLAGS);
+ optionFlags = field.setValue(optionFlags, value);
+ setInt(OFFSET_OPTION_FLAGS, optionFlags);
+ }
+
+
+ public boolean isFontStyleModified()
+ {
+ return getOptionFlag(styleModified);
+ }
+
+
+ public void setFontStyleModified(boolean modified)
+ {
+ setOptionFlag(modified, styleModified);
+ }
+
+ public boolean isFontOutlineModified()
+ {
+ return getOptionFlag(outlineModified);
+ }
+
+ public void setFontOutlineModified(boolean modified)
+ {
+ setOptionFlag(modified, outlineModified);
+ }
+
+ public boolean isFontShadowModified()
+ {
+ return getOptionFlag(shadowModified);
+ }
+
+ public void setFontShadowModified(boolean modified)
+ {
+ setOptionFlag(modified, shadowModified);
+ }
+ public void setFontCancellationModified(boolean modified)
+ {
+ setOptionFlag(modified, cancellationModified);
+ }
+
+ public boolean isFontCancellationModified()
+ {
+ return getOptionFlag(cancellationModified);
+ }
+
+ public void setEscapementTypeModified(boolean modified)
+ {
+ int value = modified? 0 : 1;
+ setInt(OFFSET_ESCAPEMENT_TYPE_MODIFIED, value);
+ }
+ public boolean isEscapementTypeModified()
+ {
+ int escapementModified = getInt(OFFSET_ESCAPEMENT_TYPE_MODIFIED);
+ return escapementModified == 0;
+ }
+
+ public void setUnderlineTypeModified(boolean modified)
+ {
+ int value = modified? 0 : 1;
+ setInt(OFFSET_UNDERLINE_TYPE_MODIFIED, value);
+ }
+
+ public boolean isUnderlineTypeModified()
+ {
+ int underlineModified = getInt(OFFSET_UNDERLINE_TYPE_MODIFIED);
+ return underlineModified == 0;
+ }
+
+ public void setFontWieghtModified(boolean modified)
+ {
+ int value = modified? 0 : 1;
+ setInt(OFFSET_FONT_WEIGHT_MODIFIED, value);
+ }
+
+ public boolean isFontWeightModified()
+ {
+ int fontStyleModified = getInt(OFFSET_FONT_WEIGHT_MODIFIED);
+ return fontStyleModified == 0;
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(" [Font Formatting]\n");
+
+ buffer.append(" .font height = ").append(getFontHeight()).append(" twips\n");
+
+ if( isFontStyleModified() )
+ {
+ buffer.append(" .font posture = ").append(isItalic()?"Italic":"Normal").append("\n");
+ }
+ else
+ {
+ buffer.append(" .font posture = ]not modified]").append("\n");
+ }
+
+ if( isFontOutlineModified() )
+ {
+ buffer.append(" .font outline = ").append(isOutlineOn()).append("\n");
+ }
+ else
+ {
+ buffer.append(" .font outline is not modified\n");
+ }
+
+ if( isFontShadowModified() )
+ {
+ buffer.append(" .font shadow = ").append(isShadowOn()).append("\n");
+ }
+ else
+ {
+ buffer.append(" .font shadow is not modified\n");
+ }
+
+ if( isFontCancellationModified() )
+ {
+ buffer.append(" .font strikeout = ").append(isStruckout()).append("\n");
+ }
+ else
+ {
+ buffer.append(" .font strikeout is not modified\n");
+ }
+
+ if( isFontStyleModified() )
+ {
+ buffer.append(" .font weight = ").
+ append(getFontWeight()).
+ append(
+ getFontWeight() == FONT_WEIGHT_NORMAL ? "(Normal)"
+ : getFontWeight() == FONT_WEIGHT_BOLD ? "(Bold)"
+ : "0x"+Integer.toHexString(getFontWeight())).
+ append("\n");
+ }
+ else
+ {
+ buffer.append(" .font weight = ]not modified]").append("\n");
+ }
+
+ if( isEscapementTypeModified() )
+ {
+ buffer.append(" .escapement type = ").append(getEscapementType()).append("\n");
+ }
+ else
+ {
+ buffer.append(" .escapement type is not modified\n");
+ }
+
+ if( isUnderlineTypeModified() )
+ {
+ buffer.append(" .underline type = ").append(getUnderlineType()).append("\n");
+ }
+ else
+ {
+ buffer.append(" .underline type is not modified\n");
+ }
+ buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase()).append("\n");
+
+ buffer.append(" [/Font Formatting]\n");
+ return buffer.toString();
+ }
+
+ public Object clone()
+ {
+ byte[] rawData = _rawData.clone();
+ return new FontFormatting(rawData);
+ }
}
/**
* Pattern Formatting Block of the Conditional Formatting Rule Record.
- *
- * @author Dmitriy Kumshayev
*/
public final class PatternFormatting implements Cloneable {
/** No background */
* High level representation for Font Formatting component
* of Conditional Formatting settings
*/
-public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.FontFormatting
-{
- /** Underline type - None */
- public final static byte U_NONE = FontFormatting.U_NONE;
- /** Underline type - Single */
- public final static byte U_SINGLE = FontFormatting.U_SINGLE;
- /** Underline type - Double */
- public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
- /** Underline type - Single Accounting */
- public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
- /** Underline type - Double Accounting */
- public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
-
- private final FontFormatting fontFormatting;
- private final HSSFWorkbook workbook;
-
- protected HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook)
- {
- this.fontFormatting = cfRuleRecord.getFontFormatting();
- this.workbook = workbook;
- }
-
- protected FontFormatting getFontFormattingBlock()
- {
- return fontFormatting;
- }
-
- /**
- * get the type of super or subscript for the font
- *
- * @return super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
- */
- public short getEscapementType()
- {
- return fontFormatting.getEscapementType();
- }
-
- /**
- * @return font color index
- */
- public short getFontColorIndex()
- {
- return fontFormatting.getFontColorIndex();
- }
-
- public HSSFColor getFontColor() {
- return workbook.getCustomPalette().getColor(
- getFontColorIndex()
+public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.FontFormatting {
+ /** Underline type - None */
+ public final static byte U_NONE = FontFormatting.U_NONE;
+ /** Underline type - Single */
+ public final static byte U_SINGLE = FontFormatting.U_SINGLE;
+ /** Underline type - Double */
+ public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
+ /** Underline type - Single Accounting */
+ public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
+ /** Underline type - Double Accounting */
+ public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
+
+ private final FontFormatting fontFormatting;
+ private final HSSFWorkbook workbook;
+
+ protected HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) {
+ this.fontFormatting = cfRuleRecord.getFontFormatting();
+ this.workbook = workbook;
+ }
+
+ protected FontFormatting getFontFormattingBlock() {
+ return fontFormatting;
+ }
+
+ /**
+ * get the type of super or subscript for the font
+ *
+ * @return super or subscript option
+ * @see #SS_NONE
+ * @see #SS_SUPER
+ * @see #SS_SUB
+ */
+ public short getEscapementType()
+ {
+ return fontFormatting.getEscapementType();
+ }
+
+ /**
+ * @return font color index
+ */
+ public short getFontColorIndex()
+ {
+ return fontFormatting.getFontColorIndex();
+ }
+
+ public HSSFColor getFontColor() {
+ return workbook.getCustomPalette().getColor(
+ getFontColorIndex()
);
}
if (color != null && !(color instanceof HSSFColor)) {
throw new IllegalArgumentException("Only HSSFColor objects are supported");
}
-
+
HSSFColor hcolor = (HSSFColor)color;
if (hcolor == null) {
fontFormatting.setFontColorIndex((short)0);
}
/**
- * gets the height of the font in 1/20th point units
- *
- * @return fontheight (in points/20); or -1 if not modified
- */
- public int getFontHeight()
- {
- return fontFormatting.getFontHeight();
- }
-
- /**
- * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
- * 0x190 for normal and 0x2bc for bold
- *
- * @return bw - a number between 100-1000 for the fonts "boldness"
- */
-
- public short getFontWeight()
- {
- return fontFormatting.getFontWeight();
- }
-
- /**
- * @see org.apache.poi.hssf.record.cf.FontFormatting#getRawRecord()
- */
- protected byte[] getRawRecord()
- {
- return fontFormatting.getRawRecord();
- }
-
- /**
- * get the type of underlining for the font
- *
- * @return font underlining type
- *
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
- */
- public short getUnderlineType()
- {
- return fontFormatting.getUnderlineType();
- }
-
- /**
- * get whether the font weight is set to bold or not
- *
- * @return bold - whether the font is bold or not
- */
- public boolean isBold()
- {
- return fontFormatting.isFontWeightModified() && fontFormatting.isBold();
- }
-
- /**
- * @return true if escapement type was modified from default
- */
- public boolean isEscapementTypeModified()
- {
- return fontFormatting.isEscapementTypeModified();
- }
-
- /**
- * @return true if font cancellation was modified from default
- */
- public boolean isFontCancellationModified()
- {
- return fontFormatting.isFontCancellationModified();
- }
-
- /**
- * @return true if font outline type was modified from default
- */
- public boolean isFontOutlineModified()
- {
- return fontFormatting.isFontOutlineModified();
- }
-
- /**
- * @return true if font shadow type was modified from default
- */
- public boolean isFontShadowModified()
- {
- return fontFormatting.isFontShadowModified();
- }
-
- /**
- * @return true if font style was modified from default
- */
- public boolean isFontStyleModified()
- {
- return fontFormatting.isFontStyleModified();
- }
-
- /**
- * @return true if font style was set to <i>italic</i>
- */
- public boolean isItalic()
- {
- return fontFormatting.isFontStyleModified() && fontFormatting.isItalic();
- }
-
- /**
- * @return true if font outline is on
- */
- public boolean isOutlineOn()
- {
- return fontFormatting.isFontOutlineModified() && fontFormatting.isOutlineOn();
- }
-
- /**
- * @return true if font shadow is on
- */
- public boolean isShadowOn()
- {
- return fontFormatting.isFontOutlineModified() && fontFormatting.isShadowOn();
- }
-
- /**
- * @return true if font strikeout is on
- */
- public boolean isStruckout()
- {
- return fontFormatting.isFontCancellationModified() && fontFormatting.isStruckout();
- }
-
- /**
- * @return true if font underline type was modified from default
- */
- public boolean isUnderlineTypeModified()
- {
- return fontFormatting.isUnderlineTypeModified();
- }
-
- /**
- * @return true if font weight was modified from default
- */
- public boolean isFontWeightModified()
- {
- return fontFormatting.isFontWeightModified();
- }
-
- /**
- * set font style options.
- *
- * @param italic - if true, set posture style to italic, otherwise to normal
- * @param bold if true, set font weight to bold, otherwise to normal
- */
-
- public void setFontStyle(boolean italic, boolean bold)
- {
- boolean modified = italic || bold;
- fontFormatting.setItalic(italic);
- fontFormatting.setBold(bold);
- fontFormatting.setFontStyleModified(modified);
- fontFormatting.setFontWieghtModified(modified);
- }
-
- /**
- * set font style options to default values (non-italic, non-bold)
- */
- public void resetFontStyle()
- {
- setFontStyle(false,false);
- }
-
- /**
- * set the escapement type for the font
- *
- * @param escapementType super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
- */
- public void setEscapementType(short escapementType)
- {
- switch(escapementType)
- {
- case HSSFFontFormatting.SS_SUB:
- case HSSFFontFormatting.SS_SUPER:
- fontFormatting.setEscapementType(escapementType);
- fontFormatting.setEscapementTypeModified(true);
- break;
- case HSSFFontFormatting.SS_NONE:
- fontFormatting.setEscapementType(escapementType);
- fontFormatting.setEscapementTypeModified(false);
- break;
- default:
- }
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setEscapementTypeModified(boolean)
- */
- public void setEscapementTypeModified(boolean modified)
- {
- fontFormatting.setEscapementTypeModified(modified);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCancellationModified(boolean)
- */
- public void setFontCancellationModified(boolean modified)
- {
- fontFormatting.setFontCancellationModified(modified);
- }
-
- /**
- * @param fci
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontColorIndex(short)
- */
- public void setFontColorIndex(short fci)
- {
- fontFormatting.setFontColorIndex(fci);
- }
-
- /**
- * @param height
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(int)
- */
- public void setFontHeight(int height)
- {
- fontFormatting.setFontHeight(height);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontOutlineModified(boolean)
- */
- public void setFontOutlineModified(boolean modified)
- {
- fontFormatting.setFontOutlineModified(modified);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontShadowModified(boolean)
- */
- public void setFontShadowModified(boolean modified)
- {
- fontFormatting.setFontShadowModified(modified);
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontStyleModified(boolean)
- */
- public void setFontStyleModified(boolean modified)
- {
- fontFormatting.setFontStyleModified(modified);
- }
-
- /**
- * @param on
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setOutline(boolean)
- */
- public void setOutline(boolean on)
- {
- fontFormatting.setOutline(on);
- fontFormatting.setFontOutlineModified(on);
- }
-
- /**
- * @param on
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setShadow(boolean)
- */
- public void setShadow(boolean on)
- {
- fontFormatting.setShadow(on);
- fontFormatting.setFontShadowModified(on);
- }
-
- /**
- * @param strike
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setStrikeout(boolean)
- */
- public void setStrikeout(boolean strike)
- {
- fontFormatting.setStrikeout(strike);
- fontFormatting.setFontCancellationModified(strike);
- }
-
- /**
- * set the type of underlining type for the font
- *
- * @param underlineType super or subscript option
- *
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
- */
- public void setUnderlineType(short underlineType)
- {
- switch(underlineType)
- {
- case HSSFFontFormatting.U_SINGLE:
- case HSSFFontFormatting.U_DOUBLE:
- case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
- case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
- fontFormatting.setUnderlineType(underlineType);
- setUnderlineTypeModified(true);
- break;
-
- case HSSFFontFormatting.U_NONE:
- fontFormatting.setUnderlineType(underlineType);
- setUnderlineTypeModified(false);
- break;
- default:
- }
- }
-
- /**
- * @param modified
- * @see org.apache.poi.hssf.record.cf.FontFormatting#setUnderlineTypeModified(boolean)
- */
- public void setUnderlineTypeModified(boolean modified)
- {
- fontFormatting.setUnderlineTypeModified(modified);
- }
+ * gets the height of the font in 1/20th point units
+ *
+ * @return fontheight (in points/20); or -1 if not modified
+ */
+ public int getFontHeight() {
+ return fontFormatting.getFontHeight();
+ }
+
+ /**
+ * get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
+ * 0x190 for normal and 0x2bc for bold
+ *
+ * @return bw - a number between 100-1000 for the fonts "boldness"
+ */
+ public short getFontWeight() {
+ return fontFormatting.getFontWeight();
+ }
+
+ /**
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#getRawRecord()
+ */
+ protected byte[] getRawRecord() {
+ return fontFormatting.getRawRecord();
+ }
+
+ /**
+ * get the type of underlining for the font
+ *
+ * @return font underlining type
+ *
+ * @see #U_NONE
+ * @see #U_SINGLE
+ * @see #U_DOUBLE
+ * @see #U_SINGLE_ACCOUNTING
+ * @see #U_DOUBLE_ACCOUNTING
+ */
+ public short getUnderlineType()
+ {
+ return fontFormatting.getUnderlineType();
+ }
+
+ /**
+ * get whether the font weight is set to bold or not
+ *
+ * @return bold - whether the font is bold or not
+ */
+ public boolean isBold()
+ {
+ return fontFormatting.isFontWeightModified() && fontFormatting.isBold();
+ }
+
+ /**
+ * @return true if escapement type was modified from default
+ */
+ public boolean isEscapementTypeModified()
+ {
+ return fontFormatting.isEscapementTypeModified();
+ }
+
+ /**
+ * @return true if font cancellation was modified from default
+ */
+ public boolean isFontCancellationModified()
+ {
+ return fontFormatting.isFontCancellationModified();
+ }
+
+ /**
+ * @return true if font outline type was modified from default
+ */
+ public boolean isFontOutlineModified()
+ {
+ return fontFormatting.isFontOutlineModified();
+ }
+
+ /**
+ * @return true if font shadow type was modified from default
+ */
+ public boolean isFontShadowModified()
+ {
+ return fontFormatting.isFontShadowModified();
+ }
+
+ /**
+ * @return true if font style was modified from default
+ */
+ public boolean isFontStyleModified()
+ {
+ return fontFormatting.isFontStyleModified();
+ }
+
+ /**
+ * @return true if font style was set to <i>italic</i>
+ */
+ public boolean isItalic()
+ {
+ return fontFormatting.isFontStyleModified() && fontFormatting.isItalic();
+ }
+
+ /**
+ * @return true if font outline is on
+ */
+ public boolean isOutlineOn()
+ {
+ return fontFormatting.isFontOutlineModified() && fontFormatting.isOutlineOn();
+ }
+
+ /**
+ * @return true if font shadow is on
+ */
+ public boolean isShadowOn()
+ {
+ return fontFormatting.isFontOutlineModified() && fontFormatting.isShadowOn();
+ }
+
+ /**
+ * @return true if font strikeout is on
+ */
+ public boolean isStruckout()
+ {
+ return fontFormatting.isFontCancellationModified() && fontFormatting.isStruckout();
+ }
+
+ /**
+ * @return true if font underline type was modified from default
+ */
+ public boolean isUnderlineTypeModified()
+ {
+ return fontFormatting.isUnderlineTypeModified();
+ }
+
+ /**
+ * @return true if font weight was modified from default
+ */
+ public boolean isFontWeightModified()
+ {
+ return fontFormatting.isFontWeightModified();
+ }
+
+ /**
+ * set font style options.
+ *
+ * @param italic - if true, set posture style to italic, otherwise to normal
+ * @param bold if true, set font weight to bold, otherwise to normal
+ */
+
+ public void setFontStyle(boolean italic, boolean bold)
+ {
+ boolean modified = italic || bold;
+ fontFormatting.setItalic(italic);
+ fontFormatting.setBold(bold);
+ fontFormatting.setFontStyleModified(modified);
+ fontFormatting.setFontWieghtModified(modified);
+ }
+
+ /**
+ * set font style options to default values (non-italic, non-bold)
+ */
+ public void resetFontStyle()
+ {
+ setFontStyle(false,false);
+ }
+
+ /**
+ * set the escapement type for the font
+ *
+ * @param escapementType super or subscript option
+ * @see #SS_NONE
+ * @see #SS_SUPER
+ * @see #SS_SUB
+ */
+ public void setEscapementType(short escapementType) {
+ switch(escapementType) {
+ case HSSFFontFormatting.SS_SUB:
+ case HSSFFontFormatting.SS_SUPER:
+ fontFormatting.setEscapementType(escapementType);
+ fontFormatting.setEscapementTypeModified(true);
+ break;
+ case HSSFFontFormatting.SS_NONE:
+ fontFormatting.setEscapementType(escapementType);
+ fontFormatting.setEscapementTypeModified(false);
+ break;
+ default:
+ }
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setEscapementTypeModified(boolean)
+ */
+ public void setEscapementTypeModified(boolean modified) {
+ fontFormatting.setEscapementTypeModified(modified);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCancellationModified(boolean)
+ */
+ public void setFontCancellationModified(boolean modified)
+ {
+ fontFormatting.setFontCancellationModified(modified);
+ }
+
+ /**
+ * @param fci
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontColorIndex(short)
+ */
+ public void setFontColorIndex(short fci)
+ {
+ fontFormatting.setFontColorIndex(fci);
+ }
+
+ /**
+ * @param height
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(int)
+ */
+ public void setFontHeight(int height)
+ {
+ fontFormatting.setFontHeight(height);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontOutlineModified(boolean)
+ */
+ public void setFontOutlineModified(boolean modified)
+ {
+ fontFormatting.setFontOutlineModified(modified);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontShadowModified(boolean)
+ */
+ public void setFontShadowModified(boolean modified)
+ {
+ fontFormatting.setFontShadowModified(modified);
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setFontStyleModified(boolean)
+ */
+ public void setFontStyleModified(boolean modified)
+ {
+ fontFormatting.setFontStyleModified(modified);
+ }
+
+ /**
+ * @param on
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setOutline(boolean)
+ */
+ public void setOutline(boolean on)
+ {
+ fontFormatting.setOutline(on);
+ fontFormatting.setFontOutlineModified(on);
+ }
+
+ /**
+ * @param on
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setShadow(boolean)
+ */
+ public void setShadow(boolean on)
+ {
+ fontFormatting.setShadow(on);
+ fontFormatting.setFontShadowModified(on);
+ }
+
+ /**
+ * @param strike
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setStrikeout(boolean)
+ */
+ public void setStrikeout(boolean strike)
+ {
+ fontFormatting.setStrikeout(strike);
+ fontFormatting.setFontCancellationModified(strike);
+ }
+
+ /**
+ * set the type of underlining type for the font
+ *
+ * @param underlineType super or subscript option
+ *
+ * @see #U_NONE
+ * @see #U_SINGLE
+ * @see #U_DOUBLE
+ * @see #U_SINGLE_ACCOUNTING
+ * @see #U_DOUBLE_ACCOUNTING
+ */
+ public void setUnderlineType(short underlineType) {
+ switch(underlineType) {
+ case HSSFFontFormatting.U_SINGLE:
+ case HSSFFontFormatting.U_DOUBLE:
+ case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
+ case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
+ fontFormatting.setUnderlineType(underlineType);
+ setUnderlineTypeModified(true);
+ break;
+
+ case HSSFFontFormatting.U_NONE:
+ fontFormatting.setUnderlineType(underlineType);
+ setUnderlineTypeModified(false);
+ break;
+ default:
+ }
+ }
+
+ /**
+ * @param modified
+ * @see org.apache.poi.hssf.record.cf.FontFormatting#setUnderlineTypeModified(boolean)
+ */
+ public void setUnderlineTypeModified(boolean modified)
+ {
+ fontFormatting.setUnderlineTypeModified(modified);
+ }
}
/**\r
* High level representation for Font Formatting component\r
* of Conditional Formatting settings\r
- *\r
- * @author Dmitriy Kumshayev\r
- * @author Yegor Kozlov\r
*/\r
public interface FontFormatting {\r
/** Escapement type - None */\r