예제 #1
0
        private void WriteLocalFile(IDataStream DataStream, string value, ref int NewPos)
        {
            int i = 0;

            while (i + 3 <= value.Length && value.Substring(i, 3) == ".." + Path.DirectorySeparatorChar)
            {
                i += 3;
            }
            value = value.Substring(i);

            bool IsCompressed = !StrOps.IsWide(value);
            int  WideDataLen  = 0;

            byte[] ByteStr = null;
            if (!IsCompressed)
            {
                ByteStr     = Encoding.Unicode.GetBytes(value);
                WideDataLen = 4 + 2 + ByteStr.Length;
            }

            NewPos += 2 + 4 + value.Length + 1 + 24 + 4 + WideDataLen;
            if (DataStream == null)
            {
                return;
            }


            DataStream.Write16((UInt16)(i / 3));

            DataStream.Write32((UInt32)(value.Length + 1));

            byte[] NewData = new byte[value.Length + 1];
            StrOps.CompressBestUnicode(value, NewData, 0);

            DataStream.Write(NewData, NewData.Length);


            DataStream.Write32(0xDEADFFFF);
            NewData = new byte[20];
            DataStream.Write(NewData, NewData.Length);

            if (IsCompressed)
            {
                DataStream.Write32(0);
                return;
            }
            else
            {
                DataStream.Write32((UInt32)(4 + 2 + ByteStr.Length));
            }

            DataStream.Write32((UInt32)ByteStr.Length);
            DataStream.Write16(0x0003);

            DataStream.Write(ByteStr, ByteStr.Length);
        }
예제 #2
0
        private void WriteString(IDataStream DataStream, string value, ref int NewPos, int ByteSize)
        {
            if (value == null || value.Length == 0)
            {
                return;
            }
            byte[] ByteStr = Encoding.Unicode.GetBytes(value);

            if (DataStream != null)
            {
                DataStream.Write32((UInt32)((ByteStr.Length + 2) / ByteSize));
            }
            NewPos += 4;

            if (DataStream != null)
            {
                DataStream.Write(ByteStr, ByteStr.Length);
            }
            NewPos += ByteStr.Length;

            if (DataStream != null)
            {
                DataStream.Write16(0);
            }
            NewPos += 2;
        }
예제 #3
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     base.SaveToStream(Workbook, SaveData, Row);
     byte[] b = new byte[2];
     b[0] = BoolErr;
     b[1] = ErrFlag;
     Workbook.Write(b, 2);
 }
예제 #4
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     Workbook.WriteHeader((UInt16)Id, (UInt16)Data.Length);
     byte[] Pos = new byte[4];
     Array.Copy(Data, 0, Pos, 0, 4);
     Workbook.WriteRaw(Pos, Pos.Length);
     Workbook.Write(Data, 4, Data.Length - 4);
 }
예제 #5
0
        internal void WriteToDataStream(IDataStream s)
        {
            s.WriteByte(adapterIndex);
            s.WriteByte(outputIndex);

            byte[] strData = Encoding.UTF8.GetBytes(adapterName);
            s.WriteUInt16((ushort)strData.Length);
            s.Write(strData, 0, strData.Length);

            strData = Encoding.UTF8.GetBytes(outputName);
            s.WriteUInt16((ushort)strData.Length);
            s.Write(strData, 0, strData.Length);

            s.WriteInt16(X);
            s.WriteInt16(Y);
            s.WriteUInt16(Width);
            s.WriteUInt16(Height);
        }
예제 #6
0
파일: UXlsNotes.cs 프로젝트: mwilian/demos
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            base.SaveToStream(Workbook, SaveData, Row);
            Workbook.Write16(OptionFlags);
            Workbook.Write16(ObjId);

            byte[] bAuthor = Biff8Author();
            Workbook.Write(bAuthor, bAuthor.Length);
        }
예제 #7
0
 internal override void SaveFirstMul(IDataStream Workbook, TSaveData SaveData, int Row, int JoinedRecordSize)
 {
     unchecked
     {
         Workbook.WriteHeader((UInt16)xlr.MULRK, (UInt16)(JoinedRecordSize - XlsConsts.SizeOfTRecordHeader));
         Workbook.Write32((UInt32)((UInt16)Row + (((UInt16)Col) << 16)));
     }
     Workbook.Write16(SaveData.GetBiff8FromCellXF(XF));
     Workbook.Write(BitConverter.GetBytes((Int32)RK), 4);
 }
