| Method from com.lowagie.text.pdf.MultiColumnText Detail: |
public void addColumn(float[] left,
float[] right) {
ColumnDef nextDef = new ColumnDef(left, right);
simple = nextDef.isSimple();
columnDefs.add(nextDef);
}
Add a new column. The parameters are limits for each column
wall in the format of a sequence of points (x1,y1,x2,y2,...). |
public void addElement(Element element) throws DocumentException {
if (simple) {
columnText.addElement(element);
} else if (element instanceof Phrase) {
columnText.addText((Phrase) element);
} else if (element instanceof Chunk) {
columnText.addText((Chunk) element);
} else {
throw new DocumentException("Can't add " + element.getClass() + " to MultiColumnText with complex columns");
}
}
Add an element to be rendered in a column.
Note that you can only add a Phrase
or a Chunk if the columns are
not all simple. This is an underlying restriction in
com.lowagie.text.pdf.ColumnText |
public void addRegularColumns(float left,
float right,
float gutterWidth,
int numColumns) {
float currX = left;
float width = right - left;
float colWidth = (width - (gutterWidth * (numColumns - 1))) / numColumns;
for (int i = 0; i < numColumns; i++) {
addSimpleColumn(currX, currX + colWidth);
currX += colWidth + gutterWidth;
}
}
Add the specified number of evenly spaced rectangular columns.
Columns will be separated by the specified gutterWidth. |
public void addSimpleColumn(float left,
float right) {
ColumnDef newCol = new ColumnDef(left, right);
columnDefs.add(newCol);
}
Add a simple rectangular column with specified left
and right x position boundaries. |
public ArrayList getChunks() {
return null;
}
|
public int getCurrentColumn() {
if (columnsRightToLeft) {
return (columnDefs.size() - currentColumn - 1);
}
return currentColumn;
}
|
public boolean isContent() {
return true;
}
|
public boolean isNestable() {
return false;
}
|
public boolean isOverflow() {
return overflow;
}
Indicates that all of the text did not fit in the
specified height. Note that isOverflow will return
false before the MultiColumnText object has been
added to the document. It will always be false if
the height is AUTOMATIC. |
public void nextColumn() throws DocumentException {
currentColumn = (currentColumn + 1) % columnDefs.size();
top = nextY;
if (currentColumn == 0) {
newPage();
}
}
Moves the text insertion point to the beginning of the next column, issuing a page break if
needed. |
public boolean process(ElementListener listener) {
try {
return listener.add(this);
} catch (DocumentException de) {
return false;
}
}
Processes the element by adding it to an
ElementListener. |
public void resetCurrentColumn() {
currentColumn = 0;
}
Resets the current column. |
public void setAlignment(int alignment) {
columnText.setAlignment(alignment);
}
Sets the default alignment |
public void setArabicOptions(int arabicOptions) {
columnText.setArabicOptions(arabicOptions);
}
Sets the arabic shaping options. The option can be AR_NOVOWEL,
AR_COMPOSEDTASHKEEL and AR_LIG. |
public void setColumnsRightToLeft(boolean direction) {
columnsRightToLeft = direction;
}
Sets the direction of the columns. |
public void setRunDirection(int runDirection) {
columnText.setRunDirection(runDirection);
}
|
public void setSpaceCharRatio(float spaceCharRatio) {
columnText.setSpaceCharRatio(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 spaceCharRatio times more than extra character spacing.
If the ratio is PdfWriter.NO_SPACE_CHAR_RATIO then the extra character spacing
will be zero. |
public boolean shiftCurrentColumn() {
if (currentColumn + 1 < columnDefs.size()) {
currentColumn++;
return true;
}
return false;
}
Shifts the current column. |
public int type() {
return Element.MULTI_COLUMN_TEXT;
}
Gets the type of the text element. |
public void useColumnParams(ColumnText sourceColumn) {
// note that canvas will be overwritten later
columnText.setSimpleVars(sourceColumn);
}
Copy the parameters from the specified ColumnText to use
when rendering. Parameters like setArabicOptions
must be set in this way. |
public float write(PdfContentByte canvas,
PdfDocument document,
float documentY) throws DocumentException {
this.document = document;
columnText.setCanvas(canvas);
if (columnDefs.isEmpty()) {
throw new DocumentException("MultiColumnText has no columns");
}
overflow = false;
pageBottom = document.bottom();
float currentHeight = 0;
boolean done = false;
try {
while (!done) {
if (top == AUTOMATIC) {
top = document.getVerticalPosition(true); // RS - 07/07/2005 - Get current doc writing position for top of columns on new page.
}
else if (nextY == AUTOMATIC) {
nextY = document.getVerticalPosition(true); // RS - 07/07/2005 - - Get current doc writing position for top of columns on new page.
}
ColumnDef currentDef = (ColumnDef) columnDefs.get(getCurrentColumn());
columnText.setYLine(top);
float[] left = currentDef.resolvePositions(Rectangle.LEFT);
float[] right = currentDef.resolvePositions(Rectangle.RIGHT);
if (document.isMarginMirroring() && document.getPageNumber() % 2 == 0){
float delta = document.rightMargin() - document.left();
left = (float[])left.clone();
right = (float[])right.clone();
for (int i = 0; i < left.length; i += 2) {
left[i] -= delta;
}
for (int i = 0; i < right.length; i += 2) {
right[i] -= delta;
}
}
currentHeight = Math.max(currentHeight, getHeight(left, right));
if (currentDef.isSimple()) {
columnText.setSimpleColumn(left[2], left[3], right[0], right[1]);
} else {
columnText.setColumns(left, right);
}
int result = columnText.go();
if ((result & ColumnText.NO_MORE_TEXT) != 0) {
done = true;
top = columnText.getYLine();
} else if (shiftCurrentColumn()) {
top = nextY;
} else { // check if we are done because of height
totalHeight += currentHeight;
if ((desiredHeight != AUTOMATIC) && (totalHeight >= desiredHeight)) {
overflow = true;
break;
} else { // need to start new page and reset the columns
documentY = nextY;
newPage();
currentHeight = 0;
}
}
}
} catch (DocumentException ex) {
ex.printStackTrace();
throw ex;
}
if (desiredHeight == AUTOMATIC && columnDefs.size() == 1) {
currentHeight = documentY - columnText.getYLine();
}
return currentHeight;
}
Write out the columns. After writing, use
#isOverflow() to see if all text was written. |