Beispiel #1
0
        // Token: 0x06002B87 RID: 11143 RVA: 0x000C698C File Offset: 0x000C4B8C
        internal DynamicDocumentPaginator GetPaginator(DocumentReference docRef)
        {
            DynamicDocumentPaginator dynamicDocumentPaginator = null;
            IDocumentPaginatorSource documentPaginatorSource  = docRef.CurrentlyLoadedDoc;

            if (documentPaginatorSource != null)
            {
                dynamicDocumentPaginator = (documentPaginatorSource.DocumentPaginator as DynamicDocumentPaginator);
            }
            else
            {
                documentPaginatorSource = docRef.GetDocument(false);
                if (documentPaginatorSource != null)
                {
                    dynamicDocumentPaginator = (documentPaginatorSource.DocumentPaginator as DynamicDocumentPaginator);
                    dynamicDocumentPaginator.PaginationCompleted += this._OnChildPaginationCompleted;
                    dynamicDocumentPaginator.PaginationProgress  += this._OnChildPaginationProgress;
                    dynamicDocumentPaginator.PagesChanged        += this._OnChildPagesChanged;
                }
            }
            return(dynamicDocumentPaginator);
        }
Beispiel #2
0
        private void _OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action == NotifyCollectionChangedAction.Add)
            {
                if (args.NewItems.Count != 1)
                {
                    throw new NotSupportedException(SR.Get(SRID.RangeActionsNotSupported));
                }
                else
                {
                    // get the affected item
                    object item = args.NewItems[0];

                    DocumentsTrace.FixedDocumentSequence.Content.Trace(string.Format("_OnCollectionChange: Add {0}", item.GetHashCode()));
                    AddLogicalChild(item);

                    int pageCount = this.PageCount;
                    DynamicDocumentPaginator paginator = GetPaginator((DocumentReference)item);
                    if (paginator == null)
                    {
                        throw new ApplicationException(SR.Get(SRID.DocumentReferenceHasInvalidDocument));
                    }

                    int addedPages = paginator.PageCount;
                    int firstPage  = pageCount - addedPages;

                    if (addedPages > 0)
                    {
                        DocumentsTrace.FixedDocumentSequence.Content.Trace(string.Format("_OnCollectionChange: Add with IDP {0}", paginator.GetHashCode()));
                        _paginator.NotifyPaginationProgress(new PaginationProgressEventArgs(firstPage, addedPages));
                        _paginator.NotifyPagesChanged(new PagesChangedEventArgs(firstPage, addedPages));
                    }
                }
            }
            else
            {
                throw new NotSupportedException(SR.Get(SRID.UnexpectedCollectionChangeAction, args.Action));
            }
        }
Beispiel #3
0
        /// <summary>
        /// <see cref="DynamicDocumentPaginator.GetObjectPosition"/>
        /// </summary>
        internal ContentPosition GetObjectPosition(Object o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }

            foreach (DocumentReference docRef in References)
            {
                DynamicDocumentPaginator childPaginator = GetPaginator(docRef);
                if (childPaginator != null)
                {
                    ContentPosition cp = childPaginator.GetObjectPosition(o);
                    if (cp != ContentPosition.Missing && (cp is ITextPointer))
                    {
                        ChildDocumentBlock childBlock = new ChildDocumentBlock(this.TextContainer, docRef);
                        return(new DocumentSequenceTextPointer(childBlock, (ITextPointer)cp));
                    }
                }
            }
            return(ContentPosition.Missing);
        }
Beispiel #4
0
 // Token: 0x06002B88 RID: 11144 RVA: 0x000C6A04 File Offset: 0x000C4C04
 internal bool TranslatePageNumber(int pageNumber, out DynamicDocumentPaginator childPaginator, out int childPageNumber)
 {
     childPaginator  = null;
     childPageNumber = 0;
     foreach (DocumentReference docRef in this.References)
     {
         childPaginator = this.GetPaginator(docRef);
         if (childPaginator != null)
         {
             childPageNumber = pageNumber;
             if (childPaginator.PageCount > childPageNumber)
             {
                 return(true);
             }
             if (!childPaginator.IsPageCountValid)
             {
                 break;
             }
             pageNumber -= childPaginator.PageCount;
         }
     }
     return(false);
 }
