private RecognitionStatistics computeStatisticsForBlock(int pageIndex, FREngine.IBlock block) { RecognitionStatistics result = new RecognitionStatistics(); if (block.Type == FREngine.BlockTypeEnum.BT_Table) { FREngine.TableBlock tableBlock = block.GetAsTableBlock(); for (int iCell = 0; iCell < tableBlock.Cells.Count; iCell++) { result += computeStatisticsForBlock(pageIndex, tableBlock.Cells[iCell].Block); } } else if (block.Type == FREngine.BlockTypeEnum.BT_Text) { FREngine.ITextBlock textBlock = block.GetAsTextBlock(); int paragraphsCount = textBlock.Text.Paragraphs.Count; for (int iPar = 0; iPar < paragraphsCount; iPar++) { FREngine.IParagraph par = textBlock.Text.Paragraphs[iPar]; string text = par.Text; result.TotalCharsCount += text.Length; FREngine.CharParams charParams = engine.CreateCharParams(); for (int iChar = 0; iChar < text.Length; iChar++) { par.GetCharParams(iChar, charParams); if (charParams.IsSuspicious) { result.SuspiciousCharsCount++; } } } } return(result); }
private CustomBlock buildTextFromBlock(FREngine.IBlock block, int iBlock) { if (block.Type == FREngine.BlockTypeEnum.BT_Table) { FREngine.ITableBlock tableBlock = block.GetAsTableBlock(); CustomTable cstable = new CustomTable(); cstable.X = tableBlock.Region.BoundingRectangle.Left; cstable.Y = tableBlock.Region.BoundingRectangle.Top; cstable.Width = tableBlock.Region.BoundingRectangle.Width; cstable.Height = tableBlock.Region.BoundingRectangle.Height; cstable.ParentIndex = Page.Index; cstable.Index = tableIndex; tableIndex++; List <CustomBlock> blockItems = new List <CustomBlock>(); for (int iCell = 0; iCell < tableBlock.Cells.Count; iCell++) { FREngine.ITableCell cell = tableBlock.Cells[iCell]; CustomBlock csBlock = buildTextFromBlock(cell.Block, iCell); if (csBlock != null) { blockItems.Add(csBlock); //blockAll.Add(csBlock); } } var rowItemsGroup = blockItems.GroupBy(x => x.Y); int iRow = 0; foreach (var item in rowItemsGroup) { CustomRow rowItem = new CustomRow() { Width = cstable.Width, Height = item.Max(x => x.Height), BlockItems = item.ToList(), X = item.Min(x => x.X), Y = item.Min(x => x.Y), Value = string.Join("\t", item.Select(x => x.Value)), Index = iRow, ParentIndex = iBlock, }; cstable.RowItems.Add(rowItem); iRow++; } cstable.Value = string.Join("\n", cstable.RowItems.Select(x => x.Value));; // //string.Join("|", cstable.BlockItems.Select(x => x.Value)); Page.TableItems.Add(cstable); return(null); } if (block.Type != FREngine.BlockTypeEnum.BT_Text) { return(null); } CustomBlock result = new CustomBlock(); FREngine.ITextBlock textBlock = block.GetAsTextBlock(); result.Index = iBlock; result.X = textBlock.Region.BoundingRectangle.Left; result.Y = textBlock.Region.BoundingRectangle.Top; result.Width = textBlock.Region.BoundingRectangle.Width; result.Height = textBlock.Region.BoundingRectangle.Height; for (int iPar = 0; iPar < textBlock.Text.Paragraphs.Count; iPar++) { FREngine.IParagraph par = textBlock.Text.Paragraphs[iPar]; result.LineItems.AddRange(buildTextFromParagraph(par, iBlock)); } result.Value = string.Join("\n", result.LineItems.Select(x => x.Value)); return(result); }