Пример #1
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));
        }
        protected override object CreateText()
        {
            var location = anchor.Location;

            LoggingService.Debug("Creating text for search result (" + location.Line + ", " + location.Column + ") ");

            TextBlock textBlock = new TextBlock();

            textBlock.FontFamily = new FontFamily(SD.EditorControlService.GlobalOptions.FontFamily);
            if (result.DefaultTextColor != null && !IsSelected)
            {
                if (result.DefaultTextColor.Background != null)
                {
                    textBlock.Background = result.DefaultTextColor.Background.GetBrush(null);
                }
                if (result.DefaultTextColor.Foreground != null)
                {
                    textBlock.Foreground = result.DefaultTextColor.Foreground.GetBrush(null);
                }
            }

            textBlock.Inlines.Add("(" + location.Line + ", " + location.Column + ")\t");

            RichText displayText = result.DisplayText;

            if (displayText != null)
            {
                if (IsSelected)
                {
                    RichTextModel model = displayText.ToRichTextModel();
                    model.SetForeground(0, displayText.Length, null);
                    model.SetBackground(0, displayText.Length, null);
                    displayText = new RichText(displayText.Text, model);
                }
                textBlock.Inlines.AddRange(displayText.CreateRuns());
            }

            if (showFileName)
            {
                textBlock.Inlines.Add(
                    new Run {
                    Text = StringParser.Parse("\t${res:MainWindow.Windows.SearchResultPanel.In} ")
                           + Path.GetFileName(anchor.FileName) + "(" + Path.GetDirectoryName(anchor.FileName) + ")",
                    FontStyle = FontStyles.Italic
                });
            }
            return(textBlock);
        }
Пример #3
0
        public void AddSignatureBlock(string signature, RichTextModel highlighting = null)
        {
            var document = new TextDocument(signature);
            var richText = highlighting ?? DocumentPrinter.ConvertTextDocumentToRichText(document, new DocumentHighlighter(document, highlightingDefinition)).ToRichTextModel();
            var block    = new Paragraph();
            // HACK: measure width of signature using a TextBlock
            // Paragraph sadly does not support TextWrapping.NoWrap
            var text = new TextBlock {
                FontFamily    = GetCodeFont(),
                FontSize      = DisplaySettingsPanel.CurrentDisplaySettings.SelectedFontSize,
                TextAlignment = TextAlignment.Left
            };

            text.Inlines.AddRange(richText.CreateRuns(document));
            text.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            this.document.MinPageWidth = Math.Min(text.DesiredSize.Width, MainWindow.Instance.ActualWidth);
            block.Inlines.AddRange(richText.CreateRuns(document));
            block.FontFamily    = GetCodeFont();
            block.TextAlignment = TextAlignment.Left;
            AddBlock(block);
        }
Пример #4
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));
        }
Пример #5
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 };
     }
 }