/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { float sp_left = spacing_left; if (float.IsNaN(sp_left)) { sp_left = 0f; } float sp_right = spacing_right; if (float.IsNaN(sp_right)) { sp_right = 0f; } float sp_top = spacing_top; if (float.IsNaN(sp_top)) { sp_top = 0f; } float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) { sp_bottom = 0f; } Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top)); rect.CloneNonPositionParameters(this); canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect); rect.BackgroundColor = null; canvases[PdfPTable.LINECANVAS].Rectangle(rect); }
/** * @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[]) */ public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { float[] width = widths[0]; Rectangle rect = new Rectangle(width[0], heights[heights.Length - 1], width[width.Length - 1], heights[0]); rect.CloneNonPositionParameters(this); int bd = rect.Border; rect.Border = Rectangle.NO_BORDER; canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect); rect.Border = bd; rect.BackgroundColor = null; canvases[PdfPTable.LINECANVAS].Rectangle(rect); }
/** * 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); } } }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { float sp_left = spacing_left; if (float.IsNaN(sp_left)) sp_left = 0f; float sp_right = spacing_right; if (float.IsNaN(sp_right)) sp_right = 0f; float sp_top = spacing_top; if (float.IsNaN(sp_top)) sp_top = 0f; float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) sp_bottom = 0f; Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top)); rect.CloneNonPositionParameters(this); canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect); rect.BackgroundColor = null; canvases[PdfPTable.LINECANVAS].Rectangle(rect); }
/** * 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(); } } } }
/** * Gets a Rectangle that is altered to fit on the page. * * @param top the top position * @param bottom the bottom position * @return a <CODE>Rectangle</CODE> */ public Rectangle Rectangle(float top, float bottom) { Rectangle tmp = new Rectangle(Left, Bottom, Right, Top); tmp.CloneNonPositionParameters(this); if (Top > top) { tmp.Top = top; tmp.Border = border - (border & TOP_BORDER); } if (Bottom < bottom) { tmp.Bottom = bottom; tmp.Border = border - (border & BOTTOM_BORDER); } return tmp; }