Пример #1
0
 /// <summary>
 ///     Internal use only.
 ///     Constructor.
 /// </summary>
 /// <param name="representative">
 ///     Representative cell for the cell.
 ///     (Usually the one located at top left corner of the group of merged cell.)
 /// </param>
 /// <param name="rowSpan">Number of rows that this group of merged cells spans.</param>
 /// <param name="colSpan">Number of columns that this group of merged cells spans.</param>
 /// <param name="rowIndex">
 ///     The relative row index of the cell within this group
 ///     of merged cells.
 /// </param>
 /// <param name="colIndex">
 ///     The relative column index of the cell within this group
 ///     of merged cells.
 /// </param>
 internal CellMergeInfo(RtfTableCell representative, int rowSpan, int colSpan,
                        int rowIndex, int colIndex)
 {
     Representative = representative;
     RowSpan        = rowSpan;
     ColSpan        = colSpan;
     RowIndex       = rowIndex;
     ColIndex       = colIndex;
 }
Пример #2
0
 private void ValidateMergedCellBorders(RtfTableCell representative)
 {
     if (!representative.IsMerged)
     {
         throw new Exception("Invalid representative (cell is not merged).");
     }
     ValidateMergedCellBorder(representative, Direction.Top);
     ValidateMergedCellBorder(representative, Direction.Right);
     ValidateMergedCellBorder(representative, Direction.Bottom);
     ValidateMergedCellBorder(representative, Direction.Left);
 }
Пример #3
0
        public RtfTable(int rowCount, int colCount, float horizontalWidth, float fontSize)
        {
            _fontSize           = fontSize;
            _alignment          = Align.None;
            _margins            = new Margins();
            RowCount            = rowCount;
            ColCount            = colCount;
            _representativeList = new List <RtfTableCell>();
            _startNewPage       = false;
            TitleRowCount       = 0;
            CellPadding         = new Margins[RowCount];
            if (RowCount < 1 || ColCount < 1)
            {
                throw new Exception("The number of rows or columns is less than 1.");
            }

            HeaderBackgroundColor = null;
            RowBackgroundColor    = null;
            RowAltBackgroundColor = null;

            // Set cell default width according to paper width
            _defaultCellWidth  = horizontalWidth / colCount;
            _cells             = new RtfTableCell[RowCount][];
            _rowHeight         = new float[RowCount];
            _rowKeepInSamePage = new bool[RowCount];
            for (var i = 0; i < RowCount; i++)
            {
                _cells[i]             = new RtfTableCell[ColCount];
                _rowHeight[i]         = 0F;
                _rowKeepInSamePage[i] = false;
                CellPadding[i]        = new Margins();
                for (var j = 0; j < ColCount; j++)
                {
                    _cells[i][j] = new RtfTableCell(_defaultCellWidth, i, j, this);
                }
            }
        }
Пример #4
0
        private void ValidateMergedCellBorder(RtfTableCell representative, Direction dir)
        {
            if (!representative.IsMerged)
            {
                throw new Exception("Invalid representative (cell is not merged).");
            }
            var    stat = new Dictionary <Border, int>();
            Border majorityBorder;
            int    majorityCount;
            var    limit = dir == Direction.Top || dir == Direction.Bottom
                ? representative.MergeInfo.ColSpan
                : representative.MergeInfo.RowSpan;

            for (var i = 0; i < limit; i++)
            {
                int    r, c;
                Border bdr;
                if (dir == Direction.Top || dir == Direction.Bottom)
                {
                    if (dir == Direction.Top)
                    {
                        r = 0;
                    }
                    else
                    {
                        r = representative.MergeInfo.RowSpan - 1;
                    }
                    c = i;
                }
                else
                {
                    // dir == right || left
                    if (dir == Direction.Right)
                    {
                        c = representative.MergeInfo.ColSpan - 1;
                    }
                    else
                    {
                        c = 0;
                    }
                    r = i;
                }
                bdr = _cells[representative.RowIndex + r][representative.ColIndex + c].Borders[dir];
                if (stat.ContainsKey(bdr))
                {
                    stat[bdr] = stat[bdr] + 1;
                }
                else
                {
                    stat[bdr] = 1;
                }
            }
            majorityCount  = -1;
            majorityBorder = representative.Borders[dir];
            foreach (var de in stat)
            {
                if (de.Value > majorityCount)
                {
                    majorityCount        = de.Value;
                    majorityBorder.Style = de.Key.Style;
                    majorityBorder.Width = de.Key.Width;
                    majorityBorder.Color = de.Key.Color;
                }
            }
        }