Example #1
0
        private void RenderWithNoLeftElipsis(DrawingContext dc, PatternMatchResult matchingText, Rect bounds, FormattedText allText, int matchPosRightOffset)
        {
            var highlightBrush = GetHighlightBrush();

            allText.Trimming     = TextTrimming.CharacterEllipsis;
            allText.MaxTextWidth = bounds.Width;
            foreach (var matchPos in matchingText.MatchStarts)
            {
                // The offset position is used when the formatted text does not start at the beginning of the string
                var offsetPos = matchPos - matchPosRightOffset;
                var length    = matchingText.Pattern.Length;
                if (offsetPos < 0)
                {
                    length   -= offsetPos;
                    offsetPos = 0;
                }

                if (length > 0)
                {
                    var geo = allText.BuildHighlightGeometry(bounds.TopLeft, offsetPos, length);
                    dc.DrawGeometry(highlightBrush, null, geo);

                    if (HighlightForegroundBrush != null)
                    {
                        allText.SetForegroundBrush(HighlightForegroundBrush, offsetPos, length);
                    }
                }
            }
            dc.DrawText(allText, bounds.TopLeft);
        }
 protected List <Token> GetMethodBlockTokens(List <Token> tokens, PatternMatchResult methodMatch)
 {
     if (methodMatch.MatchesCount > 2)
     {
         var methodBlockMatch  = methodMatch.GetMatch(2);
         var methodBlockTokens = TokenUtils.GetMatchResultBlockTokens(tokens, methodBlockMatch);
         return(methodBlockTokens);
     }
     throw new ParseException(tokens, methodMatch.Start);
 }
    public bool IsEqual_Op(PatternMatchResult m)
    {
        bool ret = VisionLabPINVOKE.PatternMatchResult_IsEqual_Op(swigCPtr, PatternMatchResult.getCPtr(m));

        if (VisionLabPINVOKE.SWIGPendingException.Pending)
        {
            throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
 protected List <Token> GetMethodSignatureTokens(List <Token> tokens, PatternMatchResult methodMatch)
 {
     if (methodMatch.MatchesCount > 1)
     {
         var methodIdMatch   = methodMatch.GetMatch(0);
         var methodArgsMatch = methodMatch.GetMatch(1);
         var methodSignature = TokenUtils.GetMatchResultTokens(tokens, methodIdMatch);
         methodSignature.AddRange(TokenUtils.GetMatchResultTokens(tokens, methodArgsMatch));
         return(methodSignature);
     }
     throw new ParseException(tokens, methodMatch.Start);
 }
Example #5
0
        protected override void OnRender(DrawingContext dc)
        {
            RenderBackground(dc);

            var sourceText = Text;

            if (String.IsNullOrEmpty(sourceText))
            {
                return;
            }

            Rect bounds;

            if (!TryGetTextRenderBounds(out bounds))
            {
                return;
            }

            var matchingText = new PatternMatchResult(MatchPattern, sourceText, 100);
            var allText      = FormatText(sourceText, bounds.Height);

            if (!matchingText.HasMatches || !HighlightMatches)
            {
                // If not matches or not highlighting matches, render normally
                allText.MaxTextWidth = bounds.Width;
                dc.DrawText(allText, bounds.TopLeft);
                return;
            }

            if (matchingText.MatchesWholeString)
            {
                allText.MaxTextWidth = bounds.Width;
                var geo            = allText.BuildHighlightGeometry(bounds.TopLeft, 0, sourceText.Length);
                var highlightBrush = GetHighlightBrush();
                dc.DrawGeometry(highlightBrush, null, geo);
                dc.DrawText(allText, bounds.TopLeft);
                return;
            }

            if (!UseLeftTrimming || matchingText.StartsWithAMatch || allText.Width <= bounds.Width)
            {
                // No left elipsis needed
                RenderWithNoLeftElipsis(dc, matchingText, bounds, allText, 0);
                return;
            }

            RenderLeftRightTrimmedText(dc, bounds, matchingText, allText);
        }
Example #6
0
        private void RenderLeftRightTrimmedText(DrawingContext dc, Rect bounds, PatternMatchResult matchingText, FormattedText allText)
        {
            var leadingElipsisText = FormatText("...", bounds.Height);
            var leadingElipsisGeo  = leadingElipsisText.BuildHighlightGeometry(bounds.TopLeft);
            var leadingGeo         = allText.BuildHighlightGeometry(bounds.TopLeft, 0, matchingText.MatchStarts[0]);
            var highlightGeo       = allText.BuildHighlightGeometry(bounds.TopLeft, matchingText.MatchStarts[0], matchingText.Pattern.Length);

            // We know it does not fit and we know it does not start with a match
            if (leadingGeo == null ||
                highlightGeo == null ||
                leadingElipsisGeo == null ||
                (leadingGeo.Bounds.Width < leadingElipsisGeo.Bounds.Width))
            {
                // the leading text is shorter than the elipsis text
                // Just write the leading text, the match, and then the trailtext w/elipsis
                // No left elipsis needed
                RenderWithNoLeftElipsis(dc, matchingText, bounds, allText, 0);
                return;
            }

            var availableWidth = bounds.Width;

            availableWidth -= leadingElipsisGeo.Bounds.Width * 2;
            availableWidth -= highlightGeo.Bounds.Width;

            var leadingTextSource  = matchingText.GetTextBefore(0);
            var trailingTextSource = matchingText.GetTextAfter(0);

            var leadingText  = "";
            var trailingText = "";

            var shrunkTrailing         = FormatText(trailingText, bounds.Height);
            var shrunkLeading          = FormatText(leadingText, bounds.Height);
            var initialLeadingSize     = FormatText(leadingTextSource, bounds.Height).WidthIncludingTrailingWhitespace;
            var appendLettersPassCount = 0;
            var leadingPassPadding     = (matchingText.Pattern.Length) / 2;

            while ((shrunkLeading.WidthIncludingTrailingWhitespace + shrunkTrailing.WidthIncludingTrailingWhitespace) < availableWidth)
            {
                // Add characters until the width is as wide as the column
                // This roughly centers the highlighted text between the leading and trailing parts
                if (appendLettersPassCount > leadingPassPadding)
                {
                    if (leadingText.Length < leadingTextSource.Length)
                    {
                        leadingText = leadingTextSource.Substring(leadingTextSource.Length - leadingText.Length - 1,
                                                                  leadingText.Length + 1);
                        shrunkLeading = FormatText(leadingText, bounds.Height);
                    }

                    if (shrunkLeading.WidthIncludingTrailingWhitespace + shrunkTrailing.WidthIncludingTrailingWhitespace >=
                        availableWidth)
                    {
                        break;
                    }
                }

                if (trailingText.Length < trailingTextSource.Length)
                {
                    trailingText   = trailingTextSource.Substring(0, trailingText.Length + 1);
                    shrunkTrailing = FormatText(trailingText, bounds.Height);
                }

                if (leadingText == leadingTextSource && trailingText == trailingTextSource)
                {
                    // Somehow it managed to fit
                    break;
                }

                appendLettersPassCount++;
            }


            if (leadingText == leadingTextSource || initialLeadingSize - shrunkLeading.WidthIncludingTrailingWhitespace < leadingElipsisText.WidthIncludingTrailingWhitespace)
            {
                // The whole leading text is there, no elipsis required
                RenderWithNoLeftElipsis(dc, matchingText, bounds, allText, 0);
                return;
            }

            // Draw the elipsis
            dc.DrawText(leadingElipsisText, bounds.TopLeft);

            var shrunkText = leadingText + matchingText.GetTextFromBeginningOfMatchOn(0);

            // Draw the remainder as a new match
            //var remainingMatch = new PatternMatchResult(matchingText.Pattern, shrunkText, 100);

            if (bounds.Width - leadingElipsisText.Width > 0)
            {
                var remainingBounds = new Rect(bounds.Left + leadingElipsisText.Width, bounds.Top,
                                               bounds.Width - leadingElipsisText.Width, bounds.Height);

                int matchPosOffset = leadingTextSource.Length - leadingText.Length;
                RenderWithNoLeftElipsis(dc, matchingText, remainingBounds, FormatText(shrunkText, bounds.Height), matchPosOffset);
            }
        }
 public static PatternMatchResult StrToPatternMatchResult(string str) {
   PatternMatchResult ret = new PatternMatchResult(VisionLabPINVOKE.StrToPatternMatchResult(str), true);
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public static string PatternMatchResultToStr(PatternMatchResult mr) {
   string ret = VisionLabPINVOKE.PatternMatchResultToStr(PatternMatchResult.getCPtr(mr));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public bool IsEqual_Op(PatternMatchResult m) {
   bool ret = VisionLabPINVOKE.PatternMatchResult_IsEqual_Op(swigCPtr, PatternMatchResult.getCPtr(m));
   if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 internal static HandleRef getCPtr(PatternMatchResult obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
 internal static HandleRef getCPtr(PatternMatchResult obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
 public static LetterMatch PatternMatchResultToLetterMatch(PatternMatchResult pmr)
 {
     return(new LetterMatch(pmr.id, pmr.error));
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PatternMatchResult obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 public static LetterMatch PatternMatchResultToLetterMatch(PatternMatchResult pmr)
 {
     return new LetterMatch(pmr.id, pmr.error);
 }