예제 #8
0
        /// <summary>
        /// Writes the DirtyImageFragment to the data stream in compressed format.
        /// </summary>
        /// <param name="s">The stream to write the frame to.</param>
        /// <param name="compressor">A TJCompressor instance that is preconfigured with quality and subsampling options.  Can be null if the image is already compressed.</param>
        /// <param name="compressToBuffer">The buffer to compress to, not used if the image is already compressed.</param>
        public void WriteToDataStream(IDataStream s, TJCompressor compressor, ref byte[] compressToBuffer)
        {
            s.WriteInt16((short)bounds.X);
            s.WriteInt16((short)bounds.Y);
            s.WriteUInt16((ushort)bounds.Width);
            s.WriteUInt16((ushort)bounds.Height);

            if (screenshot.BufferIsCompressed)
            {
                s.WriteInt32(screenshot.Buffer.Length);                  // Write length of image
                s.Write(screenshot.Buffer, 0, screenshot.Buffer.Length); // Write image
            }
            else
            {
                turbojpegCLI.PixelFormat pixelFormat = screenshot.BitsPerPixel == 24 ? turbojpegCLI.PixelFormat.BGR : turbojpegCLI.PixelFormat.BGRX;
                compressor.setSourceImage(screenshot.Buffer, 0, 0, screenshot.Width, screenshot.Stride, screenshot.Height, pixelFormat);
                compressor.compress(ref compressToBuffer, turbojpegCLI.Flag.NONE);
                int compressedSize = compressor.getCompressedSize();
                s.WriteInt32(compressedSize);                 // Write length of image
                s.Write(compressToBuffer, 0, compressedSize); // Write image
            }
        }
예제 #9
0
파일: USST.cs 프로젝트: mwilian/demos
 private static void AddContinue(IDataStream DataStream, byte[] Buffer, ref int BufferPos, ref long BeginRecordPos, ref long TotalSize)
 {
     if (DataStream != null)
     {
         Array.Copy(BitConverter.GetBytes((UInt16)(BufferPos - 4)), 0, Buffer, 2, 2);                 //Adapt the record size before writing it.
         DataStream.WriteHeader((UInt16)(Buffer[0] + (Buffer[1] << 8)), (UInt16)(Buffer[2] + (Buffer[3] << 8)));
         DataStream.Write(Buffer, 4, BufferPos - 4);
         BeginRecordPos = DataStream.Position;
         Array.Copy(BitConverter.GetBytes((UInt16)xlr.CONTINUE), 0, Buffer, 0, 2);
         Buffer[4] = 0; Buffer[5] = 0;             //Clear the OptionFlags.
     }
     TotalSize += BufferPos;
     BufferPos  = 4;
 }
예제 #10
0
        private void SaveToStreamExt(IDataStream DataStream, TSaveData SaveData, int FirstRecord, int RecordCount)
        {
            if (RecordCount > 0)
            {
                Sort(); //just in case...
                int MyRecordCount = RecordCount;

                DataStream.WriteHeader((UInt16)RecordId, (UInt16)(2 + RecordCount * TPageBreak.Biff8Length));
                DataStream.Write16((UInt16)MyRecordCount);
                for (int i = FirstRecord; i < FirstRecord + RecordCount; i++)
                {
                    DataStream.Write(FList[i].Biff8Data(), TPageBreak.Biff8Length);
                }
            }
        }
예제 #11
0
        internal static void SaveToStream(TNameRecordList Names, IDataStream Workbook, TFormulaType FmlaType, TParsedTokenList Data, bool WriteLen)
        {
            if (Data.TextLenght > FlxConsts.Max_FormulaLen97_2003)
            {
                FlxMessages.ThrowException(FlxErr.ErrFormulaTooLong, TFormulaConvertInternalToText.AsString(Data, 0, 0, null));
            }
            int FmlaNoArrayLen;

            byte[] bData = TFormulaConvertInternalToBiff8.GetTokenData(Names, Data, FmlaType, out FmlaNoArrayLen);
            if (WriteLen)
            {
                Workbook.Write16((UInt16)FmlaNoArrayLen);
            }
            Workbook.Write(bData, bData.Length);
        }
