コード例 #1
0
ファイル: RichTextColorizer.cs プロジェクト: VE-2016/VE-2016
        /// <inheritdoc/>
        protected override void ColorizeLine(DocumentLine line)
        {
            var sections = richTextModel.GetHighlightedSections(line.Offset, line.Length);

            foreach (HighlightedSection section in sections)
            {
                if (HighlightingColorizer.IsEmptyColor(section.Color))
                {
                    continue;
                }
                ChangeLinePart(section.Offset, section.Offset + section.Length,
                               visualLineElement => HighlightingColorizer.ApplyColorToElement(visualLineElement, section.Color, CurrentContext));
            }
        }
コード例 #2
0
ファイル: RichText.cs プロジェクト: Zolniu/DigitalRune
		/// <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 };
			}
		}
コード例 #3
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 };
     }
 }