Beispiel #1
0
        public string ReadString(int lengthbits, out RichTextFormat rtf)
        {
            /* BEGIN - SAME AS ReadString() */
            if (reader.BaseStream.Position == reader.BaseStream.Length)
            {
                if (ContinuedIndex < record.ContinuedRecords.Count - 1)
                {
                    SwitchToContinuedRecord();
                }
                else
                {
                    rtf = null;
                    return(null);
                }
            }

            int  stringlength = lengthbits == 8 ? reader.ReadByte() : reader.ReadUInt16();
            byte option       = reader.ReadByte();
            bool compressed   = (option & 0x01) == 0;
            bool phonetic     = (option & 0x04) == 0x04;
            bool richtext     = (option & 0x08) == 0x08;
            int  runs         = 0; //Number of Rich-Text formatting runs
            int  size         = 0; //Size of Asian phonetic settings block in bytes

            if (richtext)
            {
                runs = reader.ReadUInt16();
            }
            if (phonetic)
            {
                size = reader.ReadInt32();
            }

            string        firstpart = ReadString(stringlength, compressed);
            StringBuilder text      = new StringBuilder();

            text.Append(firstpart);
            if (firstpart.Length < stringlength)
            {
                SwitchToContinuedRecord();
                text.Append(ReadContinuedString(stringlength - firstpart.Length));
            }
            /* END - SAME AS ReadString() */

            /*
             * Added, 2-13-2009
             * Sunil Shenoi
             *
             * Process the rich text formatting information as in Section 2.5.3.
             */
            //if ((4 * runs + size) > 100)
            if (stringlength > 2000 || firstpart.Length > 2000 || size > 2000)
            {
                throw new Exception("invalid size of rich text formatting information");
            }
            byte[] richTextBytes = ReadBytes(4 * runs + size);
            rtf = DecodeRichTextFormatting(richTextBytes, runs);

            return(text.ToString());
        }
        public string ReadString(int lengthbits, out RichTextFormat rtf)
        {
            /* BEGIN - SAME AS ReadString() */
            if (reader.BaseStream.Position == reader.BaseStream.Length)
            {
                if (ContinuedIndex < record.ContinuedRecords.Count - 1)
                {
                    SwitchToContinuedRecord();
                }
                else
                {
                    rtf = null;
                    return null;
                }
            }

            int stringlength = lengthbits == 8 ? reader.ReadByte() : reader.ReadUInt16();
            byte option = reader.ReadByte();
            bool compressed = (option & 0x01) == 0;
            bool phonetic = (option & 0x04) == 0x04;
            bool richtext = (option & 0x08) == 0x08;
            int runs = 0; //Number of Rich-Text formatting runs
            int size = 0; //Size of Asian phonetic settings block in bytes
            if (richtext)
            {
                runs = reader.ReadUInt16();
            }
            if (phonetic)
            {
                size = reader.ReadInt32();
            }

            string firstpart = ReadString(stringlength, compressed);
            StringBuilder text = new StringBuilder();
            text.Append(firstpart);
            if (firstpart.Length < stringlength)
            {
                SwitchToContinuedRecord();
                text.Append(ReadContinuedString(stringlength - firstpart.Length));
            }
            /* END - SAME AS ReadString() */

            /*
             * Added, 2-13-2009
             * Sunil Shenoi
             *
             * Process the rich text formatting information as in Section 2.5.3.
             */
            //if ((4 * runs + size) > 100)
            if (stringlength > 2000 || firstpart.Length > 2000 || size > 2000)
            {
                throw new Exception("invalid size of rich text formatting information");
            }
            byte[] richTextBytes = ReadBytes(4 * runs + size);
            rtf = DecodeRichTextFormatting(richTextBytes, runs);

            return text.ToString();
        }
Beispiel #3
0
        /*
         * Added, 2-13-2009
         * Sunil Shenoi
         *
         * Decode the rich text formatting information associated with a given string.
         */
        private RichTextFormat DecodeRichTextFormatting(byte[] richTextBytes, int runs)
        {
            RichTextFormat rtf = new RichTextFormat(runs);

            // process the byte array into pairs of UInt16's
            for (int i = 0; i < runs; i++)
            {
                rtf.CharIndexes.Add(BitConverter.ToUInt16(richTextBytes, (i * 4)));
                rtf.FontIndexes.Add(BitConverter.ToUInt16(richTextBytes, (i * 4) + 2));
            }

            return(rtf);
        }
        private RichTextFormat DecodeRichTextFormatting(byte[] richTextBytes, int runs)
        {
            RichTextFormat richTextFormat = new RichTextFormat(runs);

            checked
            {
                for (int i = 0; i < runs; i++)
                {
                    richTextFormat.CharIndexes.Add(BitConverter.ToUInt16(richTextBytes, i * 4));
                    richTextFormat.FontIndexes.Add(BitConverter.ToUInt16(richTextBytes, i * 4 + 2));
                }
                return(richTextFormat);
            }
        }
 public string ReadString(int lengthbits, out RichTextFormat rtf)
 {
     checked
     {
         string result;
         if (this.reader.BaseStream.Position == this.reader.BaseStream.Length)
         {
             if (this.ContinuedIndex >= this.record.ContinuedRecords.Count - 1)
             {
                 rtf    = null;
                 result = null;
                 return(result);
             }
             this.SwitchToContinuedRecord();
         }
         int  num        = (int)((lengthbits == 8) ? ((ushort)this.reader.ReadByte()) : this.reader.ReadUInt16());
         byte b          = this.reader.ReadByte();
         bool compressed = (b & 1) == 0;
         bool flag       = (b & 4) == 4;
         bool flag2      = (b & 8) == 8;
         int  num2       = 0;
         int  num3       = 0;
         if (flag2)
         {
             num2 = (int)this.reader.ReadUInt16();
         }
         if (flag)
         {
             num3 = this.reader.ReadInt32();
         }
         string        text          = this.ReadString(num, compressed);
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.Append(text);
         if (text.Length < num)
         {
             this.SwitchToContinuedRecord();
             stringBuilder.Append(this.ReadContinuedString(num - text.Length));
         }
         if (num > 2000 || text.Length > 2000 || num3 > 2000)
         {
             throw new Exception("invalid size of rich text formatting information");
         }
         byte[] richTextBytes = this.ReadBytes(4 * num2 + num3);
         rtf    = this.DecodeRichTextFormatting(richTextBytes, num2);
         result = stringBuilder.ToString();
         return(result);
     }
 }
        /*
         * Added, 2-13-2009
         * Sunil Shenoi
         *
         * Decode the rich text formatting information associated with a given string.
         */
        private RichTextFormat DecodeRichTextFormatting(byte[] richTextBytes, int runs)
        {
            RichTextFormat rtf = new RichTextFormat(runs);

            // process the byte array into pairs of UInt16's
            for (int i = 0; i < runs; i++)
            {
                rtf.CharIndexes.Add(BitConverter.ToUInt16(richTextBytes, (i * 4)));
                rtf.FontIndexes.Add(BitConverter.ToUInt16(richTextBytes, (i * 4) + 2));
            }

            return rtf;
        }