예제 #12
0
파일: USST.cs 프로젝트: mwilian/demos
        internal void SaveToStream(IDataStream DataStream, TSaveData SaveData)
        {
            long BeginRecordPos = DataStream.Position;

            byte[] Buffer = new byte[XlsConsts.MaxRecordDataSize + 4];
            Array.Copy(BitConverter.GetBytes((UInt16)xlr.SST), 0, Buffer, 0, 2);

            bool   Repeatable = SaveData.Repeatable;
            UInt32 TotalRefs;
            IEnumerator <KeyValuePair <TSSTEntry, TSSTEntry> > myEnumerator;

            TSSTEntry[] SortedEntries;
            PrepareToSave(Repeatable, out TotalRefs, out myEnumerator, out SortedEntries);

            Array.Copy(BitConverter.GetBytes(TotalRefs), 0, Buffer, 4, 4);
            Array.Copy(BitConverter.GetBytes((UInt32)Data.Count), 0, Buffer, 8, 4);

            int  BufferPos = 4 + 8;
            long TotalSize = 0;

            if (Repeatable)
            {
                //REPEATABLEWRITES
                foreach (TSSTEntry Se in SortedEntries)
                {
                    Se.SaveToStream(DataStream, Buffer, ref BufferPos, ref BeginRecordPos, ref TotalSize);
                }
            }
            else
            {
                myEnumerator.Reset();
                while (myEnumerator.MoveNext())
                {
                    myEnumerator.Current.Key.SaveToStream(DataStream, Buffer, ref BufferPos, ref BeginRecordPos, ref TotalSize);
                }
            }

            //Flush the buffer.
            Array.Copy(BitConverter.GetBytes((UInt16)(BufferPos - 4)), 0, Buffer, 2, 2);  //Adapt the record size before writing it.
            DataStream.WriteHeader((UInt16)(Buffer[0] + (Buffer[1] << 8)), (UInt16)(Buffer[2] + (Buffer[3] << 8)));
            DataStream.Write(Buffer, 4, BufferPos - 4);
            TotalSize += BufferPos;


            WriteExtSST(DataStream, Repeatable);
        }
예제 #13
0
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            if (FText == null || FText.Length == 0)
            {
                return;
            }

            byte[] b = Encoding.Unicode.GetBytes(TrimmedText);

            Workbook.WriteHeader((UInt16)Id, (UInt16)(b.Length + 12));
            Workbook.Write16(0x0800); //record id
            Workbook.WriteRow(FirstRow);
            Workbook.WriteRow(LastRow);
            Workbook.WriteCol(FirstCol);
            Workbook.WriteCol(LastCol);

            Workbook.Write(b, b.Length);
            Workbook.Write16(0); //null terminated.
        }
예제 #14
0
        internal void SaveToStream(IDataStream DataStream, TSaveData SaveData, byte PanePos)
        {
            if (SelectedCells == null || SelectedCells.Length == 0)
            {
                return;
            }

            if ((SaveData.ExcludedRecords & TExcludedRecords.CellSelection) != 0)
            {
                return;                                                                   //Note that this will invalidate the size, but it doesnt matter as this is not saved for real use. We could write blanks here if we wanted to keep the offsets right.
            }
            byte[] ppos = new byte[1]; ppos[0] = PanePos;

            int CurrentPos = 0;

            do
            {
                int    OldPos     = CurrentPos;
                UInt16 RecordSize = ActualRecordSize(ref CurrentPos);
                DataStream.WriteHeader((UInt16)xlr.SELECTION, (UInt16)(RecordSize - XlsConsts.SizeOfTRecordHeader));
                DataStream.Write(ppos, ppos.Length);

                DataStream.WriteRow(ActiveRow);
                DataStream.WriteCol(ActiveCol);

                DataStream.Write16((UInt16)ActiveSel);

                int len = CurrentPos - OldPos;
                DataStream.Write16((UInt16)len);

                unchecked
                {
                    for (int i = 0; i < len; i++)
                    {
                        DataStream.WriteRow(SelectedCells[i].Top);
                        DataStream.WriteRow(SelectedCells[i].Bottom);
                        DataStream.WriteColByte(SelectedCells[i].Left);
                        DataStream.WriteColByte(SelectedCells[i].Right);
                    }
                }
            }while (CurrentPos < SelectedCells.Length);
        }
예제 #15
0
파일: USST.cs 프로젝트: mwilian/demos
        //We don't implement writing value to a label, as it is deprecated. All writing should go to a LabelSST

        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            base.SaveToStream(Workbook, SaveData, Row);
            Workbook.Write(Data, 6, Data.Length - 6);
        }
예제 #16
0
 internal override void SaveLastMul(IDataStream Workbook, TSaveData SaveData)
 {
     Workbook.Write16(SaveData.GetBiff8FromCellXF(XF));
     Workbook.Write(BitConverter.GetBytes((Int32)RK), 4);
     Workbook.Write16((UInt16)Col);
 }
