⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfprow.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			xPos -= widths[newStart - 1];		}		xPos -= cells[newStart].getLeft();		for (int k = newStart; k < colEnd; ++k) {			PdfPCell cell = cells[k];			if (cell == null)				continue;			writeBorderAndBackground(xPos, yPos, cell, canvases);			Image img = cell.getImage();			float tly = 0;			switch (cell.getVerticalAlignment()) {			case Element.ALIGN_BOTTOM:				tly = cell.getTop() + yPos - maxHeight + cell.getHeight()						- cell.getEffectivePaddingTop();				break;			case Element.ALIGN_MIDDLE:				tly = cell.getTop() + yPos + (cell.getHeight() - maxHeight) / 2						- cell.getEffectivePaddingTop();				break;			default:				tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();				break;			}			if (img != null) {                if (cell.getRotation() != 0) {                    img = Image.getInstance(img);                    img.setRotation(img.getImageRotation() + (float)(cell.getRotation() * Math.PI / 180.0));                }				boolean vf = false;				if (cell.getHeight() > maxHeight) {					img.scalePercent(100);					float scale = (maxHeight - cell.getEffectivePaddingTop() - cell							.getEffectivePaddingBottom())							/ img.getScaledHeight();					img.scalePercent(scale * 100);					vf = true;				}				float left = cell.getLeft() + xPos						+ cell.getEffectivePaddingLeft();				if (vf) {					switch (cell.getHorizontalAlignment()) {					case Element.ALIGN_CENTER:						left = xPos								+ (cell.getLeft() + cell.getEffectivePaddingLeft()										+ cell.getRight()										- cell.getEffectivePaddingRight() - img										.getScaledWidth()) / 2;						break;					case Element.ALIGN_RIGHT:						left = xPos + cell.getRight()								- cell.getEffectivePaddingRight()								- img.getScaledWidth();						break;					default:						break;					}					tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();				}				img.setAbsolutePosition(left, tly - img.getScaledHeight());				try {					canvases[PdfPTable.TEXTCANVAS].addImage(img);				} catch (DocumentException e) {					throw new ExceptionConverter(e);				}			} else {                // rotation sponsored by Connection GmbH                if (cell.getRotation() == 90 || cell.getRotation() == 270) {                    float netWidth = maxHeight - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom();                    float netHeight = cell.getWidth() - cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight();                    ColumnText ct = ColumnText.duplicate(cell.getColumn());                    ct.setCanvases(canvases);                    ct.setSimpleColumn(0, 0, netWidth + 0.001f, -netHeight);                    try {                        ct.go(true);                    } catch (DocumentException e) {                        throw new ExceptionConverter(e);                    }                    float calcHeight = -ct.getYLine();                    if (netWidth <= 0 || netHeight <= 0)                        calcHeight = 0;                    if (calcHeight > 0) {                        if (cell.isUseDescender())                            calcHeight -= ct.getDescender();                        ct = ColumnText.duplicate(cell.getColumn());                        ct.setCanvases(canvases);                        ct.setSimpleColumn(0, -0.001f, netWidth + 0.001f, calcHeight);                        float pivotX;                        float pivotY;                        if (cell.getRotation() == 90) {                            pivotY = cell.getTop() + yPos - maxHeight + cell.getEffectivePaddingBottom();                            switch (cell.getVerticalAlignment()) {                            case Element.ALIGN_BOTTOM:                                pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight();                                break;                            case Element.ALIGN_MIDDLE:                                pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() + calcHeight) / 2;                                break;                            default: //top                                pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft() + calcHeight;                                break;                            }                            saveAndRotateCanvases(canvases, 0,1,-1,0,pivotX,pivotY);                        }                        else {                            pivotY = cell.getTop() + yPos - cell.getEffectivePaddingTop();                            switch (cell.getVerticalAlignment()) {                            case Element.ALIGN_BOTTOM:                                pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft();                                break;                            case Element.ALIGN_MIDDLE:                                pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() - calcHeight) / 2;                                break;                            default: //top                                pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight() - calcHeight;                                break;                            }                            saveAndRotateCanvases(canvases, 0,-1,1,0,pivotX,pivotY);                        }                        try {                            ct.go();                        } catch (DocumentException e) {                            throw new ExceptionConverter(e);                        } finally {                            restoreCanvases(canvases);                        }                    }                }                 else {                    float fixedHeight = cell.getFixedHeight();                    float rightLimit = cell.getRight() + xPos                            - cell.getEffectivePaddingRight();                    float leftLimit = cell.getLeft() + xPos                            + cell.getEffectivePaddingLeft();                    if (cell.isNoWrap()) {                        switch (cell.getHorizontalAlignment()) {                            case Element.ALIGN_CENTER:                                rightLimit += 10000;                                leftLimit -= 10000;                                break;                            case Element.ALIGN_RIGHT:                            	if (cell.getRotation() == 180) {                            		rightLimit += 20000;                            	}                            	else {                            		leftLimit -= 20000;                            	}                                break;                            default:                            	if (cell.getRotation() == 180) {                            		leftLimit -= 20000;                            	}                            	else {                            		rightLimit += 20000;                            	}                                break;                        }                    }                    ColumnText ct = ColumnText.duplicate(cell.getColumn());                    ct.setCanvases(canvases);                    float bry = tly                            - (maxHeight /* cell.height() */                            - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom());                    if (fixedHeight > 0) {                        if (cell.getHeight() > maxHeight) {                            tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();                            bry = cell.getTop() + yPos - maxHeight + cell.getEffectivePaddingBottom();                        }                    }                    if ((tly > bry || ct.zeroHeightElement()) && leftLimit < rightLimit) {                        ct.setSimpleColumn(leftLimit, bry - 0.001f,	rightLimit, tly);                        if (cell.getRotation() == 180) {                            float shx = leftLimit + rightLimit;                            float shy = yPos + yPos - maxHeight + cell.getEffectivePaddingBottom() - cell.getEffectivePaddingTop();                            saveAndRotateCanvases(canvases, -1,0,0,-1,shx,shy);                        }                        try {                            ct.go();                        } catch (DocumentException e) {                            throw new ExceptionConverter(e);                        } finally {                            if (cell.getRotation() == 180) {                                restoreCanvases(canvases);                            }                        }                    }                }            }			PdfPCellEvent evt = cell.getCellEvent();			if (evt != null) {				Rectangle rect = new Rectangle(cell.getLeft() + xPos, cell.getTop()						+ yPos - maxHeight, cell.getRight() + xPos, cell.getTop()						+ yPos);				evt.cellLayout(cell, rect, canvases);			}		}	}	/**	 * Checks if the dimensions of the columns were calculated.	 * @return true if the dimensions of the columns were calculated	 */	public boolean isCalculated() {		return calculated;	}	/**	 * Gets the maximum height of the row (i.e. of the 'highest' cell).	 * @return the maximum height of the row	 */	public float getMaxHeights() {		if (calculated)			return maxHeight;		else			return calculateHeights();	}	/**	 * Changes the maximum height of the row (to make it higher).	 * (added by Jin-Hsia Yang)	 * @param maxHeight the new maximum height	 */	public void setMaxHeights(float maxHeight) {		this.maxHeight = maxHeight;	}	//end add	float[] getEventWidth(float xPos) {		int n = 0;		for (int k = 0; k < cells.length; ++k) {			if (cells[k] != null)				++n;		}		float width[] = new float[n + 1];		n = 0;		width[n++] = xPos;		for (int k = 0; k < cells.length; ++k) {			if (cells[k] != null) {				width[n] = width[n - 1] + cells[k].getWidth();				++n;			}		}		return width;	}	/**	 * Splits a row to newHeight. The returned row is the remainder. It will	 * return null if the newHeight was so small that only an empty row would	 * result.	 * 	 * @param newHeight	 *            the new height	 * @return the remainder row or null if the newHeight was so small that only	 *         an empty row would result	 */	public PdfPRow splitRow(float newHeight) {		PdfPCell newCells[] = new PdfPCell[cells.length];		float fh[] = new float[cells.length * 2];		boolean allEmpty = true;		for (int k = 0; k < cells.length; ++k) {			PdfPCell cell = cells[k];			if (cell == null)				continue;			fh[k * 2] = cell.getFixedHeight();			fh[k * 2 + 1] = cell.getMinimumHeight();			Image img = cell.getImage();			PdfPCell c2 = new PdfPCell(cell);			if (img != null) {				if (newHeight > cell.getEffectivePaddingBottom()						+ cell.getEffectivePaddingTop() + 2) {					c2.setPhrase(null);					allEmpty = false;				}			} else {                int status;                float y;				ColumnText ct = ColumnText.duplicate(cell.getColumn());                if (cell.getRotation() == 90 || cell.getRotation() == 270) {                    y = setColumn(ct,                            cell.getTop() - newHeight + cell.getEffectivePaddingBottom(),                            cell.getLeft() + cell.getEffectivePaddingLeft(),                            cell.getTop() - cell.getEffectivePaddingTop(),                            cell.getRight() - cell.getEffectivePaddingRight());                }                else {                    float rightLimit = cell.isNoWrap() ? 20000 : cell.getRight()                            - cell.getEffectivePaddingRight();                    float y1 = cell.getTop() - newHeight                            + cell.getEffectivePaddingBottom();                    float y2 = cell.getTop() - cell.getEffectivePaddingTop();                    y = setColumn(ct,                            cell.getLeft() + cell.getEffectivePaddingLeft(), y1,                            rightLimit, y2);                }				try {					status = ct.go(true);				} catch (DocumentException e) {					throw new ExceptionConverter(e);				}				boolean thisEmpty = (ct.getYLine() == y);				if (thisEmpty)					ct = ColumnText.duplicate(cell.getColumn());				allEmpty = (allEmpty && thisEmpty);				if ((status & ColumnText.NO_MORE_TEXT) == 0 || thisEmpty) {					c2.setColumn(ct);                    ct.setFilledWidth(0);				} else {					c2.setPhrase(null);				}			}			newCells[k] = c2;			cell.setFixedHeight(newHeight);		}		if (allEmpty) {			for (int k = 0; k < cells.length; ++k) {				PdfPCell cell = cells[k];				if (cell == null)					continue;				float f = fh[k * 2];				float m = fh[k * 2 + 1];				if (f <= 0)					cell.setMinimumHeight(m);				else					cell.setFixedHeight(f);			}			return null;		}		calculateHeights();		PdfPRow split = new PdfPRow(newCells);		split.widths = (float[]) widths.clone();		split.calculateHeights();		return split;	}		/**	 * Returns the array of cells in the row.	 * Please be extremely careful with this method.	 * Use the cells as read only objects.	 * @return	an array of cells	 * @since	2.1.1	 */	public PdfPCell[] getCells() {		return cells;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -