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

📄 columntext.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    if (compositeColumn == null) {                        if (item == null) {                            listIdx = 0;                            compositeElements.removeFirst();                            continue main_loop;                        }                        compositeColumn = new ColumnText(canvas);                        compositeColumn.setUseAscender(firstPass ? useAscender : false);                        compositeColumn.setAlignment(item.getAlignment());                        compositeColumn.setIndent(item.getIndentationLeft() + listIndentation + item.getFirstLineIndent());                        compositeColumn.setExtraParagraphSpace(item.getExtraParagraphSpace());                        compositeColumn.setFollowingIndent(compositeColumn.getIndent());                        compositeColumn.setRightIndent(item.getIndentationRight() + list.getIndentationRight());                        compositeColumn.setLeading(item.getLeading(), item.getMultipliedLeading());                        compositeColumn.setRunDirection(runDirection);                        compositeColumn.setArabicOptions(arabicOptions);                        compositeColumn.setSpaceCharRatio(spaceCharRatio);                        compositeColumn.addText(item);                        if (!firstPass) {                            yLine -= item.spacingBefore();                        }                        createHere = true;                    }                    compositeColumn.leftX = leftX;                    compositeColumn.rightX = rightX;                    compositeColumn.yLine = yLine;                    compositeColumn.rectangularWidth = rectangularWidth;                    compositeColumn.rectangularMode = rectangularMode;                    compositeColumn.minY = minY;                    compositeColumn.maxY = maxY;                    boolean keepCandidate = (item.getKeepTogether() && createHere && !firstPass);                    status = compositeColumn.go(simulate || (keepCandidate && keep == 0));                    updateFilledWidth(compositeColumn.filledWidth);                    if ((status & NO_MORE_TEXT) == 0 && keepCandidate) {                        compositeColumn = null;                        yLine = lastY;                        return NO_MORE_COLUMN;                    }                    if (simulate || !keepCandidate)                        break;                    if (keep == 0) {                        compositeColumn = null;                        yLine = lastY;                    }                }                firstPass = false;                yLine = compositeColumn.yLine;                linesWritten += compositeColumn.linesWritten;                descender = compositeColumn.descender;                if (!Float.isNaN(compositeColumn.firstLineY) && !compositeColumn.firstLineYDone) {                    if (!simulate)                        showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(item.getListSymbol()), compositeColumn.leftX + listIndentation, compositeColumn.firstLineY, 0);                    compositeColumn.firstLineYDone = true;                }                if ((status & NO_MORE_TEXT) != 0) {                    compositeColumn = null;                    ++listIdx;                    yLine -= item.spacingAfter();                }                if ((status & NO_MORE_COLUMN) != 0) {                    return NO_MORE_COLUMN;                }            }            else if (element.type() == Element.PTABLE) {            	// don't write anything in the current column if there's no more space available                if (yLine < minY || yLine > maxY)                    return NO_MORE_COLUMN;                                // get the PdfPTable element                PdfPTable table = (PdfPTable)element;                                // we ignore tables without a body                if (table.size() <= table.getHeaderRows()) {                    compositeElements.removeFirst();                    continue;                }                                // offsets                float yTemp = yLine;                if (!firstPass && listIdx == 0) {                    yTemp -= table.spacingBefore();                }                float yLineWrite = yTemp;                                // don't write anything in the current column if there's no more space available                if (yTemp < minY || yTemp > maxY) {                    return NO_MORE_COLUMN;                }                                // coordinates                currentLeading = 0;                float x1 = leftX;                float tableWidth;                if (table.isLockedWidth()) {                    tableWidth = table.getTotalWidth();                    updateFilledWidth(tableWidth);                }                else {                    tableWidth = rectangularWidth * table.getWidthPercentage() / 100f;                    table.setTotalWidth(tableWidth);                }                                // how many header rows are real header rows; how many are footer rows?                int headerRows = table.getHeaderRows();                int footerRows = table.getFooterRows();                if (footerRows > headerRows)                    footerRows = headerRows;                int realHeaderRows = headerRows - footerRows;                float headerHeight = table.getHeaderHeight();                float footerHeight = table.getFooterHeight();                // make sure the header and footer fit on the page                boolean skipHeader = (!firstPass && table.isSkipFirstHeader() && listIdx <= headerRows);                if (!skipHeader) {                    yTemp -= headerHeight;                    if (yTemp < minY || yTemp > maxY) {                        if (firstPass) {                            compositeElements.removeFirst();                            continue;                        }                        return NO_MORE_COLUMN;                    }                }                                // how many real rows (not header or footer rows) fit on a page?                int k;                if (listIdx < headerRows) {                    listIdx = headerRows;                }                if (!table.isComplete()) {                	yTemp -= footerHeight;                }                for (k = listIdx; k < table.size(); ++k) {                    float rowHeight = table.getRowHeight(k);                    if (yTemp - rowHeight < minY)                        break;                    yTemp -= rowHeight;                }                if (!table.isComplete()) {                	yTemp += footerHeight;                }                // either k is the first row that doesn't fit on the page (break);                if (k < table.size()) {                	if (table.isSplitRows() && (!table.isSplitLate() || (k == listIdx && firstPass))) {                        if (!splittedRow) {                            splittedRow = true;                            table = new PdfPTable(table);                            compositeElements.set(0, table);                            ArrayList rows = table.getRows();                            for (int i = headerRows; i < listIdx; ++i)                                rows.set(i, null);                        }                        float h = yTemp - minY;                        PdfPRow newRow = table.getRow(k).splitRow(h);                        if (newRow == null) {                            if (k == listIdx) {                                return NO_MORE_COLUMN;                            }                        }                        else {                            yTemp = minY;                            table.getRows().add(++k, newRow);                        }                    }                    else if (!table.isSplitRows() && k == listIdx && firstPass) {                        compositeElements.removeFirst();                        splittedRow = false;                        continue;                    }                    else if (k == listIdx && !firstPass && (!table.isSplitRows() || table.isSplitLate()) && (table.getFooterRows() == 0 || table.isComplete())) {                        return NO_MORE_COLUMN;                    }                }                // or k is the number of rows in the table (for loop was done).                firstPass = false;                // we draw the table (for real now)                if (!simulate) {                	// set the alignment                    switch (table.getHorizontalAlignment()) {                        case Element.ALIGN_LEFT:                            break;                        case Element.ALIGN_RIGHT:                            x1 += rectangularWidth - tableWidth;                            break;                        default:                            x1 += (rectangularWidth - tableWidth) / 2f;                    }                    // copy the rows that fit on the page in a new table nt                    PdfPTable nt = PdfPTable.shallowCopy(table);                    ArrayList rows = table.getRows();                    ArrayList sub = nt.getRows();                                        // first we add the real header rows (if necessary)                    if (!skipHeader) {                        for (int j = 0; j < realHeaderRows; ++j) {                        	PdfPRow headerRow = (PdfPRow)rows.get(j);                            sub.add(headerRow);                        }                    }                    else {                        nt.setHeaderRows(footerRows);                    }                    // then we add the real content                    for (int j = listIdx; j < k; ++j) {                        sub.add(rows.get(j));                    }                    // if k < table.size(), we must indicate that the new table is complete;                    // otherwise no footers will be added (because iText thinks the table continues on the same page)                    if (k < table.size()) {                    	nt.setComplete(true);                    }                    // we add the footer rows if necessary (not for incomplete tables)                    for (int j = 0; j < footerRows && nt.isComplete(); ++j) {                        sub.add(rows.get(j + realHeaderRows));                    }                    // we need a correction if the last row needs to be extended                    float rowHeight = 0;                    if (table.isExtendLastRow()) {                        PdfPRow last = (PdfPRow)sub.get(sub.size() - 1 - footerRows);                        rowHeight = last.getMaxHeights();                        last.setMaxHeights(yTemp - minY + rowHeight);                        yTemp = minY;                    }                                        // now we render the rows of the new table                    if (canvases != null)                        nt.writeSelectedRows(0, -1, x1, yLineWrite, canvases);                    else                        nt.writeSelectedRows(0, -1, x1, yLineWrite, canvas);                    if (table.isExtendLastRow()) {                        PdfPRow last = (PdfPRow)sub.get(sub.size() - 1 - footerRows);                        last.setMaxHeights(rowHeight);                    }                }                else if (table.isExtendLastRow() && minY > PdfPRow.BOTTOM_LIMIT) {                    yTemp = minY;                }                yLine = yTemp;                if (!(skipHeader || table.isComplete())) {                	yLine += footerHeight;                }                if (k >= table.size()) {                    yLine -= table.spacingAfter();                    compositeElements.removeFirst();                    splittedRow = false;                    listIdx = 0;                }                else {                    if (splittedRow) {                        ArrayList rows = table.getRows();                        for (int i = listIdx; i < k; ++i)                            rows.set(i, null);                    }                    listIdx = k;                    return NO_MORE_COLUMN;                }            }            else if (element.type() == Element.YMARK) {                if (!simulate) {                    DrawInterface zh = (DrawInterface)element;                    zh.draw(canvas, leftX, minY, rightX, maxY, yLine);                }                compositeElements.removeFirst();            }            else                compositeElements.removeFirst();        }    }        /**     * Gets the canvas.     * @return a PdfContentByte.     */    public PdfContentByte getCanvas() {        return canvas;    }        /**     * Sets the canvas.     * @param canvas     */    public void setCanvas(PdfContentByte canvas) {        this.canvas = canvas;        this.canvases = null;        if (compositeColumn != null)            compositeColumn.setCanvas(canvas);    }        /**     * Sets the canvases.     * @param canvases     */    public void setCanvases(PdfContentByte[] canvases) {        this.canvases = canvases;        this.canvas = canvases[PdfPTable.TEXTCANVAS];        if (compositeColumn != null)            compositeColumn.setCanvases(canvases);    }        /**     * Gets the canvases.     * @return an array of PdfContentByte     */    public PdfContentByte[] getCanvases() {        return canvases;    }        /**     * Checks if the element has a height of 0.     * @return true or false     * @since 2.1.2     */    public boolean zeroHeightElement() {        return composite && !compositeElements.isEmpty() && ((Element)compositeElements.getFirst()).type() == Element.YMARK;    }        /**     * Checks if UseAscender is enabled/disabled.     * @return true is the adjustment of the first line height is based on max ascender.     */    public boolean isUseAscender() {        return useAscender;    }    /**     * Enables/Disables adjustment of first line height based on max ascender.     * @param use enable adjustment if true     */    public void setUseAscender(boolean use) {        useAscender = use;    }        /**     * Checks the status variable and looks if there's still some text.     */    public static boolean hasMoreText(int status) {    	return (status & ColumnText.NO_MORE_TEXT) == 0;    }    /**     * Holds value of property filledWidth.     */    private float filledWidth;    /**     * Gets the real width used by the largest line.     * @return the real width used by the largest line     */    public float getFilledWidth() {        return this.filledWidth;    }    /**     * Sets the real width used by the largest line. Only used to set it     * to zero to start another measurement.     * @param filledWidth the real width used by the largest line     */    public void setFilledWidth(float filledWidth) {        this.filledWidth = filledWidth;    }        /**     * Replaces the <CODE>filledWidth</CODE> if greater than the existing one.     * @param w the new <CODE>filledWidth</CODE> if greater than the existing one     */    public void updateFilledWidth(float w) {        if (w > filledWidth)            filledWidth = w;    }    private boolean adjustFirstLine = true;    /**     * Gets the first line adjustment property.     * @return the first line adjustment property.     */    public boolean isAdjustFirstLine() {        return this.adjustFirstLine;    }    /**     * Sets the first line adjustment. Some objects have properties, like spacing before, that     * behave differently if the object is the first to be written after go() or not. The first line adjustment is      * <CODE>true</CODE> by default but can be changed if several objects are to be placed one     * after the other in the same column calling go() several times.     * @param adjustFirstLine <CODE>true</CODE> to adjust the first line, <CODE>false</CODE> otherwise     */    public void setAdjustFirstLine(boolean adjustFirstLine) {        this.adjustFirstLine = adjustFirstLine;    }}

⌨️ 快捷键说明

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