Example #1
0
        private List <string> GetSplittedString()
        {
            if (!ContentText.ToLower().Contains(HighlightText.ToLower()))
            {
                return new List <string>()
                       {
                           ContentText
                       }
            }
            ;

            int           startIndex    = ContentText.IndexOf(HighlightText, StringComparison.OrdinalIgnoreCase);
            List <string> splittedTexts = new List <string>();
            string        matchedText   = ContentText.Substring(startIndex, HighlightText.Length);
            string        startText     = startIndex > 0 ? ContentText.Substring(0, startIndex) : string.Empty;
            string        lastText      = ContentText.Substring(startIndex + HighlightText.Length);

            if (!string.IsNullOrEmpty(startText))
            {
                splittedTexts.Add(startText);
            }

            if (!string.IsNullOrEmpty(matchedText))
            {
                splittedTexts.Add(matchedText);
            }

            if (!string.IsNullOrEmpty(lastText))
            {
                splittedTexts.Add(lastText);
            }

            return(splittedTexts);
        }
    }
Example #2
0
 private void Start()
 {
     highlightText = gameObject.AddComponent <HighlightText>();
     highlightAudioButtons[0].interactable = true;
 }
Example #3
0
        // rendering
        protected override void OnRender(DrawingContext drawingContext)
        {
            // draw background
            drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight)));
            drawingContext.DrawRectangle(BackgroundBrush, new Pen(), new Rect(0, 0, ActualWidth, ActualHeight));

            // draw text
            if (Text == string.Empty)
            {
                return;
            }
            var formattedText = new FormattedText(
                Text,
                System.Globalization.CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface(FontFamily.Source),
                FontSize, ForegroundBrush);

            var leftMargin = 4.0 + BorderThickness.Left + LineNumberMarginWidth;
            var topMargin  = 2.0 + BorderThickness.Top;

            // Background highlight
            if (HighlightText != null && HighlightText.Any())
            {
                foreach (string text in HighlightText)
                {
                    var index     = 0;
                    var lastIndex = Text.LastIndexOf(text, StringComparison.OrdinalIgnoreCase);

                    while (index <= lastIndex)
                    {
                        index = Text.IndexOf(text, index, StringComparison.OrdinalIgnoreCase);

                        Geometry geom = formattedText.BuildHighlightGeometry(new Point(leftMargin, topMargin - VerticalOffset), index, text.Length);
                        if (geom != null)
                        {
                            drawingContext.DrawGeometry(HighlightBrush, null, geom);
                        }
                        index += 1;
                    }
                }
            }

            HighlightSyntax(formattedText);

            // left from first char boundary

            var leftBorder = GetRectFromCharacterIndex(0).Left;

            if (!double.IsInfinity(leftBorder))
            {
                _leftTextBorder = leftBorder;
            }

            drawingContext.DrawText(formattedText, new Point(_leftTextBorder - HorizontalOffset, topMargin - VerticalOffset));


            // draw lines
            if (GetLastVisibleLineIndex() != -1)
            {
                LastLineNumberFormat = GetLineNumbers();
            }
            if (LastLineNumberFormat != null)
            {
                LastLineNumberFormat.SetForegroundBrush(LineNumberBrush);
                drawingContext.DrawText(LastLineNumberFormat, new Point(3, topMargin));
            }
        }