Beispiel #5
0
        // Token: 0x06002B73 RID: 11123 RVA: 0x000C64D0 File Offset: 0x000C46D0
        UIElement IFixedNavigate.FindElementByID(string elementID, out FixedPage rootFixedPage)
        {
            UIElement uielement = null;

            rootFixedPage = null;
            if (char.IsDigit(elementID[0]))
            {
                int pageNumber = Convert.ToInt32(elementID, CultureInfo.InvariantCulture) - 1;
                DynamicDocumentPaginator paginator;
                int pageNumber2;
                if (this.TranslatePageNumber(pageNumber, out paginator, out pageNumber2))
                {
                    FixedDocument fixedDocument = paginator.Source as FixedDocument;
                    if (fixedDocument != null)
                    {
                        uielement = fixedDocument.GetFixedPage(pageNumber2);
                    }
                }
            }
            else
            {
                foreach (DocumentReference docRef in this.References)
                {
                    DynamicDocumentPaginator paginator     = this.GetPaginator(docRef);
                    FixedDocument            fixedDocument = paginator.Source as FixedDocument;
                    if (fixedDocument != null)
                    {
                        uielement = ((IFixedNavigate)fixedDocument).FindElementByID(elementID, out rootFixedPage);
                        if (uielement != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(uielement);
        }
 // Take a child paginator and a page nubmer, find which global page number it corresponds to
 private bool _SynthesizeGlobalPageNumber(DynamicDocumentPaginator childPaginator, int childPageNumber, out int pageNumber)
 {
     pageNumber = 0;
     foreach (DocumentReference docRef in References)
     {
         DynamicDocumentPaginator innerPaginator = GetPaginator(docRef);
         if (innerPaginator != null)
         {
             if (innerPaginator == childPaginator)
             {
                 pageNumber += childPageNumber;
                 return true;
             }
             pageNumber += innerPaginator.PageCount;
         }
     }
     return false;
 }
        //----------------------------------------------------------------------
        // IDP Helper
        //----------------------------------------------------------------------

        // Take a global page number and translate it into a child paginator with a child page number.
        // A document will be look at if the previous document has finished pagination.
        internal bool TranslatePageNumber(int pageNumber, out DynamicDocumentPaginator childPaginator, out int childPageNumber)
        {
            childPaginator = null;
            childPageNumber = 0;

            foreach (DocumentReference docRef in References)
            {
                childPaginator = GetPaginator(docRef);
                if (childPaginator != null)
                {
                    childPageNumber = pageNumber;
                    if (childPaginator.PageCount > childPageNumber)
                    {
                        // The page falls inside this paginator.
                        return true;
                    }
                    else
                    {
                        if (!childPaginator.IsPageCountValid)
                        {
                            // Don't bother look further if this doc has not finished
                            // pagination
                            break;
                        }
                        pageNumber -= childPaginator.PageCount;
                    }
                }
            }
            return false;
        }
        //--------------------------------------------------------------------
        //
        // Ctors
        //
        //---------------------------------------------------------------------

        #region Ctors
        internal FixedDocumentSequenceDocumentPage(FixedDocumentSequence documentSequence, DynamicDocumentPaginator documentPaginator, DocumentPage documentPage)
            : base((documentPage is FixedDocumentPage) ? ((FixedDocumentPage)documentPage).FixedPage : documentPage.Visual, documentPage.Size, documentPage.BleedBox, documentPage.ContentBox)
        {
            Debug.Assert(documentSequence != null);
            Debug.Assert(documentPaginator != null);
            Debug.Assert(documentPage != null);
            _fixedDocumentSequence = documentSequence;
            _documentPaginator = documentPaginator;
            _documentPage = documentPage;
        }
 internal RequestedPage(int pageNumber)
 {
     PageNumber = pageNumber;
     ChildPageNumber = 0;
     ChildPaginator = null;
 }
Beispiel #10
0
 // Token: 0x06002B95 RID: 11157 RVA: 0x000C7070 File Offset: 0x000C5270
 internal FixedDocumentSequenceDocumentPage(FixedDocumentSequence documentSequence, DynamicDocumentPaginator documentPaginator, DocumentPage documentPage) : base((documentPage is FixedDocumentPage) ? ((FixedDocumentPage)documentPage).FixedPage : documentPage.Visual, documentPage.Size, documentPage.BleedBox, documentPage.ContentBox)
 {
     this._fixedDocumentSequence = documentSequence;
     this._documentPaginator     = documentPaginator;
     this._documentPage          = documentPage;
 }
Beispiel #11
0
        // Token: 0x06002E71 RID: 11889 RVA: 0x000D23C8 File Offset: 0x000D05C8
        internal static TextRange Find(ITextPointer start, ITextPointer end, string findPattern, CultureInfo cultureInfo, bool matchCase, bool matchWholeWord, bool matchLast, bool matchDiacritics, bool matchKashida, bool matchAlefHamza)
        {
            if (findPattern.Length == 0)
            {
                return(null);
            }
            IDocumentPaginatorSource documentPaginatorSource  = start.TextContainer.Parent as IDocumentPaginatorSource;
            DynamicDocumentPaginator dynamicDocumentPaginator = documentPaginatorSource.DocumentPaginator as DynamicDocumentPaginator;
            int pageNumber;
            int num;

            if (matchLast)
            {
                pageNumber = dynamicDocumentPaginator.GetPageNumber((ContentPosition)start);
                num        = dynamicDocumentPaginator.GetPageNumber((ContentPosition)end);
            }
            else
            {
                pageNumber = dynamicDocumentPaginator.GetPageNumber((ContentPosition)end);
                num        = dynamicDocumentPaginator.GetPageNumber((ContentPosition)start);
            }
            TextRange                textRange   = null;
            CompareInfo              compareInfo = cultureInfo.CompareInfo;
            bool                     replaceAlefWithAlefHamza = false;
            CompareOptions           compareOptions           = FixedFindEngine._InitializeSearch(cultureInfo, matchCase, matchAlefHamza, matchDiacritics, ref findPattern, out replaceAlefWithAlefHamza);
            int                      num2 = num;
            FixedDocumentSequence    fixedDocumentSequence     = documentPaginatorSource as FixedDocumentSequence;
            DynamicDocumentPaginator dynamicDocumentPaginator2 = null;

            if (fixedDocumentSequence != null)
            {
                fixedDocumentSequence.TranslatePageNumber(num, out dynamicDocumentPaginator2, out num2);
            }
            if (num - pageNumber != 0)
            {
                ITextPointer startPosition = null;
                ITextPointer endPosition   = null;
                FixedFindEngine._GetFirstPageSearchPointers(start, end, num2, matchLast, out startPosition, out endPosition);
                textRange = TextFindEngine.InternalFind(startPosition, endPosition, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza);
                if (textRange == null)
                {
                    num = (matchLast ? (num - 1) : (num + 1));
                    int num3 = matchLast ? -1 : 1;
                    while (matchLast ? (num >= pageNumber) : (num <= pageNumber))
                    {
                        num2 = num;
                        dynamicDocumentPaginator2 = null;
                        FixedDocument fixedDocument;
                        if (fixedDocumentSequence != null)
                        {
                            fixedDocumentSequence.TranslatePageNumber(num, out dynamicDocumentPaginator2, out num2);
                            fixedDocument = (FixedDocument)dynamicDocumentPaginator2.Source;
                        }
                        else
                        {
                            fixedDocument = (documentPaginatorSource as FixedDocument);
                        }
                        string text = FixedFindEngine._GetPageString(fixedDocument, num2, replaceAlefWithAlefHamza);
                        if (text == null)
                        {
                            return(TextFindEngine.InternalFind(start, end, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
                        }
                        if (FixedFindEngine._FoundOnPage(text, findPattern, cultureInfo, compareOptions))
                        {
                            if (fixedDocumentSequence != null)
                            {
                                ChildDocumentBlock childBlock = fixedDocumentSequence.TextContainer.FindChildBlock(fixedDocument.DocumentReference);
                                if (matchLast)
                                {
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(num2)));
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(num2)));
                                }
                                else
                                {
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(num2)));
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(num2)));
                                }
                            }
                            else
                            {
                                FixedTextBuilder fixedTextBuilder = ((FixedDocument)documentPaginatorSource).FixedContainer.FixedTextBuilder;
                                if (matchLast)
                                {
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, fixedTextBuilder.GetPageEndFlowPosition(num));
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, fixedTextBuilder.GetPageStartFlowPosition(num));
                                }
                                else
                                {
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, fixedTextBuilder.GetPageStartFlowPosition(num));
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, fixedTextBuilder.GetPageEndFlowPosition(num));
                                }
                            }
                            textRange = TextFindEngine.InternalFind(start, end, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza);
                            if (textRange != null)
                            {
                                return(textRange);
                            }
                        }
                        num += num3;
                    }
                }
            }
            else
            {
                FixedDocument doc   = (dynamicDocumentPaginator2 != null) ? (dynamicDocumentPaginator2.Source as FixedDocument) : (documentPaginatorSource as FixedDocument);
                string        text2 = FixedFindEngine._GetPageString(doc, num2, replaceAlefWithAlefHamza);
                if (text2 == null || FixedFindEngine._FoundOnPage(text2, findPattern, cultureInfo, compareOptions))
                {
                    textRange = TextFindEngine.InternalFind(start, end, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza);
                }
            }
            return(textRange);
        }
        //Searches for the specified pattern and updates start *or* end pointers depending on search direction
        //At the end of the operation, start or end should be pointing to the beginning/end of the page
        //of occurance of pattern respectively
        internal static TextRange Find(ITextPointer start,
                                       ITextPointer end,
                                       string findPattern,
                                       CultureInfo cultureInfo,
                                       bool matchCase,
                                       bool matchWholeWord,
                                       bool matchLast,
                                       bool matchDiacritics,
                                       bool matchKashida,
                                       bool matchAlefHamza)
        {
            Debug.Assert(start != null);
            Debug.Assert(end != null);
            Debug.Assert(((start is DocumentSequenceTextPointer) && (end is DocumentSequenceTextPointer)) ||
                         ((start is FixedTextPointer) && (end is FixedTextPointer)));
            Debug.Assert(findPattern != null);

            if (findPattern.Length == 0)
            {
                return(null);
            }

            IDocumentPaginatorSource paginatorSource = start.TextContainer.Parent as IDocumentPaginatorSource;
            DynamicDocumentPaginator paginator       = paginatorSource.DocumentPaginator as DynamicDocumentPaginator;

            Debug.Assert(paginator != null);

            int pageNumber    = -1;
            int endPageNumber = -1;

            if (matchLast)
            {
                endPageNumber = paginator.GetPageNumber((ContentPosition)start);
                pageNumber    = paginator.GetPageNumber((ContentPosition)end);
            }
            else
            {
                endPageNumber = paginator.GetPageNumber((ContentPosition)end);
                pageNumber    = paginator.GetPageNumber((ContentPosition)start);
            }

            TextRange result = null;

            CompareInfo    compareInfo = cultureInfo.CompareInfo;
            bool           replaceAlefWithAlefHamza = false;
            CompareOptions compareOptions           = _InitializeSearch(cultureInfo, matchCase, matchAlefHamza, matchDiacritics, ref findPattern, out replaceAlefWithAlefHamza);

            //Translate the page number
            int translatedPageNumber = pageNumber;
            //If this is a DocumentSequence, we need to pass translated page number to the below call
            FixedDocumentSequence    documentSequence = paginatorSource as FixedDocumentSequence;
            DynamicDocumentPaginator childPaginator   = null;

            if (documentSequence != null)
            {
                documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber);
            }

            if (pageNumber - endPageNumber != 0)
            {
                ITextPointer firstSearchPageStart = null;
                ITextPointer firstSearchPageEnd   = null;

                _GetFirstPageSearchPointers(start, end, translatedPageNumber, matchLast, out firstSearchPageStart, out firstSearchPageEnd);

                Debug.Assert(firstSearchPageStart != null);
                Debug.Assert(firstSearchPageEnd != null);

                //Need to search the first page using TextFindEngine to start exactly from the requested search location to avoid false positives
                result = TextFindEngine.InternalFind(firstSearchPageStart,
                                                     firstSearchPageEnd,
                                                     findPattern,
                                                     cultureInfo,
                                                     matchCase,
                                                     matchWholeWord,
                                                     matchLast,
                                                     matchDiacritics,
                                                     matchKashida,
                                                     matchAlefHamza);
                if (result == null)
                {
                    //Start from the next page and check all pages until the end
                    pageNumber = matchLast ? pageNumber - 1 : pageNumber + 1;
                    int increment = matchLast ? -1 : 1;
                    for (; matchLast?pageNumber >= endPageNumber : pageNumber <= endPageNumber; pageNumber += increment)
                    {
                        FixedDocument fixedDoc = null;

                        translatedPageNumber = pageNumber;
                        childPaginator       = null;
                        if (documentSequence != null)
                        {
                            documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber);
                            fixedDoc = (FixedDocument)childPaginator.Source;
                        }
                        else
                        {
                            fixedDoc = paginatorSource as FixedDocument;
                        }

                        Debug.Assert(fixedDoc != null);

                        String pageString = _GetPageString(fixedDoc, translatedPageNumber, replaceAlefWithAlefHamza);

                        if (pageString == null)
                        {
                            //This is not a page-per-stream
                            //Default back to slow search
                            return(TextFindEngine.InternalFind(start,
                                                               end,
                                                               findPattern,
                                                               cultureInfo,
                                                               matchCase,
                                                               matchWholeWord,
                                                               matchLast,
                                                               matchDiacritics,
                                                               matchKashida,
                                                               matchAlefHamza));
                        }

                        if (_FoundOnPage(pageString, findPattern, cultureInfo, compareOptions))
                        {
                            //Update end or start pointer depending on search direction
                            if (documentSequence != null)
                            {
                                ChildDocumentBlock childBlock = documentSequence.TextContainer.FindChildBlock(fixedDoc.DocumentReference);
                                if (matchLast)
                                {
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(translatedPageNumber)));
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(translatedPageNumber)));
                                }
                                else
                                {
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(translatedPageNumber)));
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(translatedPageNumber)));
                                }
                            }
                            else
                            {
                                //We are working on a FixedDocument
                                FixedTextBuilder textBuilder = ((FixedDocument)(paginatorSource)).FixedContainer.FixedTextBuilder;
                                if (matchLast)
                                {
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, textBuilder.GetPageEndFlowPosition(pageNumber));
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, textBuilder.GetPageStartFlowPosition(pageNumber));
                                }
                                else
                                {
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, textBuilder.GetPageStartFlowPosition(pageNumber));
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, textBuilder.GetPageEndFlowPosition(pageNumber));
                                }
                            }
                            result = TextFindEngine.InternalFind(start,
                                                                 end,
                                                                 findPattern,
                                                                 cultureInfo,
                                                                 matchCase,
                                                                 matchWholeWord,
                                                                 matchLast,
                                                                 matchDiacritics,
                                                                 matchKashida,
                                                                 matchAlefHamza);

                            //If the result is null, this means we had a false positive
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            else
            {
                //Make sure fast search result and slow search result are consistent
                FixedDocument fixedDoc   = childPaginator != null ? childPaginator.Source as FixedDocument : paginatorSource as FixedDocument;
                String        pageString = _GetPageString(fixedDoc, translatedPageNumber, replaceAlefWithAlefHamza);
                if (pageString == null ||
                    _FoundOnPage(pageString, findPattern, cultureInfo, compareOptions))
                {
                    //The search is only limited to the current page
                    result = TextFindEngine.InternalFind(start,
                                                         end,
                                                         findPattern,
                                                         cultureInfo,
                                                         matchCase,
                                                         matchWholeWord,
                                                         matchLast,
                                                         matchDiacritics,
                                                         matchKashida,
                                                         matchAlefHamza);
                }
            }

            return(result);
        }
