Exemplo n.º 1
0
        /**
         * Writes the border and background of one cell in the row.
         *
         * @param xPos The x-coordinate where the table starts on the canvas
         * @param yPos The y-coordinate where the table starts on the canvas
         * @param currentMaxHeight The height of the cell to be drawn.
         * @param cell
         * @param canvases
         * @since    2.1.6   extra parameter currentMaxHeight
         */
        public void WriteBorderAndBackground(float xPos, float yPos, float currentMaxHeight, PdfPCell cell, PdfContentByte[] canvases)
        {
            BaseColor background = cell.BackgroundColor;

            if (background != null || cell.HasBorders())
            {
                // Add xPos resp. yPos to the cell's coordinates for absolute coordinates
                float right  = cell.Right + xPos;
                float top    = cell.Top + yPos;
                float left   = cell.Left + xPos;
                float bottom = top - currentMaxHeight;

                if (background != null)
                {
                    PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS];
                    backgr.SetColorFill(background);
                    backgr.Rectangle(left, bottom, right - left, top - bottom);
                    backgr.Fill();
                }
                if (cell.HasBorders())
                {
                    Rectangle newRect = new Rectangle(left, bottom, right, top);
                    // Clone non-position parameters except for the background color
                    newRect.CloneNonPositionParameters(cell);
                    newRect.BackgroundColor = null;
                    // Write the borders on the line canvas
                    PdfContentByte lineCanvas = canvases[PdfPTable.LINECANVAS];
                    lineCanvas.Rectangle(newRect);
                }
            }
        }
Exemplo n.º 2
0
        /**
        * Writes the border and background of one cell in the row.
        *
        * @param xPos The x-coordinate where the table starts on the canvas
        * @param yPos The y-coordinate where the table starts on the canvas
        * @param currentMaxHeight The height of the cell to be drawn.
        * @param cell
        * @param canvases
        * @since    2.1.6   extra parameter currentMaxHeight
        */
        public void WriteBorderAndBackground(float xPos, float yPos, float currentMaxHeight, PdfPCell cell, PdfContentByte[] canvases)
        {
            BaseColor background = cell.BackgroundColor;
            if (background != null || cell.HasBorders()) {
                // Add xPos resp. yPos to the cell's coordinates for absolute coordinates
                float right = cell.Right + xPos;
                float top = cell.Top + yPos;
                float left = cell.Left + xPos;
                float bottom = top - currentMaxHeight;

                if (background != null) {
                    PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS];
                    backgr.SetColorFill(background);
                    backgr.Rectangle(left, bottom, right - left, top - bottom);
                    backgr.Fill();
                }
                if (cell.HasBorders()) {
                    Rectangle newRect = new Rectangle(left, bottom, right, top);
                    // Clone non-position parameters except for the background color
                    newRect.CloneNonPositionParameters(cell);
                    newRect.BackgroundColor = null;
                    // Write the borders on the line canvas
                    PdfContentByte lineCanvas = canvases[PdfPTable.LINECANVAS];
                    lineCanvas.Rectangle(newRect);
                }
            }
        }
