Beispiel #1
0
        /// <summary>
        /// <see cref="DynamicDocumentPaginator.GetPageNumber"/>
        /// </summary>
        internal int GetPageNumber(ContentPosition contentPosition)
        {
            if (contentPosition == null)
            {
                throw new ArgumentNullException("contentPosition");
            }

            // ContentPosition may be only created by DynamicDocumentPaginator.GetObjectPosition or
            // DynamicDocumentPaginator.GetPagePosition.
            // Because of that we are expecting one of 2 types here.
            DynamicDocumentPaginator childPaginator       = null;
            ContentPosition          childContentPosition = null;

            if (contentPosition is DocumentSequenceTextPointer)
            {
                DocumentSequenceTextPointer dsTextPointer = (DocumentSequenceTextPointer)contentPosition;

                #pragma warning suppress 6506 // dsTextPointer is obviously not null
                childPaginator       = GetPaginator(dsTextPointer.ChildBlock.DocRef);
                childContentPosition = dsTextPointer.ChildPointer as ContentPosition;
            }

            if (childContentPosition == null)
            {
                throw new ArgumentException(SR.Get(SRID.IDPInvalidContentPosition));
            }

            int childPageNumber = childPaginator.GetPageNumber(childContentPosition);
            int pageNumber;
            _SynthesizeGlobalPageNumber(childPaginator, childPageNumber, out pageNumber);
            return(pageNumber);
        }
Beispiel #2
0
        // Token: 0x06002B79 RID: 11129 RVA: 0x000C66D0 File Offset: 0x000C48D0
        internal int GetPageNumber(ContentPosition contentPosition)
        {
            if (contentPosition == null)
            {
                throw new ArgumentNullException("contentPosition");
            }
            DynamicDocumentPaginator dynamicDocumentPaginator = null;
            ContentPosition          contentPosition2         = null;

            if (contentPosition is DocumentSequenceTextPointer)
            {
                DocumentSequenceTextPointer documentSequenceTextPointer = (DocumentSequenceTextPointer)contentPosition;
                dynamicDocumentPaginator = this.GetPaginator(documentSequenceTextPointer.ChildBlock.DocRef);
                contentPosition2         = (documentSequenceTextPointer.ChildPointer as ContentPosition);
            }
            if (contentPosition2 == null)
            {
                throw new ArgumentException(SR.Get("IDPInvalidContentPosition"));
            }
            int pageNumber = dynamicDocumentPaginator.GetPageNumber(contentPosition2);
            int result;

            this._SynthesizeGlobalPageNumber(dynamicDocumentPaginator, pageNumber, out result);
            return(result);
        }
Beispiel #3
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);
        }