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

📄 columntext.java

📁 java itext java itext java itext
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * @param ury the upper right y corner
 * @param leading the leading
 * @param alignment the column alignment
 */    
    public void setSimpleColumn(float llx, float lly, float urx, float ury, float leading, int alignment)
    {
        float leftLine[] = new float[4];
        float rightLine[] = new float[4];
        leftLine[0] = Math.min(llx, urx);
        leftLine[1] = Math.max(lly, ury);
        leftLine[2] = leftLine[0];
        leftLine[3] = Math.min(lly, ury);
        rightLine[0] = Math.max(llx, urx);
        rightLine[1] = leftLine[1];
        rightLine[2] = rightLine[0];
        rightLine[3] = leftLine[3];
        setColumns(leftLine, rightLine);
        setLeading(leading);
        this.alignment = alignment;
        yLine = leftLine[1];
        rectangularWidth = Math.abs(llx - urx);
    }
    
/**
 * Sets the leading to fixed
 * @param leading the leading
 */    
    public void setLeading(float leading)
    {
        fixedLeading = leading;
        multipliedLeading = 0;
    }
    
/**
 * Sets the leading fixed and variable. The resultant leading will be
 * fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the
 * size of the bigest font in the line.
 * @param fixedLeading the fixed leading
 * @param multipliedLeading the variable leading
 */    
    public void setLeading(float fixedLeading, float multipliedLeading)
    {
        this.fixedLeading = fixedLeading;
        this.multipliedLeading = multipliedLeading;
    }
    
/**
 * Gets the fixed leading
 * @return the leading
 */    
    public float getLeading()
    {
        return fixedLeading;
    }
    
/**
 * Gets the variable leading
 * @return the leading
 */    
    public float getMultipliedLeading()
    {
        return multipliedLeading;
    }
    
/**
 * Sets the yLine. The line will be written to yLine-leading.
 * @param yLine the yLine
 */    
    public void setYLine(float yLine)
    {
        this.yLine = yLine;
    }
	
/**
 * Gets the yLine.
 * @return the yLine
 */    
    public float getYLine()
    {
        return yLine;
    }
    
/**
 * Sets the alignment.
 * @param alignment the alignment
 */    
    public void setAlignment(int alignment)
    {
        this.alignment = alignment;
    }
    
/**
 * Gets the alignment.
 * @return the alignment
 */    
    public int getAlignment()
    {
        return alignment;
    }
    
/**
 * Sets the first paragraph line indent.
 * @param indent the indent
 */    
    public void setIndent(float indent)
    {
        this.indent = indent;
    }
    
/**
 * Gets the first paragraph line indent.
 * @return the indent
 */    
    public float getIndent()
    {
        return indent;
    }
    
/**
 * Creates a line from the chunk array.
 * @param width the width of the line
 * @return the line or null if no more chunks
 */    
    protected PdfLine createLine(float width)
    {
        if (chunks.size() == 0)
            return null;
        splittedChunkText = null;
        currentStandbyChunk = null;
        PdfLine line = new PdfLine(0, width, alignment, 0);
        String total;
        for (currentChunkMarker = 0; currentChunkMarker < chunks.size(); ++currentChunkMarker) {
            PdfChunk original = (PdfChunk)(chunks.get(currentChunkMarker));
            total = original.toString();
            currentStandbyChunk = line.add(original);
            if (currentStandbyChunk != null) {
                splittedChunkText = original.toString();
                original.setValue(total);
                return line;
            }
        }
        return line;
    }
    
/**
 * Normalizes the list of chunks when the line is accepted.
 */    
    protected void shortenChunkArray()
    {
        if (currentChunkMarker < 0)
            return;
        if (currentChunkMarker >= chunks.size()) {
            chunks.clear();
            return;
        }
        PdfChunk split = (PdfChunk)(chunks.get(currentChunkMarker));
        split.setValue(splittedChunkText);
        chunks.set(currentChunkMarker, currentStandbyChunk);
        for (int j = currentChunkMarker - 1; j >= 0; --j)
            chunks.remove(j);
    }
	
/**
 * Outputs the lines to the document. It is equivalent to <CODE>go(false)</CODE>.
 * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE>
 * and/or <CODE>NO_MORE_COLUMN</CODE>
 * @throws DocumentException on error
 */    
    public int go() throws DocumentException
    {
        return go(false);
    }
    
