示例#1
0
        private void AddToColGaps(List<TextRecord> txtRow)
        {
            // this keeps a record of gaps between texts
            if (txtRow.Count == 0)
                return;

            TextRecordSorter trs = new TextRecordSorter();
            txtRow.Sort(trs);

            // colgaps are the spaces between the texts - we accumulate these
            // then we will know where the vertical lines will go
            int iLeft = 0;
            int iNextLeft = 0;
            int iRight = 0;
            for (int i = 0; i <= txtRow.Count; i++)
            {
                if (iLeft == m_iMaxX)
                    continue;
                if (i == txtRow.Count)
                    iRight = m_iMaxX;
                else
                {
                    TextRecord tr = txtRow[i];
                    Rectangle rc = tr.ActualRectangle();
                    iRight = rc.Left;
                    if (iRight <= iLeft + 1)
                    {
                        iLeft = rc.Right;
                        continue;   // same cell
                    }
                    iNextLeft = rc.Right;
                }

                bool bAdded = AddGap(iLeft, iRight);

                // not found -> add it on
                if (!bAdded)
                {
                    m_ColGaps.Add(new Point(iLeft, iRight));
                }
                iLeft = iNextLeft;
            }

        }
示例#2
0
        private void UnMergeCellsForTextsInShadedAreas(List<TextRecord> texts, List<FilledArea> areas)
        {
            if (MergedCells.Count == 0 || texts.Count == 0 || areas.Count == 0)
                return;

            // ok. sort the texts on Y. sort the areas on Y
            TextRecordSorter trs = new TextRecordSorter();
            texts.Sort(trs);
            FilledAreaSorter fas = new FilledAreaSorter();
            areas.Sort(fas);
            // trundle through each area, look for texts in it. the sorting makes it quicker

            foreach (FilledArea fa in areas)
            {
                // if filled area is not > 1 cell continue;
                Rectangle rcFilledArea = DetermineCellRange(fa.Bounds);
                if (fa.Bounds.Height < 2 && fa.Bounds.Width < 2)
                    continue;

                Rectangle rcFaCells = DetermineCellRange(fa.Bounds);
                List<Rectangle> rcThisLine = new List<Rectangle>();
                foreach (TextRecord tr in texts)
                {
                    if (tr.Text.Bounds.Bottom < fa.Bounds.Top)
                        continue;   // text before area

                    if (!fa.Bounds.Contains(tr.Text.Bounds.Location))
                    {   // deal with current lineTexts
                        SplitCells(rcFaCells, rcThisLine);
                        rcThisLine.Clear();
                        if (fa.Bounds.Bottom < tr.Text.Bounds.Top)
                            break;
                        continue; //  same line
                    }

                    Rectangle rcTextCell = DetermineCellRange(tr.Text.Bounds);

                    if (rcThisLine.Count == 0)
                    {
                        rcThisLine.Add(rcTextCell);
                    }
                    else if (Math.Abs(rcTextCell.Top - rcThisLine[rcThisLine.Count - 1].Top) == 0)
                    {
                        rcThisLine.Add(rcTextCell);
                    }
                    else // start of next line in filled area
                    {
                        SplitCells(rcFaCells, rcThisLine);
                        rcThisLine.Clear();
                        rcThisLine.Add(rcTextCell);
                    }
                }
                SplitCells(rcFaCells, rcThisLine);

            }
        }
示例#3
0
        private void PutTextInCells(List<TextRecord> list)
        {
            TextRecordSorter trs = new TextRecordSorter();
            list.Sort(trs);

            foreach (TextRecord tr in list)
            {                
                Rectangle r = DetermineCellRange(tr.ActualRectangle());

                if (r.Top >= m_cells.GetLength(0) || r.Left >= m_cells.GetLength(1))
                    continue;

                if (tr.Text.Bounds.Height < 5)  // too squished
                    continue;

                if (m_cells[r.Top, r.Left] == null)
                    m_cells[r.Top, r.Left] = new Cell();

                for (int i = 0; i < r.Width; i++)
                {
                    for (int j = 0; j < r.Height; j++)
                    {
                        if (i == 0 & j == 0)
                            continue;

                        if (m_cells[r.Top + j, r.Left + i] != null)
                        {
                            // throw new InvalidOperationException();
                            continue;
                        }

                        m_cells[r.Top + j, r.Left + i] = new DummyCell();

                    }
                }

                m_cells[r.Top, r.Left].Accept(tr, r);
            }
        }