PdfRpt.Core.PdfTable.MainTableCellsEvent.getAggregateValuePosition C# (CSharp) Method

getAggregateValuePosition() private method

private getAggregateValuePosition ( Rectangle position ) : AggregateValuePosition
position iTextSharp.text.Rectangle
return PdfRpt.Core.Contracts.AggregateValuePosition
        private AggregateValuePosition getAggregateValuePosition(Rectangle position)
        {
            float x;
            if (!_pdfRptCell.BasicProperties.HorizontalAlignment.HasValue)
                _pdfRptCell.BasicProperties.HorizontalAlignment = HorizontalAlignment.Center;

            if (!_pdfRptCell.BasicProperties.RunDirection.HasValue)
                _pdfRptCell.BasicProperties.RunDirection = PdfRunDirection.LeftToRight;

            var emptyCell = new PdfPCell();
            var paddingLeft = _pdfRptCell.BasicProperties.PaddingLeft;
            if (paddingLeft.ApproxEquals(0))
            {
                paddingLeft = emptyCell.PaddingLeft;
            }

            var paddingRight = _pdfRptCell.BasicProperties.PaddingRight;
            if (paddingRight.ApproxEquals(0))
            {
                paddingRight = emptyCell.PaddingRight;
            }

            var borderWidth = _pdfRptCell.BasicProperties.BorderWidth;
            if (borderWidth.ApproxEquals(0))
            {
                borderWidth = emptyCell.BorderWidth;
            }

            var alignment = _pdfRptCell.BasicProperties.HorizontalAlignment.Value;
            switch (alignment)
            {
                case HorizontalAlignment.Left:
                    if (_pdfRptCell.BasicProperties.RunDirection.Value == PdfRunDirection.RightToLeft)
                    {
                        x = position.Right - paddingRight - borderWidth;
                        alignment = HorizontalAlignment.Right;
                    }
                    else
                    {
                        x = position.Left + paddingLeft + borderWidth;
                    }
                    break;

                case HorizontalAlignment.Right:
                    if (_pdfRptCell.BasicProperties.RunDirection.Value == PdfRunDirection.RightToLeft)
                    {
                        x = position.Left + paddingLeft + borderWidth;
                        alignment = HorizontalAlignment.Left;
                    }
                    else
                    {
                        x = position.Right - paddingRight - borderWidth;
                    }
                    break;

                default:
                    x = (position.Left + position.Right) / 2;
                    break;
            }

            return new AggregateValuePosition
            {
                HorizontalAlignment = alignment,
                X = x
            };
        }