Пример #1
0
 /// <summary>
 /// Creates a new RichTextColorizer instance.
 /// </summary>
 public RichTextColorizer(RichTextModel richTextModel)
 {
     if (richTextModel == null)
     {
         throw new ArgumentNullException("richTextModel");
     }
     this.richTextModel = richTextModel;
 }
Пример #2
0
		/// <summary>
		/// Creates a new RichTextModelWriter that inserts into document, starting at insertionOffset.
		/// </summary>
		public RichTextModelWriter(RichTextModel richTextModel, IDocument document, int insertionOffset)
			: base(new DocumentTextWriter(document, insertionOffset))
		{
			if (richTextModel == null)
				throw new ArgumentNullException("richTextModel");
			this.richTextModel = richTextModel;
			this.documentTextWriter = (DocumentTextWriter)base.textWriter;
			currentColor = richTextModel.GetHighlightingAt(Math.Max(0, insertionOffset - 1));
		}
Пример #3
0
        /// <summary>
        /// Creates a <see cref="RichTextModel"/> that stores the highlighting of this line.
        /// </summary>
        public RichTextModel ToRichTextModel()
        {
            var builder     = new RichTextModel();
            int startOffset = DocumentLine.Offset;

            foreach (HighlightedSection section in Sections)
            {
                builder.ApplyHighlighting(section.Offset - startOffset, section.Length, section.Color);
            }
            return(builder);
        }
Пример #4
0
 /// <summary>
 /// Creates a new RichTextModelWriter that inserts into document, starting at insertionOffset.
 /// </summary>
 public RichTextModelWriter(RichTextModel richTextModel, IDocument document, int insertionOffset)
     : base(new DocumentTextWriter(document, insertionOffset))
 {
     if (richTextModel == null)
     {
         throw new ArgumentNullException("richTextModel");
     }
     this.richTextModel      = richTextModel;
     this.documentTextWriter = (DocumentTextWriter)base.textWriter;
     currentColor            = richTextModel.GetHighlightingAt(Math.Max(0, insertionOffset - 1));
 }
Пример #5
0
		void GenerateHeader()
		{
			CSharpAmbience ambience = new CSharpAmbience();
			ambience.ConversionFlags = ConversionFlags.StandardConversionFlags;
			var stringBuilder = new StringBuilder();
			var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex);
			ambience.ConvertEntity(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop());
			string code = stringBuilder.ToString();
			var inlineBuilder = new RichTextModel();
			inlineBuilder.SetFontWeight(formatter.parameterStartOffset, formatter.parameterLength, FontWeights.Bold);
			header.Inlines.Clear();
			header.Inlines.AddRange(new RichText(code, inlineBuilder).CreateRuns());
		}
Пример #6
0
        /// <summary>
        /// Creates a substring of this rich text.
        /// </summary>
        public RichText Substring(int offset, int length)
        {
            if (offset == 0 && length == this.Length)
            {
                return(this);
            }
            string          newText = text.Substring(offset, length);
            RichTextModel   model   = ToRichTextModel();
            OffsetChangeMap map     = new OffsetChangeMap(2);

            map.Add(new OffsetChangeMapEntry(offset + length, text.Length - offset - length, 0));
            map.Add(new OffsetChangeMapEntry(0, offset, 0));
            model.UpdateOffsets(map);
            return(new RichText(newText, model));
        }
Пример #7
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 };
			}
		}
Пример #8
0
        /// <summary>
        /// Concatenates the specified rich texts.
        /// </summary>
        public static RichText Concat(params RichText[] texts)
        {
            if (texts == null || texts.Length == 0)
            {
                return(Empty);
            }
            else if (texts.Length == 1)
            {
                return(texts[0]);
            }
            string        newText = string.Concat(texts.Select(txt => txt.text));
            RichTextModel model   = texts[0].ToRichTextModel();
            int           offset  = texts[0].Length;

            for (int i = 1; i < texts.Length; i++)
            {
                model.Append(offset, texts[i].stateChangeOffsets, texts[i].stateChanges);
                offset += texts[i].Length;
            }
            return(new RichText(newText, model));
        }
Пример #9
0
        public void ConcatTest()
        {
            var textModel = new RichTextModel();

            textModel.SetHighlighting(0, 5, new HighlightingColor {
                Name = "text1"
            });
            var text1 = new RichText("text1", textModel);

            var textModel2 = new RichTextModel();

            textModel2.SetHighlighting(0, 5, new HighlightingColor {
                Name = "text2"
            });
            var text2 = new RichText("text2", textModel2);

            RichText text3 = RichText.Concat(text1, RichText.Empty, text2);

            Assert.AreEqual(text1.GetHighlightingAt(0), text3.GetHighlightingAt(0));
            Assert.AreNotEqual(text1.GetHighlightingAt(0), text3.GetHighlightingAt(5));
            Assert.AreEqual(text2.GetHighlightingAt(0), text3.GetHighlightingAt(5));
        }
Пример #10
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 };
     }
 }
Пример #11
0
		/// <summary>
		/// Creates a new RichTextColorizer instance.
		/// </summary>
		public RichTextColorizer(RichTextModel richTextModel)
		{
			if (richTextModel == null)
				throw new ArgumentNullException("richTextModel");
			this.richTextModel = richTextModel;
		}