//Simulates a write to know how much it takes. private long SSTRecordSize(bool Repeatable) { long BeginRecordPos = 0; byte[] Buffer = new byte[XlsConsts.MaxRecordDataSize + 4]; int BufferPos = 4 + 8; long TotalSize = 0; if (Repeatable) { //REPEATABLEWRITES TSSTEntry[] SortedEntries = new TSSTEntry[Data.Count]; Data.Keys.CopyTo(SortedEntries, 0); Array.Sort(SortedEntries); foreach (TSSTEntry Se in SortedEntries) { Se.SaveToStream(null, Buffer, ref BufferPos, ref BeginRecordPos, ref TotalSize); } } else { Dictionary <TSSTEntry, TSSTEntry> .Enumerator myEnumerator = Data.GetEnumerator(); while (myEnumerator.MoveNext()) { myEnumerator.Current.Key.SaveToStream(null, Buffer, ref BufferPos, ref BeginRecordPos, ref TotalSize); } } TotalSize += BufferPos; return(TotalSize); }
internal void Load(TSSTRecord aSSTRecord) { int Ofs = 8; TxBaseRecord TmpSSTRecord = aSSTRecord; Data = CreateData(); IndexData = new List <TSSTEntry>((int)aSSTRecord.Count); //Excel will always have the right count here, but silly third poarties might not. //long aCount = aSSTRecord.Count; //for (int i=0; i<aCount;i++) while (TmpSSTRecord.Continue != null || Ofs < TmpSSTRecord.DataSize) { TSSTEntry Es = new TSSTEntry(ref TmpSSTRecord, ref Ofs); if (Data.ContainsKey(Es)) //An excel file could have a repeated string. { IndexData.Add(Data[Es]); } else { Data.Add(Es, Es); IndexData.Add(Es); } } //We need IndexData until all the LABELSST records have been loaded }
public int CompareTo(object obj) { //Only of use in Testing. TSSTEntry x = obj as TSSTEntry; if (x == null) { return(-1); } int Result = OptionFlags.CompareTo(x.OptionFlags); if (Result != 0) { return(Result); } Result = Data.CompareTo(x.Data); if (Result != 0) { return(Result); } Result = BitOps.CompareMemOrdinal(RichTextFormats, x.RichTextFormats); if (Result != 0) { return(Result); } Result = BitOps.CompareMemOrdinal(x.FarEastData, x.FarEastData); if (Result != 0) { return(Result); } return(0); }
internal TLabelSSTRecord(int aCol, int aXF, TSST aSST, IFlexCelFontList aFontList, TRichString Value) : base((int)xlr.LABELSST, aCol, aXF) { SST = aSST; FontList = aFontList; pSSTEntry = null; AsRichString = Value; }
internal TLabelSSTRecord(int aCol, int aXF, TSST aSST, IFlexCelFontList aFontList, object Value) : base((int)xlr.LABELSST, aCol, aXF) { SST = aSST; FontList = aFontList; pSSTEntry = null; AsString = FlxConvert.ToStringWithArrays(Value); }
internal void WriteExtSST(IDataStream DataStream, bool Repeatable) { // Calc number of strings per hash bucket UInt16 n = (UInt16)((Data.Count / 128) + 1); if (n < 8) { n = 8; } int nBuckets = 0; if (Data.Count == 0) { nBuckets = 0; } else { nBuckets = (Data.Count - 1) / n + 1; } DataStream.WriteHeader((UInt16)xlr.EXTSST, (UInt16)(2 + 8 * nBuckets)); DataStream.Write16(n); if (Repeatable) { //REPEATABLEWRITES TSSTEntry[] SortedEntries = new TSSTEntry[Data.Count]; Data.Keys.CopyTo(SortedEntries, 0); Array.Sort(SortedEntries); int i = 0; while (i < SortedEntries.Length) { TSSTEntry e = SortedEntries[i]; DataStream.Write32((UInt32)e.AbsStreamPos); DataStream.Write32(e.RecordStreamPos); i += n; } } else { Dictionary <TSSTEntry, TSSTEntry> .Enumerator myEnumerator = Data.GetEnumerator(); while (myEnumerator.MoveNext()) { TSSTEntry e = myEnumerator.Current.Key; DataStream.Write32((UInt32)e.AbsStreamPos); DataStream.Write32(e.RecordStreamPos); for (int i = 0; i < n - 1; i++) { if (!myEnumerator.MoveNext()) { return; //the if is needed to fix a bug in mono. } } } } }
/// <summary> /// Should be called before we release SST.IndexData /// </summary> /// <param name="aSST"></param> /// <param name="index"></param> /// <param name="aFontList"></param> private void AttachToSST(long index, TSST aSST, IFlexCelFontList aFontList) { if (aSST == null || aFontList == null || index >= aSST.IndexData.Count) { XlsMessages.ThrowException(XlsErr.ErrExcelInvalid); } SST = aSST; pSSTEntry = SST.IndexData[(int)index]; pSSTEntry.AddRef(); FontList = aFontList; }
internal void LoadXml(TxSSTRecord aSSTRecord) { if (IndexData == null) { IndexData = new List <TSSTEntry>(); } TSSTEntry es = new TSSTEntry(aSSTRecord.Text, aSSTRecord.RTFRuns, false); if (Data.ContainsKey(es)) { IndexData.Add(Data[es]); } else { IndexData.Add(es); Data.Add(es, es); } //We need IndexData until all the LABELSST records have been loaded }
internal void FixRefs() { List <TSSTEntry> KeysToRemove = new List <TSSTEntry>(); Dictionary <TSSTEntry, TSSTEntry> .Enumerator myEnumerator = Data.GetEnumerator(); while (myEnumerator.MoveNext()) { TSSTEntry en = myEnumerator.Current.Key; if ((en).Refs <= 0) { KeysToRemove.Add(en); } } //Now do the actual remove for (int i = 0; i < KeysToRemove.Count; i++) { Data.Remove(KeysToRemove[i]); } }
internal TSSTEntry AddString(string s, TRTFRun[] RTFRuns) { if (Data == null) { Data = CreateData(); //this is for testing } TSSTEntry es = new TSSTEntry(s, RTFRuns, false); if (Data.ContainsKey(es)) { es = ((TSSTEntry)Data[es]); es.AddRef(); } else { es.AddRef(); Data.Add(es, es); } return(es); }
internal void PrepareToSave(bool Repeatable, out UInt32 TotalRefs, out IEnumerator <KeyValuePair <TSSTEntry, TSSTEntry> > myEnumerator, out TSSTEntry[] SortedEntries) { //Renum the items. We need the order to serialize to disk UInt32 i = 0; TotalRefs = 0; myEnumerator = null; SortedEntries = null; if (Repeatable) { //REPEATABLEWRITES //Allow to create always the same file. It takes more time because it needs to sort the entries, and this is not needed, except for testing. SortedEntries = new TSSTEntry[Data.Count]; Data.Keys.CopyTo(SortedEntries, 0); Array.Sort(SortedEntries); foreach (TSSTEntry Se in SortedEntries) { Debug.Assert(Se.Refs > 0, "Refs should be >0"); Se.PosInTable = i; TotalRefs += (UInt32)Se.Refs; i++; } } else { myEnumerator = Data.GetEnumerator(); while (myEnumerator.MoveNext()) { TSSTEntry Se = myEnumerator.Current.Key; Debug.Assert(Se.Refs > 0, "Refs should be >0"); Se.PosInTable = i; TotalRefs += (UInt32)Se.Refs; i++; } } }
internal TSSTEntry this[TSSTEntry es] { get{ return((TSSTEntry)Data[es]); } }