Example #1
0
        /// <summary>
        /// Applies a font to the specified Chars of a string.
        /// </summary>
        /// <param name="startIndex">The start index to apply the font to (inclusive).</param>
        /// <param name="endIndex">The end index to apply the font to (exclusive).</param>
        /// <param name="fontIndex">The font to use.</param>
        public void ApplyFont(int startIndex, int endIndex, short fontIndex)
        {
            if (startIndex > endIndex)
            {
                throw new ArgumentException("Start index must be less than end index.");
            }
            if (startIndex < 0 || endIndex > Length)
            {
                throw new ArgumentException("Start and end index not in range.");
            }
            if (startIndex == endIndex)
            {
                return;
            }

            //Need to Check what the font Is currently, so we can reapply it after
            //the range Is completed
            short currentFont = NO_FONT;

            if (endIndex != Length)
            {
                currentFont = this.GetFontAtIndex(endIndex);
            }

            //Need to clear the current formatting between the startIndex and endIndex
            _string = CloneStringIfRequired();
            System.Collections.Generic.List <UnicodeString.FormatRun> formatting = _string.FormatIterator();

            ArrayList deletedFR = new ArrayList();

            if (formatting != null)
            {
                IEnumerator formats = formatting.GetEnumerator();
                while (formats.MoveNext())
                {
                    UnicodeString.FormatRun r = (UnicodeString.FormatRun)formats.Current;
                    if ((r.CharacterPos >= startIndex) && (r.CharacterPos < endIndex))
                    {
                        deletedFR.Add(r);
                    }
                }
            }
            foreach (UnicodeString.FormatRun fr in deletedFR)
            {
                _string.RemoveFormatRun(fr);
            }

            _string.AddFormatRun(new UnicodeString.FormatRun((short)startIndex, fontIndex));
            if (endIndex != Length)
            {
                _string.AddFormatRun(new UnicodeString.FormatRun((short)endIndex, currentFont));
            }

            AddToSSTIfRequired();
        }
Example #2
0
        public void TestSmallStringSize()
        {
            //Test a basic string
            UnicodeString s = MakeUnicodeString("Test");

            ConfirmSize(7, s);

            //Test a small string that is uncompressed
            s             = MakeUnicodeString(STR_16_BIT);
            s.OptionFlags = (/*setter*/ (byte)0x01);
            ConfirmSize(11, s);

            //Test a compressed small string that has rich text formatting
            s.String      = (/*setter*/ "Test");
            s.OptionFlags = (/*setter*/ (byte)0x8);
            UnicodeString.FormatRun r = new UnicodeString.FormatRun((short)0, (short)1);
            s.AddFormatRun(r);
            UnicodeString.FormatRun r2 = new UnicodeString.FormatRun((short)2, (short)2);
            s.AddFormatRun(r2);
            ConfirmSize(17, s);

            //Test a uncompressed small string that has rich text formatting
            s.String      = (/*setter*/ STR_16_BIT);
            s.OptionFlags = (/*setter*/ (byte)0x9);
            ConfirmSize(21, s);

            //Test a compressed small string that has rich text and extended text
            s.String      = (/*setter*/ "Test");
            s.OptionFlags = (/*setter*/ (byte)0xC);
            ConfirmSize(17, s);

            // Extended phonetics data
            // Minimum size is 14
            // Also Adds 4 bytes to hold the length
            s.ExtendedRst = (
                new UnicodeString.ExtRst()
                );
            ConfirmSize(35, s);

            //Test a uncompressed small string that has rich text and extended text
            s.String      = (/*setter*/ STR_16_BIT);
            s.OptionFlags = (/*setter*/ (byte)0xD);
            ConfirmSize(39, s);

            s.ExtendedRst = (/*setter*/ null);
            ConfirmSize(21, s);
        }
Example #3
0
        public void TestPerfectRichStringSize()
        {
            //Test a rich text string
            UnicodeString s = MakeUnicodeString(MAX_DATA_SIZE - 2 - 1 - 8 - 2);

            s.AddFormatRun(new UnicodeString.FormatRun((short)1, (short)0));
            s.AddFormatRun(new UnicodeString.FormatRun((short)2, (short)1));
            s.OptionFlags = ((byte)0x8);
            ConfirmSize(MAX_DATA_SIZE, s);

            //Test an uncompressed rich text string
            //Note that we can only ever Get to a maximim size of 8227 since an uncompressed
            //string is1 writing double bytes.
            s = MakeUnicodeString((MAX_DATA_SIZE - 2 - 1 - 8 - 2) / 2, true);
            s.AddFormatRun(new UnicodeString.FormatRun((short)1, (short)0));
            s.AddFormatRun(new UnicodeString.FormatRun((short)2, (short)1));
            s.OptionFlags = ((byte)0x9);
            ConfirmSize(MAX_DATA_SIZE - 1, s);
        }
Example #4
0
        public void TestSmallStringSize()
        {
            //Test a basic string
            UnicodeString s = MakeUnicodeString("Test");

            ConfirmSize(7, s);

            //Test a small string that is uncompressed
            s             = MakeUnicodeString(STR_16_BIT);
            s.OptionFlags = ((byte)0x01);
            ConfirmSize(11, s);

            //Test a compressed small string that has rich text formatting
            s.String      = "Test";
            s.OptionFlags = ((byte)0x8);
            FormatRun r = new FormatRun((short)0, (short)1);

            s.AddFormatRun(r);
            FormatRun r2 = new FormatRun((short)2, (short)2);

            s.AddFormatRun(r2);
            ConfirmSize(17, s);

            //Test a uncompressed small string that has rich text formatting
            s.String      = STR_16_BIT;
            s.OptionFlags = ((byte)0x9);
            ConfirmSize(21, s);

            //Test a compressed small string that has rich text and extended text
            s.String      = "Test";
            s.OptionFlags = ((byte)0xC);
            s.SetExtendedRst(new byte[] { (byte)0x1, (byte)0x2, (byte)0x3, (byte)0x4, (byte)0x5 });
            ConfirmSize(26, s);

            //Test a uncompressed small string that has rich text and extended text
            s.String      = STR_16_BIT;
            s.OptionFlags = ((byte)0xD);
            ConfirmSize(30, s);
        }