public OcrResultIterator(OcrResultIterator i)
 {
     result    = i.result;
     lineIndex = i.lineIndex;
     wordIndex = i.wordIndex;
     charIndex = i.charIndex;
 }
        public bool FindWord(string searchWord, out Point position)
        {
            bool  result      = false;
            float minDistance = float.MaxValue;
            Point center      = new Point(bitmap.Width / 2, bitmap.Height / 2);

            position = new Point(0, 0);

            debugText += ocrResult.Text;

            // We remove whitespace in both the search word and the recognition result
            // to allow searching for longer phrases
            searchWord = Sanitize(searchWord);
            if (searchWord.Length > 0)
            {
                OcrResultIterator i = new OcrResultIterator(ocrResult);
                //foreach (OcrLine ocrLine in ocrResult.Lines)
                {
                    //foreach (OcrWord ocrWord in ocrLine.Words)
                    while (!i.Done())
                    {
                        //string word = ocrWord.Text;

                        // Sometimes the engine splits words when it shouldn't
                        // Append following words until we have enough text to possibly fit the search word
                        OcrWord           ocrWord = i.NextWord();
                        string            word    = Sanitize(ocrWord.Text);
                        OcrResultIterator j       = new OcrResultIterator(i);
                        while (word.Length < searchWord.Length && !j.Done())
                        {
                            ocrWord = j.NextWord();
                            word   += Sanitize(ocrWord.Text);
                        }

                        debugText += "\r\nWord: '" + word + "'";
                        if (word.Contains(searchWord))
                        {
                            debugText += "\r\n*** Word match!";
                            Windows.Foundation.Rect rect = ocrWord.BoundingRect;
                            Point wordCenter             = new Point((int)(rect.Left + rect.Right) / 2, (int)(rect.Top + rect.Bottom) / 2);
                            int   dx       = wordCenter.X - center.X;
                            int   dy       = wordCenter.Y - center.Y;
                            float distance = (float)Math.Sqrt(dx * dx + dy * dy);
                            if (distance <= minDistance)
                            {
                                debugText  += "\r\n*** Closest!";
                                position    = wordCenter;
                                result      = true;
                                minDistance = distance;
                            }
                        }
                    }
                }
            }

            return(result);
        }