예제 #17
0
        internal void SaveBiff8Data(IDataStream DataStream, bool SaveCoords, out int Len)
        {
            if (DataStream != null)
            {
                if (SaveCoords)
                {
                    DataStream.WriteRow(FirstRow);
                    DataStream.WriteRow(LastRow);
                    DataStream.WriteCol(FirstCol);
                    DataStream.WriteCol(LastCol);
                }

                //CLSID
                DataStream.Write32(0x79EAC9D0);
                DataStream.Write32(0x11CEBAF9);
                DataStream.Write32(0xAA00828C);
                DataStream.Write32(0x0BA94B00);

                //Starts HyperLink Object - MS-OSHARED
                DataStream.Write32(0x02);
                DataStream.Write32(OptionFlags);
            }

            Len = 32;

            WriteString(DataStream, FDescription, ref Len);
            WriteString(DataStream, FTargetFrame, ref Len);

            //This part of the structure is different depending on the type of link.
            switch (FLinkType)
            {
            case THyperLinkType.URL:
                if (DataStream != null)
                {
                    DataStream.Write(URLGUID, URLGUID.Length);
                }
                Len += URLGUID.Length;
                WriteString(DataStream, FText, ref Len, 1);
                break;

            case THyperLinkType.LocalFile:
                if (DataStream != null)
                {
                    DataStream.Write(FILEGUID, FILEGUID.Length);
                }
                Len += FILEGUID.Length;
                WriteLocalFile(DataStream, FText, ref Len);
                break;

            case THyperLinkType.UNC:
                //String Moniker
                WriteString(DataStream, FText, ref Len);
                break;

            case THyperLinkType.CurrentWorkbook:
                //CurrentWorkbook doesn't have monikers.
                break;

            default:
                XlsMessages.ThrowException(XlsErr.ErrInvalidHyperLinkType, (int)FLinkType);
                break;
            }


            WriteString(DataStream, FTextMark, ref Len);
        }
예제 #18
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     base.SaveToStream(Workbook, SaveData, Row);
     Workbook.Write(BitConverter.GetBytes((Int32)RK), 4);
 }
예제 #19
0
 internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
 {
     base.SaveToStream(Workbook, SaveData, Row);
     Workbook.Write(BitConverter.GetBytes(NumValue), 8);
 }
예제 #20
0
 public static void StoreData(IDataStream dataStream)
 {
     dataStream.Write(Data);
 }
예제 #21
0
        public void Write(string data)
        {
            var compressedData = Compress(data);

            _dataStream.Write(compressedData);
        }
예제 #22
0
        internal override void SaveToStream(IDataStream Workbook, TSaveData SaveData, int Row)
        {
            Workbook.WriteHeader((UInt16)Id, (UInt16)TotalSizeNoHeaders());

            Workbook.Write16((UInt16)Id); //FrtHeader
            Workbook.Write(new byte[10], 10);

            Workbook.Write32((UInt32)TotalSizeNoHeaders());


            int ic = SheetColor.GetBiff8ColorIndex(SaveData.Palette, TAutomaticColor.SheetTab);

            if (ic < 0x08 || ic > 0x3f)
            {
                ic = 0x7f;
            }
            Workbook.Write32((UInt32)ic);

            UInt32 ic2 = (UInt32)ic;

            if (CondFmtCalc)
            {
                ic2 |= 0x80;
            }
            if (NotPublished)
            {
                ic2 |= 0x100;
            }
            Workbook.Write32(ic2);

            switch (SheetColor.ColorType)
            {
            case TColorType.RGB:
                Workbook.Write32(0x02);
                UInt32 RGB = (UInt32)(SheetColor.RGB);
                UInt32 BGR = 0xFF000000 | (RGB & 0x00FF00) | ((RGB & 0xFF0000) >> 16) | ((RGB & 0x0000FF) << 16);

                Workbook.Write32(BGR);
                break;

            case TColorType.Automatic:
                Workbook.Write32(0x00);
                Workbook.Write32(0x00);
                break;

            case TColorType.Theme:
                Workbook.Write32(0x03);
                Workbook.Write32((UInt32)SheetColor.Theme);
                break;

            case TColorType.Indexed:
                Workbook.Write32(0x01);
                Workbook.Write32((UInt32)ic);
                break;

            default:
                XlsMessages.ThrowException(XlsErr.ErrExcelInvalid);
                break;
            }

            Workbook.Write(BitConverter.GetBytes(SheetColor.Tint), 8);
        }
예제 #23
0
        public void Write(string data)
        {
            var encryptedData = Encrypt(data);

            _dataStream.Write(encryptedData);
        }