FileDocCategorySizeDatePackage
FontRecord.javaAPI DocApache Poi 3.0.116200Mon Jan 01 12:39:40 GMT 2007org.apache.poi.hssf.record

FontRecord

public class FontRecord extends Record
Title: Font Record - descrbes a font in the workbook (index = 0-3,5-infinity - skip 4)

Description: An element in the Font Table

REFERENCE: PG 315 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)

author
Andrew C. Oliver (acoliver at apache dot org)
version
2.0-pre

Fields Summary
public static final short
sid
public static final short
SS_NONE
public static final short
SS_SUPER
public static final short
SS_SUB
public static final byte
U_NONE
public static final byte
U_SINGLE
public static final byte
U_DOUBLE
public static final byte
U_SINGLE_ACCOUNTING
public static final byte
U_DOUBLE_ACCOUNTING
private short
field_1_font_height
private short
field_2_attributes
private static final BitField
italic
private static final BitField
strikeout
private static final BitField
macoutline
private static final BitField
macshadow
private short
field_3_color_palette_index
private short
field_4_bold_weight
private short
field_5_super_sub_script
private byte
field_6_underline
private byte
field_7_family
private byte
field_8_charset
private byte
field_9_zero
private byte
field_10_font_name_len
private String
field_11_font_name
Constructors Summary
public FontRecord()

         // whoa...the font name

     
    
    
public FontRecord(RecordInputStream in)
Constructs a Font record and sets its fields appropriately.

param
id id must be 0x31 (NOT 0x231 see MSKB #Q184647 for an "explanation of this bug in the documentation) or an exception will be throw upon validation
param
size the size of the data area of the record
param
data data of the record (should not contain sid/len)

        super(in);
    
Methods Summary
protected voidfillFields(org.apache.poi.hssf.record.RecordInputStream in)

        field_1_font_height         = in.readShort();
        field_2_attributes          = in.readShort();
        field_3_color_palette_index = in.readShort();
        field_4_bold_weight         = in.readShort();
        field_5_super_sub_script    = in.readShort();
        field_6_underline           = in.readByte();
        field_7_family              = in.readByte();
        field_8_charset             = in.readByte();
        field_9_zero                = in.readByte();
        field_10_font_name_len      = in.readByte();
        if (field_10_font_name_len > 0)
        {
            if (in.readByte() == 0)
            {   // is compressed unicode
                field_11_font_name = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_10_font_name_len));
            }
            else
            {   // is not compressed unicode
                field_11_font_name = in.readUnicodeLEString(field_10_font_name_len);
            }
        }
    
public shortgetAttributes()
get the font attributes (see individual bit getters that reference this method)

return
attribute - the bitmask

        return field_2_attributes;
    
public shortgetBoldWeight()
get the bold 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"

        return field_4_bold_weight;
    
public bytegetCharset()
get the character set

return
charset - characterset

        return field_8_charset;
    
public shortgetColorPaletteIndex()
get the font's color palette index

return
cpi - font color index

        return field_3_color_palette_index;
    
public bytegetFamily()
get the font family (TODO)

return
family

        return field_7_family;
    
public shortgetFontHeight()
gets the height of the font in 1/20th point units

return
fontheight (in points/20)

        return field_1_font_height;
    
public java.lang.StringgetFontName()
get the name of the font

return
fn - name of the font (i.e. "Arial")

        return field_11_font_name;
    
public bytegetFontNameLength()
get the length of the fontname string

return
length of the font name
see
#getFontName()

        return field_10_font_name_len;
    
public intgetRecordSize()

        return (getFontNameLength() * 2) + 20;
    
public shortgetSid()

        return sid;
    
public shortgetSuperSubScript()
get the type of super or subscript for the font

return
super or subscript option
see
#SS_NONE
see
#SS_SUPER
see
#SS_SUB

        return field_5_super_sub_script;
    
public bytegetUnderline()
get the type of underlining for the font

return
super or subscript option
see
#U_NONE
see
#U_SINGLE
see
#U_DOUBLE
see
#U_SINGLE_ACCOUNTING
see
#U_DOUBLE_ACCOUNTING

        return field_6_underline;
    
public booleanisItalic()
get whether the font is to be italics or not

return
italics - whether the font is italics or not
see
#getAttributes()

        return italic.isSet(field_2_attributes);
    
public booleanisMacoutlined()
whether to use the mac outline font style thing (mac only) - Some mac person should comment this instead of me doing it (since I have no idea)

return
mac - whether to do that mac font outline thing or not
see
#getAttributes()

        return macoutline.isSet(field_2_attributes);
    
public booleanisMacshadowed()
whether to use the mac shado font style thing (mac only) - Some mac person should comment this instead of me doing it (since I have no idea)

return
mac - whether to do that mac font shadow thing or not
see
#getAttributes()

        return macshadow.isSet(field_2_attributes);
    
public booleanisStruckout()
get whether the font is to be stricken out or not

return
strike - whether the font is stricken out or not
see
#getAttributes()

        return strikeout.isSet(field_2_attributes);
    
