Exemplo n.º 1
0
        // constructors

        /**
         * Constructs a <CODE>PdfCell</CODE>-object.
         *
         * @param	cell		the original <CODE>Cell</CODE>
         * @param	rownumber	the number of the <CODE>Row</CODE> the <CODE>Cell</CODE> was in.
         * @param	left		the left border of the <CODE>PdfCell</CODE>
         * @param	right		the right border of the <CODE>PdfCell</CODE>
         * @param	top			the top border of the <CODE>PdfCell</CODE>
         * @param	cellspacing	the cellspacing of the <CODE>Table</CODE>
         * @param	cellpadding	the cellpadding	of the <CODE>Table</CODE>
         */

        public PdfCell(Cell cell, int rownumber, float left, float right, float top, float cellspacing, float cellpadding) : base(left, top, right, top)
        {
            // copying the attributes from class Cell
            this.Border          = cell.Border;
            this.BorderWidth     = cell.BorderWidth;
            this.BorderColor     = cell.BorderColor;
            this.BackgroundColor = cell.BackgroundColor;
            this.GrayFill        = cell.GrayFill;

            // initialisation of some parameters
            PdfChunk chunk;
            PdfChunk overflow;

            lines   = new ArrayList();
            images  = new ArrayList();
            leading = cell.Leading;
            int alignment = cell.HorizontalAlignment;

            left  += cellspacing + cellpadding;
            right -= cellspacing + cellpadding;

            float height  = leading + cellpadding;
            float rowSpan = (float)cell.Rowspan;

            switch (cell.VerticalAlignment)
            {
            case Element.ALIGN_BOTTOM:
                height *= rowSpan;
                break;

            case Element.ALIGN_MIDDLE:
                height *= (float)(rowSpan / 1.5);
                break;

            default:
                height -= cellpadding * 0.4f;
                break;
            }

            line = new PdfLine(left, right, alignment, height);

            ArrayList allActions;
            int       aCounter;

            // we loop over all the elements of the cell
            foreach (IElement ele in cell.Elements)
            {
                switch (ele.Type)
                {
                case Element.JPEG:
                case Element.IMGRAW:
                case Element.IMGTEMPLATE:
                case Element.GIF:
                case Element.PNG:
                    height = addImage((Image)ele, left, right, height, alignment);
                    break;

                // if the element is a list
                case Element.LIST:
                    if (line.Size > 0)
                    {
                        line.resetAlignment();
                        lines.Add(line);
                    }
                    allActions = new ArrayList();
                    processActions(ele, null, allActions);
                    aCounter = 0;
                    // we loop over all the listitems
                    foreach (ListItem item in ((List)ele).Items)
                    {
                        line          = new PdfLine(left + item.IndentationLeft, right, alignment, leading);
                        line.ListItem = item;
                        foreach (Chunk c in item.Chunks)
                        {
                            chunk = new PdfChunk(c, (PdfAction)(allActions[aCounter++]));
                            while ((overflow = line.Add(chunk)) != null)
                            {
                                lines.Add(line);
                                line  = new PdfLine(left + item.IndentationLeft, right, alignment, leading);
                                chunk = overflow;
                            }
                            line.resetAlignment();
                            lines.Add(line);
                            line = new PdfLine(left + item.IndentationLeft, right, alignment, leading);
                        }
                    }
                    line = new PdfLine(left, right, alignment, leading);
                    break;

                // if the element is something else
                default:
                    allActions = new ArrayList();
                    processActions(ele, null, allActions);
                    aCounter = 0;
                    // we loop over the chunks
                    foreach (Chunk c in ele.Chunks)
                    {
                        chunk = new PdfChunk(c, (PdfAction)(allActions[aCounter++]));
                        while ((overflow = line.Add(chunk)) != null)
                        {
                            lines.Add(line);
                            line  = new PdfLine(left, right, alignment, leading);
                            chunk = overflow;
                        }
                    }
                    // if the element is a paragraph, section or chapter, we reset the alignment and add the line
                    switch (ele.Type)
                    {
                    case Element.PARAGRAPH:
                    case Element.SECTION:
                    case Element.CHAPTER:
                        line.resetAlignment();
                        lines.Add(line);
                        line = new PdfLine(left, right, alignment, leading);
                        break;
                    }
                    break;
                }
            }
            if (line.Size > 0)
            {
                lines.Add(line);
            }
            // we set some additional parameters
            this.Bottom      = top - leading * (lines.Count - 1) - cellpadding - height - 2 * cellspacing;
            this.cellpadding = cellpadding;
            this.cellspacing = cellspacing;

            rowspan        = cell.Rowspan;
            this.rownumber = rownumber;
        }