Ejemplo n.º 1
0
        ///<summary>
        /// For a given page # and a page, returns a page that include the original
        /// page along with any annotations that are displayed on that page.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pageNumber"></param>
        private DocumentPage ComposePageWithAnnotationVisuals(int pageNumber, DocumentPage page)
        {
            // Need to store these because our current highlight mechanism
            // causes the page to be disposed
            Size tempSize = page.Size;

            AdornerDecorator decorator = new AdornerDecorator();

            decorator.FlowDirection = _flowDirection;
            DocumentPageView dpv = new DocumentPageView();

            dpv.UseAsynchronousGetPage = false;
            dpv.DocumentPaginator      = _originalPaginator;
            dpv.PageNumber             = pageNumber;
            decorator.Child            = dpv;

            // Arrange the first time to get the DPV setup right
            decorator.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            decorator.Arrange(new Rect(decorator.DesiredSize));
            decorator.UpdateLayout();

            // Create a new one for each page because it keeps a cache of annotation components
            // and we don't want to be holding them in memory once the page is no longer used
            AnnotationComponentManager manager = new MS.Internal.Annotations.Component.AnnotationComponentManager(null);

            // Setup DPs and processors for annotation handling.  If the service isn't already
            // enabled the processors will be registered by the service when it is enabled.
            if (_isFixedContent)
            {
                // Setup service to look for FixedPages in the content
                AnnotationService.SetSubTreeProcessorId(decorator, FixedPageProcessor.Id);
                // If the service is already registered, set it up for fixed content
                _locatorManager.RegisterSelectionProcessor(new FixedTextSelectionProcessor(), typeof(TextRange));
            }
            else
            {
                // Setup up an initial DataId used to identify the document
                AnnotationService.SetDataId(decorator, "FlowDocument");
                _locatorManager.RegisterSelectionProcessor(new TextViewSelectionProcessor(), typeof(DocumentPageView));
                // Setup the selection processor, pre-targeting it at a specific DocumentPageView
                TextSelectionProcessor textSelectionProcessor = new TextSelectionProcessor();
                textSelectionProcessor.SetTargetDocumentPageView(dpv);
                _locatorManager.RegisterSelectionProcessor(textSelectionProcessor, typeof(TextRange));
            }

            // Get attached annotations for the page
            IList <IAttachedAnnotation> attachedAnnotations = ProcessAnnotations(dpv);

            // Now make sure they have a visual component added to the DPV via the component manager
            foreach (IAttachedAnnotation attachedAnnotation in attachedAnnotations)
            {
                if (attachedAnnotation.AttachmentLevel != AttachmentLevel.Unresolved && attachedAnnotation.AttachmentLevel != AttachmentLevel.Incomplete)
                {
                    manager.AddAttachedAnnotation(attachedAnnotation, false);
                }
            }

            // Update layout a second time to get the annotations layed out correctly
            decorator.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            decorator.Arrange(new Rect(decorator.DesiredSize));
            decorator.UpdateLayout();

/*          Look into using the VisualBrush in order to get a dead page instead of a live one...
 *          VisualBrush visualBrush = new VisualBrush(decorator);
 *          Rectangle rectangle = new Rectangle();
 *          rectangle.Fill = visualBrush;
 *          rectangle.Margin = new Thickness(0);
 */

            return(new AnnotatedDocumentPage(page, decorator, tempSize, new Rect(tempSize), new Rect(tempSize)));
        }
        ///<summary> 
        /// For a given page # and a page, returns a page that include the original
        /// page along with any annotations that are displayed on that page.
        /// </summary>
        /// <param name="page"></param> 
        /// <param name="pageNumber"></param>
        private DocumentPage ComposePageWithAnnotationVisuals(int pageNumber, DocumentPage page) 
        { 
            // Need to store these because our current highlight mechanism
            // causes the page to be disposed 
            Size tempSize = page.Size;

            AdornerDecorator decorator = new AdornerDecorator();
            decorator.FlowDirection = _flowDirection; 
            DocumentPageView dpv = new DocumentPageView();
            dpv.UseAsynchronousGetPage = false; 
            dpv.DocumentPaginator = _originalPaginator; 
            dpv.PageNumber = pageNumber;
            decorator.Child = dpv; 

            // Arrange the first time to get the DPV setup right
            decorator.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            decorator.Arrange(new Rect(decorator.DesiredSize)); 
            decorator.UpdateLayout();
 
            // Create a new one for each page because it keeps a cache of annotation components 
            // and we don't want to be holding them in memory once the page is no longer used
            AnnotationComponentManager manager = new MS.Internal.Annotations.Component.AnnotationComponentManager(null); 

            // Setup DPs and processors for annotation handling.  If the service isn't already
            // enabled the processors will be registered by the service when it is enabled.
            if (_isFixedContent) 
            {
                // Setup service to look for FixedPages in the content 
                AnnotationService.SetSubTreeProcessorId(decorator, FixedPageProcessor.Id); 
                // If the service is already registered, set it up for fixed content
                _locatorManager.RegisterSelectionProcessor(new FixedTextSelectionProcessor(), typeof(TextRange)); 
            }
            else
            {
                // Setup up an initial DataId used to identify the document 
                AnnotationService.SetDataId(decorator, "FlowDocument");
                _locatorManager.RegisterSelectionProcessor(new TextViewSelectionProcessor(), typeof(DocumentPageView)); 
                // Setup the selection processor, pre-targeting it at a specific DocumentPageView 
                TextSelectionProcessor textSelectionProcessor = new TextSelectionProcessor();
                textSelectionProcessor.SetTargetDocumentPageView(dpv); 
                _locatorManager.RegisterSelectionProcessor(textSelectionProcessor, typeof(TextRange));
            }

            // Get attached annotations for the page 
            IList<IAttachedAnnotation> attachedAnnotations = ProcessAnnotations(dpv);
 
            // Now make sure they have a visual component added to the DPV via the component manager 
            foreach (IAttachedAnnotation attachedAnnotation in attachedAnnotations)
            { 
                if (attachedAnnotation.AttachmentLevel != AttachmentLevel.Unresolved && attachedAnnotation.AttachmentLevel != AttachmentLevel.Incomplete)
                {
                    manager.AddAttachedAnnotation(attachedAnnotation, false);
                } 
            }
 
            // Update layout a second time to get the annotations layed out correctly 
            decorator.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            decorator.Arrange(new Rect(decorator.DesiredSize)); 
            decorator.UpdateLayout();

/*          Look into using the VisualBrush in order to get a dead page instead of a live one...
            VisualBrush visualBrush = new VisualBrush(decorator); 
            Rectangle rectangle = new Rectangle();
            rectangle.Fill = visualBrush; 
            rectangle.Margin = new Thickness(0); 
*/
 
            return new AnnotatedDocumentPage(page, decorator, tempSize, new Rect(tempSize), new Rect(tempSize));
        }
Ejemplo n.º 3
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods


        /// <summary>
        ///     Initializes the service on this tree node.
        /// </summary>
        /// <param name="root">the tree node the service is being created on</param>
        private void Initialize(DependencyObject root)
        {
            Invariant.Assert(root != null, "Parameter 'root' is null.");

            // Root of the subtree this service will operate on
            _root = root;

            // Object that resolves and generates locators
            _locatorManager = new LocatorManager();

            // sets up dependency for AnnotationComponentManager
            _annotationComponentManager = new AnnotationComponentManager(this);

            //set known component types priorities
            AdornerPresentationContext.SetTypeZLevel(typeof(StickyNoteControl), 0);
            AdornerPresentationContext.SetTypeZLevel(typeof(MarkedHighlightComponent), 1);
            AdornerPresentationContext.SetTypeZLevel(typeof(HighlightComponent), 1);
            //set ZRanges for the ZLevels
            AdornerPresentationContext.SetZLevelRange(0, Int32.MaxValue / 2 + 1, Int32.MaxValue);
            AdornerPresentationContext.SetZLevelRange(1, 0, 0);
        }