Ejemplo n.º 1
0
        // Token: 0x06002E75 RID: 11893 RVA: 0x000D2854 File Offset: 0x000D0A54
        private static string _GetPageString(FixedDocument doc, int translatedPageNo, bool replaceAlefWithAlefHamza)
        {
            string      text        = null;
            PageContent pageContent = doc.Pages[translatedPageNo];
            Stream      pageStream  = pageContent.GetPageStream();
            bool        reverseRTL  = true;

            if (doc.HasExplicitStructure)
            {
                reverseRTL = false;
            }
            if (pageStream != null)
            {
                text = FixedFindEngine._ConstructPageString(pageStream, reverseRTL);
                if (replaceAlefWithAlefHamza)
                {
                    text = TextFindEngine.ReplaceAlefHamzaWithAlef(text);
                }
            }
            return(text);
        }
        // Token: 0x060039B2 RID: 14770 RVA: 0x001059FC File Offset: 0x00103BFC
        public static ITextRange Find(ITextPointer findContainerStartPosition, ITextPointer findContainerEndPosition, string findPattern, FindFlags flags, CultureInfo cultureInfo)
        {
            if (findContainerStartPosition == null || findContainerEndPosition == null || findContainerStartPosition.CompareTo(findContainerEndPosition) == 0 || findPattern == null || findPattern == string.Empty)
            {
                return(null);
            }
            bool matchCase       = (flags & FindFlags.MatchCase) > FindFlags.None;
            bool flag            = (flags & FindFlags.FindWholeWordsOnly) > FindFlags.None;
            bool matchLast       = (flags & FindFlags.FindInReverse) > FindFlags.None;
            bool matchDiacritics = (flags & FindFlags.MatchDiacritics) > FindFlags.None;
            bool matchKashida    = (flags & FindFlags.MatchKashida) > FindFlags.None;
            bool matchAlefHamza  = (flags & FindFlags.MatchAlefHamza) > FindFlags.None;

            if (flag)
            {
                ushort[] array  = new ushort[1];
                ushort[] array2 = new ushort[1];
                char[]   array3 = findPattern.ToCharArray();
                SafeNativeMethods.GetStringTypeEx(0U, 1U, new char[]
                {
                    array3[0]
                }, 1, array);
                SafeNativeMethods.GetStringTypeEx(0U, 1U, new char[]
                {
                    array3[findPattern.Length - 1]
                }, 1, array2);
                if ((array[0] & 8) != 0 || (array[0] & 64) != 0 || (array2[0] & 8) != 0 || (array2[0] & 64) != 0)
                {
                    flag = false;
                }
            }
            if (findContainerStartPosition is DocumentSequenceTextPointer || findContainerStartPosition is FixedTextPointer)
            {
                return(FixedFindEngine.Find(findContainerStartPosition, findContainerEndPosition, findPattern, cultureInfo, matchCase, flag, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
            }
            return(TextFindEngine.InternalFind(findContainerStartPosition, findContainerEndPosition, findPattern, cultureInfo, matchCase, flag, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------
        //
        // Public methods
        //
        //---------------------------------------------------------------------

        #region Public methods

        /// <summary>
        /// Performs find operation on of a given text range.
        /// </summary>
        /// <param name="findContainerStartPosition">Text position to start search.</param>
        /// <param name="findContainerEndPosition">Text position to end search.</param>
        /// <param name="findPattern">Pattern to find.</param>
        /// <param name="flags">Find flags.</param>
        /// <param name="cultureInfo">Culture specific information.</param>
        /// <returns>TextRange for the result or <c>null</c></returns>
        /// <remarks>
        /// Very limited functionality for now
        /// </remarks>
        public static ITextRange Find(
            ITextPointer findContainerStartPosition,
            ITextPointer findContainerEndPosition,
            string findPattern,
            FindFlags flags,
            CultureInfo cultureInfo)
        {
            //  throw exceptions here
            if (findContainerStartPosition == null ||
                findContainerEndPosition == null ||
                findContainerStartPosition.CompareTo(findContainerEndPosition) == 0 ||
                findPattern == null ||
                findPattern == string.Empty)
            {
                return(null);
            }

            TextRange findResult      = null;
            bool      matchCase       = (flags & FindFlags.MatchCase) != 0;
            bool      matchWholeWord  = (flags & FindFlags.FindWholeWordsOnly) != 0;
            bool      matchLast       = (flags & FindFlags.FindInReverse) != 0;
            bool      matchDiacritics = (flags & FindFlags.MatchDiacritics) != 0;
            bool      matchKashida    = (flags & FindFlags.MatchKashida) != 0;
            bool      matchAlefHamza  = (flags & FindFlags.MatchAlefHamza) != 0;

            if (matchWholeWord)
            {
                UInt16[] findPatternStartCharType1 = new UInt16[1];
                UInt16[] findPatternEndCharType1   = new UInt16[1];
                char[]   charFindPattern           = findPattern.ToCharArray();

                // Get the character type for the start/end character of the find pattern.
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[0] }, 1, findPatternStartCharType1);
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[findPattern.Length - 1] }, 1, findPatternEndCharType1);

                // Reset the finding whole word flag if FindPattern includes the space
                // or blank character at the start or end position.
                if ((findPatternStartCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternStartCharType1[0] & SafeNativeMethods.C1_BLANK) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_BLANK) != 0)
                {
                    matchWholeWord = false;
                }
            }

            //If this we're searching on a Fixed layout, we need to do a faster search that takes into accout
            //page-per-stream scenarios
            if (findContainerStartPosition is DocumentSequenceTextPointer ||
                findContainerStartPosition is FixedTextPointer)
            {
                return(FixedFindEngine.Find(findContainerStartPosition,
                                            findContainerEndPosition,
                                            findPattern,
                                            cultureInfo,
                                            matchCase,
                                            matchWholeWord,
                                            matchLast,
                                            matchDiacritics,
                                            matchKashida,
                                            matchAlefHamza));
            }

            // Find the text with the specified option flags.
            findResult = InternalFind(
                findContainerStartPosition,
                findContainerEndPosition,
                findPattern,
                cultureInfo,
                matchCase,
                matchWholeWord,
                matchLast,
                matchDiacritics,
                matchKashida,
                matchAlefHamza);

            return(findResult);
        }
Ejemplo n.º 4
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);
        }