PdfRpt.Core.Helper.ElementsWidth.GetCellWidth C# (CSharp) Method

GetCellWidth() public static method

Tries to find the PdfPCell's width, before rendering
public static GetCellWidth ( this cell ) : float
cell this pdf cell
return float
        public static float GetCellWidth(this PdfPCell cell)
        {
            if (cell == null) return 0;

            var rulesWidth = new List<float>();
            var startWidth = cell.PaddingLeft + cell.PaddingRight + 1 + cell.BorderWidth;
            var cellWidth = startWidth;

            var compositeElements = cell.CompositeElements;
            if (compositeElements == null)
            {
                if (cell.Image != null)
                {
                    cellWidth += cell.Image.Width;
                }

                if (cell.Phrase != null)
                {
                    cellWidth += GetPhraseWidth(cell.Phrase);
                }

                if (cell.Table != null)
                {
                    cellWidth += cell.Table.TotalWidth;
                }

                return cellWidth;
            }

            foreach (var baseLevel in compositeElements)
            {
                if (baseLevel is Phrase)
                {
                    cellWidth += GetPhraseWidth((Phrase)baseLevel);
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth;
                }
                else if (baseLevel is List)
                {
                    cellWidth = getListWidth(rulesWidth, startWidth, cellWidth, baseLevel);
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth;
                }
                else if (baseLevel is PdfGrid)
                {
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth + ((PdfGrid)baseLevel).TotalWidth;
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth;
                }
            }

            return rulesWidth.Concat(new[] { cellWidth }).Max();
        }