Exemple #1
0
        /**
         * Gets the lines of a cell that can be drawn between certain limits.
         * <P>
         * Remark: all the lines that can be drawn are removed from the object!
         *
         * @param   top     the top of the part of the table that can be drawn
         * @param   bottom  the bottom of the part of the table that can be drawn
         * @return  an <CODE>ArrayList</CODE> of <CODE>PdfLine</CODE>s
         */

        public ArrayList GetLines(float top, float bottom)
        {
            float lineHeight;
            float currentPosition = Math.Min(this.Top, top);

            this.Top = currentPosition + cellspacing;
            ArrayList result = new ArrayList();

            // if the bottom of the page is higher than the top of the cell: do nothing
            if (Top < bottom)
            {
                return(result);
            }

            // we loop over the lines
            int  size        = lines.Count;
            bool aboveBottom = true;

            for (int i = 0; i < size && aboveBottom; i++)
            {
                line             = (PdfLine)lines[i];
                lineHeight       = line.Height;
                currentPosition -= lineHeight;
                // if the currentPosition is higher than the bottom, we add the line to the result
                if (currentPosition > (bottom + cellpadding + GetBorderWidthInside(BOTTOM_BORDER)))   // bugfix by Tom Ring and Veerendra Namineni
                {
                    result.Add(line);
                }
                else
                {
                    aboveBottom = false;
                }
            }
            // if the bottom of the cell is higher than the bottom of the page, the cell is written, so we can remove all lines
            float difference = 0f;

            if (!header)
            {
                if (aboveBottom)
                {
                    lines         = new ArrayList();
                    contentHeight = 0f;
                }
                else
                {
                    size = result.Count;
                    for (int i = 0; i < size; i++)
                    {
                        line        = RemoveLine(0);
                        difference += line.Height;
                    }
                }
            }
            if (difference > 0)
            {
                foreach (Image image in images)
                {
                    image.SetAbsolutePosition(image.AbsoluteX, image.AbsoluteY - difference - leading);
                }
            }
            return(result);
        }
Exemple #2
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 other Rectangle attributes from class Cell
            CloneNonPositionParameters(cell);
            this.cellpadding       = cellpadding;
            this.cellspacing       = cellspacing;
            this.verticalAlignment = cell.VerticalAlignment;
            this.useAscender       = cell.UseAscender;
            this.useDescender      = cell.UseDescender;
            this.useBorderPadding  = cell.UseBorderPadding;

            // 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;

            left         += GetBorderWidthInside(LEFT_BORDER);
            right        -= GetBorderWidthInside(RIGHT_BORDER);
            contentHeight = 0;
            rowspan       = cell.Rowspan;

            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.JPEG2000:
                case Element.JBIG2:
                case Element.IMGRAW:
                case Element.IMGTEMPLATE:
                    AddImage((Image)ele, left, right, 0.4f * leading, alignment);
                    break;

                // if the element is a list
                case Element.LIST:
                    if (line != null && line.Size > 0)
                    {
                        line.ResetAlignment();
                        AddLine(line);
                    }
                    // we loop over all the listitems
                    AddList((List)ele, left, right, alignment);
                    line = new PdfLine(left, right, alignment, leading);
                    break;

                // if the element is something else
                default:
                    allActions = new ArrayList();
                    ProcessActions(ele, null, allActions);
                    aCounter = 0;

                    float currentLineLeading = leading;
                    float currentLeft        = left;
                    float currentRight       = right;
                    if (ele is Phrase)
                    {
                        currentLineLeading = ((Phrase)ele).Leading;
                    }
                    if (ele is Paragraph)
                    {
                        Paragraph p = (Paragraph)ele;
                        currentLeft  += p.IndentationLeft;
                        currentRight -= p.IndentationRight;
                    }
                    if (line == null)
                    {
                        line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                    }
                    // we loop over the chunks
                    ArrayList chunks = ele.Chunks;
                    if (chunks.Count == 0)
                    {
                        AddLine(line);     // add empty line - all cells need some lines even if they are empty
                        line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                    }
                    else
                    {
                        foreach (Chunk c in chunks)
                        {
                            chunk = new PdfChunk(c, (PdfAction)allActions[aCounter++]);
                            while ((overflow = line.Add(chunk)) != null)
                            {
                                AddLine(line);
                                line  = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                                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();
                        FlushCurrentLine();
                        break;
                    }
                    break;
                }
            }
            FlushCurrentLine();
            if (lines.Count > cell.MaxLines)
            {
                while (lines.Count > cell.MaxLines)
                {
                    RemoveLine(lines.Count - 1);
                }
                if (cell.MaxLines > 0)
                {
                    String more = cell.ShowTruncation;
                    if (more != null && more.Length > 0)
                    {
                        // Denote that the content has been truncated
                        lastLine = (PdfLine)lines[lines.Count - 1];
                        if (lastLine.Size >= 0)
                        {
                            PdfChunk lastChunk = lastLine.GetChunk(lastLine.Size - 1);
                            float    moreWidth = new PdfChunk(more, lastChunk).Width;
                            while (lastChunk.ToString().Length > 0 && lastChunk.Width + moreWidth > right - left)
                            {
                                // Remove characters to leave room for the 'more' indicator
                                lastChunk.Value = lastChunk.ToString().Substring(0, lastChunk.Length - 1);
                            }
                            lastChunk.Value = lastChunk.ToString() + more;
                        }
                        else
                        {
                            lastLine.Add(new PdfChunk(new Chunk(more), null));
                        }
                    }
                }
            }
            // we set some additional parameters
            if (useDescender && lastLine != null)
            {
                contentHeight -= lastLine.Descender;
            }

            // adjust first line height so that it touches the top
            if (lines.Count > 0)
            {
                firstLine = (PdfLine)lines[0];
                float firstLineRealHeight = FirstLineRealHeight;
                contentHeight   -= firstLine.Height;
                firstLine.height = firstLineRealHeight;
                contentHeight   += firstLineRealHeight;
            }

            float newBottom = top - contentHeight - (2f * Cellpadding) - (2f * Cellspacing);

            newBottom -= GetBorderWidthInside(TOP_BORDER) + GetBorderWidthInside(BOTTOM_BORDER);
            Bottom     = newBottom;

            this.rownumber = rownumber;
        }