/// <summary> /// Normalizes the heb lines. /// </summary> /// <param name="line">The line.</param> public static void NormalizeHebLines(TLine line) { string lineData = line.ToString(); if (Regex.IsMatch(lineData, "\\p{IsHebrew}")) { int[] indexes, lengths, originalIndexes; string nbidi = NBidi.NBidi.LogicalToVisual(lineData, out indexes, out lengths); originalIndexes = new int[indexes.Length]; for (int i = 0; i < indexes.Length; i++) { originalIndexes[indexes[i]] = i; } TChar[] finalTCharString = CreateHebTCharString(line, originalIndexes, lineData); ReplaceLineWithNewWords(line.Words, finalTCharString); } }
/// <summary> /// Creates the hebrew character string. /// </summary> /// <param name="line">The line.</param> /// <param name="newIndexes">The new indexes.</param> /// <param name="lineData">The line data.</param> /// <returns></returns> private static TChar[] CreateHebTCharString(TLine line, int[] newIndexes, string lineData) { TChar[] tempTCharString = new TChar[lineData.Length]; List <TChar> chrlist = new List <TChar>(); chrlist.AddRange(line.Words[0].Chars); for (int i = 1; i < line.Words.Count; i++) { chrlist.Add(new TChar(' ', 100, new TOCRRect())); chrlist.AddRange(line.Words[i].Chars); } for (int i = 0; i < chrlist.Count; i++) { tempTCharString[newIndexes[i]] = chrlist[i]; } return(tempTCharString); }
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); }
/// <summary> /// Adds the line. /// </summary> /// <param name="oLine">The o line.</param> public void AddLine(TLine oLine) { m_oLines.Add(oLine); m_oLines.Sort(new CompareTLines(this)); m_oRect.Add(oLine.Rect); }