Beispiel #1
0
 /// <summary>
 /// Creates a RichText instance with the given text and RichTextModel.
 /// </summary>
 /// <param name="text">
 /// The text to use in this RichText instance.
 /// </param>
 /// <param name="model">
 /// The model that contains the formatting to use for this RichText instance.
 /// <c>model.DocumentLength</c> should correspond to <c>text.Length</c>.
 /// This parameter may be null, in which case the RichText instance just holds plain text.
 /// </param>
 public RichText(string text, RichTextModel model = null)
 {
     if (text == null)
     {
         throw new ArgumentNullException("text");
     }
     this.text = text;
     if (model != null)
     {
         var sections = model.GetHighlightedSections(0, text.Length).ToArray();
         stateChangeOffsets = new int[sections.Length];
         stateChanges       = new HighlightingColor[sections.Length];
         for (int i = 0; i < sections.Length; i++)
         {
             stateChangeOffsets[i] = sections[i].Offset;
             stateChanges[i]       = sections[i].Color;
         }
     }
     else
     {
         stateChangeOffsets = new int[] { 0 };
         stateChanges       = new HighlightingColor[] { HighlightingColor.Empty };
     }
 }