// Token: 0x060062CF RID: 25295 RVA: 0x001BB61C File Offset: 0x001B981C
        private static Annotation CreateStickyNoteForSelection(AnnotationService service, XmlQualifiedName noteType, string author)
        {
            AnnotationHelper.CheckInputs(service);
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            if (textSelection.IsEmpty)
            {
                throw new InvalidOperationException(SR.Get("EmptySelectionNotSupported"));
            }
            Annotation annotation = null;

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateStickyNoteBegin);
            try
            {
                annotation = AnnotationHelper.CreateAnnotationForSelection(service, textSelection, noteType, author);
                Invariant.Assert(annotation != null, "CreateAnnotationForSelection returned null.");
                service.Store.AddAnnotation(annotation);
                textSelection.SetCaretToPosition(textSelection.MovingPosition, textSelection.MovingPosition.LogicalDirection, true, true);
            }
            finally
            {
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.CreateStickyNoteEnd);
            }
            return(annotation);
        }
        // Token: 0x060062D7 RID: 25303 RVA: 0x001BBC34 File Offset: 0x001B9E34
        private static void DeleteSpannedAnnotations(AnnotationService service, XmlQualifiedName annotationType)
        {
            AnnotationHelper.CheckInputs(service);
            Invariant.Assert(annotationType != null && (annotationType == HighlightComponent.TypeName || annotationType == StickyNoteControl.TextSchemaName || annotationType == StickyNoteControl.InkSchemaName), "Invalid Annotation Type");
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            IList <IAttachedAnnotation> spannedAnnotations = AnnotationHelper.GetSpannedAnnotations(service);

            foreach (IAttachedAnnotation attachedAnnotation in spannedAnnotations)
            {
                if (annotationType.Equals(attachedAnnotation.Annotation.AnnotationType))
                {
                    TextAnchor textAnchor = attachedAnnotation.AttachedAnchor as TextAnchor;
                    if (textAnchor != null && ((textSelection.Start.CompareTo(textAnchor.Start) > 0 && textSelection.Start.CompareTo(textAnchor.End) < 0) || (textSelection.End.CompareTo(textAnchor.Start) > 0 && textSelection.End.CompareTo(textAnchor.End) < 0) || (textSelection.Start.CompareTo(textAnchor.Start) <= 0 && textSelection.End.CompareTo(textAnchor.End) >= 0) || AnnotationHelper.CheckCaret(textSelection, textAnchor, annotationType)))
                    {
                        service.Store.DeleteAnnotation(attachedAnnotation.Annotation.Id);
                    }
                }
            }
        }
        // Token: 0x060062DA RID: 25306 RVA: 0x001BBE8C File Offset: 0x001BA08C
        private static Annotation Highlight(AnnotationService service, string author, Brush highlightBrush, bool create)
        {
            AnnotationHelper.CheckInputs(service);
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            if (textSelection.IsEmpty)
            {
                throw new InvalidOperationException(SR.Get("EmptySelectionNotSupported"));
            }
            Color?color = null;

            if (highlightBrush != null)
            {
                SolidColorBrush solidColorBrush = highlightBrush as SolidColorBrush;
                if (solidColorBrush == null)
                {
                    throw new ArgumentException(SR.Get("InvalidHighlightColor"), "highlightBrush");
                }
                byte a;
                if (solidColorBrush.Opacity <= 0.0)
                {
                    a = 0;
                }
                else if (solidColorBrush.Opacity >= 1.0)
                {
                    a = solidColorBrush.Color.A;
                }
                else
                {
                    a = (byte)(solidColorBrush.Opacity * (double)solidColorBrush.Color.A);
                }
                color = new Color?(Color.FromArgb(a, solidColorBrush.Color.R, solidColorBrush.Color.G, solidColorBrush.Color.B));
            }
            ITextRange textRange = new TextRange(textSelection.Start, textSelection.End);
            Annotation result    = AnnotationHelper.ProcessHighlights(service, textRange, author, color, create);

            textSelection.SetCaretToPosition(textSelection.MovingPosition, textSelection.MovingPosition.LogicalDirection, true, true);
            return(result);
        }
        // Token: 0x060062D1 RID: 25297 RVA: 0x001BB730 File Offset: 0x001B9930
        private static IList <IAttachedAnnotation> GetSpannedAnnotations(AnnotationService service)
        {
            AnnotationHelper.CheckInputs(service);
            bool flag = true;
            DocumentViewerBase documentViewerBase = service.Root as DocumentViewerBase;

            if (documentViewerBase == null)
            {
                FlowDocumentReader flowDocumentReader = service.Root as FlowDocumentReader;
                if (flowDocumentReader != null)
                {
                    documentViewerBase = (AnnotationHelper.GetFdrHost(flowDocumentReader) as DocumentViewerBase);
                }
            }
            else
            {
                flag = (documentViewerBase.Document is FlowDocument);
            }
            bool           flag2         = true;
            ITextSelection textSelection = AnnotationHelper.GetTextSelection((FrameworkElement)service.Root);

            Invariant.Assert(textSelection != null, "TextSelection is null");
            int num  = 0;
            int num2 = 0;

            if (documentViewerBase != null)
            {
                TextSelectionHelper.GetPointerPage(textSelection.Start, out num);
                TextSelectionHelper.GetPointerPage(textSelection.End, out num2);
                if (num == -1 || num2 == -1)
                {
                    throw new ArgumentException(SR.Get("InvalidSelectionPages"));
                }
                flag2 = AnnotationHelper.AreAllPagesVisible(documentViewerBase, num, num2);
            }
            IList <IAttachedAnnotation> list;

            if (flag2)
            {
                list = service.GetAttachedAnnotations();
            }
            else if (flag)
            {
                list = AnnotationHelper.GetSpannedAnnotationsForFlow(service, textSelection);
            }
            else
            {
                list = AnnotationHelper.GetSpannedAnnotationsForFixed(service, num, num2);
            }
            IList <TextSegment> textSegments = textSelection.TextSegments;

            if (list != null && list.Count > 0 && (flag2 || !flag))
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    TextAnchor textAnchor = list[i].AttachedAnchor as TextAnchor;
                    if (textAnchor == null || !textAnchor.IsOverlapping(textSegments))
                    {
                        list.RemoveAt(i);
                    }
                }
            }
            return(list);
        }
        /// <summary>Returns an <see cref="T:System.Windows.Annotations.IAnchorInfo" /> object that provides anchoring information, such as the anchor location, about the specified annotation.</summary>
        /// <param name="service">The annotation service to use for this operation.</param>
        /// <param name="annotation">The annotation to get anchoring information for.</param>
        /// <returns>An <see cref="T:System.Windows.Annotations.IAnchorInfo" /> object that provides anchoring information about the specified annotation, or <see langword="null" /> if it cannot be resolved.</returns>
        // Token: 0x060062C1 RID: 25281 RVA: 0x001BB2D0 File Offset: 0x001B94D0
        public static IAnchorInfo GetAnchorInfo(AnnotationService service, Annotation annotation)
        {
            AnnotationHelper.CheckInputs(service);
            if (annotation == null)
            {
                throw new ArgumentNullException("annotation");
            }
            bool flag = true;
            DocumentViewerBase documentViewerBase = service.Root as DocumentViewerBase;

            if (documentViewerBase == null)
            {
                FlowDocumentReader flowDocumentReader = service.Root as FlowDocumentReader;
                if (flowDocumentReader != null)
                {
                    documentViewerBase = (AnnotationHelper.GetFdrHost(flowDocumentReader) as DocumentViewerBase);
                }
            }
            else
            {
                flag = (documentViewerBase.Document is FlowDocument);
            }
            IList <IAttachedAnnotation> list = null;

            if (flag)
            {
                TextSelectionProcessor textSelectionProcessor  = service.LocatorManager.GetSelectionProcessor(typeof(TextRange)) as TextSelectionProcessor;
                TextSelectionProcessor textSelectionProcessor2 = service.LocatorManager.GetSelectionProcessor(typeof(TextAnchor)) as TextSelectionProcessor;
                Invariant.Assert(textSelectionProcessor != null, "TextSelectionProcessor should be available for TextRange if we are processing flow content.");
                Invariant.Assert(textSelectionProcessor2 != null, "TextSelectionProcessor should be available for TextAnchor if we are processing flow content.");
                try
                {
                    textSelectionProcessor.Clamping  = false;
                    textSelectionProcessor2.Clamping = false;
                    list = AnnotationHelper.ResolveAnnotations(service, new Annotation[]
                    {
                        annotation
                    });
                    goto IL_12E;
                }
                finally
                {
                    textSelectionProcessor.Clamping  = true;
                    textSelectionProcessor2.Clamping = true;
                }
            }
            FixedPageProcessor fixedPageProcessor = service.LocatorManager.GetSubTreeProcessorForLocatorPart(FixedPageProcessor.CreateLocatorPart(0)) as FixedPageProcessor;

            Invariant.Assert(fixedPageProcessor != null, "FixedPageProcessor should be available if we are processing fixed content.");
            try
            {
                fixedPageProcessor.UseLogicalTree = true;
                list = AnnotationHelper.ResolveAnnotations(service, new Annotation[]
                {
                    annotation
                });
            }
            finally
            {
                fixedPageProcessor.UseLogicalTree = false;
            }
IL_12E:
            Invariant.Assert(list != null);
            if (list.Count > 0)
            {
                return(list[0]);
            }
            return(null);
        }