Beispiel #1
0
        /// <summary>
        /// Adds a new Font object to this collection.
        /// </summary>
        /// <param name="font">The Font object to add to this collection.</param>
        /// <returns>The id of the Font within this collection.</returns>
        public ushort Add(Font font)
        {
            ushort? fontId = GetId(font);

            if (fontId == null)
            {
                fontId = (ushort)_fonts.Count;
                _fonts.Add((Font)font.Clone());
            }

            return (ushort) fontId;
        }
Beispiel #2
0
        /// <summary>
        /// Calculates whether a given Font object is value-equal to this
        /// Font object.
        /// </summary>
        /// <param name="that">A Font object to compare to this Font.</param>
        /// <returns>true if equal, false otherwise</returns>
        public bool Equals(Font that)
        {
            if (_height != that._height) return false;
            if (_italic != that._italic) return false;
            if (_underlined != that._underlined) return false;
            if (_struckOut != that._struckOut) return false;
            if (!_color.Equals(that._color)) return false;
            if (_weight != that._weight) return false;
            if (_escapement != that._escapement) return false;
            if (_underline != that._underline) return false;
            if (_fontFamily != that._fontFamily) return false;
            if (_characterSet != that._characterSet) return false;
            #if SILVERLIGHT
            if (string.Compare(_fontName, that._fontName, StringComparison.InvariantCulture) != 0) return false;
            #else
            if (string.Compare(_fontName, that._fontName, false) != 0) return false;
            #endif

            return true;
        }
Beispiel #3
0
        /// <summary>
        /// Creates and returns a new Font object value-equal to this Font object.
        /// </summary>
        /// <returns>A new Font object value-equal to this Font object.</returns>
        public object Clone()
        {
            Font clone = new Font(_doc, _target);

            clone._height = _height;
            clone._italic = _italic;
            //clone._underlined = _underlined;
            clone._struckOut = _struckOut;
            clone._color = (Color)_color.Clone();
            clone._weight = _weight;
            clone._escapement = _escapement;
            clone._underline = _underline;
            clone._fontFamily = _fontFamily;
            clone._characterSet = _characterSet;
            clone._fontName = _fontName;

            return clone;
        }
Beispiel #4
0
 private void ReadBytes(Bytes bytes, Font font, string format)
 {
     _font   = font;
     _format = format;
     ReadXF_3(bytes.Get(4, 2));
 }
Beispiel #5
0
 internal void OnFontChange(Font newFont)
 {
     _font = (Font)newFont.Clone();
     //_font.ID = newFont.ID;
     OnChange();
 }
Beispiel #6
0
 internal XF(XlsDocument doc, Bytes bytes, Font font, string format) : this(doc)
 {
     ReadBytes(bytes, font, format);
 }
