Custom Presentation: Highlight Text Not Contained Within Annotations

5 posts, 0 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 28 Aug 2012 Link to this post

    Hi,

    I haven't attempted this yet but, do you have any advice on the best way to highlight any text that is NOT contained within Custom Annotations?

    i.e. what do you think is the most efficient check process to find and highlight all text not contained within annotations?

    Thanks for your time, any advice is appreciated,

    Rob 
  2. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 28 Aug 2012 Link to this post

    My logic tells me to follow something similar to your "HighlightCurrentWordLayer" example, but rather than checking for specific words I should check if the text is contained within RangeStart and RangeEnd Annotation tags.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 28 Aug 2012 Link to this post

    Well this seems pretty close to what I need:

    public override void UpdateUIViewPortOverride(UILayerUpdateContext context)
    {
        foreach (SpanLayoutBox spanBox in context.GetVisibleTextLayoutBoxes())
        {
            SizeF spanBoxSize = spanBox.Size;
            this.AddRectangle(spanBoxSize, spanBox);
        }
    }

    private void AddRectangle(SizeF spanBoxSize, SpanLayoutBox spanBox)
    {
        Rectangle rectangle = new Rectangle();
        rectangle.Width = Math.Max(0, (double)spanBoxSize.Width);
        rectangle.Height = (double)spanBoxSize.Height;
     
        Canvas.SetTop(rectangle, spanBox.ControlBoundingRectangle.Top);
        Canvas.SetLeft(rectangle, spanBox.BoundingRectangle.Left);
     
        rectangle.Fill = FillBrush;
        rectangle.Opacity = AddToDatabaseHighlightLayer.MouseOutOpacity;
     
        base.AddDecorationElement(rectangle);
    }


    All I need to do now is restric it so that it only highlights text that is not contained within my CustomAnnotations.

    (I've attached an image of my document for this current UI layer).




  5. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 28 Aug 2012 Link to this post

    Ok, I now have it working so that any text surrounded by my custom annotations are ignored.

    Here's my new UpdateUIViewPortOverride method:

    public override void UpdateUIViewPortOverride(UILayerUpdateContext context)
     {
         foreach (SpanLayoutBox spanBox in context.GetVisibleTextLayoutBoxes())
         {
             AnnotationMarkerLayoutBox previousAnnotationLayoutBox = (AnnotationMarkerLayoutBox)DocumentStructureCollection.GetPreviousElementOfType(spanBox, typeof(AnnotationMarkerLayoutBox));
             AnnotationMarkerLayoutBox nextAnnotationLayoutBox = (AnnotationMarkerLayoutBox)DocumentStructureCollection.GetNextElementOfType(spanBox, typeof(AnnotationMarkerLayoutBox));
     
             if ((previousAnnotationLayoutBox.AssociatedAnnotationMarker is SemanticRangeStart && nextAnnotationLayoutBox.AssociatedAnnotationMarker is SemanticRangeEnd) ||
                 (previousAnnotationLayoutBox.AssociatedAnnotationMarker is LineBreakSpacingRangeStart && nextAnnotationLayoutBox.AssociatedAnnotationMarker is LineBreakSpacingRangeEnd) ||
                 (previousAnnotationLayoutBox.AssociatedAnnotationMarker is CommentLineRangeStart && nextAnnotationLayoutBox.AssociatedAnnotationMarker is CommentLineRangeEnd) ||
                 (previousAnnotationLayoutBox.AssociatedAnnotationMarker is CommentParagraphStart && nextAnnotationLayoutBox.AssociatedAnnotationMarker is CommentParagraphEnd) ||
                 (previousAnnotationLayoutBox.AssociatedAnnotationMarker is RoomGroupRangeStart && nextAnnotationLayoutBox.AssociatedAnnotationMarker is RoomGroupRangeEnd))
             {
                  
             }
             else
             {
                 if (!String.IsNullOrWhiteSpace(spanBox.Text.Trim()))
                 {
                     SizeF spanBoxSize = spanBox.Size;
                     this.AddRectangle(spanBoxSize, spanBox);
                 }
             }
         }
    }

  6. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 31 Aug 2012 Link to this post

    Hello Rob,

    We are glad to hear that you have found a solution to your question. Thank you for sharing it with the community!

    All the best,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready