/** * 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(); } } } }