private static String _GetPageString(FixedDocument doc, int translatedPageNo, bool replaceAlefWithAlefHamza) { String pageString = null; Debug.Assert(doc != null); Debug.Assert(translatedPageNo >= 0 && translatedPageNo < doc.PageCount); PageContent pageContent = doc.Pages[translatedPageNo]; Stream pageStream = pageContent.GetPageStream(); bool reverseRTL = true; if (doc.HasExplicitStructure) { reverseRTL = false; } if (pageStream != null) { pageString = _ConstructPageString(pageStream, reverseRTL); if (replaceAlefWithAlefHamza) { // Replace the alef-hamza with the alef. pageString = TextFindEngine.ReplaceAlefHamzaWithAlef(pageString); } } return(pageString); }
// Token: 0x060039B7 RID: 14775 RVA: 0x00105DC4 File Offset: 0x00103FC4 private static int StandardMatchIndexCalculation(string textString, string findPattern, bool matchWholeWord, bool matchLast, bool ignoreCase, CompareInfo compareInfo, bool hasPreceedingSeparatorChar, bool hasFollowingSeparatorChar, out int matchLength) { CompareOptions options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None; int num = -1; int num2 = 0; int i = textString.Length; matchLength = 0; while (i > 0) { num = (matchLast ? compareInfo.LastIndexOf(textString, findPattern, num2 + i - 1, i, options) : compareInfo.IndexOf(textString, findPattern, num2, i, options)); matchLength = findPattern.Length; if (num == -1 || !matchWholeWord || TextFindEngine.IsAtWordBoundary(textString, num, matchLength, hasPreceedingSeparatorChar, hasFollowingSeparatorChar)) { break; } if (matchLast) { num2 = 0; i = num + matchLength - 1; } else { num2 = num + 1; i = textString.Length - num2; } num = -1; } return(num); }
// Token: 0x060039B3 RID: 14771 RVA: 0x00105B0C File Offset: 0x00103D0C internal static TextRange InternalFind(ITextPointer startPosition, ITextPointer endPosition, string findPattern, CultureInfo cultureInfo, bool matchCase, bool matchWholeWord, bool matchLast, bool matchDiacritics, bool matchKashida, bool matchAlefHamza) { Invariant.Assert(startPosition.CompareTo(endPosition) <= 0); ITextPointer textPointer; LogicalDirection direction; if (matchLast) { textPointer = endPosition; direction = LogicalDirection.Backward; } else { textPointer = startPosition; direction = LogicalDirection.Forward; } int num = Math.Max(64, findPattern.Length * 2 * 2); textPointer = textPointer.CreatePointer(); while ((matchLast ? startPosition.CompareTo(textPointer) : textPointer.CompareTo(endPosition)) < 0) { ITextPointer textPointer2 = textPointer.CreatePointer(); char[] array = new char[num]; int[] array2 = new int[num + 1]; int num2 = TextFindEngine.SetFindTextAndFindTextPositionMap(startPosition, endPosition, textPointer, direction, matchLast, array, array2); if (!matchDiacritics || num2 >= findPattern.Length) { int num3 = matchLast ? (array.Length - num2) : 0; bool hasPreceedingSeparatorChar = false; bool hasFollowingSeparatorChar = false; if (matchWholeWord) { TextFindEngine.GetContextualInformation(textPointer2, matchLast ? (-array2[array2.Length - num2 - 1]) : array2[num2], out hasPreceedingSeparatorChar, out hasFollowingSeparatorChar); } string textString = new string(array, num3, num2); int num5; int num4 = TextFindEngine.FindMatchIndexFromFindContent(textString, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza, hasPreceedingSeparatorChar, hasFollowingSeparatorChar, out num5); if (num4 != -1) { ITextPointer textPointer3 = textPointer2.CreatePointer(); textPointer3.MoveByOffset(matchLast ? (-array2[num3 + num4]) : array2[num4]); ITextPointer textPointer4 = textPointer2.CreatePointer(); textPointer4.MoveByOffset(matchLast ? (-array2[num3 + num4 + num5]) : array2[num4 + num5]); return(new TextRange(textPointer3, textPointer4)); } if (num2 > findPattern.Length) { textPointer = textPointer2.CreatePointer(); textPointer.MoveByOffset(matchLast ? (-array2[array.Length - num2 + findPattern.Length]) : array2[num2 - findPattern.Length]); } } } return(null); }
// Token: 0x060039B4 RID: 14772 RVA: 0x00105CA4 File Offset: 0x00103EA4 private static void GetContextualInformation(ITextPointer position, int oppositeEndOffset, out bool hasPreceedingSeparatorChar, out bool hasFollowingSeparatorChar) { ITextPointer position2 = position.CreatePointer(oppositeEndOffset, position.LogicalDirection); if (oppositeEndOffset < 0) { hasPreceedingSeparatorChar = TextFindEngine.HasNeighboringSeparatorChar(position2, LogicalDirection.Backward); hasFollowingSeparatorChar = TextFindEngine.HasNeighboringSeparatorChar(position, LogicalDirection.Forward); return; } hasPreceedingSeparatorChar = TextFindEngine.HasNeighboringSeparatorChar(position, LogicalDirection.Backward); hasFollowingSeparatorChar = TextFindEngine.HasNeighboringSeparatorChar(position2, LogicalDirection.Forward); }
// Token: 0x060039B6 RID: 14774 RVA: 0x00105D68 File Offset: 0x00103F68 private static int FindMatchIndexFromFindContent(string textString, string findPattern, CultureInfo cultureInfo, bool matchCase, bool matchWholeWord, bool matchLast, bool matchDiacritics, bool matchKashida, bool matchAlefHamza, bool hasPreceedingSeparatorChar, bool hasFollowingSeparatorChar, out int matchLength) { bool flag; bool flag2; TextFindEngine.InitializeBidiFlags(findPattern, out flag, out flag2); CompareInfo compareInfo = cultureInfo.CompareInfo; int result; if (!matchDiacritics && flag) { result = TextFindEngine.BidiIgnoreDiacriticsMatchIndexCalculation(textString, findPattern, matchKashida, matchAlefHamza, matchWholeWord, matchLast, !matchCase, compareInfo, hasPreceedingSeparatorChar, hasFollowingSeparatorChar, out matchLength); } else { result = TextFindEngine.StandardMatchIndexCalculation(textString, findPattern, matchWholeWord, matchLast, !matchCase, compareInfo, hasPreceedingSeparatorChar, hasFollowingSeparatorChar, out matchLength); } return(result); }
private static CompareOptions _InitializeSearch(CultureInfo cultureInfo, bool matchCase, bool matchAlefHamza, bool matchDiacritics, ref string findPattern, out bool replaceAlefWithAlefHamza) { CompareOptions compareOptions = CompareOptions.None; replaceAlefWithAlefHamza = false; if (!matchCase) { compareOptions |= CompareOptions.IgnoreCase; } bool stringContainedBidiCharacter; bool stringContainedAlefCharacter; // Initialize Bidi flags whether the string contains the bidi characters // or alef character. TextFindEngine.InitializeBidiFlags( findPattern, out stringContainedBidiCharacter, out stringContainedAlefCharacter); if (stringContainedAlefCharacter && !matchAlefHamza) { // Replace the alef-hamza with the alef. findPattern = TextFindEngine.ReplaceAlefHamzaWithAlef(findPattern); replaceAlefWithAlefHamza = true; } // Ignore Bidi diacritics that use for only Bidi language. if (!matchDiacritics && stringContainedBidiCharacter) { // Ignore Bidi diacritics with checking non-space character. compareOptions |= CompareOptions.IgnoreNonSpace; } return(compareOptions); }
// 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)); }
// Token: 0x060039BF RID: 14783 RVA: 0x0010640C File Offset: 0x0010460C private static bool IsAtWordBoundary(string textString, int matchIndex, int matchLength, bool hasPreceedingSeparatorChar, bool hasFollowingSeparatorChar) { bool result = false; int length = textString.Length; Invariant.Assert(matchIndex + matchLength <= length); if (matchIndex == 0) { if (hasPreceedingSeparatorChar) { if (matchIndex + matchLength < length) { if (TextFindEngine.IsSeparatorChar(textString[matchIndex + matchLength])) { result = true; } } else if (hasFollowingSeparatorChar) { result = true; } } } else if (matchIndex + matchLength == length) { if (TextFindEngine.IsSeparatorChar(textString[matchIndex - 1]) && hasFollowingSeparatorChar) { result = true; } } else if (TextFindEngine.IsSeparatorChar(textString[matchIndex - 1]) && TextFindEngine.IsSeparatorChar(textString[matchIndex + matchLength])) { result = true; } return(result); }
// Token: 0x060039B5 RID: 14773 RVA: 0x00105CE8 File Offset: 0x00103EE8 private static bool HasNeighboringSeparatorChar(ITextPointer position, LogicalDirection direction) { ITextPointer textPointer = position.GetNextInsertionPosition(direction); if (textPointer == null) { return(true); } if (position.CompareTo(textPointer) > 0) { ITextPointer textPointer2 = position; position = textPointer; textPointer = textPointer2; } int offsetToPosition = position.GetOffsetToPosition(textPointer); char[] array = new char[offsetToPosition]; int[] findTextPositionMap = new int[offsetToPosition + 1]; int num = TextFindEngine.SetFindTextAndFindTextPositionMap(position, textPointer, position.CreatePointer(), LogicalDirection.Forward, false, array, findTextPositionMap); if (num == 0) { return(true); } bool result; if (direction == LogicalDirection.Forward) { result = TextFindEngine.IsSeparatorChar(array[0]); } else { result = TextFindEngine.IsSeparatorChar(array[num - 1]); } return(result); }
// Token: 0x06002E73 RID: 11891 RVA: 0x000D272C File Offset: 0x000D092C private static CompareOptions _InitializeSearch(CultureInfo cultureInfo, bool matchCase, bool matchAlefHamza, bool matchDiacritics, ref string findPattern, out bool replaceAlefWithAlefHamza) { CompareOptions compareOptions = CompareOptions.None; replaceAlefWithAlefHamza = false; if (!matchCase) { compareOptions |= CompareOptions.IgnoreCase; } bool flag; bool flag2; TextFindEngine.InitializeBidiFlags(findPattern, out flag, out flag2); if (flag2 && !matchAlefHamza) { findPattern = TextFindEngine.ReplaceAlefHamzaWithAlef(findPattern); replaceAlefWithAlefHamza = true; } if (!matchDiacritics && flag) { compareOptions |= CompareOptions.IgnoreNonSpace; } return(compareOptions); }
// Token: 0x060039BC RID: 14780 RVA: 0x00106178 File Offset: 0x00104378 private static int SetFindTextAndFindTextPositionMap(ITextPointer startPosition, ITextPointer endPosition, ITextPointer navigator, LogicalDirection direction, bool matchLast, char[] findText, int[] findTextPositionMap) { Invariant.Assert(startPosition.CompareTo(navigator) <= 0); Invariant.Assert(endPosition.CompareTo(navigator) >= 0); int num = 0; int num2 = 0; if (matchLast && num2 == 0) { findTextPositionMap[findTextPositionMap.Length - 1] = 0; } while ((matchLast ? startPosition.CompareTo(navigator) : navigator.CompareTo(endPosition)) < 0) { switch (navigator.GetPointerContext(direction)) { case TextPointerContext.None: case TextPointerContext.ElementStart: case TextPointerContext.ElementEnd: if (TextFindEngine.IsAdjacentToFormatElement(navigator, direction)) { num++; } else if (!matchLast) { findText[num2] = '\n'; findTextPositionMap[num2] = num2 + num; num2++; } else { num2++; findText[findText.Length - num2] = '\n'; findTextPositionMap[findText.Length - num2] = num2 + num; } navigator.MoveToNextContextPosition(direction); break; case TextPointerContext.Text: { int num3 = navigator.GetTextRunLength(direction); num3 = Math.Min(num3, findText.Length - num2); if (!matchLast) { num3 = Math.Min(num3, navigator.GetOffsetToPosition(endPosition)); navigator.GetTextInRun(direction, findText, num2, num3); for (int i = num2; i < num2 + num3; i++) { findTextPositionMap[i] = i + num; } } else { num3 = Math.Min(num3, startPosition.GetOffsetToPosition(navigator)); navigator.GetTextInRun(direction, findText, findText.Length - num2 - num3, num3); int num4 = findText.Length - num2 - 1; for (int j = num2; j < num2 + num3; j++) { findTextPositionMap[num4--] = j + num + 1; } } navigator.MoveByOffset(matchLast ? (-num3) : num3); num2 += num3; break; } case TextPointerContext.EmbeddedElement: if (!matchLast) { findText[num2] = ''; findTextPositionMap[num2] = num2 + num; num2++; } else { num2++; findText[findText.Length - num2] = ''; findTextPositionMap[findText.Length - num2] = num2 + num; } navigator.MoveToNextContextPosition(direction); break; } if (num2 >= findText.Length) { break; } } if (!matchLast) { if (num2 > 0) { findTextPositionMap[num2] = findTextPositionMap[num2 - 1] + 1; } else { findTextPositionMap[0] = 0; } } return(num2); }
// Token: 0x060039B8 RID: 14776 RVA: 0x00105E50 File Offset: 0x00104050 private static int BidiIgnoreDiacriticsMatchIndexCalculation(string textString, string findPattern, bool matchKashida, bool matchAlefHamza, bool matchWholeWord, bool matchLast, bool ignoreCase, CompareInfo compareInfo, bool hasPreceedingSeparatorChar, bool hasFollowingSeparatorChar, out int matchLength) { int num = -1; int num2 = matchLast ? (textString.Length - 1) : 0; int num3 = matchLast ? -1 : textString.Length; int num4 = matchLast ? -1 : 1; if (Environment.OSVersion.Version.Major >= 6) { uint num5 = 2U; if (ignoreCase) { num5 |= 1U; } if (matchLast) { num5 |= 8388608U; } if (matchKashida) { textString = textString.Replace('ـ', '0'); findPattern = findPattern.Replace('ـ', '0'); } if (matchAlefHamza) { textString = textString.Replace('آ', '0'); textString = textString.Replace('أ', '1'); textString = textString.Replace('إ', '2'); findPattern = findPattern.Replace('آ', '0'); findPattern = findPattern.Replace('أ', '1'); findPattern = findPattern.Replace('إ', '2'); } matchLength = 0; if (matchWholeWord) { int num6 = num2; while (num == -1) { if (num6 == num3) { break; } for (int i = num6; i < textString.Length; i++) { string sourceString = textString.Substring(num6, i - num6 + 1); int num7 = TextFindEngine.FindNLSString(compareInfo.LCID, num5, sourceString, findPattern, out matchLength); if (num7 >= 0 && TextFindEngine.IsAtWordBoundary(textString, num6 + num7, matchLength, hasPreceedingSeparatorChar, hasFollowingSeparatorChar)) { num = num6 + num7; break; } } num6 += num4; } } else { num = TextFindEngine.FindNLSString(compareInfo.LCID, num5, textString, findPattern, out matchLength); } } else { CompareOptions options = CompareOptions.IgnoreNonSpace | (ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None); matchLength = 0; int num8 = num2; while (num == -1 && num8 != num3) { for (int j = num8; j < textString.Length; j++) { if (compareInfo.Compare(textString, num8, j - num8 + 1, findPattern, 0, findPattern.Length, options) == 0 && (!matchWholeWord || TextFindEngine.IsAtWordBoundary(textString, num8, j - num8 + 1, hasPreceedingSeparatorChar, hasFollowingSeparatorChar)) && (!matchKashida || TextFindEngine.IsKashidaMatch(textString.Substring(num8, j - num8 + 1), findPattern, compareInfo)) && (!matchAlefHamza || TextFindEngine.IsAlefHamzaMatch(textString.Substring(num8, j - num8 + 1), findPattern, compareInfo))) { num = num8; matchLength = j - num8 + 1; break; } } num8 += num4; } } return(num); }
// 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); }