public intserialize(int offset, byte[] data)

        int realflen = getFontNameLength() * 2;

        LittleEndian.putShort(data, 0 + offset, sid);
        LittleEndian.putShort(
            data, 2 + offset,
            ( short ) (15 + realflen
                       + 1));   // 19 - 4 (sid/len) + font name length = datasize

        // undocumented single byte (1)
        LittleEndian.putShort(data, 4 + offset, getFontHeight());
        LittleEndian.putShort(data, 6 + offset, getAttributes());
        LittleEndian.putShort(data, 8 + offset, getColorPaletteIndex());
        LittleEndian.putShort(data, 10 + offset, getBoldWeight());
        LittleEndian.putShort(data, 12 + offset, getSuperSubScript());
        data[ 14 + offset ] = getUnderline();
        data[ 15 + offset ] = getFamily();
        data[ 16 + offset ] = getCharset();
        data[ 17 + offset ] = field_9_zero;
        data[ 18 + offset ] = getFontNameLength();
        data[ 19 + offset ] = ( byte ) 1;
        if (getFontName() != null) {
           StringUtil.putUnicodeLE(getFontName(), data, 20 + offset);
        }
        return getRecordSize();
    
public voidsetAttributes(short attributes)
set the font attributes (see individual bit setters that reference this method)

param
attributes the bitmask to set

        field_2_attributes = attributes;
    
public voidsetBoldWeight(short bw)
set the bold weight for this font (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"

        field_4_bold_weight = bw;
    
public voidsetCharset(byte charset)
set the character set

param
charset - characterset

        field_8_charset = charset;
    
public voidsetColorPaletteIndex(short cpi)
set the font's color palette index

param
cpi - font color index

        field_3_color_palette_index = cpi;
    
public voidsetFamily(byte f)
set the font family (TODO)

param
f family

        field_7_family = f;
    
public voidsetFontHeight(short height)
sets the height of the font in 1/20th point units

param
height fontheight (in points/20)

        field_1_font_height = height;
    
public voidsetFontName(java.lang.String fn)
set the name of the font

param
fn - name of the font (i.e. "Arial")

        field_11_font_name = fn;
    
public voidsetFontNameLength(byte len)
set the length of the fontname string

param
len length of the font name
see
#setFontName(String)

        field_10_font_name_len = len;
    
public voidsetItalic(boolean italics)
set the font to be italics or not

param
italics - whether the font is italics or not
see
#setAttributes(short)

        field_2_attributes = italic.setShortBoolean(field_2_attributes, italics);
    
public voidsetMacoutline(boolean mac)
whether to use the mac outline font style thing (mac only) - Some mac person should comment this instead of me doing it (since I have no idea)

param
mac - whether to do that mac font outline thing or not
see
#setAttributes(short)

        field_2_attributes = macoutline.setShortBoolean(field_2_attributes, mac);
    
public voidsetMacshadow(boolean mac)
whether to use the mac shado font style thing (mac only) - Some mac person should comment this instead of me doing it (since I have no idea)

param
mac - whether to do that mac font shadow thing or not
see
#setAttributes(short)

        field_2_attributes = macshadow.setShortBoolean(field_2_attributes, mac);
    
public voidsetStrikeout(boolean strike)
set the font to be stricken out or not

param
strike - whether the font is stricken out or not
see
#setAttributes(short)

        field_2_attributes = strikeout.setShortBoolean(field_2_attributes, strike);
    
public voidsetSuperSubScript(short sss)
set the type of super or subscript for the font

param
sss super or subscript option
see
#SS_NONE
see
#SS_SUPER
see
#SS_SUB

        field_5_super_sub_script = sss;
    
public voidsetUnderline(byte u)
set the type of underlining for the font

param
u super or subscript option
see
#U_NONE
see
#U_SINGLE
see
#U_DOUBLE
see
#U_SINGLE_ACCOUNTING
see
#U_DOUBLE_ACCOUNTING

        field_6_underline = u;
    
public java.lang.StringtoString()

        StringBuffer buffer = new StringBuffer();

        buffer.append("[FONT]\n");
        buffer.append("    .fontheight      = ")
            .append(Integer.toHexString(getFontHeight())).append("\n");
        buffer.append("    .attributes      = ")
            .append(Integer.toHexString(getAttributes())).append("\n");
        buffer.append("         .italic     = ").append(isItalic())
            .append("\n");
        buffer.append("         .strikout   = ").append(isStruckout())
            .append("\n");
        buffer.append("         .macoutlined= ").append(isMacoutlined())
            .append("\n");
        buffer.append("         .macshadowed= ").append(isMacshadowed())
            .append("\n");
        buffer.append("    .colorpalette    = ")
            .append(Integer.toHexString(getColorPaletteIndex())).append("\n");
        buffer.append("    .boldweight      = ")
            .append(Integer.toHexString(getBoldWeight())).append("\n");
        buffer.append("    .supersubscript  = ")
            .append(Integer.toHexString(getSuperSubScript())).append("\n");
        buffer.append("    .underline       = ")
            .append(Integer.toHexString(getUnderline())).append("\n");
        buffer.append("    .family          = ")
            .append(Integer.toHexString(getFamily())).append("\n");
        buffer.append("    .charset         = ")
            .append(Integer.toHexString(getCharset())).append("\n");
        buffer.append("    .namelength      = ")
            .append(Integer.toHexString(getFontNameLength())).append("\n");
        buffer.append("    .fontname        = ").append(getFontName())
            .append("\n");
        buffer.append("[/FONT]\n");
        return buffer.toString();
    
protected voidvalidateSid(short id)

        if (id != sid)
        {
            throw new RecordFormatException("NOT A FONT RECORD");
        }