Exemplo n.º 3
0
        /**
        * Writes the border and background of one cell in the row.
        * @param xPos
        * @param yPos
        * @param cell
        * @param canvases
        */
        public void WriteBorderAndBackground(float xPos, float yPos, PdfPCell cell,
                PdfContentByte[] canvases)
        {
            PdfContentByte lines = canvases[PdfPTable.LINECANVAS];
            PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS];
            // the coordinates of the border are retrieved
            float x1 = cell.Left + xPos;
            float y2 = cell.Top + yPos;
            float x2 = cell.Right + xPos;
            float y1 = y2 - maxHeight;

            // the backgroundcolor is set
            Color background = cell.BackgroundColor;
            if (background != null) {
                backgr.SetColorFill(background);
                backgr.Rectangle(x1, y1, x2 - x1, y2 - y1);
                backgr.Fill();
            }
            // if the element hasn't got any borders, nothing is added
            if (cell.HasBorders()) {
                if (cell.UseVariableBorders) {
                    Rectangle borderRect = new Rectangle(cell.Left + xPos, cell.Top
                            - maxHeight + yPos, cell.Right + xPos, cell.Top
                            + yPos);
                    borderRect.CloneNonPositionParameters(cell);
                    borderRect.BackgroundColor = null;
                    lines.Rectangle(borderRect);
                } else {
                    // the width is set to the width of the element
                    if (cell.BorderWidth != Rectangle.UNDEFINED) {
                        lines.SetLineWidth(cell.BorderWidth);
                    }
                    // the color is set to the color of the element
                    Color color = cell.BorderColor;
                    if (color != null) {
                        lines.SetColorStroke(color);
                    }

                    // if the box is a rectangle, it is added as a rectangle
                    if (cell.HasBorder(Rectangle.BOX)) {
                        lines.Rectangle(x1, y1, x2 - x1, y2 - y1);
                    }
                    // if the border isn't a rectangle, the different sides are
                    // added apart
                    else {
                        if (cell.HasBorder(Rectangle.RIGHT_BORDER)) {
                            lines.MoveTo(x2, y1);
                            lines.LineTo(x2, y2);
                        }
                        if (cell.HasBorder(Rectangle.LEFT_BORDER)) {
                            lines.MoveTo(x1, y1);
                            lines.LineTo(x1, y2);
                        }
                        if (cell.HasBorder(Rectangle.BOTTOM_BORDER)) {
                            lines.MoveTo(x1, y1);
                            lines.LineTo(x2, y1);
                        }
                        if (cell.HasBorder(Rectangle.TOP_BORDER)) {
                            lines.MoveTo(x1, y2);
                            lines.LineTo(x2, y2);
                        }
                    }
                    lines.Stroke();
                    if (color != null) {
                        lines.ResetRGBColorStroke();
                    }
                }
            }
        }
Exemplo n.º 4
0
        /**
         * Writes the border and background of one cell in the row.
         * @param xPos
         * @param yPos
         * @param cell
         * @param canvases
         */
        public void WriteBorderAndBackground(float xPos, float yPos, PdfPCell cell,
                                             PdfContentByte[] canvases)
        {
            PdfContentByte lines  = canvases[PdfPTable.LINECANVAS];
            PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS];
            // the coordinates of the border are retrieved
            float x1 = cell.Left + xPos;
            float y2 = cell.Top + yPos;
            float x2 = cell.Right + xPos;
            float y1 = y2 - maxHeight;

            // the backgroundcolor is set
            Color background = cell.BackgroundColor;

            if (background != null)
            {
                backgr.SetColorFill(background);
                backgr.Rectangle(x1, y1, x2 - x1, y2 - y1);
                backgr.Fill();
            }
            // if the element hasn't got any borders, nothing is added
            if (cell.HasBorders())
            {
                if (cell.UseVariableBorders)
                {
                    Rectangle borderRect = new Rectangle(cell.Left + xPos, cell.Top
                                                         - maxHeight + yPos, cell.Right + xPos, cell.Top
                                                         + yPos);
                    borderRect.CloneNonPositionParameters(cell);
                    borderRect.BackgroundColor = null;
                    lines.Rectangle(borderRect);
                }
                else
                {
                    // the width is set to the width of the element
                    if (cell.BorderWidth != Rectangle.UNDEFINED)
                    {
                        lines.SetLineWidth(cell.BorderWidth);
                    }
                    // the color is set to the color of the element
                    Color color = cell.BorderColor;
                    if (color != null)
                    {
                        lines.SetColorStroke(color);
                    }

                    // if the box is a rectangle, it is added as a rectangle
                    if (cell.HasBorder(Rectangle.BOX))
                    {
                        lines.Rectangle(x1, y1, x2 - x1, y2 - y1);
                    }
                    // if the border isn't a rectangle, the different sides are
                    // added apart
                    else
                    {
                        if (cell.HasBorder(Rectangle.RIGHT_BORDER))
                        {
                            lines.MoveTo(x2, y1);
                            lines.LineTo(x2, y2);
                        }
                        if (cell.HasBorder(Rectangle.LEFT_BORDER))
                        {
                            lines.MoveTo(x1, y1);
                            lines.LineTo(x1, y2);
                        }
                        if (cell.HasBorder(Rectangle.BOTTOM_BORDER))
                        {
                            lines.MoveTo(x1, y1);
                            lines.LineTo(x2, y1);
                        }
                        if (cell.HasBorder(Rectangle.TOP_BORDER))
                        {
                            lines.MoveTo(x1, y2);
                            lines.LineTo(x2, y2);
                        }
                    }
                    lines.Stroke();
                    if (color != null)
                    {
                        lines.ResetRGBColorStroke();
                    }
                }
            }
        }