Exemple #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.
             */
            byte[] richTextBytes = ReadBytes(4 * runs + size);
            rtf = DecodeRichTextFormatting(richTextBytes, runs);

            return(text.ToString());
        }
Exemple #2
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);
        }
        /*
         * 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;
        }
        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.
             */
            byte[] richTextBytes = ReadBytes(4 * runs + size);
            rtf = DecodeRichTextFormatting(richTextBytes, runs);

            return text.ToString();
        }