/**
 * Outputs the lines to the document. The output can be simulated.
 * @param simulate <CODE>true</CODE> to simulate the writting to the document
 * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE>
 * and/or <CODE>NO_MORE_COLUMN</CODE>
 * @throws DocumentException on error
 */    
    public int go(boolean simulate) throws DocumentException
    {
        boolean dirty = false;
        Object currentValues[] = new Object[2];
        PdfFont currentFont = null;
        Float lastBaseFactor = new Float(0);
        currentValues[1] = lastBaseFactor;
        PdfDocument pdf = null;
        PdfContentByte graphics = null;
        if (text != null) {
            pdf = text.getPdfDocument();
            graphics = text.getDuplicate();
        }
        else if (simulate == false)
            throw new NullPointerException("ColumnText.go with simulate==false and text==null.");
        float firstIndent = indent;
        
        int status = 0;
        if (rectangularWidth > 0) {
            for (;;) {
                if (rectangularWidth <= firstIndent) {
                    status = NO_MORE_COLUMN;
                    if (chunks.size() == 0)
                        status |= NO_MORE_TEXT;
                    break;
                }
                if (chunks.size() == 0) {
                    status = NO_MORE_TEXT;
                    break;
                }
                float yTemp = yLine;
                PdfLine line = createLine(rectangularWidth - firstIndent);
                float maxSize = line.getMaxSize();
                currentLeading = fixedLeading + maxSize * multipliedLeading;
                float xx[] = findLimitsTwoLines();
                if (xx == null) {
                    status = NO_MORE_COLUMN;
                    yLine = yTemp;
                    break;
                }
                float x1 = Math.max(xx[0], xx[2]);
                float x2 = Math.min(xx[1], xx[3]);
                if (!simulate && !dirty) {
                    text.beginText();
                    dirty = true;
                }
                shortenChunkArray();
                if (!simulate) {
                    currentValues[0] = currentFont;
                    text.setTextMatrix(x1 + firstIndent + line.indentLeft(), yLine);
                    pdf.writeLineToContent(line, text, graphics, currentValues);            
                    currentFont = (PdfFont)currentValues[0];
                }
                firstIndent = line.isNewlineSplit() ? indent : 0;
                yLine -= line.isNewlineSplit() ? extraParagraphSpace : 0;
            }
        }
        else {
            currentLeading = fixedLeading;
            for (;;) {
                float yTemp = yLine;
                float xx[] = findLimitsTwoLines();
                if (xx == null) {
                    status = NO_MORE_COLUMN;
                    if (chunks.size() == 0)
                        status |= NO_MORE_TEXT;
                    yLine = yTemp;
                    break;
                }
                if (chunks.size() == 0) {
                    status = NO_MORE_TEXT;
                    yLine = yTemp;
                    break;
                }
                float x1 = Math.max(xx[0], xx[2]);
                float x2 = Math.min(xx[1], xx[3]);
                if (x2 - x1 <= firstIndent)
                    continue;
                if (!simulate && !dirty) {
                    text.beginText();
                    dirty = true;
                }
                PdfLine line = createLine(x2 - x1 - firstIndent);
                shortenChunkArray();
                if (!simulate) {
                    currentValues[0] = currentFont;
                    text.setTextMatrix(x1 + firstIndent + line.indentLeft(), yLine);
                    pdf.writeLineToContent(line, text, graphics, currentValues);            
                    currentFont = (PdfFont)currentValues[0];
                }
                firstIndent = line.isNewlineSplit() ? indent : 0;
                yLine -= line.isNewlineSplit() ? extraParagraphSpace : 0;
            }
        }
        if (dirty) {
            text.endText();
            text.add(graphics);
        }
        return status;
    }
    
/**
 * Sets the extra space between paragraphs.
 * @return the extra space between paragraphs
 */    
    public float getExtraParagraphSpace() {
        return extraParagraphSpace;
    }
    
/**
 * Sets the extra space between paragraphs.
 * @param extraParagraphSpace the extra space between paragraphs
 */    
    public void setExtraParagraphSpace(float extraParagraphSpace) {
        this.extraParagraphSpace = extraParagraphSpace;
    }
    
/**
 * Clears the chunk array. A call to <CODE>go()</CODE> will always return
 * NO_MORE_TEXT.
 */    
    public void clearChunks()
    {
        chunks.clear();
    }
    
}

⌨️ 快捷键说明

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