?? columntext.java
字號:
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; lastWasNewline = true; } /** * Gets the first paragraph line indent. * @return the indent */ public float getIndent() { return indent; } /** * Sets the following paragraph lines indent. * @param indent the indent */ public void setFollowingIndent(float indent) { this.followingIndent = indent; lastWasNewline = true; } /** * Gets the following paragraph lines indent. * @return the indent */ public float getFollowingIndent() { return followingIndent; } /** * Sets the right paragraph lines indent. * @param indent the indent */ public void setRightIndent(float indent) { this.rightIndent = indent; lastWasNewline = true; } /** * Gets the right paragraph lines indent. * @return the indent */ public float getRightIndent() { return rightIndent; } /** * 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; float ratio = spaceCharRatio; Object currentValues[] = new Object[2]; PdfFont currentFont = null; Float lastBaseFactor = new Float(0); currentValues[1] = lastBaseFactor; PdfDocument pdf = null; PdfContentByte graphics = null; PdfContentByte text = null; int localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI; if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT) localRunDirection = runDirection; if (canvas != null) { graphics = canvas; pdf = canvas.getPdfDocument(); text = canvas.getDuplicate(); } else if (!simulate) throw new NullPointerException("ColumnText.go with simulate==false and text==null."); if (!simulate) { if (ratio == GLOBAL_SPACE_CHAR_RATIO) ratio = text.getPdfWriter().getSpaceCharRatio(); else if (ratio < 0.001f) ratio = 0.001f; } float firstIndent = 0; int status = 0; if (rectangularWidth > 0) { for (;;) { firstIndent = (lastWasNewline ? indent : followingIndent); if (rectangularWidth <= firstIndent + rightIndent) { status = NO_MORE_COLUMN; if (bidiLine.isEmpty()) status |= NO_MORE_TEXT; break; } if (bidiLine.isEmpty()) { status = NO_MORE_TEXT; break; } float yTemp = yLine; PdfLine line = bidiLine.processLine(rectangularWidth - firstIndent - rightIndent, alignment, localRunDirection); if (line == null) { status = NO_MORE_TEXT; break; } float maxSize = line.getMaxSizeSimple(); currentLeading = fixedLeading + maxSize * multipliedLeading; float xx[] = findLimitsTwoLines(); if (xx == null) { status = NO_MORE_COLUMN; yLine = yTemp; bidiLine.restore(); break; } float x1 = Math.max(xx[0], xx[2]); if (!simulate && !dirty) { text.beginText(); dirty = true; } if (!simulate) { currentValues[0] = currentFont; text.setTextMatrix(x1 + (line.isRTL() ? rightIndent : firstIndent) + line.indentLeft(), yLine); pdf.writeLineToContent(line, text, graphics, currentValues, ratio); currentFont = (PdfFont)currentValues[0]; } lastWasNewline = line.isNewlineSplit(); yLine -= line.isNewlineSplit() ? extraParagraphSpace : 0; } } else { currentLeading = fixedLeading; for (;;) { firstIndent = (lastWasNewline ? indent : followingIndent); float yTemp = yLine; float xx[] = findLimitsTwoLines(); if (xx == null) { status = NO_MORE_COLUMN; if (bidiLine.isEmpty()) status |= NO_MORE_TEXT; yLine = yTemp; break; } if (bidiLine.isEmpty()) { 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 + rightIndent) continue; if (!simulate && !dirty) { text.beginText(); dirty = true; } PdfLine line = bidiLine.processLine(x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection); if (line == null) { status = NO_MORE_TEXT; yLine = yTemp; break; } if (!simulate) { currentValues[0] = currentFont; text.setTextMatrix(x1 + (line.isRTL() ? rightIndent : firstIndent) + line.indentLeft(), yLine); pdf.writeLineToContent(line, text, graphics, currentValues, ratio); currentFont = (PdfFont)currentValues[0]; } lastWasNewline = line.isNewlineSplit(); yLine -= line.isNewlineSplit() ? extraParagraphSpace : 0; } } if (dirty) { text.endText(); canvas.add(text); } 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() { bidiLine.clearChunks(); } /** Gets the space/character extra spacing ratio for * fully justified text. * @return the space/character extra spacing ratio */ public float getSpaceCharRatio() { return spaceCharRatio; } /** Sets the ratio between the extra word spacing and the extra character spacing * when the text is fully justified. * Extra word spacing will grow <CODE>spaceCharRatio</CODE> times more than extra character spacing. * If the ratio is <CODE>PdfWriter.NO_SPACE_CHAR_RATIO</CODE> then the extra character spacing * will be zero. * @param spaceCharRatio the ratio between the extra word spacing and the extra character spacing */ public void setSpaceCharRatio(float spaceCharRatio) { this.spaceCharRatio = spaceCharRatio; } /** Sets the run direction. * @param runDirection the run direction */ public void setRunDirection(int runDirection) { if (runDirection < PdfWriter.RUN_DIRECTION_DEFAULT || runDirection > PdfWriter.RUN_DIRECTION_RTL) throw new RuntimeException("Invalid run direction: " + runDirection); this.runDirection = runDirection; } /** Gets the run direction. * @return the run direction */ public int getRunDirection() { return runDirection; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -