public void AddRow(FixedSOMTableRow row)
 {
     base.Add(row);
     int colCount = row.SemanticBoxes.Count;
     if (colCount > _numCols)
     {
         _numCols = colCount;
     }
 }
Example #2
0
        // Token: 0x06002E20 RID: 11808 RVA: 0x000D05A4 File Offset: 0x000CE7A4
        public void AddRow(FixedSOMTableRow row)
        {
            base.Add(row);
            int count = row.SemanticBoxes.Count;

            if (count > this._numCols)
            {
                this._numCols = count;
            }
        }
Example #3
0
 internal void DeleteEmptyRows()
 {
     for (int i = 0; i < this.SemanticBoxes.Count;)
     {
         FixedSOMTableRow row = this.SemanticBoxes[i] as FixedSOMTableRow;
         Debug.Assert(row != null);
         if (row != null && row.IsEmpty && row.BoundingRect.Height < _minRowHeight)
         {
             this.SemanticBoxes.RemoveAt(i);
         }
         else
         {
             i++;
         }
     }
 }
Example #4
0
        // Token: 0x06002E27 RID: 11815 RVA: 0x000D081C File Offset: 0x000CEA1C
        internal void DeleteEmptyRows()
        {
            int i = 0;

            while (i < base.SemanticBoxes.Count)
            {
                FixedSOMTableRow fixedSOMTableRow = base.SemanticBoxes[i] as FixedSOMTableRow;
                if (fixedSOMTableRow != null && fixedSOMTableRow.IsEmpty && fixedSOMTableRow.BoundingRect.Height < 10.0)
                {
                    base.SemanticBoxes.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }
Example #5
0
        // Token: 0x06002E21 RID: 11809 RVA: 0x000D05D4 File Offset: 0x000CE7D4
        public bool AddContainer(FixedSOMContainer container)
        {
            Rect   boundingRect = container.BoundingRect;
            double num          = boundingRect.Height * 0.2;
            double num2         = boundingRect.Width * 0.2;

            boundingRect.Inflate(-num2, -num);
            if (base.BoundingRect.Contains(boundingRect))
            {
                foreach (FixedSOMSemanticBox fixedSOMSemanticBox in base.SemanticBoxes)
                {
                    FixedSOMTableRow fixedSOMTableRow = (FixedSOMTableRow)fixedSOMSemanticBox;
                    if (fixedSOMTableRow.BoundingRect.Contains(boundingRect))
                    {
                        foreach (FixedSOMSemanticBox fixedSOMSemanticBox2 in fixedSOMTableRow.SemanticBoxes)
                        {
                            FixedSOMTableCell fixedSOMTableCell = (FixedSOMTableCell)fixedSOMSemanticBox2;
                            if (fixedSOMTableCell.BoundingRect.Contains(boundingRect))
                            {
                                fixedSOMTableCell.AddContainer(container);
                                FixedSOMFixedBlock fixedSOMFixedBlock = container as FixedSOMFixedBlock;
                                if (fixedSOMFixedBlock != null)
                                {
                                    if (fixedSOMFixedBlock.IsRTL)
                                    {
                                        this._RTLCount++;
                                    }
                                    else
                                    {
                                        this._LTRCount++;
                                    }
                                }
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            return(false);
        }
Example #6
0
        private void _DetectTables()
        {
            double minLineSeparation = FixedSOMLineRanges.MinLineSeparation;

            List <FixedSOMLineRanges> horizontal = _lines.HorizontalLines;
            List <FixedSOMLineRanges> vertical   = _lines.VerticalLines;

            if (horizontal.Count < 2 || vertical.Count < 2)
            {
                return;
            }

            List <FixedSOMTableRow> tableRows  = new List <FixedSOMTableRow>();
            FixedSOMTableRow        currentRow = null;

            //iterate through
            for (int h = 0; h < horizontal.Count; h++)
            {
                int v               = 0;
                int h2              = -1;
                int hSeg2           = -1;
                int hLastCellBottom = -1;
                int vLastCellRight  = -1;

                double dropLine = horizontal[h].Line + minLineSeparation;
                //loop through each line segment on this Y value
                for (int hSeg = 0; hSeg < horizontal[h].Count; hSeg++)
                {
                    // X range for this segment -- allow some margin for error
                    double hStart = horizontal[h].Start[hSeg] - minLineSeparation;
                    double hEnd   = horizontal[h].End[hSeg] + minLineSeparation;

                    // no cell has been started
                    int vCellStart = -1;
                    while (v < vertical.Count && vertical[v].Line < hStart)
                    {
                        v++;
                    }
                    for (; v < vertical.Count && vertical[v].Line < hEnd; v++)
                    {
                        int vSeg = vertical[v].GetLineAt(dropLine);
                        if (vSeg != -1)
                        {
                            double vBottom = vertical[v].End[vSeg];
                            if (vCellStart != -1 && horizontal[h2].Line <vBottom + minLineSeparation &&
                                                                         horizontal[h2].End[hSeg2] + minLineSeparation> vertical[v].Line)
                            {
                                // should also check if any other lines cut through rectangle?
                                double top    = horizontal[h].Line;
                                double bottom = horizontal[h2].Line;
                                double left   = vertical[vCellStart].Line;
                                double right  = vertical[v].Line;
                                // Create Table Cell
                                FixedSOMTableCell cell = new FixedSOMTableCell(left, top, right, bottom);
                                //_fixedSOMPage.Add(cell); // for now just doing cells

                                // Check if in same row
                                if (vCellStart == vLastCellRight && h2 == hLastCellBottom)
                                {
                                    // same row!
                                    // Assert(currentRow != null);
                                }
                                else
                                {
                                    currentRow = new FixedSOMTableRow();
                                    tableRows.Add(currentRow);
                                }
                                currentRow.AddCell(cell);

                                vLastCellRight  = v;
                                hLastCellBottom = h2;
                            }
                            vCellStart = -1; // any previously started cell is not valid

                            // look for cell bottom
                            for (h2 = h + 1; h2 < horizontal.Count && horizontal[h2].Line < vBottom + minLineSeparation; h2++)
                            {
                                hSeg2 = horizontal[h2].GetLineAt(vertical[v].Line + minLineSeparation);
                                if (hSeg2 != -1)
                                {
                                    // start of new cell! (maybe...)
                                    vCellStart = v;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            _FillTables(tableRows);
        }
       private void _DetectTables()
       { 
           double minLineSeparation = FixedSOMLineRanges.MinLineSeparation;
 
           List<FixedSOMLineRanges> horizontal = _lines.HorizontalLines; 
           List<FixedSOMLineRanges> vertical = _lines.VerticalLines;
 
           if (horizontal.Count < 2 || vertical.Count < 2)
               return;

           List<FixedSOMTableRow> tableRows = new List<FixedSOMTableRow>(); 
           FixedSOMTableRow currentRow = null;
 
            //iterate through 
            for (int h = 0; h < horizontal.Count; h++)
            { 
                int v = 0;
                int h2 = -1;
                int hSeg2 = -1;
                int hLastCellBottom = -1; 
                int vLastCellRight = -1;
 
                double dropLine = horizontal[h].Line + minLineSeparation; 
                //loop through each line segment on this Y value
                for (int hSeg = 0; hSeg < horizontal[h].Count; hSeg++) 
                {
                    // X range for this segment -- allow some margin for error
                    double hStart = horizontal[h].Start[hSeg] - minLineSeparation;
                    double hEnd = horizontal[h].End[hSeg] + minLineSeparation; 

                    // no cell has been started 
                    int vCellStart = -1; 
                    while (v < vertical.Count && vertical[v].Line < hStart)
                    { 
                        v++;
                    }
                    for (; v < vertical.Count && vertical[v].Line < hEnd; v++)
                    { 
                        int vSeg = vertical[v].GetLineAt(dropLine);
                        if (vSeg != -1) 
                        { 
                            double vBottom = vertical[v].End[vSeg];
                            if (vCellStart != -1 && horizontal[h2].Line < vBottom + minLineSeparation && 
                                horizontal[h2].End[hSeg2] + minLineSeparation > vertical[v].Line)
                            {
                                // should also check if any other lines cut through rectangle?
                                double top = horizontal[h].Line; 
                                double bottom = horizontal[h2].Line;
                                double left = vertical[vCellStart].Line; 
                                double right = vertical[v].Line; 
                                // Create Table Cell
                                FixedSOMTableCell cell = new FixedSOMTableCell(left, top, right, bottom); 
                                //_fixedSOMPage.Add(cell); // for now just doing cells

                                // Check if in same row
                                if (vCellStart == vLastCellRight && h2 == hLastCellBottom) 
                                {
                                    // same row! 
                                    // Assert(currentRow != null); 
                                }
                                else 
                                {
                                    currentRow = new FixedSOMTableRow();
                                    tableRows.Add(currentRow);
                                } 
                                currentRow.AddCell(cell);
 
                                vLastCellRight = v; 
                                hLastCellBottom = h2;
                            } 
                            vCellStart = -1; // any previously started cell is not valid

                            // look for cell bottom
                            for (h2 = h + 1; h2 < horizontal.Count && horizontal[h2].Line < vBottom + minLineSeparation; h2++) 
                            {
                                hSeg2 = horizontal[h2].GetLineAt(vertical[v].Line + minLineSeparation); 
                                if (hSeg2 != -1) 
                                {
                                    // start of new cell! (maybe...) 
                                    vCellStart = v;
                                    break;
                                }
                            } 
                        }
                    } 
                } 
            }
 
            _FillTables(tableRows);

        }
Example #8
0
        // Token: 0x06002E28 RID: 11816 RVA: 0x000D0884 File Offset: 0x000CEA84
        internal void DeleteEmptyColumns()
        {
            int count = base.SemanticBoxes.Count;

            int[] array = new int[count];
            for (;;)
            {
                double num  = double.MaxValue;
                bool   flag = true;
                for (int i = 0; i < count; i++)
                {
                    FixedSOMTableRow fixedSOMTableRow = (FixedSOMTableRow)base.SemanticBoxes[i];
                    int num2 = array[i];
                    flag = (flag && num2 < fixedSOMTableRow.SemanticBoxes.Count);
                    if (flag)
                    {
                        FixedSOMTableCell fixedSOMTableCell = (FixedSOMTableCell)fixedSOMTableRow.SemanticBoxes[num2];
                        flag = (fixedSOMTableCell.IsEmpty && fixedSOMTableCell.BoundingRect.Width < 5.0);
                    }
                    if (num2 + 1 < fixedSOMTableRow.SemanticBoxes.Count)
                    {
                        FixedSOMTableCell fixedSOMTableCell = (FixedSOMTableCell)fixedSOMTableRow.SemanticBoxes[num2 + 1];
                        double            left = fixedSOMTableCell.BoundingRect.Left;
                        if (left < num)
                        {
                            if (num != 1.7976931348623157E+308)
                            {
                                flag = false;
                            }
                            num = left;
                        }
                        else if (left > num)
                        {
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    for (int i = 0; i < count; i++)
                    {
                        FixedSOMTableRow fixedSOMTableRow2 = (FixedSOMTableRow)base.SemanticBoxes[i];
                        fixedSOMTableRow2.SemanticBoxes.RemoveAt(array[i]);
                    }
                    if (num == 1.7976931348623157E+308)
                    {
                        break;
                    }
                }
                else
                {
                    if (num == 1.7976931348623157E+308)
                    {
                        return;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        FixedSOMTableRow fixedSOMTableRow3 = (FixedSOMTableRow)base.SemanticBoxes[i];
                        int num3 = array[i];
                        if (num3 + 1 < fixedSOMTableRow3.SemanticBoxes.Count && fixedSOMTableRow3.SemanticBoxes[num3 + 1].BoundingRect.Left == num)
                        {
                            array[i] = num3 + 1;
                        }
                        else
                        {
                            FixedSOMTableCell fixedSOMTableCell2 = (FixedSOMTableCell)fixedSOMTableRow3.SemanticBoxes[num3];
                            int columnSpan = fixedSOMTableCell2.ColumnSpan;
                            fixedSOMTableCell2.ColumnSpan = columnSpan + 1;
                        }
                    }
                }
            }
        }
Example #9
0
        //Deletes an entire column if its empty
        //Sets column spans

        internal void DeleteEmptyColumns()
        {
            int nRows = this.SemanticBoxes.Count;

            int[] indexInRow = new int[nRows];

            while (true)
            {
                double nextCol   = double.MaxValue;
                bool   deleteCol = true;
                int    r;
                for (r = 0; r < nRows; r++)
                {
                    FixedSOMTableRow row = (FixedSOMTableRow)(this.SemanticBoxes[r]);
                    int idx = indexInRow[r];
                    FixedSOMTableCell cell;

                    deleteCol = deleteCol && idx < row.SemanticBoxes.Count;
                    if (deleteCol)
                    {
                        cell = (FixedSOMTableCell)row.SemanticBoxes[idx];
                        // is empty?
                        deleteCol = cell.IsEmpty && cell.BoundingRect.Width < _minColumnWidth;
                    }

                    // where does next column start?
                    if (idx + 1 < row.SemanticBoxes.Count)
                    {
                        cell = (FixedSOMTableCell)row.SemanticBoxes[idx + 1];
                        double cellStart = cell.BoundingRect.Left;

                        if (cellStart < nextCol)
                        {
                            if (nextCol != double.MaxValue)
                            {
                                // can't delete colums where not all have same width
                                deleteCol = false;
                            }
                            nextCol = cellStart;
                        }
                        else if (cellStart > nextCol)
                        {
                            deleteCol = false;
                        }
                    }
                }

                if (deleteCol)
                {
                    for (r = 0; r < nRows; r++)
                    {
                        FixedSOMTableRow row = (FixedSOMTableRow)(this.SemanticBoxes[r]);
                        row.SemanticBoxes.RemoveAt(indexInRow[r]);
                    }

                    if (nextCol == double.MaxValue)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                // are we done?
                if (nextCol == double.MaxValue)
                {
                    break;
                }
                // increment ColumnSpans, indexInRow
                for (r = 0; r < nRows; r++)
                {
                    FixedSOMTableRow row = (FixedSOMTableRow)(this.SemanticBoxes[r]);
                    int idx = indexInRow[r];
                    if (idx + 1 < row.SemanticBoxes.Count && row.SemanticBoxes[idx + 1].BoundingRect.Left == nextCol)
                    {
                        indexInRow[r] = idx + 1;
                    }
                    else
                    {
                        ((FixedSOMTableCell)row.SemanticBoxes[idx]).ColumnSpan++;
                    }
                }
            }
        }
Example #10
0
        // Token: 0x06002E05 RID: 11781 RVA: 0x000CFA4C File Offset: 0x000CDC4C
        private void _FillTables(List <FixedSOMTableRow> tableRows)
        {
            List <FixedSOMTable> list = new List <FixedSOMTable>();

            foreach (FixedSOMTableRow fixedSOMTableRow in tableRows)
            {
                FixedSOMTable fixedSOMTable = null;
                double        num           = 0.01;
                foreach (FixedSOMTable fixedSOMTable2 in list)
                {
                    if (Math.Abs(fixedSOMTable2.BoundingRect.Left - fixedSOMTableRow.BoundingRect.Left) < num && Math.Abs(fixedSOMTable2.BoundingRect.Right - fixedSOMTableRow.BoundingRect.Right) < num && Math.Abs(fixedSOMTable2.BoundingRect.Bottom - fixedSOMTableRow.BoundingRect.Top) < num)
                    {
                        fixedSOMTable = fixedSOMTable2;
                        break;
                    }
                }
                if (fixedSOMTable == null)
                {
                    fixedSOMTable = new FixedSOMTable(this._fixedSOMPage);
                    list.Add(fixedSOMTable);
                }
                fixedSOMTable.AddRow(fixedSOMTableRow);
            }
            for (int i = 0; i < list.Count - 1; i++)
            {
                for (int j = i + 1; j < list.Count; j++)
                {
                    if (list[i].BoundingRect.Contains(list[j].BoundingRect) && list[i].AddContainer(list[j]))
                    {
                        list.RemoveAt(j--);
                    }
                    else if (list[j].BoundingRect.Contains(list[i].BoundingRect) && list[j].AddContainer(list[i]))
                    {
                        list.RemoveAt(i--);
                        if (i < 0)
                        {
                            break;
                        }
                    }
                }
            }
            foreach (FixedSOMTable fixedSOMTable3 in list)
            {
                if (!fixedSOMTable3.IsSingleCelled)
                {
                    bool flag = false;
                    int  k    = 0;
                    while (k < this._fixedSOMPage.SemanticBoxes.Count)
                    {
                        if (this._fixedSOMPage.SemanticBoxes[k] is FixedSOMFixedBlock && fixedSOMTable3.AddContainer(this._fixedSOMPage.SemanticBoxes[k] as FixedSOMContainer))
                        {
                            this._fixedSOMPage.SemanticBoxes.RemoveAt(k);
                            flag = true;
                        }
                        else
                        {
                            k++;
                        }
                    }
                    if (flag)
                    {
                        fixedSOMTable3.DeleteEmptyRows();
                        fixedSOMTable3.DeleteEmptyColumns();
                        foreach (FixedSOMSemanticBox fixedSOMSemanticBox in fixedSOMTable3.SemanticBoxes)
                        {
                            FixedSOMTableRow fixedSOMTableRow2 = (FixedSOMTableRow)fixedSOMSemanticBox;
                            foreach (FixedSOMSemanticBox fixedSOMSemanticBox2 in fixedSOMTableRow2.SemanticBoxes)
                            {
                                FixedSOMTableCell fixedSOMTableCell = (FixedSOMTableCell)fixedSOMSemanticBox2;
                                int l = 0;
                                while (l < fixedSOMTableCell.SemanticBoxes.Count)
                                {
                                    FixedSOMTable fixedSOMTable4 = fixedSOMTableCell.SemanticBoxes[l] as FixedSOMTable;
                                    if (fixedSOMTable4 != null && fixedSOMTable4.IsEmpty)
                                    {
                                        fixedSOMTableCell.SemanticBoxes.Remove(fixedSOMTable4);
                                    }
                                    else
                                    {
                                        l++;
                                    }
                                }
                                this._CreateGroups(fixedSOMTableCell);
                                fixedSOMTableCell.SemanticBoxes.Sort();
                            }
                        }
                        this._fixedSOMPage.AddTable(fixedSOMTable3);
                    }
                }
            }
        }
Example #11
0
        // Token: 0x06002DFF RID: 11775 RVA: 0x000CF298 File Offset: 0x000CD498
        private void _DetectTables()
        {
            double minLineSeparation = FixedSOMLineRanges.MinLineSeparation;
            List <FixedSOMLineRanges> horizontalLines = this._lines.HorizontalLines;
            List <FixedSOMLineRanges> verticalLines   = this._lines.VerticalLines;

            if (horizontalLines.Count < 2 || verticalLines.Count < 2)
            {
                return;
            }
            List <FixedSOMTableRow> list             = new List <FixedSOMTableRow>();
            FixedSOMTableRow        fixedSOMTableRow = null;

            for (int i = 0; i < horizontalLines.Count; i++)
            {
                int    j    = 0;
                int    num  = -1;
                int    num2 = -1;
                int    num3 = -1;
                int    num4 = -1;
                double line = horizontalLines[i].Line + minLineSeparation;
                for (int k = 0; k < horizontalLines[i].Count; k++)
                {
                    double num5 = horizontalLines[i].Start[k] - minLineSeparation;
                    double num6 = horizontalLines[i].End[k] + minLineSeparation;
                    int    num7 = -1;
                    while (j < verticalLines.Count)
                    {
                        if (verticalLines[j].Line >= num5)
                        {
                            break;
                        }
                        j++;
                    }
                    while (j < verticalLines.Count && verticalLines[j].Line < num6)
                    {
                        int lineAt = verticalLines[j].GetLineAt(line);
                        if (lineAt != -1)
                        {
                            double num8 = verticalLines[j].End[lineAt];
                            if (num7 != -1 && horizontalLines[num].Line <num8 + minLineSeparation && horizontalLines[num].End[num2] + minLineSeparation> verticalLines[j].Line)
                            {
                                double            line2 = horizontalLines[i].Line;
                                double            line3 = horizontalLines[num].Line;
                                double            line4 = verticalLines[num7].Line;
                                double            line5 = verticalLines[j].Line;
                                FixedSOMTableCell cell  = new FixedSOMTableCell(line4, line2, line5, line3);
                                if (num7 != num4 || num != num3)
                                {
                                    fixedSOMTableRow = new FixedSOMTableRow();
                                    list.Add(fixedSOMTableRow);
                                }
                                fixedSOMTableRow.AddCell(cell);
                                num4 = j;
                                num3 = num;
                            }
                            num7 = -1;
                            num  = i + 1;
                            while (num < horizontalLines.Count && horizontalLines[num].Line < num8 + minLineSeparation)
                            {
                                num2 = horizontalLines[num].GetLineAt(verticalLines[j].Line + minLineSeparation);
                                if (num2 != -1)
                                {
                                    num7 = j;
                                    break;
                                }
                                num++;
                            }
                        }
                        j++;
                    }
                }
            }
            this._FillTables(list);
        }