Exemplo n.º 1
0
        private void initCells()
        {
            if (_cellsFound)
            {
                return;
            }

            short expectedCellsCount = _tprops.GetItcMac();

            int lastCellStart      = 0;
            List <TableCell> cells = new List <TableCell>(
                expectedCellsCount + 1);

            for (int p = 0; p < NumParagraphs; p++)
            {
                Paragraph paragraph = GetParagraph(p);
                String    s         = paragraph.Text;

                if (((s.Length > 0 && s[s.Length - 1] == TABLE_CELL_MARK) || paragraph
                     .IsEmbeddedCellMark()) &&
                    paragraph.GetTableLevel() == _levelNum)
                {
                    TableCellDescriptor tableCellDescriptor = _tprops.GetRgtc() != null &&
                                                              _tprops.GetRgtc().Length > cells.Count ? _tprops
                                                              .GetRgtc()[cells.Count] : new TableCellDescriptor();
                    short leftEdge = (_tprops.GetRgdxaCenter() != null &&
                                      _tprops.GetRgdxaCenter().Length > cells.Count) ? (short)_tprops
                                     .GetRgdxaCenter()[cells.Count] : (short)0;
                    short rightEdge = (_tprops.GetRgdxaCenter() != null &&
                                       _tprops.GetRgdxaCenter().Length > cells.Count + 1) ? (short)_tprops
                                      .GetRgdxaCenter()[cells.Count + 1] : (short)0;

                    TableCell tableCell = new TableCell(GetParagraph(
                                                            lastCellStart).StartOffset, GetParagraph(p)
                                                        .EndOffset, this, _levelNum, tableCellDescriptor,
                                                        leftEdge, rightEdge - leftEdge);
                    cells.Add(tableCell);
                    lastCellStart = p + 1;
                }
            }

            if (lastCellStart < (NumParagraphs - 1))
            {
                TableCellDescriptor tableCellDescriptor = _tprops.GetRgtc() != null &&
                                                          _tprops.GetRgtc().Length > cells.Count ? _tprops
                                                          .GetRgtc()[cells.Count] : new TableCellDescriptor();
                short leftEdge = _tprops.GetRgdxaCenter() != null &&
                                 _tprops.GetRgdxaCenter().Length > cells.Count ? (short)_tprops
                                 .GetRgdxaCenter()[cells.Count] : (short)0;
                short rightEdge = _tprops.GetRgdxaCenter() != null &&
                                  _tprops.GetRgdxaCenter().Length > cells.Count + 1 ? (short)_tprops
                                  .GetRgdxaCenter()[cells.Count + 1] : (short)0;

                TableCell tableCell = new TableCell(lastCellStart,
                                                    (NumParagraphs - 1), this, _levelNum,
                                                    tableCellDescriptor, leftEdge, rightEdge - leftEdge);
                cells.Add(tableCell);
            }

            if (cells.Count > 0)
            {
                TableCell lastCell = cells[cells.Count - 1];
                if (lastCell.NumParagraphs == 1 &&
                    (lastCell.GetParagraph(0).IsTableRowEnd()))
                {
                    // remove "fake" cell
                    cells.RemoveAt(cells.Count - 1);
                }
            }

            if (cells.Count != expectedCellsCount)
            {
                _tprops.SetItcMac((short)cells.Count);
            }

            _cells      = cells.ToArray();
            _cellsFound = true;
        }