Beispiel #13
0
        //--------------------------------------------------------------------
        //
        // Ctors
        //
        //---------------------------------------------------------------------

        #region Ctors
        internal FixedDocumentSequenceDocumentPage(FixedDocumentSequence documentSequence, DynamicDocumentPaginator documentPaginator, DocumentPage documentPage)
            : base((documentPage is FixedDocumentPage) ? ((FixedDocumentPage)documentPage).FixedPage : documentPage.Visual, documentPage.Size, documentPage.BleedBox, documentPage.ContentBox)
        {
            Debug.Assert(documentSequence != null);
            Debug.Assert(documentPaginator != null);
            Debug.Assert(documentPage != null);
            _fixedDocumentSequence = documentSequence;
            _documentPaginator     = documentPaginator;
            _documentPage          = documentPage;
        }
Beispiel #14
0
 internal RequestedPage(int pageNumber)
 {
     PageNumber      = pageNumber;
     ChildPageNumber = 0;
     ChildPaginator  = null;
 }
Beispiel #15
0
 public void WindowLoaded(object sender, RoutedEventArgs e)
 {
     _dynPaginator = ((IDocumentPaginatorSource) fd1).DocumentPaginator as DynamicDocumentPaginator;
     if (_dynPaginator == null)
         throw new NullReferenceException("Can't get a DynamicDocumentPaginator for FlowDocument fd1.");
 }