/// <summary> A constructor used when creating a writable record /// /// </summary> /// <param name="fnt">the font /// </param> /// <param name="form">the format /// </param> public XFRecord(FontRecord fnt, DisplayFormat form) : base(NExcel.Biff.Type.XF) { initialized = false; locked = true; hidden = false; align = Alignment.GENERAL; valign = VerticalAlignment.BOTTOM; orientation = Orientation.HORIZONTAL; wrap = false; leftBorder = BorderLineStyle.NONE; rightBorder = BorderLineStyle.NONE; topBorder = BorderLineStyle.NONE; bottomBorder = BorderLineStyle.NONE; leftBorderColour = Colour.PALETTE_BLACK; rightBorderColour = Colour.PALETTE_BLACK; topBorderColour = Colour.PALETTE_BLACK; bottomBorderColour = Colour.PALETTE_BLACK; pattern = Pattern.NONE; backgroundColour = Colour.DEFAULT_BACKGROUND; shrinkToFit = false; // This will be set by the initialize method and the subclass respectively parentFormat = 0; xfFormatType = null; font = fnt; format = form; biffType = biff8; read = false; copied = false; formatInfoInitialized = true; Assert.verify(font != null); Assert.verify(format != null); }
/// <summary> Sets the font object with a workbook specific clone. Called from /// the CellValue object when the font has been identified as a statically /// shared font /// </summary> public virtual void setFont(FontRecord f) { // This style cannot be initialized, otherwise it would mean it would // have been initialized with shared font Assert.verify(!initialized); font = f; }
/// <summary> Adds a font record to this workbook. If the FontRecord passed in has not /// been initialized, then its font index is determined based upon the size /// of the fonts list. The FontRecord's initialized method is called, and /// it is added to the list of fonts. /// /// </summary> /// <param name="f">the font to add /// </param> public virtual void addFont(FontRecord f) { if (!f.IsInitialized()) { int pos = fonts.Count; // Remember that the pos with index 4 is skipped if (pos >= 4) { pos++; } f.initialize(pos); fonts.Add(f); } }
/// <summary> Standard equals method</summary> /// <param name="o">the object to compare /// </param> /// <returns> TRUE if the objects are equal, FALSE otherwise /// </returns> public override bool Equals(System.Object o) { if (o == this) { return(true); } if (!(o is FontRecord)) { return(false); } FontRecord font = (FontRecord)o; if (pointHeight == font.pointHeight && colourIndex == font.colourIndex && boldWeight == font.boldWeight && scriptStyle == font.scriptStyle && underlineStyle == font.underlineStyle && italic == font.italic && struckout == font.struckout && fontFamily == font.fontFamily && characterSet == font.characterSet && name.Equals(font.name)) { return(true); } return(false); }
/// <summary> Copy constructor. Used for copying writable formats, typically /// when duplicating formats to handle merged cells /// /// </summary> /// <param name="fmt">XFRecord /// </param> protected internal XFRecord(XFRecord fmt) : base(NExcel.Biff.Type.XF) { initialized = false; locked = fmt.locked; hidden = fmt.hidden; align = fmt.align; valign = fmt.valign; orientation = fmt.orientation; wrap = fmt.wrap; leftBorder = fmt.leftBorder; rightBorder = fmt.rightBorder; topBorder = fmt.topBorder; bottomBorder = fmt.bottomBorder; leftBorderColour = fmt.leftBorderColour; rightBorderColour = fmt.rightBorderColour; topBorderColour = fmt.topBorderColour; bottomBorderColour = fmt.bottomBorderColour; pattern = fmt.pattern; xfFormatType = fmt.xfFormatType; shrinkToFit = fmt.shrinkToFit; parentFormat = fmt.parentFormat; backgroundColour = fmt.backgroundColour; // Shallow copy is sufficient for these purposes font = fmt.font; format = fmt.format; fontIndex = fmt.fontIndex; formatIndex = fmt.formatIndex; formatInfoInitialized = fmt.formatInfoInitialized; biffType = biff8; read = false; copied = true; }
// [TODO-NExcel_Next] // /** // * Writes out the list of fonts // * // * @param outputFile the compound file to write the data to // * @exception IOException // */ // public void write(File outputFile) throws IOException // { // Iterator i = fonts.iterator(); // // FontRecord font = null; // while (i.hasNext()) // { // font = (FontRecord) i.next(); // outputFile.write(font); // } // } // /// <summary> Rationalizes all the fonts, removing any duplicates /// /// </summary> /// <returns> the mappings between new indexes and old ones /// </returns> internal virtual IndexMapping rationalize() { IndexMapping mapping = new IndexMapping(fonts.Count + 1); // allow for skipping record 4 ArrayList newfonts = new ArrayList(); FontRecord fr = null; int numremoved = 0; // Preserve the default fonts for (int i = 0; i < numDefaultFonts; i++) { fr = (FontRecord)fonts[i]; newfonts.Add(fr); mapping.setMapping(fr.FontIndex, fr.FontIndex); } // Now do the rest // Iterator it = null; // FontRecord fr2 = null; bool duplicate = false; for (int i = numDefaultFonts; i < fonts.Count; i++) { fr = (FontRecord)fonts[i]; // Compare to all the fonts currently on the list duplicate = false; foreach (FontRecord fr2 in newfonts) { if (duplicate) { break; } if (fr.Equals(fr2)) { duplicate = true; mapping.setMapping(fr.FontIndex, mapping.getNewIndex(fr2.FontIndex)); numremoved++; } } if (!duplicate) { // Add to the new list newfonts.Add(fr); int newindex = fr.FontIndex - numremoved; Assert.verify(newindex > 4); mapping.setMapping(fr.FontIndex, newindex); } } // Iterate through the remaining fonts, updating all the font indices foreach (FontRecord fr3 in newfonts) { fr3.initialize(mapping.getNewIndex(fr3.FontIndex)); } fonts = newfonts; return(mapping); }
/// <summary> A public copy constructor which can be used for copy formats between /// different sheets. Unlike the the other copy constructor, this /// version does a deep copy /// /// </summary> /// <param name="cellFormat">the format to copy /// </param> protected internal XFRecord(CellFormat cellFormat) : base(NExcel.Biff.Type.XF) { Assert.verify(cellFormat is XFRecord); XFRecord fmt = (XFRecord)cellFormat; if (!fmt.formatInfoInitialized) { fmt.initializeFormatInformation(); } locked = fmt.locked; hidden = fmt.hidden; align = fmt.align; valign = fmt.valign; orientation = fmt.orientation; wrap = fmt.wrap; leftBorder = fmt.leftBorder; rightBorder = fmt.rightBorder; topBorder = fmt.topBorder; bottomBorder = fmt.bottomBorder; leftBorderColour = fmt.leftBorderColour; rightBorderColour = fmt.rightBorderColour; topBorderColour = fmt.topBorderColour; bottomBorderColour = fmt.bottomBorderColour; pattern = fmt.pattern; xfFormatType = fmt.xfFormatType; parentFormat = fmt.parentFormat; shrinkToFit = fmt.shrinkToFit; backgroundColour = fmt.backgroundColour; // Deep copy of the font font = new FontRecord(fmt.Font); // Copy the format if (fmt.Format == null) { // format is writable if (fmt.format.isBuiltIn()) { format = fmt.format; } else { // Format is not built in, so do a deep copy format = new FormatRecord((FormatRecord)fmt.format); } } else if (fmt.Format is BuiltInFormat) { // read excel format is built in excelFormat = (BuiltInFormat)fmt.excelFormat; format = (BuiltInFormat)fmt.excelFormat; } else { // read excel format is user defined Assert.verify(fmt.formatInfoInitialized); // in this case FormattingRecords should initialize the excelFormat // field with an instance of FormatRecord Assert.verify(fmt.excelFormat is FormatRecord); // Format is not built in, so do a deep copy FormatRecord fr = new FormatRecord((FormatRecord)fmt.excelFormat); // Set both format fields to be the same object, since // FormatRecord implements all the necessary interfaces excelFormat = fr; format = fr; } biffType = biff8; // The format info should be all OK by virtue of the deep copy formatInfoInitialized = true; // This format was not read in read = false; // Treat this as a new cell record, so set the copied flag to false copied = false; // The font or format indexes need to be set, so set initialized to false initialized = false; }
/// <summary> Initializes the internal format information from the data read in</summary> private void initializeFormatInformation() { // Initialize the cell format string if (formatIndex < BuiltInFormat.builtIns.Length && BuiltInFormat.builtIns[formatIndex] != null) { excelFormat = BuiltInFormat.builtIns[formatIndex]; } else { excelFormat = formattingRecords.getFormatRecord(formatIndex); } // Initialize the font font = formattingRecords.Fonts.getFont(fontIndex); // Initialize the cell format data from the binary record sbyte[] data = getRecord().Data; // Get the parent record int cellAttributes = IntegerHelper.getInt(data[4], data[5]); parentFormat = (cellAttributes & 0xfff0) >> 4; int formatType = cellAttributes & 0x4; xfFormatType = formatType == 0?cell:style; locked = ((cellAttributes & 0x1) != 0); hidden = ((cellAttributes & 0x2) != 0); if (xfFormatType == cell && (parentFormat & 0xfff) == 0xfff) { // Something is screwy with the parent format - set to zero parentFormat = 0; logger.warn("Invalid parent format found - ignoring"); } int alignMask = IntegerHelper.getInt(data[6], data[7]); // Get the wrap if ((alignMask & 0x08) != 0) { wrap = true; } // Get the horizontal alignment align = Alignment.getAlignment(alignMask & 0x7); // Get the vertical alignment valign = VerticalAlignment.getAlignment((alignMask >> 4) & 0x7); // Get the orientation orientation = Orientation.getOrientation((alignMask >> 8) & 0xff); int attr = IntegerHelper.getInt(data[8], data[9]); // Get the shrink to fit flag shrinkToFit = (attr & 0x10) != 0; // Get the used attribute if (biffType == biff8) { usedAttributes = data[9]; } // Get the borders int borderMask = IntegerHelper.getInt(data[10], data[11]); leftBorder = BorderLineStyle.getStyle(borderMask & 0x7); rightBorder = BorderLineStyle.getStyle((borderMask >> 4) & 0x7); topBorder = BorderLineStyle.getStyle((borderMask >> 8) & 0x7); bottomBorder = BorderLineStyle.getStyle((borderMask >> 12) & 0x7); int borderColourMask = IntegerHelper.getInt(data[12], data[13]); leftBorderColour = Colour.getInternalColour(borderColourMask & 0x7f); rightBorderColour = Colour.getInternalColour((borderColourMask & 0x3f80) >> 7); borderColourMask = IntegerHelper.getInt(data[14], data[15]); topBorderColour = Colour.getInternalColour(borderColourMask & 0x7f); bottomBorderColour = Colour.getInternalColour((borderColourMask & 0x3f80) >> 7); if (biffType == biff8) { // Get the background pattern int patternVal = IntegerHelper.getInt(data[16], data[17]); pattern = Pattern.getPattern(patternVal); // Get the background colour int colourPaletteMask = IntegerHelper.getInt(data[18], data[19]); backgroundColour = Colour.getInternalColour(colourPaletteMask & 0x3f); if (backgroundColour == Colour.UNKNOWN || backgroundColour == Colour.DEFAULT_BACKGROUND1) { backgroundColour = Colour.DEFAULT_BACKGROUND; } } else { pattern = Pattern.NONE; backgroundColour = Colour.DEFAULT_BACKGROUND; } // Set the lazy initialization flag formatInfoInitialized = true; }