Java Code Examples for com.lowagie.text.Rectangle#cloneNonPositionParameters()

The following examples show how to use com.lowagie.text.Rectangle#cloneNonPositionParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfCell.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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>
 */

@Override
public Rectangle rectangle(float top, float bottom) {
	Rectangle tmp = new Rectangle(getLeft(), getBottom(), getRight(), getTop());
	tmp.cloneNonPositionParameters(this);
	if (getTop() > top) {
		tmp.setTop(top);
		tmp.setBorder(border - (border & TOP));
	}
	if (getBottom() < bottom) {
		tmp.setBottom(bottom);
		tmp.setBorder(border - (border & BOTTOM));
	}
	return tmp;
}
 
Example 2
Source File: PdfPRow.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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) {
	Color background = cell.getBackgroundColor();
	if (background != null || cell.hasBorders()) {
		// Add xPos resp. yPos to the cell's coordinates for absolute coordinates
		float right = cell.getRight() + xPos;
		float top = cell.getTop() + yPos;
		float left = cell.getLeft() + 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.setBackgroundColor(null);
			// Write the borders on the line canvas
			PdfContentByte lineCanvas = canvases[PdfPTable.LINECANVAS];
			lineCanvas.rectangle(newRect);
		}
	}
}
 
Example 3
Source File: PdfCell.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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(getLeft(), getBottom(), getRight(), getTop());
    tmp.cloneNonPositionParameters(this);
    if (getTop() > top) {
        tmp.setTop(top);
        tmp.setBorder(border - (border & TOP));
    }
    if (getBottom() < bottom) {
        tmp.setBottom(bottom);
        tmp.setBorder(border - (border & BOTTOM));
    }
    return tmp;
}
 
Example 4
Source File: PdfPRow.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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) {
	Color background = cell.getBackgroundColor();
	if (background != null || cell.hasBorders()) {
		// Add xPos resp. yPos to the cell's coordinates for absolute coordinates
		float right = cell.getRight() + xPos;
		float top = cell.getTop() + yPos;
		float left = cell.getLeft() + 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.setBackgroundColor(null);
			// Write the borders on the line canvas
			PdfContentByte lineCanvas = canvases[PdfPTable.LINECANVAS];
			lineCanvas.rectangle(newRect);
		}
	}
}
 
Example 5
Source File: PdfPRow.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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();
	} else if (cell.grayFill() > 0) {
		backgr.setGrayFill(cell.grayFill());
		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.isUseVariableBorders()) {
			Rectangle borderRect = new Rectangle(cell.left() + xPos, cell
					.top()
					- maxHeight + yPos, cell.right() + xPos, cell.top()
					+ yPos);
			borderRect.cloneNonPositionParameters(cell);
			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)) {
					lines.moveTo(x2, y1);
					lines.lineTo(x2, y2);
				}
				if (cell.hasBorder(Rectangle.LEFT)) {
					lines.moveTo(x1, y1);
					lines.lineTo(x1, y2);
				}
				if (cell.hasBorder(Rectangle.BOTTOM)) {
					lines.moveTo(x1, y1);
					lines.lineTo(x2, y1);
				}
				if (cell.hasBorder(Rectangle.TOP)) {
					lines.moveTo(x1, y2);
					lines.lineTo(x2, y2);
				}
			}
			lines.stroke();
			if (color != null) {
				lines.resetRGBColorStroke();
			}
		}
	}
}