Example #1
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.");
			}
			
			// Set cell default width according to paper width
			_defaultCellWidth = horizontalWidth / (float)colCount;
			_cells = new RtfTableCell[_rowCount][];
			_rowHeight = new float[_rowCount];
			_rowKeepInSamePage = new bool[_rowCount];
			for (int i = 0; i < _rowCount; i++) {
				_cells[i] = new RtfTableCell[_colCount];
				_rowHeight[i] = 0F;
				_rowKeepInSamePage[i] = false;
				_cellPadding[i] = new Margins();
				for (int j = 0; j < _colCount; j++) {
					_cells[i][j] = new RtfTableCell(_defaultCellWidth, i, j, this);
				}
			}
		}
Example #2
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.");
            }

            // Set cell default width according to paper width
            _defaultCellWidth  = horizontalWidth / (float)colCount;
            _cells             = new RtfTableCell[_rowCount][];
            _rowHeight         = new float[_rowCount];
            _rowKeepInSamePage = new bool[_rowCount];
            for (int i = 0; i < _rowCount; i++)
            {
                _cells[i]             = new RtfTableCell[_colCount];
                _rowHeight[i]         = 0F;
                _rowKeepInSamePage[i] = false;
                _cellPadding[i]       = new Margins();
                for (int j = 0; j < _colCount; j++)
                {
                    _cells[i][j] = new RtfTableCell(_defaultCellWidth, i, j, this);
                }
            }
        }
Example #3
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;
 }
Example #4
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);
 }
Example #5
0
        protected void TypeCellParagraph(RtfTableCell cell, int fontsize, Align align, string text)
        {
            if (doc != null)
            {
                FontDescriptor times = doc.createFont("Times New Roman");
                RtfCharFormat fmt;
                RtfParagraph par;

                par = cell.addParagraph();
                par.Alignment = align;
                fmt = par.addCharFormat();
                fmt.Font = times;
                fmt.FontSize = fontsize;
                par.setText(text);
            }
        }
Example #6
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;
		}
Example #7
0
		private void validateMergedCellBorder(RtfTableCell representative, Direction dir)
		{
			if (!representative.IsMerged) {
				throw new Exception("Invalid representative (cell is not merged).");
			}
			Dictionary<Border, int> stat = new Dictionary<Border, int>();
			Border majorityBorder;
			int majorityCount;
			int limit = (dir == Direction.Top || dir == Direction.Bottom) ? 
				representative.MergeInfo.ColSpan : representative.MergeInfo.RowSpan;
			
			for (int i = 0; i < limit; i++) {
				int r, c;
				Border bdr;
				if (dir == Direction.Top || dir == Direction.Bottom) {
					if (dir == Direction.Top) {
						r = 0;
					} else { // dir == bottom
						r = representative.MergeInfo.RowSpan - 1;
					}
					c = i;
				} else { // dir == right || left
					if (dir == Direction.Right) {
						c = representative.MergeInfo.ColSpan - 1;
					} else { // dir == left
						c = 0;
					}
					r = i;
				}
				bdr = _cells[representative.RowIndex + r][representative.ColIndex + c].Borders[dir];
				if (stat.ContainsKey(bdr)) {
					stat[bdr] = (int)stat[bdr] + 1;
				} else {
					stat[bdr] = 1;
				}
			}
			majorityCount = -1;
			majorityBorder = representative.Borders[dir];
			foreach(KeyValuePair<Border, int> de in stat.ToList()) {
				if(de.Value > majorityCount) {
					majorityCount = de.Value;
					majorityBorder.Style = de.Key.Style;
					majorityBorder.Width = de.Key.Width;
					majorityBorder.Color = de.Key.Color;
				}
			}
		}
Example #8
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);
		}
Example #9
0
        private void validateMergedCellBorder(RtfTableCell representative, Direction dir)
        {
            if (!representative.IsMerged)
            {
                throw new Exception("Invalid representative (cell is not merged).");
            }
            Dictionary <Border, int> stat = new Dictionary <Border, int>();
            Border majorityBorder;
            int    majorityCount;
            int    limit = (dir == Direction.Top || dir == Direction.Bottom) ?
                           representative.MergeInfo.ColSpan : representative.MergeInfo.RowSpan;

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