Beispiel #7
0
        internal bool Equals(XF that)
        {
            if (_horizontalAlignment != that._horizontalAlignment)
            {
                return(false);
            }
            if (_textWrapRight != that._textWrapRight)
            {
                return(false);
            }
            if (_verticalAlignment != that._verticalAlignment)
            {
                return(false);
            }
            if (_rotation != that._rotation)
            {
                return(false);
            }
            if (_indentLevel != that._indentLevel)
            {
                return(false);
            }
            if (_shrinkToCell != that._shrinkToCell)
            {
                return(false);
            }
            if (_textDirection != that._textDirection)
            {
                return(false);
            }
            if (_cellLocked != that._cellLocked)
            {
                return(false);
            }
            if (_formulaHidden != that._formulaHidden)
            {
                return(false);
            }
            if (_isStyleXF != that._isStyleXF)
            {
                return(false);
            }
            if (_useNumber != that._useNumber)
            {
                return(false);
            }
            if (_useFont != that._useFont)
            {
                return(false);
            }
            if (_useMisc != that._useMisc)
            {
                return(false);
            }
            if (_useBorder != that._useBorder)
            {
                return(false);
            }
            if (_useBackground != that._useBackground)
            {
                return(false);
            }
            if (_useProtection != that._useProtection)
            {
                return(false);
            }
            if (_leftLineStyle != that._leftLineStyle)
            {
                return(false);
            }
            if (_rightLineStyle != that._rightLineStyle)
            {
                return(false);
            }
            if (_topLineStyle != that._topLineStyle)
            {
                return(false);
            }
            if (_bottomLineStyle != that._bottomLineStyle)
            {
                return(false);
            }
            if (!_leftLineColor.Equals(that._leftLineColor))
            {
                return(false);
            }
            if (!_rightLineColor.Equals(that._rightLineColor))
            {
                return(false);
            }
            if (_diagonalDescending != that._diagonalDescending)
            {
                return(false);
            }
            if (_diagonalAscending != that._diagonalAscending)
            {
                return(false);
            }
            if (!_topLineColor.Equals(that._topLineColor))
            {
                return(false);
            }
            if (!_bottomLineColor.Equals(that._bottomLineColor))
            {
                return(false);
            }
            if (!_diagonalLineColor.Equals(that._diagonalLineColor))
            {
                return(false);
            }
            if (_diagonalLineStyle != that._diagonalLineStyle)
            {
                return(false);
            }
            if (_pattern != that._pattern)
            {
                return(false);
            }
            if (!_patternColor.Equals(that._patternColor))
            {
                return(false);
            }
            if (!_patternBackgroundColor.Equals(that._patternBackgroundColor))
            {
                return(false);
            }

            if (!Font.Equals(that.Font))
            {
                return(false);
            }
            if (!Format.Equals(that.Format))
            {
                return(false);
            }
            if (!Style.Equals(that.Style))
            {
                return(false);
            }

            //if (_targetObject != that._targetObject) return false;

            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// Gets whether the specified Font is included in this collection, and so will
        /// be written to the XlsDocument.
        /// </summary>
        /// <param name="font">The Font object to see whether it is written.</param>
        /// <returns>true if the specified Font is written, otherwise false</returns>
        public bool IsWritten(Font font)
		{
			return (GetId(font) != null);
		}
Beispiel #9
0
        private void SetDefaults()
        {
            _font = new Font(_doc, this);
            _format = Formats.Default;
            _style = new Style(_doc, this);

            _horizontalAlignment = HorizontalAlignments.Default;
            _textWrapRight = false;
            _verticalAlignment = VerticalAlignments.Default;
            _rotation = 0;
            _indentLevel = 0;
            _shrinkToCell = false;
            _textDirection = TextDirections.Default;
            _cellLocked = false; //NOTE: Unsure about this default (compare to Commented XF String in BinData)
            _formulaHidden = false; //NOTE: Unsure about this default (compare to Commented XF String in BinData)
            _isStyleXF = false; //NOTE: Unsure about this default (compare to Commented XF String in BinData)
            _useNumber = true;
            _useFont = true;
            _useMisc = true;
            _useBorder = true;
            _useBackground = true;
            _useProtection = true; //You should ALWAYS use protection ;-)
            _leftLineStyle = 0;
            _rightLineStyle = 0;
            _topLineStyle = 0;
            _bottomLineStyle = 0;
            _leftLineColor = Colors.DefaultLineColor;
            _rightLineColor = Colors.DefaultLineColor;
            _diagonalDescending = false;
            _diagonalAscending = false;
            _topLineColor = Colors.DefaultLineColor;
            _bottomLineColor = Colors.DefaultLineColor;
            _diagonalLineColor = Colors.DefaultLineColor;
            _diagonalLineStyle = LineStyle.None;
            _pattern = 0;
            _patternColor = Colors.DefaultPatternColor;
            _patternBackgroundColor = Colors.DefaultPatternBackgroundColor;

            OnChange();
        }
Beispiel #10
0
 private void ReadBytes(Bytes bytes, Font font, string format)
 {
     _font = font;
     _format = format;
     ReadXF_3(bytes.Get(4, 2));
 }
Beispiel #11
0
 internal void OnFontChange(Font newFont)
 {
     _font = (Font) newFont.Clone();
     //_font.ID = newFont.ID;
     OnChange();
 }
Beispiel #12
0
 internal XF(XlsDocument doc, Bytes bytes, Font font, string format)
     : this(doc)
 {
     ReadBytes(bytes, font, format);
 }
Beispiel #13
0
 private void AddDefaultFonts()
 {
     Font font = new Font(_doc, (XF)null);
     _fonts.Add(font);
     _fonts.Add((Font) font.Clone());
     _fonts.Add((Font) font.Clone());
     _fonts.Add((Font) font.Clone());
     _fonts.Add((Font)font.Clone()); //we won't write this one out - just leave it here to fill the 4-index that's never written
 }
Beispiel #14
0
        /// <summary>
        /// Gets the id of the specified Font in this collection.
        /// </summary>
        /// <param name="font">The Font for which to return an id.</param>
        /// <returns>the ushort id of the Font if it exists in this collection, 
        /// null otherwise</returns>
        public ushort? GetId(Font font)
        {
            for (ushort i = 0; i < (ushort)_fonts.Count; i++)
            {
                if (_fonts[i].Equals(font))
                    return i;
            }

            return null;
        }
Beispiel #15
0
        private void ReadBytes(Bytes bytes, BytesReadCallback bytesReadCallback)
        {
            if (bytes == null)
                throw new ArgumentNullException("bytes");

            if (bytes.Length == 0)
                throw new ArgumentException("can't be zero-length", "bytes");

            //The XF's read in won't necessarily have the same ID (index) once added to this Workbook,
            //so we need to keep the cross-reference list for re-assignment as we read in the cell records later
            SortedList<ushort, ushort> xfIdLookups = new SortedList<ushort, ushort>();

            List<Record> records = Record.GetAll(bytes);

            List<Record> fontRecords = new List<Record>();
            List<Record> formatRecords = new List<Record>();
            List<Record> xfRecords = new List<Record>();
            List<Record> boundSheetRecords = new List<Record>();
            Record sstRecord = Record.Empty;

            SortedList<int, List<Record>> sheetRecords = new SortedList<int, List<Record>>();

            int sheetIndex = -1;

            foreach (Record record in records)
            {
                if (sheetIndex >= 0)
                {
                    if (!sheetRecords.ContainsKey(sheetIndex))
                        sheetRecords[sheetIndex] = new List<Record>();
                    sheetRecords[sheetIndex].Add(record);
                    if (record.RID == RID.EOF)
                        sheetIndex++;
                }
                else if (record.RID == RID.FONT)
                    fontRecords.Add(record);
                else if (record.RID == RID.FORMAT)
                    formatRecords.Add(record);
                else if (record.RID == RID.XF)
                    xfRecords.Add(record);
                else if (record.RID == RID.BOUNDSHEET)
                    boundSheetRecords.Add(record);
                else if (record.RID == RID.SST)
                    sstRecord = record;
                else if (record.RID == RID.EOF)
                    sheetIndex++;
            }

            SortedList<ushort, string> formats = new SortedList<ushort, string>();

            ushort index = 0;
            foreach (Record record in fontRecords)
            {
                Font font = new Font(_doc, record.Data);
                this.Fonts.Add(font);
            }

            foreach (Record record in formatRecords)
            {
                Bytes recordData = record.Data;
                string format = UnicodeBytes.Read(recordData.Get(2, recordData.Length - 2), 16);
                index = BitConverter.ToUInt16(recordData.Get(2).ByteArray, 0);
                formats[index] = format;
                this.Formats.Add(format);
            }

            index = 0;
            for (index = 0; index < xfRecords.Count; index++)
            {
                Record record = xfRecords[index];
                Bytes recordData = record.Data;
                ushort fontIndex = BitConverter.ToUInt16(recordData.Get(0, 2).ByteArray, 0);
                ushort formatIndex = BitConverter.ToUInt16(recordData.Get(2, 2).ByteArray, 0);
                //ushort styleIndex = BitConverter.ToUInt16(recordData.Get(4, 2))

                //TODO: Defaults to default font.  Should it?  NOTE: This is encountered with TestReferenceFile BlankBudgetWorksheet.xls
                Font font = fontIndex < _fonts.Count ? _fonts[fontIndex] : _fonts[0];

                string format;
                if (formats.ContainsKey(formatIndex))
                    format = formats[formatIndex];
                else if (_formats.ContainsKey(formatIndex))
                    format = _formats[formatIndex];
                else
                    throw new Exception(string.Format("Format {0} not found in read FORMAT records or standard/default FORMAT records.", formatIndex));
                xfIdLookups[index] = this.XFs.Add(new XF(_doc, record.Data, font, format));
            }
            this.XFs.XfIdxLookups = xfIdLookups;

            if (sstRecord != Record.Empty)
                this.SharedStringTable.ReadBytes(sstRecord);

            if (bytesReadCallback != null)
                bytesReadCallback(records);

            for (int i = 0; i < boundSheetRecords.Count; i++)
            {
                _worksheets.Add(boundSheetRecords[i], sheetRecords[i]);
            }
        }