/// <summary> /// Returns the font in use at a particular index. /// </summary> /// <param name="index">The index.</param> /// <returns>The font that's currently being applied at that /// index or null if no font Is being applied or the /// index Is out of range.</returns> public short GetFontAtIndex(int index) { int size = _string.FormatRunCount; UnicodeString.FormatRun currentRun = null; for (int i = 0; i < size; i++) { UnicodeString.FormatRun r = _string.GetFormatRun(i); if (r.CharacterPos > index) { break; } else { currentRun = r; } } if (currentRun == null) { return(NO_FONT); } else { return(currentRun.FontIndex); } }
public void TestFormatRun() { UnicodeString.FormatRun fr = new UnicodeString.FormatRun((short)4, (short)0x15c); Assert.AreEqual(4, fr.CharacterPos); Assert.AreEqual(0x15c, fr.FontIndex); MemoryStream baos = new MemoryStream(); LittleEndianOutputStream out1 = new LittleEndianOutputStream(baos); fr.Serialize(out1); byte[] b = baos.ToArray(); Assert.AreEqual(4, b.Length); Assert.AreEqual(4, b[0]); Assert.AreEqual(0, b[1]); Assert.AreEqual(0x5c, b[2]); Assert.AreEqual(0x01, b[3]); LittleEndianInputStream inp = new LittleEndianInputStream( new MemoryStream(b) ); fr = new UnicodeString.FormatRun(inp); Assert.AreEqual(4, fr.CharacterPos); Assert.AreEqual(0x15c, fr.FontIndex); }
/// <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(); }
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); }
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); }
/// <summary> /// Gets the font used in a particular formatting run. /// </summary> /// <param name="index">the index of the formatting run.</param> /// <returns>the font number used.</returns> public short GetFontOfFormattingRun(int index) { UnicodeString.FormatRun r = _string.GetFormatRun(index); return(r.FontIndex); }
/// <summary> /// The index within the string to which the specified formatting run applies. /// </summary> /// <param name="index">the index of the formatting run</param> /// <returns>the index within the string.</returns> public int GetIndexOfFormattingRun(int index) { UnicodeString.FormatRun r = _string.GetFormatRun(index); return(r.CharacterPos); }