/// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public System.Object Clone()
        {
            TWord oNewWord = (TWord)MemberwiseClone();

            oNewWord.m_oChars = new TChars();
            foreach (TChar oChar in m_oChars)
            {
                oNewWord.m_oChars.Add((TChar)oChar.Clone());
            }
            return(oNewWord);
        }
Beispiel #2
0
 /// <summary>
 /// Sets the word.
 /// </summary>
 /// <param name="oWord">The o word.</param>
 public void SetWord(TWord oWord)
 {
     m_oWorkingWord = oWord;
 }
        private void AddWord(TWord oNewWord)
        {
            // Use the Deskew method to use the same Y-Axis
            TOCRRect oNewWordRect = Deskew(oNewWord.Rect);

            // Build candidate lines
            List <TLine> oCandidateLines = new List <TLine>();

            foreach (TLine oLine in m_oLines)
            {
                if (Deskew(oLine.Rect).Bottom + MMtoPixel(20) < oNewWordRect.Top)
                {
                    continue;
                }

                if (Deskew(oLine.Rect).Top - MMtoPixel(20) > oNewWordRect.Bottom)
                {
                    break;
                }

                oCandidateLines.Add(oLine);
            }

            // Try 1: Find closer matching on top
            foreach (TLine oLine in oCandidateLines)
            {
                foreach (TWord oWord in oLine)
                {
                    TOCRRect oWordRect = Deskew(oWord.Rect);
                    // If the word in
                    if (oWordRect.IsEqualTop(oNewWordRect))
                    {
                        oLine.AddWord(oNewWord);
                        return;
                    }
                }
            }

            // Now we remove lines that one word is above or beneath the new word
            List <TLine> oCandidateLines2 = new List <TLine>();

            foreach (TLine oLine in oCandidateLines)
            {
                bool bLineOk = true;
                foreach (TWord oWord in oLine)
                {
                    TOCRRect oWordRect = Deskew(oWord.Rect);

                    // Word is above or beneath the new word
                    if ((oNewWordRect.Top > oWordRect.Bottom) || (oNewWordRect.Bottom < oWordRect.Top))
                    {
                        bLineOk = false;
                        break;
                    }
                }
                if (bLineOk)
                {
                    oCandidateLines2.Add(oLine);
                }
            }


            // Try 2: Find closer matching on bottom
            foreach (TLine oLine in oCandidateLines2)
            {
                foreach (TWord oWord in oLine)
                {
                    TOCRRect oWordRect = Deskew(oWord.Rect);
                    // If the word in
                    if (oWordRect.IsEqualBottom(oNewWordRect))
                    {
                        oLine.AddWord(oNewWord);
                        return;
                    }
                }
            }

            // Try 3: Find far matching from top
            foreach (TLine oLine in oCandidateLines2)
            {
                foreach (TWord oWord in oLine)
                {
                    TOCRRect oWordRect = Deskew(oWord.Rect);
                    if (Math.Abs(oNewWordRect.Top - oWordRect.Top) <=
                        Math.Min(MMtoPixel(2), oWordRect.Height / 2))
                    {
                        oLine.AddWord(oNewWord);
                        return;
                    }
                }
            }
            // Try 4: Find far matching from bottom
            foreach (TLine oLine in oCandidateLines2)
            {
                foreach (TWord oWord in oLine)
                {
                    TOCRRect oWordRect = Deskew(oWord.Rect);

                    if (Math.Abs(oNewWordRect.Bottom - oWordRect.Bottom) <=
                        Math.Min(MMtoPixel(2), oWordRect.Height / 2))
                    {
                        oLine.AddWord(oNewWord);
                        return;
                    }
                }
            }

            // We do not found any line that can take the word, so we create a new line
            TLine oNewLine = new TLine();

            oNewLine.AddWord(oNewWord);
            AddLine(oNewLine);
        }